@mawesome/npm-vm 0.0.0-alpha.0 → 0.1.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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -1
  3. package/dist/cli.js +4157 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/index-B071ZJDk.d.cts +164 -0
  6. package/dist/index-B071ZJDk.d.ts +164 -0
  7. package/dist/index.cjs +7 -0
  8. package/dist/index.d.cts +2 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +2 -0
  11. package/dist/internal.cjs +2709 -0
  12. package/dist/internal.cjs.map +1 -0
  13. package/dist/internal.d.cts +139 -0
  14. package/dist/internal.d.ts +139 -0
  15. package/dist/internal.js +2706 -0
  16. package/dist/internal.js.map +1 -0
  17. package/dist/provenance--sOYCeF2.js +322 -0
  18. package/dist/provenance--sOYCeF2.js.map +1 -0
  19. package/dist/provenance-DDegWCyS.js +2 -0
  20. package/dist/runtime/atomic-C3shKdH9.cjs +88 -0
  21. package/dist/runtime/bootstrap.cjs +271 -0
  22. package/dist/runtime/commonjs-AANzyd21.cjs +7393 -0
  23. package/dist/runtime/dispatch-B9OSfqsn.cjs +25156 -0
  24. package/dist/runtime/dist-CXwBT6rE.cjs +30766 -0
  25. package/dist/runtime/home-BaoZZSBy.cjs +91 -0
  26. package/dist/runtime/install-C_M5WK98.cjs +13598 -0
  27. package/dist/runtime/journal-_bs-eJRJ.cjs +282 -0
  28. package/dist/runtime/launchers/cmd.tmpl +2 -0
  29. package/dist/runtime/launchers/ps1.tmpl +5 -0
  30. package/dist/runtime/launchers/sh.tmpl +3 -0
  31. package/dist/runtime/lease-HBD4CmBx.cjs +224 -0
  32. package/dist/runtime/lock-DBeYN-Zg.cjs +141 -0
  33. package/dist/runtime/messages-vUDkl1-0.cjs +174 -0
  34. package/dist/runtime/p-map-b8pXdaFZ.cjs +105 -0
  35. package/dist/runtime/proc-hB8N9WjN.cjs +127 -0
  36. package/dist/runtime/provenance-B4bajGXQ.cjs +2 -0
  37. package/dist/runtime/rolldown-runtime-BGT596CS.cjs +64 -0
  38. package/dist/runtime/runtime.cjs +143 -0
  39. package/dist/runtime/src-SpeGbMJx.cjs +314 -0
  40. package/dist/src-Bc9nN1Kl.cjs +2125 -0
  41. package/dist/src-Bc9nN1Kl.cjs.map +1 -0
  42. package/dist/src-NhNG2mnQ.js +1798 -0
  43. package/dist/src-NhNG2mnQ.js.map +1 -0
  44. package/package.json +87 -17
  45. package/index.js +0 -3
@@ -0,0 +1,271 @@
1
+ 'use strict';
2
+ /*
3
+ * npm-vm launcher entry (spec RUN-2), called by the shims as `node bootstrap.cjs <npm|npx|cli> [arguments]`.
4
+ * Hand-written ES5 so any Node from 10 up can run it and fall back to Node's own npm below the floor.
5
+ */
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var childProcess = require('child_process');
9
+
10
+ var LAUNCHER_ABI = 1;
11
+ var FLOOR = [22, 9, 0];
12
+ var FLOOR_TEXT = '22.9.0';
13
+ var VERSION_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
14
+ var home = __dirname;
15
+
16
+ function fail(message, code) {
17
+ process.stderr.write('npm-vm: ' + message + '\n');
18
+ process.exitCode = code;
19
+ }
20
+
21
+ function setupHint() {
22
+ return 'Run "npx --prefix ~ -y @mawesome/npm-vm setup" to reinstall npm-vm.';
23
+ }
24
+
25
+ function belowFloor(version) {
26
+ var parts = version.split('.');
27
+ for (var i = 0; i < 3; i += 1) {
28
+ var part = parseInt(parts[i], 10) || 0;
29
+ if (part < FLOOR[i]) {
30
+ return true;
31
+ }
32
+ if (part > FLOOR[i]) {
33
+ return false;
34
+ }
35
+ }
36
+ return false;
37
+ }
38
+
39
+ function ownNpmRoot() {
40
+ if (process.platform === 'win32') {
41
+ return path.join(path.dirname(process.execPath), 'node_modules', 'npm');
42
+ }
43
+ var real = process.execPath;
44
+ try {
45
+ real = fs.realpathSync(process.execPath);
46
+ } catch (error) {
47
+ // Resolve as given; a missing npm is reported when spawning fails.
48
+ }
49
+ return path.join(path.dirname(real), '..', 'lib', 'node_modules', 'npm');
50
+ }
51
+
52
+ function declaresNpm(manifest) {
53
+ var devEngines = manifest && manifest.devEngines;
54
+ var pm = devEngines && devEngines.packageManager;
55
+ if (pm) {
56
+ var entries = Array.isArray(pm) ? pm : [pm];
57
+ for (var i = 0; i < entries.length; i += 1) {
58
+ if (entries[i] && entries[i].name === 'npm') {
59
+ return true;
60
+ }
61
+ }
62
+ }
63
+ return (
64
+ typeof manifest.packageManager === 'string' && manifest.packageManager.indexOf('npm@') === 0
65
+ );
66
+ }
67
+
68
+ /** Whether the nearest package.json above cwd asks for an npm version, so the fallback can say it is ignored. */
69
+ function projectDeclaresNpm() {
70
+ var dir = process.cwd();
71
+ for (;;) {
72
+ var file = path.join(dir, 'package.json');
73
+ if (fs.existsSync(file)) {
74
+ try {
75
+ return declaresNpm(JSON.parse(fs.readFileSync(file, 'utf8')));
76
+ } catch (error) {
77
+ return false;
78
+ }
79
+ }
80
+ var parent = path.dirname(dir);
81
+ if (parent === dir) {
82
+ return false;
83
+ }
84
+ dir = parent;
85
+ }
86
+ }
87
+
88
+ /** Runs a Node script with the inherited stdio, forwarding signals as the runtime does (spec RUN-4, RUN-5). */
89
+ function runScript(script, args) {
90
+ var child = childProcess.spawn(process.execPath, [script].concat(args), { stdio: 'inherit' });
91
+ var handlers = [];
92
+ var alive = true;
93
+ function forward(signal) {
94
+ if (alive) {
95
+ child.kill(signal);
96
+ }
97
+ }
98
+ function later(signal) {
99
+ var timer = setTimeout(function () {
100
+ forward(signal);
101
+ }, 1000);
102
+ if (timer.unref) {
103
+ timer.unref();
104
+ }
105
+ }
106
+ if (process.platform !== 'win32') {
107
+ var now = ['SIGTERM', 'SIGHUP'];
108
+ var delayed = ['SIGINT', 'SIGQUIT'];
109
+ var i;
110
+ for (i = 0; i < now.length; i += 1) {
111
+ handlers.push([now[i], forward.bind(null, now[i])]);
112
+ }
113
+ for (i = 0; i < delayed.length; i += 1) {
114
+ handlers.push([delayed[i], later.bind(null, delayed[i])]);
115
+ }
116
+ for (i = 0; i < handlers.length; i += 1) {
117
+ process.on(handlers[i][0], handlers[i][1]);
118
+ }
119
+ }
120
+ function cleanup() {
121
+ alive = false;
122
+ for (var j = 0; j < handlers.length; j += 1) {
123
+ process.removeListener(handlers[j][0], handlers[j][1]);
124
+ }
125
+ }
126
+ child.on('error', function (error) {
127
+ cleanup();
128
+ fail('cannot start ' + script + ': ' + error.message, 1);
129
+ });
130
+ child.on('exit', function (code, signal) {
131
+ cleanup();
132
+ if (signal) {
133
+ process.kill(process.pid, signal);
134
+ return;
135
+ }
136
+ process.exitCode = code === null ? 1 : code;
137
+ });
138
+ }
139
+
140
+ function runOwnNpm(selector, args) {
141
+ if (projectDeclaresNpm()) {
142
+ process.stderr.write(
143
+ 'npm-vm: Node ' +
144
+ process.versions.node +
145
+ ' is below ' +
146
+ FLOOR_TEXT +
147
+ "; running Node's own npm and ignoring the project's npm requirement. Upgrade Node to honour it.\n"
148
+ );
149
+ }
150
+ var cli = selector === 'npx' ? 'npx-cli.js' : 'npm-cli.js';
151
+ runScript(path.join(ownNpmRoot(), 'bin', cli), args);
152
+ }
153
+
154
+ function runtimePath(candidate) {
155
+ if (candidate) {
156
+ return path.join(__dirname, 'runtime.cjs');
157
+ }
158
+ var current;
159
+ try {
160
+ current = fs.readFileSync(path.join(home, 'current'), 'utf8').trim();
161
+ } catch (error) {
162
+ return null;
163
+ }
164
+ if (!VERSION_RE.test(current)) {
165
+ return null;
166
+ }
167
+ var installed = path.join(home, 'versions', current, 'runtime.cjs');
168
+ if (fs.existsSync(installed)) {
169
+ return installed;
170
+ }
171
+ return replacedRuntime(current);
172
+ }
173
+
174
+ /** A reinstall of the current version moves the old copy aside for an instant; a crash there leaves it usable. */
175
+ function replacedRuntime(version) {
176
+ var versions = path.join(home, 'versions');
177
+ var names;
178
+ try {
179
+ names = fs.readdirSync(versions);
180
+ } catch (error) {
181
+ return null;
182
+ }
183
+ var prefix = '.' + version + '.replaced.';
184
+ for (var i = 0; i < names.length; i += 1) {
185
+ if (
186
+ names[i].indexOf(prefix) === 0 &&
187
+ fs.existsSync(path.join(versions, names[i], 'runtime.cjs'))
188
+ ) {
189
+ return path.join(versions, names[i], 'runtime.cjs');
190
+ }
191
+ }
192
+ return null;
193
+ }
194
+
195
+ function main() {
196
+ var args = process.argv.slice(2);
197
+ var candidate = false;
198
+ if (args[0] === '--candidate') {
199
+ candidate = true;
200
+ args.shift();
201
+ }
202
+ var selector = args.shift();
203
+ if (selector !== 'npm' && selector !== 'npx' && selector !== 'cli') {
204
+ fail('usage: bootstrap.cjs <npm|npx|cli> [arguments]', 64);
205
+ return;
206
+ }
207
+ if (belowFloor(process.versions.node)) {
208
+ if (selector === 'cli') {
209
+ fail(
210
+ 'npm-vm needs Node ' +
211
+ FLOOR_TEXT +
212
+ ' or newer; the active Node is ' +
213
+ process.versions.node +
214
+ '. Switch to a newer Node to run npm-vm commands.',
215
+ 64
216
+ );
217
+ return;
218
+ }
219
+ runOwnNpm(selector, args);
220
+ return;
221
+ }
222
+ var script = runtimePath(candidate);
223
+ if (script === null) {
224
+ fail(
225
+ 'launcher mismatch: the current pointer in ' +
226
+ home +
227
+ ' is missing or malformed. ' +
228
+ setupHint(),
229
+ 6
230
+ );
231
+ return;
232
+ }
233
+ var runtime;
234
+ try {
235
+ runtime = require(script);
236
+ } catch (error) {
237
+ fail(
238
+ 'launcher mismatch: cannot load ' + script + ' (' + error.message + '). ' + setupHint(),
239
+ 6
240
+ );
241
+ return;
242
+ }
243
+ if (
244
+ typeof runtime.abi !== 'number' ||
245
+ runtime.abi > LAUNCHER_ABI ||
246
+ runtime.abi < LAUNCHER_ABI - 1
247
+ ) {
248
+ fail(
249
+ 'launcher mismatch: runtime ABI ' +
250
+ runtime.abi +
251
+ ' is not supported by launcher ABI ' +
252
+ LAUNCHER_ABI +
253
+ '. ' +
254
+ setupHint(),
255
+ 6
256
+ );
257
+ return;
258
+ }
259
+ runtime.main(selector, args, { home: home, launcherAbi: LAUNCHER_ABI }).then(
260
+ function (code) {
261
+ process.exitCode = code;
262
+ return code;
263
+ },
264
+ function (error) {
265
+ fail(error && error.stack ? error.stack : String(error), 1);
266
+ return 1;
267
+ }
268
+ );
269
+ }
270
+
271
+ main();