Skip to content

Commit 7ec5770

Browse files
The tarball IO honors the sandboxDir it is handed
Per-package sandboxes exposed a latent bug: realTarballIo ignored the sandboxDir argument, always installing into one fixed directory and reading the started package's name back from it. With two sandboxes, startBin looked for node_modules in directories nothing had installed into, and both bins reported exit null. installSandbox now creates the directory it was asked for (fresh each time) and startBin reads the manifest from the same directory it starts in. Also hoists the sandbox name regexes and de-nests a test ternary, per lint. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent dd09c89 commit 7ec5770

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

packages/cli-conformance/src/checks/tarball.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export interface TarballInput {
106106

107107
const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
108108

109+
/** Package-name characters that cannot appear in a directory name. */
110+
const SANDBOX_NAME_UNSAFE = /[@/]/g;
111+
const LEADING_DASH = /^-/;
112+
109113
/**
110114
* Check 3: the tarballs a registry would receive. 3a — packed output
111115
* imports only what the packed manifest declares. 3b — the root tarball
@@ -306,7 +310,7 @@ async function sandboxFindings(
306310
): Promise<readonly Finding[]> {
307311
const sandboxDir = join(
308312
input.sandboxDir,
309-
packageName.replace(/[@/]/g, "-").replace(/^-/, ""),
313+
packageName.replace(SANDBOX_NAME_UNSAFE, "-").replace(LEADING_DASH, ""),
310314
);
311315
// Transitive: a sibling reached only through another sibling still
312316
// needs its override, or the install falls back to the registry.

packages/cli-conformance/src/tarball-io.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export function realTarballIo(
3838
// exact files CI uploads and attaches to the GitHub Release.
3939
const tarballDir = resolve(options.tarballDir ?? join(absWork, "tarballs"));
4040
rmSync(tarballDir, { recursive: true, force: true });
41-
const sandbox = () => join(absWork, "sandbox");
4241

4342
return {
4443
async pack(pkgDir) {
@@ -88,8 +87,9 @@ export function realTarballIo(
8887
return files;
8988
},
9089

91-
async installSandbox({ rootTarball, overrides }) {
92-
const dir = sandbox();
90+
async installSandbox({ sandboxDir, rootTarball, overrides }) {
91+
const dir = resolve(sandboxDir);
92+
rmSync(dir, { recursive: true, force: true });
9393
mkdirSync(dir, { recursive: true });
9494
const rootManifest = await this.readPackedManifest(rootTarball);
9595
const name = manifestName(rootManifest);
@@ -176,7 +176,7 @@ export function realTarballIo(
176176
argv,
177177
timeoutMs,
178178
}) {
179-
const rootManifestPath = join(sandbox(), "package.json");
179+
const rootManifestPath = join(sandboxDir, "package.json");
180180
const rootManifest = JSON.parse(
181181
readFileSync(rootManifestPath, "utf8"),
182182
) as {

packages/cli-conformance/tests/tarball.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,15 @@ describe("sibling manifests and per-package sandboxes (the rc.8 class)", () => {
616616
overrides: Partial<TarballIo> = {},
617617
): TarballIo {
618618
return fakeIo({
619-
readPackedManifest: (tarball) =>
620-
Promise.resolve(
621-
tarball.includes("cli-engine")
622-
? ENGINE_MANIFEST
623-
: tarball.includes("prisma-wrapper")
624-
? wrapperManifest
625-
: SHELL_MANIFEST,
626-
),
619+
readPackedManifest: (tarball) => {
620+
if (tarball.includes("cli-engine")) {
621+
return Promise.resolve(ENGINE_MANIFEST);
622+
}
623+
if (tarball.includes("prisma-wrapper")) {
624+
return Promise.resolve(wrapperManifest);
625+
}
626+
return Promise.resolve(SHELL_MANIFEST);
627+
},
627628
readPackedFiles: (tarball) =>
628629
Promise.resolve(
629630
tarball.includes("prisma-wrapper")

0 commit comments

Comments
 (0)