@astryxdesign/cli 0.1.6-canary.eb549c8 → 0.1.6-canary.ef814e0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.6-canary.
|
|
3
|
+
"version": "0.1.6-canary.ef814e0",
|
|
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",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"zod": "^4.4.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@astryxdesign/charts": "0.1.6-canary.
|
|
79
|
-
"@astryxdesign/core": "0.1.6-canary.
|
|
80
|
-
"@astryxdesign/lab": "0.1.6-canary.
|
|
81
|
-
"@astryxdesign/theme-neutral": "0.1.6-canary.
|
|
78
|
+
"@astryxdesign/charts": "0.1.6-canary.ef814e0",
|
|
79
|
+
"@astryxdesign/core": "0.1.6-canary.ef814e0",
|
|
80
|
+
"@astryxdesign/lab": "0.1.6-canary.ef814e0",
|
|
81
|
+
"@astryxdesign/theme-neutral": "0.1.6-canary.ef814e0",
|
|
82
82
|
"gpt-tokenizer": "^3.4.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@astryxdesign/charts": "0.1.6-canary.
|
|
100
|
-
"@astryxdesign/core": "0.1.6-canary.
|
|
101
|
-
"@astryxdesign/lab": "0.1.6-canary.
|
|
102
|
-
"@astryxdesign/theme-neutral": "0.1.6-canary.
|
|
99
|
+
"@astryxdesign/charts": "0.1.6-canary.ef814e0",
|
|
100
|
+
"@astryxdesign/core": "0.1.6-canary.ef814e0",
|
|
101
|
+
"@astryxdesign/lab": "0.1.6-canary.ef814e0",
|
|
102
|
+
"@astryxdesign/theme-neutral": "0.1.6-canary.ef814e0",
|
|
103
103
|
"gpt-tokenizer": "^3.4.0"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# Authoring an Astryx Integration
|
|
2
|
-
|
|
3
|
-
> **Status:** working notes. This should eventually move to the public wiki
|
|
4
|
-
> alongside the rest of the integration-authoring guidance; it lives here for
|
|
5
|
-
> now so it ships and is versioned with the CLI.
|
|
6
|
-
|
|
7
|
-
An **Integration** is an npm package that contributes components, templates, and/or
|
|
8
|
-
codemods to a consumer's design-system workflow. Consumers install the 3rd party
|
|
9
|
-
package, add a line to their astryx.config file:
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
import {createConfig} from '@astryxdesign/cli/config';
|
|
13
|
-
|
|
14
|
-
export default createConfig({
|
|
15
|
-
integrations: ['@acme/astryx-widgets'],
|
|
16
|
-
...
|
|
17
|
-
});
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Then the integration's components and templates will be surfaced alongside Astryx
|
|
21
|
-
components in the Astryx CLI.
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
astryx component AcmeCarousel --props
|
|
25
|
-
astryx component --list --package @acme/astryx-widgets
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## The Integration File
|
|
29
|
-
|
|
30
|
-
In order to register your package as an Astryx Integration, create an
|
|
31
|
-
`astryx.integration.{ts,mjs,js}` file as a sibling to your `package.json`. This file
|
|
32
|
-
tells Astryx where to find your components, templates, codemods, etc.
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
// astryx.integration.{ts,mjs,js}
|
|
36
|
-
import {createIntegration} from '@astryxdesign/cli/integration';
|
|
37
|
-
|
|
38
|
-
export default createIntegration({
|
|
39
|
-
components: './components',
|
|
40
|
-
templates: './templates',
|
|
41
|
-
codemods: './codemods',
|
|
42
|
-
issuesUrl: 'https://github.com/acme/widgets/issues',
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Components
|
|
47
|
-
|
|
48
|
-
Your components themselves may be exported from your library as you see fit (consumers
|
|
49
|
-
will still import them from your package) but Astryx CLI will look for a .doc.{ts,mjs,js}
|
|
50
|
-
file with the same stem e.g. `AcmeCarousel.tsx` and `AcmeCarousel.doc.ts`.
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
// AcmeCarousel.doc.ts
|
|
54
|
-
import {createComponentDoc} from '@astryxdesign/cli/doc';
|
|
55
|
-
|
|
56
|
-
export default createComponentDoc({
|
|
57
|
-
name: 'AcmeCarousel',
|
|
58
|
-
description: '...',
|
|
59
|
-
...
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Templates
|
|
64
|
-
|
|
65
|
-
Templates are typically not exported from the package directly, but instead accessed
|
|
66
|
-
via the Astryx CLI. Consumers can look through your templates and materialize them
|
|
67
|
-
into their apps.
|
|
68
|
-
|
|
69
|
-
You define a template with the `createPageTemplate` (for full pages) or `createBlockTemplate`
|
|
70
|
-
(for smaller chunks). e.g. `AcmeLandingPage.tsx`, `AcmeLandingPage.template.ts`
|
|
71
|
-
|
|
72
|
-
```js
|
|
73
|
-
// AcmeLandingPage.template.ts
|
|
74
|
-
import {createPageTemplate} from '@astryxdesign/cli/template';
|
|
75
|
-
|
|
76
|
-
export default createPageTemplate({
|
|
77
|
-
...
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Note that, since the CLI needs access to the template source code, you need to make sure
|
|
82
|
-
that it is included in your published package. This will also allow us to render previews
|
|
83
|
-
of templates in the future by bundling your template into a doc site build.
|
|
84
|
-
|
|
85
|
-
Typically, this is done via the package.json `exports` key.
|
|
86
|
-
|
|
87
|
-
```jsonc
|
|
88
|
-
{
|
|
89
|
-
"exports": {
|
|
90
|
-
// ...
|
|
91
|
-
"./templates/*.tsx": "./templates/*.tsx",
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
In order to verify that it's working, you can test importing the template component like this:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
import('@acme/astryx-widgets/templates/AcmeLandingPage.tsx');
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Import **with the `.tsx` extension** — an extensionless specifier won't resolve
|
|
103
|
-
under `moduleResolution: bundler`. The extensionful `"./templates/*.tsx"` export
|
|
104
|
-
above is what lets that import type-check without consumers enabling
|
|
105
|
-
`allowImportingTsExtensions`.
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file Proves the minimal `exports` recipe an integration package needs so a
|
|
5
|
-
* bundler-resolution consumer can `import()` its block templates AND type-check
|
|
6
|
-
* them under `moduleResolution: bundler`.
|
|
7
|
-
*
|
|
8
|
-
* Integration packages in this ecosystem ship TypeScript SOURCE — their block
|
|
9
|
-
* templates are `.tsx` files with no compiled `.d.ts`. A later feature renders
|
|
10
|
-
* showcase previews by a REAL dynamic `import()` of a block's `.tsx` source
|
|
11
|
-
* (e.g. `import('@acme/widgets/templates/Gauge/GaugeShowcase.tsx')`) instead of
|
|
12
|
-
* eval'ing source text. For that import to resolve, the integration's
|
|
13
|
-
* `package.json#exports` map must GATE the deep path.
|
|
14
|
-
*
|
|
15
|
-
* These tests stand up a throwaway `@acme/widgets` fixture and drive the two
|
|
16
|
-
* gates that matter with the repo's own toolchain:
|
|
17
|
-
* 1. `tsc --noEmit` under `moduleResolution: bundler` (the consumer profile
|
|
18
|
-
* used by the Next.js example apps — NO `allowImportingTsExtensions`).
|
|
19
|
-
* 2. `esbuild --bundle` (a real bundler resolving + loading the deep import).
|
|
20
|
-
*
|
|
21
|
-
* CANONICAL RECIPE (see integration-authoring.md):
|
|
22
|
-
* exports: { "./templates/*.tsx": "./templates/*.tsx" }
|
|
23
|
-
* import: import('@acme/widgets/templates/<Name>/<Name>Showcase.tsx') // WITH .tsx
|
|
24
|
-
*
|
|
25
|
-
* The negative controls lock in WHY the extension is required: a bare
|
|
26
|
-
* `./templates/*` export with an extensionless import fails to type-check under
|
|
27
|
-
* bundler resolution (TS cannot infer the `.tsx` extension for a deep
|
|
28
|
-
* specifier), and an extensionless import fails to bundle.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
32
|
-
import * as fs from 'node:fs';
|
|
33
|
-
import * as os from 'node:os';
|
|
34
|
-
import * as path from 'node:path';
|
|
35
|
-
import {createRequire} from 'node:module';
|
|
36
|
-
import {execFileSync} from 'node:child_process';
|
|
37
|
-
|
|
38
|
-
const require = createRequire(import.meta.url);
|
|
39
|
-
|
|
40
|
-
/** Resolve the workspace tsc/esbuild binaries; null if unavailable. */
|
|
41
|
-
function resolveBin(spec) {
|
|
42
|
-
try {
|
|
43
|
-
return require.resolve(spec);
|
|
44
|
-
} catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const TSC_BIN = resolveBin('typescript/bin/tsc');
|
|
49
|
-
const ESBUILD_BIN = resolveBin('esbuild/bin/esbuild');
|
|
50
|
-
|
|
51
|
-
let tmpDir;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Build an @acme/widgets fixture: a block template (`.template.ts` doc +
|
|
55
|
-
* same-stem `.tsx` source) under `templates/`, plus an astryx.integration
|
|
56
|
-
* manifest, plus a caller-supplied `exports` map.
|
|
57
|
-
* @param {Record<string, string> | undefined} exportsMap
|
|
58
|
-
*/
|
|
59
|
-
function makeWidgets(exportsMap) {
|
|
60
|
-
const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
|
|
61
|
-
const blockDir = path.join(pkgDir, 'templates', 'Gauge');
|
|
62
|
-
fs.mkdirSync(blockDir, {recursive: true});
|
|
63
|
-
|
|
64
|
-
const pkg = {name: '@acme/widgets', version: '2.0.0', type: 'module'};
|
|
65
|
-
if (exportsMap) pkg.exports = exportsMap;
|
|
66
|
-
fs.writeFileSync(
|
|
67
|
-
path.join(pkgDir, 'package.json'),
|
|
68
|
-
JSON.stringify(pkg, null, 2),
|
|
69
|
-
);
|
|
70
|
-
fs.writeFileSync(
|
|
71
|
-
path.join(pkgDir, 'astryx.integration.mjs'),
|
|
72
|
-
`export default { templates: './templates' };\n`,
|
|
73
|
-
);
|
|
74
|
-
// The template-spec doc (canonical `.template.*` family).
|
|
75
|
-
fs.writeFileSync(
|
|
76
|
-
path.join(blockDir, 'GaugeShowcase.template.ts'),
|
|
77
|
-
`export default { name: 'Gauge showcase', description: 'A gauge.' };\n`,
|
|
78
|
-
);
|
|
79
|
-
// The same-stem `.tsx` SOURCE that a preview will dynamically import().
|
|
80
|
-
// Returns a plain value so the fixture type-checks without React types.
|
|
81
|
-
fs.writeFileSync(
|
|
82
|
-
path.join(blockDir, 'GaugeShowcase.tsx'),
|
|
83
|
-
`const GaugeShowcase = (): string => 'gauge-showcase';\n` +
|
|
84
|
-
`export default GaugeShowcase;\n`,
|
|
85
|
-
);
|
|
86
|
-
return pkgDir;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Write a consumer that dynamically imports the given specifier. */
|
|
90
|
-
function writeConsumer(specifier) {
|
|
91
|
-
fs.writeFileSync(
|
|
92
|
-
path.join(tmpDir, 'consumer.ts'),
|
|
93
|
-
`const load = () => import('${specifier}');\nexport default load;\n`,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The realistic consumer tsconfig: matches the repo's Next.js example apps
|
|
99
|
-
* (`moduleResolution: bundler`, `noEmit`, and deliberately NO
|
|
100
|
-
* `allowImportingTsExtensions`).
|
|
101
|
-
*/
|
|
102
|
-
function writeTsconfig() {
|
|
103
|
-
fs.writeFileSync(
|
|
104
|
-
path.join(tmpDir, 'tsconfig.json'),
|
|
105
|
-
JSON.stringify(
|
|
106
|
-
{
|
|
107
|
-
compilerOptions: {
|
|
108
|
-
target: 'ES2022',
|
|
109
|
-
lib: ['ES2022', 'DOM', 'DOM.Iterable'],
|
|
110
|
-
module: 'ESNext',
|
|
111
|
-
moduleResolution: 'bundler',
|
|
112
|
-
jsx: 'react-jsx',
|
|
113
|
-
strict: true,
|
|
114
|
-
skipLibCheck: true,
|
|
115
|
-
esModuleInterop: true,
|
|
116
|
-
noEmit: true,
|
|
117
|
-
isolatedModules: true,
|
|
118
|
-
},
|
|
119
|
-
include: ['consumer.ts'],
|
|
120
|
-
},
|
|
121
|
-
null,
|
|
122
|
-
2,
|
|
123
|
-
),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** @returns {{ok: boolean, out: string}} */
|
|
128
|
-
function runTsc() {
|
|
129
|
-
try {
|
|
130
|
-
execFileSync(process.execPath, [TSC_BIN, '--noEmit', '-p', 'tsconfig.json'], {
|
|
131
|
-
cwd: tmpDir,
|
|
132
|
-
stdio: 'pipe',
|
|
133
|
-
});
|
|
134
|
-
return {ok: true, out: ''};
|
|
135
|
-
} catch (e) {
|
|
136
|
-
return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** @returns {{ok: boolean, out: string}} */
|
|
141
|
-
function runEsbuild() {
|
|
142
|
-
try {
|
|
143
|
-
// esbuild's bin is a native executable (not a node script), so invoke it
|
|
144
|
-
// directly rather than through process.execPath.
|
|
145
|
-
execFileSync(
|
|
146
|
-
ESBUILD_BIN,
|
|
147
|
-
[
|
|
148
|
-
'consumer.ts',
|
|
149
|
-
'--bundle',
|
|
150
|
-
'--format=esm',
|
|
151
|
-
'--loader:.tsx=tsx',
|
|
152
|
-
'--outfile=/dev/null',
|
|
153
|
-
'--log-level=error',
|
|
154
|
-
],
|
|
155
|
-
{cwd: tmpDir, stdio: 'pipe'},
|
|
156
|
-
);
|
|
157
|
-
return {ok: true, out: ''};
|
|
158
|
-
} catch (e) {
|
|
159
|
-
return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
beforeEach(() => {
|
|
164
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-block-exports-'));
|
|
165
|
-
fs.writeFileSync(
|
|
166
|
-
path.join(tmpDir, 'package.json'),
|
|
167
|
-
JSON.stringify({name: 'consumer', private: true, type: 'module'}),
|
|
168
|
-
);
|
|
169
|
-
writeTsconfig();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
afterEach(() => {
|
|
173
|
-
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const CANONICAL = 'import(@acme/widgets/templates/Gauge/GaugeShowcase.tsx)';
|
|
177
|
-
const SPEC = '@acme/widgets/templates/Gauge/GaugeShowcase.tsx';
|
|
178
|
-
|
|
179
|
-
describe('integration block-template exports recipe', () => {
|
|
180
|
-
it.runIf(TSC_BIN != null)(
|
|
181
|
-
`CANONICAL: exports {"./templates/*.tsx"} + ${CANONICAL} type-checks under bundler resolution`,
|
|
182
|
-
() => {
|
|
183
|
-
makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
|
|
184
|
-
writeConsumer(SPEC);
|
|
185
|
-
const {ok, out} = runTsc();
|
|
186
|
-
expect(out).toBe('');
|
|
187
|
-
expect(ok).toBe(true);
|
|
188
|
-
},
|
|
189
|
-
30_000,
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
it.runIf(ESBUILD_BIN != null)(
|
|
193
|
-
`CANONICAL: the same import resolves + bundles with a real bundler`,
|
|
194
|
-
() => {
|
|
195
|
-
makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
|
|
196
|
-
writeConsumer(SPEC);
|
|
197
|
-
const {ok, out} = runEsbuild();
|
|
198
|
-
expect(out).toBe('');
|
|
199
|
-
expect(ok).toBe(true);
|
|
200
|
-
},
|
|
201
|
-
30_000,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
it.runIf(TSC_BIN != null)(
|
|
205
|
-
'NEGATIVE: an extensionless import does NOT type-check (TS cannot infer .tsx)',
|
|
206
|
-
() => {
|
|
207
|
-
makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
|
|
208
|
-
writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
|
|
209
|
-
const {ok, out} = runTsc();
|
|
210
|
-
expect(ok).toBe(false);
|
|
211
|
-
expect(out).toContain('TS2307');
|
|
212
|
-
},
|
|
213
|
-
30_000,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
it.runIf(TSC_BIN != null)(
|
|
217
|
-
'NEGATIVE: a bare "./templates/*" export (no .tsx entry) does NOT type-check the .tsx import',
|
|
218
|
-
() => {
|
|
219
|
-
// Only a bare mapping — the extensionful subpath is not exported.
|
|
220
|
-
makeWidgets({'./templates/*': './templates/*'});
|
|
221
|
-
writeConsumer(SPEC);
|
|
222
|
-
const {ok, out} = runTsc();
|
|
223
|
-
expect(ok).toBe(false);
|
|
224
|
-
// Bare export forces the TS5097 opt-in requirement (allowImportingTsExtensions).
|
|
225
|
-
expect(out).toContain('TS5097');
|
|
226
|
-
},
|
|
227
|
-
30_000,
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
it.runIf(ESBUILD_BIN != null)(
|
|
231
|
-
'NEGATIVE: an extensionless import does NOT bundle against the .tsx-only export',
|
|
232
|
-
() => {
|
|
233
|
-
makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
|
|
234
|
-
writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
|
|
235
|
-
const {ok} = runEsbuild();
|
|
236
|
-
expect(ok).toBe(false);
|
|
237
|
-
},
|
|
238
|
-
30_000,
|
|
239
|
-
);
|
|
240
|
-
});
|