@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.
Files changed (64) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +40 -0
  3. package/changes.json +46 -0
  4. package/index.js +32 -0
  5. package/lib/compiler.d.ts +105 -0
  6. package/lib/compiler.js +289 -0
  7. package/lib/fs/README.md +40 -0
  8. package/lib/fs/SnapshotZipFS.d.ts +228 -0
  9. package/lib/fs/SnapshotZipFS.js +283 -0
  10. package/lib/fs/bootstrap.js +20 -0
  11. package/lib/fs/bundle.d.ts +17 -0
  12. package/lib/fs/bundle.js +51 -0
  13. package/lib/fs/package.json +15 -0
  14. package/lib/fs/patch.bundle.js +7823 -0
  15. package/lib/fs/patch.bundle.js.map +1 -0
  16. package/lib/fs/patch.d.ts +12 -0
  17. package/lib/fs/patch.js +122 -0
  18. package/lib/logger.d.ts +18 -0
  19. package/lib/logger.js +60 -0
  20. package/lib/nexe.d.ts +5 -0
  21. package/lib/nexe.js +53 -0
  22. package/lib/options.d.ts +56 -0
  23. package/lib/options.js +244 -0
  24. package/lib/patches/boot-nexe.d.ts +5 -0
  25. package/lib/patches/boot-nexe.js +38 -0
  26. package/lib/patches/build-fixes.d.ts +2 -0
  27. package/lib/patches/build-fixes.js +22 -0
  28. package/lib/patches/disable-node-cli.d.ts +2 -0
  29. package/lib/patches/disable-node-cli.js +48 -0
  30. package/lib/patches/flags.d.ts +2 -0
  31. package/lib/patches/flags.js +22 -0
  32. package/lib/patches/gyp.d.ts +2 -0
  33. package/lib/patches/gyp.js +25 -0
  34. package/lib/patches/ico.d.ts +2 -0
  35. package/lib/patches/ico.js +24 -0
  36. package/lib/patches/index.d.ts +3 -0
  37. package/lib/patches/index.js +15 -0
  38. package/lib/patches/node-rc.d.ts +2 -0
  39. package/lib/patches/node-rc.js +37 -0
  40. package/lib/patches/snapshot.d.ts +2 -0
  41. package/lib/patches/snapshot.js +25 -0
  42. package/lib/patches/third-party-main.d.ts +2 -0
  43. package/lib/patches/third-party-main.js +99 -0
  44. package/lib/releases.d.ts +15 -0
  45. package/lib/releases.js +57 -0
  46. package/lib/steps/artifacts.d.ts +11 -0
  47. package/lib/steps/artifacts.js +89 -0
  48. package/lib/steps/bundle.d.ts +2 -0
  49. package/lib/steps/bundle.js +104 -0
  50. package/lib/steps/clean.d.ts +2 -0
  51. package/lib/steps/clean.js +30 -0
  52. package/lib/steps/cli.d.ts +12 -0
  53. package/lib/steps/cli.js +55 -0
  54. package/lib/steps/download.d.ts +7 -0
  55. package/lib/steps/download.js +76 -0
  56. package/lib/steps/resource.d.ts +2 -0
  57. package/lib/steps/resource.js +38 -0
  58. package/lib/steps/shim.d.ts +2 -0
  59. package/lib/steps/shim.js +45 -0
  60. package/lib/target.d.ts +11 -0
  61. package/lib/target.js +82 -0
  62. package/lib/util.d.ts +29 -0
  63. package/lib/util.js +104 -0
  64. package/package.json +148 -0
@@ -0,0 +1,12 @@
1
+ export interface NexeHeader {
2
+ blobPath: string;
3
+ layout: {
4
+ resourceStart: number;
5
+ resourceSize: number;
6
+ contentSize: number;
7
+ contentStart: number;
8
+ };
9
+ }
10
+ declare function shimFs(binary: NexeHeader, fs?: typeof import('fs')): void;
11
+ declare function restoreFs(): void;
12
+ export { shimFs, restoreFs };
@@ -0,0 +1,122 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.restoreFs = exports.shimFs = void 0;
27
+ const libzip_1 = require("@yarnpkg/libzip");
28
+ const fslib_1 = require("@yarnpkg/fslib");
29
+ const SnapshotZipFS_1 = require("./SnapshotZipFS");
30
+ const assert = __importStar(require("assert"));
31
+ const constants = __importStar(require("constants"));
32
+ const path_1 = require("path");
33
+ let originalFsMethods = null;
34
+ let lazyRestoreFs = () => { };
35
+ const patches = process.nexe.patches || {};
36
+ const originalPatches = Object.assign({}, patches);
37
+ delete process.nexe;
38
+ function shimFs(binary, fs = require('fs')) {
39
+ if (originalFsMethods !== null) {
40
+ return;
41
+ }
42
+ originalFsMethods = Object.assign({}, fs);
43
+ const realFs = Object.assign({}, fs);
44
+ const nodeFs = new fslib_1.NodeFS(realFs);
45
+ const blob = Buffer.allocUnsafe(binary.layout.resourceSize);
46
+ const blobFd = realFs.openSync(binary.blobPath, 'r');
47
+ const bytesRead = realFs.readSync(blobFd, blob, 0, binary.layout.resourceSize, binary.layout.resourceStart);
48
+ assert.equal(bytesRead, binary.layout.resourceSize);
49
+ const zipFs = new libzip_1.ZipFS(blob, { readOnly: true });
50
+ const snapshotZipFS = new SnapshotZipFS_1.SnapshotZipFS({
51
+ libzip: (0, libzip_1.getLibzipSync)(),
52
+ zipFs,
53
+ baseFs: nodeFs,
54
+ root: (0, path_1.dirname)(process.argv[0]),
55
+ });
56
+ const posixSnapshotZipFs = new fslib_1.PosixFS(snapshotZipFS);
57
+ (0, fslib_1.patchFs)(fs, posixSnapshotZipFs);
58
+ let log = (_) => true;
59
+ if ((process.env.DEBUG || '').toLowerCase().includes('nexe:require')) {
60
+ process.stderr.write(
61
+ // @ts-ignore
62
+ `[nexe] - FILES ${JSON.stringify(Array.from(zipFs.entries.keys()), null, 4)}\n`);
63
+ process.stderr.write(
64
+ // @ts-ignore
65
+ `[nexe] - DIRECTORIES ${JSON.stringify(Array.from(zipFs.listings.keys()), null, 4)}\n`);
66
+ log = (text) => {
67
+ return process.stderr.write(`[nexe] - ${text}\n`);
68
+ };
69
+ }
70
+ function internalModuleReadFile(original, ...args) {
71
+ log(`internalModuleReadFile ${args[0]}`);
72
+ try {
73
+ return posixSnapshotZipFs.readFileSync(args[0], 'utf-8');
74
+ }
75
+ catch (e) {
76
+ return '';
77
+ }
78
+ }
79
+ if (patches.internalModuleReadFile) {
80
+ patches.internalModuleReadFile = internalModuleReadFile;
81
+ }
82
+ let returningArray;
83
+ patches.internalModuleReadJSON = function (original, ...args) {
84
+ if (returningArray == null)
85
+ returningArray = Array.isArray(original.call(this, ''));
86
+ const res = internalModuleReadFile.call(this, original, ...args);
87
+ return returningArray && !Array.isArray(res)
88
+ ? res === ''
89
+ ? []
90
+ : [res, /"(main|name|type|exports|imports)"/.test(res)]
91
+ : res;
92
+ };
93
+ patches.internalModuleStat = function (original, ...args) {
94
+ let statPath = args[0];
95
+ //in node 22, the path arg moved to arg[1]
96
+ if (typeof args[0] !== 'string')
97
+ statPath = args[1];
98
+ let result = 0;
99
+ try {
100
+ const stat = posixSnapshotZipFs.statSync(statPath);
101
+ if (stat.isDirectory())
102
+ result = 1;
103
+ else
104
+ result = 0;
105
+ }
106
+ catch (e) {
107
+ result = -constants.ENOENT;
108
+ }
109
+ log(`internalModuleStat ${result} ${statPath}`);
110
+ return result;
111
+ };
112
+ lazyRestoreFs = () => {
113
+ Object.assign(fs, originalFsMethods);
114
+ Object.assign(patches, originalPatches);
115
+ lazyRestoreFs = () => { };
116
+ };
117
+ }
118
+ exports.shimFs = shimFs;
119
+ function restoreFs() {
120
+ lazyRestoreFs();
121
+ }
122
+ exports.restoreFs = restoreFs;
@@ -0,0 +1,18 @@
1
+ export interface LogStep {
2
+ modify(text: string, color?: string): void;
3
+ log(text: string, color?: string): void;
4
+ pause(): void;
5
+ resume(): void;
6
+ }
7
+ export declare class Logger {
8
+ verbose: boolean;
9
+ private silent;
10
+ private ora;
11
+ private modify;
12
+ write: (text: string, color?: string) => void;
13
+ constructor(level: 'verbose' | 'silent' | 'info');
14
+ flush(): Promise<unknown>;
15
+ _write(update: string, color?: string): void;
16
+ _modify(update: string, color?: any): void;
17
+ step(text: string, method?: string): LogStep;
18
+ }
package/lib/logger.js ADDED
@@ -0,0 +1,60 @@
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
+ exports.Logger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const ora_1 = __importDefault(require("ora"));
9
+ const frameLength = 120;
10
+ class Logger {
11
+ constructor(level) {
12
+ this.verbose = level === 'verbose';
13
+ this.silent = level === 'silent';
14
+ if (!this.silent) {
15
+ this.ora = (0, ora_1.default)({
16
+ text: 'Starting...',
17
+ color: 'blue',
18
+ spinner: 'dots',
19
+ });
20
+ this.ora.stop();
21
+ }
22
+ const noop = () => { };
23
+ this.modify = this.silent ? noop : this._modify.bind(this);
24
+ this.write = this.silent ? noop : this._write.bind(this);
25
+ }
26
+ flush() {
27
+ !this.silent && this.ora.succeed();
28
+ return new Promise((resolve) => setTimeout(resolve, frameLength));
29
+ }
30
+ _write(update, color = 'green') {
31
+ this.ora.succeed().text = chalk_1.default[color](update);
32
+ this.ora.start();
33
+ }
34
+ _modify(update, color = this.ora.color) {
35
+ this.ora.text = update;
36
+ this.ora.color = color;
37
+ }
38
+ step(text, method = 'succeed') {
39
+ if (this.silent) {
40
+ return { modify() { }, log() { }, pause() { }, resume() { } };
41
+ }
42
+ if (!this.ora.id) {
43
+ this.ora.start().text = text;
44
+ if (method !== 'succeed') {
45
+ this.ora[method]();
46
+ }
47
+ }
48
+ else {
49
+ this.ora[method]().text = text;
50
+ this.ora.start();
51
+ }
52
+ return {
53
+ modify: this.modify,
54
+ log: this.verbose ? this.write : this.modify,
55
+ pause: () => this.ora.stopAndPersist(),
56
+ resume: () => this.ora.start(),
57
+ };
58
+ }
59
+ }
60
+ exports.Logger = Logger;
package/lib/nexe.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { NexeCompiler } from './compiler';
2
+ import { NexeOptions } from './options';
3
+ declare function compile(compilerOptions?: Partial<NexeOptions>, callback?: (err: Error | null) => void): Promise<void>;
4
+ export { compile, NexeCompiler };
5
+ export { argv, version, NexeOptions, help } from './options';
package/lib/nexe.js ADDED
@@ -0,0 +1,53 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.help = exports.version = exports.argv = exports.NexeCompiler = exports.compile = void 0;
16
+ const app_builder_1 = require("app-builder");
17
+ const compiler_1 = require("./compiler");
18
+ Object.defineProperty(exports, "NexeCompiler", { enumerable: true, get: function () { return compiler_1.NexeCompiler; } });
19
+ const options_1 = require("./options");
20
+ const resource_1 = __importDefault(require("./steps/resource"));
21
+ const clean_1 = __importDefault(require("./steps/clean"));
22
+ const cli_1 = __importDefault(require("./steps/cli"));
23
+ const bundle_1 = __importDefault(require("./steps/bundle"));
24
+ const download_1 = __importDefault(require("./steps/download"));
25
+ const shim_1 = __importDefault(require("./steps/shim"));
26
+ const artifacts_1 = __importDefault(require("./steps/artifacts"));
27
+ const patches_1 = __importDefault(require("./patches"));
28
+ function compile(compilerOptions, callback) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ let error = null, options = null, compiler = null;
31
+ try {
32
+ options = (0, options_1.normalizeOptions)(compilerOptions);
33
+ compiler = new compiler_1.NexeCompiler(options);
34
+ yield (0, app_builder_1.compose)(clean_1.default, resource_1.default, cli_1.default, bundle_1.default, shim_1.default, download_1.default, options.build ? [artifacts_1.default, ...patches_1.default, ...options.patches] : [], options.plugins)(compiler);
35
+ }
36
+ catch (e) {
37
+ error = e;
38
+ }
39
+ if (error) {
40
+ compiler && compiler.quit(error);
41
+ if (callback)
42
+ return callback(error);
43
+ return Promise.reject(error);
44
+ }
45
+ if (callback)
46
+ callback(null);
47
+ });
48
+ }
49
+ exports.compile = compile;
50
+ var options_2 = require("./options");
51
+ Object.defineProperty(exports, "argv", { enumerable: true, get: function () { return options_2.argv; } });
52
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return options_2.version; } });
53
+ Object.defineProperty(exports, "help", { enumerable: true, get: function () { return options_2.help; } });
@@ -0,0 +1,56 @@
1
+ import parseArgv from 'minimist';
2
+ import { NexeCompiler } from './compiler';
3
+ import { NexeTarget } from './target';
4
+ export declare const version = "{{ version }}";
5
+ export interface NexePatch {
6
+ (compiler: NexeCompiler, next: () => Promise<void>): Promise<void>;
7
+ }
8
+ export interface NexeOptions {
9
+ build: boolean;
10
+ input: string;
11
+ output: string;
12
+ targets: (string | NexeTarget)[];
13
+ name: string;
14
+ remote: string;
15
+ asset: string;
16
+ cwd: string;
17
+ fs: boolean | string[];
18
+ flags: string[];
19
+ configure: string[];
20
+ vcBuild: string[];
21
+ make: string[];
22
+ snapshot?: string;
23
+ resources: string[];
24
+ temp: string;
25
+ rc: {
26
+ [key: string]: string;
27
+ };
28
+ enableNodeCli: boolean;
29
+ bundle: boolean | string;
30
+ patches: (string | NexePatch)[];
31
+ plugins: (string | NexePatch)[];
32
+ native: any;
33
+ mangle: boolean;
34
+ ghToken: string;
35
+ sourceUrl?: string;
36
+ enableStdIn?: boolean;
37
+ python?: string;
38
+ loglevel: 'info' | 'silent' | 'verbose';
39
+ silent?: boolean;
40
+ fakeArgv?: boolean;
41
+ verbose?: boolean;
42
+ info?: boolean;
43
+ ico?: string;
44
+ debugBundle?: boolean;
45
+ warmup?: string;
46
+ clean?: boolean;
47
+ /**
48
+ * Api Only
49
+ */
50
+ downloadOptions: any;
51
+ }
52
+ declare const argv: parseArgv.ParsedArgs;
53
+ declare let help: string;
54
+ export declare function resolveEntry(input: string, cwd: string, maybeEntry: string | undefined, bundle: boolean | string): string;
55
+ declare function normalizeOptions(input?: Partial<NexeOptions>): NexeOptions;
56
+ export { argv, normalizeOptions, help };
package/lib/options.js ADDED
@@ -0,0 +1,244 @@
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
+ exports.help = exports.normalizeOptions = exports.argv = exports.resolveEntry = exports.version = void 0;
7
+ const minimist_1 = __importDefault(require("minimist"));
8
+ const compiler_1 = require("./compiler");
9
+ const util_1 = require("./util");
10
+ const path_1 = require("path");
11
+ const target_1 = require("./target");
12
+ const os_1 = require("os");
13
+ const chalk_1 = __importDefault(require("chalk"));
14
+ const resolve_dependencies_1 = require("resolve-dependencies");
15
+ const caw = require('caw');
16
+ const c = process.platform === 'win32' ? chalk_1.default.constructor({ enabled: false }) : chalk_1.default;
17
+ exports.version = "5.0.0-beta.4";
18
+ const defaults = {
19
+ flags: [],
20
+ cwd: process.cwd(),
21
+ fs: true,
22
+ configure: [],
23
+ mangle: true,
24
+ make: [],
25
+ targets: [],
26
+ vcBuild: util_1.isWindows ? ['nosign', 'release'] : [],
27
+ enableNodeCli: false,
28
+ build: false,
29
+ bundle: true,
30
+ patches: [],
31
+ plugins: [],
32
+ remote: 'https://github.com/nexe/nexe/releases/download/v3.3.3/',
33
+ };
34
+ const alias = {
35
+ i: 'input',
36
+ o: 'output',
37
+ v: 'version',
38
+ a: 'asset',
39
+ t: 'target',
40
+ b: 'build',
41
+ n: 'name',
42
+ r: 'resource',
43
+ p: 'python',
44
+ f: 'flag',
45
+ c: 'configure',
46
+ m: 'make',
47
+ h: 'help',
48
+ l: 'loglevel',
49
+ 'fake-argv': 'fakeArgv',
50
+ 'gh-token': 'ghToken',
51
+ };
52
+ const argv = (0, minimist_1.default)(process.argv, { alias, default: Object.assign({}, defaults) });
53
+ exports.argv = argv;
54
+ let help = `
55
+ ${c.bold('nexe <entry-file> [options]')}
56
+
57
+ ${c.underline.bold('Options:')}
58
+
59
+ -i --input -- application entry point
60
+ -o --output -- path to output file
61
+ -t --target -- node version description
62
+ -n --name -- main app module name
63
+ -r --resource -- *embed files (glob) within the binary
64
+ --remote -- alternate location (URL) to download pre-built base (nexe) binaries from
65
+ --plugin -- extend nexe runtime behavior
66
+
67
+ ${c.underline.bold('Building from source:')}
68
+
69
+ -b --build -- build from source
70
+ -p --python -- python3 (as python) executable path
71
+ -f --flag -- *v8 flags to include during compilation
72
+ -c --configure -- *arguments to the configure step
73
+ -m --make -- *arguments to the make/build step
74
+ --patch -- module with middleware default export for adding a build patch
75
+ --no-mangle -- used when generating base binaries, or when patching _third_party_main manually
76
+ --snapshot -- path to a warmup snapshot
77
+ --ico -- file name for alternate icon file (windows)
78
+ --rc-* -- populate rc file options (windows)
79
+ --sourceUrl -- pass an alternate source (node.tar.gz) url
80
+ --enableNodeCli -- enable node cli enforcement (blocks app cli)
81
+
82
+ ${c.underline.bold('Other options:')}
83
+
84
+ --bundle -- custom bundling module with 'createBundle' export
85
+ --temp -- temp file storage default '~/.nexe'
86
+ --cwd -- set the current working directory for the command
87
+ --fake-argv -- fake argv[1] with entry file
88
+ --clean -- force download of sources
89
+ --silent -- disable logging
90
+ --verbose -- set logging to verbose
91
+
92
+ -* variable key name * option can be used more than once`.trim();
93
+ exports.help = help;
94
+ exports.help = help = os_1.EOL + help + os_1.EOL;
95
+ function flatten(...args) {
96
+ return [].concat(...args).filter((x) => x);
97
+ }
98
+ /**
99
+ * Extract keys such as { "rc-CompanyName": "Node.js" } to
100
+ * { CompanyName: "Node.js" }
101
+ * @param {*} match
102
+ * @param {*} options
103
+ */
104
+ function extractCliMap(match, options) {
105
+ return Object.keys(options)
106
+ .filter((x) => match.test(x))
107
+ .reduce((map, option) => {
108
+ const key = option.split('-')[1];
109
+ map[key] = options[option];
110
+ delete options[option];
111
+ return map;
112
+ }, {});
113
+ }
114
+ function extractLogLevel(options) {
115
+ if (options.loglevel)
116
+ return options.loglevel;
117
+ if (options.silent)
118
+ return 'silent';
119
+ if (options.verbose)
120
+ return 'verbose';
121
+ return 'info';
122
+ }
123
+ function isName(name) {
124
+ return name && name !== 'index' && name !== util_1.STDIN_FLAG;
125
+ }
126
+ function extractName(options) {
127
+ let name = options.name;
128
+ //try and use the input filename as the output filename if its not index
129
+ if (!isName(name) && typeof options.input === 'string') {
130
+ name = (0, path_1.basename)(options.input).replace((0, path_1.extname)(options.input), '');
131
+ }
132
+ //try and use the directory as the filename
133
+ if (!isName(name) && (0, path_1.basename)(options.cwd)) {
134
+ name = (0, path_1.basename)(options.cwd);
135
+ }
136
+ return name.replace(/\.exe$/, '');
137
+ }
138
+ function padRelative(input) {
139
+ let prefix = '';
140
+ if (!input.startsWith('.')) {
141
+ prefix = './';
142
+ }
143
+ return prefix + input;
144
+ }
145
+ function isEntryFile(filename) {
146
+ return Boolean(filename && !(0, path_1.isAbsolute)(filename));
147
+ }
148
+ function resolveEntry(input, cwd, maybeEntry, bundle) {
149
+ let result = null;
150
+ if (input === '-' || maybeEntry === '-') {
151
+ return util_1.STDIN_FLAG;
152
+ }
153
+ if (input && (0, path_1.isAbsolute)(input)) {
154
+ return input;
155
+ }
156
+ if (input) {
157
+ const inputPath = padRelative(input);
158
+ result = (0, resolve_dependencies_1.resolveSync)(cwd, inputPath);
159
+ }
160
+ if (isEntryFile(maybeEntry) && (!result || !result.absPath)) {
161
+ const inputPath = padRelative(maybeEntry);
162
+ result = (0, resolve_dependencies_1.resolveSync)(cwd, inputPath);
163
+ }
164
+ if (!process.stdin.isTTY && (!result || !result.absPath) && bundle === defaults.bundle) {
165
+ return util_1.STDIN_FLAG;
166
+ }
167
+ if (!result || !result.absPath) {
168
+ result = (0, resolve_dependencies_1.resolveSync)(cwd, '.');
169
+ }
170
+ if (!result.absPath) {
171
+ throw new compiler_1.NexeError(`Entry file "${input || ''}" not found!`);
172
+ }
173
+ return result.absPath;
174
+ }
175
+ exports.resolveEntry = resolveEntry;
176
+ function isCli(options) {
177
+ return argv === options;
178
+ }
179
+ function normalizeOptions(input) {
180
+ const options = Object.assign({}, defaults, input);
181
+ const opts = options;
182
+ const cwd = (options.cwd = (0, path_1.resolve)(options.cwd));
183
+ options.temp = options.temp
184
+ ? (0, path_1.resolve)(cwd, options.temp)
185
+ : process.env.NEXE_TEMP || (0, path_1.join)((0, os_1.homedir)(), '.nexe');
186
+ const maybeEntry = isCli(input) ? argv._[argv._.length - 1] : undefined;
187
+ options.input = resolveEntry(options.input, cwd, maybeEntry, options.bundle);
188
+ options.enableStdIn = isCli(input) && options.input === util_1.STDIN_FLAG;
189
+ options.name = extractName(options);
190
+ options.loglevel = extractLogLevel(options);
191
+ options.flags = flatten(opts.flag, options.flags);
192
+ options.targets = flatten(opts.target, options.targets).map(target_1.getTarget);
193
+ if (!options.targets.length) {
194
+ options.targets.push((0, target_1.getTarget)());
195
+ }
196
+ options.ghToken = options.ghToken || process.env.GITHUB_TOKEN || '';
197
+ options.make = flatten(util_1.isWindows ? options.vcBuild : options.make);
198
+ options.configure = flatten(options.configure);
199
+ options.resources = flatten(opts.resource, options.resources);
200
+ if (!options.remote.endsWith('/')) {
201
+ options.remote += '/';
202
+ }
203
+ options.downloadOptions = options.downloadOptions || {};
204
+ options.downloadOptions.headers = options.downloadOptions.headers || {};
205
+ options.downloadOptions.headers['User-Agent'] = 'nexe (https://www.npmjs.com/package/nexe)';
206
+ options.downloadOptions.agent = process.env.HTTPS_PROXY
207
+ ? caw(process.env.HTTPS_PROXY, { protocol: 'https' })
208
+ : options.downloadOptions.agent || require('https').globalAgent;
209
+ options.downloadOptions.rejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED
210
+ ? false
211
+ : true;
212
+ options.rc = options.rc || extractCliMap(/^rc-.*/, options);
213
+ options.output =
214
+ options.targets[0].platform === 'windows'
215
+ ? `${(options.output || options.name).replace(/\.exe$/, '')}.exe`
216
+ : `${options.output || options.name}`;
217
+ options.output = (0, path_1.resolve)(cwd, options.output);
218
+ const requireDefault = (x) => {
219
+ if (typeof x === 'string') {
220
+ return require(x).default;
221
+ }
222
+ return x;
223
+ };
224
+ options.mangle = 'mangle' in opts ? opts.mangle : true;
225
+ options.plugins = flatten(opts.plugin, options.plugins).map(requireDefault);
226
+ options.patches = flatten(opts.patch, options.patches).map(requireDefault);
227
+ if ((!options.mangle && !options.bundle) || options.patches.length) {
228
+ options.build = true;
229
+ }
230
+ if (options.build) {
231
+ const { arch } = options.targets[0];
232
+ if (util_1.isWindows) {
233
+ options.make = Array.from(new Set(options.make.concat(arch)));
234
+ }
235
+ else {
236
+ options.configure = Array.from(new Set(options.configure.concat([`--dest-cpu=${arch}`])));
237
+ }
238
+ }
239
+ Object.keys(alias)
240
+ .filter((k) => k !== 'rc')
241
+ .forEach((x) => delete opts[x]);
242
+ return options;
243
+ }
244
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ declare const fs: any, fd: any, stat: any, tailSize: number, tailWindow: Buffer;
3
+ declare const footerPosition: number;
4
+ declare const footer: Buffer, contentSize: number, resourceSize: number, contentStart: number, resourceStart: number;
5
+ declare const contentBuffer: Buffer, Module: any;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ 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));
3
+ fs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize);
4
+ const footerPosition = tailWindow.indexOf('<nexe~~sentinel>');
5
+ if (footerPosition == -1) {
6
+ throw 'Invalid Nexe binary';
7
+ }
8
+ 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;
9
+ Object.defineProperty(process, '__nexe', (function () {
10
+ let nexeHeader = null;
11
+ return {
12
+ get: function () {
13
+ return nexeHeader;
14
+ },
15
+ set: function (value) {
16
+ if (nexeHeader) {
17
+ throw new Error('This property is readonly');
18
+ }
19
+ nexeHeader = Object.assign({}, value, {
20
+ blobPath: process.execPath,
21
+ layout: {
22
+ stat,
23
+ contentSize,
24
+ contentStart,
25
+ resourceSize,
26
+ resourceStart,
27
+ },
28
+ });
29
+ Object.freeze(nexeHeader);
30
+ },
31
+ enumerable: false,
32
+ configurable: false,
33
+ };
34
+ })());
35
+ const contentBuffer = Buffer.from(Array(contentSize)), Module = require('module');
36
+ fs.readSync(fd, contentBuffer, 0, contentSize, contentStart);
37
+ fs.closeSync(fd);
38
+ new Module(process.execPath, null)._compile(contentBuffer.toString(), process.execPath);
@@ -0,0 +1,2 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ export default function buildFixes(compiler: NexeCompiler, next: () => Promise<void>): Promise<void>;
@@ -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 buildFixes(compiler, next) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ if (!compiler.target.version.startsWith('8.2')) {
15
+ return next();
16
+ }
17
+ const file = yield compiler.readFileAsync('./tools/msvs/find_python.cmd');
18
+ yield compiler.replaceInFileAsync('./tools/msvs/find_python.cmd', '%p%python.exe -V 2>&1', '"%p%python.exe" -V 2>&1');
19
+ return next();
20
+ });
21
+ }
22
+ exports.default = buildFixes;
@@ -0,0 +1,2 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ export default function disableNodeCli(compiler: NexeCompiler, next: () => Promise<void>): Promise<void>;