Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support newer moduleResolution kinds, update build to TS 5.x #453

Merged
merged 10 commits into from Jul 17, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -48,13 +48,15 @@ This also allows for passing in different `tsconfig` files depending on your bui
* `inlineSourceMap`: false (see [#71](https://github.com/ezolenko/rollup-plugin-typescript2/issues/71))
* `outDir`: `./placeholder` in cache root (see [#83](https://github.com/ezolenko/rollup-plugin-typescript2/issues/83) and [Microsoft/TypeScript#24715](https://github.com/Microsoft/TypeScript/issues/24715))
* `declarationDir`: Rollup's `output.file` or `output.dir` (*unless `useTsconfigDeclarationDir` is true in the plugin options*)
* `moduleResolution`: `node` (*`classic` is [deprecated](https://www.typescriptlang.org/docs/handbook/module-resolution.html). It also breaks this plugin, see [#12](https://github.com/ezolenko/rollup-plugin-typescript2/issues/12) and [#14](https://github.com/ezolenko/rollup-plugin-typescript2/issues/14)*)
* `allowNonTsExtensions`: true to let other plugins on the chain generate typescript; update plugin's `include` filter to pick them up (see [#111](https://github.com/ezolenko/rollup-plugin-typescript2/issues/111))

### Some compiler options have more than one compatible value

* `module`: defaults to `ES2015`. Other valid values are `ES2020`, `ES2022` and `ESNext` (required for dynamic imports, see [#54](https://github.com/ezolenko/rollup-plugin-typescript2/issues/54)).

* `moduleResolution`: defaults to `node10` (same as `node`), but value from tsconfig is used if specified. Other valid (but mostly untested) values are `node16`, `nodenext` and `bundler`. If in doubt, use `node10`.
* `classic` is [deprecated](https://www.typescriptlang.org/docs/handbook/module-resolution.html) and changed to `node10`. It also breaks this plugin, see [#12](https://github.com/ezolenko/rollup-plugin-typescript2/issues/12) and [#14](https://github.com/ezolenko/rollup-plugin-typescript2/issues/14).

### Some options need additional configuration on plugin side

* `allowJs`: lets TypeScript process JS files as well. If you use it, modify this plugin's `include` option to add `"*.js+(|x)", "**/*.js+(|x)"` (might also want to `exclude` `"**/node_modules/**/*"`, as it can slow down the build significantly).
Expand Down
1 change: 0 additions & 1 deletion __tests__/get-options-overrides.spec.ts
Expand Up @@ -22,7 +22,6 @@ const forcedOptions: ts.CompilerOptions = {
allowNonTsExtensions: true,
importHelpers: true,
inlineSourceMap: false,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
noEmit: false,
noEmitOnError: false,
noEmitHelpers: false,
Expand Down
2 changes: 1 addition & 1 deletion dist/get-options-overrides.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/rollup-plugin-typescript2.cjs.js
Expand Up @@ -27834,11 +27834,12 @@ function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }, preParsed
noEmitOnError: false,
inlineSourceMap: false,
outDir: pluginutils.normalizePath(`${cacheRoot}/placeholder`),
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
allowNonTsExtensions: true,
};
if (!preParsedTsconfig)
return overrides;
if (preParsedTsconfig.options.moduleResolution === tsModule.ModuleResolutionKind.Classic)
overrides.moduleResolution = tsModule.ModuleResolutionKind.Node10;
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;
// only set declarationDir if useTsconfigDeclarationDir is enabled
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.cjs.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/rollup-plugin-typescript2.es.js
Expand Up @@ -27805,11 +27805,12 @@ function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }, preParsed
noEmitOnError: false,
inlineSourceMap: false,
outDir: normalizePath(`${cacheRoot}/placeholder`),
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
allowNonTsExtensions: true,
};
if (!preParsedTsconfig)
return overrides;
if (preParsedTsconfig.options.moduleResolution === tsModule.ModuleResolutionKind.Classic)
overrides.moduleResolution = tsModule.ModuleResolutionKind.Node10;
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;
// only set declarationDir if useTsconfigDeclarationDir is enabled
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -65,7 +65,7 @@
"rollup-plugin-typescript2": "0.34.0",
"ts-jest": "^28.0.0",
"tslint": "6.1.3",
"typescript": "^4.6.3"
"typescript": "^5.1.3"
},
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion src/get-options-overrides.ts
Expand Up @@ -16,13 +16,14 @@ export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IO
noEmitOnError: false,
inlineSourceMap: false,
outDir: normalize(`${cacheRoot}/placeholder`), // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
allowNonTsExtensions: true,
};

if (!preParsedTsconfig)
return overrides;

if (preParsedTsconfig.options.moduleResolution === tsModule.ModuleResolutionKind.Classic)
overrides.moduleResolution = tsModule.ModuleResolutionKind.Node10;
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;

Expand Down