From d25e11bee6ca5ca523884da132d18e1400e077b9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 24 Aug 2021 14:41:48 +0200 Subject: Initial commit --- node_modules/nexe/lib/patches/boot-nexe.d.ts | 5 ++ node_modules/nexe/lib/patches/boot-nexe.js | 38 +++++++++ node_modules/nexe/lib/patches/build-fixes.d.ts | 2 + node_modules/nexe/lib/patches/build-fixes.js | 22 ++++++ .../nexe/lib/patches/disable-node-cli.d.ts | 2 + node_modules/nexe/lib/patches/disable-node-cli.js | 45 +++++++++++ node_modules/nexe/lib/patches/flags.d.ts | 2 + node_modules/nexe/lib/patches/flags.js | 22 ++++++ node_modules/nexe/lib/patches/gyp.d.ts | 2 + node_modules/nexe/lib/patches/gyp.js | 25 ++++++ node_modules/nexe/lib/patches/ico.d.ts | 2 + node_modules/nexe/lib/patches/ico.js | 24 ++++++ node_modules/nexe/lib/patches/index.d.ts | 3 + node_modules/nexe/lib/patches/index.js | 12 +++ node_modules/nexe/lib/patches/node-rc.d.ts | 2 + node_modules/nexe/lib/patches/node-rc.js | 37 +++++++++ node_modules/nexe/lib/patches/snapshot.d.ts | 2 + node_modules/nexe/lib/patches/snapshot.js | 25 ++++++ .../nexe/lib/patches/third-party-main.d.ts | 2 + node_modules/nexe/lib/patches/third-party-main.js | 92 ++++++++++++++++++++++ 20 files changed, 366 insertions(+) create mode 100644 node_modules/nexe/lib/patches/boot-nexe.d.ts create mode 100644 node_modules/nexe/lib/patches/boot-nexe.js create mode 100644 node_modules/nexe/lib/patches/build-fixes.d.ts create mode 100644 node_modules/nexe/lib/patches/build-fixes.js create mode 100644 node_modules/nexe/lib/patches/disable-node-cli.d.ts create mode 100644 node_modules/nexe/lib/patches/disable-node-cli.js create mode 100644 node_modules/nexe/lib/patches/flags.d.ts create mode 100644 node_modules/nexe/lib/patches/flags.js create mode 100644 node_modules/nexe/lib/patches/gyp.d.ts create mode 100644 node_modules/nexe/lib/patches/gyp.js create mode 100644 node_modules/nexe/lib/patches/ico.d.ts create mode 100644 node_modules/nexe/lib/patches/ico.js create mode 100644 node_modules/nexe/lib/patches/index.d.ts create mode 100644 node_modules/nexe/lib/patches/index.js create mode 100644 node_modules/nexe/lib/patches/node-rc.d.ts create mode 100644 node_modules/nexe/lib/patches/node-rc.js create mode 100644 node_modules/nexe/lib/patches/snapshot.d.ts create mode 100644 node_modules/nexe/lib/patches/snapshot.js create mode 100644 node_modules/nexe/lib/patches/third-party-main.d.ts create mode 100644 node_modules/nexe/lib/patches/third-party-main.js (limited to 'node_modules/nexe/lib/patches') diff --git a/node_modules/nexe/lib/patches/boot-nexe.d.ts b/node_modules/nexe/lib/patches/boot-nexe.d.ts new file mode 100644 index 0000000..fae3f7a --- /dev/null +++ b/node_modules/nexe/lib/patches/boot-nexe.d.ts @@ -0,0 +1,5 @@ +/// +declare const fs: any, fd: any, stat: any, tailSize: number, tailWindow: Buffer; +declare const footerPosition: number; +declare const footer: Buffer, contentSize: number, resourceSize: number, contentStart: number, resourceStart: number; +declare const contentBuffer: Buffer, Module: any; diff --git a/node_modules/nexe/lib/patches/boot-nexe.js b/node_modules/nexe/lib/patches/boot-nexe.js new file mode 100644 index 0000000..d5aa8db --- /dev/null +++ b/node_modules/nexe/lib/patches/boot-nexe.js @@ -0,0 +1,38 @@ +"use strict"; +const fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), tailSize = Math.min(stat.size, 16000), tailWindow = Buffer.from(Array(tailSize)); +fs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize); +const footerPosition = tailWindow.indexOf(''); +if (footerPosition == -1) { + throw 'Invalid Nexe binary'; +} +const footer = tailWindow.slice(footerPosition, footerPosition + 32), contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize; +Object.defineProperty(process, '__nexe', (function () { + let nexeHeader = null; + return { + get: function () { + return nexeHeader; + }, + set: function (value) { + if (nexeHeader) { + throw new Error('This property is readonly'); + } + nexeHeader = Object.assign({}, value, { + blobPath: process.execPath, + layout: { + stat, + contentSize, + contentStart, + resourceSize, + resourceStart, + }, + }); + Object.freeze(nexeHeader); + }, + enumerable: false, + configurable: false, + }; +})()); +const contentBuffer = Buffer.from(Array(contentSize)), Module = require('module'); +fs.readSync(fd, contentBuffer, 0, contentSize, contentStart); +fs.closeSync(fd); +new Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath); diff --git a/node_modules/nexe/lib/patches/build-fixes.d.ts b/node_modules/nexe/lib/patches/build-fixes.d.ts new file mode 100644 index 0000000..bbed32e --- /dev/null +++ b/node_modules/nexe/lib/patches/build-fixes.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function buildFixes(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/build-fixes.js b/node_modules/nexe/lib/patches/build-fixes.js new file mode 100644 index 0000000..1bfb565 --- /dev/null +++ b/node_modules/nexe/lib/patches/build-fixes.js @@ -0,0 +1,22 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function buildFixes(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + if (!compiler.target.version.startsWith('8.2')) { + return next(); + } + const file = yield compiler.readFileAsync('./tools/msvs/find_python.cmd'); + yield compiler.replaceInFileAsync('./tools/msvs/find_python.cmd', '%p%python.exe -V 2>&1', '"%p%python.exe" -V 2>&1'); + return next(); + }); +} +exports.default = buildFixes; diff --git a/node_modules/nexe/lib/patches/disable-node-cli.d.ts b/node_modules/nexe/lib/patches/disable-node-cli.d.ts new file mode 100644 index 0000000..7425253 --- /dev/null +++ b/node_modules/nexe/lib/patches/disable-node-cli.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function disableNodeCli(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/disable-node-cli.js b/node_modules/nexe/lib/patches/disable-node-cli.js new file mode 100644 index 0000000..569b400 --- /dev/null +++ b/node_modules/nexe/lib/patches/disable-node-cli.js @@ -0,0 +1,45 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const util_1 = require("../util"); +function disableNodeCli(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + if (compiler.options.enableNodeCli) { + return next(); + } + if (util_1.semverGt(compiler.target.version, '11.6.0')) { + yield compiler.replaceInFileAsync('src/node.cc', /(? 1/g, (match) => { + if (matches++) { + return 'false'; + } + return match; + }); + } + else { + const nodeccMarker = 'argv[index][0] =='; + yield compiler.replaceInFileAsync('src/node.cc', `${nodeccMarker} '-'`, + // allow NODE_OPTIONS, introduced in 8.0 + util_1.semverGt(compiler.target.version, '7.99') + ? `(${nodeccMarker} (is_env ? '-' : ']'))` + : `(${nodeccMarker} ']')`); + } + return next(); + }); +} +exports.default = disableNodeCli; diff --git a/node_modules/nexe/lib/patches/flags.d.ts b/node_modules/nexe/lib/patches/flags.d.ts new file mode 100644 index 0000000..85f487c --- /dev/null +++ b/node_modules/nexe/lib/patches/flags.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function flags(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/flags.js b/node_modules/nexe/lib/patches/flags.js new file mode 100644 index 0000000..1821081 --- /dev/null +++ b/node_modules/nexe/lib/patches/flags.js @@ -0,0 +1,22 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function flags(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const nodeflags = compiler.options.flags; + if (!nodeflags.length) { + return next(); + } + yield compiler.replaceInFileAsync('node.gyp', "'node_v8_options%': ''", `'node_v8_options%': '${nodeflags.join(' ')}'`); + return next(); + }); +} +exports.default = flags; diff --git a/node_modules/nexe/lib/patches/gyp.d.ts b/node_modules/nexe/lib/patches/gyp.d.ts new file mode 100644 index 0000000..38d7108 --- /dev/null +++ b/node_modules/nexe/lib/patches/gyp.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function nodeGyp({ files, replaceInFileAsync }: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/gyp.js b/node_modules/nexe/lib/patches/gyp.js new file mode 100644 index 0000000..5e51a0b --- /dev/null +++ b/node_modules/nexe/lib/patches/gyp.js @@ -0,0 +1,25 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function nodeGyp({ files, replaceInFileAsync }, next) { + return __awaiter(this, void 0, void 0, function* () { + yield next(); + const nodeGypMarker = "'lib/fs.js',"; + yield replaceInFileAsync('node.gyp', nodeGypMarker, ` + ${nodeGypMarker} + ${files + .filter((x) => x.filename.startsWith('lib')) + .map((x) => `'${x.filename}'`) + .toString()}, + `.trim()); + }); +} +exports.default = nodeGyp; diff --git a/node_modules/nexe/lib/patches/ico.d.ts b/node_modules/nexe/lib/patches/ico.d.ts new file mode 100644 index 0000000..316d393 --- /dev/null +++ b/node_modules/nexe/lib/patches/ico.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function ico(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/ico.js b/node_modules/nexe/lib/patches/ico.js new file mode 100644 index 0000000..01d09b2 --- /dev/null +++ b/node_modules/nexe/lib/patches/ico.js @@ -0,0 +1,24 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_1 = require("path"); +const util_1 = require("../util"); +function ico(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const iconFile = compiler.options.ico; + if (!iconFile) { + return next(); + } + yield compiler.setFileContentsAsync('src/res/node.ico', yield util_1.readFileAsync(path_1.normalize(iconFile))); + return next(); + }); +} +exports.default = ico; diff --git a/node_modules/nexe/lib/patches/index.d.ts b/node_modules/nexe/lib/patches/index.d.ts new file mode 100644 index 0000000..b48c12d --- /dev/null +++ b/node_modules/nexe/lib/patches/index.d.ts @@ -0,0 +1,3 @@ +import gyp from './gyp'; +declare const patches: (typeof gyp)[]; +export default patches; diff --git a/node_modules/nexe/lib/patches/index.js b/node_modules/nexe/lib/patches/index.js new file mode 100644 index 0000000..6c75700 --- /dev/null +++ b/node_modules/nexe/lib/patches/index.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gyp_1 = require("./gyp"); +const third_party_main_1 = require("./third-party-main"); +const build_fixes_1 = require("./build-fixes"); +const disable_node_cli_1 = require("./disable-node-cli"); +const flags_1 = require("./flags"); +const ico_1 = require("./ico"); +const node_rc_1 = require("./node-rc"); +const snapshot_1 = require("./snapshot"); +const patches = [gyp_1.default, third_party_main_1.default, build_fixes_1.default, disable_node_cli_1.default, flags_1.default, ico_1.default, node_rc_1.default, snapshot_1.default]; +exports.default = patches; diff --git a/node_modules/nexe/lib/patches/node-rc.d.ts b/node_modules/nexe/lib/patches/node-rc.d.ts new file mode 100644 index 0000000..5be1bb6 --- /dev/null +++ b/node_modules/nexe/lib/patches/node-rc.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function nodeRc(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/node-rc.js b/node_modules/nexe/lib/patches/node-rc.js new file mode 100644 index 0000000..d689f84 --- /dev/null +++ b/node_modules/nexe/lib/patches/node-rc.js @@ -0,0 +1,37 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function nodeRc(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const options = compiler.options.rc; + if (!options) { + return next(); + } + const file = yield compiler.readFileAsync('src/res/node.rc'); + Object.keys(options).forEach((key) => { + let value = options[key]; + const isVar = /^[A-Z_]+$/.test(value); + value = isVar ? value : `"${value}"`; + file.contents = file.contents + .toString() + .replace(new RegExp(`VALUE "${key}",.*`), `VALUE "${key}", ${value}`); + }); + ['PRODUCTVERSION', 'FILEVERSION'].forEach((x) => { + if (options[x]) { + file.contents = file.contents + .toString() + .replace(new RegExp(x + ' .*$', 'm'), `${x} ${options[x]}`); + } + }); + return next(); + }); +} +exports.default = nodeRc; diff --git a/node_modules/nexe/lib/patches/snapshot.d.ts b/node_modules/nexe/lib/patches/snapshot.d.ts new file mode 100644 index 0000000..a94e274 --- /dev/null +++ b/node_modules/nexe/lib/patches/snapshot.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function (compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/snapshot.js b/node_modules/nexe/lib/patches/snapshot.js new file mode 100644 index 0000000..5435b9b --- /dev/null +++ b/node_modules/nexe/lib/patches/snapshot.js @@ -0,0 +1,25 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_1 = require("path"); +const util_1 = require("../util"); +function default_1(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { snapshot, warmup, cwd } = compiler.options; + if (!snapshot) { + return next(); + } + const variablePrefix = util_1.semverGt(compiler.target.version, '11.0.0') ? 'v8_' : ''; + yield compiler.replaceInFileAsync(compiler.configureScript, 'def configure_v8(o):', `def configure_v8(o):\n o['variables']['${variablePrefix}embed_script'] = r'${path_1.resolve(cwd, snapshot)}'\n o['variables']['${variablePrefix}warmup_script'] = r'${path_1.resolve(cwd, warmup || snapshot)}'`); + return next(); + }); +} +exports.default = default_1; diff --git a/node_modules/nexe/lib/patches/third-party-main.d.ts b/node_modules/nexe/lib/patches/third-party-main.d.ts new file mode 100644 index 0000000..606a50e --- /dev/null +++ b/node_modules/nexe/lib/patches/third-party-main.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function main(compiler: NexeCompiler, next: () => Promise): Promise; diff --git a/node_modules/nexe/lib/patches/third-party-main.js b/node_modules/nexe/lib/patches/third-party-main.js new file mode 100644 index 0000000..3a098c0 --- /dev/null +++ b/node_modules/nexe/lib/patches/third-party-main.js @@ -0,0 +1,92 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const cherow_1 = require("cherow"); +const util_1 = require("../util"); +function walkSome(node, visit) { + if (!node || typeof node.type !== 'string' || node._visited) { + return false; + } + visit(node); + node._visited = true; + for (let childNode in node) { + const child = node[childNode]; + if (Array.isArray(child)) { + for (let i = 0; i < child.length; i++) { + if (walkSome(child[i], visit)) { + return true; + } + } + } + else if (walkSome(child, visit)) { + return true; + } + } + return false; +} +function main(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + let bootFile = 'lib/internal/bootstrap_node.js'; + const { version } = compiler.target; + if (version.startsWith('4.')) { + bootFile = 'src/node.js'; + } + else if (util_1.semverGt(version, '11.99')) { + bootFile = 'lib/internal/bootstrap/pre_execution.js'; + } + else if (util_1.semverGt(version, '9.10.1')) { + bootFile = 'lib/internal/bootstrap/node.js'; + } + const file = yield compiler.readFileAsync(bootFile), ast = cherow_1.parse(file.contents.toString(), { + loc: true, + tolerant: true, + next: true, + globalReturn: true, + node: true, + skipShebang: true, + }), location = { start: { line: 0 } }; + walkSome(ast, (node) => { + if (!location.start.line && node.type === 'BlockStatement') { + //Find the first block statement and mark the location + Object.assign(location, node.loc); + return true; + } + }); + const fileLines = file.contents.toString().split('\n'); + fileLines.splice(location.start.line, 0, "if (true) {\n const __nexe_patches = (process.nexe = { patches: {} }).patches\n const slice = [].slice\n const __nexe_noop_patch = function (original) {\n const args = slice.call(arguments, 1)\n return original.apply(this, args)\n }\n const __nexe_patch = function (obj, method, patch) {\n const original = obj[method]\n if (!original) return\n __nexe_patches[method] = patch\n obj[method] = function() {\n const args = [original].concat(slice.call(arguments))\n return __nexe_patches[method].apply(this, args)\n }\n }\n __nexe_patch((process).binding('fs'), 'internalModuleReadFile', __nexe_noop_patch)\n __nexe_patch((process).binding('fs'), 'internalModuleReadJSON', __nexe_noop_patch)\n __nexe_patch((process).binding('fs'), 'internalModuleStat', __nexe_noop_patch)\n}\n" + + '\n' + + (util_1.semverGt(version, '11.99') ? 'expandArgv1 = false;\n' : '')); + file.contents = fileLines.join('\n'); + if (util_1.semverGt(version, '11.99')) { + if (util_1.semverGt(version, '12.17.99')) { + yield compiler.replaceInFileAsync(bootFile, 'initializeFrozenIntrinsics();', 'initializeFrozenIntrinsics();\n' + util_1.wrap("\"use strict\";\nconst fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), tailSize = Math.min(stat.size, 16000), tailWindow = Buffer.from(Array(tailSize));\nfs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize);\nconst footerPosition = tailWindow.indexOf('');\nif (footerPosition == -1) {\n throw 'Invalid Nexe binary';\n}\nconst footer = tailWindow.slice(footerPosition, footerPosition + 32), contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize;\nObject.defineProperty(process, '__nexe', (function () {\n let nexeHeader = null;\n return {\n get: function () {\n return nexeHeader;\n },\n set: function (value) {\n if (nexeHeader) {\n throw new Error('This property is readonly');\n }\n nexeHeader = Object.assign({}, value, {\n blobPath: process.execPath,\n layout: {\n stat,\n contentSize,\n contentStart,\n resourceSize,\n resourceStart,\n },\n });\n Object.freeze(nexeHeader);\n },\n enumerable: false,\n configurable: false,\n };\n})());\nconst contentBuffer = Buffer.from(Array(contentSize)), Module = require('module');\nfs.readSync(fd, contentBuffer, 0, contentSize, contentStart);\nfs.closeSync(fd);\nnew Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath);\n")); + } + else { + yield compiler.replaceInFileAsync(bootFile, 'initializePolicy();', 'initializePolicy();\n' + util_1.wrap("\"use strict\";\nconst fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), tailSize = Math.min(stat.size, 16000), tailWindow = Buffer.from(Array(tailSize));\nfs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize);\nconst footerPosition = tailWindow.indexOf('');\nif (footerPosition == -1) {\n throw 'Invalid Nexe binary';\n}\nconst footer = tailWindow.slice(footerPosition, footerPosition + 32), contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize;\nObject.defineProperty(process, '__nexe', (function () {\n let nexeHeader = null;\n return {\n get: function () {\n return nexeHeader;\n },\n set: function (value) {\n if (nexeHeader) {\n throw new Error('This property is readonly');\n }\n nexeHeader = Object.assign({}, value, {\n blobPath: process.execPath,\n layout: {\n stat,\n contentSize,\n contentStart,\n resourceSize,\n resourceStart,\n },\n });\n Object.freeze(nexeHeader);\n },\n enumerable: false,\n configurable: false,\n };\n})());\nconst contentBuffer = Buffer.from(Array(contentSize)), Module = require('module');\nfs.readSync(fd, contentBuffer, 0, contentSize, contentStart);\nfs.closeSync(fd);\nnew Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath);\n")); + } + yield compiler.replaceInFileAsync(bootFile, 'assert(!CJSLoader.hasLoadedAnyUserCJSModule)', '/*assert(!CJSLoader.hasLoadedAnyUserCJSModule)*/'); + const { contents: nodeccContents } = yield compiler.readFileAsync('src/node.cc'); + if (nodeccContents.includes('if (env->worker_context() != nullptr) {')) { + yield compiler.replaceInFileAsync('src/node.cc', 'if (env->worker_context() != nullptr) {', 'if (env->worker_context() == nullptr) {\n' + + ' return StartExecution(env, "internal/main/run_main_module"); } else {\n'); + } + else { + yield compiler.replaceInFileAsync('src/node.cc', 'MaybeLocal StartMainThreadExecution(Environment* env) {', 'MaybeLocal StartMainThreadExecution(Environment* env) {\n' + + ' return StartExecution(env, "internal/main/run_main_module");\n'); + } + } + else { + yield compiler.setFileContentsAsync('lib/_third_party_main.js', "\"use strict\";\nconst fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), tailSize = Math.min(stat.size, 16000), tailWindow = Buffer.from(Array(tailSize));\nfs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize);\nconst footerPosition = tailWindow.indexOf('');\nif (footerPosition == -1) {\n throw 'Invalid Nexe binary';\n}\nconst footer = tailWindow.slice(footerPosition, footerPosition + 32), contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize;\nObject.defineProperty(process, '__nexe', (function () {\n let nexeHeader = null;\n return {\n get: function () {\n return nexeHeader;\n },\n set: function (value) {\n if (nexeHeader) {\n throw new Error('This property is readonly');\n }\n nexeHeader = Object.assign({}, value, {\n blobPath: process.execPath,\n layout: {\n stat,\n contentSize,\n contentStart,\n resourceSize,\n resourceStart,\n },\n });\n Object.freeze(nexeHeader);\n },\n enumerable: false,\n configurable: false,\n };\n})());\nconst contentBuffer = Buffer.from(Array(contentSize)), Module = require('module');\nfs.readSync(fd, contentBuffer, 0, contentSize, contentStart);\nfs.closeSync(fd);\nnew Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath);\n"); + } + return next(); + }); +} +exports.default = main; -- cgit