Skip to content

Commit c380e86

Browse files
authored
Merge branch 'main' into uikit/f1-copy-test-entrances-outlast-setup
2 parents 89b8b6e + 9a4627b commit c380e86

28 files changed

Lines changed: 2012 additions & 161 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[perf] A standalone `astryx theme build` against the current Core loads Core's root entry only when the theme imports it. A theme that imports only `@astryxdesign/core/theme` no longer loads all of Core and its components. Family builds and builds against an older Core still load the root. Some builds hand the theme its Core: family builds, builds against an older Core, and themes whose folder has no Core. There, a theme that imports a Core root `require()` cannot load, such as one that awaits at its top level, fails with `ERR_THEME_LOAD`. The error names that root.
6+
7+
@vjeux
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[perf] Under a finger, the touch-inset pass of a Switch or InfoTip resolves a control's style only when a transform scales it.
6+
7+
@vjeux

‎.github/actions/test-scope/action.yml‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ runs:
206206
'.github/scripts/knowledge-paths.cjs',
207207
'scripts/component-packages.cjs',
208208
...(audit ? ['.github/scripts/component-audit-scope.cjs'] : []),
209+
// Data, not code: the Lab entry check reads the base's copy.
210+
'packages/cli/assets/discover/official-packages.json',
209211
];
212+
const optionalPolicy = new Set(['packages/cli/assets/discover/official-packages.json']);
210213
const {repository} = await github.graphql(
211214
`query($owner: String!, $repo: String!, ${policy.map((_, i) => `$f${i}: String!`).join(', ')}) {
212215
repository(owner: $owner, name: $repo) {
@@ -217,6 +220,8 @@ runs:
217220
);
218221
for (const [i, file] of policy.entries()) {
219222
const blob = repository?.[`f${i}`];
223+
// A missing data file only keeps the change out of the Lab-only lane.
224+
if (optionalPolicy.has(file) && (typeof blob?.text !== 'string' || blob.isTruncated)) continue;
220225
if (typeof blob?.text !== 'string' || blob.isTruncated) throw new Error(`the base has no readable ${file}`);
221226
fs.mkdirSync(path.join(root, path.dirname(file)), {recursive: true});
222227
fs.writeFileSync(path.join(root, file), blob.text);
@@ -235,8 +240,21 @@ runs:
235240
.join('\n');
236241
const outputFile = path.join(root, 'classification');
237242
fs.writeFileSync(outputFile, '');
243+
// GitHub's patch text for the Lab entry files, handed over as data:
244+
// the classifier reads it and never runs it. GitHub leaves out the
245+
// patch of a large diff; such a file then keeps full CI.
246+
const LAB_ENTRY = /^(internal\/shadcn-registry\/routes\.lock\.json|packages\/cli\/assets\/discover\/official-packages\.json|apps\/storybook\/stories\/[A-Z][A-Za-z0-9]*\.stories\.tsx)$/;
247+
const patchesFile = path.join(root, 'lab-entry-patches.json');
248+
fs.writeFileSync(patchesFile, JSON.stringify(Object.fromEntries(
249+
files.filter(f => LAB_ENTRY.test(f.filename)).map(f => [f.filename, typeof f.patch === 'string' ? f.patch : null]),
250+
)));
238251
try {
239-
execFileSync('node', [path.join(root, '.github/scripts/change-scope.cjs'), '--github-output'], {
252+
execFileSync('node', [
253+
path.join(root, '.github/scripts/change-scope.cjs'),
254+
'--github-output',
255+
'--patches', patchesFile,
256+
'--official-packages-base', path.join(root, 'packages/cli/assets/discover/official-packages.json'),
257+
], {
240258
input: `${nameStatus}\n`,
241259
env: {...process.env, GITHUB_OUTPUT: outputFile},
242260
stdio: ['pipe', 'inherit', 'inherit'],

‎.github/scripts/change-scope.cjs‎

Lines changed: 204 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const {
1111
} = require('./knowledge-paths.cjs');
1212

1313
/**
14-
* Classifies changed paths without reading PR-controlled content.
14+
* Classifies changed paths. It reads no pull-request content as code: the
15+
* only content it reads is GitHub's patch text for a Lab component's three
16+
* entry files, as data (spec:AST-030 FR26).
1517
*
1618
* A spec-only PR may change only spec records. Templates, schemas, indexes,
1719
* architecture, guidance, audits, workflows, and code deliberately do not
@@ -31,6 +33,152 @@ const CHANGESET_PATTERN = /^\.changeset\/(?!README\.md$)[^/]+\.md$/;
3133
// runs the Lab tests and the Storybook build (spec:AST-030 FR26).
3234
const LAB_ROOT = 'packages/lab/';
3335

36+
// A new Lab component also adds its routes, its CLI discovery entry and its
37+
// Storybook story. These three files still count toward a Lab-only change when
38+
// their diff names only Lab components the change itself carries. The diff is
39+
// read as data (GitHub's patch text, never run); a missing patch, or any line
40+
// the checks do not recognize, keeps the change out of the Lab-only lane.
41+
const ROUTES_LOCK = 'internal/shadcn-registry/routes.lock.json';
42+
const OFFICIAL_PACKAGES = 'packages/cli/assets/discover/official-packages.json';
43+
const LAB_STORY =
44+
/^apps\/storybook\/stories\/([A-Z][A-Za-z0-9]*)\.stories\.tsx$/;
45+
const LAB_COMPONENT_DIR = /^packages\/lab\/src\/([A-Z][A-Za-z0-9]*)\//;
46+
47+
// The registry's route slug for a component name. It mirrors
48+
// slugifyRegistryName in apps/docsite/src/lib/shadcnRegistry.mjs (a test pins
49+
// the two equal): the trusted classifier loads no docsite module.
50+
function labRouteSlug(name) {
51+
return String(name)
52+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
53+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
54+
.replace(/[^a-zA-Z0-9]+/g, '-')
55+
.replace(/^-+|-+$/g, '')
56+
.toLowerCase();
57+
}
58+
59+
// The changed lines of a unified diff, without the file headers.
60+
function changedLines(patch) {
61+
return patch
62+
.split('\n')
63+
.filter(line => /^[+-]/.test(line) && !/^(\+\+\+|---) /.test(line))
64+
.map(line => ({
65+
sign: line[0],
66+
text: line.slice(1).trim().replace(/,$/, ''),
67+
}));
68+
}
69+
70+
function routesLockNamesLabOnly(patch, slugs) {
71+
const ownSlug = value =>
72+
[...slugs].some(
73+
slug =>
74+
value === `components/lab/${slug}` ||
75+
value.startsWith(`examples/${slug}/`) ||
76+
value.startsWith(`showcases/${slug}/`),
77+
);
78+
const ownName = value =>
79+
[...slugs].some(
80+
slug =>
81+
value === `component-lab-${slug}` ||
82+
value.startsWith(`example-${slug}-`) ||
83+
value.startsWith(`showcase-${slug}-`),
84+
);
85+
const lines = changedLines(patch);
86+
return (
87+
lines.length > 0 &&
88+
lines.every(({text}) => {
89+
if (['{', '}', ']', '"aliases": []', '"aliases": ['].includes(text))
90+
return true;
91+
const name = /^"name": "([^"]+)"$/.exec(text);
92+
if (name) return ownName(name[1]);
93+
const route = /^"path": "([^"]+)"$/.exec(text);
94+
if (route) return ownSlug(route[1]);
95+
const alias = /^"([^"]+)"$/.exec(text);
96+
return (
97+
alias != null &&
98+
/^components\/lab\//.test(alias[1]) &&
99+
ownSlug(alias[1])
100+
);
101+
})
102+
);
103+
}
104+
105+
// The Lab package's line range in the base's official-packages.json.
106+
function labPackageLines(baseText) {
107+
const lines = baseText.split('\n');
108+
const start = lines.findIndex(line =>
109+
line.includes('"package": "@astryxdesign/lab"'),
110+
);
111+
if (start === -1) return null;
112+
const next = lines.findIndex(
113+
(line, index) => index > start && line.includes('"package": "'),
114+
);
115+
return {first: start + 1, last: next === -1 ? lines.length : next};
116+
}
117+
118+
function officialPackagesNamesLabOnly(patch, names, baseText) {
119+
if (typeof baseText !== 'string') return false;
120+
const range = labPackageLines(baseText);
121+
if (range == null) return false;
122+
const hunks = [
123+
...patch.matchAll(/^@@ -(\d+)(?:,(\d+))? \+\d+(?:,\d+)? @@/gm),
124+
];
125+
if (hunks.length === 0) return false;
126+
// Every hunk edits inside the Lab package's entry of the base file.
127+
const inLab = hunks.every(([, start, count = '1']) => {
128+
const first = Number(start);
129+
const last = first + Math.max(Number(count), 1) - 1;
130+
return first > range.first && last < range.last;
131+
});
132+
const lines = changedLines(patch);
133+
return (
134+
inLab &&
135+
lines.length > 0 &&
136+
lines.every(({text}) => {
137+
if (['{', '}', '"kind": "component"'].includes(text)) return true;
138+
const name = /^"name": "([^"]+)"$/.exec(text);
139+
return name != null && names.has(name[1]);
140+
})
141+
);
142+
}
143+
144+
function storyImportsLab(patch) {
145+
const added = patch
146+
.split('\n')
147+
.filter(line => line.startsWith('+') && !line.startsWith('+++ '))
148+
.map(line => line.slice(1))
149+
.join('\n');
150+
return /from '@astryxdesign\/lab(?:\/[^']*)?';/.test(added);
151+
}
152+
153+
/**
154+
* Whether a Lab entry file's change belongs to the Lab components this change
155+
* carries (spec:AST-030 FR26). `names` are the Lab component folders the change
156+
* touches; `patches` maps a path to GitHub's patch text; `officialPackagesBase`
157+
* is the base's official-packages.json.
158+
*/
159+
function isLabEntryChange(change, {names, patches, officialPackagesBase}) {
160+
const patch = patches?.[change.filename];
161+
if (
162+
typeof patch !== 'string' ||
163+
patch === '' ||
164+
change.previous_filename != null
165+
)
166+
return false;
167+
const slugs = new Set([...names].map(labRouteSlug));
168+
if (change.filename === ROUTES_LOCK)
169+
return routesLockNamesLabOnly(patch, slugs);
170+
if (change.filename === OFFICIAL_PACKAGES)
171+
return officialPackagesNamesLabOnly(patch, names, officialPackagesBase);
172+
const story = LAB_STORY.exec(change.filename);
173+
// Only a new story: its whole text is in the patch.
174+
return (
175+
story != null &&
176+
change.status === 'A' &&
177+
names.has(story[1]) &&
178+
storyImportsLab(patch)
179+
);
180+
}
181+
34182
const SURFACES = Object.freeze({
35183
KNOWLEDGE: 'knowledge',
36184
DOCSITE: 'docsite',
@@ -175,7 +323,10 @@ function normalizeChange(change) {
175323
};
176324
}
177325

178-
function classifyChanges(changes, {expectedCount} = {}) {
326+
function classifyChanges(
327+
changes,
328+
{expectedCount, patches = null, officialPackagesBase = null} = {},
329+
) {
179330
const normalized = changes
180331
.map(normalizeChange)
181332
.filter(change => change.filename);
@@ -239,16 +390,42 @@ function classifyChanges(changes, {expectedCount} = {}) {
239390
const docsiteOnly = exactSurface(SURFACES.DOCSITE);
240391
const toolingOnly = exactSurface(SURFACES.NODE_TOOLING);
241392
// Every changed path is in the Lab package, besides Changesets, which no
242-
// test or build reads (spec:AST-030 FR26).
393+
// test or build reads, and the Lab entry files of the Lab components the
394+
// change carries (spec:AST-030 FR26).
395+
const labNames = new Set(
396+
allPaths.flatMap(filePath => {
397+
const match = LAB_COMPONENT_DIR.exec(filePath);
398+
return match ? [match[1]] : [];
399+
}),
400+
);
401+
const labEntries = new Set(
402+
normalized
403+
.filter(change =>
404+
isLabEntryChange(change, {
405+
names: labNames,
406+
patches,
407+
officialPackagesBase,
408+
}),
409+
)
410+
.map(change => change.filename),
411+
);
243412
const labOnly =
244413
complete &&
245414
allPaths.some(filePath => filePath.startsWith(LAB_ROOT)) &&
246415
allPaths.every(
247416
filePath =>
248-
filePath.startsWith(LAB_ROOT) || CHANGESET_PATTERN.test(filePath),
417+
filePath.startsWith(LAB_ROOT) ||
418+
CHANGESET_PATTERN.test(filePath) ||
419+
labEntries.has(filePath),
420+
);
421+
// An incomplete list, or any shared infrastructure, runs everything. A Lab
422+
// entry file of a Lab-only change is not shared infrastructure for it.
423+
const fullSuite =
424+
!complete ||
425+
allPaths.some(
426+
filePath =>
427+
isSharedInfraPath(filePath) && !(labOnly && labEntries.has(filePath)),
249428
);
250-
// An incomplete list, or any shared infrastructure, runs everything.
251-
const fullSuite = !complete || allPaths.some(isSharedInfraPath);
252429
return {
253430
specOnly,
254431
toolingOnly,
@@ -324,7 +501,23 @@ if (require.main === module) {
324501
.filter(Boolean);
325502
process.stdout.write(`${JSON.stringify(classifyPaths(paths))}\n`);
326503
} else {
327-
const result = classifyChanges(parseNameStatus(fs.readFileSync(0, 'utf8')));
504+
// `--patches <file>`: GitHub's patch text per path, as JSON, for the Lab
505+
// entry files. `--official-packages-base <file>`: the base's copy.
506+
const flag = name => {
507+
const index = process.argv.indexOf(name);
508+
return index === -1 ? null : process.argv[index + 1];
509+
};
510+
const readJson = file =>
511+
file ? JSON.parse(fs.readFileSync(file, 'utf8')) : null;
512+
const readText = file =>
513+
file && fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
514+
const result = classifyChanges(
515+
parseNameStatus(fs.readFileSync(0, 'utf8')),
516+
{
517+
patches: readJson(flag('--patches')),
518+
officialPackagesBase: readText(flag('--official-packages-base')),
519+
},
520+
);
328521
if (result.specChangesetConflict) {
329522
console.error(
330523
'Pure spec-record changes must not add a Changeset; they do not release packages.',
@@ -346,6 +539,8 @@ if (require.main === module) {
346539

347540
module.exports = {
348541
LAB_ROOT,
542+
OFFICIAL_PACKAGES,
543+
ROUTES_LOCK,
349544
NODE_TOOLING_PATHS,
350545
SURFACES,
351546
classifyChanges,
@@ -354,6 +549,8 @@ module.exports = {
354549
isNodeToolingPath,
355550
isPackageReleasePath,
356551
isSharedInfraPath,
552+
isLabEntryChange,
357553
isSpecRecordPath,
554+
labRouteSlug,
358555
parseNameStatus,
359556
};

0 commit comments

Comments
 (0)