diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-24 14:41:48 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-24 14:41:48 +0200 |
commit | d25e11bee6ca5ca523884da132d18e1400e077b9 (patch) | |
tree | 8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/nexe/lib/steps | |
download | kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2 kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip |
Initial commit
Diffstat (limited to 'node_modules/nexe/lib/steps')
-rw-r--r-- | node_modules/nexe/lib/steps/artifacts.d.ts | 11 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/artifacts.js | 66 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/bundle.d.ts | 2 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/bundle.js | 79 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/clean.d.ts | 2 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/clean.js | 30 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/cli.d.ts | 12 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/cli.js | 55 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/download.d.ts | 7 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/download.js | 76 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/resource.d.ts | 2 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/resource.js | 35 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/shim.d.ts | 2 | ||||
-rw-r--r-- | node_modules/nexe/lib/steps/shim.js | 38 |
14 files changed, 417 insertions, 0 deletions
diff --git a/node_modules/nexe/lib/steps/artifacts.d.ts b/node_modules/nexe/lib/steps/artifacts.d.ts new file mode 100644 index 0000000..8042d38 --- /dev/null +++ b/node_modules/nexe/lib/steps/artifacts.d.ts @@ -0,0 +1,11 @@ +import { NexeCompiler } from '../compiler'; +/** + * The artifacts step is where source patches are committed, or written as "artifacts" + * Steps: + * - A temporary directory is created in the downloaded source + * - On start, any files in that directory are restored into the source tree + * - After the patch functions have run, the temporary directory is emptied + * - Original versions of sources to be patched are written to the temporary directory + * - Finally, The patched files are written into source. + */ +export default function artifacts(compiler: NexeCompiler, next: () => Promise<void>): Promise<void[]>; diff --git a/node_modules/nexe/lib/steps/artifacts.js b/node_modules/nexe/lib/steps/artifacts.js new file mode 100644 index 0000000..d152178 --- /dev/null +++ b/node_modules/nexe/lib/steps/artifacts.js @@ -0,0 +1,66 @@ +"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 fs = require("fs"); +const util_1 = require("util"); +const util_2 = require("../util"); +const mkdirpAsync = require("mkdirp"); +const unlinkAsync = util_1.promisify(fs.unlink), readdirAsync = util_1.promisify(fs.readdir); +function readDirAsync(dir) { + return readdirAsync(dir).then((paths) => { + return Promise.all(paths.map((file) => { + const path = path_1.join(dir, file); + return util_2.isDirectoryAsync(path).then((x) => (x ? readDirAsync(path) : path)); + })).then((result) => { + return [].concat(...result); + }); + }); +} +function maybeReadFileContentsAsync(file) { + return util_2.readFileAsync(file, 'utf-8').catch((e) => { + if (e.code === 'ENOENT') { + return ''; + } + throw e; + }); +} +/** + * The artifacts step is where source patches are committed, or written as "artifacts" + * Steps: + * - A temporary directory is created in the downloaded source + * - On start, any files in that directory are restored into the source tree + * - After the patch functions have run, the temporary directory is emptied + * - Original versions of sources to be patched are written to the temporary directory + * - Finally, The patched files are written into source. + */ +function artifacts(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { src } = compiler; + const temp = path_1.join(src, 'nexe'); + yield mkdirpAsync(temp); + const tmpFiles = yield readDirAsync(temp); + yield Promise.all(tmpFiles.map((path) => __awaiter(this, void 0, void 0, function* () { + return compiler.writeFileAsync(path.replace(temp, ''), yield util_2.readFileAsync(path, 'utf-8')); + }))); + yield next(); + yield Promise.all(tmpFiles.map((x) => unlinkAsync(x))); + return Promise.all(compiler.files.map((file) => __awaiter(this, void 0, void 0, function* () { + const sourceFile = path_1.join(src, file.filename); + const tempFile = path_1.join(temp, file.filename); + const fileContents = yield maybeReadFileContentsAsync(sourceFile); + yield mkdirpAsync(path_1.dirname(tempFile)); + yield util_2.writeFileAsync(tempFile, fileContents); + yield compiler.writeFileAsync(file.filename, file.contents); + }))); + }); +} +exports.default = artifacts; diff --git a/node_modules/nexe/lib/steps/bundle.d.ts b/node_modules/nexe/lib/steps/bundle.d.ts new file mode 100644 index 0000000..64229c8 --- /dev/null +++ b/node_modules/nexe/lib/steps/bundle.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function bundle(compiler: NexeCompiler, next: any): Promise<any>; diff --git a/node_modules/nexe/lib/steps/bundle.js b/node_modules/nexe/lib/steps/bundle.js new file mode 100644 index 0000000..d09f470 --- /dev/null +++ b/node_modules/nexe/lib/steps/bundle.js @@ -0,0 +1,79 @@ +"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 compiler_1 = require("../compiler"); +const path_1 = require("path"); +const resolve_dependencies_1 = require("resolve-dependencies"); +const util_1 = require("../util"); +function getStdIn(stdin) { + let out = ''; + return new Promise((resolve) => { + stdin + .setEncoding('utf8') + .on('readable', () => { + let current; + while ((current = stdin.read())) { + out += current; + } + }) + .on('end', () => resolve(out.trim())); + setTimeout(() => { + if (!out.trim()) { + resolve(out.trim()); + } + }, 1000); + }); +} +function bundle(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { bundle: doBundle, cwd, input: inputPath } = compiler.options; + let input = inputPath; + compiler.entrypoint = './' + path_1.relative(cwd, input); + if (util_1.semverGt(compiler.target.version, '11.99')) { + compiler.startup = ''; + } + else { + compiler.startup = ';require("module").runMain();'; + } + if (!doBundle) { + yield compiler.addResource(path_1.resolve(cwd, input)); + return next(); + } + let code = ''; + if (typeof doBundle === 'string') { + code = yield require(doBundle).createBundle(compiler.options); + } + if (input === util_1.STDIN_FLAG && (code = code || util_1.dequote(yield getStdIn(process.stdin)))) { + compiler.stdinUsed = true; + compiler.entrypoint = './__nexe_stdin.js'; + yield compiler.addResource(path_1.resolve(cwd, compiler.entrypoint), code); + return next(); + } + if (input === util_1.STDIN_FLAG) { + const maybeInput = resolve_dependencies_1.resolveSync(cwd, '.'); + if (!maybeInput || !maybeInput.absPath) { + throw new compiler_1.NexeError('No valid input detected'); + } + input = maybeInput.absPath; + compiler.entrypoint = './' + path_1.relative(cwd, input); + } + const { files, warnings } = resolve_dependencies_1.default(input, ...Object.keys(compiler.bundle.list).filter((x) => x.endsWith('.js')), { cwd, expand: 'variable', loadContent: false }); + if (warnings.filter((x) => x.startsWith('Error parsing file') && !x.includes('node_modules')).length) { + throw new compiler_1.NexeError('Parsing Error:\n' + warnings.join('\n')); + } + //TODO: warnings.forEach((x) => console.log(x)) + yield Promise.all(Object.entries(files).map(([key, file]) => { + return compiler.addResource(key, file); + })); + return next(); + }); +} +exports.default = bundle; diff --git a/node_modules/nexe/lib/steps/clean.d.ts b/node_modules/nexe/lib/steps/clean.d.ts new file mode 100644 index 0000000..ced1461 --- /dev/null +++ b/node_modules/nexe/lib/steps/clean.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function clean(compiler: NexeCompiler, next: () => Promise<any>): Promise<any>; diff --git a/node_modules/nexe/lib/steps/clean.js b/node_modules/nexe/lib/steps/clean.js new file mode 100644 index 0000000..27dba57 --- /dev/null +++ b/node_modules/nexe/lib/steps/clean.js @@ -0,0 +1,30 @@ +"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 clean(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { options } = compiler; + if (options.clean) { + let path = compiler.src; + if (!options.build) { + path = compiler.getNodeExecutableLocation(compiler.options.targets[0]); + } + const step = compiler.log.step('Cleaning up nexe build artifacts...'); + step.log(`Deleting contents at: ${path}`); + yield util_1.rimrafAsync(path); + step.log(`Deleted contents at: ${path}`); + return compiler.quit(); + } + return next(); + }); +} +exports.default = clean; diff --git a/node_modules/nexe/lib/steps/cli.d.ts b/node_modules/nexe/lib/steps/cli.d.ts new file mode 100644 index 0000000..02b796a --- /dev/null +++ b/node_modules/nexe/lib/steps/cli.d.ts @@ -0,0 +1,12 @@ +import { NexeCompiler } from '../compiler'; +/** + * The "cli" step detects the appropriate input. If no input options are passed, + * the package.json#main file is used. + * After all the build steps have run, the output (the executable) is written to a file or piped to stdout. + * + * Configuration: + * + * @param {*} compiler + * @param {*} next + */ +export default function cli(compiler: NexeCompiler, next: () => Promise<void>): Promise<unknown>; diff --git a/node_modules/nexe/lib/steps/cli.js b/node_modules/nexe/lib/steps/cli.js new file mode 100644 index 0000000..6223338 --- /dev/null +++ b/node_modules/nexe/lib/steps/cli.js @@ -0,0 +1,55 @@ +"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 fs_1 = require("fs"); +const util_1 = require("../util"); +const mkdirp = require("mkdirp"); +/** + * The "cli" step detects the appropriate input. If no input options are passed, + * the package.json#main file is used. + * After all the build steps have run, the output (the executable) is written to a file or piped to stdout. + * + * Configuration: + * + * @param {*} compiler + * @param {*} next + */ +function cli(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + yield next(); + const { log } = compiler, target = compiler.options.targets.shift(), deliverable = yield compiler.compileAsync(target), output = path_1.normalize(compiler.output); + mkdirp.sync(path_1.dirname(output)); + return new Promise((res, rej) => { + const step = log.step('Writing result to file'); + deliverable + .pipe(fs_1.createWriteStream(output)) + .on('error', rej) + .once('close', (e) => { + if (e) { + rej(e); + } + else if (compiler.output) { + const output = compiler.output, mode = fs_1.statSync(output).mode | 0o111, inputFileLogOutput = path_1.relative(process.cwd(), path_1.resolve(compiler.options.cwd, compiler.entrypoint || compiler.options.input)), outputFileLogOutput = path_1.relative(process.cwd(), output); + fs_1.chmodSync(output, mode.toString(8).slice(-3)); + step.log(`Entry: '${compiler.stdinUsed + ? compiler.options.mangle + ? util_1.STDIN_FLAG + : '[none]' + : inputFileLogOutput}' written to: ${outputFileLogOutput}`); + compiler.quit(); + res(output); + } + }); + }); + }); +} +exports.default = cli; diff --git a/node_modules/nexe/lib/steps/download.d.ts b/node_modules/nexe/lib/steps/download.d.ts new file mode 100644 index 0000000..50c81ed --- /dev/null +++ b/node_modules/nexe/lib/steps/download.d.ts @@ -0,0 +1,7 @@ +import { NexeCompiler } from '../compiler'; +/** + * Downloads the node source to the configured temporary directory + * @param {*} compiler + * @param {*} next + */ +export default function downloadNode(compiler: NexeCompiler, next: () => Promise<void>): Promise<void>; diff --git a/node_modules/nexe/lib/steps/download.js b/node_modules/nexe/lib/steps/download.js new file mode 100644 index 0000000..598245c --- /dev/null +++ b/node_modules/nexe/lib/steps/download.js @@ -0,0 +1,76 @@ +"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 download = require("download"); +const util_1 = require("../util"); +const compiler_1 = require("../compiler"); +const path_1 = require("path"); +function fetchNodeSourceAsync(dest, url, step, options = {}) { + const setText = (p) => step.modify(`Downloading Node: ${p.toFixed()}%...`); + return download(url, dest, Object.assign(options, { extract: true, strip: 1 })) + .on('response', (res) => { + const total = +res.headers['content-length']; + let current = 0; + res.on('data', (data) => { + current += data.length; + setText((current / total) * 100); + if (current === total) { + step.log('Extracting Node...'); + } + }); + }) + .then(() => step.log(`Node source extracted to: ${dest}`)); +} +function fetchPrebuiltBinary(compiler, step) { + return __awaiter(this, void 0, void 0, function* () { + const { target, remoteAsset } = compiler, filename = compiler.getNodeExecutableLocation(target); + try { + yield download(remoteAsset, path_1.dirname(filename), compiler.options.downloadOptions).on('response', (res) => { + const total = +res.headers['content-length']; + let current = 0; + res.on('data', (data) => { + current += data.length; + step.modify(`Downloading...${((current / total) * 100).toFixed()}%`); + }); + }); + } + catch (e) { + if (e.statusCode === 404) { + throw new compiler_1.NexeError(`${remoteAsset} is not available, create it using the --build flag`); + } + else { + throw new compiler_1.NexeError('Error downloading prebuilt binary: ' + e); + } + } + }); +} +/** + * Downloads the node source to the configured temporary directory + * @param {*} compiler + * @param {*} next + */ +function downloadNode(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { src, log, target } = compiler, { version } = target, { sourceUrl, downloadOptions, build } = compiler.options, url = sourceUrl || `https://nodejs.org/dist/v${version}/node-v${version}.tar.gz`, step = log.step(`Downloading ${build ? '' : 'pre-built '}Node.js${build ? `source from: ${url}` : ''}`), exeLocation = compiler.getNodeExecutableLocation(build ? undefined : target), downloadExists = yield util_1.pathExistsAsync(build ? src : exeLocation); + if (downloadExists) { + step.log('Already downloaded...'); + return next(); + } + if (build) { + yield fetchNodeSourceAsync(src, url, step, downloadOptions); + } + else { + yield fetchPrebuiltBinary(compiler, step); + } + return next(); + }); +} +exports.default = downloadNode; diff --git a/node_modules/nexe/lib/steps/resource.d.ts b/node_modules/nexe/lib/steps/resource.d.ts new file mode 100644 index 0000000..dc50712 --- /dev/null +++ b/node_modules/nexe/lib/steps/resource.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function resource(compiler: NexeCompiler, next: () => Promise<any>): Promise<any>; diff --git a/node_modules/nexe/lib/steps/resource.js b/node_modules/nexe/lib/steps/resource.js new file mode 100644 index 0000000..25f0f39 --- /dev/null +++ b/node_modules/nexe/lib/steps/resource.js @@ -0,0 +1,35 @@ +"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"); +const globs = require("globby"); +const path_1 = require("path"); +function resource(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + const { cwd, resources } = compiler.options; + if (!resources.length) { + return next(); + } + const step = compiler.log.step('Bundling Resources...'); + let count = 0; + // workaround for https://github.com/sindresorhus/globby/issues/127 + // and https://github.com/mrmlnc/fast-glob#pattern-syntax + const resourcesWithForwardSlashes = resources.map((r) => r.replace(/\\/g, '/')); + yield util_1.each(globs(resourcesWithForwardSlashes, { cwd, onlyFiles: true }), (file) => __awaiter(this, void 0, void 0, function* () { + count++; + step.log(`Including file: ${file}`); + yield compiler.addResource(path_1.resolve(cwd, file)); + })); + step.log(`Included ${count} file(s)`); + return next(); + }); +} +exports.default = resource; diff --git a/node_modules/nexe/lib/steps/shim.d.ts b/node_modules/nexe/lib/steps/shim.d.ts new file mode 100644 index 0000000..a94e274 --- /dev/null +++ b/node_modules/nexe/lib/steps/shim.d.ts @@ -0,0 +1,2 @@ +import { NexeCompiler } from '../compiler'; +export default function (compiler: NexeCompiler, next: () => Promise<void>): Promise<void>; diff --git a/node_modules/nexe/lib/steps/shim.js b/node_modules/nexe/lib/steps/shim.js new file mode 100644 index 0000000..c364c81 --- /dev/null +++ b/node_modules/nexe/lib/steps/shim.js @@ -0,0 +1,38 @@ +"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 default_1(compiler, next) { + return __awaiter(this, void 0, void 0, function* () { + yield next(); + compiler.shims.push(util_1.wrap('' + + "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nlet originalFsMethods = null;\nlet lazyRestoreFs = () => { };\n// optional Win32 file namespace prefix followed by drive letter and colon\nconst windowsFullPathRegex = /^(\\\\{2}\\?\\\\)?([a-zA-Z]):/;\nconst upcaseDriveLetter = (s) => s.replace(windowsFullPathRegex, (_match, ns, drive) => `${ns || ''}${drive.toUpperCase()}:`);\nfunction shimFs(binary, fs = require('fs')) {\n if (originalFsMethods !== null) {\n return;\n }\n originalFsMethods = Object.assign({}, fs);\n const { blobPath, resources: manifest } = binary, { resourceStart, stat } = binary.layout, directories = {}, notAFile = '!@#$%^&*', isWin = process.platform.startsWith('win'), isString = (x) => typeof x === 'string' || x instanceof String, noop = () => { }, path = require('path'), winPath = isWin ? upcaseDriveLetter : (s) => s, baseDir = winPath(path.dirname(process.execPath));\n let log = (_) => true;\n let loggedManifest = false;\n if ((process.env.DEBUG || '').toLowerCase().includes('nexe:require')) {\n log = (text) => {\n setupManifest();\n if (!loggedManifest) {\n process.stderr.write('[nexe] - MANIFEST' + JSON.stringify(manifest, null, 4) + '\\n');\n process.stderr.write('[nexe] - DIRECTORIES' + JSON.stringify(directories, null, 4) + '\\n');\n loggedManifest = true;\n }\n return process.stderr.write('[nexe] - ' + text + '\\n');\n };\n }\n const getKey = function getKey(filepath) {\n if (Buffer.isBuffer(filepath)) {\n filepath = filepath.toString();\n }\n if (!isString(filepath)) {\n return notAFile;\n }\n let key = path.resolve(baseDir, filepath);\n return winPath(key);\n };\n const statTime = function () {\n return {\n dev: 0,\n ino: 0,\n nlink: 0,\n rdev: 0,\n uid: 123,\n gid: 500,\n blksize: 4096,\n blocks: 0,\n atime: new Date(stat.atime),\n atimeMs: stat.atime.getTime(),\n mtime: new Date(stat.mtime),\n mtimeMs: stat.mtime.getTime(),\n ctime: new Date(stat.ctime),\n ctimMs: stat.ctime.getTime(),\n birthtime: new Date(stat.birthtime),\n birthtimeMs: stat.birthtime.getTime(),\n };\n };\n let BigInt;\n try {\n BigInt = eval('BigInt');\n }\n catch (ignored) { }\n const createStat = function (extensions, options) {\n const stat = Object.assign(new fs.Stats(), binary.layout.stat, statTime(), extensions);\n if (options && options.bigint && BigInt) {\n for (const k in stat) {\n if (Object.prototype.hasOwnProperty.call(stat, k) && typeof stat[k] === 'number') {\n stat[k] = BigInt(stat[k]);\n }\n }\n }\n return stat;\n };\n const ownStat = function (filepath, options) {\n setupManifest();\n const key = getKey(filepath);\n if (directories[key]) {\n let mode = binary.layout.stat.mode;\n mode |= fs.constants.S_IFDIR;\n mode &= ~fs.constants.S_IFREG;\n return createStat({ mode, size: 0 }, options);\n }\n if (manifest[key]) {\n return createStat({ size: manifest[key][1] }, options);\n }\n };\n const getStat = function (fn) {\n return function stat(filepath, options, callback) {\n let stat;\n if (typeof options === 'function') {\n callback = options;\n stat = ownStat(filepath, null);\n }\n else {\n stat = ownStat(filepath, options);\n }\n if (stat) {\n process.nextTick(() => {\n callback(null, stat);\n });\n }\n else {\n return originalFsMethods[fn].apply(fs, arguments);\n }\n };\n };\n function makeLong(filepath) {\n return path._makeLong && path._makeLong(filepath);\n }\n function fileOpts(options) {\n return !options ? {} : isString(options) ? { encoding: options } : options;\n }\n let setupManifest = () => {\n Object.keys(manifest).forEach((filepath) => {\n const entry = manifest[filepath];\n const absolutePath = getKey(filepath);\n const longPath = makeLong(absolutePath);\n const normalizedPath = winPath(path.normalize(filepath));\n if (!manifest[absolutePath]) {\n manifest[absolutePath] = entry;\n }\n if (longPath && !manifest[longPath]) {\n manifest[longPath] = entry;\n }\n if (!manifest[normalizedPath]) {\n manifest[normalizedPath] = manifest[filepath];\n }\n let currentDir = path.dirname(absolutePath);\n let prevDir = absolutePath;\n while (currentDir !== prevDir) {\n directories[currentDir] = directories[currentDir] || {};\n directories[currentDir][path.basename(prevDir)] = true;\n const longDir = makeLong(currentDir);\n if (longDir && !directories[longDir]) {\n directories[longDir] = directories[currentDir];\n }\n prevDir = currentDir;\n currentDir = path.dirname(currentDir);\n }\n });\n manifest[notAFile] = false;\n directories[notAFile] = false;\n setupManifest = noop;\n };\n //naive patches intended to work for most use cases\n const nfs = {\n existsSync: function existsSync(filepath) {\n setupManifest();\n const key = getKey(filepath);\n if (manifest[key] || directories[key]) {\n return true;\n }\n return originalFsMethods.existsSync.apply(fs, arguments);\n },\n realpath: function realpath(filepath, options, cb) {\n setupManifest();\n const key = getKey(filepath);\n if (isString(filepath) && (manifest[filepath] || manifest[key])) {\n return process.nextTick(() => cb(null, filepath));\n }\n return originalFsMethods.realpath.call(fs, filepath, options, cb);\n },\n realpathSync: function realpathSync(filepath, options) {\n setupManifest();\n const key = getKey(filepath);\n if (manifest[key]) {\n return filepath;\n }\n return originalFsMethods.realpathSync.call(fs, filepath, options);\n },\n readdir: function readdir(filepath, options, callback) {\n setupManifest();\n const dir = directories[getKey(filepath)];\n if (dir) {\n if ('function' === typeof options) {\n callback = options;\n options = { encoding: 'utf8' };\n }\n process.nextTick(() => callback(null, Object.keys(dir)));\n }\n else {\n return originalFsMethods.readdir.apply(fs, arguments);\n }\n },\n readdirSync: function readdirSync(filepath, options) {\n setupManifest();\n const dir = directories[getKey(filepath)];\n if (dir) {\n return Object.keys(dir);\n }\n return originalFsMethods.readdirSync.apply(fs, arguments);\n },\n readFile: function readFile(filepath, options, callback) {\n setupManifest();\n const entry = manifest[getKey(filepath)];\n if (!entry) {\n return originalFsMethods.readFile.apply(fs, arguments);\n }\n const [offset, length] = entry;\n const resourceOffset = resourceStart + offset;\n const encoding = fileOpts(options).encoding;\n callback = typeof options === 'function' ? options : callback;\n originalFsMethods.open(blobPath, 'r', function (err, fd) {\n if (err)\n return callback(err, null);\n originalFsMethods.read(fd, Buffer.alloc(length), 0, length, resourceOffset, function (error, bytesRead, result) {\n if (error) {\n return originalFsMethods.close(fd, function () {\n callback(error, null);\n });\n }\n originalFsMethods.close(fd, function (err) {\n if (err) {\n return callback(err, result);\n }\n callback(err, encoding ? result.toString(encoding) : result);\n });\n });\n });\n },\n createReadStream: function createReadStream(filepath, options) {\n setupManifest();\n const entry = manifest[getKey(filepath)];\n if (!entry) {\n return originalFsMethods.createReadStream.apply(fs, arguments);\n }\n const [offset, length] = entry;\n const resourceOffset = resourceStart + offset;\n const opts = fileOpts(options);\n return originalFsMethods.createReadStream(blobPath, Object.assign({}, opts, {\n start: resourceOffset,\n end: resourceOffset + length - 1,\n }));\n },\n readFileSync: function readFileSync(filepath, options) {\n setupManifest();\n const entry = manifest[getKey(filepath)];\n if (!entry) {\n return originalFsMethods.readFileSync.apply(fs, arguments);\n }\n const [offset, length] = entry;\n const resourceOffset = resourceStart + offset;\n const encoding = fileOpts(options).encoding;\n const fd = originalFsMethods.openSync(process.execPath, 'r');\n const result = Buffer.alloc(length);\n originalFsMethods.readSync(fd, result, 0, length, resourceOffset);\n originalFsMethods.closeSync(fd);\n return encoding ? result.toString(encoding) : result;\n },\n statSync: function statSync(filepath, options) {\n const stat = ownStat(filepath, options);\n if (stat) {\n return stat;\n }\n return originalFsMethods.statSync.apply(fs, arguments);\n },\n stat: getStat('stat'),\n lstat: getStat('lstat'),\n lstatSync: function statSync(filepath, options) {\n const stat = ownStat(filepath, options);\n if (stat) {\n return stat;\n }\n return originalFsMethods.lstatSync.apply(fs, arguments);\n },\n };\n if (typeof fs.exists === 'function') {\n nfs.exists = function (filepath, cb) {\n cb = cb || noop;\n const exists = nfs.existsSync(filepath);\n process.nextTick(() => cb(exists));\n };\n }\n const patches = process.nexe.patches || {};\n delete process.nexe;\n patches.internalModuleReadFile = function (original, ...args) {\n setupManifest();\n const filepath = getKey(args[0]);\n if (manifest[filepath]) {\n log('read (hit) ' + filepath);\n return nfs.readFileSync(filepath, 'utf-8');\n }\n log('read (miss) ' + filepath);\n return original.call(this, ...args);\n };\n let returningArray;\n patches.internalModuleReadJSON = function (original, ...args) {\n if (returningArray == null)\n returningArray = Array.isArray(original.call(this, ''));\n const res = patches.internalModuleReadFile.call(this, original, ...args);\n return returningArray && !Array.isArray(res)\n ? [res, /\"(main|name|type|exports|imports)\"/.test(res)]\n : res;\n };\n patches.internalModuleStat = function (original, ...args) {\n setupManifest();\n const filepath = getKey(args[0]);\n if (manifest[filepath]) {\n log('stat (hit) ' + filepath + ' ' + 0);\n return 0;\n }\n if (directories[filepath]) {\n log('stat dir (hit) ' + filepath + ' ' + 1);\n return 1;\n }\n const res = original.call(this, ...args);\n if (res === 0) {\n log('stat (miss) ' + filepath + ' ' + res);\n }\n else if (res === 1) {\n log('stat dir (miss) ' + filepath + ' ' + res);\n }\n else {\n log('stat (fail) ' + filepath + ' ' + res);\n }\n return res;\n };\n if (typeof fs.exists === 'function') {\n nfs.exists = function (filepath, cb) {\n cb = cb || noop;\n const exists = nfs.existsSync(filepath);\n if (!exists) {\n return originalFsMethods.exists(filepath, cb);\n }\n process.nextTick(() => cb(exists));\n };\n }\n if (typeof fs.copyFile === 'function') {\n nfs.copyFile = function (filepath, dest, flags, callback) {\n setupManifest();\n const entry = manifest[getKey(filepath)];\n if (!entry) {\n return originalFsMethods.copyFile.apply(fs, arguments);\n }\n if (typeof flags === 'function') {\n callback = flags;\n flags = 0;\n }\n nfs.readFile(filepath, (err, buffer) => {\n if (err) {\n return callback(err);\n }\n originalFsMethods.writeFile(dest, buffer, (err) => {\n if (err) {\n return callback(err);\n }\n callback(null);\n });\n });\n };\n nfs.copyFileSync = function (filepath, dest) {\n setupManifest();\n const entry = manifest[getKey(filepath)];\n if (!entry) {\n return originalFsMethods.copyFileSync.apply(fs, arguments);\n }\n return originalFsMethods.writeFileSync(dest, nfs.readFileSync(filepath));\n };\n }\n Object.assign(fs, nfs);\n lazyRestoreFs = () => {\n Object.keys(nfs).forEach((key) => {\n fs[key] = originalFsMethods[key];\n });\n lazyRestoreFs = () => { };\n };\n return true;\n}\nexports.shimFs = shimFs;\nfunction restoreFs() {\n lazyRestoreFs();\n}\nexports.restoreFs = restoreFs;\n" + + '\nshimFs(process.__nexe)' + + `\n${compiler.options.fs ? '' : 'restoreFs()'}` + //TODO support only restoring specific methods + )); + compiler.shims.push(util_1.wrap(` + if (process.argv[1] && process.env.NODE_UNIQUE_ID) { + const cluster = require('cluster') + cluster._setupWorker() + delete process.env.NODE_UNIQUE_ID + } + `)); + compiler.shims.push(util_1.wrap(` + if (!process.send) { + const path = require('path') + const entry = path.resolve(path.dirname(process.execPath),${JSON.stringify(compiler.entrypoint)}) + process.argv.splice(1,0, entry) + } + `)); + }); +} +exports.default = default_1; |