@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
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2013-2018 Nexe Contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @depup/nexe
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [nexe](https://www.npmjs.com/package/nexe)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/nexe
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [nexe](https://www.npmjs.com/package/nexe) @ 5.0.0-beta.4 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 10 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| @yarnpkg/fslib | ^3.0.0-rc.43 | ^3.1.4 |
|
|
26
|
+
| @yarnpkg/libzip | ^3.0.0-rc.43 | ^3.2.2 |
|
|
27
|
+
| archiver | ^5.3.1 | ^7.0.1 |
|
|
28
|
+
| chalk | ^2.4.2 | ^5.6.2 |
|
|
29
|
+
| globby | ^11.0.2 | ^16.1.1 |
|
|
30
|
+
| got | ^12.6.0 | ^14.6.6 |
|
|
31
|
+
| meriyah | ^4.3.5 | ^7.1.0 |
|
|
32
|
+
| mkdirp | ^1.0.4 | ^3.0.1 |
|
|
33
|
+
| ora | ^3.4.0 | ^9.3.0 |
|
|
34
|
+
| rimraf | ^3.0.2 | ^6.1.3 |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/nexe
|
|
39
|
+
|
|
40
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bumped": {
|
|
3
|
+
"@yarnpkg/fslib": {
|
|
4
|
+
"from": "^3.0.0-rc.43",
|
|
5
|
+
"to": "^3.1.4"
|
|
6
|
+
},
|
|
7
|
+
"@yarnpkg/libzip": {
|
|
8
|
+
"from": "^3.0.0-rc.43",
|
|
9
|
+
"to": "^3.2.2"
|
|
10
|
+
},
|
|
11
|
+
"archiver": {
|
|
12
|
+
"from": "^5.3.1",
|
|
13
|
+
"to": "^7.0.1"
|
|
14
|
+
},
|
|
15
|
+
"chalk": {
|
|
16
|
+
"from": "^2.4.2",
|
|
17
|
+
"to": "^5.6.2"
|
|
18
|
+
},
|
|
19
|
+
"globby": {
|
|
20
|
+
"from": "^11.0.2",
|
|
21
|
+
"to": "^16.1.1"
|
|
22
|
+
},
|
|
23
|
+
"got": {
|
|
24
|
+
"from": "^12.6.0",
|
|
25
|
+
"to": "^14.6.6"
|
|
26
|
+
},
|
|
27
|
+
"meriyah": {
|
|
28
|
+
"from": "^4.3.5",
|
|
29
|
+
"to": "^7.1.0"
|
|
30
|
+
},
|
|
31
|
+
"mkdirp": {
|
|
32
|
+
"from": "^1.0.4",
|
|
33
|
+
"to": "^3.0.1"
|
|
34
|
+
},
|
|
35
|
+
"ora": {
|
|
36
|
+
"from": "^3.4.0",
|
|
37
|
+
"to": "^9.3.0"
|
|
38
|
+
},
|
|
39
|
+
"rimraf": {
|
|
40
|
+
"from": "^3.0.2",
|
|
41
|
+
"to": "^6.1.3"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"timestamp": "2026-03-17T19:30:12.638Z",
|
|
45
|
+
"totalUpdated": 10
|
|
46
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const options = require('./lib/options')
|
|
3
|
+
if (require.main === module) {
|
|
4
|
+
//fast path for help/version
|
|
5
|
+
const argv = options.argv
|
|
6
|
+
const eol = require('os').EOL
|
|
7
|
+
const showHelp = argv.help || argv._.some(x => x === 'help')
|
|
8
|
+
const showVersion = argv.version || argv._.some(x => x === 'version')
|
|
9
|
+
if (showHelp || showVersion) {
|
|
10
|
+
process.stderr.write(showHelp ? options.help : options.version + eol)
|
|
11
|
+
} else {
|
|
12
|
+
const nexe = require('./lib/nexe')
|
|
13
|
+
nexe.compile(argv).catch((error) => {
|
|
14
|
+
const NexeError = require('./lib/compiler').NexeError
|
|
15
|
+
const chalk = require('chalk')
|
|
16
|
+
const isSilent = Boolean(argv.silent === true || argv.loglevel === 'silent')
|
|
17
|
+
if (!isSilent) {
|
|
18
|
+
if (error instanceof NexeError) {
|
|
19
|
+
process.stderr.write(eol + chalk.red('Error: ') + error.message + eol
|
|
20
|
+
+ eol + 'See nexe -h for usage..' + eol + eol
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
process.stderr.write(error.stack + eol)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
process.exit(1)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
module.exports = require('./lib/nexe')
|
|
32
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
5
|
+
import { ReadStream } from 'fs';
|
|
6
|
+
import { Logger } from './logger';
|
|
7
|
+
import { NexeOptions } from './options';
|
|
8
|
+
import { NexeTarget } from './target';
|
|
9
|
+
import { Readable } from 'stream';
|
|
10
|
+
import { Bundle } from './fs/bundle';
|
|
11
|
+
import { File } from 'resolve-dependencies';
|
|
12
|
+
type StringReplacer = (match: string) => string;
|
|
13
|
+
export interface NexeFile {
|
|
14
|
+
filename: string;
|
|
15
|
+
absPath: string;
|
|
16
|
+
contents: string | Buffer;
|
|
17
|
+
}
|
|
18
|
+
export { NexeOptions };
|
|
19
|
+
export declare class NexeError extends Error {
|
|
20
|
+
constructor(m: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class NexeCompiler {
|
|
23
|
+
options: NexeOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Epoch of when compilation started
|
|
26
|
+
*/
|
|
27
|
+
private start;
|
|
28
|
+
private compileStep;
|
|
29
|
+
log: Logger;
|
|
30
|
+
/**
|
|
31
|
+
* Copy of process.env
|
|
32
|
+
*/
|
|
33
|
+
env: {
|
|
34
|
+
[x: string]: string | undefined;
|
|
35
|
+
TZ?: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Virtual FileSystem
|
|
39
|
+
*/
|
|
40
|
+
bundle: Bundle;
|
|
41
|
+
/**
|
|
42
|
+
* Root directory for the source of the current build
|
|
43
|
+
*/
|
|
44
|
+
src: string;
|
|
45
|
+
/**
|
|
46
|
+
* In memory files that are being manipulated by the compiler
|
|
47
|
+
*/
|
|
48
|
+
files: NexeFile[];
|
|
49
|
+
/**
|
|
50
|
+
* Standalone pieces of code run before the application entrypoint
|
|
51
|
+
*/
|
|
52
|
+
shims: string[];
|
|
53
|
+
/**
|
|
54
|
+
* The last shim (defaults to "require('module').runMain()")
|
|
55
|
+
*/
|
|
56
|
+
startup: string;
|
|
57
|
+
/**
|
|
58
|
+
* The main entrypoint filename for your application - eg. node mainFile.js
|
|
59
|
+
*/
|
|
60
|
+
entrypoint: string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Not used
|
|
63
|
+
*/
|
|
64
|
+
targets: NexeTarget[];
|
|
65
|
+
/**
|
|
66
|
+
* Current target of the compiler
|
|
67
|
+
*/
|
|
68
|
+
target: NexeTarget;
|
|
69
|
+
/**
|
|
70
|
+
* Output filename (-o myapp.exe)
|
|
71
|
+
*/
|
|
72
|
+
output: string;
|
|
73
|
+
/**
|
|
74
|
+
* Flag to indicate whether or notstdin was used for input
|
|
75
|
+
*/
|
|
76
|
+
stdinUsed: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Path to the configure script
|
|
79
|
+
*/
|
|
80
|
+
configureScript: string;
|
|
81
|
+
/**
|
|
82
|
+
* The file path of node binary
|
|
83
|
+
*/
|
|
84
|
+
nodeSrcBinPath: string;
|
|
85
|
+
/**
|
|
86
|
+
* Remote asset path if available
|
|
87
|
+
*/
|
|
88
|
+
remoteAsset: string;
|
|
89
|
+
constructor(options: NexeOptions);
|
|
90
|
+
addResource(absoluteFileName: string, content?: Buffer | string | File): void;
|
|
91
|
+
readFileAsync(file: string): Promise<NexeFile>;
|
|
92
|
+
writeFileAsync(file: string, contents: string | Buffer): Promise<void>;
|
|
93
|
+
replaceInFileAsync(file: string, replace: string | RegExp, value: string | StringReplacer): Promise<void>;
|
|
94
|
+
setFileContentsAsync(file: string, contents: string | Buffer): Promise<void>;
|
|
95
|
+
quit(error?: any): Promise<unknown>;
|
|
96
|
+
assertBuild(): void;
|
|
97
|
+
getNodeExecutableLocation(target?: NexeTarget): string;
|
|
98
|
+
private _runBuildCommandAsync;
|
|
99
|
+
private _configureAsync;
|
|
100
|
+
build(): Promise<ReadStream>;
|
|
101
|
+
private _shouldCompileBinaryAsync;
|
|
102
|
+
compileAsync(target: NexeTarget): Promise<Readable>;
|
|
103
|
+
code(): string;
|
|
104
|
+
private _assembleDeliverable;
|
|
105
|
+
}
|
package/lib/compiler.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NexeCompiler = exports.NexeError = void 0;
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const buffer_1 = require("buffer");
|
|
21
|
+
const fs_1 = require("fs");
|
|
22
|
+
const child_process_1 = require("child_process");
|
|
23
|
+
const logger_1 = require("./logger");
|
|
24
|
+
const util_1 = require("./util");
|
|
25
|
+
const options_1 = require("./options");
|
|
26
|
+
const stream_1 = require("stream");
|
|
27
|
+
const MultiStream = require("multistream");
|
|
28
|
+
const bundle_1 = require("./fs/bundle");
|
|
29
|
+
const isBsd = Boolean(~process.platform.indexOf('bsd'));
|
|
30
|
+
const make = util_1.isWindows ? 'vcbuild.bat' : isBsd ? 'gmake' : 'make';
|
|
31
|
+
const configure = util_1.isWindows ? 'configure' : './configure';
|
|
32
|
+
class NexeError extends Error {
|
|
33
|
+
constructor(m) {
|
|
34
|
+
super(m);
|
|
35
|
+
Object.setPrototypeOf(this, NexeError.prototype);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.NexeError = NexeError;
|
|
39
|
+
class NexeCompiler {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
/**
|
|
43
|
+
* Epoch of when compilation started
|
|
44
|
+
*/
|
|
45
|
+
this.start = Date.now();
|
|
46
|
+
this.log = new logger_1.Logger(this.options.loglevel);
|
|
47
|
+
/**
|
|
48
|
+
* Copy of process.env
|
|
49
|
+
*/
|
|
50
|
+
this.env = Object.assign({}, process.env);
|
|
51
|
+
/**
|
|
52
|
+
* In memory files that are being manipulated by the compiler
|
|
53
|
+
*/
|
|
54
|
+
this.files = [];
|
|
55
|
+
/**
|
|
56
|
+
* Standalone pieces of code run before the application entrypoint
|
|
57
|
+
*/
|
|
58
|
+
this.shims = [];
|
|
59
|
+
/**
|
|
60
|
+
* The last shim (defaults to "require('module').runMain()")
|
|
61
|
+
*/
|
|
62
|
+
this.startup = '';
|
|
63
|
+
/**
|
|
64
|
+
* Output filename (-o myapp.exe)
|
|
65
|
+
*/
|
|
66
|
+
this.output = this.options.output;
|
|
67
|
+
/**
|
|
68
|
+
* Flag to indicate whether or notstdin was used for input
|
|
69
|
+
*/
|
|
70
|
+
this.stdinUsed = false;
|
|
71
|
+
const { python } = (this.options = options);
|
|
72
|
+
//SOMEDAY iterate over multiple targets with `--outDir`
|
|
73
|
+
this.targets = options.targets;
|
|
74
|
+
this.target = this.targets[0];
|
|
75
|
+
if (!/https?\:\/\//.test(options.remote)) {
|
|
76
|
+
throw new NexeError(`Invalid remote URI scheme (must be http or https): ${options.remote}`);
|
|
77
|
+
}
|
|
78
|
+
this.remoteAsset = options.remote + this.target.toString();
|
|
79
|
+
this.src = (0, path_1.join)(this.options.temp, this.target.version);
|
|
80
|
+
this.configureScript = configure + ((0, util_1.semverGt)(this.target.version, '10.10.0') ? '.py' : '');
|
|
81
|
+
this.nodeSrcBinPath = util_1.isWindows
|
|
82
|
+
? (0, path_1.join)(this.src, 'Release', 'node.exe')
|
|
83
|
+
: (0, path_1.join)(this.src, 'out', 'Release', 'node');
|
|
84
|
+
this.log.step('nexe ' + options_1.version, 'info');
|
|
85
|
+
this.bundle = new bundle_1.Bundle(options);
|
|
86
|
+
if (util_1.isWindows) {
|
|
87
|
+
const originalPath = process.env.PATH;
|
|
88
|
+
delete process.env.PATH;
|
|
89
|
+
this.env = Object.assign({}, process.env);
|
|
90
|
+
this.env.PATH = python
|
|
91
|
+
? (this.env.PATH = (0, util_1.dequote)((0, path_1.normalize)(python)) + path_1.delimiter + originalPath)
|
|
92
|
+
: originalPath;
|
|
93
|
+
process.env.PATH = originalPath;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.env = Object.assign({}, process.env);
|
|
97
|
+
python && (this.env.PYTHON = python);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
addResource(absoluteFileName, content) {
|
|
101
|
+
return this.bundle.addResource(absoluteFileName, content);
|
|
102
|
+
}
|
|
103
|
+
readFileAsync(file) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
this.assertBuild();
|
|
106
|
+
let cachedFile = this.files.find((x) => (0, path_1.normalize)(x.filename) === (0, path_1.normalize)(file));
|
|
107
|
+
if (!cachedFile) {
|
|
108
|
+
const absPath = (0, path_1.join)(this.src, file);
|
|
109
|
+
cachedFile = {
|
|
110
|
+
absPath,
|
|
111
|
+
filename: file,
|
|
112
|
+
contents: yield (0, util_1.readFileAsync)(absPath, 'utf-8').catch((x) => {
|
|
113
|
+
if (x.code === 'ENOENT')
|
|
114
|
+
return '';
|
|
115
|
+
throw x;
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
this.files.push(cachedFile);
|
|
119
|
+
}
|
|
120
|
+
return cachedFile;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
writeFileAsync(file, contents) {
|
|
124
|
+
this.assertBuild();
|
|
125
|
+
return (0, util_1.writeFileAsync)((0, path_1.join)(this.src, file), contents);
|
|
126
|
+
}
|
|
127
|
+
replaceInFileAsync(file, replace, value) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const entry = yield this.readFileAsync(file);
|
|
130
|
+
entry.contents = entry.contents.toString().replace(replace, value);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
setFileContentsAsync(file, contents) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const entry = yield this.readFileAsync(file);
|
|
136
|
+
entry.contents = contents;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
quit(error) {
|
|
140
|
+
const time = Date.now() - this.start;
|
|
141
|
+
this.log.write(`Finished in ${time / 1000}s`, error ? 'red' : 'green');
|
|
142
|
+
return this.log.flush();
|
|
143
|
+
}
|
|
144
|
+
assertBuild() {
|
|
145
|
+
if (!this.options.build) {
|
|
146
|
+
throw new NexeError('This feature is only available with `--build`');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
getNodeExecutableLocation(target) {
|
|
150
|
+
if (this.options.asset) {
|
|
151
|
+
return (0, path_1.resolve)(this.options.cwd, this.options.asset);
|
|
152
|
+
}
|
|
153
|
+
if (target) {
|
|
154
|
+
return (0, path_1.join)(this.options.temp, target.toString());
|
|
155
|
+
}
|
|
156
|
+
return this.nodeSrcBinPath;
|
|
157
|
+
}
|
|
158
|
+
_runBuildCommandAsync(command, args) {
|
|
159
|
+
if (this.log.verbose) {
|
|
160
|
+
this.compileStep.pause();
|
|
161
|
+
}
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
(0, child_process_1.spawn)(command, args, {
|
|
164
|
+
cwd: this.src,
|
|
165
|
+
env: this.env,
|
|
166
|
+
shell: true,
|
|
167
|
+
stdio: this.log.verbose ? 'inherit' : 'ignore',
|
|
168
|
+
})
|
|
169
|
+
.once('error', (e) => {
|
|
170
|
+
if (this.log.verbose) {
|
|
171
|
+
this.compileStep.resume();
|
|
172
|
+
}
|
|
173
|
+
reject(e);
|
|
174
|
+
})
|
|
175
|
+
.once('close', (code) => {
|
|
176
|
+
if (this.log.verbose) {
|
|
177
|
+
this.compileStep.resume();
|
|
178
|
+
}
|
|
179
|
+
if (code != 0) {
|
|
180
|
+
const error = `${command} ${args.join(' ')} exited with code: ${code}`;
|
|
181
|
+
reject(new NexeError(error));
|
|
182
|
+
}
|
|
183
|
+
resolve();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
_configureAsync() {
|
|
188
|
+
if (util_1.isWindows && (0, util_1.semverGt)(this.target.version, '10.15.99')) {
|
|
189
|
+
return Promise.resolve();
|
|
190
|
+
}
|
|
191
|
+
return this._runBuildCommandAsync(this.env.PYTHON || 'python', [
|
|
192
|
+
this.configureScript,
|
|
193
|
+
...this.options.configure,
|
|
194
|
+
]);
|
|
195
|
+
}
|
|
196
|
+
build() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
this.compileStep.log(`Configuring node build${this.options.configure.length ? ': ' + this.options.configure : '...'}`);
|
|
199
|
+
yield this._configureAsync();
|
|
200
|
+
const buildOptions = this.options.make;
|
|
201
|
+
this.compileStep.log(`Compiling Node${buildOptions.length ? ' with arguments: ' + buildOptions : '...'}`);
|
|
202
|
+
yield this._runBuildCommandAsync(make, buildOptions);
|
|
203
|
+
return (0, fs_1.createReadStream)(this.getNodeExecutableLocation());
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
_shouldCompileBinaryAsync(binary, location) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
//SOMEDAY combine make/configure/vcBuild/and modified times of included files
|
|
209
|
+
const { snapshot, build } = this.options;
|
|
210
|
+
if (!binary) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
if (build && snapshot != null && (yield (0, util_1.pathExistsAsync)(snapshot))) {
|
|
214
|
+
const snapshotLastModified = (yield (0, util_1.statAsync)(snapshot)).mtimeMs;
|
|
215
|
+
const binaryLastModified = (yield (0, util_1.statAsync)(location)).mtimeMs;
|
|
216
|
+
return snapshotLastModified > binaryLastModified;
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
compileAsync(target) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const step = (this.compileStep = this.log.step('Compiling result'));
|
|
224
|
+
const build = this.options.build;
|
|
225
|
+
const location = this.getNodeExecutableLocation(build ? undefined : target);
|
|
226
|
+
let binary = (yield (0, util_1.pathExistsAsync)(location)) ? (0, fs_1.createReadStream)(location) : null;
|
|
227
|
+
if (yield this._shouldCompileBinaryAsync(binary, location)) {
|
|
228
|
+
binary = yield this.build();
|
|
229
|
+
step.log('Node binary compiled');
|
|
230
|
+
}
|
|
231
|
+
return this._assembleDeliverable(binary);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
code() {
|
|
235
|
+
return [this.shims.join(''), this.startup].join(';');
|
|
236
|
+
}
|
|
237
|
+
_assembleDeliverable(binary) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
if (!this.options.mangle) {
|
|
240
|
+
return binary;
|
|
241
|
+
}
|
|
242
|
+
const launchCode = this.code();
|
|
243
|
+
const codeSize = buffer_1.Buffer.byteLength(launchCode);
|
|
244
|
+
const sentinel = buffer_1.Buffer.from('<nexe~~sentinel>');
|
|
245
|
+
let vfsSize = 0;
|
|
246
|
+
const streams = [
|
|
247
|
+
binary,
|
|
248
|
+
(0, bundle_1.toStream)(launchCode),
|
|
249
|
+
this.bundle.toStream().pipe(new stream_1.Transform({
|
|
250
|
+
transform: (chunk, _, cb) => {
|
|
251
|
+
vfsSize || this.bundle.finalize();
|
|
252
|
+
chunk && (vfsSize += chunk.length);
|
|
253
|
+
cb(null, chunk);
|
|
254
|
+
},
|
|
255
|
+
})),
|
|
256
|
+
];
|
|
257
|
+
let done = false;
|
|
258
|
+
return new MultiStream((cb) => {
|
|
259
|
+
if (done)
|
|
260
|
+
cb(null, null);
|
|
261
|
+
else if (streams.length)
|
|
262
|
+
cb(null, streams.shift());
|
|
263
|
+
else {
|
|
264
|
+
done = true;
|
|
265
|
+
const trailers = buffer_1.Buffer.alloc(16);
|
|
266
|
+
trailers.writeDoubleLE(codeSize, 0);
|
|
267
|
+
trailers.writeDoubleLE(vfsSize, 8);
|
|
268
|
+
cb(null, (0, bundle_1.toStream)(buffer_1.Buffer.concat([sentinel, trailers])));
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
__decorate([
|
|
275
|
+
util_1.bound
|
|
276
|
+
], NexeCompiler.prototype, "addResource", null);
|
|
277
|
+
__decorate([
|
|
278
|
+
util_1.bound
|
|
279
|
+
], NexeCompiler.prototype, "readFileAsync", null);
|
|
280
|
+
__decorate([
|
|
281
|
+
util_1.bound
|
|
282
|
+
], NexeCompiler.prototype, "writeFileAsync", null);
|
|
283
|
+
__decorate([
|
|
284
|
+
util_1.bound
|
|
285
|
+
], NexeCompiler.prototype, "replaceInFileAsync", null);
|
|
286
|
+
__decorate([
|
|
287
|
+
util_1.bound
|
|
288
|
+
], NexeCompiler.prototype, "setFileContentsAsync", null);
|
|
289
|
+
exports.NexeCompiler = NexeCompiler;
|
package/lib/fs/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# nexe-fs
|
|
2
|
+
|
|
3
|
+
### Getting Started:
|
|
4
|
+
|
|
5
|
+
This module contains a set of patches used to create (and use) the Nexe Virtual FileSystem
|
|
6
|
+
|
|
7
|
+
In order for NVFS to work with node's `require` method. A custom build of node must be used. If using the `nexe` cli this will be handled automatically
|
|
8
|
+
|
|
9
|
+
The customization should be applied as early as possbile when node is starting up.
|
|
10
|
+
|
|
11
|
+
i.e. The contents of `nexe-fs/bootstrap` should be put [here](https://github.com/nodejs/node/blob/0827c80920311fa9d1e6989c8a73aaaeca962eb7/lib/internal/bootstrap/node.js#L27-L28).
|
|
12
|
+
|
|
13
|
+
### Creating a NVFS:
|
|
14
|
+
|
|
15
|
+
To create a virtual file system use the `Bundle` Object, in your build process:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const { Bundle } = require('nexe-fs')
|
|
19
|
+
|
|
20
|
+
const bundle = new Bundle()
|
|
21
|
+
await bundle.addResource(absoluteFileName)
|
|
22
|
+
|
|
23
|
+
bundle.toStream().pipe(fs.createWriteStream('./myFsBlob'))
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
In the entrypoint of your application, the fs patch needs to be applied (executed as early as possible)
|
|
27
|
+
For example, In the build process, the application's entrypoint could be prepended with the following:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const codeToPrependToEntrypoint = fs.readFileSync(require.resolve('nexe-fs/patch'), 'utf-8') + `
|
|
31
|
+
shimFs({
|
|
32
|
+
blobPath: 'location/of/myFsBlob',
|
|
33
|
+
resources: ${JSON.stringify(bundle)},
|
|
34
|
+
layout: {
|
|
35
|
+
resourceStart: 0 // the offset within the blob that is referenced by the bundle index
|
|
36
|
+
}
|
|
37
|
+
})`
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Since a custom node build is being used. A great place for this code would be the node source file: `_third_party_main.js`
|