@astryxdesign/cli 0.7.12-canary.6718d7e → 0.7.12-canary.9a690d5

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.
@@ -473,16 +473,51 @@ export async function swizzleCopy(component, options = {}) {
473
473
  );
474
474
  }
475
475
 
476
+ // The marker tells @astryxdesign/build that the output folder holds Astryx
477
+ // source, so the copy compiles below the theme as the package does.
478
+ const markerDest = confineWrite(path.join(outputBase, SWIZZLE_MARKER), cwd, {
479
+ allowAbsolute: true,
480
+ label: 'output file',
481
+ });
482
+ const markerExisting = readExisting(markerDest);
483
+ const markerContent = swizzleMarkerContent(
484
+ markerExisting,
485
+ owner.ownerPackage,
486
+ ownerVersion,
487
+ );
488
+ // Every module under the marker compiles as Astryx source, so swizzle marks
489
+ // only a folder it owns: one the copy creates, an empty one, or one it
490
+ // marked before. Any other folder is reported with what it holds.
491
+ const foundInOutputBase =
492
+ markerExisting == null &&
493
+ fs.existsSync(outputBase) &&
494
+ fs.statSync(outputBase).isDirectory()
495
+ ? fs.readdirSync(outputBase).sort()
496
+ : [];
497
+ const marksOutputBase = foundInOutputBase.length === 0;
498
+ const writes = marksOutputBase
499
+ ? [
500
+ ...outputs,
501
+ {
502
+ dest: markerDest,
503
+ content: markerContent,
504
+ marker: true,
505
+ unchanged: markerExisting === markerContent,
506
+ },
507
+ ]
508
+ : outputs;
509
+
476
510
  const outputDirExisted = fs.existsSync(outputDir);
477
511
  /** @type {string[]} folders this run created, outermost first */
478
512
  const createdDirs = [];
479
513
  /** @type {Array<{dest: string, original: Buffer|null}>} */
480
514
  const written = [];
481
515
  let copied = 0;
482
- for (const output of outputs) {
516
+ for (const output of writes) {
517
+ const counts = !('marker' in output);
483
518
  // An identical file is already in place: it is part of this copy, unwritten.
484
519
  if (output.unchanged) {
485
- copied++;
520
+ if (counts) copied++;
486
521
  continue;
487
522
  }
488
523
  try {
@@ -491,7 +526,7 @@ export async function swizzleCopy(component, options = {}) {
491
526
  if (firstCreated != null) createdDirs.push(firstCreated);
492
527
  written.push({dest: output.dest, original});
493
528
  fs.writeFileSync(output.dest, output.content);
494
- copied++;
529
+ if (counts) copied++;
495
530
  } catch (err) {
496
531
  const unrestored = undoCopy(written);
497
532
  for (const dir of [...createdDirs].reverse()) {
@@ -516,10 +551,44 @@ export async function swizzleCopy(component, options = {}) {
516
551
  usesStyleX: outputs.some(o => o.content.includes('@stylexjs/stylex')),
517
552
  dependencies: plan.dependencies,
518
553
  };
554
+ data.marker = marksOutputBase
555
+ ? {path: toPosix(path.relative(cwd, markerDest)), written: true}
556
+ : {
557
+ path: toPosix(path.relative(cwd, markerDest)),
558
+ written: false,
559
+ found: foundInOutputBase.slice(0, 5),
560
+ };
519
561
  if (feedback) data.feedback = feedback;
520
562
  return {type: 'swizzle.copy', package: data.package, data};
521
563
  }
522
564
 
565
+ /** The file that marks a swizzle output folder as Astryx source. */
566
+ const SWIZZLE_MARKER = 'astryx-swizzle.json';
567
+
568
+ /**
569
+ * The marker's content after a copy from `ownerPackage`: the packages the
570
+ * folder's copies came from, each with its version. Unreadable content is
571
+ * replaced.
572
+ * @param {string|null} existing
573
+ * @param {string} ownerPackage
574
+ * @param {string} version
575
+ * @returns {string}
576
+ */
577
+ function swizzleMarkerContent(existing, ownerPackage, version) {
578
+ /** @type {Record<string, string>} */
579
+ let packages = {};
580
+ try {
581
+ const parsed = existing == null ? null : JSON.parse(existing);
582
+ if (parsed?.packages && typeof parsed.packages === 'object') {
583
+ packages = {...parsed.packages};
584
+ }
585
+ } catch {
586
+ // Unreadable content is rewritten below.
587
+ }
588
+ packages[ownerPackage] = version;
589
+ return `${JSON.stringify({packages}, null, 2)}\n`;
590
+ }
591
+
523
592
  /**
524
593
  * Undo the writes of a copy that failed part-way, newest first: delete the
525
594
  * files the copy created and put back the bytes of the files it replaced. A
@@ -21,8 +21,12 @@ export const doc = {
21
21
  'the owner package exports: names the package exports are imported from its ' +
22
22
  'public paths, and every internal module the component needs is ' +
23
23
  "copied beside it in the package's folder layout. Tests, stories and docs are not " +
24
- 'copied. The receipt flags whether any copied file uses StyleX and lists each npm ' +
25
- 'package the copy imports with the range the owner package declares. With no name ' +
24
+ 'copied. An output folder swizzle owns (one the copy creates, an empty one, or one it ' +
25
+ 'marked before) gets an astryx-swizzle.json marker naming each package its copies came from, ' +
26
+ "with its version, so @astryxdesign/build's Babel, PostCSS and Vite integrations, and " +
27
+ 'withAstryx() under webpack, compile the copy below the theme. The receipt flags whether ' +
28
+ 'any copied file uses StyleX and lists each npm package the copy imports with the range ' +
29
+ 'the owner package declares. With no name ' +
26
30
  '(or list) it returns the swizzlable component names instead. An integration ' +
27
31
  'component that replaces a Core component is what that Core name copies; ' +
28
32
  "options.package '@astryxdesign/core' copies the original. The list names Core " +
@@ -81,7 +85,7 @@ export const doc = {
81
85
  {
82
86
  type: 'swizzle.copy',
83
87
  description:
84
- 'A receipt after copying the component into the project: the component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder; the internal modules copied beside it start with `../`, e.g. `../InputGroup/groupStyles.ts`), whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling.',
88
+ 'A receipt after copying the component into the project: the component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder; the internal modules copied beside it start with `../`, e.g. `../InputGroup/groupStyles.ts`), whether any file uses StyleX, the npm packages the copy imports with the ranges the owner declares (dependencies), the output folder\'s astryx-swizzle.json (marker: {path, written, found?}; written is false for a folder swizzle does not own, and found names up to five entries it already holds), and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling.',
85
89
  },
86
90
  ],
87
91
  throws: [
@@ -42,6 +42,11 @@ export type SwizzleCopyResponse = {
42
42
  files: string[];
43
43
  usesStyleX: boolean;
44
44
  dependencies: Record<string, string>;
45
+ marker?: {
46
+ path: string;
47
+ written: boolean;
48
+ found?: string[];
49
+ } | undefined;
45
50
  feedback?: SwizzleFeedback | undefined;
46
51
  };
47
52
  };
@@ -37,6 +37,7 @@
37
37
  * @property {string[]} data.files Copied file names, relative to the component folder; the internal modules copied beside it start with `../` (spec:AST-110 FR2).
38
38
  * @property {boolean} data.usesStyleX Whether any copied file uses StyleX (requires build-time setup).
39
39
  * @property {Record<string, string>} data.dependencies Each npm package the copied files import, other than the owner package, with the version range the owner package declares (`*` when it declares none). The copy builds once the product installs them (spec:AST-110 FR1).
40
+ * @property {{path: string, written: boolean, found?: string[]}} [data.marker] The output folder's astryx-swizzle.json, relative to the project (spec:AST-110 FR5). Swizzle writes it only into a folder it owns: one the copy creates, an empty one, or one it marked before. When it does not, `written` is false and `found` names up to five entries already in the folder.
40
41
  * @property {SwizzleFeedback} [data.feedback]
41
42
  */
42
43
 
@@ -160,6 +160,10 @@ export const docs = {
160
160
  type: 'prose',
161
161
  text: 'If a swizzled component fails at runtime with a `stylex.create` error, the app is missing a StyleX compiler: see the StyleX Build Setup section of {@link generic:tokens-and-setup}.',
162
162
  },
163
+ {
164
+ type: 'prose',
165
+ text: '`{@command swizzle <Component>}` writes an `astryx-swizzle.json` marker into an output folder it owns (one the copy creates, an empty one, or one it marked before); every module under that folder then compiles as Astryx source, so keep copies in a folder of their own, such as the default `components/astryx`. For a folder that already holds other files it writes no marker and says how to add one by hand. With `@astryxdesign/build`\'s Babel, PostCSS and Vite integrations, or `withAstryx()` under webpack, a copy under that folder compiles into `astryx-base`, below `astryx-theme`, so theme component overrides reach it as they reach the package component. Under Turbopack, and with the stock StyleX plugins above, a copy\'s rules land in your own styles, above `astryx-theme`, and theme component overrides do not reach it.',
166
+ },
163
167
  ],
164
168
  },
165
169
  {
@@ -22,6 +22,10 @@ export const doc = {
22
22
  "is copied beside it in the package's folder layout. " +
23
23
  'Tests, stories and docs are not copied. It lists the npm packages the copy imports, ' +
24
24
  'with the ranges the owner package declares, to install if your project lacks them. ' +
25
+ 'An output folder swizzle owns (one the copy ' +
26
+ 'creates, an empty one, or one it marked before) gets an astryx-swizzle.json marker naming ' +
27
+ "each package its copies came from, so @astryxdesign/build's Babel, PostCSS and Vite " +
28
+ 'integrations, and withAstryx() under webpack, compile the copy below your theme. ' +
25
29
  'With no name it lists the swizzlable components. ' +
26
30
  'An integration component that replaces a Core component is what that Core name ' +
27
31
  'copies; --package @astryxdesign/core copies the original. --list lists Core ' +
@@ -113,6 +113,18 @@ export function registerSwizzle(program) {
113
113
  );
114
114
  }
115
115
 
116
+ const {marker} = result.data;
117
+ if (marker) {
118
+ const folder = marker.path.replace(/\/?astryx-swizzle\.json$/, '') || '.';
119
+ out.push(
120
+ text(
121
+ marker.written
122
+ ? `Marked ${folder}/ with astryx-swizzle.json: with @astryxdesign/build's Babel, PostCSS and Vite integrations, or withAstryx() under webpack, every module under it compiles below your theme, so theme overrides reach the copy. Keep only swizzled copies there. Turbopack does not read the marker yet.`
123
+ : `Did not mark ${folder}/ with astryx-swizzle.json: it already holds ${(marker.found ?? []).join(', ')} and no astryx-swizzle.json. If it holds only swizzled copies, add ${marker.path} to mark it, so theme overrides reach them; keep the product's own components out of a marked folder.`,
124
+ ),
125
+ );
126
+ }
127
+
116
128
  // StyleX build requirement — swizzled StyleX source throws on import
117
129
  // ("Unexpected 'stylex.create' call at runtime") unless the consumer's
118
130
  // build runs a StyleX compiler, so the page does not render at all.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.12-canary.6718d7e",
3
+ "version": "0.7.12-canary.9a690d5",
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",
@@ -124,7 +124,7 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/core": "0.7.12-canary.6718d7e"
127
+ "@astryxdesign/core": "0.7.12-canary.9a690d5"
128
128
  },
129
129
  "peerDependenciesMeta": {
130
130
  "@astryxdesign/core": {
@@ -132,10 +132,10 @@
132
132
  }
133
133
  },
134
134
  "devDependencies": {
135
- "@astryxdesign/charts": "0.7.12-canary.6718d7e",
136
- "@astryxdesign/core": "0.7.12-canary.6718d7e",
137
- "@astryxdesign/lab": "0.7.12-canary.6718d7e",
138
- "@astryxdesign/theme-neutral": "0.7.12-canary.6718d7e",
135
+ "@astryxdesign/charts": "0.7.12-canary.9a690d5",
136
+ "@astryxdesign/core": "0.7.12-canary.9a690d5",
137
+ "@astryxdesign/lab": "0.7.12-canary.9a690d5",
138
+ "@astryxdesign/theme-neutral": "0.7.12-canary.9a690d5",
139
139
  "@heroicons/react": "^2.2.0",
140
140
  "@stylexjs/stylex": "^0.19.0",
141
141
  "@types/babel__core": "^7.20.5",