Skip to content

Commit f015c78

Browse files
committed
refactor: combine check-tsconfig with parse-tsconfig
- `checkTsConfig` is literally only used by `parseTsConfig` - I first just moved the function over, but it's a two-liner, so thought it made more sense to just in-line it - merge the unit tests as well - we already check the non-error case in `parse-tsconfig.spec`, so only add the error case - `check-tsconfig` was longer in the past and more files were being created then for separation, so this may have made more sense then, but now it is unnecessary - c.f. 7332077
1 parent bba2f19 commit f015c78

File tree

5 files changed

+12
-47
lines changed

5 files changed

+12
-47
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ It can also be useful to review some issues and have a "goal" in mind (especiall
6666
Once you have some understanding of the codebase's main workflow, you can start to dive deeper into pieces that require more domain knowledge.<br />
6767
A useful resource as you dive deeper are the [unit tests](__tests__/). They're good to look through as you dig into a module to understand how it's used.
6868

69-
1. From here, you can start to read more of the modules that integrate with the TypeScript API, such as [`host`](src/host.ts), [`parse-tsconfig`](src/parse-tsconfig.ts), [`check-tsconfig`](src/check-tsconfig.ts), and maybe how TS is imported in [`tsproxy`](src/tsproxy.ts) and [`tslib`](src/tslib.ts)
69+
1. From here, you can start to read more of the modules that integrate with the TypeScript API, such as [`host`](src/host.ts) and [`parse-tsconfig`](src/parse-tsconfig.ts), and maybe how TS is imported in [`tsproxy`](src/tsproxy.ts) and [`tslib`](src/tslib.ts)
7070
- A _very_ useful reference here is the [TypeScript Wiki](https://github.com/microsoft/TypeScript/wiki), which has two main articles that are the basis for most Compiler integrations:
7171
- [Using the Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API)
7272
- [Using the Language Service API](https://github.com/microsoft/TypeScript/wiki/Using-the-Language-Service-API)

__tests__/check-tsconfig.spec.ts

-33
This file was deleted.

__tests__/parse-tsconfig.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ test("parseTsConfig", () => {
1515
expect(() => parseTsConfig(stubbedContext, defaultOpts)).not.toThrow();
1616
});
1717

18+
test("parseTsConfig - incompatible module", () => {
19+
expect(() => parseTsConfig(stubbedContext, {
20+
...defaultOpts,
21+
tsconfigOverride: { compilerOptions: { module: "none" } },
22+
})).toThrow("Incompatible tsconfig option. Module resolves to 'None'. This is incompatible with Rollup, please use");
23+
});
24+
1825
test("parseTsConfig - tsconfig errors", () => {
1926
const data = { error: "" };
2027

src/check-tsconfig.ts

-11
This file was deleted.

src/parse-tsconfig.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { printDiagnostics } from "./print-diagnostics";
77
import { convertDiagnostic } from "./tscache";
88
import { getOptionsOverrides } from "./get-options-overrides";
99
import { IOptions } from "./ioptions";
10-
import { checkTsConfig } from "./check-tsconfig";
1110

1211
export function parseTsConfig(context: IContext, pluginOptions: IOptions)
1312
{
@@ -45,7 +44,10 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions)
4544
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
4645
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
4746

48-
checkTsConfig(parsedTsConfig);
47+
const module = parsedTsConfig.options.module!;
48+
if (module !== tsModule.ModuleKind.ES2015 && module !== tsModule.ModuleKind.ES2020 && module !== tsModule.ModuleKind.ESNext)
49+
throw new Error(`rpt2: Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with Rollup, please use 'module: "ES2015"', 'module: "ES2020"', or 'module: "ESNext"'.`);
50+
4951
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty);
5052

5153
context.debug(`built-in options overrides: ${JSON.stringify(compilerOptionsOverride, undefined, 4)}`);

0 commit comments

Comments
 (0)