Skip to content

Commit d6f988c

Browse files
NotWoodsshellscape
authored andcommitted
chore: migrate rollup-plugin-typescript (rollup#59)
* chore: migrate rollup-plugin-typescript * feat: add support for tsconfig with extendsCo-authored-by: Tobias Lundin <[email protected]> * chore: Update README for typescript plugin
1 parent af2f8f1 commit d6f988c

File tree

47 files changed

+1246
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1246
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/typescript/CHANGELOG.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# @rollup/plugin-typescript changelog
2+
3+
## 2.0.0
4+
5+
_2019-11-25_
6+
7+
- **Breaking:** Minimum compatible Rollup version is 1.2.0
8+
- **Breaking:** Minimum supported Node version is 8.0.0
9+
- Published as @rollup/plugin-typescript
10+
11+
## 1.0.1
12+
13+
_2019-03-24_
14+
15+
- Update dependencies ([#136](https://github.com/rollup/rollup-plugin-typescript/issues/136))
16+
17+
## 1.0.0
18+
19+
_2018-09-16_
20+
21+
- Major update for TypeScript 2/3, Rollup 1 compatibility, lots of fixes ([#124](https://github.com/rollup/rollup-plugin-typescript/issues/124))
22+
- Require TypeScript as peer dependency ([#121](https://github.com/rollup/rollup-plugin-typescript/issues/121))
23+
- Also test on Node 10 ([#119](https://github.com/rollup/rollup-plugin-typescript/issues/119))
24+
- Fix example in readme ([#98](https://github.com/rollup/rollup-plugin-typescript/issues/98))
25+
26+
## 0.8.1
27+
28+
- Ignore typescript-helpers in source maps ([#61](https://github.com/rollup/rollup-plugin-typescript/issues/61))
29+
30+
## 0.8.0
31+
32+
- Fix the rollup breaking change with paths ([#52](https://github.com/rollup/rollup-plugin-typescript/issues/52))
33+
- Don't fail without source maps ([#57](https://github.com/rollup/rollup-plugin-typescript/pull/57))
34+
35+
## 0.7.7
36+
37+
- Add missing `__assign` helper ([#49](https://github.com/rollup/rollup-plugin-typescript/issues/49))
38+
39+
## 0.7.6
40+
41+
- Ignore the `declaration` option ([#45](https://github.com/rollup/rollup-plugin-typescript/issues/45))
42+
- Disable `strictNullChecks` with a warning for TypeScript versions that don't support it ([#46](https://github.com/rollup/rollup-plugin-typescript/issues/46))
43+
44+
## 0.7.5
45+
46+
- Ensure NPM doesn't ignore typescript-helpers
47+
48+
## 0.7.4
49+
50+
- Resolve typescript-helpers to a file in the filesystem.
51+
52+
## 0.7.3
53+
54+
- Update Tippex to ^2.1.1
55+
56+
## 0.7.2
57+
58+
- Don't error if both `sourceMap` and `inlineSourceMap` are specified
59+
60+
## 0.7.1
61+
62+
- No plugin specific options should be forwarded to TypeScript
63+
64+
## 0.7.0
65+
66+
- Use `compilerOptions` from `tsconfig.json` if found ([#39](https://github.com/rollup/rollup-plugin-typescript/pull/32))
67+
68+
## 0.6.1
69+
70+
- Upgrade Tippex to ^2.1.0
71+
- Upgrade TypeScript to ^1.8.9
72+
73+
## 0.6.0
74+
75+
- Upgrade to TypeScript ^1.8.7
76+
- Update `__awaiter` helper to support TypeScript 1.8.x ([#32](https://github.com/rollup/rollup-plugin-typescript/pull/32))
77+
- Update `ts.nodeModuleNameResolver` to support both 1.7.x and 1.8.x ([#31](https://github.com/rollup/rollup-plugin-typescript/issues/31))
78+
79+
## 0.5.0
80+
81+
- Do not duplicate TypeScript's helpers ([#24](https://github.com/rollup/rollup-plugin-typescript/issues/24))
82+
- Handle `export abstract class` ([#23](https://github.com/rollup/rollup-plugin-typescript/issues/23))
83+
84+
## 0.4.1
85+
86+
- Does not attempt resolve or transform `.d.ts` files ([#22](https://github.com/rollup/rollup-plugin-typescript/pull/22))
87+
88+
## 0.4.0
89+
90+
- Work around TypeScript 1.7.5's transpilation issues ([#9](https://github.com/rollup/rollup-plugin-typescript/issues/9))
91+
- Overridable TypeScript version when transpiling ([#4](https://github.com/rollup/rollup-plugin-typescript/issues/4))
92+
- Add `jsx` support ([#11](https://github.com/rollup/rollup-plugin-typescript/issues/11))
93+
94+
## 0.3.0
95+
96+
- Author plugin in TypeScript
97+
- Report diagnostics
98+
- Resolve identifiers using `ts.nodeModuleNameResolver`
99+
100+
## 0.2.1
101+
102+
- Upgrade to TypeScript ^1.7.5
103+
- Enable source maps per default
104+
105+
## 0.2.0
106+
107+
- Use (_prerelease version of_) TypeScript 1.7.0 to generate ES5 while preserving ES2015 imports for efficient bundling.
108+
109+
## 0.1.0
110+
111+
- Initial release

packages/typescript/README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
[npm]: https://img.shields.io/npm/v/@rollup/plugin-typescript
2+
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-typescript
3+
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-typescript
4+
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-typescript
5+
6+
[![npm][npm]][npm-url]
7+
[![size][size]][size-url]
8+
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9+
10+
# @rollup/plugin-typescript
11+
12+
🍣 A Rollup plugin for seamless integration between Rollup and Typescript.
13+
14+
## Requirements
15+
16+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. Due to the use of `tslib` to inject helpers, this plugin requires at least [TypeScript 2.1](https://github.com/Microsoft/TypeScript/wiki/Roadmap#21-december-2016). See also [here](https://blog.mariusschulz.com/2016/12/16/typescript-2-1-external-helpers-library#the-importhelpers-flag-and-tslib).
17+
18+
## Install
19+
20+
Using npm:
21+
22+
```console
23+
npm install @rollup/plugin-typescript --save-dev
24+
```
25+
26+
Note that both `typescript` and `tslib` are peer dependencies of this plugin that need to be installed separately.
27+
28+
## Why?
29+
30+
See [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).
31+
32+
## Usage
33+
34+
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
35+
36+
```js
37+
// rollup.config.js
38+
import typescript from '@rollup/plugin-typescript';
39+
40+
export default {
41+
input: 'src/index.ts',
42+
output: {
43+
dir: 'output',
44+
format: 'cjs'
45+
},
46+
plugins: [typescript()]
47+
};
48+
```
49+
50+
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
51+
52+
## Options
53+
54+
The plugin loads any [`compilerOptions`](http://www.typescriptlang.org/docs/handbook/compiler-options.html) from the `tsconfig.json` file by default. Passing options to the plugin directly overrides those options:
55+
56+
```js
57+
...
58+
export default {
59+
input: './main.ts',
60+
plugins: [
61+
typescript({lib: ["es5", "es6", "dom"], target: "es5"})
62+
]
63+
}
64+
```
65+
66+
The following options are unique to `rollup-plugin-typescript`:
67+
68+
### `exclude`
69+
70+
Type: `String` | `Array[...String]`
71+
Default: `null`
72+
73+
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
74+
75+
### `include`
76+
77+
Type: `String` | `Array(String)`
78+
Default: `null`
79+
80+
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all `.ts` and `.tsx` files are targeted.
81+
82+
### `tsconfig`
83+
84+
Type: `String` | `Boolean`
85+
Default: `true`
86+
87+
When set to false, ignores any options specified in the config file. If set to a string that corresponds to a file path, the specified file will be used as config file.
88+
89+
### `typescript`
90+
91+
Type: `import('typescript')`
92+
Default: _peer dependency_
93+
94+
Overrides the TypeScript module used for transpilation.
95+
96+
```js
97+
typescript({
98+
typescript: require('some-fork-of-typescript')
99+
});
100+
```
101+
102+
### `tslib`
103+
104+
Type: `import('tslib')`
105+
Default: _peer dependency_
106+
107+
Overrides the injected TypeScript helpers with a custom version
108+
109+
```js
110+
typescript({
111+
tslib: require('some-fork-of-tslib')
112+
});
113+
```
114+
115+
### Importing CommonJS
116+
117+
Though it is not recommended, it is possible to configure this plugin to handle imports of CommonJS files from TypeScript. For this, you need to specify `CommonJS` as the module format and add `rollup-plugin-commonjs` to transpile the CommonJS output generated by TypeScript to ES Modules so that rollup can process it.
118+
119+
```js
120+
// rollup.config.js
121+
import typescript from 'rollup-plugin-typescript';
122+
import commonjs from 'rollup-plugin-commonjs';
123+
124+
export default {
125+
input: './main.ts',
126+
plugins: [
127+
typescript({ module: 'CommonJS' }),
128+
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
129+
]
130+
};
131+
```
132+
133+
Note that this will often result in less optimal output.
134+
135+
## Issues
136+
137+
This plugin will currently **not warn for any type violations**. This plugin relies on TypeScript's [transpileModule](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function) function which basically transpiles TypeScript to JavaScript by stripping any type information on a per-file basis. While this is faster than using the language service, no cross-file type checks are possible with this approach.
138+
139+
This also causes issues with emit-less types, see [rollup/rollup-plugin-typescript#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).
140+
141+
## Meta
142+
143+
[CONTRIBUTING](/.github/CONTRIBUTING.md)
144+
145+
[LICENSE (MIT)](/LICENSE)

packages/typescript/index.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Plugin } from 'rollup';
2+
import { CompilerOptionsValue, TsConfigSourceFile } from 'typescript';
3+
4+
interface RollupTypescriptOptions {
5+
/**
6+
* Determine which files are transpiled by Typescript (all `.ts` and
7+
* `.tsx` files by default).
8+
*/
9+
include?: string | RegExp | ReadonlyArray<string | RegExp> | null;
10+
/**
11+
* Determine which files are transpiled by Typescript (all `.ts` and
12+
* `.tsx` files by default).
13+
*/
14+
exclude?: string | RegExp | ReadonlyArray<string | RegExp> | null;
15+
/**
16+
* When set to false, ignores any options specified in the config file.
17+
* If set to a string that corresponds to a file path, the specified file
18+
* will be used as config file.
19+
*/
20+
tsconfig?: string | false;
21+
/**
22+
* Overrides TypeScript used for transpilation
23+
*/
24+
typescript?: typeof import('typescript');
25+
/**
26+
* Overrides the injected TypeScript helpers with a custom version
27+
*/
28+
tslib?: typeof import('tslib');
29+
30+
/**
31+
* Other Typescript compiler options
32+
*/
33+
[option: string]:
34+
| CompilerOptionsValue
35+
| TsConfigSourceFile
36+
| RollupTypescriptOptions['include']
37+
| RollupTypescriptOptions['typescript']
38+
| RollupTypescriptOptions['tslib']
39+
| undefined;
40+
}
41+
42+
/**
43+
* Seamless integration between Rollup and Typescript.
44+
*/
45+
export default function typescript(options?: RollupTypescriptOptions): Plugin;

packages/typescript/package.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@rollup/plugin-typescript",
3+
"version": "2.0.0",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"description": "Seamless integration between Rollup and TypeScript.",
8+
"license": "MIT",
9+
"repository": "rollup/plugins",
10+
"author": "Oskar Segersvärd",
11+
"homepage": "https://github.com/rollup/plugins/packages/typescript/#readme",
12+
"bugs": "https://github.com/rollup/plugins/issues",
13+
"main": "dist/index.js",
14+
"engines": {
15+
"node": ">=8.0.0"
16+
},
17+
"scripts": {
18+
"build": "rollup -c",
19+
"ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov",
20+
"ci:lint": "pnpm run build && pnpm run lint && pnpm run security",
21+
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
22+
"ci:test": "pnpm run test -- --verbose",
23+
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
24+
"lint:docs": "prettier --single-quote --write README.md",
25+
"lint:js": "eslint --fix --cache src test",
26+
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
27+
"prebuild": "del-cli dist",
28+
"prepare": "pnpm run build",
29+
"prepublishOnly": "pnpm run lint",
30+
"pretest": "pnpm run build",
31+
"security": "echo 'pnpm needs `npm audit` support'",
32+
"test": "ava"
33+
},
34+
"files": [
35+
"dist",
36+
"index.d.ts",
37+
"README.md",
38+
"LICENSE"
39+
],
40+
"keywords": [
41+
"rollup",
42+
"plugin",
43+
"typescript",
44+
"es2015"
45+
],
46+
"peerDependencies": {
47+
"rollup": "^1.20.0",
48+
"tslib": "*",
49+
"typescript": ">=2.1.0"
50+
},
51+
"dependencies": {
52+
"@rollup/pluginutils": "^3.0.0",
53+
"resolve": "^1.12.2"
54+
},
55+
"devDependencies": {
56+
"@rollup/plugin-buble": "^0.20.0",
57+
"buble": "^0.19.8",
58+
"rollup": "^1.27.5",
59+
"rollup-plugin-commonjs": "^9.3.4",
60+
"tslib": "^1.10.0",
61+
"typescript": "^3.7.2"
62+
},
63+
"ava": {
64+
"files": [
65+
"!**/fixtures/**",
66+
"!**/output/**",
67+
"!**/helpers/**",
68+
"!**/recipes/**",
69+
"!**/types.ts"
70+
]
71+
},
72+
"jsnext:main": "dist/index.es.js",
73+
"module": "dist/index.es.js"
74+
}

0 commit comments

Comments
 (0)