@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,30 @@
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 clean(compiler, next) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const { options } = compiler;
16
+ if (options.clean) {
17
+ let path = compiler.src;
18
+ if (!options.build) {
19
+ path = compiler.getNodeExecutableLocation(compiler.options.targets[0]);
20
+ }
21
+ const step = compiler.log.step('Cleaning up nexe build artifacts...');
22
+ step.log(`Deleting contents at: ${path}`);
23
+ yield (0, util_1.rimrafAsync)(path);
24
+ step.log(`Deleted contents at: ${path}`);
25
+ return compiler.quit();
26
+ }
27
+ return next();
28
+ });
29
+ }
30
+ exports.default = clean;
@@ -0,0 +1,12 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ /**
3
+ * The "cli" step detects the appropriate input. If no input options are passed,
4
+ * the package.json#main file is used.
5
+ * After all the build steps have run, the output (the executable) is written to a file or piped to stdout.
6
+ *
7
+ * Configuration:
8
+ *
9
+ * @param {*} compiler
10
+ * @param {*} next
11
+ */
12
+ export default function cli(compiler: NexeCompiler, next: () => Promise<void>): Promise<unknown>;
@@ -0,0 +1,55 @@
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 fs_1 = require("fs");
14
+ const util_1 = require("../util");
15
+ const mkdirp = require("mkdirp");
16
+ /**
17
+ * The "cli" step detects the appropriate input. If no input options are passed,
18
+ * the package.json#main file is used.
19
+ * After all the build steps have run, the output (the executable) is written to a file or piped to stdout.
20
+ *
21
+ * Configuration:
22
+ *
23
+ * @param {*} compiler
24
+ * @param {*} next
25
+ */
26
+ function cli(compiler, next) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ yield next();
29
+ const { log } = compiler, target = compiler.options.targets.shift(), deliverable = yield compiler.compileAsync(target), output = (0, path_1.normalize)(compiler.output);
30
+ mkdirp.sync((0, path_1.dirname)(output));
31
+ return new Promise((res, rej) => {
32
+ const step = log.step('Writing result to file');
33
+ deliverable
34
+ .pipe((0, fs_1.createWriteStream)(output))
35
+ .on('error', rej)
36
+ .once('close', (e) => {
37
+ if (e) {
38
+ rej(e);
39
+ }
40
+ else if (compiler.output) {
41
+ const output = compiler.output, mode = (0, fs_1.statSync)(output).mode | 0o111, inputFileLogOutput = (0, path_1.relative)(process.cwd(), (0, path_1.resolve)(compiler.options.cwd, compiler.entrypoint || compiler.options.input)), outputFileLogOutput = (0, path_1.relative)(process.cwd(), output);
42
+ (0, fs_1.chmodSync)(output, mode.toString(8).slice(-3));
43
+ step.log(`Entry: '${compiler.stdinUsed
44
+ ? compiler.options.mangle
45
+ ? util_1.STDIN_FLAG
46
+ : '[none]'
47
+ : inputFileLogOutput}' written to: ${outputFileLogOutput}`);
48
+ compiler.quit();
49
+ res(output);
50
+ }
51
+ });
52
+ });
53
+ });
54
+ }
55
+ exports.default = cli;
@@ -0,0 +1,7 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ /**
3
+ * Downloads the node source to the configured temporary directory
4
+ * @param {*} compiler
5
+ * @param {*} next
6
+ */
7
+ export default function downloadNode(compiler: NexeCompiler, next: () => Promise<void>): Promise<void>;
@@ -0,0 +1,76 @@
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 download = require("download");
13
+ const util_1 = require("../util");
14
+ const compiler_1 = require("../compiler");
15
+ const path_1 = require("path");
16
+ function fetchNodeSourceAsync(dest, url, step, options = {}) {
17
+ const setText = (p) => step.modify(`Downloading Node: ${p.toFixed()}%...`);
18
+ return download(url, dest, Object.assign(options, { extract: true, strip: 1 }))
19
+ .on('response', (res) => {
20
+ const total = +res.headers['content-length'];
21
+ let current = 0;
22
+ res.on('data', (data) => {
23
+ current += data.length;
24
+ setText((current / total) * 100);
25
+ if (current === total) {
26
+ step.log('Extracting Node...');
27
+ }
28
+ });
29
+ })
30
+ .then(() => step.log(`Node source extracted to: ${dest}`));
31
+ }
32
+ function fetchPrebuiltBinary(compiler, step) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const { target, remoteAsset } = compiler, filename = compiler.getNodeExecutableLocation(target);
35
+ try {
36
+ yield download(remoteAsset, (0, path_1.dirname)(filename), compiler.options.downloadOptions).on('response', (res) => {
37
+ const total = +res.headers['content-length'];
38
+ let current = 0;
39
+ res.on('data', (data) => {
40
+ current += data.length;
41
+ step.modify(`Downloading...${((current / total) * 100).toFixed()}%`);
42
+ });
43
+ });
44
+ }
45
+ catch (e) {
46
+ if (e.statusCode === 404) {
47
+ throw new compiler_1.NexeError(`${remoteAsset} is not available, create it using the --build flag`);
48
+ }
49
+ else {
50
+ throw new compiler_1.NexeError('Error downloading prebuilt binary: ' + e);
51
+ }
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Downloads the node source to the configured temporary directory
57
+ * @param {*} compiler
58
+ * @param {*} next
59
+ */
60
+ function downloadNode(compiler, next) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ 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 (0, util_1.pathExistsAsync)(build ? src : exeLocation);
63
+ if (downloadExists) {
64
+ step.log('Already downloaded...');
65
+ return next();
66
+ }
67
+ if (build) {
68
+ yield fetchNodeSourceAsync(src, url, step, downloadOptions);
69
+ }
70
+ else {
71
+ yield fetchPrebuiltBinary(compiler, step);
72
+ }
73
+ return next();
74
+ });
75
+ }
76
+ exports.default = downloadNode;
@@ -0,0 +1,2 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ export default function resource(compiler: NexeCompiler, next: () => Promise<any>): Promise<any>;
@@ -0,0 +1,38 @@
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
+ const util_1 = require("../util");
16
+ const globby_1 = __importDefault(require("globby"));
17
+ const path_1 = require("path");
18
+ function resource(compiler, next) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const { cwd, resources } = compiler.options;
21
+ if (!resources.length) {
22
+ return next();
23
+ }
24
+ const step = compiler.log.step('Bundling Resources...');
25
+ let count = 0;
26
+ // workaround for https://github.com/sindresorhus/globby/issues/127
27
+ // and https://github.com/mrmlnc/fast-glob#pattern-syntax
28
+ const resourcesWithForwardSlashes = resources.map((r) => r.replace(/\\/g, '/'));
29
+ yield (0, util_1.each)((0, globby_1.default)(resourcesWithForwardSlashes, { cwd, onlyFiles: true }), (file) => __awaiter(this, void 0, void 0, function* () {
30
+ count++;
31
+ step.log(`Including file: ${file}`);
32
+ yield compiler.addResource((0, path_1.resolve)(cwd, file));
33
+ }));
34
+ step.log(`Included ${count} file(s)`);
35
+ return next();
36
+ });
37
+ }
38
+ exports.default = resource;
@@ -0,0 +1,2 @@
1
+ import { NexeCompiler } from '../compiler';
2
+ export default function (compiler: NexeCompiler, next: () => Promise<void>): Promise<void>;