Skip to content

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

TypeScript

test(shadcn-registry): ShadCN's temporary directories stay in the consumer project (#9223)

Christopher Chedeau6224efd251c4
diff --git a/internal/shadcn-registry/generate-shadcn-registry.test.mjs b/internal/shadcn-registry/generate-shadcn-registry.test.mjs
index 7a67b12b70..1aecf90ddd 100644
--- a/internal/shadcn-registry/generate-shadcn-registry.test.mjs
+++ b/internal/shadcn-registry/generate-shadcn-registry.test.mjs
@@ -4,6 +4,9 @@
* @file Registry serializer contract tests.
* @input Minimal component, block, page, and StyleX fixtures.
* @output Regression coverage for schema, package boundaries, names, and output.
+ * The stock-ShadCN cases leave nothing in the system temporary directory:
+ * ShadCN's own scratch directories stay in each consumer project, and the
+ * no-op package managers are removed after the file.
* @position Node test lane for ShadCN compatibility.
*/
@@ -22,7 +25,7 @@ import {tmpdir} from 'node:os';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {promisify} from 'node:util';
-import {describe, expect, it} from 'vitest';
+import {afterAll, describe, expect, it} from 'vitest';
import {reconcileRegistryCompositions} from '../../packages/cli/api/upgrade/registry/registry.mjs';
import {
createShadcnPrecompiledDeclaration,
@@ -79,6 +82,17 @@ const SHADCN_ENV = {
...process.env,
PATH: `${NOOP_PACKAGE_MANAGERS}${path.delimiter}${process.env.PATH ?? ''}`,
};
+afterAll(() => {
+ rmSync(NOOP_PACKAGE_MANAGERS, {recursive: true, force: true});
+});
+
+// ShadCN leaves an empty temporary directory behind for every file it
+// transforms, so it gets a TMPDIR inside the project, which each test removes.
+function shadcnEnv(project) {
+ const scratch = path.join(project, '.tmp');
+ mkdirSync(scratch, {recursive: true});
+ return {...SHADCN_ENV, TMPDIR: scratch};
+}
const packages = [
{
@@ -618,7 +632,7 @@ describe('buildShadcnRegistry', () => {
await execFileAsync(
process.execPath,
[SHADCN_ENTRY, 'add', itemPath, '--yes'],
- {cwd: project, timeout: 30_000, env: SHADCN_ENV},
+ {cwd: project, timeout: 30_000, env: shadcnEnv(project)},
);
expect(
@@ -711,7 +725,7 @@ describe('buildShadcnRegistry', () => {
await execFileAsync(
process.execPath,
[SHADCN_ENTRY, 'add', itemPath, '--yes'],
- {cwd: project, timeout: 30_000, env: SHADCN_ENV},
+ {cwd: project, timeout: 30_000, env: shadcnEnv(project)},
);
const sourcePath = path.join(
@@ -792,7 +806,7 @@ describe('buildShadcnRegistry', () => {
await execFileAsync(
process.execPath,
[SHADCN_ENTRY, 'add', itemPath, '--yes'],
- {cwd: project, timeout: 30_000, env: SHADCN_ENV},
+ {cwd: project, timeout: 30_000, env: shadcnEnv(project)},
);
await new Promise((resolve, reject) => {
server.once('error', reject);
@@ -941,7 +955,7 @@ describe('buildShadcnRegistry', () => {
await execFileAsync(
process.execPath,
[SHADCN_ENTRY, 'add', itemPath, '--yes'],
- {cwd: project, timeout: 30_000, env: SHADCN_ENV},
+ {cwd: project, timeout: 30_000, env: shadcnEnv(project)},
);
expect(
@@ -1022,7 +1036,7 @@ describe('buildShadcnRegistry', () => {
cwd: project,
timeout: 30_000,
env: {
- ...SHADCN_ENV,
+ ...shadcnEnv(project),
NO_PROXY: '127.0.0.1,localhost',
no_proxy: '127.0.0.1,localhost',
},
diff --git a/internal/shadcn-registry/verify-full-catalog.mjs b/internal/shadcn-registry/verify-full-catalog.mjs
index 303ad11ecc..7f2060af4d 100644
--- a/internal/shadcn-registry/verify-full-catalog.mjs
+++ b/internal/shadcn-registry/verify-full-catalog.mjs
@@ -7,6 +7,8 @@
* ShadCN client in TypeScript and JavaScript modes, verifies exact written
* bytes and dependencies, then compiles every installed source file against
* current local exports or the exact published packages named by production.
+ * ShadCN's own scratch directories stay inside each consumer, which is
+ * removed afterwards.
* @input A generated preview or hidden production registry under
* apps/docsite/public/shadcn.
* @output A clean-consumer proof for every canonical item and alias route.
@@ -449,13 +451,17 @@ function runShadcn(project, itemPaths) {
if (!fs.existsSync(SHADCN_BIN)) {
fail('the pinned ShadCN binary is not installed');
}
+ // ShadCN leaves an empty temporary directory behind for every file it
+ // transforms: keep them inside the consumer, which main() removes.
+ const scratch = path.join(project, '.tmp');
+ fs.mkdirSync(scratch, {recursive: true});
const result = spawnSync(
SHADCN_BIN,
['add', ...itemPaths, '--yes', '--overwrite', '--silent'],
{
cwd: project,
encoding: 'utf8',
- env: {...process.env, CI: 'true'},
+ env: {...process.env, CI: 'true', TMPDIR: scratch},
maxBuffer: MAX_COMMAND_OUTPUT,
timeout: 10 * 60_000,
},