Skip to content

Commit

Permalink
refactor: combine check-tsconfig with parse-tsconfig (#413)
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
agilgur5 committed Aug 25, 2022
1 parent 27356be commit 79053fe
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -65,7 +65,7 @@ It can also be useful to review some issues and have a "goal" in mind (especiall
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 />
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.

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)
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)
- 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:
- [Using the Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API)
- [Using the Language Service API](https://github.com/microsoft/TypeScript/wiki/Using-the-Language-Service-API)
Expand Down
33 changes: 0 additions & 33 deletions __tests__/check-tsconfig.spec.ts

This file was deleted.

7 changes: 7 additions & 0 deletions __tests__/parse-tsconfig.spec.ts
Expand Up @@ -14,6 +14,13 @@ test("parseTsConfig", () => {
expect(() => parseTsConfig(makeContext(), defaultOpts)).not.toThrow();
});

test("parseTsConfig - incompatible module", () => {
expect(() => parseTsConfig(makeContext(), {
...defaultOpts,
tsconfigOverride: { compilerOptions: { module: "none" } },
})).toThrow("Incompatible tsconfig option. Module resolves to 'None'. This is incompatible with Rollup, please use");
});

test("parseTsConfig - tsconfig errors", () => {
const context = makeContext();

Expand Down
11 changes: 0 additions & 11 deletions src/check-tsconfig.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/parse-tsconfig.ts
Expand Up @@ -7,7 +7,6 @@ import { printDiagnostics } from "./print-diagnostics";
import { convertDiagnostic } from "./tscache";
import { getOptionsOverrides } from "./get-options-overrides";
import { IOptions } from "./ioptions";
import { checkTsConfig } from "./check-tsconfig";

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

checkTsConfig(parsedTsConfig);
const module = parsedTsConfig.options.module!;
if (module !== tsModule.ModuleKind.ES2015 && module !== tsModule.ModuleKind.ES2020 && module !== tsModule.ModuleKind.ESNext)
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"'.`);

printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty);

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

0 comments on commit 79053fe

Please sign in to comment.