@depup/nexe 5.0.0-beta.4-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +40 -0
- package/changes.json +46 -0
- package/index.js +32 -0
- package/lib/compiler.d.ts +105 -0
- package/lib/compiler.js +289 -0
- package/lib/fs/README.md +40 -0
- package/lib/fs/SnapshotZipFS.d.ts +228 -0
- package/lib/fs/SnapshotZipFS.js +283 -0
- package/lib/fs/bootstrap.js +20 -0
- package/lib/fs/bundle.d.ts +17 -0
- package/lib/fs/bundle.js +51 -0
- package/lib/fs/package.json +15 -0
- package/lib/fs/patch.bundle.js +7823 -0
- package/lib/fs/patch.bundle.js.map +1 -0
- package/lib/fs/patch.d.ts +12 -0
- package/lib/fs/patch.js +122 -0
- package/lib/logger.d.ts +18 -0
- package/lib/logger.js +60 -0
- package/lib/nexe.d.ts +5 -0
- package/lib/nexe.js +53 -0
- package/lib/options.d.ts +56 -0
- package/lib/options.js +244 -0
- package/lib/patches/boot-nexe.d.ts +5 -0
- package/lib/patches/boot-nexe.js +38 -0
- package/lib/patches/build-fixes.d.ts +2 -0
- package/lib/patches/build-fixes.js +22 -0
- package/lib/patches/disable-node-cli.d.ts +2 -0
- package/lib/patches/disable-node-cli.js +48 -0
- package/lib/patches/flags.d.ts +2 -0
- package/lib/patches/flags.js +22 -0
- package/lib/patches/gyp.d.ts +2 -0
- package/lib/patches/gyp.js +25 -0
- package/lib/patches/ico.d.ts +2 -0
- package/lib/patches/ico.js +24 -0
- package/lib/patches/index.d.ts +3 -0
- package/lib/patches/index.js +15 -0
- package/lib/patches/node-rc.d.ts +2 -0
- package/lib/patches/node-rc.js +37 -0
- package/lib/patches/snapshot.d.ts +2 -0
- package/lib/patches/snapshot.js +25 -0
- package/lib/patches/third-party-main.d.ts +2 -0
- package/lib/patches/third-party-main.js +99 -0
- package/lib/releases.d.ts +15 -0
- package/lib/releases.js +57 -0
- package/lib/steps/artifacts.d.ts +11 -0
- package/lib/steps/artifacts.js +89 -0
- package/lib/steps/bundle.d.ts +2 -0
- package/lib/steps/bundle.js +104 -0
- package/lib/steps/clean.d.ts +2 -0
- package/lib/steps/clean.js +30 -0
- package/lib/steps/cli.d.ts +12 -0
- package/lib/steps/cli.js +55 -0
- package/lib/steps/download.d.ts +7 -0
- package/lib/steps/download.js +76 -0
- package/lib/steps/resource.d.ts +2 -0
- package/lib/steps/resource.js +38 -0
- package/lib/steps/shim.d.ts +2 -0
- package/lib/steps/shim.js +45 -0
- package/lib/target.d.ts +11 -0
- package/lib/target.js +82 -0
- package/lib/util.d.ts +29 -0
- package/lib/util.js +104 -0
- package/package.json +148 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
function disableNodeCli(compiler, next) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
if (compiler.options.enableNodeCli) {
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
if ((0, util_1.semverGt)(compiler.target.version, '18.99')) {
|
|
19
|
+
yield compiler.replaceInFileAsync('src/node.cc', /(?<!static ExitCode )ProcessGlobalArgsInternal\(argv[^;]*;/gm, 'ExitCode::kNoFailure;/*$&*/');
|
|
20
|
+
}
|
|
21
|
+
else if ((0, util_1.semverGt)(compiler.target.version, '11.6.0')) {
|
|
22
|
+
yield compiler.replaceInFileAsync('src/node.cc', /(?<!int )ProcessGlobalArgs\(argv[^;]*;/gm, '0;/*$&*/');
|
|
23
|
+
}
|
|
24
|
+
else if ((0, util_1.semverGt)(compiler.target.version, '10.9')) {
|
|
25
|
+
yield compiler.replaceInFileAsync('src/node.cc', /(?<!void )ProcessArgv\(argv/g, '//$&');
|
|
26
|
+
}
|
|
27
|
+
else if ((0, util_1.semverGt)(compiler.target.version, '9.999')) {
|
|
28
|
+
yield compiler.replaceInFileAsync('src/node.cc', 'int i = 1; i < v8_argc; i++', 'int i = v8_argc; i < v8_argc; i++');
|
|
29
|
+
let matches = 0;
|
|
30
|
+
yield compiler.replaceInFileAsync('src/node.cc', /v8_argc > 1/g, (match) => {
|
|
31
|
+
if (matches++) {
|
|
32
|
+
return 'false';
|
|
33
|
+
}
|
|
34
|
+
return match;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const nodeccMarker = 'argv[index][0] ==';
|
|
39
|
+
yield compiler.replaceInFileAsync('src/node.cc', `${nodeccMarker} '-'`,
|
|
40
|
+
// allow NODE_OPTIONS, introduced in 8.0
|
|
41
|
+
(0, util_1.semverGt)(compiler.target.version, '7.99')
|
|
42
|
+
? `(${nodeccMarker} (is_env ? '-' : ']'))`
|
|
43
|
+
: `(${nodeccMarker} ']')`);
|
|
44
|
+
}
|
|
45
|
+
return next();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
exports.default = disableNodeCli;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
function flags(compiler, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const nodeflags = compiler.options.flags;
|
|
15
|
+
if (!nodeflags.length) {
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
yield compiler.replaceInFileAsync('node.gyp', "'node_v8_options%': ''", `'node_v8_options%': '${nodeflags.join(' ')}'`);
|
|
19
|
+
return next();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.default = flags;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
function nodeGyp({ files, replaceInFileAsync }, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
yield next();
|
|
15
|
+
const nodeGypMarker = "'lib/fs.js',";
|
|
16
|
+
yield replaceInFileAsync('node.gyp', nodeGypMarker, `
|
|
17
|
+
${nodeGypMarker}
|
|
18
|
+
${files
|
|
19
|
+
.filter((x) => x.filename.startsWith('lib'))
|
|
20
|
+
.map((x) => `'${x.filename}'`)
|
|
21
|
+
.toString()},
|
|
22
|
+
`.trim());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.default = nodeGyp;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
function ico(compiler, next) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const iconFile = compiler.options.ico;
|
|
17
|
+
if (!iconFile) {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
yield compiler.setFileContentsAsync('src/res/node.ico', yield (0, util_1.readFileAsync)((0, path_1.normalize)(iconFile)));
|
|
21
|
+
return next();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.default = ico;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const gyp_1 = __importDefault(require("./gyp"));
|
|
7
|
+
const third_party_main_1 = __importDefault(require("./third-party-main"));
|
|
8
|
+
const build_fixes_1 = __importDefault(require("./build-fixes"));
|
|
9
|
+
const disable_node_cli_1 = __importDefault(require("./disable-node-cli"));
|
|
10
|
+
const flags_1 = __importDefault(require("./flags"));
|
|
11
|
+
const ico_1 = __importDefault(require("./ico"));
|
|
12
|
+
const node_rc_1 = __importDefault(require("./node-rc"));
|
|
13
|
+
const snapshot_1 = __importDefault(require("./snapshot"));
|
|
14
|
+
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];
|
|
15
|
+
exports.default = patches;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
function nodeRc(compiler, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const options = compiler.options.rc;
|
|
15
|
+
if (!options) {
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
const file = yield compiler.readFileAsync('src/res/node.rc');
|
|
19
|
+
Object.keys(options).forEach((key) => {
|
|
20
|
+
let value = options[key];
|
|
21
|
+
const isVar = /^[A-Z_]+$/.test(value);
|
|
22
|
+
value = isVar ? value : `"${value}"`;
|
|
23
|
+
file.contents = file.contents
|
|
24
|
+
.toString()
|
|
25
|
+
.replace(new RegExp(`VALUE "${key}",.*`), `VALUE "${key}", ${value}`);
|
|
26
|
+
});
|
|
27
|
+
['PRODUCTVERSION', 'FILEVERSION'].forEach((x) => {
|
|
28
|
+
if (options[x]) {
|
|
29
|
+
file.contents = file.contents
|
|
30
|
+
.toString()
|
|
31
|
+
.replace(new RegExp(x + ' .*$', 'm'), `${x} ${options[x]}`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return next();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.default = nodeRc;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
function default_1(compiler, next) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { snapshot, warmup, cwd } = compiler.options;
|
|
17
|
+
if (!snapshot) {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
const variablePrefix = (0, util_1.semverGt)(compiler.target.version, '11.0.0') ? 'v8_' : '';
|
|
21
|
+
yield compiler.replaceInFileAsync(compiler.configureScript, 'def configure_v8(o):', `def configure_v8(o):\n o['variables']['${variablePrefix}embed_script'] = r'${(0, path_1.resolve)(cwd, snapshot)}'\n o['variables']['${variablePrefix}warmup_script'] = r'${(0, path_1.resolve)(cwd, warmup || snapshot)}'`);
|
|
22
|
+
return next();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const meriyah_1 = require("meriyah");
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
function walkSome(node, visit) {
|
|
15
|
+
if (!node || typeof node.type !== 'string' || node._visited) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
visit(node);
|
|
19
|
+
node._visited = true;
|
|
20
|
+
for (let childNode in node) {
|
|
21
|
+
const child = node[childNode];
|
|
22
|
+
if (Array.isArray(child)) {
|
|
23
|
+
for (let i = 0; i < child.length; i++) {
|
|
24
|
+
if (walkSome(child[i], visit)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (walkSome(child, visit)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function main(compiler, next) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
let bootFile = 'lib/internal/bootstrap_node.js';
|
|
38
|
+
const { version } = compiler.target;
|
|
39
|
+
if (version.startsWith('4.')) {
|
|
40
|
+
bootFile = 'src/node.js';
|
|
41
|
+
}
|
|
42
|
+
else if ((0, util_1.semverGt)(version, '18.11.99')) {
|
|
43
|
+
bootFile = 'lib/internal/process/pre_execution.js';
|
|
44
|
+
}
|
|
45
|
+
else if ((0, util_1.semverGt)(version, '11.99')) {
|
|
46
|
+
bootFile = 'lib/internal/bootstrap/pre_execution.js';
|
|
47
|
+
}
|
|
48
|
+
else if ((0, util_1.semverGt)(version, '9.10.1')) {
|
|
49
|
+
bootFile = 'lib/internal/bootstrap/node.js';
|
|
50
|
+
}
|
|
51
|
+
const file = yield compiler.readFileAsync(bootFile), ast = (0, meriyah_1.parse)(file.contents.toString(), {
|
|
52
|
+
next: true,
|
|
53
|
+
globalReturn: true,
|
|
54
|
+
loc: true,
|
|
55
|
+
specDeviation: true,
|
|
56
|
+
}), location = { start: { line: 0 } };
|
|
57
|
+
walkSome(ast, (node) => {
|
|
58
|
+
if (!location.start.line && node.type === 'BlockStatement') {
|
|
59
|
+
//Find the first block statement and mark the location
|
|
60
|
+
Object.assign(location, node.loc);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const fileLines = file.contents.toString().split('\n');
|
|
65
|
+
if ((0, util_1.semverGt)(version, '19.99')) {
|
|
66
|
+
yield compiler.replaceInFileAsync('lib/internal/modules/cjs/loader.js', "'use strict';", "'use strict';\n" + "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');
|
|
67
|
+
fileLines.splice(location.start.line, 0, 'expandArgv1 = false;');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
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" +
|
|
71
|
+
'\n' +
|
|
72
|
+
((0, util_1.semverGt)(version, '11.99') ? 'expandArgv1 = false;\n' : ''));
|
|
73
|
+
}
|
|
74
|
+
file.contents = fileLines.join('\n');
|
|
75
|
+
if ((0, util_1.semverGt)(version, '11.99')) {
|
|
76
|
+
if ((0, util_1.semverGt)(version, '12.17.99')) {
|
|
77
|
+
yield compiler.replaceInFileAsync(bootFile, 'initializeFrozenIntrinsics();', 'initializeFrozenIntrinsics();\n' + (0, 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('<nexe~~sentinel>');\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"));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
yield compiler.replaceInFileAsync(bootFile, 'initializePolicy();', 'initializePolicy();\n' + (0, 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('<nexe~~sentinel>');\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"));
|
|
81
|
+
}
|
|
82
|
+
yield compiler.replaceInFileAsync(bootFile, 'assert(!CJSLoader.hasLoadedAnyUserCJSModule)', '/*assert(!CJSLoader.hasLoadedAnyUserCJSModule)*/');
|
|
83
|
+
const { contents: nodeccContents } = yield compiler.readFileAsync('src/node.cc');
|
|
84
|
+
if (nodeccContents.includes('if (env->worker_context() != nullptr) {')) {
|
|
85
|
+
yield compiler.replaceInFileAsync('src/node.cc', 'if (env->worker_context() != nullptr) {', 'if (env->worker_context() == nullptr) {\n' +
|
|
86
|
+
' return StartExecution(env, "internal/main/run_main_module"); } else {\n');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
yield compiler.replaceInFileAsync('src/node.cc', 'MaybeLocal<Value> StartMainThreadExecution(Environment* env) {', 'MaybeLocal<Value> StartMainThreadExecution(Environment* env) {\n' +
|
|
90
|
+
' return StartExecution(env, "internal/main/run_main_module");\n');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
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('<nexe~~sentinel>');\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");
|
|
95
|
+
}
|
|
96
|
+
return next();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.default = main;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NexeTarget } from './target';
|
|
2
|
+
export { NexeTarget };
|
|
3
|
+
export interface GitAsset {
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
browser_download_url: string;
|
|
7
|
+
}
|
|
8
|
+
export interface GitRelease {
|
|
9
|
+
tag_name: string;
|
|
10
|
+
assets_url: string;
|
|
11
|
+
upload_url: string;
|
|
12
|
+
assets: GitAsset[];
|
|
13
|
+
}
|
|
14
|
+
export declare function getLatestGitRelease(options?: any): Promise<GitRelease>;
|
|
15
|
+
export declare function getUnBuiltReleases(options?: any): Promise<NexeTarget[]>;
|
package/lib/releases.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUnBuiltReleases = exports.getLatestGitRelease = void 0;
|
|
13
|
+
const got = require("got");
|
|
14
|
+
const target_1 = require("./target");
|
|
15
|
+
const versionsToSkip = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 22];
|
|
16
|
+
function getJson(url, options) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return JSON.parse((yield got(url, options)).body);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function isBuildableVersion(version) {
|
|
22
|
+
if (version === '12.11.0') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return !versionsToSkip.includes(Number(version.split('.')[0]));
|
|
26
|
+
}
|
|
27
|
+
function getLatestGitRelease(options) {
|
|
28
|
+
return getJson('https://api.github.com/repos/nexe/nexe/releases/latest', options);
|
|
29
|
+
}
|
|
30
|
+
exports.getLatestGitRelease = getLatestGitRelease;
|
|
31
|
+
function getUnBuiltReleases(options) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const nodeReleases = yield getJson('https://nodejs.org/download/release/index.json');
|
|
34
|
+
const existingVersions = (yield getLatestGitRelease(options)).assets.map((x) => (0, target_1.getTarget)(x.name));
|
|
35
|
+
const versionMap = {};
|
|
36
|
+
return nodeReleases
|
|
37
|
+
.reduce((versions, { version }) => {
|
|
38
|
+
version = version.replace('v', '').trim();
|
|
39
|
+
if (!isBuildableVersion(version) || versionMap[version]) {
|
|
40
|
+
return versions;
|
|
41
|
+
}
|
|
42
|
+
versionMap[version] = true;
|
|
43
|
+
target_1.platforms.forEach((platform) => {
|
|
44
|
+
target_1.architectures.forEach((arch) => {
|
|
45
|
+
if (arch === 'x86' && platform === 'mac')
|
|
46
|
+
return;
|
|
47
|
+
if (arch.includes('arm'))
|
|
48
|
+
return;
|
|
49
|
+
versions.push((0, target_1.getTarget)({ platform, arch, version }));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
return versions;
|
|
53
|
+
}, [])
|
|
54
|
+
.filter((x) => !existingVersions.some((t) => (0, target_1.targetsEqual)(t, x)));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.getUnBuiltReleases = getUnBuiltReleases;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NexeCompiler } from '../compiler';
|
|
2
|
+
/**
|
|
3
|
+
* The artifacts step is where source patches are committed, or written as "artifacts"
|
|
4
|
+
* Steps:
|
|
5
|
+
* - A temporary directory is created in the downloaded source
|
|
6
|
+
* - On start, any files in that directory are restored into the source tree
|
|
7
|
+
* - After the patch functions have run, the temporary directory is emptied
|
|
8
|
+
* - Original versions of sources to be patched are written to the temporary directory
|
|
9
|
+
* - Finally, The patched files are written into source.
|
|
10
|
+
*/
|
|
11
|
+
export default function artifacts(compiler: NexeCompiler, next: () => Promise<void>): Promise<void[]>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const path_1 = require("path");
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const util_1 = require("util");
|
|
38
|
+
const util_2 = require("../util");
|
|
39
|
+
const mkdirpAsync = require("mkdirp");
|
|
40
|
+
const unlinkAsync = (0, util_1.promisify)(fs.unlink), readdirAsync = (0, util_1.promisify)(fs.readdir);
|
|
41
|
+
function readDirAsync(dir) {
|
|
42
|
+
return readdirAsync(dir).then((paths) => {
|
|
43
|
+
return Promise.all(paths.map((file) => {
|
|
44
|
+
const path = (0, path_1.join)(dir, file);
|
|
45
|
+
return (0, util_2.isDirectoryAsync)(path).then((x) => (x ? readDirAsync(path) : path));
|
|
46
|
+
})).then((result) => {
|
|
47
|
+
return [].concat(...result);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function maybeReadFileContentsAsync(file) {
|
|
52
|
+
return (0, util_2.readFileAsync)(file, 'utf-8').catch((e) => {
|
|
53
|
+
if (e.code === 'ENOENT') {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
throw e;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The artifacts step is where source patches are committed, or written as "artifacts"
|
|
61
|
+
* Steps:
|
|
62
|
+
* - A temporary directory is created in the downloaded source
|
|
63
|
+
* - On start, any files in that directory are restored into the source tree
|
|
64
|
+
* - After the patch functions have run, the temporary directory is emptied
|
|
65
|
+
* - Original versions of sources to be patched are written to the temporary directory
|
|
66
|
+
* - Finally, The patched files are written into source.
|
|
67
|
+
*/
|
|
68
|
+
function artifacts(compiler, next) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const { src } = compiler;
|
|
71
|
+
const temp = (0, path_1.join)(src, 'nexe');
|
|
72
|
+
yield mkdirpAsync(temp);
|
|
73
|
+
const tmpFiles = yield readDirAsync(temp);
|
|
74
|
+
yield Promise.all(tmpFiles.map((path) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return compiler.writeFileAsync(path.replace(temp, ''), yield (0, util_2.readFileAsync)(path, 'utf-8'));
|
|
76
|
+
})));
|
|
77
|
+
yield next();
|
|
78
|
+
yield Promise.all(tmpFiles.map((x) => unlinkAsync(x)));
|
|
79
|
+
return Promise.all(compiler.files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const sourceFile = (0, path_1.join)(src, file.filename);
|
|
81
|
+
const tempFile = (0, path_1.join)(temp, file.filename);
|
|
82
|
+
const fileContents = yield maybeReadFileContentsAsync(sourceFile);
|
|
83
|
+
yield mkdirpAsync((0, path_1.dirname)(tempFile));
|
|
84
|
+
yield (0, util_2.writeFileAsync)(tempFile, fileContents);
|
|
85
|
+
yield compiler.writeFileAsync(file.filename, file.contents);
|
|
86
|
+
})));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.default = artifacts;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const compiler_1 = require("../compiler");
|
|
36
|
+
const path_1 = require("path");
|
|
37
|
+
const resolve_dependencies_1 = __importStar(require("resolve-dependencies"));
|
|
38
|
+
const util_1 = require("../util");
|
|
39
|
+
function getStdIn(stdin) {
|
|
40
|
+
let out = '';
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
stdin
|
|
43
|
+
.setEncoding('utf8')
|
|
44
|
+
.on('readable', () => {
|
|
45
|
+
let current;
|
|
46
|
+
while ((current = stdin.read())) {
|
|
47
|
+
out += current;
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.on('end', () => resolve(out.trim()));
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
if (!out.trim()) {
|
|
53
|
+
resolve(out.trim());
|
|
54
|
+
}
|
|
55
|
+
}, 1000);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function bundle(compiler, next) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { bundle: doBundle, cwd, input: inputPath } = compiler.options;
|
|
61
|
+
let input = inputPath;
|
|
62
|
+
compiler.entrypoint = './' + (0, path_1.relative)(cwd, input);
|
|
63
|
+
if ((0, util_1.semverGt)(compiler.target.version, '11.99')) {
|
|
64
|
+
compiler.startup = '';
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
compiler.startup = ';require("module").runMain();';
|
|
68
|
+
}
|
|
69
|
+
if (!doBundle) {
|
|
70
|
+
yield compiler.addResource((0, path_1.resolve)(cwd, input));
|
|
71
|
+
return next();
|
|
72
|
+
}
|
|
73
|
+
let code = '';
|
|
74
|
+
if (typeof doBundle === 'string') {
|
|
75
|
+
code = yield require(doBundle).createBundle(compiler.options);
|
|
76
|
+
}
|
|
77
|
+
if (input === util_1.STDIN_FLAG && (code = code || (0, util_1.dequote)(yield getStdIn(process.stdin)))) {
|
|
78
|
+
compiler.stdinUsed = true;
|
|
79
|
+
compiler.entrypoint = './__nexe_stdin.js';
|
|
80
|
+
yield compiler.addResource((0, path_1.resolve)(cwd, compiler.entrypoint), code);
|
|
81
|
+
return next();
|
|
82
|
+
}
|
|
83
|
+
if (input === util_1.STDIN_FLAG) {
|
|
84
|
+
const maybeInput = (0, resolve_dependencies_1.resolveSync)(cwd, '.');
|
|
85
|
+
if (!maybeInput || !maybeInput.absPath) {
|
|
86
|
+
throw new compiler_1.NexeError('No valid input detected');
|
|
87
|
+
}
|
|
88
|
+
input = maybeInput.absPath;
|
|
89
|
+
compiler.entrypoint = './' + (0, path_1.relative)(cwd, input);
|
|
90
|
+
}
|
|
91
|
+
const step = compiler.log.step('Resolving dependencies...');
|
|
92
|
+
const { files, warnings } = yield (0, resolve_dependencies_1.default)(input, ...Object.keys(compiler.bundle.list).filter((x) => x.endsWith('.js') || x.endsWith('.mjs')), { cwd, expand: 'variable', loadContent: false });
|
|
93
|
+
if (warnings.filter((x) => x.startsWith('Error parsing file') && !x.includes('node_modules')).length) {
|
|
94
|
+
throw new compiler_1.NexeError('Parsing Error:\n' + warnings.join('\n'));
|
|
95
|
+
}
|
|
96
|
+
//TODO: warnings.forEach((x) => console.log(x))
|
|
97
|
+
yield Promise.all(Object.entries(files).map(([key]) => {
|
|
98
|
+
step.log(`Including dependency: ${key}`);
|
|
99
|
+
return compiler.addResource(key);
|
|
100
|
+
}));
|
|
101
|
+
return next();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.default = bundle;
|