Skip to content

Commit

Permalink
refactor: combine check-tsconfig with parse-tsconfig
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 24, 2022
1 parent bba2f19 commit f015c78
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ test("parseTsConfig", () => {
expect(() => parseTsConfig(stubbedContext, defaultOpts)).not.toThrow();
});

test("parseTsConfig - incompatible module", () => {
expect(() => parseTsConfig(stubbedContext, {
...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 data = { error: "" };

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
Original file line number Diff line number Diff line change
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 f015c78

Please sign in to comment.