@neon-rs/manifest 0.0.2 → 0.0.4
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/abstract.cjs +85 -0
- package/lib/abstract.d.cts +25 -0
- package/lib/cache/cache.cjs +2 -0
- package/lib/cache/cache.d.cts +9 -0
- package/lib/cache/npm/legacy.cjs +116 -0
- package/lib/cache/npm/legacy.d.cts +1 -0
- package/lib/cache/npm/manifest.cjs +76 -0
- package/lib/cache/npm/manifest.d.cts +26 -0
- package/lib/cache/npm/npm.cjs +136 -0
- package/lib/cache/npm/npm.d.cts +17 -0
- package/lib/cache/npm/package.cjs +114 -0
- package/lib/cache/npm/package.d.cts +19 -0
- package/lib/cache/npm.cjs +308 -0
- package/lib/cache/npm.d.cts +31 -0
- package/lib/cache.cjs +2 -0
- package/lib/cache.d.cts +5 -0
- package/lib/change.cjs +48 -0
- package/lib/change.d.cts +49 -0
- package/lib/index.cjs +3 -574
- package/lib/index.d.cts +1 -64
- package/lib/index.d.mts +1 -1
- package/lib/index.mjs +1 -1
- package/lib/library/legacy.cjs +110 -0
- package/lib/library/legacy.d.cts +1 -0
- package/lib/library/library.cjs +143 -0
- package/lib/library/library.d.cts +31 -0
- package/lib/library/neon.cjs +11 -0
- package/lib/library/neon.d.cts +4 -0
- package/lib/neon.cjs +11 -0
- package/lib/neon.d.cts +4 -0
- package/lib/platform.cjs +31 -3
- package/lib/platform.d.cts +3 -1
- package/lib/platform.d.mts +1 -1
- package/lib/platform.mjs +1 -1
- package/lib/util.cjs +92 -0
- package/lib/util.d.cts +25 -0
- package/package.json +22 -9
package/lib/index.cjs
CHANGED
|
@@ -1,576 +1,5 @@
|
|
|
1
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.LibraryManifest =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const platform_cjs_1 = require("./platform.cjs");
|
|
33
|
-
const jscodeshift_1 = __importDefault(require("jscodeshift"));
|
|
34
|
-
function assertIsObject(json, path) {
|
|
35
|
-
if (!json || typeof json !== 'object') {
|
|
36
|
-
throw new TypeError(`expected "${path}" property to be an object, found ${json}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Idea thanks to https://www.lucaspaganini.com/academy/assertion-functions-typescript-narrowing-5
|
|
40
|
-
function assertHasProps(keys, json, path) {
|
|
41
|
-
assertIsObject(json, path);
|
|
42
|
-
for (const key of keys) {
|
|
43
|
-
if (!(key in json)) {
|
|
44
|
-
throw new TypeError(`property "${path}.${key}" not found`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function assertIsBinaryCfg(json) {
|
|
49
|
-
assertHasProps(['type', 'rust', 'node', 'os', 'arch', 'abi'], json, "neon");
|
|
50
|
-
if (json.type !== 'binary') {
|
|
51
|
-
throw new TypeError(`expected "neon.type" property to be "binary", found ${json.type}`);
|
|
52
|
-
}
|
|
53
|
-
if (typeof json.rust !== 'string' || !(0, platform_cjs_1.isRustTarget)(json.rust)) {
|
|
54
|
-
throw new TypeError(`expected "neon.rust" to be a valid Rust target, found ${json.rust}`);
|
|
55
|
-
}
|
|
56
|
-
if (typeof json.node !== 'string' || !(0, platform_cjs_1.isNodePlatform)(json.node)) {
|
|
57
|
-
throw new TypeError(`expected "neon.node" to be a valid Node target, found ${json.node}`);
|
|
58
|
-
}
|
|
59
|
-
if (typeof json.os !== 'string') {
|
|
60
|
-
throw new TypeError(`expected "neon.os" to be a string, found ${json.os}`);
|
|
61
|
-
}
|
|
62
|
-
if (typeof json.arch !== 'string') {
|
|
63
|
-
throw new TypeError(`expected "neon.arch" to be a string, found ${json.arch}`);
|
|
64
|
-
}
|
|
65
|
-
if (json.abi !== null && typeof json.abi !== 'string') {
|
|
66
|
-
throw new TypeError(`expected "neon.abi" to be a string or null, found ${json.abi}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function assertIsPlatformMap(json, path) {
|
|
70
|
-
assertIsObject(json, path);
|
|
71
|
-
for (const key in json) {
|
|
72
|
-
const value = json[key];
|
|
73
|
-
if (!(0, platform_cjs_1.isNodePlatform)(key)) {
|
|
74
|
-
throw new TypeError(`platform table key ${key} is not a valid Node platform`);
|
|
75
|
-
}
|
|
76
|
-
if (typeof value !== 'string' || !(0, platform_cjs_1.isRustTarget)(value)) {
|
|
77
|
-
throw new TypeError(`platform table value ${value} is not a valid Rust target`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function assertIsPlatformFamily(json, path) {
|
|
82
|
-
if (typeof json === 'string') {
|
|
83
|
-
(0, platform_cjs_1.assertIsPlatformPreset)(json);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (Array.isArray(json)) {
|
|
87
|
-
for (const elt of json) {
|
|
88
|
-
(0, platform_cjs_1.assertIsPlatformPreset)(elt);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
assertIsPlatformMap(json, path);
|
|
93
|
-
}
|
|
94
|
-
function assertIsBinaryV2(json) {
|
|
95
|
-
if (!json || typeof json !== 'object') {
|
|
96
|
-
throw new TypeError(`expected "neon" to be an object, found ${json}`);
|
|
97
|
-
}
|
|
98
|
-
assertHasProps(['rust', 'node', 'platform', 'arch', 'abi'], json, "neon");
|
|
99
|
-
if (!(0, platform_cjs_1.isRustTarget)(json.rust)) {
|
|
100
|
-
throw new TypeError(`expected "neon.rust" to be a valid Rust target, found ${json.rust}`);
|
|
101
|
-
}
|
|
102
|
-
if (!(0, platform_cjs_1.isNodePlatform)(json.node)) {
|
|
103
|
-
throw new TypeError(`expected "neon.node" to be a valid Node platform, found ${json.node}`);
|
|
104
|
-
}
|
|
105
|
-
if (typeof json.platform !== 'string') {
|
|
106
|
-
throw new TypeError(`expected "neon.platform" to be a string, found ${json.platform}`);
|
|
107
|
-
}
|
|
108
|
-
if (typeof json.arch !== 'string') {
|
|
109
|
-
throw new TypeError(`expected "neon.arch" to be a string, found ${json.arch}`);
|
|
110
|
-
}
|
|
111
|
-
if (json.abi !== null && typeof json.abi !== 'string') {
|
|
112
|
-
throw new TypeError(`expected "neon.abi" to be a string or null, found ${json.abi}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function assertIsBinaryV1(json) {
|
|
116
|
-
assertHasProps(['binary'], json, "neon");
|
|
117
|
-
const binary = json.binary;
|
|
118
|
-
if (!binary || typeof binary !== 'object') {
|
|
119
|
-
throw new TypeError(`expected "neon.binary" to be an object, found ${binary}`);
|
|
120
|
-
}
|
|
121
|
-
assertHasProps(['rust', 'node', 'platform', 'arch', 'abi'], binary, "neon.binary");
|
|
122
|
-
if (typeof binary.rust !== 'string' || !(0, platform_cjs_1.isRustTarget)(binary.rust)) {
|
|
123
|
-
throw new TypeError(`expected "neon.binary.rust" to be a valid Rust target, found ${binary.rust}`);
|
|
124
|
-
}
|
|
125
|
-
if (!(0, platform_cjs_1.isNodePlatform)(binary.node)) {
|
|
126
|
-
throw new TypeError(`expected "neon.binary.node" to be a valid Node platform, found ${binary.node}`);
|
|
127
|
-
}
|
|
128
|
-
if (typeof binary.platform !== 'string') {
|
|
129
|
-
throw new TypeError(`expected "neon.binary.platform" to be a string, found ${binary.platform}`);
|
|
130
|
-
}
|
|
131
|
-
if (typeof binary.arch !== 'string') {
|
|
132
|
-
throw new TypeError(`expected "neon.binary.arch" to be a string, found ${binary.arch}`);
|
|
133
|
-
}
|
|
134
|
-
if (binary.abi !== null && typeof binary.abi !== 'string') {
|
|
135
|
-
throw new TypeError(`expected "neon.binary.abi" to be a string or null, found ${binary.abi}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function assertIsLibraryV1(json) {
|
|
139
|
-
assertIsObject(json, "neon");
|
|
140
|
-
for (const key in json) {
|
|
141
|
-
const value = json[key];
|
|
142
|
-
if (!(0, platform_cjs_1.isRustTarget)(key)) {
|
|
143
|
-
throw new TypeError(`target table key ${key} is not a valid Rust target`);
|
|
144
|
-
}
|
|
145
|
-
if (typeof value !== 'string') {
|
|
146
|
-
throw new TypeError(`target table value ${value} is not a string`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function assertIsLibraryCfg(json) {
|
|
151
|
-
assertHasProps(['type', 'org', 'platforms'], json, "neon");
|
|
152
|
-
if (json.type !== 'library') {
|
|
153
|
-
throw new TypeError(`expected "neon.type" property to be "library", found ${json.type}`);
|
|
154
|
-
}
|
|
155
|
-
if (typeof json.org !== 'string') {
|
|
156
|
-
throw new TypeError(`expected "neon.org" to be a string, found ${json.org}`);
|
|
157
|
-
}
|
|
158
|
-
assertIsPlatformFamily(json.platforms, "neon.platforms");
|
|
159
|
-
if ('load' in json) {
|
|
160
|
-
if (typeof json.load !== 'string' && typeof json.load !== 'undefined') {
|
|
161
|
-
throw new TypeError(`expected "neon.load" to be a string, found ${json.load}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function assertIsPreamble(json) {
|
|
166
|
-
if (!json || typeof json !== 'object') {
|
|
167
|
-
throw new TypeError(`expected binary Neon package manifest, found ${json}`);
|
|
168
|
-
}
|
|
169
|
-
if (!('version' in json) || typeof json.version !== 'string') {
|
|
170
|
-
throw new TypeError('valid "version" string not found in Neon package manifest');
|
|
171
|
-
}
|
|
172
|
-
if (!('name' in json) || typeof json.name !== 'string') {
|
|
173
|
-
throw new TypeError('valid "name" string not found in Neon package manifest');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
class AbstractManifest {
|
|
177
|
-
constructor(json) {
|
|
178
|
-
assertIsPreamble(json);
|
|
179
|
-
this._json = json;
|
|
180
|
-
this._upgraded = false;
|
|
181
|
-
}
|
|
182
|
-
get name() { return this._json.name; }
|
|
183
|
-
set name(value) { this._json.name = value; }
|
|
184
|
-
get version() { return this._json.version; }
|
|
185
|
-
set version(value) { this._json.version = value; }
|
|
186
|
-
get description() { return this._json.description ?? ""; }
|
|
187
|
-
get upgraded() { return this._upgraded; }
|
|
188
|
-
async save(dir) {
|
|
189
|
-
dir = dir ?? process.cwd();
|
|
190
|
-
await fs.writeFile(path.join(dir, "package.json"), JSON.stringify(this._json, null, 2), { encoding: 'utf8' });
|
|
191
|
-
}
|
|
192
|
-
stringify() {
|
|
193
|
-
return JSON.stringify(this._json);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function assertHasCfg(json) {
|
|
197
|
-
if (!('neon' in json)) {
|
|
198
|
-
throw new TypeError('property "neon" not found');
|
|
199
|
-
}
|
|
200
|
-
assertIsObject(json.neon, "neon");
|
|
201
|
-
}
|
|
202
|
-
function assertHasBinaryCfg(json) {
|
|
203
|
-
assertHasCfg(json);
|
|
204
|
-
assertIsBinaryCfg(json.neon);
|
|
205
|
-
}
|
|
206
|
-
function assertHasLibraryCfg(json) {
|
|
207
|
-
assertHasCfg(json);
|
|
208
|
-
assertIsLibraryCfg(json.neon);
|
|
209
|
-
}
|
|
210
|
-
async function readManifest(dir) {
|
|
211
|
-
dir = dir ?? process.cwd();
|
|
212
|
-
return JSON.parse(await fs.readFile(path.join(dir, "package.json"), { encoding: 'utf8' }));
|
|
213
|
-
}
|
|
214
|
-
class BinaryManifest extends AbstractManifest {
|
|
215
|
-
constructor(json) {
|
|
216
|
-
super(json);
|
|
217
|
-
this._upgraded = normalizeBinaryCfg(this._json);
|
|
218
|
-
assertHasBinaryCfg(this._json);
|
|
219
|
-
this._binaryJSON = this._json;
|
|
220
|
-
}
|
|
221
|
-
cfg() {
|
|
222
|
-
return this._binaryJSON.neon;
|
|
223
|
-
}
|
|
224
|
-
static async load(dir) {
|
|
225
|
-
return new BinaryManifest(await readManifest(dir));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
exports.BinaryManifest = BinaryManifest;
|
|
229
|
-
function normalizeBinaryCfg(json) {
|
|
230
|
-
assertHasCfg(json);
|
|
231
|
-
// V3 format: {
|
|
232
|
-
// neon: {
|
|
233
|
-
// type: 'binary',
|
|
234
|
-
// rust: RustTarget,
|
|
235
|
-
// node: NodeTarget,
|
|
236
|
-
// os: string,
|
|
237
|
-
// arch: string,
|
|
238
|
-
// abi: string | null
|
|
239
|
-
// }
|
|
240
|
-
// }
|
|
241
|
-
if ('type' in json.neon && 'os' in json.neon) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
// V2 format: {
|
|
245
|
-
// neon: {
|
|
246
|
-
// type: 'binary',
|
|
247
|
-
// rust: RustTarget,
|
|
248
|
-
// node: NodeTarget,
|
|
249
|
-
// platform: string,
|
|
250
|
-
// arch: string,
|
|
251
|
-
// abi: string | null
|
|
252
|
-
// }
|
|
253
|
-
// }
|
|
254
|
-
if ('type' in json.neon) {
|
|
255
|
-
json.neon = upgradeBinaryV2(json.neon);
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
// V1 format: {
|
|
259
|
-
// neon: {
|
|
260
|
-
// binary: {
|
|
261
|
-
// rust: RustTarget,
|
|
262
|
-
// node: NodeTarget,
|
|
263
|
-
// platform: string,
|
|
264
|
-
// arch: string,
|
|
265
|
-
// abi: string | null
|
|
266
|
-
// }
|
|
267
|
-
// }
|
|
268
|
-
// }
|
|
269
|
-
json.neon = upgradeBinaryV1(json.neon);
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
function normalizeLibraryCfg(json) {
|
|
273
|
-
assertHasCfg(json);
|
|
274
|
-
// V5 format: {
|
|
275
|
-
// type: 'library',
|
|
276
|
-
// org: string,
|
|
277
|
-
// platforms: PlatformFamily,
|
|
278
|
-
// load?: string | undefined
|
|
279
|
-
// }
|
|
280
|
-
if ('type' in json.neon && json.neon.type === 'library') {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
// V4 format: {
|
|
284
|
-
// neon: {
|
|
285
|
-
// type: 'source',
|
|
286
|
-
// org: string,
|
|
287
|
-
// platforms: PlatformFamily,
|
|
288
|
-
// load?: string | undefined
|
|
289
|
-
// }
|
|
290
|
-
// }
|
|
291
|
-
if ('type' in json.neon && 'platforms' in json.neon) {
|
|
292
|
-
json.neon.type = 'library';
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
// V3 format: {
|
|
296
|
-
// neon: {
|
|
297
|
-
// type: 'source',
|
|
298
|
-
// org: string,
|
|
299
|
-
// targets: PlatformFamily
|
|
300
|
-
// }
|
|
301
|
-
// }
|
|
302
|
-
if ('type' in json.neon) {
|
|
303
|
-
const org = json.neon['org'];
|
|
304
|
-
const targets = json.neon['targets'];
|
|
305
|
-
assertIsPlatformFamily(targets, "neon.targets");
|
|
306
|
-
json.neon = {
|
|
307
|
-
type: 'library',
|
|
308
|
-
org,
|
|
309
|
-
platforms: targets
|
|
310
|
-
};
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
// V2 format: {
|
|
314
|
-
// neon: {
|
|
315
|
-
// org: string,
|
|
316
|
-
// targets: { Node => Rust }
|
|
317
|
-
// }
|
|
318
|
-
// }
|
|
319
|
-
if ('org' in json.neon) {
|
|
320
|
-
const platforms = json.neon['targets'];
|
|
321
|
-
assertIsPlatformMap(platforms, "neon.targets");
|
|
322
|
-
json.neon = {
|
|
323
|
-
type: 'library',
|
|
324
|
-
org: json.neon.org,
|
|
325
|
-
platforms
|
|
326
|
-
};
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
|
-
// V1 format: {
|
|
330
|
-
// neon: {
|
|
331
|
-
// targets: { Rust => fully-qualified package name }
|
|
332
|
-
// }
|
|
333
|
-
// }
|
|
334
|
-
const targets = json.neon['targets'];
|
|
335
|
-
assertIsLibraryV1(targets);
|
|
336
|
-
json.neon = upgradeLibraryV1(targets);
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
// The source manifest is the source of truth for all Neon
|
|
340
|
-
// project metadata. This means you never need to go searching
|
|
341
|
-
// for any other files to query the Neon project's metadata.
|
|
342
|
-
// (Some data is replicated in the binary manifests, however,
|
|
343
|
-
// since they are independently published in npm.)
|
|
344
|
-
class LibraryManifest extends AbstractManifest {
|
|
345
|
-
constructor(json) {
|
|
346
|
-
super(json);
|
|
347
|
-
this._upgraded = normalizeLibraryCfg(this._json);
|
|
348
|
-
assertHasLibraryCfg(this._json);
|
|
349
|
-
this._sourceJSON = this._json;
|
|
350
|
-
this._expandedPlatforms = (0, platform_cjs_1.expandPlatformFamily)(this._sourceJSON.neon.platforms);
|
|
351
|
-
}
|
|
352
|
-
static async load(dir) {
|
|
353
|
-
return new LibraryManifest(await readManifest(dir));
|
|
354
|
-
}
|
|
355
|
-
cfg() {
|
|
356
|
-
return this._sourceJSON.neon;
|
|
357
|
-
}
|
|
358
|
-
packageNames() {
|
|
359
|
-
const cfg = this.cfg();
|
|
360
|
-
return Object.keys(this._expandedPlatforms).map(key => `${cfg.org}/${key}`);
|
|
361
|
-
}
|
|
362
|
-
packageFor(target) {
|
|
363
|
-
const cfg = this.cfg();
|
|
364
|
-
for (const key in this._expandedPlatforms) {
|
|
365
|
-
const value = this._expandedPlatforms[key];
|
|
366
|
-
if (value === target) {
|
|
367
|
-
return `${cfg.org}/${key}`;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return undefined;
|
|
371
|
-
}
|
|
372
|
-
allPlatforms() {
|
|
373
|
-
return this._expandedPlatforms;
|
|
374
|
-
}
|
|
375
|
-
rustTargetFor(node) {
|
|
376
|
-
return this._expandedPlatforms[node];
|
|
377
|
-
}
|
|
378
|
-
manifestFor(target) {
|
|
379
|
-
const targetInfo = (0, platform_cjs_1.getTargetDescriptor)(target);
|
|
380
|
-
const name = this.packageFor(target);
|
|
381
|
-
if (!name) {
|
|
382
|
-
throw new Error(`Rust target ${target} not found in "neon.platforms" table.`);
|
|
383
|
-
}
|
|
384
|
-
const json = {
|
|
385
|
-
name,
|
|
386
|
-
description: `Prebuilt binary package for \`${this.name}\` on \`${targetInfo.node}\`.`,
|
|
387
|
-
version: this.version,
|
|
388
|
-
os: [targetInfo.os],
|
|
389
|
-
cpu: [targetInfo.arch],
|
|
390
|
-
main: "index.node",
|
|
391
|
-
files: ["index.node"],
|
|
392
|
-
neon: {
|
|
393
|
-
type: "binary",
|
|
394
|
-
rust: target,
|
|
395
|
-
node: targetInfo.node,
|
|
396
|
-
os: targetInfo.os,
|
|
397
|
-
arch: targetInfo.arch,
|
|
398
|
-
abi: targetInfo.abi
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
const OPTIONAL_KEYS = [
|
|
402
|
-
'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
|
|
403
|
-
];
|
|
404
|
-
for (const key of OPTIONAL_KEYS) {
|
|
405
|
-
if (key in this._json) {
|
|
406
|
-
json[key] = this._json[key];
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return new BinaryManifest(json);
|
|
410
|
-
}
|
|
411
|
-
async updateLoader(platforms) {
|
|
412
|
-
const cfg = this.cfg();
|
|
413
|
-
if (!cfg.load) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
const loader = await fs.readFile(cfg.load, 'utf8');
|
|
417
|
-
function isPlatformTable(p) {
|
|
418
|
-
return p.value.properties.every(p => {
|
|
419
|
-
return p.type === 'Property' &&
|
|
420
|
-
p.key.type === 'Literal' &&
|
|
421
|
-
(0, platform_cjs_1.isNodePlatform)(p.key.value);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
const result = (0, jscodeshift_1.default)(loader)
|
|
425
|
-
.find(jscodeshift_1.default.ObjectExpression)
|
|
426
|
-
.filter(isPlatformTable)
|
|
427
|
-
.replaceWith((p) => {
|
|
428
|
-
const newProps = platforms.map(platform => {
|
|
429
|
-
return jscodeshift_1.default.property('init', jscodeshift_1.default.literal(platform), jscodeshift_1.default.arrowFunctionExpression([], jscodeshift_1.default.callExpression(jscodeshift_1.default.identifier('require'), [jscodeshift_1.default.literal(`${cfg.org}/${platform}`)])));
|
|
430
|
-
});
|
|
431
|
-
return jscodeshift_1.default.objectExpression([...p.value.properties, ...newProps]);
|
|
432
|
-
})
|
|
433
|
-
.toSource({ quote: 'single' });
|
|
434
|
-
await fs.writeFile(cfg.load, result, 'utf8');
|
|
435
|
-
}
|
|
436
|
-
async addTargetPair(pair) {
|
|
437
|
-
const { node, rust } = pair;
|
|
438
|
-
if (this._expandedPlatforms[node] === rust) {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
this._expandedPlatforms[node] = rust;
|
|
442
|
-
await this.save();
|
|
443
|
-
await this.updateLoader([node]);
|
|
444
|
-
return pair;
|
|
445
|
-
}
|
|
446
|
-
async addNodePlatform(platform) {
|
|
447
|
-
const targets = (0, platform_cjs_1.node2Rust)(platform);
|
|
448
|
-
if (targets.length > 1) {
|
|
449
|
-
throw new Error(`multiple Rust targets found for Node platform ${platform}; please specify one of ${targets.join(', ')}`);
|
|
450
|
-
}
|
|
451
|
-
return await this.addTargetPair({ node: platform, rust: targets[0] });
|
|
452
|
-
}
|
|
453
|
-
async addRustTarget(target) {
|
|
454
|
-
return await this.addTargetPair({ node: (0, platform_cjs_1.rust2Node)(target), rust: target });
|
|
455
|
-
}
|
|
456
|
-
filterNewTargets(family) {
|
|
457
|
-
let newTargets = [];
|
|
458
|
-
for (const [key, value] of Object.entries(family)) {
|
|
459
|
-
const node = key;
|
|
460
|
-
const rust = value;
|
|
461
|
-
if (this._expandedPlatforms[node] === rust) {
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
newTargets.push({ node, rust });
|
|
465
|
-
}
|
|
466
|
-
return newTargets;
|
|
467
|
-
}
|
|
468
|
-
async addPlatforms(family, opts = {}) {
|
|
469
|
-
let newTargets = this.filterNewTargets(family);
|
|
470
|
-
if (!newTargets.length) {
|
|
471
|
-
return [];
|
|
472
|
-
}
|
|
473
|
-
for (const { node, rust } of newTargets) {
|
|
474
|
-
if (opts.platformsSrc) {
|
|
475
|
-
opts.platformsSrc[node] = rust;
|
|
476
|
-
}
|
|
477
|
-
this._expandedPlatforms[node] = rust;
|
|
478
|
-
}
|
|
479
|
-
await this.save();
|
|
480
|
-
await this.updateLoader(newTargets.map(({ node }) => node));
|
|
481
|
-
return newTargets;
|
|
482
|
-
}
|
|
483
|
-
async addPlatformPreset(preset) {
|
|
484
|
-
const platformsSrc = this.cfg().platforms;
|
|
485
|
-
if (typeof platformsSrc === 'string') {
|
|
486
|
-
this.cfg().platforms = [platformsSrc, preset];
|
|
487
|
-
return this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset));
|
|
488
|
-
}
|
|
489
|
-
if (Array.isArray(platformsSrc)) {
|
|
490
|
-
platformsSrc.push(preset);
|
|
491
|
-
return this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset));
|
|
492
|
-
}
|
|
493
|
-
// Edge case: an empty object can be treated like an empty array
|
|
494
|
-
if (Object.keys(platformsSrc).length === 0) {
|
|
495
|
-
this.cfg().platforms = [];
|
|
496
|
-
return await this.addPlatformPreset(preset);
|
|
497
|
-
}
|
|
498
|
-
return this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset), { platformsSrc });
|
|
499
|
-
}
|
|
500
|
-
async updateTargets(log, bundle) {
|
|
501
|
-
if (!this._json.optionalDependencies) {
|
|
502
|
-
this._json.optionalDependencies = {};
|
|
503
|
-
}
|
|
504
|
-
const packages = this.packageNames();
|
|
505
|
-
for (const pkg of packages) {
|
|
506
|
-
if (!(pkg in this._json.optionalDependencies)) {
|
|
507
|
-
this._json.optionalDependencies[pkg] = this.version;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
this.save();
|
|
511
|
-
log(`package.json after: ${await fs.readFile(path.join(process.cwd(), "package.json"))}`);
|
|
512
|
-
if (!bundle) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
const PREAMBLE = `// AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
|
|
516
|
-
//
|
|
517
|
-
// This code is never executed but is detected by the static analysis of
|
|
518
|
-
// bundlers such as \`@vercel/ncc\`. The require() expression that selects
|
|
519
|
-
// the right binary module for the current platform is too dynamic to be
|
|
520
|
-
// analyzable by bundler analyses, so this module provides an exhaustive
|
|
521
|
-
// static list for those analyses.
|
|
522
|
-
|
|
523
|
-
if (0) {
|
|
524
|
-
`;
|
|
525
|
-
const requires = packages.map(name => ` require('${name}');`).join('\n');
|
|
526
|
-
log(`generating bundler compatibility module at ${bundle}`);
|
|
527
|
-
await fs.writeFile(bundle, PREAMBLE + requires + '\n}\n');
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
exports.LibraryManifest = LibraryManifest;
|
|
531
|
-
function upgradeLibraryV1(object) {
|
|
532
|
-
function splitSwap([key, value]) {
|
|
533
|
-
if (!/^@.*\//.test(value)) {
|
|
534
|
-
throw new TypeError(`expected namespaced npm package name, found ${value}`);
|
|
535
|
-
}
|
|
536
|
-
const pkg = value.split('/')[1];
|
|
537
|
-
(0, platform_cjs_1.assertIsNodePlatform)(pkg);
|
|
538
|
-
(0, platform_cjs_1.assertIsRustTarget)(key);
|
|
539
|
-
return [pkg, key];
|
|
540
|
-
}
|
|
541
|
-
const entries = Object.entries(object).map(splitSwap);
|
|
542
|
-
const orgs = new Set(Object.values(object).map(v => v.split('/')[0]));
|
|
543
|
-
if (orgs.size === 0) {
|
|
544
|
-
throw new Error("empty target table");
|
|
545
|
-
}
|
|
546
|
-
else if (orgs.size > 1) {
|
|
547
|
-
throw new Error(`multiple npm orgs found: ${orgs}`);
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
type: 'library',
|
|
551
|
-
org: [...orgs][0],
|
|
552
|
-
platforms: Object.fromEntries(entries)
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
function upgradeBinaryV1(json) {
|
|
556
|
-
assertIsBinaryV1(json);
|
|
557
|
-
return {
|
|
558
|
-
type: 'binary',
|
|
559
|
-
rust: json.binary.rust,
|
|
560
|
-
node: json.binary.node,
|
|
561
|
-
os: json.binary.platform,
|
|
562
|
-
arch: json.binary.arch,
|
|
563
|
-
abi: json.binary.abi
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
function upgradeBinaryV2(json) {
|
|
567
|
-
assertIsBinaryV2(json);
|
|
568
|
-
return {
|
|
569
|
-
type: 'binary',
|
|
570
|
-
rust: json.rust,
|
|
571
|
-
node: json.node,
|
|
572
|
-
os: json.platform,
|
|
573
|
-
arch: json.arch,
|
|
574
|
-
abi: json.abi
|
|
575
|
-
};
|
|
576
|
-
}
|
|
3
|
+
exports.LibraryManifest = void 0;
|
|
4
|
+
var library_cjs_1 = require("./library/library.cjs");
|
|
5
|
+
Object.defineProperty(exports, "LibraryManifest", { enumerable: true, get: function () { return library_cjs_1.LibraryManifest; } });
|
package/lib/index.d.cts
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export interface BinaryCfg {
|
|
3
|
-
type: "binary";
|
|
4
|
-
rust: RustTarget;
|
|
5
|
-
node: NodePlatform;
|
|
6
|
-
os: string;
|
|
7
|
-
arch: string;
|
|
8
|
-
abi: string | null;
|
|
9
|
-
}
|
|
10
|
-
export interface LibraryCfg {
|
|
11
|
-
type: "library";
|
|
12
|
-
org: string;
|
|
13
|
-
platforms: PlatformFamily;
|
|
14
|
-
load?: string;
|
|
15
|
-
}
|
|
16
|
-
type Preamble = {
|
|
17
|
-
name: string;
|
|
18
|
-
version: string;
|
|
19
|
-
optionalDependencies?: Record<string, string> | undefined;
|
|
20
|
-
};
|
|
21
|
-
declare class AbstractManifest implements Preamble {
|
|
22
|
-
protected _json: Preamble;
|
|
23
|
-
protected _upgraded: boolean;
|
|
24
|
-
constructor(json: unknown);
|
|
25
|
-
get name(): string;
|
|
26
|
-
set name(value: string);
|
|
27
|
-
get version(): string;
|
|
28
|
-
set version(value: string);
|
|
29
|
-
get description(): string;
|
|
30
|
-
get upgraded(): boolean;
|
|
31
|
-
save(dir?: string | undefined): Promise<undefined>;
|
|
32
|
-
stringify(): string;
|
|
33
|
-
}
|
|
34
|
-
export declare class BinaryManifest extends AbstractManifest {
|
|
35
|
-
private _binaryJSON;
|
|
36
|
-
constructor(json: unknown);
|
|
37
|
-
cfg(): BinaryCfg;
|
|
38
|
-
static load(dir?: string | undefined): Promise<BinaryManifest>;
|
|
39
|
-
}
|
|
40
|
-
type AddPlatformsOptions = {
|
|
41
|
-
platformsSrc?: PlatformMap;
|
|
42
|
-
};
|
|
43
|
-
export declare class LibraryManifest extends AbstractManifest {
|
|
44
|
-
private _sourceJSON;
|
|
45
|
-
private _expandedPlatforms;
|
|
46
|
-
constructor(json: unknown);
|
|
47
|
-
static load(dir?: string | undefined): Promise<LibraryManifest>;
|
|
48
|
-
cfg(): LibraryCfg;
|
|
49
|
-
packageNames(): string[];
|
|
50
|
-
packageFor(target: RustTarget): string | undefined;
|
|
51
|
-
allPlatforms(): PlatformMap;
|
|
52
|
-
rustTargetFor(node: NodePlatform): RustTarget | undefined;
|
|
53
|
-
manifestFor(target: RustTarget): BinaryManifest;
|
|
54
|
-
updateLoader(platforms: NodePlatform[]): Promise<void>;
|
|
55
|
-
addTargetPair(pair: TargetPair): Promise<TargetPair | null>;
|
|
56
|
-
addNodePlatform(platform: NodePlatform): Promise<TargetPair | null>;
|
|
57
|
-
addRustTarget(target: RustTarget): Promise<TargetPair | null>;
|
|
58
|
-
filterNewTargets(family: PlatformMap): TargetPair[];
|
|
59
|
-
addPlatforms(family: PlatformMap, opts?: AddPlatformsOptions): Promise<TargetPair[]>;
|
|
60
|
-
addPlatformPreset(preset: PlatformPreset): Promise<TargetPair[]>;
|
|
61
|
-
updateTargets(log: (msg: string) => void, bundle: string | null): Promise<void>;
|
|
62
|
-
}
|
|
63
|
-
export type Manifest = LibraryManifest | BinaryManifest;
|
|
64
|
-
export {};
|
|
1
|
+
export { LibraryCfg, LibraryManifest } from './library/library.cjs';
|
package/lib/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { LibraryCfg, LibraryManifest } from './index.cjs';
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { LibraryManifest } from './index.cjs';
|