@hakobu/hakobu 1.0.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 +21 -0
- package/README.md +673 -0
- package/dictionary/angular-bridge.js +3 -0
- package/dictionary/any-promise.js +3 -0
- package/dictionary/async.js +3 -0
- package/dictionary/aws-sdk.js +7 -0
- package/dictionary/babel-core.js +3 -0
- package/dictionary/batch.js +3 -0
- package/dictionary/bcrypt.js +3 -0
- package/dictionary/better-sqlite3.js +3 -0
- package/dictionary/bignum.js +3 -0
- package/dictionary/bindings.js +3 -0
- package/dictionary/blessed.js +8 -0
- package/dictionary/body-parser.js +9 -0
- package/dictionary/browserify.js +7 -0
- package/dictionary/bson.js +3 -0
- package/dictionary/buffermaker.js +7 -0
- package/dictionary/bunyan.js +9 -0
- package/dictionary/busboy.js +7 -0
- package/dictionary/bytes.js +3 -0
- package/dictionary/callsites.js +3 -0
- package/dictionary/chokidar.js +3 -0
- package/dictionary/coffee-script.js +7 -0
- package/dictionary/colors.js +3 -0
- package/dictionary/compression.js +3 -0
- package/dictionary/compressjs.js +7 -0
- package/dictionary/connect-mongo.js +3 -0
- package/dictionary/connect-mongodb.js +3 -0
- package/dictionary/connect-redis.js +3 -0
- package/dictionary/connect.js +10 -0
- package/dictionary/consolidate.js +3 -0
- package/dictionary/cookie-parser.js +3 -0
- package/dictionary/cookie.js +3 -0
- package/dictionary/cors.js +3 -0
- package/dictionary/cron.js +3 -0
- package/dictionary/cross-env.js +11 -0
- package/dictionary/cross-spawn-async.js +3 -0
- package/dictionary/curve25519.js +3 -0
- package/dictionary/data-preflight.js +7 -0
- package/dictionary/debug.js +3 -0
- package/dictionary/denymount.js +3 -0
- package/dictionary/diff.js +3 -0
- package/dictionary/drivelist.js +22 -0
- package/dictionary/ed25519.js +3 -0
- package/dictionary/ejs.js +3 -0
- package/dictionary/elasticsearch.js +3 -0
- package/dictionary/electron.js +17 -0
- package/dictionary/emailjs.js +3 -0
- package/dictionary/engine.io.js +3 -0
- package/dictionary/epoll.js +3 -0
- package/dictionary/errorhandler.js +7 -0
- package/dictionary/errors.js +7 -0
- package/dictionary/eslint.js +7 -0
- package/dictionary/etcher-image-write.js +3 -0
- package/dictionary/exceljs.js +21 -0
- package/dictionary/exiftool.exe.js +13 -0
- package/dictionary/exiftool.pl.js +13 -0
- package/dictionary/express-load.js +12 -0
- package/dictionary/express-session.js +3 -0
- package/dictionary/express.js +14 -0
- package/dictionary/extender.js +11 -0
- package/dictionary/extsprintf.js +3 -0
- package/dictionary/faye-websocket.js +3 -0
- package/dictionary/feathers.js +3 -0
- package/dictionary/findup-sync.js +3 -0
- package/dictionary/floordate.js +3 -0
- package/dictionary/fmt.js +3 -0
- package/dictionary/formidable.js +3 -0
- package/dictionary/fs-extra.js +3 -0
- package/dictionary/fsevents.js +3 -0
- package/dictionary/geoip-lite.js +7 -0
- package/dictionary/github.js +7 -0
- package/dictionary/gm.js +3 -0
- package/dictionary/google-closure-compiler-java.js +13 -0
- package/dictionary/google-closure-compiler.js +13 -0
- package/dictionary/googleapis.js +7 -0
- package/dictionary/got.js +3 -0
- package/dictionary/graceful-fs.js +19 -0
- package/dictionary/grpc.js +11 -0
- package/dictionary/gulp.js +3 -0
- package/dictionary/hap-nodejs.js +3 -0
- package/dictionary/heapdump.js +3 -0
- package/dictionary/hoek.js +3 -0
- package/dictionary/homebridge.js +3 -0
- package/dictionary/http-proxy.js +3 -0
- package/dictionary/http-server.js +3 -0
- package/dictionary/image-size.js +3 -0
- package/dictionary/indexof.js +3 -0
- package/dictionary/inquirer.js +3 -0
- package/dictionary/j.js +16 -0
- package/dictionary/jade.js +3 -0
- package/dictionary/jsdom.js +3 -0
- package/dictionary/json-stringify-date.js +3 -0
- package/dictionary/json-stringify-safe.js +3 -0
- package/dictionary/jsonwebtoken.js +3 -0
- package/dictionary/kerberos.js +3 -0
- package/dictionary/knex.js +7 -0
- package/dictionary/later.js +7 -0
- package/dictionary/level.js +3 -0
- package/dictionary/leveldown.js +10 -0
- package/dictionary/levelup.js +3 -0
- package/dictionary/liftoff.js +12 -0
- package/dictionary/lodash.js +3 -0
- package/dictionary/log4js.js +7 -0
- package/dictionary/logform.js +7 -0
- package/dictionary/machinepack-urls.js +7 -0
- package/dictionary/markdown.js +3 -0
- package/dictionary/mdns.js +6 -0
- package/dictionary/method-override.js +3 -0
- package/dictionary/microjob.js +16 -0
- package/dictionary/mime-types.js +3 -0
- package/dictionary/mime.js +3 -0
- package/dictionary/minimatch.js +3 -0
- package/dictionary/minstache.js +3 -0
- package/dictionary/module-deps.js +3 -0
- package/dictionary/moment-timezone.js +3 -0
- package/dictionary/moment.js +7 -0
- package/dictionary/mongodb-core.js +22 -0
- package/dictionary/mongodb.js +7 -0
- package/dictionary/mongoose.js +7 -0
- package/dictionary/mongoskin.js +7 -0
- package/dictionary/ms.js +3 -0
- package/dictionary/msgpack.js +3 -0
- package/dictionary/multer.js +3 -0
- package/dictionary/muri.js +3 -0
- package/dictionary/native-or-bluebird.js +3 -0
- package/dictionary/natives.js +3 -0
- package/dictionary/nconf.js +7 -0
- package/dictionary/nedb.js +3 -0
- package/dictionary/negotiator.js +7 -0
- package/dictionary/newrelic.js +3 -0
- package/dictionary/nib.js +3 -0
- package/dictionary/nightmare.js +18 -0
- package/dictionary/node-forge.js +7 -0
- package/dictionary/node-libcurl.js +3 -0
- package/dictionary/node-notifier.js +30 -0
- package/dictionary/node-pre-gyp.js +7 -0
- package/dictionary/node-redis-pubsub.js +3 -0
- package/dictionary/node-sass.js +3 -0
- package/dictionary/node-uuid.js +3 -0
- package/dictionary/node-xlsx.js +3 -0
- package/dictionary/node-zookeeper-client.js +7 -0
- package/dictionary/nodegit.js +7 -0
- package/dictionary/nodemailer-sendmail-transport.js +3 -0
- package/dictionary/nodemailer.js +3 -0
- package/dictionary/npm-registry-client.js +7 -0
- package/dictionary/npm.js +7 -0
- package/dictionary/nssocket.js +3 -0
- package/dictionary/oauth2orize.js +7 -0
- package/dictionary/octobat.js +3 -0
- package/dictionary/open.js +13 -0
- package/dictionary/opn.js +4 -0
- package/dictionary/optimist.js +3 -0
- package/dictionary/passport-local.js +3 -0
- package/dictionary/passport.js +3 -0
- package/dictionary/pg-cursor.js +3 -0
- package/dictionary/pg-query-stream.js +3 -0
- package/dictionary/pg-types.js +7 -0
- package/dictionary/pg.js +7 -0
- package/dictionary/pg.js.js +7 -0
- package/dictionary/pgpass.js +7 -0
- package/dictionary/phantom.js +19 -0
- package/dictionary/phantomjs-prebuilt.js +16 -0
- package/dictionary/pkginfo.js +3 -0
- package/dictionary/pm2.js +7 -0
- package/dictionary/pmx.js +3 -0
- package/dictionary/pouchdb.js +3 -0
- package/dictionary/primus-emitter.js +3 -0
- package/dictionary/primus-spark-latency.js +3 -0
- package/dictionary/primus.js +3 -0
- package/dictionary/publicsuffixlist.js +15 -0
- package/dictionary/pug.js +3 -0
- package/dictionary/punt.js +3 -0
- package/dictionary/puppeteer.js +13 -0
- package/dictionary/pwd.js +3 -0
- package/dictionary/q.js +3 -0
- package/dictionary/raven.js +3 -0
- package/dictionary/rc.js +12 -0
- package/dictionary/readable-stream.js +3 -0
- package/dictionary/rechoir.js +3 -0
- package/dictionary/redis-parser.js +3 -0
- package/dictionary/redis.js +3 -0
- package/dictionary/regression.js +3 -0
- package/dictionary/reload.js +7 -0
- package/dictionary/request.js +3 -0
- package/dictionary/require-uncached.js +3 -0
- package/dictionary/require_optional.js +3 -0
- package/dictionary/s3.js +3 -0
- package/dictionary/safe_datejs.js +3 -0
- package/dictionary/sails.js +33 -0
- package/dictionary/sax.js +3 -0
- package/dictionary/scrypt.js +3 -0
- package/dictionary/semver.js +3 -0
- package/dictionary/sequelize.js +7 -0
- package/dictionary/serialport.js +3 -0
- package/dictionary/sha3.js +3 -0
- package/dictionary/sharp.js +11 -0
- package/dictionary/shelljs.js +7 -0
- package/dictionary/sinon.js +3 -0
- package/dictionary/socket.io-client.js +13 -0
- package/dictionary/socket.io.js +12 -0
- package/dictionary/sqip.js +7 -0
- package/dictionary/sqlite3.js +7 -0
- package/dictionary/steam-crypto.js +7 -0
- package/dictionary/steam-resources.js +19 -0
- package/dictionary/steam.js +3 -0
- package/dictionary/stripe-webhook-middleware.js +3 -0
- package/dictionary/stripe.js +3 -0
- package/dictionary/strong-globalize.js +3 -0
- package/dictionary/stylus.js +14 -0
- package/dictionary/supervisor.js +3 -0
- package/dictionary/svgo.js +8 -0
- package/dictionary/tabtab.js +3 -0
- package/dictionary/tesseract.js.js +7 -0
- package/dictionary/thread-stream.js +7 -0
- package/dictionary/throng.js +3 -0
- package/dictionary/time.js +3 -0
- package/dictionary/tinify.js +7 -0
- package/dictionary/tiny-worker.js +7 -0
- package/dictionary/tmp.js +3 -0
- package/dictionary/transformers.js +3 -0
- package/dictionary/uglify-js.js +9 -0
- package/dictionary/umd.js +19 -0
- package/dictionary/underscore.js +3 -0
- package/dictionary/union.js +3 -0
- package/dictionary/update-notifier.js +3 -0
- package/dictionary/usage.js +7 -0
- package/dictionary/v8flags.js +13 -0
- package/dictionary/verror.js +3 -0
- package/dictionary/voc.js +3 -0
- package/dictionary/webdriverio.js +7 -0
- package/dictionary/winston-uber.js +7 -0
- package/dictionary/winston.js +7 -0
- package/dictionary/ws.js +3 -0
- package/dictionary/xlsx.js +16 -0
- package/dictionary/xml2js.js +3 -0
- package/dictionary/yargs.js +3 -0
- package/dictionary/zeromq.js +13 -0
- package/lib-es5/addon-extract.js +164 -0
- package/lib-es5/analyzer.js +687 -0
- package/lib-es5/app-bundle.js +133 -0
- package/lib-es5/appdir.js +265 -0
- package/lib-es5/bin.js +304 -0
- package/lib-es5/bootstrap.js +179 -0
- package/lib-es5/bundler.js +496 -0
- package/lib-es5/chmod.js +15 -0
- package/lib-es5/colors.js +12 -0
- package/lib-es5/commands.js +376 -0
- package/lib-es5/common.js +328 -0
- package/lib-es5/compress_type.js +10 -0
- package/lib-es5/config.js +291 -0
- package/lib-es5/detector.js +421 -0
- package/lib-es5/esm-hooks.js +366 -0
- package/lib-es5/esm-resolver.js +292 -0
- package/lib-es5/esm-transformer.js +378 -0
- package/lib-es5/exports-resolver.js +184 -0
- package/lib-es5/external-artifacts.js +170 -0
- package/lib-es5/fabricator.js +137 -0
- package/lib-es5/follow.js +190 -0
- package/lib-es5/help.js +52 -0
- package/lib-es5/index.d.ts +2 -0
- package/lib-es5/index.js +552 -0
- package/lib-es5/log.js +7 -0
- package/lib-es5/mach-o.js +262 -0
- package/lib-es5/manifest.js +21 -0
- package/lib-es5/options.js +19 -0
- package/lib-es5/packager.js +1036 -0
- package/lib-es5/packer.js +137 -0
- package/lib-es5/pe-metadata.js +130 -0
- package/lib-es5/producer.js +378 -0
- package/lib-es5/refiner.js +87 -0
- package/lib-es5/resolver.js +142 -0
- package/lib-es5/runtime-diagnostics.js +172 -0
- package/lib-es5/sea.js +307 -0
- package/lib-es5/snapshot-fs-patch.js +396 -0
- package/lib-es5/snapshot-fs.js +255 -0
- package/lib-es5/snapshot-index.js +135 -0
- package/lib-es5/snapshot-path.js +168 -0
- package/lib-es5/types.js +9 -0
- package/lib-es5/walker.js +1019 -0
- package/lib-es5/windows-sign.js +139 -0
- package/package.json +99 -0
- package/prelude/bootstrap.js +2263 -0
- package/prelude/diagnostic.js +147 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hakobu External Artifact Runtime
|
|
4
|
+
*
|
|
5
|
+
* Manages declared external artifacts — files or directories that are
|
|
6
|
+
* intentionally kept outside the packaged executable. Examples:
|
|
7
|
+
*
|
|
8
|
+
* - Browser binaries (Playwright, Camoufox)
|
|
9
|
+
* - ffmpeg or other helper tools
|
|
10
|
+
* - Large data files
|
|
11
|
+
*
|
|
12
|
+
* External artifacts are:
|
|
13
|
+
* - Declared explicitly in the packaging manifest (not guessed)
|
|
14
|
+
* - Resolved at runtime to real filesystem paths
|
|
15
|
+
* - NOT embedded in the snapshot
|
|
16
|
+
* - Validated at startup (required artifacts must exist)
|
|
17
|
+
*
|
|
18
|
+
* Resolution strategy:
|
|
19
|
+
* 1. Check HAKOBU_EXTERNAL_{NAME} env var (uppercase, dashes→underscores)
|
|
20
|
+
* 2. Check {execDir}/externals/{name}/ (relative to the executable)
|
|
21
|
+
* 3. Check the declared pattern path (absolute or relative to cwd)
|
|
22
|
+
* 4. If required and not found → throw with clear guidance
|
|
23
|
+
*
|
|
24
|
+
* Usage from packaged code:
|
|
25
|
+
* const { getExternal } = require('@hakobu/runtime');
|
|
26
|
+
* const browserPath = getExternal('camoufox-browser');
|
|
27
|
+
*/
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ExternalArtifactRegistry = void 0;
|
|
33
|
+
const fs_1 = __importDefault(require("fs"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const runtime_diagnostics_1 = require("./runtime-diagnostics");
|
|
36
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
37
|
+
// Registry
|
|
38
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
39
|
+
/**
|
|
40
|
+
* Runtime registry of declared external artifacts.
|
|
41
|
+
* Created from the manifest's externals list during bootstrap.
|
|
42
|
+
*/
|
|
43
|
+
class ExternalArtifactRegistry {
|
|
44
|
+
declarations;
|
|
45
|
+
resolved;
|
|
46
|
+
execDir;
|
|
47
|
+
constructor(artifacts, execDir) {
|
|
48
|
+
this.declarations = new Map();
|
|
49
|
+
this.resolved = new Map();
|
|
50
|
+
this.execDir = execDir || path_1.default.dirname(process.execPath);
|
|
51
|
+
for (const artifact of artifacts) {
|
|
52
|
+
this.declarations.set(artifact.name, artifact);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get a declared external artifact by name.
|
|
57
|
+
* Resolves the path on first access and caches the result.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The declared artifact name
|
|
60
|
+
* @returns ResolvedExternal with the real filesystem path
|
|
61
|
+
* @throws Error if the artifact is required but not found
|
|
62
|
+
*/
|
|
63
|
+
get(name) {
|
|
64
|
+
// Check cache
|
|
65
|
+
if (this.resolved.has(name)) {
|
|
66
|
+
return this.resolved.get(name);
|
|
67
|
+
}
|
|
68
|
+
const decl = this.declarations.get(name);
|
|
69
|
+
if (!decl) {
|
|
70
|
+
throw (0, runtime_diagnostics_1.externalNotDeclared)(name, [...this.declarations.keys()]);
|
|
71
|
+
}
|
|
72
|
+
const resolved = this.resolve(decl);
|
|
73
|
+
if (resolved) {
|
|
74
|
+
this.resolved.set(name, resolved);
|
|
75
|
+
return resolved;
|
|
76
|
+
}
|
|
77
|
+
if (decl.required) {
|
|
78
|
+
throw (0, runtime_diagnostics_1.externalNotFound)(name, [
|
|
79
|
+
`env: HAKOBU_EXTERNAL_${toEnvName(name)}`,
|
|
80
|
+
path_1.default.join(this.execDir, 'externals', name),
|
|
81
|
+
`pattern: ${decl.pattern}`,
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if a declared external artifact exists without throwing.
|
|
88
|
+
*/
|
|
89
|
+
has(name) {
|
|
90
|
+
try {
|
|
91
|
+
return this.get(name) !== null;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Validate all required externals exist. Throws on first missing.
|
|
99
|
+
*/
|
|
100
|
+
validateRequired() {
|
|
101
|
+
for (const [name, decl] of this.declarations) {
|
|
102
|
+
if (decl.required) {
|
|
103
|
+
this.get(name); // throws if missing
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* List all declared external artifact names.
|
|
109
|
+
*/
|
|
110
|
+
listDeclared() {
|
|
111
|
+
return [...this.declarations.keys()];
|
|
112
|
+
}
|
|
113
|
+
// ── Resolution logic ──
|
|
114
|
+
resolve(decl) {
|
|
115
|
+
// 1. Environment variable override
|
|
116
|
+
const envKey = `HAKOBU_EXTERNAL_${toEnvName(decl.name)}`;
|
|
117
|
+
const envVal = process.env[envKey];
|
|
118
|
+
if (envVal && fs_1.default.existsSync(envVal)) {
|
|
119
|
+
return {
|
|
120
|
+
name: decl.name,
|
|
121
|
+
resolvedPath: path_1.default.resolve(envVal),
|
|
122
|
+
resolvedVia: 'env',
|
|
123
|
+
isDirectory: fs_1.default.statSync(envVal).isDirectory(),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// 2. Executable-relative: {execDir}/externals/{name}
|
|
127
|
+
const execRelative = path_1.default.join(this.execDir, 'externals', decl.name);
|
|
128
|
+
if (fs_1.default.existsSync(execRelative)) {
|
|
129
|
+
return {
|
|
130
|
+
name: decl.name,
|
|
131
|
+
resolvedPath: execRelative,
|
|
132
|
+
resolvedVia: 'exec-relative',
|
|
133
|
+
isDirectory: fs_1.default.statSync(execRelative).isDirectory(),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// 3. Pattern path (absolute or relative to cwd)
|
|
137
|
+
const patternPath = path_1.default.resolve(decl.pattern);
|
|
138
|
+
if (fs_1.default.existsSync(patternPath)) {
|
|
139
|
+
return {
|
|
140
|
+
name: decl.name,
|
|
141
|
+
resolvedPath: patternPath,
|
|
142
|
+
resolvedVia: 'pattern',
|
|
143
|
+
isDirectory: fs_1.default.statSync(patternPath).isDirectory(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
// 4. CWD-relative by name
|
|
147
|
+
const cwdRelative = path_1.default.resolve(decl.name);
|
|
148
|
+
if (cwdRelative !== patternPath && fs_1.default.existsSync(cwdRelative)) {
|
|
149
|
+
return {
|
|
150
|
+
name: decl.name,
|
|
151
|
+
resolvedPath: cwdRelative,
|
|
152
|
+
resolvedVia: 'cwd-relative',
|
|
153
|
+
isDirectory: fs_1.default.statSync(cwdRelative).isDirectory(),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.ExternalArtifactRegistry = ExternalArtifactRegistry;
|
|
160
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
161
|
+
// Helpers
|
|
162
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
163
|
+
/**
|
|
164
|
+
* Convert an artifact name to an environment variable suffix.
|
|
165
|
+
* "camoufox-browser" → "CAMOUFOX_BROWSER"
|
|
166
|
+
*/
|
|
167
|
+
function toEnvName(name) {
|
|
168
|
+
return name.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=external-artifacts.js.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shutdown = exports.fabricateTwice = exports.fabricate = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const log_1 = require("./log");
|
|
6
|
+
const script = `
|
|
7
|
+
var vm = require('vm');
|
|
8
|
+
var module = require('module');
|
|
9
|
+
var stdin = Buffer.alloc(0);
|
|
10
|
+
process.stdin.on('data', function (data) {
|
|
11
|
+
stdin = Buffer.concat([ stdin, data ]);
|
|
12
|
+
if (stdin.length >= 4) {
|
|
13
|
+
var sizeOfSnap = stdin.readInt32LE(0);
|
|
14
|
+
if (stdin.length >= 4 + sizeOfSnap + 4) {
|
|
15
|
+
var sizeOfBody = stdin.readInt32LE(4 + sizeOfSnap);
|
|
16
|
+
if (stdin.length >= 4 + sizeOfSnap + 4 + sizeOfBody) {
|
|
17
|
+
var snap = stdin.toString('utf8', 4, 4 + sizeOfSnap);
|
|
18
|
+
var body = Buffer.alloc(sizeOfBody);
|
|
19
|
+
var startOfBody = 4 + sizeOfSnap + 4;
|
|
20
|
+
stdin.copy(body, 0, startOfBody, startOfBody + sizeOfBody);
|
|
21
|
+
stdin = Buffer.alloc(0);
|
|
22
|
+
var code = module.wrap(body);
|
|
23
|
+
var s = new vm.Script(code, {
|
|
24
|
+
filename: snap,
|
|
25
|
+
produceCachedData: true,
|
|
26
|
+
sourceless: true
|
|
27
|
+
});
|
|
28
|
+
if (!s.cachedDataProduced) {
|
|
29
|
+
console.error('Pkg: Cached data not produced.');
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
var h = Buffer.alloc(4);
|
|
33
|
+
var b = s.cachedData;
|
|
34
|
+
h.writeInt32LE(b.length, 0);
|
|
35
|
+
process.stdout.write(h);
|
|
36
|
+
process.stdout.write(b);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
process.stdin.resume();
|
|
42
|
+
`;
|
|
43
|
+
const children = {};
|
|
44
|
+
function fabricate(bakes, fabricator, snap, body, cb) {
|
|
45
|
+
const activeBakes = bakes.filter((bake) => {
|
|
46
|
+
// list of bakes that don't influence the bytecode
|
|
47
|
+
const bake2 = bake.replace(/_/g, '-');
|
|
48
|
+
return !['--prof', '--v8-options', '--trace-opt', '--trace-deopt'].includes(bake2);
|
|
49
|
+
});
|
|
50
|
+
const cmd = fabricator.binaryPath;
|
|
51
|
+
const key = JSON.stringify([cmd, activeBakes]);
|
|
52
|
+
let child = children[key];
|
|
53
|
+
if (!child) {
|
|
54
|
+
const stderr = log_1.log.debugMode ? process.stdout : 'ignore';
|
|
55
|
+
children[key] = (0, child_process_1.spawn)(cmd, activeBakes.concat('-e', script), {
|
|
56
|
+
stdio: ['pipe', 'pipe', stderr],
|
|
57
|
+
env: { PKG_EXECPATH: 'PKG_INVOKE_NODEJS' },
|
|
58
|
+
});
|
|
59
|
+
child = children[key];
|
|
60
|
+
}
|
|
61
|
+
function kill() {
|
|
62
|
+
delete children[key];
|
|
63
|
+
child.kill();
|
|
64
|
+
}
|
|
65
|
+
let stdout = Buffer.alloc(0);
|
|
66
|
+
function onError(error) {
|
|
67
|
+
removeListeners();
|
|
68
|
+
kill();
|
|
69
|
+
cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap} error (${error.message})`));
|
|
70
|
+
}
|
|
71
|
+
function onClose(code) {
|
|
72
|
+
removeListeners();
|
|
73
|
+
kill();
|
|
74
|
+
if (code !== 0) {
|
|
75
|
+
return cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap}`));
|
|
76
|
+
}
|
|
77
|
+
console.log(stdout.toString());
|
|
78
|
+
return cb(new Error(`${cmd} closed unexpectedly`));
|
|
79
|
+
}
|
|
80
|
+
function onData(data) {
|
|
81
|
+
stdout = Buffer.concat([stdout, data]);
|
|
82
|
+
if (stdout.length >= 4) {
|
|
83
|
+
const sizeOfBlob = stdout.readInt32LE(0);
|
|
84
|
+
if (stdout.length >= 4 + sizeOfBlob) {
|
|
85
|
+
const blob = Buffer.alloc(sizeOfBlob);
|
|
86
|
+
stdout.copy(blob, 0, 4, 4 + sizeOfBlob);
|
|
87
|
+
removeListeners();
|
|
88
|
+
return cb(undefined, blob);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function removeListeners() {
|
|
93
|
+
child.removeListener('error', onError);
|
|
94
|
+
child.removeListener('close', onClose);
|
|
95
|
+
child.stdin.removeListener('error', onError);
|
|
96
|
+
child.stdout.removeListener('error', onError);
|
|
97
|
+
child.stdout.removeListener('data', onData);
|
|
98
|
+
}
|
|
99
|
+
child.on('error', onError);
|
|
100
|
+
child.on('close', onClose);
|
|
101
|
+
child.stdin.on('error', onError);
|
|
102
|
+
child.stdout.on('error', onError);
|
|
103
|
+
child.stdout.on('data', onData);
|
|
104
|
+
const h = Buffer.alloc(4);
|
|
105
|
+
let b = Buffer.from(snap);
|
|
106
|
+
h.writeInt32LE(b.length, 0);
|
|
107
|
+
child.stdin.write(h);
|
|
108
|
+
child.stdin.write(b);
|
|
109
|
+
b = body;
|
|
110
|
+
h.writeInt32LE(b.length, 0);
|
|
111
|
+
child.stdin.write(h);
|
|
112
|
+
child.stdin.write(b);
|
|
113
|
+
}
|
|
114
|
+
exports.fabricate = fabricate;
|
|
115
|
+
function fabricateTwice(bakes, fabricator, snap, body, cb) {
|
|
116
|
+
fabricate(bakes, fabricator, snap, body, (error, buffer) => {
|
|
117
|
+
// node0 can not produce second time, even if first time produced fine,
|
|
118
|
+
// probably because of 'filename' cache. also, there are weird cases
|
|
119
|
+
// when node4 can not compile as well, for example file 'lib/js-yaml/dumper.js'
|
|
120
|
+
// of package js-yaml@3.9.0 does not get bytecode second time on node4-win-x64
|
|
121
|
+
if (error)
|
|
122
|
+
return fabricate(bakes, fabricator, snap, body, cb);
|
|
123
|
+
cb(undefined, buffer);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.fabricateTwice = fabricateTwice;
|
|
127
|
+
function shutdown() {
|
|
128
|
+
for (const key in children) {
|
|
129
|
+
if (children[key]) {
|
|
130
|
+
const child = children[key];
|
|
131
|
+
delete children[key];
|
|
132
|
+
child.kill();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.shutdown = shutdown;
|
|
137
|
+
//# sourceMappingURL=fabricator.js.map
|
|
@@ -0,0 +1,190 @@
|
|
|
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.follow = void 0;
|
|
7
|
+
const resolve_1 = require("resolve");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const common_1 = require("./common");
|
|
11
|
+
const resolver_1 = require("./resolver");
|
|
12
|
+
const PROOF = 'a-proof-that-main-is-captured.js';
|
|
13
|
+
function parentDirectoriesContain(parent, directory) {
|
|
14
|
+
let currentParent = parent;
|
|
15
|
+
while (true) {
|
|
16
|
+
if (currentParent === directory) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const newParent = path_1.default.dirname(currentParent);
|
|
20
|
+
if (newParent === currentParent) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
currentParent = newParent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a specifier looks like a valid npm package name
|
|
28
|
+
* npm package names must be lowercase and can only contain:
|
|
29
|
+
* - lowercase letters, digits, hyphens, underscores, dots
|
|
30
|
+
* - can be scoped (@scope/package)
|
|
31
|
+
* This helps filter out generated aliases like "connectNonLiteral"
|
|
32
|
+
*/
|
|
33
|
+
function isValidPackageName(specifier) {
|
|
34
|
+
// Scoped packages: @scope/package
|
|
35
|
+
if (specifier.startsWith('@')) {
|
|
36
|
+
const parts = specifier.split('/');
|
|
37
|
+
if (parts.length < 2)
|
|
38
|
+
return false;
|
|
39
|
+
// Scope must start with @ and both parts must be valid
|
|
40
|
+
return /^@[a-z0-9_.-]+$/.test(parts[0]) && /^[a-z0-9_.-]+$/.test(parts[1]);
|
|
41
|
+
}
|
|
42
|
+
// Regular package: must be lowercase with allowed characters
|
|
43
|
+
// Package name is the part before the first '/' (if any)
|
|
44
|
+
const packageName = specifier.split('/')[0];
|
|
45
|
+
return /^[a-z0-9_.-]+$/.test(packageName);
|
|
46
|
+
}
|
|
47
|
+
function follow(x, opts) {
|
|
48
|
+
// TODO async version
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
// Try ESM-aware resolution first for non-relative specifiers
|
|
51
|
+
// Skip if the specifier doesn't look like a valid npm package name
|
|
52
|
+
// (e.g., generated aliases like "connectNonLiteral")
|
|
53
|
+
if (!x.startsWith('.') &&
|
|
54
|
+
!x.startsWith('/') &&
|
|
55
|
+
!path_1.default.isAbsolute(x) &&
|
|
56
|
+
isValidPackageName(x)) {
|
|
57
|
+
try {
|
|
58
|
+
let extensions;
|
|
59
|
+
if (Array.isArray(opts.extensions)) {
|
|
60
|
+
extensions = opts.extensions;
|
|
61
|
+
}
|
|
62
|
+
else if (opts.extensions) {
|
|
63
|
+
extensions = [opts.extensions];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
extensions = ['.js', '.json', '.node'];
|
|
67
|
+
}
|
|
68
|
+
const result = (0, resolver_1.resolveModule)(x, {
|
|
69
|
+
basedir: opts.basedir || process.cwd(),
|
|
70
|
+
extensions,
|
|
71
|
+
});
|
|
72
|
+
// Only use ESM resolution result if it's an actual ESM package
|
|
73
|
+
// For CJS packages, fall through to standard CommonJS resolution
|
|
74
|
+
// to ensure all callbacks (catchReadFile, catchPackageFilter) are handled correctly
|
|
75
|
+
if (result.isESM) {
|
|
76
|
+
// This is a real ESM package, handle it here
|
|
77
|
+
if (opts.catchReadFile) {
|
|
78
|
+
// Find the package.json for this resolved module
|
|
79
|
+
let currentDir = path_1.default.dirname(result.resolved);
|
|
80
|
+
while (currentDir !== path_1.default.dirname(currentDir)) {
|
|
81
|
+
const pkgPath = path_1.default.join(currentDir, 'package.json');
|
|
82
|
+
// Honor ignoreFile to ensure correct package marker determination
|
|
83
|
+
if (opts.ignoreFile &&
|
|
84
|
+
path_1.default.normalize(pkgPath) === path_1.default.normalize(opts.ignoreFile)) {
|
|
85
|
+
// Skip this package.json as it's marked to be ignored
|
|
86
|
+
currentDir = path_1.default.dirname(currentDir);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (fs_1.default.existsSync(pkgPath)) {
|
|
90
|
+
// Check if this package.json is in node_modules (not the root package)
|
|
91
|
+
if (currentDir.includes('node_modules')) {
|
|
92
|
+
opts.catchReadFile(pkgPath);
|
|
93
|
+
// Also call catchPackageFilter if provided
|
|
94
|
+
if (opts.catchPackageFilter) {
|
|
95
|
+
const pkgContent = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
|
|
96
|
+
// If package doesn't have a "main" field but we resolved via exports,
|
|
97
|
+
// add a synthetic "main" field so runtime resolution works
|
|
98
|
+
if (!pkgContent.main) {
|
|
99
|
+
const relativePath = path_1.default.relative(currentDir, result.resolved);
|
|
100
|
+
pkgContent.main = `./${relativePath.replace(/\\/g, '/')}`;
|
|
101
|
+
}
|
|
102
|
+
opts.catchPackageFilter(pkgContent, currentDir, currentDir);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
currentDir = path_1.default.dirname(currentDir);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ESM package resolved successfully
|
|
111
|
+
resolve(result.resolved);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// CJS package - fall through to standard CommonJS resolution
|
|
115
|
+
// to handle all callbacks properly
|
|
116
|
+
}
|
|
117
|
+
catch (_error) {
|
|
118
|
+
// ESM resolution failed - fall through to standard CommonJS resolution
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Use standard CommonJS resolution
|
|
122
|
+
try {
|
|
123
|
+
resolve((0, resolve_1.sync)(x, {
|
|
124
|
+
basedir: opts.basedir,
|
|
125
|
+
extensions: opts.extensions,
|
|
126
|
+
isFile: (file) => {
|
|
127
|
+
if (opts.ignoreFile &&
|
|
128
|
+
path_1.default.join(path_1.default.dirname(opts.ignoreFile), PROOF) === file) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
let stat;
|
|
132
|
+
try {
|
|
133
|
+
stat = fs_1.default.statSync(file);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
const ex = e;
|
|
137
|
+
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR'))
|
|
138
|
+
return false;
|
|
139
|
+
throw ex;
|
|
140
|
+
}
|
|
141
|
+
return stat.isFile() || stat.isFIFO();
|
|
142
|
+
},
|
|
143
|
+
isDirectory: (directory) => {
|
|
144
|
+
if (opts.ignoreFile &&
|
|
145
|
+
parentDirectoriesContain(opts.ignoreFile, directory)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
let stat;
|
|
149
|
+
try {
|
|
150
|
+
stat = fs_1.default.statSync(directory);
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
const ex = e;
|
|
154
|
+
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR')) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
throw ex;
|
|
158
|
+
}
|
|
159
|
+
return stat.isDirectory();
|
|
160
|
+
},
|
|
161
|
+
readFileSync: (file) => {
|
|
162
|
+
if (opts.ignoreFile && opts.ignoreFile === file) {
|
|
163
|
+
return Buffer.from(`{"main":"${PROOF}"}`);
|
|
164
|
+
}
|
|
165
|
+
if (opts.catchReadFile) {
|
|
166
|
+
opts.catchReadFile(file);
|
|
167
|
+
}
|
|
168
|
+
return fs_1.default.readFileSync(file);
|
|
169
|
+
},
|
|
170
|
+
packageFilter: (config, base, dir) => {
|
|
171
|
+
if (opts.catchPackageFilter) {
|
|
172
|
+
opts.catchPackageFilter(config, base, dir);
|
|
173
|
+
}
|
|
174
|
+
return config;
|
|
175
|
+
},
|
|
176
|
+
/** function to synchronously resolve a potential symlink to its real path */
|
|
177
|
+
// realpathSync?: (file: string) => string;
|
|
178
|
+
realpathSync: (file) => {
|
|
179
|
+
const file2 = (0, common_1.toNormalizedRealPath)(file);
|
|
180
|
+
return file2;
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
reject(error);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
exports.follow = follow;
|
|
190
|
+
//# sourceMappingURL=follow.js.map
|
package/lib-es5/help.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const colors_1 = require("./colors");
|
|
4
|
+
function help() {
|
|
5
|
+
console.log(`
|
|
6
|
+
${colors_1.pc.bold('pkg')} [options] <input>
|
|
7
|
+
|
|
8
|
+
${colors_1.pc.dim('Options:')}
|
|
9
|
+
|
|
10
|
+
-h, --help output usage information
|
|
11
|
+
-v, --version output pkg version
|
|
12
|
+
-t, --targets comma-separated list of targets (see examples)
|
|
13
|
+
-c, --config package.json or any json file with top-level config
|
|
14
|
+
--options bake v8 options into executable to run with them on
|
|
15
|
+
-o, --output output file name or template for several files
|
|
16
|
+
--out-path path to save output one or more executables
|
|
17
|
+
-d, --debug show more information during packaging process [off]
|
|
18
|
+
-b, --build don't download prebuilt base binaries, build them
|
|
19
|
+
--public speed up and disclose the sources of top-level project
|
|
20
|
+
--public-packages force specified packages to be considered public
|
|
21
|
+
--no-bytecode skip bytecode generation and include source files as plain js
|
|
22
|
+
--no-native-build skip native addons build
|
|
23
|
+
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
|
|
24
|
+
-C, --compress [default=None] compression algorithm = Brotli or GZip
|
|
25
|
+
--sea (Experimental) compile give file using node's SEA feature. Requires node v20.0.0 or higher and only single file is supported
|
|
26
|
+
|
|
27
|
+
${colors_1.pc.dim('Examples:')}
|
|
28
|
+
|
|
29
|
+
${colors_1.pc.gray('–')} Makes executables for Linux, macOS and Windows
|
|
30
|
+
${colors_1.pc.cyan('$ pkg index.js')}
|
|
31
|
+
${colors_1.pc.gray('–')} Takes package.json from cwd and follows 'bin' entry
|
|
32
|
+
${colors_1.pc.cyan('$ pkg .')}
|
|
33
|
+
${colors_1.pc.gray('–')} Makes executable for particular target machine
|
|
34
|
+
${colors_1.pc.cyan('$ pkg -t node14-win-arm64 index.js')}
|
|
35
|
+
${colors_1.pc.gray('–')} Makes executables for target machines of your choice
|
|
36
|
+
${colors_1.pc.cyan('$ pkg -t node22-linux,node24-linux,node24-win index.js')}
|
|
37
|
+
${colors_1.pc.gray('–')} Bakes '--expose-gc' and '--max-heap-size=34' into executable
|
|
38
|
+
${colors_1.pc.cyan('$ pkg --options "expose-gc,max-heap-size=34" index.js')}
|
|
39
|
+
${colors_1.pc.gray('–')} Consider packageA and packageB to be public
|
|
40
|
+
${colors_1.pc.cyan('$ pkg --public-packages "packageA,packageB" index.js')}
|
|
41
|
+
${colors_1.pc.gray('–')} Consider all packages to be public
|
|
42
|
+
${colors_1.pc.cyan('$ pkg --public-packages "*" index.js')}
|
|
43
|
+
${colors_1.pc.gray('–')} Bakes '--expose-gc' into executable
|
|
44
|
+
${colors_1.pc.cyan('$ pkg --options expose-gc index.js')}
|
|
45
|
+
${colors_1.pc.gray('–')} reduce size of the data packed inside the executable with GZip
|
|
46
|
+
${colors_1.pc.cyan('$ pkg --compress GZip index.js')}
|
|
47
|
+
${colors_1.pc.gray('–')} compile the file using node's SEA feature. Creates executables for Linux, macOS and Windows
|
|
48
|
+
${colors_1.pc.cyan('$ pkg --sea index.js')}
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
exports.default = help;
|
|
52
|
+
//# sourceMappingURL=help.js.map
|