Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lib/npm_ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,52 @@ Deno.test("should include src directory when the source files are not necessary"
});
});

Deno.test("should include declaration maps of test files", () => {
runTest({
sourceMaps: undefined,
inlineSources: undefined,
expectHasSrcFolder: true,
includeScriptModule: true,
includeEsModule: true,
declaration: "inline",
declarationMap: true,
});
runTest({
sourceMaps: true,
inlineSources: undefined,
expectHasSrcFolder: false,
includeScriptModule: true,
includeEsModule: true,
declaration: "inline",
declarationMap: true,
});
runTest({
sourceMaps: undefined,
inlineSources: undefined,
expectHasSrcFolder: true,
includeScriptModule: true,
includeEsModule: true,
declaration: "separate",
declarationMap: true,
});
// no declaration files, so no declaration maps
runTest({
sourceMaps: undefined,
inlineSources: undefined,
expectHasSrcFolder: true,
includeScriptModule: true,
includeEsModule: true,
declaration: false,
declarationMap: true,
});
});

function runTest(options: {
sourceMaps: SourceMapOptions | undefined;
inlineSources: boolean | undefined;
expectHasSrcFolder: boolean;
declaration: "separate" | "inline" | false;
declarationMap?: boolean;
includeScriptModule: boolean | undefined;
includeEsModule: boolean | undefined;
}) {
Expand All @@ -115,6 +156,7 @@ function runTest(options: {
includeScriptModule: options.includeScriptModule,
includeEsModule: options.includeEsModule,
declaration: options.declaration,
declarationMap: options.declarationMap,
});

assertEquals(fileText, getExpectedText());
Expand All @@ -128,6 +170,9 @@ function runTest(options: {
}
if (options.declaration === "inline") {
startText += "/esm/mod.test.d.ts\n";
if (options.declarationMap) {
startText += "/esm/mod.test.d.ts.map\n";
}
}
}
if (options.includeScriptModule !== false) {
Expand All @@ -137,10 +182,16 @@ function runTest(options: {
}
if (options.declaration === "inline") {
startText += "/script/mod.test.d.ts\n";
if (options.declarationMap) {
startText += "/script/mod.test.d.ts.map\n";
}
}
}
if (options.declaration === "separate") {
startText += "/types/mod.test.d.ts\n";
if (options.declarationMap) {
startText += "/types/mod.test.d.ts.map\n";
}
}

return startText +
Expand Down
10 changes: 10 additions & 0 deletions lib/npm_ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function getNpmIgnoreText(options: {
inlineSources?: boolean;
testFiles: OutputFile[];
declaration: "separate" | "inline" | false;
declarationMap: boolean | undefined;
includeScriptModule: boolean | undefined;
includeEsModule: boolean | undefined;
}) {
Expand Down Expand Up @@ -35,6 +36,9 @@ export function getNpmIgnoreText(options: {
}
if (options.declaration === "inline") {
yield `/esm/${dtsFilePath}`;
if (options.declarationMap) {
yield `/esm/${dtsFilePath}.map`;
}
}
}
if (options.includeScriptModule) {
Expand All @@ -45,10 +49,16 @@ export function getNpmIgnoreText(options: {
}
if (options.declaration === "inline") {
yield `/script/${dtsFilePath}`;
if (options.declarationMap) {
yield `/script/${dtsFilePath}.map`;
}
}
}
if (options.declaration === "separate") {
yield `/types/${dtsFilePath}`;
if (options.declarationMap) {
yield `/types/${dtsFilePath}.map`;
}
}
}
yield "/test_runner.js";
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ export async function build(options: BuildOptions): Promise<void> {
includeScriptModule: options.scriptModule !== false,
includeEsModule: options.esModule !== false,
declaration: options.declaration!,
declarationMap,
});
writeFile(
path.join(options.outDir, ".npmignore"),
Expand Down
41 changes: 41 additions & 0 deletions tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,46 @@ Deno.test("should build test project - basic", async () => {
`/src/
/esm/mod.test.js
/esm/mod.test.d.ts
/esm/mod.test.d.ts.map
/script/mod.test.js
/script/mod.test.d.ts
/script/mod.test.d.ts.map
/esm/deps/deno.land/std@0.181.0/fmt/colors.js
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
/script/deps/deno.land/std@0.181.0/fmt/colors.js
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/_diff.js
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_diff.js
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/_format.js
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_format.js
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/asserts.js
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/asserts.js
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
/esm/_dnt.test_polyfills.js
/esm/_dnt.test_polyfills.d.ts
/esm/_dnt.test_polyfills.d.ts.map
/script/_dnt.test_polyfills.js
/script/_dnt.test_polyfills.d.ts
/script/_dnt.test_polyfills.d.ts.map
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.d.ts
/esm/_dnt.test_shims.d.ts.map
/script/_dnt.test_shims.js
/script/_dnt.test_shims.d.ts
/script/_dnt.test_shims.d.ts.map
/test_runner.js
yarn.lock
pnpm-lock.yaml
Expand Down Expand Up @@ -168,18 +182,25 @@ Deno.test("should build test project without esm", async () => {
`/src/
/script/mod.test.js
/types/mod.test.d.ts
/types/mod.test.d.ts.map
/script/deps/deno.land/std@0.181.0/fmt/colors.js
/types/deps/deno.land/std@0.181.0/fmt/colors.d.ts
/types/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_diff.js
/types/deps/deno.land/std@0.181.0/testing/_diff.d.ts
/types/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_format.js
/types/deps/deno.land/std@0.181.0/testing/_format.d.ts
/types/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/asserts.js
/types/deps/deno.land/std@0.181.0/testing/asserts.d.ts
/types/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
/script/_dnt.test_polyfills.js
/types/_dnt.test_polyfills.d.ts
/types/_dnt.test_polyfills.d.ts.map
/script/_dnt.test_shims.js
/types/_dnt.test_shims.d.ts
/types/_dnt.test_shims.d.ts.map
/test_runner.js
yarn.lock
pnpm-lock.yaml
Expand Down Expand Up @@ -550,45 +571,59 @@ Deno.test("should build with source maps", async () => {
`/esm/mod.test.js
/esm/mod.test.js.map
/esm/mod.test.d.ts
/esm/mod.test.d.ts.map
/script/mod.test.js
/script/mod.test.js.map
/script/mod.test.d.ts
/script/mod.test.d.ts.map
/esm/deps/deno.land/std@0.181.0/fmt/colors.js
/esm/deps/deno.land/std@0.181.0/fmt/colors.js.map
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
/script/deps/deno.land/std@0.181.0/fmt/colors.js
/script/deps/deno.land/std@0.181.0/fmt/colors.js.map
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/_diff.js
/esm/deps/deno.land/std@0.181.0/testing/_diff.js.map
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_diff.js
/script/deps/deno.land/std@0.181.0/testing/_diff.js.map
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/_format.js
/esm/deps/deno.land/std@0.181.0/testing/_format.js.map
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/_format.js
/script/deps/deno.land/std@0.181.0/testing/_format.js.map
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
/esm/deps/deno.land/std@0.181.0/testing/asserts.js
/esm/deps/deno.land/std@0.181.0/testing/asserts.js.map
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
/script/deps/deno.land/std@0.181.0/testing/asserts.js
/script/deps/deno.land/std@0.181.0/testing/asserts.js.map
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
/esm/_dnt.test_polyfills.js
/esm/_dnt.test_polyfills.js.map
/esm/_dnt.test_polyfills.d.ts
/esm/_dnt.test_polyfills.d.ts.map
/script/_dnt.test_polyfills.js
/script/_dnt.test_polyfills.js.map
/script/_dnt.test_polyfills.d.ts
/script/_dnt.test_polyfills.d.ts.map
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.js.map
/esm/_dnt.test_shims.d.ts
/esm/_dnt.test_shims.d.ts.map
/script/_dnt.test_shims.js
/script/_dnt.test_shims.js.map
/script/_dnt.test_shims.d.ts
/script/_dnt.test_shims.d.ts.map
/test_runner.js
yarn.lock
pnpm-lock.yaml
Expand Down Expand Up @@ -655,9 +690,11 @@ Deno.test("should build with package mappings", async () => {
/esm/mod.test.js
/script/mod.test.js
/types/mod.test.d.ts
/types/mod.test.d.ts.map
/esm/_dnt.test_shims.js
/script/_dnt.test_shims.js
/types/_dnt.test_shims.d.ts
/types/_dnt.test_shims.d.ts.map
/test_runner.js
yarn.lock
pnpm-lock.yaml
Expand Down Expand Up @@ -1182,12 +1219,16 @@ Deno.test("should build jsr project", async () => {
`/src/
/esm/mod.test.js
/esm/mod.test.d.ts
/esm/mod.test.d.ts.map
/script/mod.test.js
/script/mod.test.d.ts
/script/mod.test.d.ts.map
/esm/_dnt.test_shims.js
/esm/_dnt.test_shims.d.ts
/esm/_dnt.test_shims.d.ts.map
/script/_dnt.test_shims.js
/script/_dnt.test_shims.d.ts
/script/_dnt.test_shims.d.ts.map
/test_runner.js
yarn.lock
pnpm-lock.yaml
Expand Down