@yao-pkg/pkg 5.12.0 → 5.13.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/lib-es5/producer.js +37 -4
- package/lib-es5/walker.js +13 -2
- package/package.json +4 -5
package/lib-es5/producer.js
CHANGED
|
@@ -16,12 +16,28 @@ const log_1 = require("./log");
|
|
|
16
16
|
const fabricator_1 = require("./fabricator");
|
|
17
17
|
const types_1 = require("./types");
|
|
18
18
|
const compress_type_1 = require("./compress_type");
|
|
19
|
-
function discoverPlaceholder(binaryBuffer, searchString, padder) {
|
|
19
|
+
function discoverPlaceholder(binaryBuffer, searchString, padder, searchOffset = 0) {
|
|
20
20
|
const placeholder = Buffer.from(searchString);
|
|
21
|
-
const position = binaryBuffer.indexOf(placeholder);
|
|
21
|
+
const position = binaryBuffer.indexOf(placeholder, searchOffset);
|
|
22
22
|
if (position === -1) {
|
|
23
23
|
return { notFound: true };
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* the PAYLOAD/PRELUDE placeholders can occur twice in the binaries:
|
|
27
|
+
* - in source text as a string literal
|
|
28
|
+
* - in bytecode as a raw string
|
|
29
|
+
* the ordering depends on the platform - we need to make sure that
|
|
30
|
+
* the bytecode string is replaced, not the source literal.
|
|
31
|
+
*
|
|
32
|
+
* this rejects the source code literal if it occurs first in the binary
|
|
33
|
+
* also see: https://github.com/yao-pkg/pkg/pull/86
|
|
34
|
+
*/
|
|
35
|
+
if (binaryBuffer[position - 1] === 39 /* ascii for ' APOSTROPHE */) {
|
|
36
|
+
const nextPlaceholder = discoverPlaceholder(binaryBuffer, searchString, padder, position + placeholder.length);
|
|
37
|
+
if (!('notFound' in nextPlaceholder)) {
|
|
38
|
+
return nextPlaceholder;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
25
41
|
return { position, size: placeholder.length, padder };
|
|
26
42
|
}
|
|
27
43
|
function injectPlaceholder(fd, placeholder, value, cb) {
|
|
@@ -105,10 +121,27 @@ function findPackageJson(nodeFile) {
|
|
|
105
121
|
}
|
|
106
122
|
return dir;
|
|
107
123
|
}
|
|
124
|
+
function getPrebuildEnvPrefix(pkgName) {
|
|
125
|
+
return `npm_config_${(pkgName || '')
|
|
126
|
+
.replace(/[^a-zA-Z0-9]/g, '_')
|
|
127
|
+
.replace(/^_/, '')}`;
|
|
128
|
+
}
|
|
108
129
|
function nativePrebuildInstall(target, nodeFile) {
|
|
109
130
|
var _a, _b;
|
|
110
131
|
const prebuildInstall = path_1.default.join(__dirname, '../node_modules/.bin/prebuild-install');
|
|
111
132
|
const dir = findPackageJson(nodeFile);
|
|
133
|
+
const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(dir, 'package.json'), { encoding: 'utf-8' }));
|
|
134
|
+
// only try prebuild-install for packages that actually use it or if
|
|
135
|
+
// explicitly configured via environment variables
|
|
136
|
+
const envPrefix = getPrebuildEnvPrefix(packageJson.name);
|
|
137
|
+
if (((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['prebuild-install']) == null &&
|
|
138
|
+
![
|
|
139
|
+
`${envPrefix}_binary_host`,
|
|
140
|
+
`${envPrefix}_binary_host_mirror`,
|
|
141
|
+
`${envPrefix}_local_prebuilds`,
|
|
142
|
+
].some((i) => i in process.env)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
112
145
|
// parse the target node version from the binaryPath
|
|
113
146
|
const nodeVersion = path_1.default.basename(target.binaryPath).split('-')[1];
|
|
114
147
|
if (!/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(nodeVersion)) {
|
|
@@ -122,7 +155,7 @@ function nativePrebuildInstall(target, nodeFile) {
|
|
|
122
155
|
if (!fs_extra_1.default.existsSync(`${nodeFile}.bak`)) {
|
|
123
156
|
fs_extra_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
|
|
124
157
|
}
|
|
125
|
-
const napiVersions = (_b =
|
|
158
|
+
const napiVersions = (_b = packageJson === null || packageJson === void 0 ? void 0 : packageJson.binary) === null || _b === void 0 ? void 0 : _b.napi_versions;
|
|
126
159
|
const options = [
|
|
127
160
|
'--platform',
|
|
128
161
|
types_1.platform[target.platform],
|
|
@@ -289,7 +322,7 @@ function producer({ backpack, bakes, slash, target, symLinks, doCompress, native
|
|
|
289
322
|
if ((0, common_1.isDotNODE)(stripe.file) && nativeBuild) {
|
|
290
323
|
try {
|
|
291
324
|
const platformFile = nativePrebuildInstall(target, stripe.file);
|
|
292
|
-
if (fs_extra_1.default.existsSync(platformFile)) {
|
|
325
|
+
if (platformFile && fs_extra_1.default.existsSync(platformFile)) {
|
|
293
326
|
return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(platformFile)));
|
|
294
327
|
}
|
|
295
328
|
}
|
package/lib-es5/walker.js
CHANGED
|
@@ -29,11 +29,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
const assert_1 = __importDefault(require("assert"));
|
|
31
31
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
-
const is_core_module_1 = __importDefault(require("is-core-module"));
|
|
33
32
|
const globby_1 = __importDefault(require("globby"));
|
|
34
33
|
const path_1 = __importDefault(require("path"));
|
|
35
34
|
const chalk_1 = __importDefault(require("chalk"));
|
|
36
35
|
const minimatch_1 = require("minimatch");
|
|
36
|
+
const module_1 = require("module");
|
|
37
37
|
const common_1 = require("./common");
|
|
38
38
|
const follow_1 = require("./follow");
|
|
39
39
|
const log_1 = require("./log");
|
|
@@ -48,6 +48,17 @@ const options_1 = __importDefault(require("./options"));
|
|
|
48
48
|
// performance hit.
|
|
49
49
|
const strictVerify = Boolean(process.env.PKG_STRICT_VER);
|
|
50
50
|
const win32 = process.platform === 'win32';
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a module is a core module
|
|
53
|
+
* module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
|
|
54
|
+
* versions of Node.js, we can use module.isBuiltin instead of this function.
|
|
55
|
+
*/
|
|
56
|
+
function isBuiltin(moduleName) {
|
|
57
|
+
const moduleNameWithoutPrefix = moduleName.startsWith('node:')
|
|
58
|
+
? moduleName.slice(5)
|
|
59
|
+
: moduleName;
|
|
60
|
+
return module_1.builtinModules.includes(moduleNameWithoutPrefix);
|
|
61
|
+
}
|
|
51
62
|
function unlikelyJavascript(file) {
|
|
52
63
|
return ['.css', '.html', '.json', '.vue'].includes(path_1.default.extname(file));
|
|
53
64
|
}
|
|
@@ -666,7 +677,7 @@ class Walker {
|
|
|
666
677
|
async stepDerivatives(record, marker, derivatives) {
|
|
667
678
|
for (const derivative of derivatives) {
|
|
668
679
|
// TODO: actually use the target node version
|
|
669
|
-
if ((
|
|
680
|
+
if (isBuiltin(derivative.alias))
|
|
670
681
|
continue;
|
|
671
682
|
switch (derivative.aliasType) {
|
|
672
683
|
case common_1.ALIAS_AS_RELATIVE:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yao-pkg/pkg",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
4
4
|
"description": "Package your Node.js project into an executable",
|
|
5
5
|
"main": "lib-es5/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,12 +25,11 @@
|
|
|
25
25
|
"@babel/generator": "7.23.0",
|
|
26
26
|
"@babel/parser": "7.23.0",
|
|
27
27
|
"@babel/types": "7.23.0",
|
|
28
|
-
"@yao-pkg/pkg-fetch": "3.5.
|
|
28
|
+
"@yao-pkg/pkg-fetch": "3.5.10",
|
|
29
29
|
"chalk": "^4.1.2",
|
|
30
30
|
"fs-extra": "^9.1.0",
|
|
31
31
|
"globby": "^11.1.0",
|
|
32
32
|
"into-stream": "^6.0.0",
|
|
33
|
-
"is-core-module": "2.9.0",
|
|
34
33
|
"minimatch": "9.0.4",
|
|
35
34
|
"minimist": "^1.2.6",
|
|
36
35
|
"multistream": "^4.1.0",
|
|
@@ -43,7 +42,6 @@
|
|
|
43
42
|
"@release-it/conventional-changelog": "7.0.2",
|
|
44
43
|
"@types/babel__generator": "7.6.5",
|
|
45
44
|
"@types/fs-extra": "9.0.13",
|
|
46
|
-
"@types/is-core-module": "2.2.0",
|
|
47
45
|
"@types/minimatch": "^5.1.2",
|
|
48
46
|
"@types/minimist": "1.2.2",
|
|
49
47
|
"@types/multistream": "4.1.0",
|
|
@@ -141,5 +139,6 @@
|
|
|
141
139
|
},
|
|
142
140
|
"publishConfig": {
|
|
143
141
|
"access": "public"
|
|
144
|
-
}
|
|
142
|
+
},
|
|
143
|
+
"packageManager": "yarn@1.22.22"
|
|
145
144
|
}
|