Initial commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dinlo
2026-05-31 18:44:04 +08:00
commit 436a9631fc
8616 changed files with 1389957 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
export declare function dynamicImport(path: string): Promise<any>;
/** Like {@link dynamicImport()}, except it tries out {@link require()} first. */
export declare function dynamicImportMaybe(path: string): Promise<any>;
+23
View File
@@ -0,0 +1,23 @@
const url = require("url")
const fs = require("fs")
exports.dynamicImport = async function dynamicImport(path) {
try {
return await import(fs.existsSync(path) ? url.pathToFileURL(path).href : path)
} catch (error) {
return Promise.reject(error)
}
}
exports.dynamicImportMaybe = async function dynamicImportMaybe(path) {
try {
return require(path)
} catch (e1) {
try {
return await exports.dynamicImport(path)
} catch (e2) {
e1.message = "\n1. " + e1.message + "\n2. " + e2.message
throw e1
}
}
}
+38
View File
@@ -0,0 +1,38 @@
if (!process.send) {
console.error("The remote rebuilder expects to be spawned with an IPC channel")
process.exit(1)
}
const rebuilder = rebuilder => {
rebuilder.lifecycle.on("module-found", moduleName => process.send?.({ msg: "module-found", moduleName }))
rebuilder.lifecycle.on("module-done", moduleName => process.send?.({ msg: "module-done", moduleName }))
rebuilder.lifecycle.on("module-skip", moduleName => process.send?.({ msg: "module-skip", moduleName }))
return rebuilder
.then(() => {
process.send?.({ msg: "rebuild-done" })
return process.exit(0)
})
.catch(err => {
process.send?.({
msg: "rebuild-error",
err: {
message: err.message,
stack: err.stack,
},
})
process.exit(0)
})
}
const main = () => {
const options = JSON.parse(process.argv[2])
const dynamicImport = require("./dynamic-import").dynamicImportMaybe
return dynamicImport("@electron/rebuild").then(module => {
const { rebuild } = module
return rebuilder(rebuild(options))
})
}
main()