-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): warn when compilerOptions.module is not esnext (#788)
* feat(typescript): warn when compilerOptions.module is not esnext * fix: remove extra space * test: update snapshots * fix: add 2015 to list of valid ModuleKinds
- Loading branch information
1 parent
cdd90c7
commit 8b1691e
Showing
15 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../shared/ava.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PluginContext } from 'rollup'; | ||
import { ModuleKind } from 'typescript'; | ||
|
||
import { TypeScriptConfig } from './options/tsconfig'; | ||
|
||
const moduleError = ` | ||
Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a | ||
"module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" | ||
in the target tsconfig.json file or plugin options.`.replace(/\n/g, ''); | ||
|
||
let undef; | ||
const validModules = [ModuleKind.ES2015, ModuleKind.ES2020, ModuleKind.ESNext, undef]; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const preflight = (config: TypeScriptConfig, context: PluginContext) => { | ||
if (!validModules.includes(config.options.module)) { | ||
context.warn(`@rollup/plugin-typescript: ${moduleError}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const answer = 42; | ||
// eslint-disable-next-line no-console | ||
console.log(`the answer is ${answer}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Snapshot report for `test/warnings.ts` | ||
|
||
The actual snapshot is saved in `warnings.ts.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## bad module in tsconfig | ||
|
||
> Snapshot 1 | ||
[ | ||
{ | ||
code: 'PLUGIN_WARNING', | ||
message: '@rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you\'re doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.', | ||
plugin: 'typescript', | ||
toString: Function {}, | ||
}, | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from 'ava'; | ||
import { rollup } from 'rollup'; | ||
|
||
import typescript from '..'; | ||
|
||
test.beforeEach(() => process.chdir(__dirname)); | ||
|
||
test.serial('bad module in tsconfig', async (t) => { | ||
const warnings: any[] = []; | ||
await rollup({ | ||
input: 'fixtures/bad-module/main.ts', | ||
plugins: [typescript({ tsconfig: 'fixtures/bad-module/tsconfig.json' })], | ||
onwarn: (warning) => warnings.push(warning) | ||
}); | ||
|
||
t.snapshot(warnings); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
extensions: ['js', 'ts'], | ||
files: ['!**/fixtures/**', '!**/output/**', '!**/helpers/**', '!**/recipes/**', '!**/types.ts'], | ||
require: ['ts-node/register', 'esm'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.base.json", | ||
"include": ["packages", "scripts", "util"] | ||
"include": ["packages", "scripts", "shared", "util"] | ||
} |