diff --git a/.gitignore b/.gitignore index 6c0883e..1d3ce5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules dist -*.app \ No newline at end of file +entry-asar/*.js* +entry-asar/*.ts +*.app diff --git a/entry-asar/ambient.d.ts b/entry-asar/ambient.d.ts new file mode 100644 index 0000000..4a7ae0b --- /dev/null +++ b/entry-asar/ambient.d.ts @@ -0,0 +1,19 @@ +declare namespace NodeJS { + interface Process extends EventEmitter { + // This is an undocumented private API. It exists. + _archPath: string; + } +} + +declare module 'electron' { + const app: Electron.App; + + namespace Electron { + interface App { + getAppPath: () => string; + setAppPath: (p: string) => void; + } + } + + export { app }; +} diff --git a/entry-asar/has-asar.js b/entry-asar/has-asar.ts similarity index 86% rename from entry-asar/has-asar.js rename to entry-asar/has-asar.ts index ff6c713..625e692 100644 --- a/entry-asar/has-asar.js +++ b/entry-asar/has-asar.ts @@ -1,5 +1,5 @@ -const { app } = require('electron'); -const path = require('path'); +import { app } from 'electron'; +import path from 'path'; if (process.arch === 'arm64') { setPaths('arm64'); @@ -7,7 +7,7 @@ if (process.arch === 'arm64') { setPaths('x64'); } -function setPaths(platform) { +function setPaths(platform: string) { // This should return the full path, ending in something like // Notion.app/Contents/Resources/app.asar const appPath = app.getAppPath(); diff --git a/entry-asar/no-asar.js b/entry-asar/no-asar.ts similarity index 86% rename from entry-asar/no-asar.js rename to entry-asar/no-asar.ts index abe0af5..caadd8e 100644 --- a/entry-asar/no-asar.js +++ b/entry-asar/no-asar.ts @@ -1,10 +1,13 @@ +import { app } from 'electron'; +import path from 'path'; + if (process.arch === 'arm64') { setPaths('arm64'); } else { setPaths('x64'); } -function setPaths(platform) { +function setPaths(platform: string) { // This should return the full path, ending in something like // Notion.app/Contents/Resources/app const appPath = app.getAppPath(); diff --git a/package.json b/package.json index b8b3934..b449a01 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,14 @@ "files": [ "dist/*", "entry-asar/*", + "!entry-asar/**/*.ts", "README.md" ], "author": "Samuel Attard", "scripts": { - "build": "tsc && tsc -p tsconfig.esm.json", - "lint": "prettier --check \"{src,entry-asar}/**/*.{js,ts}\"", - "prettier:write": "prettier --write \"{src,entry-asar}/**/*.{js,ts}\"", + "build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.entry-asar.json", + "lint": "prettier --check \"{src,entry-asar}/**/*.ts\"", + "prettier:write": "prettier --write \"{src,entry-asar}/**/*.ts\"", "prepublishOnly": "npm run build", "test": "exit 0", "prepare": "husky install" @@ -57,4 +58,4 @@ "prettier --write" ] } -} \ No newline at end of file +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..b90fc83 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"] +} diff --git a/tsconfig.entry-asar.json b/tsconfig.entry-asar.json new file mode 100644 index 0000000..33a1928 --- /dev/null +++ b/tsconfig.entry-asar.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "entry-asar", + }, + "include": [ + "entry-asar" + ], + "exclude": [] +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 53692fe..063096b 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -3,5 +3,6 @@ "compilerOptions": { "module": "esnext", "outDir": "dist/esm" - } -} \ No newline at end of file + }, + "include": ["src"] +} diff --git a/tsconfig.json b/tsconfig.json index f85f433..bb91a1e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ "declaration": true }, "include": [ - "src" + "src", + "entry-asar" ] }