@yao-pkg/pkg-fetch 3.5.3

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/README.md ADDED
@@ -0,0 +1,117 @@
1
+ A utility to fetch or build patched Node binaries used by [pkg](https://github.com/yao-pkg/pkg) to generate executables. This repo hosts prebuilt binaries in [Releases](https://github.com/yao-pkg/pkg-fetch/releases).
2
+
3
+ ## Binary Compatibility
4
+
5
+ | Node | Platform | Architectures | Minimum OS version |
6
+ | --------------------------------------------------------------------------------- | ----------- | ------------------------- | --------------------------------------------------------------------------------- |
7
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | alpine | x64, arm64 | 3.7.3, other distros with musl libc >= 1.1.18 |
8
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | linux | x64 | Enterprise Linux 7, Ubuntu 14.04, Debian jessie, other distros with glibc >= 2.17 |
9
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | linux | arm64 | Enterprise Linux 8, Ubuntu 18.04, Debian buster, other distros with glibc >= 2.27 |
10
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | linuxstatic | x64, arm64 | Any distro with Linux Kernel >= 2.6.32 (>= 3.10 strongly recommended) |
11
+ | 16, 18 | linuxstatic | armv7<sup>[2](#fn2)</sup> | Any distro with Linux Kernel >= 2.6.32 (>= 3.10 strongly recommended) |
12
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | macos | x64 | 10.13 |
13
+ | 14, 16, 18 | macos | arm64<sup>[3](#fn3)</sup> | 11.0 |
14
+ | 8<sup>[1](#fn1)</sup>, 10<sup>[1](#fn1)</sup>, 12<sup>[1](#fn1)</sup>, 14, 16, 18 | win | x64 | 8.1 |
15
+ | 14, 16, 18 | win | arm64 | 10 |
16
+
17
+ <em id="fn1">[1]</em>: end-of-life, may be removed in the next major release.
18
+
19
+ <em id="fn2">[2]</em>: best-effort basis, not semver-protected.
20
+
21
+ <em id="fn3">[3]</em>: [mandatory code signing](https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-universal-apps-release-notes) is enforced by Apple.
22
+
23
+ ## Security
24
+
25
+ We do not expect this project to have vulnerabilities of its own. Nonetheless, as this project distributes prebuilt Node.js binaries,
26
+
27
+ **Node.js security vulnerabilities affect binaries distributed by this project, as well.**
28
+
29
+ Like most of you, this project does not have access to advance/private disclosures of Node.js security vulnerabilities. We can only closely monitor the **public** security advisories from the Node.js team. It takes time to build and release a new set of binaries, once a new Node.js version has been released.
30
+
31
+ **It is possible for this project to fall victim to a supply chain attack.**
32
+
33
+ This project deploys multiple defense measures to ensure that the safe binaries are delivered to users:
34
+
35
+ - Binaries are compiled by [Github Actions](https://github.com/yao-pkg/pkg-fetch/actions)
36
+ - Workflows and build logs are transparent and auditable.
37
+ - Artifacts are the source of truth. Even repository/organization administrators can't tamper them.
38
+ - Hashes of binaries are hardcoded in [source](https://github.com/yao-pkg/pkg-fetch/blob/HEAD/lib/expected.ts)
39
+ - Origins of the binaries are documented.
40
+ - Changes to the binaries are logged by VCS (Git) and are publicly visible.
41
+ - `pkg-fetch` rejects the binary if it does not match the hardcoded hash.
42
+ - GPG-signed hashes are available in [Releases](https://github.com/yao-pkg/pkg-fetch/releases)
43
+ - Easy to spot a compromise.
44
+ - `pkg-fetch` package on npm is strictly permission-controlled
45
+ - Only authorized Vercel employees can push new revisions to npm.
46
+
47
+ ## Contributing Updates to Patches
48
+
49
+ ### Example workflow for applying patches to a new version of Node.js (18.13.0)
50
+
51
+ 1. Clone Node.js as a sibling to your current `pkg-fetch` clone
52
+
53
+ - `git clone https://github.com/nodejs/node.git`
54
+ - `cd node`
55
+
56
+ 2. Checkout the tag you wish to generate a patch for
57
+
58
+ - `git checkout v18.13.0`
59
+
60
+ 3. Attempt to apply the closest patch (e.g. applying the existing patch for
61
+ 18.12.1 when trying to generate a new patch for 18.13.0)
62
+
63
+ - `git apply ..\pkg-fetch\patches\node.v18.12.1.cpp.patch --reject`
64
+
65
+ 4. If no rejects, great! you are ready to make your new patch file.
66
+
67
+ - `git add -A`
68
+ - `git diff --staged --src-prefix=node/ --dst-prefix=node/ > ..\pkg-fetch\patches\node.v18.13.0.cpp.patch`
69
+
70
+ 5. If rejects exist, resolve them yourself, and ensure all changes are saved,
71
+ and repeat step 4 to export the patch file
72
+
73
+ #### Resolving Rejects
74
+
75
+ Usually when a patch is rejected, it's because the context around the changes
76
+ was refactored slightly since the last patched version. This is not usually
77
+ complicated to resolve, but requires a human to interpret the changes since the
78
+ last version `pkg` was patched against, compared with the version you wish to
79
+ create a patch for.
80
+
81
+ One method is to pull up the diff for the file where the rejects apply for the
82
+ changes between the last tag (e.g. v18.12.1 to use the previous example) and the
83
+ tag you want a patch for (e.g. v18.13.0 to use the previous example). Alongside
84
+ this, have the `.rej` file and go through each rejected hunk by hunk and use
85
+ your best judgement to determine how it should apply against the new tag.
86
+
87
+ Save you results, and export the overall git diff with the commands from the
88
+ example above.
89
+
90
+ ### Checking that patches apply cleanly
91
+
92
+ The expectation is that a patch applies cleanly, with no delta or offsets from
93
+ the source repo.
94
+
95
+ When making a change to a patch file, it is possible to apply that patch without
96
+ building by running
97
+
98
+ `yarn applyPatches --node-range node18`
99
+
100
+ where the `--node-range` can be specified to apply patches for the version of
101
+ node for which you are updating patches. If unspecified, the latest node version
102
+ in [patches.json](./patches/patches.json) will be used.
103
+
104
+ Ultimately, the patch should result in fully functional node binary, but the
105
+ `applyPatches` script can be used to quickly iterate just the application of
106
+ the patches you are updating without needing to wait for the full build to
107
+ complete.
108
+
109
+ ## Building a Binary Locally
110
+
111
+ You can use the `yarn start` script to build the binary locally, which is helpful
112
+ when updating patches to ensure functionality before pushing patch updates for
113
+ review.
114
+
115
+ For example:
116
+
117
+ `yarn start --node-range node18 --arch x64 --output dist`
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=apply-patches.d.ts.map
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ var yargs_1 = __importDefault(require("yargs"));
44
+ var log_1 = require("./log");
45
+ var index_1 = require("./index");
46
+ var package_json_1 = require("../package.json");
47
+ var build_1 = require("./build");
48
+ function applyPatchesOnVersion(nodeRange, quietExtraction) {
49
+ if (quietExtraction === void 0) { quietExtraction = false; }
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0: return [4 /*yield*/, (0, build_1.prepBuildPath)()];
54
+ case 1:
55
+ _a.sent();
56
+ return [4 /*yield*/, (0, build_1.fetchExtractApply)((0, index_1.getNodeVersion)(nodeRange), quietExtraction)];
57
+ case 2:
58
+ _a.sent();
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ });
63
+ }
64
+ function main() {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var argv, nodeRange, quietExtraction;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ argv = yargs_1.default
71
+ .option('node-range', { alias: 'n', default: 'latest', type: 'string' })
72
+ .option('quiet-extraction', { alias: 'q', type: 'boolean' })
73
+ .version(package_json_1.version)
74
+ .alias('v', 'version')
75
+ .help()
76
+ .alias('h', 'help').argv;
77
+ nodeRange = argv["node-range"], quietExtraction = argv["quiet-extraction"];
78
+ return [4 /*yield*/, applyPatchesOnVersion(nodeRange, quietExtraction)];
79
+ case 1:
80
+ _a.sent();
81
+ return [2 /*return*/];
82
+ }
83
+ });
84
+ });
85
+ }
86
+ main().catch(function (error) {
87
+ if (!error.wasReported)
88
+ log_1.log.error(error);
89
+ process.exit(2);
90
+ });
91
+ //# sourceMappingURL=apply-patches.js.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
package/lib-es5/bin.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ var yargs_1 = __importDefault(require("yargs"));
44
+ var system_1 = require("./system");
45
+ var log_1 = require("./log");
46
+ var index_1 = require("./index");
47
+ var verify_1 = require("./verify");
48
+ var package_json_1 = require("../package.json");
49
+ function main() {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var argv, nodeRange, platform, arch, test, forceFetch, forceBuild, output, local;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ argv = yargs_1.default
56
+ .env('PKG_FETCH_OPTION_')
57
+ .option('node-range', { alias: 'n', default: 'latest', type: 'string' })
58
+ .option('platform', { alias: 'p', default: system_1.hostPlatform, type: 'string' })
59
+ .option('arch', { alias: 'a', default: system_1.hostArch, type: 'string' })
60
+ .option('test', { alias: 't', type: 'boolean' })
61
+ .option('force-fetch', {
62
+ alias: 'f',
63
+ type: 'boolean',
64
+ })
65
+ .option('force-build', {
66
+ alias: 'b',
67
+ type: 'boolean',
68
+ })
69
+ .conflicts('force-fetch', 'force-build')
70
+ .option('output', { alias: 'o', type: 'string' })
71
+ .version(package_json_1.version)
72
+ .alias('v', 'version')
73
+ .help()
74
+ .alias('h', 'help').argv;
75
+ nodeRange = argv["node-range"], platform = argv.platform, arch = argv.arch, test = argv.test, forceFetch = argv["force-fetch"], forceBuild = argv["force-build"], output = argv.output;
76
+ return [4 /*yield*/, (0, index_1.need)({
77
+ nodeRange: nodeRange,
78
+ platform: platform,
79
+ arch: arch,
80
+ forceFetch: forceFetch,
81
+ forceBuild: forceBuild,
82
+ output: output,
83
+ })];
84
+ case 1:
85
+ local = _a.sent();
86
+ log_1.log.info(local);
87
+ if (!test) return [3 /*break*/, 3];
88
+ return [4 /*yield*/, (0, verify_1.verify)(local)];
89
+ case 2:
90
+ _a.sent();
91
+ _a.label = 3;
92
+ case 3: return [2 /*return*/];
93
+ }
94
+ });
95
+ });
96
+ }
97
+ main().catch(function (error) {
98
+ if (!error.wasReported)
99
+ log_1.log.error(error);
100
+ process.exit(2);
101
+ });
102
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1,4 @@
1
+ export declare function fetchExtractApply(nodeVersion: string, quietExtraction: boolean): Promise<void>;
2
+ export declare function prepBuildPath(): Promise<void>;
3
+ export default function build(nodeVersion: string, targetArch: string, targetPlatform: string, local: string): Promise<void>;
4
+ //# sourceMappingURL=build.d.ts.map