@octanejs/codemod 0.1.0 → 0.1.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/package.json +3 -3
- package/src/project.js +32 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/codemod",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.22.2"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"./package.json": "./package.json"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@octanejs/cli": "0.3.
|
|
43
|
-
"octane": "0.16.
|
|
42
|
+
"@octanejs/cli": "0.3.2",
|
|
43
|
+
"octane": "0.16.6",
|
|
44
44
|
"picocolors": "^1.1.1",
|
|
45
45
|
"typescript": "^5.9.3"
|
|
46
46
|
},
|
package/src/project.js
CHANGED
|
@@ -415,26 +415,50 @@ function resolveBinding(specifier, packages, notes) {
|
|
|
415
415
|
if (name === null) return null;
|
|
416
416
|
const binding = CATALOG[name];
|
|
417
417
|
packages.set(name, binding);
|
|
418
|
+
const entry = DATA.bindings.find((candidate) => candidate.name === binding);
|
|
418
419
|
// An aggregate binding (`@octanejs/visx`, for `@visx/visx`) serves each
|
|
419
420
|
// package of its scope from a subpath: `@visx/hierarchy` is
|
|
420
421
|
// `@octanejs/visx/hierarchy`.
|
|
421
|
-
const upstream =
|
|
422
|
+
const upstream = entry?.upstream?.package;
|
|
422
423
|
const aggregate = upstream?.match(/^@([^/]+)\/\1$/);
|
|
423
424
|
if (aggregate && name !== upstream && name.startsWith(`@${aggregate[1]}/`)) {
|
|
424
425
|
return `${binding}/${name.slice(aggregate[1].length + 2)}${specifier.slice(name.length)}`;
|
|
425
426
|
}
|
|
426
427
|
const subpath = specifier.slice(name.length);
|
|
427
|
-
if (subpath
|
|
428
|
-
|
|
429
|
-
rule: 'bindings',
|
|
430
|
-
severity: 'warning',
|
|
431
|
-
line: 1,
|
|
432
|
-
message: `Check that \`${binding}${subpath}\` exists; the binding may export it from its root.`,
|
|
433
|
-
});
|
|
428
|
+
if (subpath === '' || entry?.exports.some((key) => serves(key, `.${subpath}`))) {
|
|
429
|
+
return binding + subpath;
|
|
434
430
|
}
|
|
431
|
+
// A binding outside the catalog has exports the codemod cannot see.
|
|
432
|
+
notes.push(
|
|
433
|
+
entry
|
|
434
|
+
? {
|
|
435
|
+
rule: 'bindings',
|
|
436
|
+
severity: 'error',
|
|
437
|
+
line: 1,
|
|
438
|
+
message: `\`${binding}\` has no \`.${subpath}\` export. Import these names from its root if it exports them there.`,
|
|
439
|
+
}
|
|
440
|
+
: {
|
|
441
|
+
rule: 'bindings',
|
|
442
|
+
severity: 'warning',
|
|
443
|
+
line: 1,
|
|
444
|
+
message: `Check that \`${binding}${subpath}\` exists; the binding may export it from its root.`,
|
|
445
|
+
},
|
|
446
|
+
);
|
|
435
447
|
return binding + subpath;
|
|
436
448
|
}
|
|
437
449
|
|
|
450
|
+
/**
|
|
451
|
+
* Whether a package `exports` key serves a subpath, directly or through a
|
|
452
|
+
* `*` pattern such as `./locale/*`.
|
|
453
|
+
*
|
|
454
|
+
* @param {string} key
|
|
455
|
+
* @param {string} subpath
|
|
456
|
+
*/
|
|
457
|
+
function serves(key, subpath) {
|
|
458
|
+
const [head, tail] = key.split('*');
|
|
459
|
+
return tail === undefined ? key === subpath : subpath.startsWith(head) && subpath.endsWith(tail);
|
|
460
|
+
}
|
|
461
|
+
|
|
438
462
|
/**
|
|
439
463
|
* The catalog entry for a package specifier, or null. The catalog keys some
|
|
440
464
|
* bindings by subpath (`better-auth/react`), so the longest matching prefix
|