Skip to content

Commit

Permalink
support newer moduleResolution kinds
Browse files Browse the repository at this point in the history
* moduleResolution classic is overridden to node10, all other values are passed through from tsconfig
* updating dev typescript to 5.1.3
  • Loading branch information
ezolenko authored Jul 17, 2023
1 parent b43001e commit ce2038d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

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

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

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

2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit ce2038d

Please sign in to comment.