@astryxdesign/cli 0.7.2-canary.52c26fb → 0.7.2-canary.58279bc
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.
|
@@ -24,7 +24,6 @@ import * as path from 'node:path';
|
|
|
24
24
|
import * as os from 'node:os';
|
|
25
25
|
import {fileURLToPath} from 'node:url';
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
|
-
import jscodeshift from 'jscodeshift';
|
|
28
27
|
import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
29
28
|
import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
|
|
30
29
|
import {
|
|
@@ -41,6 +40,7 @@ import {
|
|
|
41
40
|
} from '../../foundation/discovery/docs-discovery.mjs';
|
|
42
41
|
import {discoverIntegrationThemes} from '../../foundation/discovery/theme-discovery.mjs';
|
|
43
42
|
import {inspectPackageExport} from '../../foundation/discovery/package-exports.mjs';
|
|
43
|
+
import {moduleExportsName} from '../../foundation/discovery/module-exports.mjs';
|
|
44
44
|
import {
|
|
45
45
|
ThemeImportError,
|
|
46
46
|
resolveThemeImports,
|
|
@@ -307,98 +307,6 @@ function extractTarball(tgzPath, extractDir) {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
const MODULE_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.tsx', '.jsx'];
|
|
311
|
-
const moduleParser = jscodeshift.withParser('tsx');
|
|
312
|
-
|
|
313
|
-
/** @param {unknown} specifier @param {string} fromFile */
|
|
314
|
-
function resolveLocalModule(specifier, fromFile) {
|
|
315
|
-
if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
|
|
316
|
-
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
317
|
-
const candidates = [
|
|
318
|
-
base,
|
|
319
|
-
...MODULE_EXTENSIONS.map(extension => `${base}${extension}`),
|
|
320
|
-
...MODULE_EXTENSIONS.map(extension => path.join(base, `index${extension}`)),
|
|
321
|
-
];
|
|
322
|
-
return candidates.find(candidate => fs.existsSync(candidate)) ?? null;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/** @param {any} declaration @param {string} exportName */
|
|
326
|
-
function declarationExports(declaration, exportName) {
|
|
327
|
-
if (!declaration) return false;
|
|
328
|
-
if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
|
|
329
|
-
return declaration.id?.name === exportName;
|
|
330
|
-
}
|
|
331
|
-
if (declaration.type !== 'VariableDeclaration') return false;
|
|
332
|
-
return declaration.declarations.some(
|
|
333
|
-
(/** @type {any} */ item) =>
|
|
334
|
-
item.id?.type === 'Identifier' && item.id.name === exportName,
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Check one resolved module's static export surface without executing package
|
|
340
|
-
* code. Local ESM re-exports are followed recursively.
|
|
341
|
-
*
|
|
342
|
-
* @param {string} file
|
|
343
|
-
* @param {string} exportName
|
|
344
|
-
* @param {Set<string>} [seen]
|
|
345
|
-
*/
|
|
346
|
-
function moduleExportsName(file, exportName, seen = new Set()) {
|
|
347
|
-
const identity = `${file}\0${exportName}`;
|
|
348
|
-
if (seen.has(identity) || !fs.existsSync(file)) return false;
|
|
349
|
-
seen.add(identity);
|
|
350
|
-
|
|
351
|
-
let root;
|
|
352
|
-
try {
|
|
353
|
-
root = moduleParser(fs.readFileSync(file, 'utf-8'));
|
|
354
|
-
} catch {
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
let found = false;
|
|
359
|
-
root
|
|
360
|
-
.find(moduleParser.ExportNamedDeclaration)
|
|
361
|
-
.forEach((/** @type {any} */ exportPath) => {
|
|
362
|
-
if (found) return;
|
|
363
|
-
const node = exportPath.node;
|
|
364
|
-
if (declarationExports(node.declaration, exportName)) {
|
|
365
|
-
found = true;
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
for (const specifier of node.specifiers ?? []) {
|
|
369
|
-
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
370
|
-
if (exported !== exportName) continue;
|
|
371
|
-
if (!node.source) {
|
|
372
|
-
found = true;
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const target = resolveLocalModule(node.source.value, file);
|
|
376
|
-
const imported =
|
|
377
|
-
specifier.local?.name ?? specifier.local?.value ?? exportName;
|
|
378
|
-
if (target && moduleExportsName(target, imported, seen)) {
|
|
379
|
-
found = true;
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
if (found) return true;
|
|
385
|
-
if (
|
|
386
|
-
exportName === 'default' &&
|
|
387
|
-
root.find(moduleParser.ExportDefaultDeclaration).size() > 0
|
|
388
|
-
) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
root
|
|
393
|
-
.find(moduleParser.ExportAllDeclaration)
|
|
394
|
-
.forEach((/** @type {any} */ exportPath) => {
|
|
395
|
-
if (found) return;
|
|
396
|
-
const target = resolveLocalModule(exportPath.node.source?.value, file);
|
|
397
|
-
if (target && moduleExportsName(target, exportName, seen)) found = true;
|
|
398
|
-
});
|
|
399
|
-
return found;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
310
|
/**
|
|
403
311
|
* Whether any of these doc files has a section that sets `id`.
|
|
404
312
|
* @param {string[]} files
|
|
@@ -811,6 +811,86 @@ describe('integrationPackCheck', () => {
|
|
|
811
811
|
);
|
|
812
812
|
});
|
|
813
813
|
|
|
814
|
+
it('does not count a type-only re-export as the component', async () => {
|
|
815
|
+
fs.writeFileSync(
|
|
816
|
+
path.join(tmpDir, 'package.json'),
|
|
817
|
+
`${JSON.stringify({
|
|
818
|
+
name: '@acme/widgets',
|
|
819
|
+
version: '1.0.0',
|
|
820
|
+
files: ['astryx.integration.mjs', 'src'],
|
|
821
|
+
exports: {'.': './src/index.ts'},
|
|
822
|
+
})}\n`,
|
|
823
|
+
);
|
|
824
|
+
fs.writeFileSync(
|
|
825
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
826
|
+
"export default {components: './src'};\n",
|
|
827
|
+
);
|
|
828
|
+
fs.mkdirSync(path.join(tmpDir, 'src'));
|
|
829
|
+
fs.writeFileSync(
|
|
830
|
+
path.join(tmpDir, 'src', 'index.ts'),
|
|
831
|
+
"export type {AcmeWidget} from './AcmeWidget';\n",
|
|
832
|
+
);
|
|
833
|
+
fs.writeFileSync(
|
|
834
|
+
path.join(tmpDir, 'src', 'AcmeWidget.tsx'),
|
|
835
|
+
'export function AcmeWidget() { return null; }\n',
|
|
836
|
+
);
|
|
837
|
+
fs.writeFileSync(
|
|
838
|
+
path.join(tmpDir, 'src', 'AcmeWidget.doc.mjs'),
|
|
839
|
+
"export default {type: 'component', name: 'AcmeWidget', import: '@acme/widgets', description: 'Widget.', props: []};\n",
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
843
|
+
|
|
844
|
+
expect(result.data.issues).toContainEqual(
|
|
845
|
+
expect.objectContaining({code: 'component_export_missing'}),
|
|
846
|
+
);
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
it('follows a re-export of a folder to its index file', async () => {
|
|
850
|
+
// `./primitives` names a folder: TypeScript and bundlers load its index file.
|
|
851
|
+
fs.writeFileSync(
|
|
852
|
+
path.join(tmpDir, 'package.json'),
|
|
853
|
+
`${JSON.stringify({
|
|
854
|
+
name: '@acme/widgets',
|
|
855
|
+
version: '1.0.0',
|
|
856
|
+
files: ['astryx.integration.mjs', 'src'],
|
|
857
|
+
exports: {'.': './src/index.ts'},
|
|
858
|
+
})}\n`,
|
|
859
|
+
);
|
|
860
|
+
fs.writeFileSync(
|
|
861
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
862
|
+
"export default {components: './src'};\n",
|
|
863
|
+
);
|
|
864
|
+
const primitives = path.join(tmpDir, 'src', 'primitives');
|
|
865
|
+
fs.mkdirSync(primitives, {recursive: true});
|
|
866
|
+
fs.writeFileSync(
|
|
867
|
+
path.join(tmpDir, 'src', 'index.ts'),
|
|
868
|
+
"export * from './primitives';\n",
|
|
869
|
+
);
|
|
870
|
+
fs.writeFileSync(
|
|
871
|
+
path.join(primitives, 'index.ts'),
|
|
872
|
+
"export * from './AcmeWidget';\n",
|
|
873
|
+
);
|
|
874
|
+
fs.writeFileSync(
|
|
875
|
+
path.join(primitives, 'AcmeWidget.tsx'),
|
|
876
|
+
'export function AcmeWidget() { return null; }\n',
|
|
877
|
+
);
|
|
878
|
+
fs.writeFileSync(
|
|
879
|
+
path.join(primitives, 'AcmeWidget.doc.mjs'),
|
|
880
|
+
"export default {type: 'component', name: 'AcmeWidget', import: '@acme/widgets', description: 'Widget.', props: []};\n",
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
884
|
+
|
|
885
|
+
expect(result.data.issues).not.toContainEqual(
|
|
886
|
+
expect.objectContaining({code: 'component_export_missing'}),
|
|
887
|
+
);
|
|
888
|
+
expect(
|
|
889
|
+
result.data.packable,
|
|
890
|
+
JSON.stringify(result.data.issues, null, 2),
|
|
891
|
+
).toBe(true);
|
|
892
|
+
});
|
|
893
|
+
|
|
814
894
|
it('fails when packed template source is hidden by package exports', async () => {
|
|
815
895
|
writePackage({
|
|
816
896
|
manifest: "export default {templates: './templates'};\n",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.2-canary.
|
|
3
|
+
"version": "0.7.2-canary.58279bc",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.7.2-canary.
|
|
105
|
-
"@astryxdesign/core": "0.7.2-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.7.2-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.7.2-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.7.2-canary.58279bc",
|
|
105
|
+
"@astryxdesign/core": "0.7.2-canary.58279bc",
|
|
106
|
+
"@astryxdesign/lab": "0.7.2-canary.58279bc",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.2-canary.58279bc"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.7.2-canary.
|
|
125
|
-
"@astryxdesign/core": "0.7.2-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.7.2-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.7.2-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.7.2-canary.58279bc",
|
|
125
|
+
"@astryxdesign/core": "0.7.2-canary.58279bc",
|
|
126
|
+
"@astryxdesign/lab": "0.7.2-canary.58279bc",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.2-canary.58279bc",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|