@astryxdesign/cli 0.7.5-canary.bc40b80 → 0.7.5-canary.c60f571

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.
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
3
+ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
4
4
  import {spawnSync} from 'node:child_process';
5
5
  import * as fs from 'node:fs';
6
6
  import * as path from 'node:path';
@@ -123,4 +123,27 @@ describe('integrationPackCheck with lifecycle script output', () => {
123
123
  expect(failure?.message).toContain('npm pack failed (exit 3)');
124
124
  expect(failure?.message).toContain('prepack exploded');
125
125
  });
126
+
127
+ it.skipIf(process.platform === 'win32')(
128
+ 'packs with npm itself when an earlier npm on the PATH refuses every command',
129
+ async () => {
130
+ writeThemePackage({});
131
+ const refusing = path.join(tmpDir, '.refusing-bin');
132
+ fs.mkdirSync(refusing);
133
+ fs.writeFileSync(
134
+ path.join(refusing, 'npm'),
135
+ "#!/bin/sh\necho 'npm commands are not allowed on this machine'\nexit 1\n",
136
+ {mode: 0o755},
137
+ );
138
+ vi.stubEnv('PATH', `${refusing}${path.delimiter}${process.env.PATH}`);
139
+ try {
140
+ const result = await integrationPackCheck({cwd: tmpDir});
141
+
142
+ expect(result.data.issues).toEqual([]);
143
+ expect(result.data.packable).toBe(true);
144
+ } finally {
145
+ vi.unstubAllEnvs();
146
+ }
147
+ },
148
+ );
126
149
  });
@@ -25,6 +25,7 @@ import * as os from 'node:os';
25
25
  import {fileURLToPath} from 'node:url';
26
26
  import {spawnSync} from 'node:child_process';
27
27
  import {assertWithin} from '../../foundation/fs/path-safety.mjs';
28
+ import {npmCommand} from '../../foundation/release/cache.mjs';
28
29
  import {commandTokensIn} from '../../foundation/doc-compiler/doc-syntax.mjs';
29
30
  import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
30
31
  import {
@@ -265,17 +266,22 @@ function npmPackErrorDetail(output) {
265
266
  /**
266
267
  * Run `npm pack --json` with output directed to `destDir` so no preexisting
267
268
  * tgz is overwritten. This intentionally runs the package lifecycle, matching
268
- * the artifact `npm publish` would produce. Uses spawnSync with an args array —
269
- * no shell — so paths with metacharacters cannot inject.
269
+ * the artifact `npm publish` would produce. npm starts the way the CLI starts
270
+ * it everywhere else (`npmCommand`): npm's own entry file run with this Node
271
+ * when one is found, so an `npm` earlier on the PATH that is not npm itself
272
+ * cannot answer for it. Uses spawnSync with an args array — no shell — so
273
+ * paths with metacharacters cannot inject.
270
274
  *
271
275
  * @param {string} packageDir
272
276
  * @param {string} destDir
273
277
  * @returns {{filename: string, fileCount: number, size: number, unpackedSize: number, packedPaths: Set<string>}}
274
278
  */
275
279
  function runNpmPack(packageDir, destDir) {
280
+ const npm = npmCommand();
276
281
  const result = spawnSync(
277
- 'npm',
282
+ npm.command,
278
283
  [
284
+ ...npm.prefix,
279
285
  'pack',
280
286
  '--json',
281
287
  '--silent',
@@ -284,7 +290,7 @@ function runNpmPack(packageDir, destDir) {
284
290
  '--foreground-scripts=false',
285
291
  `--pack-destination=${destDir}`,
286
292
  ],
287
- {cwd: packageDir, encoding: 'utf-8', timeout: 60_000},
293
+ {cwd: packageDir, encoding: 'utf-8', shell: false, timeout: 60_000},
288
294
  );
289
295
  if (result.error) {
290
296
  throw new Error(`Could not start npm pack: ${result.error.message}`);
@@ -2125,10 +2125,13 @@ describe('integrationPackCheck', () => {
2125
2125
  ).toThrow(/without a files array/);
2126
2126
  });
2127
2127
 
2128
- it('reports npm missing from PATH as pack_failed', async () => {
2128
+ it('reports pack_failed when no npm can be found', async () => {
2129
2129
  writePackage({files: ['astryx.integration.mjs', 'themes']});
2130
2130
  const originalPath = process.env.PATH;
2131
+ const originalExecPath = process.execPath;
2131
2132
  process.env.PATH = '';
2133
+ // A Node with no npm beside it, and no npm on the PATH.
2134
+ process.execPath = path.join(tmpDir, 'no-npm', 'bin', 'node');
2132
2135
  try {
2133
2136
  const result = await integrationPackCheck({cwd: tmpDir});
2134
2137
  expect(result.data.packable).toBe(false);
@@ -2140,6 +2143,7 @@ describe('integrationPackCheck', () => {
2140
2143
  );
2141
2144
  } finally {
2142
2145
  process.env.PATH = originalPath;
2146
+ process.execPath = originalExecPath;
2143
2147
  }
2144
2148
  });
2145
2149
 
@@ -1,95 +1,148 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- import {describe, expect, it} from 'vitest';
4
- import transform from '../validate-data-token-ownership.mjs';
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import {afterAll, describe, expect, it} from 'vitest';
7
+ import transform, {meta} from '../validate-data-token-ownership.mjs';
8
+ import {upgrade} from '../../../../../api/upgrade/upgrade.mjs';
5
9
 
6
- async function run(source, file = 'test.tsx') {
7
- const jscodeshift = (await import('jscodeshift')).default;
8
- const parser =
9
- file.endsWith('.ts') || file.endsWith('.tsx') ? 'tsx' : 'babel';
10
- const api = {
11
- jscodeshift: jscodeshift.withParser(parser),
12
- stats: () => {},
13
- report: () => {},
10
+ const SLOW = 30_000;
11
+ const tempRoots = [];
12
+
13
+ afterAll(() => {
14
+ for (const root of tempRoots) fs.rmSync(root, {recursive: true, force: true});
15
+ });
16
+
17
+ const STALE_THEME = `/* @generated by \`astryx theme build\` */
18
+ @layer astryx-base {
19
+ :root { --color-data-categorical-green: #008000; }
20
+ }`;
21
+
22
+ const RAW_USES = {
23
+ 'src/chart.tsx': `export const fill = 'var(--color-data-categorical-green)';
24
+ export const border = \`1px solid var(--color-data-blue-3)\`;
25
+ `,
26
+ 'src/chart.css': '.bar { fill: var(--color-data-categorical-green); }\n',
27
+ };
28
+
29
+ /**
30
+ * A project with Core 0.7.0 installed and the given files, as a repository.
31
+ * @param {Record<string, string | object>} files
32
+ */
33
+ function project(files) {
34
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-data-token-'));
35
+ tempRoots.push(root);
36
+ fs.mkdirSync(path.join(root, '.git'));
37
+ const all = {
38
+ 'node_modules/@astryxdesign/core/package.json': {
39
+ name: '@astryxdesign/core',
40
+ version: '0.7.0',
41
+ },
42
+ ...files,
14
43
  };
15
- return transform({source, path: file}, api);
44
+ for (const [rel, contents] of Object.entries(all)) {
45
+ const file = path.join(root, rel);
46
+ fs.mkdirSync(path.dirname(file), {recursive: true});
47
+ fs.writeFileSync(
48
+ file,
49
+ typeof contents === 'string' ? contents : JSON.stringify(contents),
50
+ );
51
+ }
52
+ return root;
16
53
  }
17
54
 
18
- describe('validate-data-token-ownership', () => {
19
- it('reports direct string and static-template consumers with both migration paths', async () => {
20
- for (const source of [
21
- `const fill = 'var(--color-data-categorical-green)';`,
22
- 'const fill = `var(--color-data-categorical-green)`;',
23
- `const border = '1px solid var(--color-data-categorical-green)';`,
24
- 'const border = `${width}px solid var(--color-data-categorical-green)`;',
25
- ]) {
26
- await expect(run(source)).rejects.toThrow(
27
- /CSS-capable code imports dataVars.*Canvas.*resolveThemeToken/s,
28
- );
29
- }
30
- });
55
+ const PREBUILT = {
56
+ 'package.json': {dependencies: {'@astryxdesign/core': '0.7.3'}},
57
+ 'src/main.tsx': "import '@astryxdesign/core/astryx.css';\n",
58
+ };
59
+ const SOURCE_BUILT = {
60
+ 'package.json': {
61
+ dependencies: {'@astryxdesign/core': '0.7.3'},
62
+ devDependencies: {'@astryxdesign/build': '0.7.3'},
63
+ },
64
+ 'vite.config.ts':
65
+ "import {astryxStylex} from '@astryxdesign/build/vite';\nexport default {plugins: [...astryxStylex()]};\n",
66
+ };
31
67
 
32
- it('reports prebuilt CSS availability without requiring a source compile step', async () => {
33
- await expect(
34
- run('const fill = "var(--color-data-categorical-blue)";'),
35
- ).rejects.toThrow(
36
- /in prebuilt mode, loads @astryxdesign\/core\/astryx\.css/,
37
- );
38
- await expect(
39
- run('.bar { fill: var(--color-data-categorical-blue); }', 'chart.css'),
40
- ).rejects.toThrow(/load @astryxdesign\/core\/astryx\.css in prebuilt mode/);
41
- });
68
+ const runUpgrade = root =>
69
+ upgrade(
70
+ {from: '0.6.9', codemod: 'validate-data-token-ownership', apply: true},
71
+ {cwd: root},
72
+ );
42
73
 
43
- it('leaves fallbacks, dataVars access, and comments unchanged', async () => {
44
- const source = `
45
- // var(--color-data-categorical-green)
46
- const fallback = 'var(--color-data-categorical-green, #008000)';
47
- const fill = dataVars['--color-data-categorical-green'];
48
- `;
49
- expect(await run(source)).toBeUndefined();
74
+ describe('validate-data-token-ownership', () => {
75
+ it('reads only stylesheets', () => {
76
+ expect(meta.fileExtensions).toEqual(['.css']);
50
77
  });
51
78
 
52
- it('reports stale generated theme CSS with root data defaults', async () => {
53
- const source = `/* @generated by \`astryx theme build\` */
54
- @layer astryx-base {
55
- :root { --color-data-categorical-green: #008000; }
56
- }`;
57
- await expect(run(source, 'theme.css')).rejects.toThrow(
79
+ it('fails on stale generated theme CSS with root data defaults', () => {
80
+ expect(() => transform({source: STALE_THEME, path: 'theme.css'})).toThrow(
58
81
  /Rebuild it with `astryx theme build`/,
59
82
  );
60
83
  });
61
84
 
62
- it('reports raw stylesheet uses without a fallback', async () => {
63
- await expect(
64
- run('.bar { fill: var(--color-data-categorical-green); }', 'chart.css'),
65
- ).rejects.toThrow(/Raw var\(--color-data-categorical-green\).*line 1/s);
66
- });
67
-
68
- it('leaves stylesheet uses with a fallback, and comments, unchanged', async () => {
69
- expect(
70
- await run(
71
- `/* var(--color-data-categorical-green) */
72
- .bar { fill: var(--color-data-categorical-green, #008000); }`,
73
- 'chart.css',
74
- ),
75
- ).toBeUndefined();
85
+ it('passes raw data-token uses with or without a fallback', () => {
86
+ for (const source of [
87
+ '.bar { fill: var(--color-data-categorical-green); }',
88
+ '.bar { fill: var(--color-data-categorical-green, #008000); }',
89
+ `/* @generated by \`astryx theme build\` */
90
+ .bar { fill: var(--color-data-blue-3); }`,
91
+ ]) {
92
+ expect(transform({source, path: 'chart.css'})).toBeUndefined();
93
+ }
76
94
  });
77
95
 
78
- it('does not claim ownership of hand-authored CSS or sparse theme overrides', async () => {
96
+ it('does not claim ownership of hand-authored CSS or sparse theme overrides', () => {
79
97
  expect(
80
- await run(
81
- ':root { --color-data-categorical-green: #008000; }',
82
- 'app.css',
83
- ),
98
+ transform({
99
+ source: ':root { --color-data-categorical-green: #008000; }',
100
+ path: 'app.css',
101
+ }),
84
102
  ).toBeUndefined();
85
103
  expect(
86
- await run(
87
- `/* @generated by \`astryx theme build\` */
104
+ transform({
105
+ source: `/* @generated by \`astryx theme build\` */
88
106
  @scope ([data-astryx-theme="ocean"]) {
89
107
  :scope { --color-data-categorical-green: #008000; }
90
108
  }`,
91
- 'theme.css',
92
- ),
109
+ path: 'theme.css',
110
+ }),
93
111
  ).toBeUndefined();
94
112
  });
113
+
114
+ it(
115
+ 'completes `astryx upgrade --apply` over raw uses in a prebuilt project',
116
+ async () => {
117
+ const root = project({...PREBUILT, ...RAW_USES});
118
+ const res = await runUpgrade(root);
119
+ expect(res.data.complete).toBe(true);
120
+ expect(res.data.errors ?? []).toEqual([]);
121
+ expect(res.data.modifiedFiles ?? []).toEqual([]);
122
+ },
123
+ SLOW,
124
+ );
125
+
126
+ it(
127
+ 'completes `astryx upgrade --apply` over raw uses in a source-built project',
128
+ async () => {
129
+ const root = project({...SOURCE_BUILT, ...RAW_USES});
130
+ const res = await runUpgrade(root);
131
+ expect(res.data.complete).toBe(true);
132
+ expect(res.data.errors ?? []).toEqual([]);
133
+ expect(res.data.modifiedFiles ?? []).toEqual([]);
134
+ },
135
+ SLOW,
136
+ );
137
+
138
+ it(
139
+ 'fails `astryx upgrade --apply` on stale generated theme CSS',
140
+ async () => {
141
+ const root = project({...PREBUILT, 'src/theme.css': STALE_THEME});
142
+ await expect(runUpgrade(root)).rejects.toMatchObject({
143
+ code: 'ERR_CODEMOD_FAILED',
144
+ });
145
+ },
146
+ SLOW,
147
+ );
95
148
  });
@@ -1,13 +1,17 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Report data-token consumers that need an ownership migration.
4
+ * @file Reject stale generated theme CSS that still owns data-token defaults.
5
5
  *
6
- * @input Consumer JavaScript/TypeScript source and generated theme CSS
7
- * @output No rewritten source; actionable upgrade errors for fallback-less
8
- * `var(--color-data-*)` uses (in JS strings, embedded or whole, and in CSS)
9
- * and stale generated root-default artifacts
10
- * @position Next-release upgrade validation for spec:AST-066
6
+ * @input Generated theme CSS
7
+ * @output No rewritten source; an upgrade error for a generated theme
8
+ * stylesheet that still declares data-color defaults at `:root`
9
+ * @position Next-release upgrade validation for spec:AST-066 FR19
10
+ *
11
+ * Raw `var(--color-data-*)` uses are not checked: prebuilt
12
+ * `@astryxdesign/core/astryx.css` and the `@astryxdesign/build` PostCSS
13
+ * integration define all 56 defaults, and other source builds read data
14
+ * colors through `dataVars` (spec:AST-066 FR3/FR4).
11
15
  */
12
16
 
13
17
  import * as path from 'node:path';
@@ -15,87 +19,25 @@ import * as path from 'node:path';
15
19
  export const meta = {
16
20
  title: 'Validate data-token ownership',
17
21
  description:
18
- 'Reports fallback-less data-token var() uses in source strings and stylesheets for manual CSS/non-CSS migration, and stale generated theme CSS that still owns root defaults.',
19
- fileExtensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.css'],
22
+ 'Reports generated theme CSS that still emits the canonical data-color defaults at :root, so it can be rebuilt with `astryx theme build`.',
23
+ fileExtensions: ['.css'],
20
24
  };
21
25
 
22
- // A use without a fallback; `var(--color-data-x, <fallback>)` stays valid.
23
- const DIRECT_DATA_VAR = /var\(\s*(--color-data-[a-z0-9-]+)\s*\)/u;
24
- const CSS_COMMENT = /\/\*[\s\S]*?\*\//gu;
25
26
  const GENERATED_THEME_HEADER = '@generated by `astryx theme build`';
26
27
  const ROOT_DATA_DECLARATION = /:root\s*\{[^}]*--color-data-/su;
27
28
 
28
- /** @param {any} node */
29
- function staticString(node) {
30
- if (
31
- (node?.type === 'StringLiteral' || node?.type === 'Literal') &&
32
- typeof node.value === 'string'
33
- ) {
34
- return node.value;
35
- }
36
- if (node?.type === 'TemplateLiteral') {
37
- // Each static chunk of the template; a use can sit between expressions.
38
- return (node.quasis ?? [])
39
- .map((/** @type {any} */ q) => q?.value?.cooked ?? q?.value?.raw ?? '')
40
- .join('\u0000');
41
- }
42
- return undefined;
43
- }
44
-
45
29
  /**
46
30
  * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
47
- * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
48
31
  * @returns {undefined}
49
32
  */
50
- export default function validateDataTokenOwnership(file, api) {
51
- if (!file.source.includes('--color-data-')) return undefined;
52
-
53
- if (path.extname(file.path) === '.css') {
54
- if (
55
- file.source.includes(GENERATED_THEME_HEADER) &&
56
- ROOT_DATA_DECLARATION.test(file.source)
57
- ) {
58
- throw new Error(
59
- 'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults come from source-compiled dataVars consumers or @astryxdesign/core/astryx.css in prebuilt mode.',
60
- );
61
- }
62
- const uncommented = file.source.replace(CSS_COMMENT, comment =>
63
- comment.replace(/[^\n]/gu, ' '),
64
- );
65
- const cssMatch = DIRECT_DATA_VAR.exec(uncommented);
66
- if (cssMatch) {
67
- const line = uncommented.slice(0, cssMatch.index).split('\n').length;
68
- throw new Error(
69
- `Raw var(${cssMatch[1]}) without a fallback at line ${line} needs an availability check: load @astryxdesign/core/astryx.css in prebuilt mode, ensure a source-compiled dataVars consumer retains the group, or add an explicit fallback. CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex.`,
70
- );
71
- }
72
- return undefined;
73
- }
74
-
75
- const j = api.jscodeshift;
76
- const root = j(file.source);
77
- /** @type {{token: string, line: number|null}|null} */
78
- let found = null;
79
- const inspect = (/** @type {any} */ node) => {
80
- if (found) return;
81
- const value = staticString(node);
82
- const match =
83
- typeof value === 'string' ? value.match(DIRECT_DATA_VAR) : null;
84
- if (match) {
85
- found = {token: match[1], line: node.loc?.start?.line ?? null};
86
- }
87
- };
88
-
89
- /** @param {any} nodePath */
90
- const inspectPath = nodePath => inspect(nodePath.node);
91
- root.find(j.StringLiteral).forEach(inspectPath);
92
- root.find(j.Literal).forEach(inspectPath);
93
- root.find(j.TemplateLiteral).forEach(inspectPath);
94
-
95
- if (found) {
96
- const {token, line} = found;
33
+ export default function validateDataTokenOwnership(file) {
34
+ if (
35
+ path.extname(file.path) === '.css' &&
36
+ file.source.includes(GENERATED_THEME_HEADER) &&
37
+ ROOT_DATA_DECLARATION.test(file.source)
38
+ ) {
97
39
  throw new Error(
98
- `Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex and, in prebuilt mode, loads @astryxdesign/core/astryx.css; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
40
+ 'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults come from @astryxdesign/core/astryx.css in prebuilt mode, and in a source build from the @astryxdesign/build PostCSS integration or dataVars imports.',
99
41
  );
100
42
  }
101
43
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.5-canary.bc40b80",
3
+ "version": "0.7.5-canary.c60f571",
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.bc40b80",
115
- "@astryxdesign/core": "0.7.5-canary.bc40b80",
116
- "@astryxdesign/lab": "0.7.5-canary.bc40b80",
117
- "@astryxdesign/theme-neutral": "0.7.5-canary.bc40b80"
114
+ "@astryxdesign/charts": "0.7.5-canary.c60f571",
115
+ "@astryxdesign/core": "0.7.5-canary.c60f571",
116
+ "@astryxdesign/lab": "0.7.5-canary.c60f571",
117
+ "@astryxdesign/theme-neutral": "0.7.5-canary.c60f571"
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.bc40b80",
135
- "@astryxdesign/core": "0.7.5-canary.bc40b80",
136
- "@astryxdesign/lab": "0.7.5-canary.bc40b80",
137
- "@astryxdesign/theme-neutral": "0.7.5-canary.bc40b80",
134
+ "@astryxdesign/charts": "0.7.5-canary.c60f571",
135
+ "@astryxdesign/core": "0.7.5-canary.c60f571",
136
+ "@astryxdesign/lab": "0.7.5-canary.c60f571",
137
+ "@astryxdesign/theme-neutral": "0.7.5-canary.c60f571",
138
138
  "@heroicons/react": "^2.2.0",
139
139
  "@stylexjs/stylex": "^0.19.0",
140
140
  "@types/babel__core": "^7.20.5",