Skip to content

Commit 5d292b5

Browse files
dummdidummSimon Holthausen
and
Simon Holthausen
authored
docs(typescript): More informative error messages (#619)
Co-authored-by: Simon Holthausen <[email protected]>
1 parent df56bfb commit 5d292b5

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

packages/typescript/src/options/validate.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,28 @@ export function validatePaths(
4444
) {
4545
if (compilerOptions.out) {
4646
context.error(
47-
`@rollup/plugin-typescript: Deprecated 'out' option is not supported. Use 'outDir' instead.`
47+
`@rollup/plugin-typescript: Deprecated Typescript compiler option 'out' is not supported. Use 'outDir' instead.`
4848
);
4949
} else if (compilerOptions.outFile) {
5050
context.error(
51-
`@rollup/plugin-typescript: 'outFile' option is not supported. Use 'outDir' instead.`
51+
`@rollup/plugin-typescript: Typescript compiler option 'outFile' is not supported. Use 'outDir' instead.`
5252
);
5353
}
5454

5555
for (const dirProperty of DIRECTORY_PROPS) {
5656
if (compilerOptions[dirProperty]) {
5757
if (!outputOptions.dir) {
5858
context.error(
59-
`@rollup/plugin-typescript: 'dir' must be used when '${dirProperty}' is specified.`
59+
`@rollup/plugin-typescript: Rollup 'dir' option must be used when Typescript compiler option '${dirProperty}' is specified.`
6060
);
6161
}
6262

6363
// Checks if the given path lies within Rollup output dir
6464
const fromRollupDirToTs = relative(outputOptions.dir, compilerOptions[dirProperty]!);
6565
if (fromRollupDirToTs.startsWith('..')) {
66-
context.error(`@rollup/plugin-typescript: '${dirProperty}' must be located inside 'dir'.`);
66+
context.error(
67+
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside Rollup 'dir' option.`
68+
);
6769
}
6870
}
6971
}
@@ -72,21 +74,24 @@ export function validatePaths(
7274
if (tsBuildInfoPath && compilerOptions.incremental) {
7375
if (!outputOptions.dir) {
7476
context.error(
75-
`@rollup/plugin-typescript: 'dir' must be used when 'tsBuildInfoFile' or 'incremental' are specified.`
77+
`@rollup/plugin-typescript: Rollup 'dir' option must be used when Typescript compiler options 'tsBuildInfoFile' or 'incremental' are specified.`
7678
);
7779
}
7880

7981
// Checks if the given path lies within Rollup output dir
8082
const fromRollupDirToTs = relative(outputOptions.dir, tsBuildInfoPath);
8183
if (fromRollupDirToTs.startsWith('..')) {
82-
context.error(`@rollup/plugin-typescript: 'tsBuildInfoFile' must be located inside 'dir'.`);
84+
context.error(
85+
`@rollup/plugin-typescript: Path of Typescript compiler option 'tsBuildInfoFile' must be located inside Rollup 'dir' option.`
86+
);
8387
}
8488
}
8589

8690
if (compilerOptions.declaration || compilerOptions.declarationMap || compilerOptions.composite) {
8791
if (DIRECTORY_PROPS.every((dirProperty) => !compilerOptions[dirProperty])) {
8892
context.error(
89-
`@rollup/plugin-typescript: 'outDir' or 'declarationDir' must be specified to generate declaration files.`
93+
`@rollup/plugin-typescript: You are using one of Typescript's compiler options 'declaration', 'declarationMap' or 'composite'. ` +
94+
`In this case 'outDir' or 'declarationDir' must be specified to generate declaration files.`
9095
);
9196
}
9297
}

packages/typescript/test/test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,19 @@ test.serial('ensures outDir is located in Rollup output dir', async (t) => {
209209
getCode(bundle, { format: 'esm', file: 'fixtures/basic/other/out.js' }, true)
210210
);
211211
t.true(
212-
noDirError.message.includes(`'dir' must be used when 'outDir' is specified`),
212+
noDirError.message.includes(
213+
`Rollup 'dir' option must be used when Typescript compiler option 'outDir' is specified`
214+
),
213215
`Unexpected error message: ${noDirError.message}`
214216
);
215217

216218
const wrongDirError = await t.throwsAsync(() =>
217219
getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true)
218220
);
219221
t.true(
220-
wrongDirError.message.includes(`'outDir' must be located inside 'dir'`),
222+
wrongDirError.message.includes(
223+
`Path of Typescript compiler option 'outDir' must be located inside Rollup 'dir' option`
224+
),
221225
`Unexpected error message: ${wrongDirError.message}`
222226
);
223227
});
@@ -239,15 +243,19 @@ test.serial('ensures declarationDir is located in Rollup output dir', async (t)
239243
getCode(bundle, { format: 'esm', file: 'fixtures/basic/other/out.js' }, true)
240244
);
241245
t.true(
242-
noDirError.message.includes(`'dir' must be used when 'declarationDir' is specified`),
246+
noDirError.message.includes(
247+
`Rollup 'dir' option must be used when Typescript compiler option 'declarationDir' is specified`
248+
),
243249
`Unexpected error message: ${noDirError.message}`
244250
);
245251

246252
const wrongDirError = await t.throwsAsync(() =>
247253
getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true)
248254
);
249255
t.true(
250-
wrongDirError.message.includes(`'declarationDir' must be located inside 'dir'`),
256+
wrongDirError.message.includes(
257+
`Path of Typescript compiler option 'declarationDir' must be located inside Rollup 'dir' option`
258+
),
251259
`Unexpected error message: ${wrongDirError.message}`
252260
);
253261
});

0 commit comments

Comments
 (0)