@plumeria/codemod 18.5.3 → 19.0.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/README.md +14 -0
- package/dist/release.js +70 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -247,6 +247,9 @@ src/Card.tsx
|
|
|
247
247
|
The value of `color` cannot be represented statically.
|
|
248
248
|
12:3 spread-create
|
|
249
249
|
Top-level spreads cannot name a CSS Module class.
|
|
250
|
+
19:16 style-type-reference
|
|
251
|
+
`css.StaticStyles` has no CSS Modules equivalent, and the import that
|
|
252
|
+
declares it does not survive the export of Card.tsx.
|
|
250
253
|
```
|
|
251
254
|
|
|
252
255
|
Constructs that cannot be resolved statically — dynamic values, computed keys,
|
|
@@ -255,6 +258,17 @@ together with every file whose definitions they still need. A target
|
|
|
255
258
|
`*.module.css` that already exists is reported as `target-exists` and will not be
|
|
256
259
|
overwritten.
|
|
257
260
|
|
|
261
|
+
The export removes the `@plumeria/core` import, so a reference to `Style`,
|
|
262
|
+
`StyleProps`, `WithoutProperties`, `StaticStyles` or `AtomicClassNameFor` is left
|
|
263
|
+
without the import that declares it. Those are reported as
|
|
264
|
+
`style-type-reference`, whether the type names a component prop, a type alias or
|
|
265
|
+
a variable annotation.
|
|
266
|
+
|
|
267
|
+
A module that declares nothing but style prop types is the one shape this does
|
|
268
|
+
not reach: it defines no styles, so there is no stylesheet for the report to hold
|
|
269
|
+
onto, and its consumer will not compile after the export. Keep the prop type in
|
|
270
|
+
the file that defines the styles and the export reports it instead.
|
|
271
|
+
|
|
258
272
|
Several `css.create` calls in one file are not reported: they are written to the
|
|
259
273
|
same stylesheet, and a key an earlier call claimed is renamed.
|
|
260
274
|
|
package/dist/release.js
CHANGED
|
@@ -78,6 +78,13 @@ const findSources = (targets) => {
|
|
|
78
78
|
return found.sort();
|
|
79
79
|
};
|
|
80
80
|
const STYLE_PROP = 'classStyle';
|
|
81
|
+
const STYLE_TYPES = new Set([
|
|
82
|
+
'Style',
|
|
83
|
+
'StyleProps',
|
|
84
|
+
'WithoutProperties',
|
|
85
|
+
'StaticStyles',
|
|
86
|
+
'AtomicClassNameFor',
|
|
87
|
+
]);
|
|
81
88
|
const memberOf = (node) => {
|
|
82
89
|
if (node?.type !== 'MemberExpression' || node.object.type !== 'Identifier')
|
|
83
90
|
return undefined;
|
|
@@ -438,6 +445,69 @@ function planRelease(targets) {
|
|
|
438
445
|
},
|
|
439
446
|
]);
|
|
440
447
|
});
|
|
448
|
+
const styleTypeNamespaces = new Set();
|
|
449
|
+
const styleTypeLocals = new Set();
|
|
450
|
+
for (const node of ast.body) {
|
|
451
|
+
if (node.type !== 'ImportDeclaration' ||
|
|
452
|
+
node.source.value !== '@plumeria/core')
|
|
453
|
+
continue;
|
|
454
|
+
for (const specifier of node.specifiers) {
|
|
455
|
+
if (specifier.type === 'ImportNamespaceSpecifier' ||
|
|
456
|
+
specifier.type === 'ImportDefaultSpecifier') {
|
|
457
|
+
styleTypeNamespaces.add(specifier.local.name);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (specifier.type !== 'ImportSpecifier')
|
|
461
|
+
continue;
|
|
462
|
+
const imported = specifier.imported.name ?? specifier.imported.value;
|
|
463
|
+
if (STYLE_TYPES.has(imported))
|
|
464
|
+
styleTypeLocals.add(specifier.local.name);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const styleTypeUses = [];
|
|
468
|
+
walk(ast.body, (node) => {
|
|
469
|
+
if (node.type !== 'TSTypeReference')
|
|
470
|
+
return;
|
|
471
|
+
const name = node.typeName;
|
|
472
|
+
if (name?.type === 'TSQualifiedName' &&
|
|
473
|
+
name.left?.type === 'Identifier' &&
|
|
474
|
+
styleTypeNamespaces.has(name.left.name) &&
|
|
475
|
+
name.right?.type === 'Identifier' &&
|
|
476
|
+
STYLE_TYPES.has(name.right.name)) {
|
|
477
|
+
styleTypeUses.push({
|
|
478
|
+
line: node.loc.start.line,
|
|
479
|
+
column: node.loc.start.column + 1,
|
|
480
|
+
name: `${name.left.name}.${name.right.name}`,
|
|
481
|
+
});
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (name?.type === 'Identifier' && styleTypeLocals.has(name.name))
|
|
485
|
+
styleTypeUses.push({
|
|
486
|
+
line: node.loc.start.line,
|
|
487
|
+
column: node.loc.start.column + 1,
|
|
488
|
+
name: name.name,
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
if (styleTypeUses.length > 0) {
|
|
492
|
+
const held = new Set();
|
|
493
|
+
walk(ast.body, (node) => {
|
|
494
|
+
if (node.type !== 'Identifier')
|
|
495
|
+
return;
|
|
496
|
+
const owner = owners.get(node.name);
|
|
497
|
+
if (owner)
|
|
498
|
+
held.add(owner.source);
|
|
499
|
+
});
|
|
500
|
+
for (const use of styleTypeUses)
|
|
501
|
+
for (const target of held)
|
|
502
|
+
note(target, [
|
|
503
|
+
{
|
|
504
|
+
line: use.line,
|
|
505
|
+
column: use.column,
|
|
506
|
+
kind: 'style-type-reference',
|
|
507
|
+
hint: `\`${use.name}\` has no CSS Modules equivalent, and the import that declares it does not survive the export of ${path.basename(source)}.`,
|
|
508
|
+
},
|
|
509
|
+
]);
|
|
510
|
+
}
|
|
441
511
|
walk(ast.body, (node) => {
|
|
442
512
|
if (node.type !== 'JSXAttribute' ||
|
|
443
513
|
node.name?.name !== STYLE_PROP ||
|
package/package.json
CHANGED