diff --git a/packages/plugin-cli/src/archive.ts b/packages/plugin-cli/src/archive.ts index 8fbcb5e82..037a6dbbf 100644 --- a/packages/plugin-cli/src/archive.ts +++ b/packages/plugin-cli/src/archive.ts @@ -126,7 +126,12 @@ async function scanPackageDirectory( for await (const entry of await opendir(directory)) entries.push(entry); entries.sort((left, right) => Buffer.compare(Buffer.from(left.name), Buffer.from(right.name))); for (const entry of entries) { - if (IGNORED_ROOT_ENTRIES.has(entry.name) || entry.name.endsWith(".ncpkg")) continue; + if ( + relativeDirectory === "" + && (IGNORED_ROOT_ENTRIES.has(entry.name) || entry.name.endsWith(".ncpkg")) + ) { + continue; + } const relativePath = relativeDirectory ? `${relativeDirectory}/${entry.name}` : entry.name; diff --git a/packages/plugin-cli/src/cli.test.ts b/packages/plugin-cli/src/cli.test.ts index db6a91174..afcc89bbc 100644 --- a/packages/plugin-cli/src/cli.test.ts +++ b/packages/plugin-cli/src/cli.test.ts @@ -229,6 +229,30 @@ test("packer rejects symbolic links and undeclared executables", async (context) ); }); +test("packer ignores root dev artifacts without dropping nested runtime dependencies", async (context) => { + const root = await mkdtemp(path.join(tmpdir(), "netcatty-plugin-runtime-deps-")); + context.after(() => rm(root, { recursive: true, force: true })); + const directory = await createPlugin(root); + await Promise.all([ + mkdir(path.join(directory, "node_modules/dev-only"), { recursive: true }), + mkdir(path.join(directory, "dist/node_modules/runtime-dependency"), { recursive: true }), + ]); + await Promise.all([ + writeFile(path.join(directory, "node_modules/dev-only/index.js"), "dev only\n"), + writeFile( + path.join(directory, "dist/node_modules/runtime-dependency/index.js"), + "export const runtime = true;\n", + ), + ]); + const packagePath = path.join(root, "runtime-deps.ncpkg"); + + const build = await buildPluginPackage(directory, packagePath); + const validation = await validatePluginPackage(packagePath); + + assert.equal(build.fileCount, 4); + assert.equal(validation.fileCount, 4); +}); + test("manifest byte limit is enforced before JSON parsing", async (context) => { const root = await mkdtemp(path.join(tmpdir(), "netcatty-plugin-limit-")); context.after(() => rm(root, { recursive: true, force: true }));