Compare commits
5 Commits
main
...
b3059564b7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3059564b7 | ||
|
|
f7d15b8d34 | ||
|
|
1c55526cdb | ||
|
|
e9a5812213 | ||
|
|
ed1efe60a0 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,7 +1,9 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
entry-asar/*.js*
|
entry-asar/cjs/*.js*
|
||||||
entry-asar/*.ts
|
entry-asar/cjs/*.d.ts
|
||||||
|
entry-asar/esm/*.?js*
|
||||||
|
entry-asar/esm/*.d.?ts
|
||||||
*.app
|
*.app
|
||||||
test/fixtures/apps
|
test/fixtures/apps
|
||||||
coverage
|
coverage
|
||||||
|
|||||||
11
entry-asar/cjs/tsconfig.json
Normal file
11
entry-asar/cjs/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": ".",
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
".",
|
||||||
|
"../ambient.d.ts"
|
||||||
|
],
|
||||||
|
"exclude": []
|
||||||
|
}
|
||||||
28
entry-asar/esm/has-asar.mts
Normal file
28
entry-asar/esm/has-asar.mts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { app } from 'electron';
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
if (process.arch === 'arm64') {
|
||||||
|
await setPaths('arm64');
|
||||||
|
} else {
|
||||||
|
await setPaths('x64');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setPaths(platform: string) {
|
||||||
|
// This should return the full path, ending in something like
|
||||||
|
// Notion.app/Contents/Resources/app.asar
|
||||||
|
const appPath = app.getAppPath();
|
||||||
|
const asarFile = `app-${platform}.asar`;
|
||||||
|
|
||||||
|
// Maybe we'll handle this in Electron one day
|
||||||
|
if (path.basename(appPath) === 'app.asar') {
|
||||||
|
const platformAppPath = path.join(path.dirname(appPath), asarFile);
|
||||||
|
|
||||||
|
// This is an undocumented API. It exists.
|
||||||
|
app.setAppPath(platformAppPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
process._archPath = require.resolve(`../${asarFile}`);
|
||||||
|
await import(process._archPath);
|
||||||
|
}
|
||||||
29
entry-asar/esm/no-asar.mts
Normal file
29
entry-asar/esm/no-asar.mts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { app } from 'electron';
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
if (process.arch === 'arm64') {
|
||||||
|
await setPaths('arm64');
|
||||||
|
} else {
|
||||||
|
await setPaths('x64');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setPaths(platform: string) {
|
||||||
|
// This should return the full path, ending in something like
|
||||||
|
// Notion.app/Contents/Resources/app
|
||||||
|
const appPath = app.getAppPath();
|
||||||
|
const appFolder = `app-${platform}`;
|
||||||
|
|
||||||
|
// Maybe we'll handle this in Electron one day
|
||||||
|
if (path.basename(appPath) === 'app') {
|
||||||
|
const platformAppPath = path.join(path.dirname(appPath), appFolder);
|
||||||
|
|
||||||
|
// This is an undocumented private API. It exists.
|
||||||
|
app.setAppPath(platformAppPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
process._archPath = require.resolve(`../${appFolder}`);
|
||||||
|
|
||||||
|
await import(process._archPath);
|
||||||
|
}
|
||||||
13
entry-asar/esm/tsconfig.json
Normal file
13
entry-asar/esm/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.esm.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ESNext",
|
||||||
|
"target":"ESNext",
|
||||||
|
"outDir": ".",
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
".",
|
||||||
|
"../ambient.d.ts"
|
||||||
|
],
|
||||||
|
"exclude": []
|
||||||
|
}
|
||||||
@@ -20,12 +20,13 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"dist/*",
|
"dist/*",
|
||||||
"entry-asar/*",
|
"entry-asar/*",
|
||||||
"!entry-asar/**/*.ts",
|
"!entry-asar/**/*.{ts,mts}",
|
||||||
|
"!entry-asar/**/tsconfig.json",
|
||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"author": "Samuel Attard",
|
"author": "Samuel Attard",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.entry-asar.json",
|
"build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p entry-asar/esm/tsconfig.json && tsc -p entry-asar/cjs/tsconfig.json",
|
||||||
"build:docs": "npx typedoc",
|
"build:docs": "npx typedoc",
|
||||||
"lint": "prettier --check \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
"lint": "prettier --check \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
||||||
"prettier:write": "prettier --write \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
"prettier:write": "prettier --write \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
||||||
|
|||||||
45
src/index.ts
45
src/index.ts
@@ -233,14 +233,27 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
|||||||
|
|
||||||
const entryAsar = path.resolve(tmpDir, 'entry-asar');
|
const entryAsar = path.resolve(tmpDir, 'entry-asar');
|
||||||
await fs.mkdir(entryAsar);
|
await fs.mkdir(entryAsar);
|
||||||
await fs.copy(
|
|
||||||
path.resolve(__dirname, '..', '..', 'entry-asar', 'no-asar.js'),
|
|
||||||
path.resolve(entryAsar, 'index.js'),
|
|
||||||
);
|
|
||||||
let pj = await fs.readJson(
|
let pj = await fs.readJson(
|
||||||
path.resolve(opts.x64AppPath, 'Contents', 'Resources', 'app', 'package.json'),
|
path.resolve(opts.x64AppPath, 'Contents', 'Resources', 'app', 'package.json'),
|
||||||
);
|
);
|
||||||
pj.main = 'index.js';
|
|
||||||
|
// Load a shim that redirects to the correct folder for the architecture.
|
||||||
|
// This needs to be a different file depending on if the app entrypoint is CommonJS or ESM.
|
||||||
|
if (pj.type === 'module' || pj.main.endsWith('.mjs')) {
|
||||||
|
await fs.copy(
|
||||||
|
path.resolve(__dirname, '..', '..', 'entry-asar', 'esm', 'no-asar.mjs'),
|
||||||
|
path.resolve(entryAsar, 'index.mjs'),
|
||||||
|
);
|
||||||
|
pj.main = 'index.mjs';
|
||||||
|
} else {
|
||||||
|
await fs.copy(
|
||||||
|
path.resolve(__dirname, '..', '..', 'entry-asar', 'cjs', 'no-asar.js'),
|
||||||
|
path.resolve(entryAsar, 'index.js'),
|
||||||
|
);
|
||||||
|
pj.main = 'index.js';
|
||||||
|
}
|
||||||
|
|
||||||
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
|
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
|
||||||
await asar.createPackage(
|
await asar.createPackage(
|
||||||
entryAsar,
|
entryAsar,
|
||||||
@@ -313,10 +326,6 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
|||||||
|
|
||||||
const entryAsar = path.resolve(tmpDir, 'entry-asar');
|
const entryAsar = path.resolve(tmpDir, 'entry-asar');
|
||||||
await fs.mkdir(entryAsar);
|
await fs.mkdir(entryAsar);
|
||||||
await fs.copy(
|
|
||||||
path.resolve(__dirname, '..', '..', 'entry-asar', 'has-asar.js'),
|
|
||||||
path.resolve(entryAsar, 'index.js'),
|
|
||||||
);
|
|
||||||
let pj = JSON.parse(
|
let pj = JSON.parse(
|
||||||
(
|
(
|
||||||
await asar.extractFile(
|
await asar.extractFile(
|
||||||
@@ -325,7 +334,23 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
|||||||
)
|
)
|
||||||
).toString('utf8'),
|
).toString('utf8'),
|
||||||
);
|
);
|
||||||
pj.main = 'index.js';
|
|
||||||
|
// Load a shim that redirects to the correct `app.asar` for the architecture.
|
||||||
|
// This needs to be a different file depending on if the app entrypoint is CommonJS or ESM.
|
||||||
|
if (pj.type === 'module' || pj.main.endsWith('.mjs')) {
|
||||||
|
await fs.copy(
|
||||||
|
path.resolve(__dirname, '..', '..', 'entry-asar', 'esm', 'has-asar.mjs'),
|
||||||
|
path.resolve(entryAsar, 'index.mjs'),
|
||||||
|
);
|
||||||
|
pj.main = 'index.mjs';
|
||||||
|
} else {
|
||||||
|
await fs.copy(
|
||||||
|
path.resolve(__dirname, '..', '..', 'entry-asar', 'cjs', 'has-asar.js'),
|
||||||
|
path.resolve(entryAsar, 'index.js'),
|
||||||
|
);
|
||||||
|
pj.main = 'index.js';
|
||||||
|
}
|
||||||
|
|
||||||
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
|
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
|
||||||
const asarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar');
|
const asarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar');
|
||||||
await asar.createPackage(entryAsar, asarPath);
|
await asar.createPackage(entryAsar, asarPath);
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "entry-asar",
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"entry-asar"
|
|
||||||
],
|
|
||||||
"exclude": []
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
"declaration": true
|
"declaration": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src",
|
"src"
|
||||||
"entry-asar"
|
],
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user