Skip to content

Commit cb8da21

Browse files
committed
fix: npm ignore declaration map files of test modules
The .npmignore was listing the .d.ts files of test modules, but not the .d.ts.map files emitted alongside them when declarationMap is enabled (which is the default when emitting declarations).
1 parent 74e37c7 commit cb8da21

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

lib/npm_ignore.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,52 @@ Deno.test("should include src directory when the source files are not necessary"
9797
});
9898
});
9999

100+
Deno.test("should include declaration maps of test files", () => {
101+
runTest({
102+
sourceMaps: undefined,
103+
inlineSources: undefined,
104+
expectHasSrcFolder: true,
105+
includeScriptModule: true,
106+
includeEsModule: true,
107+
declaration: "inline",
108+
declarationMap: true,
109+
});
110+
runTest({
111+
sourceMaps: true,
112+
inlineSources: undefined,
113+
expectHasSrcFolder: false,
114+
includeScriptModule: true,
115+
includeEsModule: true,
116+
declaration: "inline",
117+
declarationMap: true,
118+
});
119+
runTest({
120+
sourceMaps: undefined,
121+
inlineSources: undefined,
122+
expectHasSrcFolder: true,
123+
includeScriptModule: true,
124+
includeEsModule: true,
125+
declaration: "separate",
126+
declarationMap: true,
127+
});
128+
// no declaration files, so no declaration maps
129+
runTest({
130+
sourceMaps: undefined,
131+
inlineSources: undefined,
132+
expectHasSrcFolder: true,
133+
includeScriptModule: true,
134+
includeEsModule: true,
135+
declaration: false,
136+
declarationMap: true,
137+
});
138+
});
139+
100140
function runTest(options: {
101141
sourceMaps: SourceMapOptions | undefined;
102142
inlineSources: boolean | undefined;
103143
expectHasSrcFolder: boolean;
104144
declaration: "separate" | "inline" | false;
145+
declarationMap?: boolean;
105146
includeScriptModule: boolean | undefined;
106147
includeEsModule: boolean | undefined;
107148
}) {
@@ -115,6 +156,7 @@ function runTest(options: {
115156
includeScriptModule: options.includeScriptModule,
116157
includeEsModule: options.includeEsModule,
117158
declaration: options.declaration,
159+
declarationMap: options.declarationMap,
118160
});
119161

120162
assertEquals(fileText, getExpectedText());
@@ -128,6 +170,9 @@ function runTest(options: {
128170
}
129171
if (options.declaration === "inline") {
130172
startText += "/esm/mod.test.d.ts\n";
173+
if (options.declarationMap) {
174+
startText += "/esm/mod.test.d.ts.map\n";
175+
}
131176
}
132177
}
133178
if (options.includeScriptModule !== false) {
@@ -137,10 +182,16 @@ function runTest(options: {
137182
}
138183
if (options.declaration === "inline") {
139184
startText += "/script/mod.test.d.ts\n";
185+
if (options.declarationMap) {
186+
startText += "/script/mod.test.d.ts.map\n";
187+
}
140188
}
141189
}
142190
if (options.declaration === "separate") {
143191
startText += "/types/mod.test.d.ts\n";
192+
if (options.declarationMap) {
193+
startText += "/types/mod.test.d.ts.map\n";
194+
}
144195
}
145196

146197
return startText +

lib/npm_ignore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function getNpmIgnoreText(options: {
88
inlineSources?: boolean;
99
testFiles: OutputFile[];
1010
declaration: "separate" | "inline" | false;
11+
declarationMap: boolean | undefined;
1112
includeScriptModule: boolean | undefined;
1213
includeEsModule: boolean | undefined;
1314
}) {
@@ -35,6 +36,9 @@ export function getNpmIgnoreText(options: {
3536
}
3637
if (options.declaration === "inline") {
3738
yield `/esm/${dtsFilePath}`;
39+
if (options.declarationMap) {
40+
yield `/esm/${dtsFilePath}.map`;
41+
}
3842
}
3943
}
4044
if (options.includeScriptModule) {
@@ -45,10 +49,16 @@ export function getNpmIgnoreText(options: {
4549
}
4650
if (options.declaration === "inline") {
4751
yield `/script/${dtsFilePath}`;
52+
if (options.declarationMap) {
53+
yield `/script/${dtsFilePath}.map`;
54+
}
4855
}
4956
}
5057
if (options.declaration === "separate") {
5158
yield `/types/${dtsFilePath}`;
59+
if (options.declarationMap) {
60+
yield `/types/${dtsFilePath}.map`;
61+
}
5262
}
5363
}
5464
yield "/test_runner.js";

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export async function build(options: BuildOptions): Promise<void> {
554554
includeScriptModule: options.scriptModule !== false,
555555
includeEsModule: options.esModule !== false,
556556
declaration: options.declaration!,
557+
declarationMap,
557558
});
558559
writeFile(
559560
path.join(options.outDir, ".npmignore"),

tests/integration.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,46 @@ Deno.test("should build test project - basic", async () => {
9090
`/src/
9191
/esm/mod.test.js
9292
/esm/mod.test.d.ts
93+
/esm/mod.test.d.ts.map
9394
/script/mod.test.js
9495
/script/mod.test.d.ts
96+
/script/mod.test.d.ts.map
9597
/esm/deps/deno.land/std@0.181.0/fmt/colors.js
9698
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts
99+
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
97100
/script/deps/deno.land/std@0.181.0/fmt/colors.js
98101
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts
102+
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
99103
/esm/deps/deno.land/std@0.181.0/testing/_diff.js
100104
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts
105+
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
101106
/script/deps/deno.land/std@0.181.0/testing/_diff.js
102107
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts
108+
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
103109
/esm/deps/deno.land/std@0.181.0/testing/_format.js
104110
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts
111+
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
105112
/script/deps/deno.land/std@0.181.0/testing/_format.js
106113
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts
114+
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
107115
/esm/deps/deno.land/std@0.181.0/testing/asserts.js
108116
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts
117+
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
109118
/script/deps/deno.land/std@0.181.0/testing/asserts.js
110119
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts
120+
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
111121
/esm/_dnt.test_polyfills.js
112122
/esm/_dnt.test_polyfills.d.ts
123+
/esm/_dnt.test_polyfills.d.ts.map
113124
/script/_dnt.test_polyfills.js
114125
/script/_dnt.test_polyfills.d.ts
126+
/script/_dnt.test_polyfills.d.ts.map
115127
/esm/_dnt.test_shims.js
116128
/esm/_dnt.test_shims.d.ts
129+
/esm/_dnt.test_shims.d.ts.map
117130
/script/_dnt.test_shims.js
118131
/script/_dnt.test_shims.d.ts
132+
/script/_dnt.test_shims.d.ts.map
119133
/test_runner.js
120134
yarn.lock
121135
pnpm-lock.yaml
@@ -169,18 +183,25 @@ Deno.test("should build test project without esm", async () => {
169183
`/src/
170184
/script/mod.test.js
171185
/types/mod.test.d.ts
186+
/types/mod.test.d.ts.map
172187
/script/deps/deno.land/std@0.181.0/fmt/colors.js
173188
/types/deps/deno.land/std@0.181.0/fmt/colors.d.ts
189+
/types/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
174190
/script/deps/deno.land/std@0.181.0/testing/_diff.js
175191
/types/deps/deno.land/std@0.181.0/testing/_diff.d.ts
192+
/types/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
176193
/script/deps/deno.land/std@0.181.0/testing/_format.js
177194
/types/deps/deno.land/std@0.181.0/testing/_format.d.ts
195+
/types/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
178196
/script/deps/deno.land/std@0.181.0/testing/asserts.js
179197
/types/deps/deno.land/std@0.181.0/testing/asserts.d.ts
198+
/types/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
180199
/script/_dnt.test_polyfills.js
181200
/types/_dnt.test_polyfills.d.ts
201+
/types/_dnt.test_polyfills.d.ts.map
182202
/script/_dnt.test_shims.js
183203
/types/_dnt.test_shims.d.ts
204+
/types/_dnt.test_shims.d.ts.map
184205
/test_runner.js
185206
yarn.lock
186207
pnpm-lock.yaml
@@ -551,45 +572,59 @@ Deno.test("should build with source maps", async () => {
551572
`/esm/mod.test.js
552573
/esm/mod.test.js.map
553574
/esm/mod.test.d.ts
575+
/esm/mod.test.d.ts.map
554576
/script/mod.test.js
555577
/script/mod.test.js.map
556578
/script/mod.test.d.ts
579+
/script/mod.test.d.ts.map
557580
/esm/deps/deno.land/std@0.181.0/fmt/colors.js
558581
/esm/deps/deno.land/std@0.181.0/fmt/colors.js.map
559582
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts
583+
/esm/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
560584
/script/deps/deno.land/std@0.181.0/fmt/colors.js
561585
/script/deps/deno.land/std@0.181.0/fmt/colors.js.map
562586
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts
587+
/script/deps/deno.land/std@0.181.0/fmt/colors.d.ts.map
563588
/esm/deps/deno.land/std@0.181.0/testing/_diff.js
564589
/esm/deps/deno.land/std@0.181.0/testing/_diff.js.map
565590
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts
591+
/esm/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
566592
/script/deps/deno.land/std@0.181.0/testing/_diff.js
567593
/script/deps/deno.land/std@0.181.0/testing/_diff.js.map
568594
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts
595+
/script/deps/deno.land/std@0.181.0/testing/_diff.d.ts.map
569596
/esm/deps/deno.land/std@0.181.0/testing/_format.js
570597
/esm/deps/deno.land/std@0.181.0/testing/_format.js.map
571598
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts
599+
/esm/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
572600
/script/deps/deno.land/std@0.181.0/testing/_format.js
573601
/script/deps/deno.land/std@0.181.0/testing/_format.js.map
574602
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts
603+
/script/deps/deno.land/std@0.181.0/testing/_format.d.ts.map
575604
/esm/deps/deno.land/std@0.181.0/testing/asserts.js
576605
/esm/deps/deno.land/std@0.181.0/testing/asserts.js.map
577606
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts
607+
/esm/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
578608
/script/deps/deno.land/std@0.181.0/testing/asserts.js
579609
/script/deps/deno.land/std@0.181.0/testing/asserts.js.map
580610
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts
611+
/script/deps/deno.land/std@0.181.0/testing/asserts.d.ts.map
581612
/esm/_dnt.test_polyfills.js
582613
/esm/_dnt.test_polyfills.js.map
583614
/esm/_dnt.test_polyfills.d.ts
615+
/esm/_dnt.test_polyfills.d.ts.map
584616
/script/_dnt.test_polyfills.js
585617
/script/_dnt.test_polyfills.js.map
586618
/script/_dnt.test_polyfills.d.ts
619+
/script/_dnt.test_polyfills.d.ts.map
587620
/esm/_dnt.test_shims.js
588621
/esm/_dnt.test_shims.js.map
589622
/esm/_dnt.test_shims.d.ts
623+
/esm/_dnt.test_shims.d.ts.map
590624
/script/_dnt.test_shims.js
591625
/script/_dnt.test_shims.js.map
592626
/script/_dnt.test_shims.d.ts
627+
/script/_dnt.test_shims.d.ts.map
593628
/test_runner.js
594629
yarn.lock
595630
pnpm-lock.yaml
@@ -656,9 +691,11 @@ Deno.test("should build with package mappings", async () => {
656691
/esm/mod.test.js
657692
/script/mod.test.js
658693
/types/mod.test.d.ts
694+
/types/mod.test.d.ts.map
659695
/esm/_dnt.test_shims.js
660696
/script/_dnt.test_shims.js
661697
/types/_dnt.test_shims.d.ts
698+
/types/_dnt.test_shims.d.ts.map
662699
/test_runner.js
663700
yarn.lock
664701
pnpm-lock.yaml
@@ -1189,12 +1226,16 @@ Deno.test("should build jsr project", async () => {
11891226
`/src/
11901227
/esm/mod.test.js
11911228
/esm/mod.test.d.ts
1229+
/esm/mod.test.d.ts.map
11921230
/script/mod.test.js
11931231
/script/mod.test.d.ts
1232+
/script/mod.test.d.ts.map
11941233
/esm/_dnt.test_shims.js
11951234
/esm/_dnt.test_shims.d.ts
1235+
/esm/_dnt.test_shims.d.ts.map
11961236
/script/_dnt.test_shims.js
11971237
/script/_dnt.test_shims.d.ts
1238+
/script/_dnt.test_shims.d.ts.map
11981239
/test_runner.js
11991240
yarn.lock
12001241
pnpm-lock.yaml

0 commit comments

Comments
 (0)