@astryxdesign/cli 0.7.4 → 0.7.5-canary.0b78509
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/assets/discover/official-packages.json +4 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/package.json +9 -9
|
@@ -127,7 +127,8 @@ export function docStem(docPath: string): string;
|
|
|
127
127
|
/**
|
|
128
128
|
* The local module a doc's import names: the doc's own `import`, else the
|
|
129
129
|
* subpath its directory publishes, read through the package's `exports` (its
|
|
130
|
-
* `main` when it has none).
|
|
130
|
+
* `main` when it has none). A subpath's `source` condition wins when its file
|
|
131
|
+
* is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
|
|
131
132
|
* null when the import names another package or resolves to no file.
|
|
132
133
|
*
|
|
133
134
|
* @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
|
|
@@ -705,6 +705,47 @@ describe('integration components a family doc lists in components', () => {
|
|
|
705
705
|
expect(namesIn(loaded)).toEqual(['AcmeList']);
|
|
706
706
|
});
|
|
707
707
|
|
|
708
|
+
it('reads members through the source condition, the same with or without built output', () => {
|
|
709
|
+
// The family's member is exported only from the root entry, as Lab's
|
|
710
|
+
// TourStep is.
|
|
711
|
+
const loaded = writePackage(
|
|
712
|
+
{
|
|
713
|
+
exports: {
|
|
714
|
+
'.': {
|
|
715
|
+
source: './src/index.ts',
|
|
716
|
+
types: './dist/index.d.ts',
|
|
717
|
+
default: './dist/index.js',
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
'src/index.ts':
|
|
723
|
+
"export {AcmeList} from './list/AcmeList';\nexport {AcmeListRow} from './list/row';\n",
|
|
724
|
+
'src/list/AcmeList.doc.mjs': family(
|
|
725
|
+
'AcmeList',
|
|
726
|
+
"{name: 'AcmeList', description: 'x'}, {name: 'AcmeListRow', description: 'x'}",
|
|
727
|
+
),
|
|
728
|
+
'src/list/AcmeList.tsx':
|
|
729
|
+
'export function AcmeList() { return null; }\n',
|
|
730
|
+
'src/list/row.tsx': 'export function AcmeListRow() { return null; }\n',
|
|
731
|
+
},
|
|
732
|
+
);
|
|
733
|
+
expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
|
|
734
|
+
expect(findIntegrationComponentSource(loaded, 'AcmeListRow')).toBe(
|
|
735
|
+
path.join(root, 'src', 'list', 'row.tsx'),
|
|
736
|
+
);
|
|
737
|
+
// Built output, even a stale one without the member, changes nothing.
|
|
738
|
+
fs.mkdirSync(path.join(root, 'dist'), {recursive: true});
|
|
739
|
+
fs.writeFileSync(
|
|
740
|
+
path.join(root, 'dist', 'index.js'),
|
|
741
|
+
'export function AcmeList() { return null; }\n',
|
|
742
|
+
);
|
|
743
|
+
expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
|
|
744
|
+
// A package that does not ship its source reads the built output.
|
|
745
|
+
fs.rmSync(path.join(root, 'src', 'index.ts'));
|
|
746
|
+
expect(namesIn(loaded)).toEqual(['AcmeList']);
|
|
747
|
+
});
|
|
748
|
+
|
|
708
749
|
it('lists a member another folder declares, with no source', async () => {
|
|
709
750
|
const loaded = writePackage(
|
|
710
751
|
{exports: {'./menu': './src/menu/index.ts'}},
|
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
moduleExportsName,
|
|
19
19
|
staticExportObject,
|
|
20
20
|
} from './module-exports.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
inspectPackageExport,
|
|
23
|
+
sourceExportTarget,
|
|
24
|
+
} from './package-exports.mjs';
|
|
22
25
|
|
|
23
26
|
const require = createRequire(import.meta.url);
|
|
24
27
|
|
|
@@ -996,7 +999,8 @@ function packageMain(packageDir) {
|
|
|
996
999
|
/**
|
|
997
1000
|
* The local module a doc's import names: the doc's own `import`, else the
|
|
998
1001
|
* subpath its directory publishes, read through the package's `exports` (its
|
|
999
|
-
* `main` when it has none).
|
|
1002
|
+
* `main` when it has none). A subpath's `source` condition wins when its file
|
|
1003
|
+
* is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
|
|
1000
1004
|
* null when the import names another package or resolves to no file.
|
|
1001
1005
|
*
|
|
1002
1006
|
* @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
|
|
@@ -1027,11 +1031,13 @@ export function importedModule(integration, docPath, doc) {
|
|
|
1027
1031
|
specifier === packageName
|
|
1028
1032
|
? '.'
|
|
1029
1033
|
: `./${specifier.slice(packageName.length + 1)}`;
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1034
|
+
const pkg = {name: packageName, exports: exportsMap ?? undefined};
|
|
1035
|
+
// The `source` condition first, when its file is there, so a family lists
|
|
1036
|
+
// the same members whether or not the package has been built.
|
|
1037
|
+
return (
|
|
1038
|
+
sourceExportTarget(pkg, packageDir, subpath) ??
|
|
1039
|
+
inspectPackageExport(pkg, packageDir, subpath).target
|
|
1040
|
+
);
|
|
1035
1041
|
}
|
|
1036
1042
|
|
|
1037
1043
|
/**
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The file a subpath's `source` condition names, when that file is in the
|
|
6
|
+
* package. A package that ships its source (or a workspace package before it
|
|
7
|
+
* is built) declares it beside the built target, so reading it answers the
|
|
8
|
+
* same with or without a build. Null when there is no such condition or file.
|
|
9
|
+
* @param {{exports?: unknown}} pkg
|
|
10
|
+
* @param {string} packageDir
|
|
11
|
+
* @param {string} subpath `.` or a `./`-prefixed subpath
|
|
12
|
+
* @returns {string|null}
|
|
13
|
+
*/
|
|
14
|
+
export function sourceExportTarget(pkg: {
|
|
15
|
+
exports?: unknown;
|
|
16
|
+
}, packageDir: string, subpath: string): string | null;
|
|
4
17
|
/**
|
|
5
18
|
* @typedef {object} PackageExportResult
|
|
6
19
|
* @property {string} subpath
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* their legacy public deep paths and are resolved from files on disk.
|
|
9
9
|
*
|
|
10
10
|
* @input Parsed package.json, package directory, and a public subpath
|
|
11
|
-
* @output The public specifier and confined target file, when exported
|
|
11
|
+
* @output The public specifier and confined target file, when exported, and
|
|
12
|
+
* the file a subpath's `source` condition names, when the package has it
|
|
12
13
|
* @position packages/cli/foundation/discovery — shared package import metadata
|
|
13
14
|
*/
|
|
14
15
|
|
|
@@ -165,6 +166,44 @@ function resolveLegacy(packageDir, subpath) {
|
|
|
165
166
|
return candidates.find(regularFile) ?? null;
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
/**
|
|
170
|
+
* The raw export value one subpath maps to, with the wildcard it matched.
|
|
171
|
+
* @param {unknown} exportsField
|
|
172
|
+
* @param {string} subpath
|
|
173
|
+
* @returns {{value: unknown, wildcard: string} | null}
|
|
174
|
+
*/
|
|
175
|
+
function rawExportValue(exportsField, subpath) {
|
|
176
|
+
if (exportsField == null) return null;
|
|
177
|
+
if (!isRecord(exportsField)) {
|
|
178
|
+
return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
|
|
179
|
+
}
|
|
180
|
+
if (!Object.keys(exportsField).some(key => key.startsWith('.'))) {
|
|
181
|
+
return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
|
|
182
|
+
}
|
|
183
|
+
const selected = subpathValue(exportsField, subpath);
|
|
184
|
+
return selected.found
|
|
185
|
+
? {value: selected.value, wildcard: selected.wildcard}
|
|
186
|
+
: null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The file a subpath's `source` condition names, when that file is in the
|
|
191
|
+
* package. A package that ships its source (or a workspace package before it
|
|
192
|
+
* is built) declares it beside the built target, so reading it answers the
|
|
193
|
+
* same with or without a build. Null when there is no such condition or file.
|
|
194
|
+
* @param {{exports?: unknown}} pkg
|
|
195
|
+
* @param {string} packageDir
|
|
196
|
+
* @param {string} subpath `.` or a `./`-prefixed subpath
|
|
197
|
+
* @returns {string|null}
|
|
198
|
+
*/
|
|
199
|
+
export function sourceExportTarget(pkg, packageDir, subpath) {
|
|
200
|
+
const selected = rawExportValue(pkg.exports, subpath);
|
|
201
|
+
if (!selected || !isRecord(selected.value)) return null;
|
|
202
|
+
const source = selected.value.source;
|
|
203
|
+
if (typeof source !== 'string') return null;
|
|
204
|
+
return resolveTarget(packageDir, source.replaceAll('*', selected.wildcard));
|
|
205
|
+
}
|
|
206
|
+
|
|
168
207
|
/**
|
|
169
208
|
* @typedef {object} PackageExportResult
|
|
170
209
|
* @property {string} subpath
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5-canary.0b78509",
|
|
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",
|
|
@@ -106,10 +106,10 @@
|
|
|
106
106
|
"zod": "^4.4.3"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
|
-
"@astryxdesign/charts": "
|
|
110
|
-
"@astryxdesign/core": "
|
|
111
|
-
"@astryxdesign/lab": "
|
|
112
|
-
"@astryxdesign/theme-neutral": "
|
|
109
|
+
"@astryxdesign/charts": "0.7.5-canary.0b78509",
|
|
110
|
+
"@astryxdesign/core": "0.7.5-canary.0b78509",
|
|
111
|
+
"@astryxdesign/lab": "0.7.5-canary.0b78509",
|
|
112
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.0b78509"
|
|
113
113
|
},
|
|
114
114
|
"peerDependenciesMeta": {
|
|
115
115
|
"@astryxdesign/charts": {
|
|
@@ -126,10 +126,10 @@
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
|
-
"@astryxdesign/charts": "
|
|
130
|
-
"@astryxdesign/core": "
|
|
131
|
-
"@astryxdesign/lab": "
|
|
132
|
-
"@astryxdesign/theme-neutral": "
|
|
129
|
+
"@astryxdesign/charts": "0.7.5-canary.0b78509",
|
|
130
|
+
"@astryxdesign/core": "0.7.5-canary.0b78509",
|
|
131
|
+
"@astryxdesign/lab": "0.7.5-canary.0b78509",
|
|
132
|
+
"@astryxdesign/theme-neutral": "0.7.5-canary.0b78509",
|
|
133
133
|
"@heroicons/react": "^2.2.0",
|
|
134
134
|
"@stylexjs/stylex": "^0.19.0",
|
|
135
135
|
"@types/babel__core": "^7.20.5",
|