Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): verify ignores the command a built theme module says built it (#10344)

Joey64143c6f0e0c
diff --git a/.changeset/verify-built-by-command.md b/.changeset/verify-built-by-command.md
new file mode 100644
index 0000000000..41671ada25
--- /dev/null
+++ b/.changeset/verify-built-by-command.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx integration verify` no longer reports `theme_module_stale` for a theme whose built module differs only in the command its comment says built it, such as a theme built with `yarn astryx` and verified where `pnpm exec astryx` runs. Any other difference still fails.
+@josephfarina
diff --git a/packages/cli/api/integration/pack-check.mjs b/packages/cli/api/integration/pack-check.mjs
index 3118e84439..5f4af38796 100644
--- a/packages/cli/api/integration/pack-check.mjs
+++ b/packages/cli/api/integration/pack-check.mjs
@@ -99,14 +99,20 @@ const GENERATED_HEADER_LINE =
const SOURCE_LINE = /^( \* Source: )(\S(?:.*\S)?)(\s*)$/u;
const CLI_VERSION_LINE = /^( \* CLI: @astryxdesign\/cli@)(\S+)(\s*)$/u;
const CORE_VERSION_LINE = /^( \* Core: @astryxdesign\/core@)(\S+)(\s*)$/u;
+// The built module's own doc comment names the command that built it, which
+// depends on the package manager and host that ran the build.
+const BUILT_BY_LINE =
+ /^( \* \S(?:.*\S)? theme — built by `)(\S(?:.*\S)?)( theme build`)(\s*)$/u;
/**
- * Compare generated theme outputs without making their build directory or
- * CLI/Core version look like source drift. Normalization applies only to the
- * first generated JS or CSS comment and only when it contains exactly one
- * well-formed Source, CLI, and Core line. Missing, duplicate, malformed,
- * reordered, or any other bytes stay significant. `theme build --check`
- * deliberately stays strict.
+ * Compare generated theme outputs without making their build directory,
+ * CLI/Core version, or build command look like source drift. Normalization
+ * applies only to a file whose first comment is the generated header with
+ * exactly one well-formed Source, CLI, and Core line; it covers those lines
+ * and, in a built module, the one `built by` line that names the command
+ * (`yarn astryx`, `pnpm exec astryx`, or a host's own). Missing, duplicate,
+ * malformed, reordered, or any other bytes stay significant. `theme build
+ * --check` deliberately stays strict.
* @param {string} content
*/
export function normalizeThemeVerifyForCompare(content) {
@@ -125,8 +131,12 @@ export function normalizeThemeVerifyForCompare(content) {
if (source.length !== 1 || cli.length !== 1 || core.length !== 1) {
return normalized;
}
+ const builtBy = lines.filter(line => BUILT_BY_LINE.test(line)).length;
return lines
.map((line, index) => {
+ if (builtBy === 1 && BUILT_BY_LINE.test(line)) {
+ return line.replace(BUILT_BY_LINE, '$1<command>$3$4');
+ }
if (index >= close) return line;
if (SOURCE_LINE.test(line)) {
return line.replace(SOURCE_LINE, '$1<source>$3');
diff --git a/packages/cli/api/integration/pack-check.test.mjs b/packages/cli/api/integration/pack-check.test.mjs
index fe6883e31e..a48254fa2d 100644
--- a/packages/cli/api/integration/pack-check.test.mjs
+++ b/packages/cli/api/integration/pack-check.test.mjs
@@ -64,6 +64,68 @@ ${body}
`;
}
+describe('verify-only built-by command normalization', () => {
+ /** A built module as `theme build` writes it, by one package manager. */
+ const builtModule = (/** @type {string} */ command, slug = 'terminal') =>
+ generatedJsArtifact({
+ source: `themes/${slug}/${slug}Theme.ts`,
+ body: `/**
+ * ${slug} theme — built by \`${command} theme build\`
+ * Import the CSS file alongside this module:
+ */
+export const ${slug}Theme = {name: '${slug}'};`,
+ });
+
+ // Two published theme packages, "terminal" and "xtra-professional", were
+ // built with yarn; verify under pnpm rebuilt each byte for byte except this
+ // line and reported theme_module_stale.
+ it.each(['terminal', 'xtra-professional'])(
+ 'treats the %s module built by yarn as the module built by pnpm',
+ slug => {
+ expect(
+ normalizeThemeVerifyForCompare(builtModule('yarn astryx', slug)),
+ ).toBe(
+ normalizeThemeVerifyForCompare(builtModule('pnpm exec astryx', slug)),
+ );
+ expect(
+ normalizeThemeVerifyForCompare(builtModule('npx astryx', slug)),
+ ).toBe(
+ normalizeThemeVerifyForCompare(builtModule('acme astryx', slug)),
+ );
+ expect(
+ normalizeThemeBuildForCompare(builtModule('yarn astryx', slug)),
+ ).not.toBe(
+ normalizeThemeBuildForCompare(builtModule('pnpm exec astryx', slug)),
+ );
+ },
+ );
+
+ it.each([
+ [
+ 'theme name on the built-by line',
+ source => source.replace('terminal theme — built', 'reef theme — built'),
+ ],
+ [
+ 'second built-by line',
+ source =>
+ source.replace(
+ ' * Import the CSS',
+ ' * terminal theme — built by `npm astryx theme build`\n * Import the CSS',
+ ),
+ ],
+ [
+ 'built-by line without the generated header',
+ source => source.replace('@generated by', '@generated with'),
+ ],
+ ])('keeps a %s significant', (_label, mutate) => {
+ const yarn = builtModule('yarn astryx');
+ const pnpm = builtModule('pnpm exec astryx');
+ expect(normalizeThemeVerifyForCompare(mutate(yarn))).not.toBe(
+ normalizeThemeVerifyForCompare(pnpm),
+ );
+ });
+});
+
describe('verify-only generated CSS header normalization', () => {
it('ignores one source path and exact version pair but leaves build --check strict', () => {
const current = generatedCssArtifact();