@gjsify/resolve-npm 0.44.0 → 0.45.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.
- package/lib/globals-map.mjs +255 -153
- package/lib/index.d.ts +47 -23
- package/lib/index.mjs +194 -203
- package/lib/runtime-aliases.mjs +49 -24
- package/package.json +1 -1
package/lib/runtime-aliases.mjs
CHANGED
|
@@ -64,8 +64,45 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
|
64
64
|
import { join, dirname, resolve } from 'node:path';
|
|
65
65
|
import { fileURLToPath } from 'node:url';
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The slot values a declaration may use, and the runtimes it may name.
|
|
69
|
+
*
|
|
70
|
+
* EXPORTED because they are the CANONICAL lists and every hand-retyped copy of the TARGETS
|
|
71
|
+
* has drifted: `lib/index.d.ts` denied `nativescript` for the whole life of the 4th slot,
|
|
72
|
+
* and `scripts/audit-runtimes.mjs` — the gate that would have caught that — carried two
|
|
73
|
+
* more copies of its own (`REACH_TARGETS`, `diffDeclared`'s `slots`). The SLOT VALUES had
|
|
74
|
+
* the opposite problem: nothing outside this file listed them, so nothing outside this file
|
|
75
|
+
* rejected `"Polyfill"` either. Import these; do not retype them. What cannot import them
|
|
76
|
+
* (the `.d.ts` unions, which are types) is held against them by
|
|
77
|
+
* `tests/e2e/runtime-slot-declarations`.
|
|
78
|
+
*/
|
|
67
79
|
const VALID_SLOTS = new Set(['polyfill', 'native', 'partial', 'none']);
|
|
68
|
-
|
|
80
|
+
// `react-native` is the 5th target and the only one with no `--app` of its own. Not the
|
|
81
|
+
// second: gjsify DOES bundle NativeScript (`--app nativescript`, `app/nativescript.ts`)
|
|
82
|
+
// even though `@nativescript/vite` owns the APPLICATION build there. Metro owns a React
|
|
83
|
+
// Native application's build the same way, and gjsify has no target under it at all, so
|
|
84
|
+
// this slot feeds the ALIAS layer only and `build.ts`'s `choices` stays at four.
|
|
85
|
+
// `gjsify build --dialect react-native` is a DIFFERENT axis: it says what the SOURCE is
|
|
86
|
+
// written in, not what the PACKAGE runs on, so it is not this slot's sibling and the two
|
|
87
|
+
// are never equal.
|
|
88
|
+
const VALID_TARGETS = new Set(['gjs', 'node', 'browser', 'nativescript', 'react-native']);
|
|
89
|
+
|
|
90
|
+
export { VALID_SLOTS, VALID_TARGETS };
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A runtime a package can declare a slot for. The union for JS callers, referenced from
|
|
94
|
+
* `index.mjs` and from this file's own `@param`s via
|
|
95
|
+
* `import('./runtime-aliases.mjs').Target`. It absorbs four of the six hand-written copies
|
|
96
|
+
* this package carried; the other two, in `index.d.ts`, became a second union
|
|
97
|
+
* (`RuntimeTarget`) on purpose. A `.d.ts` pointing at
|
|
98
|
+
* `import('./runtime-aliases.mjs').Target` hands every consumer without `allowJs` a TS7016
|
|
99
|
+
* against our own shipped `lib/` — measured — so one union there costs a compiler flag in
|
|
100
|
+
* somebody else's tsconfig. `tests/e2e/runtime-slot-declarations` holds `RuntimeTarget`
|
|
101
|
+
* against `VALID_TARGETS` instead. Six copies are how `index.mjs` still named four targets
|
|
102
|
+
* one commit after `VALID_TARGETS` gained the fifth.
|
|
103
|
+
*
|
|
104
|
+
* @typedef {'gjs'|'node'|'browser'|'nativescript'|'react-native'} Target
|
|
105
|
+
*/
|
|
69
106
|
|
|
70
107
|
/**
|
|
71
108
|
* Collect the target names for which `exports` declares a `./<target>`
|
|
@@ -91,12 +128,13 @@ function collectPlatformEntries(exportsField) {
|
|
|
91
128
|
|
|
92
129
|
/** @typedef {'polyfill'|'native'|'partial'|'none'} Slot */
|
|
93
130
|
/**
|
|
94
|
-
* Per-package runtime slot declaration.
|
|
95
|
-
* nativescript). The legacy "triplet" name is kept on the typedef
|
|
96
|
-
* minimal churn
|
|
97
|
-
*
|
|
131
|
+
* Per-package runtime slot declaration. Quintuplet (gjs / node / browser /
|
|
132
|
+
* nativescript / react-native). The legacy "triplet" name is kept on the typedef
|
|
133
|
+
* for minimal churn; the type is canonically a quintuplet from VALID_TARGETS'
|
|
134
|
+
* perspective.
|
|
98
135
|
*
|
|
99
|
-
* @typedef {{gjs?:Slot, node?:Slot, browser?:Slot, nativescript?:Slot
|
|
136
|
+
* @typedef {{gjs?:Slot, node?:Slot, browser?:Slot, nativescript?:Slot,
|
|
137
|
+
* 'react-native'?:Slot}} RuntimeTriplet
|
|
100
138
|
*/
|
|
101
139
|
/**
|
|
102
140
|
* @typedef {{name:string, dir:string, runtimes:RuntimeTriplet, hasGlobals:boolean,
|
|
@@ -182,13 +220,7 @@ async function ingestPackageDir(dir, out) {
|
|
|
182
220
|
const json = JSON.parse(raw);
|
|
183
221
|
const name = typeof json.name === 'string' ? json.name : null;
|
|
184
222
|
const runtimes = json?.gjsify?.runtimes;
|
|
185
|
-
if (
|
|
186
|
-
name &&
|
|
187
|
-
name.startsWith('@gjsify/') &&
|
|
188
|
-
!out.has(name) &&
|
|
189
|
-
runtimes &&
|
|
190
|
-
typeof runtimes === 'object'
|
|
191
|
-
) {
|
|
223
|
+
if (name && name.startsWith('@gjsify/') && !out.has(name) && runtimes && typeof runtimes === 'object') {
|
|
192
224
|
/** @type {RuntimeTriplet} */
|
|
193
225
|
const triplet = {};
|
|
194
226
|
for (const t of VALID_TARGETS) {
|
|
@@ -218,13 +250,7 @@ function ingestPackageDirSync(dir, out) {
|
|
|
218
250
|
const json = JSON.parse(raw);
|
|
219
251
|
const name = typeof json.name === 'string' ? json.name : null;
|
|
220
252
|
const runtimes = json?.gjsify?.runtimes;
|
|
221
|
-
if (
|
|
222
|
-
name &&
|
|
223
|
-
name.startsWith('@gjsify/') &&
|
|
224
|
-
!out.has(name) &&
|
|
225
|
-
runtimes &&
|
|
226
|
-
typeof runtimes === 'object'
|
|
227
|
-
) {
|
|
253
|
+
if (name && name.startsWith('@gjsify/') && !out.has(name) && runtimes && typeof runtimes === 'object') {
|
|
228
254
|
/** @type {RuntimeTriplet} */
|
|
229
255
|
const triplet = {};
|
|
230
256
|
for (const t of VALID_TARGETS) {
|
|
@@ -367,7 +393,6 @@ function getCacheSync() {
|
|
|
367
393
|
function warnOnce(key, message) {
|
|
368
394
|
if (_warned.has(key)) return;
|
|
369
395
|
_warned.add(key);
|
|
370
|
-
// eslint-disable-next-line no-console
|
|
371
396
|
console.warn(`[@gjsify/resolve-npm] ${message}`);
|
|
372
397
|
}
|
|
373
398
|
|
|
@@ -375,7 +400,7 @@ function warnOnce(key, message) {
|
|
|
375
400
|
* Given a package record + target runtime, resolve the alias target.
|
|
376
401
|
*
|
|
377
402
|
* @param {PackageRecord} rec
|
|
378
|
-
* @param {
|
|
403
|
+
* @param {Target} target
|
|
379
404
|
* @returns {string|null} The alias target specifier, or null if no rewrite applies.
|
|
380
405
|
*/
|
|
381
406
|
function resolveSlot(rec, target) {
|
|
@@ -447,7 +472,7 @@ function resolveSlot(rec, target) {
|
|
|
447
472
|
* (callers should `{ ...derived, ...hardcoded }` to preserve current behavior
|
|
448
473
|
* for packages opted out of the triplet model).
|
|
449
474
|
*
|
|
450
|
-
* @param {
|
|
475
|
+
* @param {Target} target
|
|
451
476
|
* @returns {Record<string,string>}
|
|
452
477
|
*/
|
|
453
478
|
export function getDerivedAliasesSync(target) {
|
|
@@ -468,7 +493,7 @@ export function getDerivedAliasesSync(target) {
|
|
|
468
493
|
* Async variant of {@link getDerivedAliasesSync} — preferred when callable from
|
|
469
494
|
* an async config hook.
|
|
470
495
|
*
|
|
471
|
-
* @param {
|
|
496
|
+
* @param {Target} target
|
|
472
497
|
* @returns {Promise<Record<string,string>>}
|
|
473
498
|
*/
|
|
474
499
|
export async function getDerivedAliases(target) {
|