Skip to content

Commit

Permalink
fix: .npmignore should ignore files relative to the root (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Mar 26, 2024
1 parent 0b68a1e commit 9f3ec7a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 115 deletions.
24 changes: 13 additions & 11 deletions lib/npm_ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,31 @@ function runTest(options: {
assertEquals(fileText, getExpectedText());

function getExpectedText() {
let startText = options.expectHasSrcFolder ? "src/\n" : "";
let startText = options.expectHasSrcFolder ? "/src/\n" : "";
if (options.includeEsModule !== false) {
startText += "esm/mod.test.js\n";
startText += options.sourceMaps === true ? "esm/mod.test.js.map\n" : "";
startText += "/esm/mod.test.js\n";
if (options.sourceMaps === true) {
startText += "/esm/mod.test.js.map\n";
}
if (options.declaration === "inline") {
startText += "esm/mod.test.d.ts\n";
startText += "/esm/mod.test.d.ts\n";
}
}
if (options.includeScriptModule !== false) {
startText += "script/mod.test.js\n";
startText += options.sourceMaps === true
? "script/mod.test.js.map\n"
: "";
startText += "/script/mod.test.js\n";
if (options.sourceMaps === true) {
startText += "/script/mod.test.js.map\n";
}
if (options.declaration === "inline") {
startText += "script/mod.test.d.ts\n";
startText += "/script/mod.test.d.ts\n";
}
}
if (options.declaration === "separate") {
startText += "types/mod.test.d.ts\n";
startText += "/types/mod.test.d.ts\n";
}

return startText +
`test_runner.js
`/test_runner.js
yarn.lock
pnpm-lock.yaml
`;
Expand Down
14 changes: 7 additions & 7 deletions lib/npm_ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getNpmIgnoreText(options: {
// to exclude something, but then the output directory still has that file
const lines = [];
if (!isUsingSourceMaps() || options.inlineSources) {
lines.push("src/");
lines.push("/src/");
}
for (const fileName of getTestFileNames()) {
lines.push(fileName);
Expand All @@ -28,30 +28,30 @@ export function getNpmIgnoreText(options: {
const filePath = file.filePath.replace(/\.ts$/i, ".js");
const dtsFilePath = file.filePath.replace(/\.ts$/i, ".d.ts");
if (options.includeEsModule) {
const esmFilePath = `esm/${filePath}`;
const esmFilePath = `/esm/${filePath}`;
yield esmFilePath;
if (options.sourceMap === true) {
yield `${esmFilePath}.map`;
}
if (options.declaration === "inline") {
yield `esm/${dtsFilePath}`;
yield `/esm/${dtsFilePath}`;
}
}
if (options.includeScriptModule) {
const scriptFilePath = `script/${filePath}`;
const scriptFilePath = `/script/${filePath}`;
yield scriptFilePath;
if (options.sourceMap === true) {
yield `${scriptFilePath}.map`;
}
if (options.declaration === "inline") {
yield `script/${dtsFilePath}`;
yield `/script/${dtsFilePath}`;
}
}
if (options.declaration === "separate") {
yield `types/${dtsFilePath}`;
yield `/types/${dtsFilePath}`;
}
}
yield "test_runner.js";
yield "/test_runner.js";
}

function isUsingSourceMaps() {
Expand Down
194 changes: 97 additions & 97 deletions tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ Deno.test("should build test project - basic", async () => {
});
assertEquals(
output.npmIgnore,
`src/
esm/mod.test.js
esm/mod.test.d.ts
script/mod.test.js
script/mod.test.d.ts
esm/deps/deno.land/[email protected]/fmt/colors.js
esm/deps/deno.land/[email protected]/fmt/colors.d.ts
script/deps/deno.land/[email protected]/fmt/colors.js
script/deps/deno.land/[email protected]/fmt/colors.d.ts
esm/deps/deno.land/[email protected]/testing/_diff.js
esm/deps/deno.land/[email protected]/testing/_diff.d.ts
script/deps/deno.land/[email protected]/testing/_diff.js
script/deps/deno.land/[email protected]/testing/_diff.d.ts
esm/deps/deno.land/[email protected]/testing/_format.js
esm/deps/deno.land/[email protected]/testing/_format.d.ts
script/deps/deno.land/[email protected]/testing/_format.js
script/deps/deno.land/[email protected]/testing/_format.d.ts
esm/deps/deno.land/[email protected]/testing/asserts.js
esm/deps/deno.land/[email protected]/testing/asserts.d.ts
script/deps/deno.land/[email protected]/testing/asserts.js
script/deps/deno.land/[email protected]/testing/asserts.d.ts
esm/_dnt.test_shims.js
esm/_dnt.test_shims.d.ts
script/_dnt.test_shims.js
script/_dnt.test_shims.d.ts
test_runner.js
`/src/
/esm/mod.test.js
/esm/mod.test.d.ts
/script/mod.test.js
/script/mod.test.d.ts
/esm/deps/deno.land/[email protected]/fmt/colors.js
/esm/deps/deno.land/[email protected]/fmt/colors.d.ts
/script/deps/deno.land/[email protected]/fmt/colors.js
/script/deps/deno.land/[email protected]/fmt/colors.d.ts
/esm/deps/deno.land/[email protected]/testing/_diff.js
/esm/deps/deno.land/[email protected]/testing/_diff.d.ts
/script/deps/deno.land/[email protected]/testing/_diff.js
/script/deps/deno.land/[email protected]/testing/_diff.d.ts
/esm/deps/deno.land/[email protected]/testing/_format.js
/esm/deps/deno.land/[email protected]/testing/_format.d.ts
/script/deps/deno.land/[email protected]/testing/_format.js
/script/deps/deno.land/[email protected]/testing/_format.d.ts
/esm/deps/deno.land/[email protected]/testing/asserts.js
/esm/deps/deno.land/[email protected]/testing/asserts.d.ts
/script/deps/deno.land/[email protected]/testing/asserts.js
/script/deps/deno.land/[email protected]/testing/asserts.d.ts
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.d.ts
/script/_dnt.test_shims.js
/script/_dnt.test_shims.d.ts
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down Expand Up @@ -162,20 +162,20 @@ Deno.test("should build test project without esm", async () => {
});
assertEquals(
output.npmIgnore,
`src/
script/mod.test.js
types/mod.test.d.ts
script/deps/deno.land/[email protected]/fmt/colors.js
types/deps/deno.land/[email protected]/fmt/colors.d.ts
script/deps/deno.land/[email protected]/testing/_diff.js
types/deps/deno.land/[email protected]/testing/_diff.d.ts
script/deps/deno.land/[email protected]/testing/_format.js
types/deps/deno.land/[email protected]/testing/_format.d.ts
script/deps/deno.land/[email protected]/testing/asserts.js
types/deps/deno.land/[email protected]/testing/asserts.d.ts
script/_dnt.test_shims.js
types/_dnt.test_shims.d.ts
test_runner.js
`/src/
/script/mod.test.js
/types/mod.test.d.ts
/script/deps/deno.land/[email protected]/fmt/colors.js
/types/deps/deno.land/[email protected]/fmt/colors.d.ts
/script/deps/deno.land/[email protected]/testing/_diff.js
/types/deps/deno.land/[email protected]/testing/_diff.d.ts
/script/deps/deno.land/[email protected]/testing/_format.js
/types/deps/deno.land/[email protected]/testing/_format.d.ts
/script/deps/deno.land/[email protected]/testing/asserts.js
/types/deps/deno.land/[email protected]/testing/asserts.d.ts
/script/_dnt.test_shims.js
/types/_dnt.test_shims.d.ts
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down Expand Up @@ -223,8 +223,8 @@ Deno.test("should build with all options off", async () => {
// This doesn't include the test files because they're not analyzed for in this scenario.
assertEquals(
output.npmIgnore,
`src/
test_runner.js
`/src/
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down Expand Up @@ -497,43 +497,43 @@ Deno.test("should build with source maps", async () => {
output.assertExists("esm/mod.js.map");
assertEquals(
output.npmIgnore,
`esm/mod.test.js
esm/mod.test.js.map
esm/mod.test.d.ts
script/mod.test.js
script/mod.test.js.map
script/mod.test.d.ts
esm/deps/deno.land/[email protected]/fmt/colors.js
esm/deps/deno.land/[email protected]/fmt/colors.js.map
esm/deps/deno.land/[email protected]/fmt/colors.d.ts
script/deps/deno.land/[email protected]/fmt/colors.js
script/deps/deno.land/[email protected]/fmt/colors.js.map
script/deps/deno.land/[email protected]/fmt/colors.d.ts
esm/deps/deno.land/[email protected]/testing/_diff.js
esm/deps/deno.land/[email protected]/testing/_diff.js.map
esm/deps/deno.land/[email protected]/testing/_diff.d.ts
script/deps/deno.land/[email protected]/testing/_diff.js
script/deps/deno.land/[email protected]/testing/_diff.js.map
script/deps/deno.land/[email protected]/testing/_diff.d.ts
esm/deps/deno.land/[email protected]/testing/_format.js
esm/deps/deno.land/[email protected]/testing/_format.js.map
esm/deps/deno.land/[email protected]/testing/_format.d.ts
script/deps/deno.land/[email protected]/testing/_format.js
script/deps/deno.land/[email protected]/testing/_format.js.map
script/deps/deno.land/[email protected]/testing/_format.d.ts
esm/deps/deno.land/[email protected]/testing/asserts.js
esm/deps/deno.land/[email protected]/testing/asserts.js.map
esm/deps/deno.land/[email protected]/testing/asserts.d.ts
script/deps/deno.land/[email protected]/testing/asserts.js
script/deps/deno.land/[email protected]/testing/asserts.js.map
script/deps/deno.land/[email protected]/testing/asserts.d.ts
esm/_dnt.test_shims.js
esm/_dnt.test_shims.js.map
esm/_dnt.test_shims.d.ts
script/_dnt.test_shims.js
script/_dnt.test_shims.js.map
script/_dnt.test_shims.d.ts
test_runner.js
`/esm/mod.test.js
/esm/mod.test.js.map
/esm/mod.test.d.ts
/script/mod.test.js
/script/mod.test.js.map
/script/mod.test.d.ts
/esm/deps/deno.land/[email protected]/fmt/colors.js
/esm/deps/deno.land/[email protected]/fmt/colors.js.map
/esm/deps/deno.land/[email protected]/fmt/colors.d.ts
/script/deps/deno.land/[email protected]/fmt/colors.js
/script/deps/deno.land/[email protected]/fmt/colors.js.map
/script/deps/deno.land/[email protected]/fmt/colors.d.ts
/esm/deps/deno.land/[email protected]/testing/_diff.js
/esm/deps/deno.land/[email protected]/testing/_diff.js.map
/esm/deps/deno.land/[email protected]/testing/_diff.d.ts
/script/deps/deno.land/[email protected]/testing/_diff.js
/script/deps/deno.land/[email protected]/testing/_diff.js.map
/script/deps/deno.land/[email protected]/testing/_diff.d.ts
/esm/deps/deno.land/[email protected]/testing/_format.js
/esm/deps/deno.land/[email protected]/testing/_format.js.map
/esm/deps/deno.land/[email protected]/testing/_format.d.ts
/script/deps/deno.land/[email protected]/testing/_format.js
/script/deps/deno.land/[email protected]/testing/_format.js.map
/script/deps/deno.land/[email protected]/testing/_format.d.ts
/esm/deps/deno.land/[email protected]/testing/asserts.js
/esm/deps/deno.land/[email protected]/testing/asserts.js.map
/esm/deps/deno.land/[email protected]/testing/asserts.d.ts
/script/deps/deno.land/[email protected]/testing/asserts.js
/script/deps/deno.land/[email protected]/testing/asserts.js.map
/script/deps/deno.land/[email protected]/testing/asserts.d.ts
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.js.map
/esm/_dnt.test_shims.d.ts
/script/_dnt.test_shims.js
/script/_dnt.test_shims.js.map
/script/_dnt.test_shims.d.ts
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down Expand Up @@ -595,14 +595,14 @@ Deno.test("should build with package mappings", async () => {
});
assertEquals(
output.npmIgnore,
`src/
esm/mod.test.js
script/mod.test.js
types/mod.test.d.ts
esm/_dnt.test_shims.js
script/_dnt.test_shims.js
types/_dnt.test_shims.d.ts
test_runner.js
`/src/
/esm/mod.test.js
/script/mod.test.js
/types/mod.test.d.ts
/esm/_dnt.test_shims.js
/script/_dnt.test_shims.js
/types/_dnt.test_shims.d.ts
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down Expand Up @@ -1114,16 +1114,16 @@ Deno.test("should build jsr project", async () => {
});
assertEquals(
output.npmIgnore,
`src/
esm/mod.test.js
esm/mod.test.d.ts
script/mod.test.js
script/mod.test.d.ts
esm/_dnt.test_shims.js
esm/_dnt.test_shims.d.ts
script/_dnt.test_shims.js
script/_dnt.test_shims.d.ts
test_runner.js
`/src/
/esm/mod.test.js
/esm/mod.test.d.ts
/script/mod.test.js
/script/mod.test.d.ts
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.d.ts
/script/_dnt.test_shims.js
/script/_dnt.test_shims.d.ts
/test_runner.js
yarn.lock
pnpm-lock.yaml
`,
Expand Down

0 comments on commit 9f3ec7a

Please sign in to comment.