beep boop

This commit is contained in:
Erick Zhao
2024-06-12 20:34:54 -07:00
parent e6d2697cbc
commit ed1efe60a0
10 changed files with 76 additions and 21 deletions

6
.gitignore vendored
View File

@@ -1,7 +1,9 @@
node_modules
dist
entry-asar/*.js*
entry-asar/*.ts
entry-asar/cjs/*.?js*
entry-asar/cjs/*.d.?ts
entry-asar/esm/*.?js*
entry-asar/esm/*.d.?ts
*.app
test/fixtures/apps
coverage

View File

@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": ".",
},
"include": [
".",
"../ambient.d.ts"
],
"exclude": []
}

View 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);
}

View File

@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"module": "ESNext",
"target":"ESNext",
"outDir": ".",
},
"include": [
".",
"../ambient.d.ts"
],
"exclude": []
}

View File

@@ -25,7 +25,7 @@
],
"author": "Samuel Attard",
"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 tsconfig.entry-asar.json && tsc -p tsconfig.entry-asar.esm.json",
"lint": "prettier --check \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
"prettier:write": "prettier --write \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
"prepublishOnly": "npm run build",

View File

@@ -290,10 +290,6 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
const entryAsar = path.resolve(tmpDir, 'entry-asar');
await fs.mkdir(entryAsar);
await fs.copy(
path.resolve(__dirname, '..', '..', 'entry-asar', 'has-asar.js'),
path.resolve(entryAsar, 'index.js'),
);
let pj = JSON.parse(
(
await asar.extractFile(
@@ -302,7 +298,23 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
)
).toString('utf8'),
);
if (pj.type === 'module') {
d('ERICK TEST!!!!');
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', 'has-asar.js'),
path.resolve(entryAsar, 'index.js'),
);
pj.main = 'index.js';
}
d(JSON.stringify(pj, null, 2));
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
const asarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar');
await asar.createPackage(entryAsar, asarPath);

View File

@@ -1,10 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "entry-asar",
},
"include": [
"entry-asar"
],
"exclude": []
}

View File

@@ -17,7 +17,6 @@
"declaration": true
},
"include": [
"src",
"entry-asar"
]
"src"
],
}