@yao-pkg/pkg-fetch 3.6.0 → 3.6.2

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/log.js CHANGED
@@ -1,83 +1,70 @@
1
1
  "use strict";
2
2
  /* eslint-disable no-underscore-dangle, no-console */
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
19
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
5
  };
21
6
  Object.defineProperty(exports, "__esModule", { value: true });
22
7
  exports.wasReported = exports.log = void 0;
23
- var progress_1 = __importDefault(require("progress"));
24
- var assert_1 = __importDefault(require("assert"));
25
- var chalk_1 = __importDefault(require("chalk"));
26
- var Log = /** @class */ (function () {
27
- function Log() {
28
- this.debugMode = false;
29
- }
30
- Log.prototype.lines = function (lines) {
8
+ const progress_1 = __importDefault(require("progress"));
9
+ const assert_1 = __importDefault(require("assert"));
10
+ const picocolors_1 = __importDefault(require("picocolors"));
11
+ const tty_1 = require("tty");
12
+ // workaround until picocolors improves its color detection
13
+ // https://github.com/alexeyraspopov/picocolors/issues/85
14
+ const pc = picocolors_1.default.createColors(tty_1.WriteStream.prototype.hasColors());
15
+ class Log {
16
+ debugMode = false;
17
+ bar;
18
+ lines(lines) {
31
19
  if (lines === undefined) {
32
20
  return;
33
21
  }
34
22
  if (!Array.isArray(lines)) {
35
- console.log(" ".concat(lines));
23
+ console.log(` ${lines}`);
36
24
  return;
37
25
  }
38
- for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
39
- var line = lines_1[_i];
40
- console.log(" ".concat(line));
26
+ for (const line of lines) {
27
+ console.log(` ${line}`);
41
28
  }
42
- };
43
- Log.prototype.debug = function (text, lines) {
29
+ }
30
+ debug(text, lines) {
44
31
  if (!this.debugMode) {
45
32
  return;
46
33
  }
47
- console.log("> ".concat(chalk_1.default.green('[debug]'), " ").concat(text));
34
+ console.log(`> ${pc.green('[debug]')} ${text}`);
48
35
  this.lines(lines);
49
- };
50
- Log.prototype.info = function (text, lines) {
51
- console.log("> ".concat(text));
36
+ }
37
+ info(text, lines) {
38
+ console.log(`> ${text}`);
52
39
  this.lines(lines);
53
- };
54
- Log.prototype.warn = function (text, lines) {
55
- console.log("> ".concat(chalk_1.default.blue('Warning'), " ").concat(text));
40
+ }
41
+ warn(text, lines) {
42
+ console.log(`> ${pc.blue('Warning')} ${text}`);
56
43
  this.lines(lines);
57
- };
58
- Log.prototype.error = function (text, lines) {
59
- var message = text instanceof Error ? text.stack : text;
60
- console.log("> ".concat(chalk_1.default.red('Error!'), " ").concat(message));
44
+ }
45
+ error(text, lines) {
46
+ const message = text instanceof Error ? text.stack : text;
47
+ console.log(`> ${pc.red('Error!')} ${message}`);
61
48
  this.lines(lines);
62
- };
63
- Log.prototype.enableProgress = function (text) {
49
+ }
50
+ enableProgress(text) {
64
51
  (0, assert_1.default)(!this.bar);
65
52
  text += ' '.repeat(35 - text.length);
66
- this.bar = new progress_1.default(" ".concat(text, " [:bar] :percent"), {
53
+ this.bar = new progress_1.default(` ${text} [:bar] :percent`, {
67
54
  stream: process.stdout,
68
55
  width: 20,
69
56
  complete: '=',
70
57
  incomplete: ' ',
71
58
  total: 100,
72
59
  });
73
- };
74
- Log.prototype.showProgress = function (percentage) {
60
+ }
61
+ showProgress(percentage) {
75
62
  if (!this.bar) {
76
63
  return;
77
64
  }
78
65
  this.bar.update(percentage / 100);
79
- };
80
- Log.prototype.disableProgress = function () {
66
+ }
67
+ disableProgress() {
81
68
  if (!this.bar) {
82
69
  return;
83
70
  }
@@ -86,22 +73,15 @@ var Log = /** @class */ (function () {
86
73
  this.bar.terminate();
87
74
  }
88
75
  delete this.bar;
89
- };
90
- return Log;
91
- }());
92
- exports.log = new Log();
93
- var ReportedError = /** @class */ (function (_super) {
94
- __extends(ReportedError, _super);
95
- function ReportedError() {
96
- var _this = _super !== null && _super.apply(this, arguments) || this;
97
- _this.name = 'ReportedError';
98
- _this.wasReported = true;
99
- return _this;
100
76
  }
101
- return ReportedError;
102
- }(Error));
77
+ }
78
+ exports.log = new Log();
79
+ class ReportedError extends Error {
80
+ name = 'ReportedError';
81
+ wasReported = true;
82
+ }
103
83
  function wasReported(error, lines) {
104
- var reportedError = new ReportedError('No message');
84
+ let reportedError = new ReportedError('No message');
105
85
  if (typeof error === 'string') {
106
86
  exports.log.error(error, lines);
107
87
  reportedError = new ReportedError(error);
@@ -0,0 +1,3 @@
1
+ declare function parseAndUpdateShas(inputFile: string): void;
2
+ export { parseAndUpdateShas };
3
+ //# sourceMappingURL=parse-update-shas.d.ts.map
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parseAndUpdateShas = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const path = __importStar(require("path"));
29
+ const log_1 = require("./log");
30
+ function parseAndUpdateShas(inputFile) {
31
+ // Read the input file containing new SHAs
32
+ if (!fs.existsSync(inputFile)) {
33
+ throw (0, log_1.wasReported)(`Input file ${inputFile} does not exist`);
34
+ }
35
+ const input = fs.readFileSync(inputFile, 'utf8');
36
+ const lines = input.split('\n').map(l => l.trim()).filter(Boolean);
37
+ // Read existing shas.txt
38
+ const shasPath = path.join(process.cwd(), 'shas.txt');
39
+ let shasTxt = '';
40
+ try {
41
+ shasTxt = fs.readFileSync(shasPath, 'utf8');
42
+ }
43
+ catch (e) {
44
+ log_1.log.info('shas.txt not found, creating new one');
45
+ shasTxt = '';
46
+ }
47
+ let shasArr = shasTxt.split('\n');
48
+ // Process each line from input
49
+ for (const line of lines) {
50
+ const [sha, patchName] = line.split(/\s+/);
51
+ if (!sha || !patchName) {
52
+ log_1.log.warn(`Skipping invalid line: ${line}`);
53
+ continue;
54
+ }
55
+ // Extract major, os, arch. E.g.: node-v22.20.0-win-x64
56
+ const match = patchName.match(/^node-v(\d+)\.[^ ]*-(.+)-(.+)$/);
57
+ if (!match) {
58
+ log_1.log.warn(`Skipping line with invalid patch name format: ${line}`);
59
+ continue;
60
+ }
61
+ const major = match[1];
62
+ const os = match[2];
63
+ const arch = match[3];
64
+ // Regex for matching line in shas.txt
65
+ const re = new RegExp(`^\\S+\\s+node-v${major}\\.([0-9.]+){2}-${os}-${arch}$`);
66
+ let found = false;
67
+ shasArr = shasArr.map(l => {
68
+ if (re.test(l)) {
69
+ found = true;
70
+ log_1.log.info(`Updating: ${l} -> ${sha} ${patchName}`);
71
+ return `${sha} ${patchName}`;
72
+ }
73
+ return l;
74
+ });
75
+ if (!found) {
76
+ log_1.log.info(`Adding new entry: ${sha} ${patchName}`);
77
+ shasArr.push(`${sha} ${patchName}`);
78
+ }
79
+ }
80
+ // Write updated shas.txt
81
+ const filteredShas = shasArr.filter(Boolean);
82
+ const updatedContent = filteredShas.length > 0 ? `${filteredShas.join('\n')}\n` : '';
83
+ fs.writeFileSync(shasPath, updatedContent);
84
+ log_1.log.info(`Successfully updated ${shasPath}`);
85
+ }
86
+ exports.parseAndUpdateShas = parseAndUpdateShas;
87
+ // Main execution
88
+ if (require.main === module) {
89
+ const args = process.argv.slice(2);
90
+ if (args.length !== 1) {
91
+ log_1.log.error('Usage: parse-update-shas.ts <input-file>');
92
+ log_1.log.error(' input-file: Path to file containing SHA lines in format "<sha> <patch-name>"');
93
+ process.exit(1);
94
+ }
95
+ const inputFile = args[0];
96
+ try {
97
+ parseAndUpdateShas(inputFile);
98
+ }
99
+ catch (error) {
100
+ if (error instanceof Error && !('wasReported' in error)) {
101
+ log_1.log.error(error);
102
+ }
103
+ process.exit(1);
104
+ }
105
+ }
106
+ //# sourceMappingURL=parse-update-shas.js.map
package/lib-es5/places.js CHANGED
@@ -4,20 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.remotePlace = exports.localPlace = exports.cachePath = void 0;
7
- var semver_1 = require("semver");
8
- var os_1 = __importDefault(require("os"));
9
- var path_1 = __importDefault(require("path"));
10
- var PKG_CACHE_PATH = process.env.PKG_CACHE_PATH;
11
- var IGNORE_TAG = Boolean(process.env.PKG_IGNORE_TAG);
7
+ const semver_1 = require("semver");
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const { PKG_CACHE_PATH } = process.env;
11
+ const IGNORE_TAG = Boolean(process.env.PKG_IGNORE_TAG);
12
12
  exports.cachePath = PKG_CACHE_PATH || path_1.default.join(os_1.default.homedir(), '.pkg-cache');
13
13
  function tagFromVersion(version) {
14
- var mj = (0, semver_1.major)(version);
15
- var mn = (0, semver_1.minor)(version);
16
- return "v".concat(mj, ".").concat(mn);
14
+ const mj = (0, semver_1.major)(version);
15
+ const mn = (0, semver_1.minor)(version);
16
+ return `v${mj}.${mn}`;
17
17
  }
18
- function localPlace(_a) {
19
- var from = _a.from, output = _a.output, version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
20
- var binDir;
18
+ function localPlace({ from, output, version, nodeVersion, platform, arch, }) {
19
+ let binDir;
21
20
  if (process.env.PKG_NODE_PATH) {
22
21
  return path_1.default.resolve(process.env.PKG_NODE_PATH);
23
22
  }
@@ -29,14 +28,13 @@ function localPlace(_a) {
29
28
  ? path_1.default.join(exports.cachePath)
30
29
  : path_1.default.join(exports.cachePath, tagFromVersion(version));
31
30
  }
32
- return path_1.default.resolve(binDir, "".concat(output ? 'node' : from, "-").concat(nodeVersion, "-").concat(platform, "-").concat(arch));
31
+ return path_1.default.resolve(binDir, `${output ? 'node' : from}-${nodeVersion}-${platform}-${arch}`);
33
32
  }
34
33
  exports.localPlace = localPlace;
35
- function remotePlace(_a) {
36
- var version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
34
+ function remotePlace({ version, nodeVersion, platform, arch, }) {
37
35
  return {
38
36
  tag: tagFromVersion(version),
39
- name: "node-".concat(nodeVersion, "-").concat(platform, "-").concat(arch),
37
+ name: `node-${nodeVersion}-${platform}-${arch}`,
40
38
  };
41
39
  }
42
40
  exports.remotePlace = remotePlace;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var expected_1 = require("./expected");
4
- var utils_1 = require("./utils");
3
+ const expected_1 = require("./expected");
4
+ const utils_1 = require("./utils");
5
5
  /* eslint-disable no-console */
6
6
  function main() {
7
- for (var _i = 0, _a = Object.keys(expected_1.EXPECTED_HASHES).sort(utils_1.nodeBinarySortFunction); _i < _a.length; _i++) {
8
- var nodeVersion = _a[_i];
9
- console.log("".concat(expected_1.EXPECTED_HASHES[nodeVersion], " ").concat(nodeVersion));
7
+ for (const nodeVersion of Object.keys(expected_1.EXPECTED_HASHES).sort(utils_1.nodeBinarySortFunction)) {
8
+ console.log(`${expected_1.EXPECTED_HASHES[nodeVersion]} ${nodeVersion}`);
10
9
  }
11
10
  }
12
11
  main();
package/lib-es5/system.js CHANGED
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.knownArchs = exports.targetArchs = exports.hostArch = exports.knownPlatforms = exports.hostPlatform = exports.hostAbi = exports.toFancyArch = exports.toFancyPlatform = exports.isValidNodeRange = exports.abiToNodeRange = void 0;
7
- var fs_1 = __importDefault(require("fs"));
8
- var child_process_1 = require("child_process");
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const child_process_1 = require("child_process");
9
9
  function getHostAbi() {
10
- return "m".concat(process.versions.modules);
10
+ return `m${process.versions.modules}`;
11
11
  }
12
12
  function abiToNodeRange(abi) {
13
13
  if (/^m?14/.test(abi))
@@ -62,25 +62,24 @@ function toFancyPlatform(platform) {
62
62
  }
63
63
  exports.toFancyPlatform = toFancyPlatform;
64
64
  function detectAlpine() {
65
- var _a;
66
- var platform = process.platform;
65
+ const { platform } = process;
67
66
  if (platform !== 'linux') {
68
67
  return false;
69
68
  }
70
69
  // https://github.com/sass/node-sass/issues/1589#issuecomment-265292579
71
- var ldd = (_a = (0, child_process_1.spawnSync)('ldd').stderr) === null || _a === void 0 ? void 0 : _a.toString();
70
+ const ldd = (0, child_process_1.spawnSync)('ldd').stderr?.toString();
72
71
  if (ldd == null) {
73
- return fs_1.default.readdirSync('/lib').some(function (file) { return file.startsWith('libc.musl'); });
72
+ return fs_1.default.readdirSync('/lib').some((file) => file.startsWith('libc.musl'));
74
73
  }
75
74
  if (/\bmusl\b/.test(ldd)) {
76
75
  return true;
77
76
  }
78
- var lddNode = (0, child_process_1.spawnSync)('ldd', [process.execPath]).stdout.toString();
77
+ const lddNode = (0, child_process_1.spawnSync)('ldd', [process.execPath]).stdout.toString();
79
78
  return /\bmusl\b/.test(lddNode);
80
79
  }
81
- var isAlpine = detectAlpine();
80
+ const isAlpine = detectAlpine();
82
81
  function getHostPlatform() {
83
- var platform = process.platform;
82
+ const { platform } = process;
84
83
  if (isAlpine) {
85
84
  return 'alpine';
86
85
  }
@@ -98,11 +97,11 @@ function toFancyArch(arch) {
98
97
  }
99
98
  exports.toFancyArch = toFancyArch;
100
99
  function getArmUnameArch() {
101
- var uname = (0, child_process_1.spawnSync)('uname', ['-a']);
100
+ const uname = (0, child_process_1.spawnSync)('uname', ['-a']);
102
101
  if (uname.error) {
103
102
  return '';
104
103
  }
105
- var unameOut = uname.stdout && uname.stdout.toString();
104
+ let unameOut = uname.stdout && uname.stdout.toString();
106
105
  unameOut = (unameOut || '').toLowerCase();
107
106
  if (unameOut.includes('aarch64'))
108
107
  return 'arm64';
@@ -113,36 +112,35 @@ function getArmUnameArch() {
113
112
  return '';
114
113
  }
115
114
  function getArmHostArch() {
116
- var _a;
117
- var cpu = fs_1.default.readFileSync('/proc/cpuinfo', 'utf8');
115
+ const cpu = fs_1.default.readFileSync('/proc/cpuinfo', 'utf8');
118
116
  if (cpu.indexOf('vfpv3') >= 0) {
119
117
  return 'armv7';
120
118
  }
121
- var name = cpu.split('model name')[1];
119
+ let name = cpu.split('model name')[1];
122
120
  if (name)
123
- _a = name.split(':'), name = _a[1];
121
+ [, name] = name.split(':');
124
122
  if (name)
125
- name = name.split('\n')[0];
123
+ [name] = name.split('\n');
126
124
  if (name && name.indexOf('ARMv7') >= 0)
127
125
  return 'armv7';
128
126
  return 'armv6';
129
127
  }
130
128
  function getHostArch() {
131
- var arch = process.arch;
129
+ const { arch } = process;
132
130
  if (arch === 'arm') {
133
131
  return getArmUnameArch() || getArmHostArch();
134
132
  }
135
133
  return toFancyArch(arch);
136
134
  }
137
135
  function getTargetArchs() {
138
- var arch = getHostArch();
136
+ const arch = getHostArch();
139
137
  if (arch === 'x64') {
140
138
  return ['x64', 'x86'];
141
139
  }
142
140
  return [arch];
143
141
  }
144
142
  function getKnownArchs() {
145
- return ['x64', 'x86', 'armv7', 'arm64', 'ppc64', 's390x'];
143
+ return ['x64', 'x86', 'armv7', 'arm64', 'ppc64', 's390x', 'riscv64', 'loong64'];
146
144
  }
147
145
  exports.hostAbi = getHostAbi();
148
146
  exports.hostPlatform = getHostPlatform();