From 1ccc7af4d45b4e314389cf9b1d12a7630df66ef4 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Thu, 6 Jun 2024 21:22:01 -0700 Subject: [PATCH] chore: move submodule, enable asar binding to fs --- .gitmodules | 4 +- {src => exe-src}/electron | 0 .../inject-asar-binding.ts | 1 + exe-src/inject-asar-fs.ts | 5 +++ {src => exe-src}/start.ts | 8 +--- next-env.d.ts | 5 +++ package.json | 2 +- pnpm-lock.yaml | 40 ++++++++----------- pnpm-workspace.yaml | 2 +- tsconfig.json | 24 ++++++++--- 10 files changed, 52 insertions(+), 39 deletions(-) rename {src => exe-src}/electron (100%) rename src/inject.ts => exe-src/inject-asar-binding.ts (95%) create mode 100644 exe-src/inject-asar-fs.ts rename {src => exe-src}/start.ts (82%) create mode 100644 next-env.d.ts diff --git a/.gitmodules b/.gitmodules index 6ffae7e..78bdd27 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "src/electron"] - path = src/electron +[submodule "exe-src/electron"] + path = exe-src/electron url = https://github.com/electron/electron.git diff --git a/src/electron b/exe-src/electron similarity index 100% rename from src/electron rename to exe-src/electron diff --git a/src/inject.ts b/exe-src/inject-asar-binding.ts similarity index 95% rename from src/inject.ts rename to exe-src/inject-asar-binding.ts index b00e69e..e666f54 100644 --- a/src/inject.ts +++ b/exe-src/inject-asar-binding.ts @@ -1,5 +1,6 @@ import * as asar from "@electron/asar" +// @ts-ignore const originalLinked = process._linkedBinding; // @ts-ignore diff --git a/exe-src/inject-asar-fs.ts b/exe-src/inject-asar-fs.ts new file mode 100644 index 0000000..b30adf2 --- /dev/null +++ b/exe-src/inject-asar-fs.ts @@ -0,0 +1,5 @@ +import { + wrapFsWithAsar +} from "./electron/lib/node/asar-fs-wrapper" + +wrapFsWithAsar(require('fs')); diff --git a/src/start.ts b/exe-src/start.ts similarity index 82% rename from src/start.ts rename to exe-src/start.ts index 0e7e5b9..9cb80df 100644 --- a/src/start.ts +++ b/exe-src/start.ts @@ -23,9 +23,5 @@ // // TODO: Pass this to the Next server above and start server with patched `fs` module -import { getAsset } from 'node:sea'; -const blob = getAsset('bundle.asar'); - -import * as test from "./electron/lib/node/asar-fs-wrapper" - -console.log({test, blob}); +// import { getAsset } from 'node:sea'; +// const blob = getAsset('bundle.asar'); diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 0000000..4f11a03 --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/package.json b/package.json index 9dba19f..318ee82 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "pnpm": ">=9.0.0" }, "scripts": { - "esbuild:build": "npx esbuild --format=cjs --target=node20 --platform=node --bundle --outfile=out/bundle.js --external:original-fs --inject:./src/inject.ts ./src/start.js", + "esbuild:build": "npx esbuild --format=cjs --target=node20 --platform=node --bundle --outfile=out/bundle.js --external:original-fs --inject:./exe-src/inject-asar-fs.ts --inject:./exe-src/inject-asar-binding.ts ./exe-src/start.js", "next:dev": "next dev", "next:build": "next build", "next:bundle": "asar pack ./.next ./out/bundle.asar", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec89010..e9dd762 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,9 +46,9 @@ importers: specifier: ^5.4.5 version: 5.4.5 - src/electron/default_app: {} + exe-src/electron/default_app: {} - src/electron/npm: + exe-src/electron/npm: dependencies: '@electron/get': specifier: ^2.0.0 @@ -60,17 +60,17 @@ importers: specifier: ^2.0.1 version: 2.0.1 - src/electron/spec: + exe-src/electron/spec: devDependencies: '@electron-ci/echo': specifier: file:./fixtures/native-addon/echo - version: file:src/electron/spec/fixtures/native-addon/echo + version: file:exe-src/electron/spec/fixtures/native-addon/echo '@electron-ci/is-valid-window': specifier: file:./is-valid-window - version: is-valid-window@file:src/electron/spec/is-valid-window + version: is-valid-window@file:exe-src/electron/spec/is-valid-window '@electron-ci/uv-dlopen': specifier: file:./fixtures/native-addon/uv-dlopen/ - version: file:src/electron/spec/fixtures/native-addon/uv-dlopen + version: file:exe-src/electron/spec/fixtures/native-addon/uv-dlopen '@electron/fuses': specifier: ^1.8.0 version: 1.8.0 @@ -161,11 +161,11 @@ importers: packages: - '@electron-ci/echo@file:src/electron/spec/fixtures/native-addon/echo': - resolution: {directory: src/electron/spec/fixtures/native-addon/echo, type: directory} + '@electron-ci/echo@file:exe-src/electron/spec/fixtures/native-addon/echo': + resolution: {directory: exe-src/electron/spec/fixtures/native-addon/echo, type: directory} - '@electron-ci/uv-dlopen@file:src/electron/spec/fixtures/native-addon/uv-dlopen': - resolution: {directory: src/electron/spec/fixtures/native-addon/uv-dlopen, type: directory} + '@electron-ci/uv-dlopen@file:exe-src/electron/spec/fixtures/native-addon/uv-dlopen': + resolution: {directory: exe-src/electron/spec/fixtures/native-addon/uv-dlopen, type: directory} '@electron/asar@3.2.10': resolution: {integrity: sha512-mvBSwIBUeiRscrCeJE1LwctAriBj65eUDm0Pc11iE5gRwzkmsdbS7FnZ1XUWjpSeQWL1L5g12Fc/SchPM9DUOw==} @@ -1141,8 +1141,8 @@ packages: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} - is-valid-window@file:src/electron/spec/is-valid-window: - resolution: {directory: src/electron/spec/is-valid-window, type: directory} + is-valid-window@file:exe-src/electron/spec/is-valid-window: + resolution: {directory: exe-src/electron/spec/is-valid-window, type: directory} isarray@0.0.1: resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==} @@ -1241,10 +1241,6 @@ packages: resolution: {integrity: sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==} engines: {node: '>=10'} - minimatch@5.1.6: - resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==} - engines: {node: '>=10'} - minimatch@9.0.4: resolution: {integrity: sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==} engines: {node: '>=16 || 14 >=14.17'} @@ -1823,9 +1819,9 @@ packages: snapshots: - '@electron-ci/echo@file:src/electron/spec/fixtures/native-addon/echo': {} + '@electron-ci/echo@file:exe-src/electron/spec/fixtures/native-addon/echo': {} - '@electron-ci/uv-dlopen@file:src/electron/spec/fixtures/native-addon/uv-dlopen': {} + '@electron-ci/uv-dlopen@file:exe-src/electron/spec/fixtures/native-addon/uv-dlopen': {} '@electron/asar@3.2.10': dependencies: @@ -2664,7 +2660,7 @@ snapshots: fs.realpath: 1.0.0 inflight: 1.0.6 inherits: 2.0.4 - minimatch: 5.1.6 + minimatch: 5.0.1 once: 1.4.0 global-agent@3.0.0: @@ -2779,7 +2775,7 @@ snapshots: is-unicode-supported@0.1.0: {} - is-valid-window@file:src/electron/spec/is-valid-window: + is-valid-window@file:exe-src/electron/spec/is-valid-window: dependencies: nan: 2.19.0 @@ -2876,10 +2872,6 @@ snapshots: dependencies: brace-expansion: 2.0.1 - minimatch@5.1.6: - dependencies: - brace-expansion: 2.0.1 - minimatch@9.0.4: dependencies: brace-expansion: 2.0.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index cd7e817..b05e723 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,2 @@ packages: - - 'src/electron/*' + - 'exe-src/electron/*' diff --git a/tsconfig.json b/tsconfig.json index 7b28589..dda6858 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,10 @@ { "compilerOptions": { - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -18,9 +22,19 @@ } ], "paths": { - "@/*": ["./src/*"] - } + "@/*": [ + "./src/*" + ] + }, + "target": "ES2017" }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], - "exclude": ["node_modules"] + "include": [ + "next-env.d.ts", + "src/**/*.ts", + "src/**/*.tsx", + ".next/types/**/*.ts" + ], + "exclude": [ + "node_modules" + ] } -- 2.51.2