Skip to content

Commit

Permalink
build: use Typescript for files in entry-asar
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Nov 2, 2023
1 parent 52fa9a2 commit 680d0e1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist
*.app
entry-asar/*.js*
entry-asar/*.ts
*.app
19 changes: 19 additions & 0 deletions entry-asar/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
6 changes: 3 additions & 3 deletions entry-asar/has-asar.js → entry-asar/has-asar.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { app } = require('electron');
const path = require('path');
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.asar
const appPath = app.getAppPath();
Expand Down
5 changes: 4 additions & 1 deletion entry-asar/no-asar.js → entry-asar/no-asar.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -57,4 +58,4 @@
"prettier --write"
]
}
}
}
4 changes: 4 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"]
}
11 changes: 11 additions & 0 deletions tsconfig.entry-asar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "entry-asar",
"types": ["node"]
},
"include": [
"entry-asar"
],
"exclude": []
}
5 changes: 3 additions & 2 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm"
}
}
},
"include": ["src"]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"declaration": true
},
"include": [
"src"
"src",
"entry-asar"
]
}

0 comments on commit 680d0e1

Please sign in to comment.