node-bin-gen 9.0.4 → 11.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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +218 -153
  3. package/package.json +8 -5
package/README.md CHANGED
@@ -11,7 +11,7 @@ $ npm install -g node-bin-gen
11
11
  # Use
12
12
 
13
13
  ```bash
14
- $ node-bin-gen {node,iojs} version [pre]
14
+ $ node-bin-gen version [pre]
15
15
  ```
16
16
 
17
17
  Use a `pre` version if you're testing.
@@ -20,7 +20,7 @@ Use a `pre` version if you're testing.
20
20
 
21
21
  Warning: requires `npm@>=3` to install the generated packages globally!
22
22
 
23
- This package generates a `node-bin` or `iojs-bin` package, and all of the `node-{os}-{cpu}` packages, which are installed by the main metapackage (and as a hack, added to the `package.json` of `node-bin` at install time as a dependency to keep npm from marking it extraneous..
23
+ This package generates a `node` package, and all of the `node-{os}-{cpu}` packages, which are installed by the main metapackage (and as a hack, added to the `package.json` of `node` at install time as a dependency to keep npm from marking it extraneous..
24
24
 
25
25
  # License
26
26
 
package/index.js CHANGED
@@ -1,216 +1,281 @@
1
1
  #!/usr/bin/env node
2
- "use strict"
3
-
4
- const fs = require('fs')
5
- const path = require('path')
6
- const os = require('os')
7
- const util = require('util')
8
- const execFile = util.promisify(require('child_process').execFile)
9
- const unlink = util.promisify(fs.unlink)
10
- const mkdir = util.promisify(fs.mkdir)
11
- const writeFile = util.promisify(fs.writeFile)
12
- const readFile = util.promisify(fs.readFile)
13
-
14
- const fetch = require('make-fetch-happen').defaults({
15
- cacheManager: path.resolve(os.homedir(), '.node-bin-gen-cache')
16
- })
17
-
18
- const VError = require('verror')
19
- const rimraf = util.promisify(require('rimraf'))
20
- const zlib = require('zlib')
21
- const { spawn } = require('child_process')
22
- const yargs = require('yargs')
23
- const pump = util.promisify(require('pump'))
24
- const debug = require('util').debuglog('node-bin-gen')
25
- const eos = util.promisify(require('end-of-stream'))
26
-
27
- yargs.option('skip-binaries', { describe: 'Skip downloading the binaries', boolean: true })
28
- yargs.option('only', { describe: 'Only download this binary package' })
29
- yargs.option('package-name', { alias: 'n', describe: 'Use this as the main package name', default: 'node' })
30
- yargs.version()
31
- yargs.demandCommand(1, 2, 'You must specify version, and optionally a prerelease')
32
- yargs.help('help').wrap(76)
33
-
34
- const argv = yargs.argv
35
-
36
- const versionprime = argv._[0]
37
- const pre = argv._[1]
2
+ "use strict";
3
+
4
+ import { open, unlink, mkdir, writeFile, readFile } from "node:fs/promises";
5
+ import { Writable, Transform } from "node:stream";
6
+ import { join, resolve, dirname } from "node:path";
7
+ import { promisify, debuglog } from "node:util";
8
+ import { execFile, spawn } from "node:child_process";
9
+ import { fileURLToPath } from "url";
10
+
11
+ import verr from "verror";
12
+ import rimrafcb from "rimraf";
13
+ import zlib from "zlib";
14
+ import yargs from "yargs";
15
+
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = dirname(__filename);
18
+
19
+ const { VError } = verr;
20
+ const rimraf = promisify(rimrafcb);
21
+
22
+ const argparser = yargs(process.argv.slice(2));
23
+ argparser.option("skip-binaries", {
24
+ describe: "Skip downloading the binaries",
25
+ boolean: true,
26
+ });
27
+ argparser.option("only", { describe: "Only download this binary package" });
28
+ argparser.option("package-name", {
29
+ alias: "n",
30
+ describe: "Use this as the main package name",
31
+ default: "node",
32
+ });
33
+ argparser.option("verbose", { describe: "output messages" });
34
+ argparser.version();
35
+ argparser.demandCommand(
36
+ 1,
37
+ 2,
38
+ "You must specify version, and optionally a prerelease"
39
+ );
40
+ argparser.help("help").wrap(76);
41
+
42
+ const argv = argparser.argv;
43
+
44
+ const versionprime = argv._[0];
45
+ const pre = argv._[1];
38
46
 
39
47
  if (!versionprime) {
40
- console.warn("Use: " + argv.$0 + " version [pre]")
41
- process.exit(1)
42
- return
48
+ console.warn("Use: " + argv.$0 + " version [pre]");
49
+ process.exit(1);
43
50
  }
44
51
 
45
- const version = (versionprime[0] != 'v') ? 'v' + versionprime : version
52
+ const ndebug = debuglog("node-bin-gen");
53
+ function debug(...args) {
54
+ if (argv.verbose) {
55
+ console.warn(...args);
56
+ }
57
+ ndebug(...args);
58
+ }
59
+
60
+ const version = versionprime[0] != "v" ? "v" + versionprime : version;
46
61
 
47
62
  async function buildArchPackage(os, cpu, version, pre) {
48
- debug("building architecture specific package", os, cpu, version, pre)
63
+ debug("building architecture specific package", os, cpu, version, pre);
49
64
 
50
- const platform = os == 'win' ? 'win32' : os
51
- const arch = os == 'win' && cpu == 'ia32' ? 'x86' : cpu
52
- const executable = os == 'win' ? 'bin/node.exe' : 'bin/node'
65
+ const platform = os == "win" ? "win32" : os;
66
+ const arch = os == "win" && cpu == "ia32" ? "x86" : cpu;
67
+ const executable = os == "win" ? "bin/node.exe" : "bin/node";
53
68
 
54
- const dir = "node-" + os + '-' + cpu
55
- const base = "node-" + version + "-" + os + "-" + cpu
56
- const filename = base + (os == 'win' ? '.zip' : ".tar.gz")
69
+ const dir = "node-" + os + "-" + cpu;
70
+ const base = "node-" + version + "-" + os + "-" + cpu;
71
+ const filename = base + (os == "win" ? ".zip" : ".tar.gz");
57
72
  const pkg = {
58
- name: 'node' + "-" + os + "-" + cpu,
59
- version: version + (pre != null ? '-' + pre : ''),
60
- description: 'node',
73
+ name:
74
+ (os == "darwin" && cpu == "arm64" ? "node-bin" : "node") +
75
+ "-" +
76
+ os +
77
+ "-" +
78
+ cpu,
79
+ version: version + (pre != null ? "-" + pre : ""),
80
+ description: "node",
61
81
  bin: {
62
- node: executable
82
+ node: executable,
63
83
  },
64
84
  files: [
65
- os == 'win' ? 'bin/node.exe' : 'bin/node',
66
- 'share',
67
- 'include',
68
- '*.md',
69
- 'LICENSE'
85
+ os == "win" ? "bin/node.exe" : "bin/node",
86
+ "share",
87
+ "include",
88
+ "*.md",
89
+ "LICENSE",
70
90
  ],
71
91
  os: platform,
72
- cpu: arch
73
- }
92
+ cpu: arch,
93
+ };
94
+
95
+ debug("removing", dir);
96
+ await rimraf(dir, { glob: false });
97
+ await mkdir(dir).catch((e) => {
98
+ if (e.code != "EEXIST") throw e;
99
+ });
100
+
101
+ const url =
102
+ "https://nodejs.org" +
103
+ (/rc/.test(version)
104
+ ? "/download/rc/"
105
+ : /test/.test(version)
106
+ ? "/download/test/"
107
+ : "/dist/") +
108
+ version +
109
+ "/" +
110
+ filename;
111
+
112
+ debug("Fetching", url);
113
+
114
+ const res = await fetch(url);
74
115
 
75
- debug('removing', dir)
76
- await rimraf(dir, { glob: false })
77
- await mkdir(dir).catch(e => {
78
- if (e.code != 'EEXIST') throw e
79
- })
116
+ if (res.status != 200 && res.status != 304) {
117
+ throw new VError("not ok: fetching %j got status code %s", url, res.status);
118
+ }
80
119
 
81
- const url = "https://nodejs.org" + (
82
- /rc/.test(version) ? "/download/rc/" :
83
- /test/.test(version) ? "/download/test/" :
84
- "/dist/"
85
- ) + version + "/" + filename
120
+ debug("Unpacking into", dir);
86
121
 
87
- debug("Fetching", url)
122
+ if (os == "win") {
123
+ const f = await open(filename, "w");
88
124
 
89
- const res = await fetch(url)
125
+ await res.body.pipeTo(Writable.toWeb(f.createWriteStream()));
126
+ f.close();
90
127
 
91
- if (res.status != 200 && res.status != 304) {
92
- throw new VError("not ok: fetching %j got status code %s", url, res.status)
93
- }
128
+ const running = execFile("unzip", [
129
+ "-d",
130
+ `${dir}/bin`,
131
+ "-o",
132
+ "-j",
133
+ filename,
134
+ `${base}/node.exe`,
135
+ ]);
94
136
 
95
- debug("Unpacking into", dir)
137
+ await new Promise((y, n) => {
138
+ running.on("error", n);
139
+ running.on("exit", y);
140
+ });
141
+ await unlink(filename);
142
+ } else {
143
+ const c = spawn("tar", ["--strip-components=1", "-C", dir, "-x"], {
144
+ stdio: ["pipe", process.stdout, process.stderr],
145
+ });
96
146
 
97
- if (os == 'win') {
98
- const f = fs.createWriteStream(filename)
99
- const written = pump(res.body, f)
100
- const closed = eos(f)
147
+ const unzip = Transform.toWeb(zlib.createGunzip());
101
148
 
102
- await Promise.all([written, closed])
103
- await execFile('unzip', ['-d', `${dir}/bin`, '-o', '-j', filename, `${base}/node.exe` ])
104
- await unlink(filename)
105
- } else {
106
- const c = spawn('tar', ['--strip-components=1', '-C', dir, '-x'], {
107
- stdio: [ 'pipe', process.stdout, process.stderr ]
108
- })
109
- await pump(res.body, zlib.createGunzip(), c.stdin)
149
+ await res.body.pipeThrough(unzip).pipeTo(Writable.toWeb(c.stdin));
110
150
  }
111
151
 
112
- await writeFile(path.join(dir, 'package.json'), JSON.stringify(pkg, null, 2))
113
- return pkg
152
+ await writeFile(join(dir, "package.json"), JSON.stringify(pkg, null, 2));
153
+ return pkg;
114
154
  }
115
155
 
116
156
  async function fetchManifest(version) {
117
- const base = 'http://nodejs.org'
157
+ const base = "http://nodejs.org";
118
158
  const url = (function () {
119
159
  if (/rc/.test(version)) {
120
- return `${base}/download/rc/index.json`
160
+ return `${base}/download/rc/index.json`;
121
161
  } else if (/test/.test(version)) {
122
- return `${base}/download/test/index.json`
162
+ return `${base}/download/test/index.json`;
123
163
  } else {
124
- return `${base}/dist/index.json`
164
+ return `${base}/dist/index.json`;
125
165
  }
126
- })()
127
- const res = await fetch(url)
128
- return res.json()
166
+ })();
167
+ const res = await fetch(url);
168
+ return res.json();
129
169
  }
130
170
 
131
- main().catch(err => {
132
- console.warn(err.stack)
133
- process.exit(1)
134
- })
171
+ main().catch((err) => {
172
+ console.warn(err.stack);
173
+ process.exit(1);
174
+ });
135
175
 
136
176
  async function main() {
177
+ const manifest = argv["skip-binaries"] ? [] : await fetchManifest(version);
137
178
 
138
- const manifest = argv['skip-binaries'] ? [] : await fetchManifest(version)
139
-
140
- const v = manifest.filter(function(ver) {
141
- return ver.version == version
142
- }).shift()
179
+ const v = manifest
180
+ .filter(function (ver) {
181
+ return ver.version == version;
182
+ })
183
+ .shift();
143
184
 
144
185
  if (!v) {
145
- throw new VError("No such version '%s'", version)
186
+ throw new VError("No such version '%s'", version);
146
187
  }
147
- debug("manifest", v)
188
+ debug("manifest", v);
148
189
 
149
190
  if (!v.files || !v.files.length) {
150
- debug("No files, defaulting")
151
- v.files = ['darwin-x64', 'linux-arm64', 'linux-armv7l', 'linux-ppc64', 'linux-ppc64le', 'linux-s390x', 'linux-x64', 'linux-x86', 'sunos-x64', 'win-x64', 'win-x86']
191
+ debug("No files, defaulting");
192
+ v.files = [
193
+ "darwin-x64",
194
+ "darwin-arm64",
195
+ "linux-arm64",
196
+ "linux-armv7l",
197
+ "linux-ppc64",
198
+ "linux-ppc64le",
199
+ "linux-s390x",
200
+ "linux-x64",
201
+ "linux-x86",
202
+ "sunos-x64",
203
+ "win-x64",
204
+ "win-x86",
205
+ ];
152
206
  }
153
207
 
154
- const files = argv.only ? [argv.only] : v.files
208
+ const files = argv.only ? [argv.only] : v.files;
155
209
 
156
- const binaries = files.filter(function(f) {
157
- return !/^headers|^src/.test(f) && !/pkg$/.test(f) && !/^win-...-(exe|msi|7z)/.test(f)
158
- }).map(function(f) {
159
- const bits = f.split('-')
160
- return {
161
- os: bits[0].replace(/^osx$/, 'darwin'),
162
- cpu: bits[1],
163
- format: bits[2] || 'tar.gz'
164
- }
165
- })
210
+ const binaries = files
211
+ .filter(function (f) {
212
+ return (
213
+ !/^headers|^src/.test(f) &&
214
+ !/pkg$/.test(f) &&
215
+ !/^win-...-(exe|msi|7z)/.test(f)
216
+ );
217
+ })
218
+ .map(function (f) {
219
+ const bits = f.split("-");
220
+ return {
221
+ os: bits[0].replace(/^osx$/, "darwin"),
222
+ cpu: bits[1],
223
+ format: bits[2] || "tar.gz",
224
+ };
225
+ });
166
226
 
167
- await Promise.all(binaries.map(v => buildArchPackage(v.os, v.cpu, version, pre)))
227
+ await Promise.all(
228
+ binaries.map((v) => buildArchPackage(v.os, v.cpu, version, pre))
229
+ );
168
230
 
169
- const pkg = buildMetapackage(version + (pre != null ? '-' + pre : ''))
231
+ const pkg = await buildMetapackage(version + (pre != null ? "-" + pre : ""));
170
232
 
171
233
  try {
172
- await mkdir(pkg.name)
173
- } catch(err) {
174
- if (err && err.code != 'EEXIST') {
175
- throw err
234
+ await mkdir(pkg.name);
235
+ } catch (err) {
236
+ if (err && err.code != "EEXIST") {
237
+ throw err;
176
238
  }
177
239
  }
178
240
 
179
- const script = `require('node-bin-setup')("${pkg.version}", require)`
241
+ const script = `require('node-bin-setup')("${pkg.version}", require)`;
180
242
 
181
243
  await Promise.all([
182
- readFile(path.resolve(__dirname, 'node-bin-README.md'), 'utf8')
183
- .then(readme => writeFile(path.resolve(pkg.name, 'README.md'), readme.replace(/\$\{packagename\}/g, pkg.name))),
184
- writeFile(path.resolve(pkg.name, 'package.json'), JSON.stringify(pkg, null, 2)),
185
- writeFile(path.resolve(pkg.name, 'installArchSpecificPackage.js'), script)
186
- ])
244
+ readFile(resolve(__dirname, "node-bin-README.md"), "utf8").then((readme) =>
245
+ writeFile(
246
+ resolve(pkg.name, "README.md"),
247
+ readme.replace(/\$\{packagename\}/g, pkg.name)
248
+ )
249
+ ),
250
+ writeFile(resolve(pkg.name, "package.json"), JSON.stringify(pkg, null, 2)),
251
+ writeFile(resolve(pkg.name, "installArchSpecificPackage.js"), script),
252
+ ]);
187
253
  }
188
254
 
189
- function buildMetapackage(version) {
255
+ async function buildMetapackage(version) {
190
256
  const pkg = {
191
- "name": argv['package-name'],
192
- "version": version.replace(/^v/, ''),
193
- "description": "node",
194
- "main": "index.js",
195
- "keywords": [
196
- "runtime"
197
- ],
198
- "repository": require('./package.json').repository,
199
- "scripts": {
200
- "preinstall": "node installArchSpecificPackage"
257
+ name: argv["package-name"],
258
+ version: version.replace(/^v/, ""),
259
+ description: "node",
260
+ main: "index.js",
261
+ keywords: ["runtime"],
262
+ repository: JSON.parse(await readFile(`${__dirname}/package.json`))
263
+ .repository,
264
+ scripts: {
265
+ preinstall: "node installArchSpecificPackage",
201
266
  },
202
- "bin": {
203
- "node": "bin/node"
267
+ bin: {
268
+ node: "bin/node",
204
269
  },
205
- "dependencies": {
206
- "node-bin-setup": "^1.0.0"
270
+ dependencies: {
271
+ "node-bin-setup": "^1.0.0",
207
272
  },
208
- "license": "ISC",
209
- "author": "",
210
- "engines": {
211
- "npm": ">=5.0.0"
212
- }
213
- }
273
+ license: "ISC",
274
+ author: "",
275
+ engines: {
276
+ npm: ">=5.0.0",
277
+ },
278
+ };
214
279
 
215
- return pkg
280
+ return pkg;
216
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-bin-gen",
3
- "version": "9.0.4",
3
+ "version": "11.0.0",
4
4
  "description": "Generate a node binary package",
5
5
  "author": "Aria Stewart <aredridel@dinhe.net>",
6
6
  "main": "index.js",
@@ -10,18 +10,18 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/aredridel/node-bin-gen"
12
12
  },
13
+ "type": "module",
13
14
  "engines": {
14
- "node": ">=8.0.0"
15
+ "node": ">=18.0.0"
15
16
  },
16
17
  "dependencies": {
17
- "end-of-stream": "^1.4.1",
18
- "make-fetch-happen": "^9.0.1",
19
- "pump": "^3.0.0",
18
+ "make-fetch-happen": "^10.0.3",
20
19
  "rimraf": "^3.0.0",
21
20
  "verror": "^1.9.0",
22
21
  "yargs": "^17.0.1"
23
22
  },
24
23
  "eslintConfig": {
24
+ "sourceType": "module",
25
25
  "parserOptions": {
26
26
  "ecmaVersion": 8
27
27
  },
@@ -39,5 +39,8 @@
39
39
  "node": true,
40
40
  "es6": true
41
41
  }
42
+ },
43
+ "devDependencies": {
44
+ "eslint": "^8.18.0"
42
45
  }
43
46
  }