Skip to content

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

TypeScript

fix(scripts): don't promote an empty codemod stage into a version tier (#5037)

Cindy Zhang3af4a2a544be
diff --git a/scripts/promote-codemod-next.mjs b/scripts/promote-codemod-next.mjs
index 20fd4f82cf..7412889419 100755
--- a/scripts/promote-codemod-next.mjs
+++ b/scripts/promote-codemod-next.mjs
@@ -44,6 +44,24 @@ function listPromotableEntries(nextDir) {
});
}
+/**
+ * Is `next/` effectively empty?
+ *
+ * Every release re-seeds the folder with an `index.mjs` exporting an empty
+ * array, so "nothing staged" is not "no entries" — it is "nothing but that
+ * placeholder manifest". Without this, a release that ships no codemods
+ * promotes the placeholder into `v{VERSION}/` and registers a tier holding no
+ * transforms.
+ */
+function isEmptyStage(nextDir, entries) {
+ if (entries.length === 0) return true;
+ if (entries.length > 1) return false;
+ const [only] = entries;
+ if (!only.isFile() || only.name !== INDEX) return false;
+ const src = fs.readFileSync(path.join(nextDir, only.name), 'utf8');
+ return /export\s+default\s*\[\s*\]\s*;/.test(src);
+}
+
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
@@ -212,7 +230,7 @@ export async function promoteCodemodNext({root = DEFAULT_ROOT} = {}) {
const nextDir = path.join(transformsDir, 'next');
const entries = listPromotableEntries(nextDir);
- if (entries.length === 0) {
+ if (isEmptyStage(nextDir, entries)) {
return {
promoted: [],
registryUpdated: false,
diff --git a/scripts/promote-codemod-next.test.mjs b/scripts/promote-codemod-next.test.mjs
index b311f292a1..f01c0190ec 100644
--- a/scripts/promote-codemod-next.test.mjs
+++ b/scripts/promote-codemod-next.test.mjs
@@ -58,6 +58,31 @@ describe('promoteCodemodNext', () => {
expect(result.message).toContain('no staged codemods');
});
+ it('does nothing when next/ holds only the re-seeded empty manifest', async () => {
+ // The state every release leaves behind: README + an index.mjs exporting
+ // []. A release with no codemods must not promote that placeholder into a
+ // version folder or register a tier with no transforms.
+ const {root, transforms} = scaffold({version: '0.4.1'});
+ fs.writeFileSync(path.join(transforms, 'next', 'README.md'), '# Next\n');
+ fs.writeFileSync(
+ path.join(transforms, 'next', 'index.mjs'),
+ '// Copyright (c) Meta Platforms, Inc. and affiliates.\n\nexport default [];\n',
+ );
+
+ const result = await promoteCodemodNext({root});
+
+ expect(result.promoted).toEqual([]);
+ expect(result.registryUpdated).toBe(false);
+ expect(result.message).toContain('no staged codemods');
+ expect(fs.existsSync(path.join(transforms, 'v0.4.1'))).toBe(false);
+ expect(
+ fs.readFileSync(
+ path.join(root, 'packages/cli/assets/codemods/registry.mjs'),
+ 'utf8',
+ ),
+ ).not.toContain('0.4.1');
+ });
+
it('promotes staged files into the current package version and registers it', async () => {
const {root, transforms} = scaffold({version: '0.4.0'});
fs.writeFileSync(path.join(transforms, 'next', 'README.md'), '# Next\n');