@astryxdesign/cli 0.7.5-canary.dbcfc30 → 0.7.5-canary.dc5a8cf

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.
Files changed (24) hide show
  1. package/api/template/tokenizer-showcase.test.mjs +47 -0
  2. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  3. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  4. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  5. package/api/theme/build/build.mjs +190 -95
  6. package/api/theme/build/build.project-core.test.mjs +63 -8
  7. package/api/theme/build/build.test.mjs +77 -0
  8. package/assets/docs/author-a-theme.doc.mjs +3 -1
  9. package/assets/docs/icons.doc.mjs +82 -1
  10. package/assets/docs/theme.doc.dense.mjs +8 -0
  11. package/assets/docs/theme.doc.mjs +16 -0
  12. package/assets/docs/theme.doc.zh.mjs +11 -0
  13. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  14. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  15. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  16. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  17. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  18. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  19. package/assets/theme.template.ts +18 -5
  20. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  21. package/foundation/agent-docs/agent-docs.mjs +1 -0
  22. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  23. package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
  24. package/package.json +9 -9
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx theme build` outside any project, as a separate process.
5
+ *
6
+ * A theme in a folder with no Core installed (an empty folder, a fresh clone)
7
+ * imports `defineTheme` from Core all the same: the build hands its imports
8
+ * the Core the CLI answers with, as a new project with that Core would build
9
+ * it (spec AST-081 FR3). The CLI runs as its own process, without the
10
+ * `NODE_PATH` a pnpm script sets (it reaches the repository's packages): in
11
+ * the test runner, or with that path, the theme's import would find the
12
+ * repository's Core, which a real run outside a project cannot.
13
+ */
14
+
15
+ import {afterEach, beforeAll, beforeEach, describe, expect, it} from 'vitest';
16
+ import * as fs from 'node:fs';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import {spawnSync} from 'node:child_process';
20
+ import {fileURLToPath} from 'node:url';
21
+ import {ensureCoreBuilt} from './ensure-core-built.mjs';
22
+
23
+ const CLI_BIN = fileURLToPath(new URL('../bin/astryx.mjs', import.meta.url));
24
+ const CORE_DIR = fileURLToPath(new URL('../../../../core', import.meta.url));
25
+
26
+ /** @param {string[]} args @param {string} cwd */
27
+ function runCliProcess(args, cwd) {
28
+ const {NODE_PATH: _repositoryPackages, ...env} = process.env;
29
+ const result = spawnSync(process.execPath, [CLI_BIN, ...args], {
30
+ cwd,
31
+ encoding: 'utf-8',
32
+ timeout: 60_000,
33
+ env,
34
+ });
35
+ if (result.error) throw result.error;
36
+ return result;
37
+ }
38
+
39
+ beforeAll(() => {
40
+ ensureCoreBuilt();
41
+ }, 200_000);
42
+
43
+ let tmpDir;
44
+ beforeEach(() => {
45
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-theme-outside-'));
46
+ });
47
+ afterEach(() => {
48
+ fs.rmSync(tmpDir, {recursive: true, force: true});
49
+ });
50
+
51
+ /**
52
+ * A project beside the empty folder: its own package.json and Core (this
53
+ * repository's, linked), so the same theme builds there through the
54
+ * project's own resolution.
55
+ * @param {string} dir
56
+ */
57
+ function makeProject(dir) {
58
+ fs.mkdirSync(path.join(dir, 'node_modules', '@astryxdesign'), {
59
+ recursive: true,
60
+ });
61
+ fs.writeFileSync(
62
+ path.join(dir, 'package.json'),
63
+ '{"name": "theme-project", "private": true, "dependencies": {"@astryxdesign/core": "*"}}\n',
64
+ );
65
+ fs.symlinkSync(
66
+ CORE_DIR,
67
+ path.join(dir, 'node_modules', '@astryxdesign', 'core'),
68
+ 'junction',
69
+ );
70
+ }
71
+
72
+ describe('theme build outside any project builds a plain-object theme as a project does', () => {
73
+ const themes = {
74
+ typography: `export default {
75
+ name: 'plain-type',
76
+ tokens: {'--color-background': '#123456'},
77
+ typography: {body: {family: 'Helvetica', fallbacks: 'Arial, sans-serif'}},
78
+ };\n`,
79
+ 'local tokens and media surfaces': `export default {
80
+ name: 'plain-local',
81
+ tokens: {'--color-background': '#123456'},
82
+ localTokens: {'--ac-selection-ink': ['#0077b6', '#48cae4']},
83
+ components: {badge: {'variant:info': {backgroundColor: 'var(--ac-selection-ink)'}}},
84
+ onDark: {components: {badge: {'variant:info': {color: 'var(--ac-selection-ink)'}}}},
85
+ };\n`,
86
+ };
87
+ for (const [what, source] of Object.entries(themes)) {
88
+ for (const ext of ['mjs', 'ts']) {
89
+ it(`with ${what}, in a .${ext} file`, () => {
90
+ const name = /name: '([^']+)'/.exec(source)[1];
91
+ const project = path.join(tmpDir, 'project');
92
+ makeProject(project);
93
+ const outside = path.join(tmpDir, 'outside');
94
+ fs.mkdirSync(outside);
95
+ for (const dir of [project, outside]) {
96
+ fs.writeFileSync(path.join(dir, `theme.${ext}`), source);
97
+ const result = runCliProcess(['theme', 'build', `theme.${ext}`], dir);
98
+ expect(result.status, result.stderr + result.stdout).toBe(0);
99
+ }
100
+ expect(fs.readFileSync(path.join(outside, `${name}.css`), 'utf8')).toBe(
101
+ fs.readFileSync(path.join(project, `${name}.css`), 'utf8'),
102
+ );
103
+ });
104
+ }
105
+ }
106
+ });
107
+
108
+ describe('theme build outside any project', () => {
109
+ for (const ext of ['mjs', 'ts']) {
110
+ it(`builds a .${ext} theme that imports defineTheme from Core, with the Core the CLI answers with`, () => {
111
+ fs.writeFileSync(
112
+ path.join(tmpDir, `outside.${ext}`),
113
+ "import {defineTheme} from '@astryxdesign/core/theme';\n" +
114
+ "export default defineTheme({name: 'outside', tokens: {'--color-background': '#123456'}});\n",
115
+ );
116
+ const result = runCliProcess(
117
+ ['theme', 'build', `outside.${ext}`],
118
+ tmpDir,
119
+ );
120
+ expect(result.status, result.stderr + result.stdout).toBe(0);
121
+ expect(
122
+ fs.readFileSync(path.join(tmpDir, 'outside.css'), 'utf8'),
123
+ ).toContain('#123456');
124
+ });
125
+ }
126
+
127
+ for (const ext of ['mjs', 'ts']) {
128
+ it(`still fails a .${ext} module that defines no theme`, () => {
129
+ fs.writeFileSync(
130
+ path.join(tmpDir, `none.${ext}`),
131
+ 'export const notATheme = 42;\n',
132
+ );
133
+ const result = runCliProcess(['theme', 'build', `none.${ext}`], tmpDir);
134
+ expect(result.status).toBe(1);
135
+ expect(result.stderr + result.stdout).toMatch(
136
+ /Could not find a defineTheme\(\) result/,
137
+ );
138
+ });
139
+ }
140
+ });
@@ -673,6 +673,7 @@ export function detectStylingSystem(targetDir) {
673
673
  '@stylexjs/rollup-plugin',
674
674
  '@stylexjs/webpack-plugin',
675
675
  '@stylexjs/nextjs-plugin',
676
+ '@stylexjs/unplugin',
676
677
  'vite-plugin-stylex',
677
678
  'unplugin-stylex',
678
679
  '@stylexswc/unplugin',
@@ -552,6 +552,11 @@ describe('detectStylingSystem', () => {
552
552
  expect(detectStylingSystem(tmpDir)).toBe('stylex');
553
553
  });
554
554
 
555
+ it('detects the official unplugin (the standard Vite path)', () => {
556
+ writePkg({'@stylexjs/unplugin': '0.10.0'});
557
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
558
+ });
559
+
555
560
  it('detects tailwind when tailwindcss is present', () => {
556
561
  writePkg({tailwindcss: '4.0.0'});
557
562
  expect(detectStylingSystem(tmpDir)).toBe('tailwind');
@@ -65,12 +65,11 @@ const RUNNERS = {
65
65
  sites: ['importThemeArtifact'],
66
66
  },
67
67
  'api/theme/build/build.mjs': {
68
- runs: "theme source modules, through jiti; eval for legacy theme object literals; the project's installed Core",
68
+ runs: "theme source modules, through jiti; the project's installed Core",
69
69
  sites: [
70
70
  '.evalModule() ×2',
71
71
  '.import()',
72
72
  'createJiti ×5',
73
- 'eval ×2',
74
73
  'import(<computed>) ×3',
75
74
  ],
76
75
  },
@@ -218,10 +217,7 @@ const RUNNERS = {
218
217
  },
219
218
  'clients/cli/commands/hook.mjs': {
220
219
  runs: SELF_DOCS,
221
- sites: [
222
- 'import ../../../api/hook/hook.doc.mjs',
223
- 'import ./hook.doc.mjs',
224
- ],
220
+ sites: ['import ../../../api/hook/hook.doc.mjs', 'import ./hook.doc.mjs'],
225
221
  },
226
222
  'clients/cli/commands/init.mjs': {
227
223
  runs: SELF_DOCS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.5-canary.dbcfc30",
3
+ "version": "0.7.5-canary.dc5a8cf",
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",
@@ -111,10 +111,10 @@
111
111
  "zod": "^4.4.3"
112
112
  },
113
113
  "peerDependencies": {
114
- "@astryxdesign/charts": "0.7.5-canary.dbcfc30",
115
- "@astryxdesign/core": "0.7.5-canary.dbcfc30",
116
- "@astryxdesign/lab": "0.7.5-canary.dbcfc30",
117
- "@astryxdesign/theme-neutral": "0.7.5-canary.dbcfc30"
114
+ "@astryxdesign/charts": "0.7.5-canary.dc5a8cf",
115
+ "@astryxdesign/core": "0.7.5-canary.dc5a8cf",
116
+ "@astryxdesign/lab": "0.7.5-canary.dc5a8cf",
117
+ "@astryxdesign/theme-neutral": "0.7.5-canary.dc5a8cf"
118
118
  },
119
119
  "peerDependenciesMeta": {
120
120
  "@astryxdesign/charts": {
@@ -131,10 +131,10 @@
131
131
  }
132
132
  },
133
133
  "devDependencies": {
134
- "@astryxdesign/charts": "0.7.5-canary.dbcfc30",
135
- "@astryxdesign/core": "0.7.5-canary.dbcfc30",
136
- "@astryxdesign/lab": "0.7.5-canary.dbcfc30",
137
- "@astryxdesign/theme-neutral": "0.7.5-canary.dbcfc30",
134
+ "@astryxdesign/charts": "0.7.5-canary.dc5a8cf",
135
+ "@astryxdesign/core": "0.7.5-canary.dc5a8cf",
136
+ "@astryxdesign/lab": "0.7.5-canary.dc5a8cf",
137
+ "@astryxdesign/theme-neutral": "0.7.5-canary.dc5a8cf",
138
138
  "@heroicons/react": "^2.2.0",
139
139
  "@stylexjs/stylex": "^0.19.0",
140
140
  "@types/babel__core": "^7.20.5",