Skip to content

Commit

Permalink
chore: migrate rollup-plugin-typescript (#59)
Browse files Browse the repository at this point in the history
* chore: migrate rollup-plugin-typescript

* feat: add support for tsconfig with extendsCo-authored-by: Tobias Lundin <tobias.lundin@gmail.com>

* chore: Update README for typescript plugin
  • Loading branch information
NotWoods authored and shellscape committed Dec 2, 2019
1 parent af2f8f1 commit d6f988c
Show file tree
Hide file tree
Showing 47 changed files with 1,246 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/auto-install/test/fixtures/yarn-bare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/auto-install/test/fixtures/yarn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
111 changes: 111 additions & 0 deletions packages/typescript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# @rollup/plugin-typescript changelog

## 2.0.0

_2019-11-25_

- **Breaking:** Minimum compatible Rollup version is 1.2.0
- **Breaking:** Minimum supported Node version is 8.0.0
- Published as @rollup/plugin-typescript

## 1.0.1

_2019-03-24_

- Update dependencies ([#136](https://github.com/rollup/rollup-plugin-typescript/issues/136))

## 1.0.0

_2018-09-16_

- Major update for TypeScript 2/3, Rollup 1 compatibility, lots of fixes ([#124](https://github.com/rollup/rollup-plugin-typescript/issues/124))
- Require TypeScript as peer dependency ([#121](https://github.com/rollup/rollup-plugin-typescript/issues/121))
- Also test on Node 10 ([#119](https://github.com/rollup/rollup-plugin-typescript/issues/119))
- Fix example in readme ([#98](https://github.com/rollup/rollup-plugin-typescript/issues/98))

## 0.8.1

- Ignore typescript-helpers in source maps ([#61](https://github.com/rollup/rollup-plugin-typescript/issues/61))

## 0.8.0

- Fix the rollup breaking change with paths ([#52](https://github.com/rollup/rollup-plugin-typescript/issues/52))
- Don't fail without source maps ([#57](https://github.com/rollup/rollup-plugin-typescript/pull/57))

## 0.7.7

- Add missing `__assign` helper ([#49](https://github.com/rollup/rollup-plugin-typescript/issues/49))

## 0.7.6

- Ignore the `declaration` option ([#45](https://github.com/rollup/rollup-plugin-typescript/issues/45))
- Disable `strictNullChecks` with a warning for TypeScript versions that don't support it ([#46](https://github.com/rollup/rollup-plugin-typescript/issues/46))

## 0.7.5

- Ensure NPM doesn't ignore typescript-helpers

## 0.7.4

- Resolve typescript-helpers to a file in the filesystem.

## 0.7.3

- Update Tippex to ^2.1.1

## 0.7.2

- Don't error if both `sourceMap` and `inlineSourceMap` are specified

## 0.7.1

- No plugin specific options should be forwarded to TypeScript

## 0.7.0

- Use `compilerOptions` from `tsconfig.json` if found ([#39](https://github.com/rollup/rollup-plugin-typescript/pull/32))

## 0.6.1

- Upgrade Tippex to ^2.1.0
- Upgrade TypeScript to ^1.8.9

## 0.6.0

- Upgrade to TypeScript ^1.8.7
- Update `__awaiter` helper to support TypeScript 1.8.x ([#32](https://github.com/rollup/rollup-plugin-typescript/pull/32))
- Update `ts.nodeModuleNameResolver` to support both 1.7.x and 1.8.x ([#31](https://github.com/rollup/rollup-plugin-typescript/issues/31))

## 0.5.0

- Do not duplicate TypeScript's helpers ([#24](https://github.com/rollup/rollup-plugin-typescript/issues/24))
- Handle `export abstract class` ([#23](https://github.com/rollup/rollup-plugin-typescript/issues/23))

## 0.4.1

- Does not attempt resolve or transform `.d.ts` files ([#22](https://github.com/rollup/rollup-plugin-typescript/pull/22))

## 0.4.0

- Work around TypeScript 1.7.5's transpilation issues ([#9](https://github.com/rollup/rollup-plugin-typescript/issues/9))
- Overridable TypeScript version when transpiling ([#4](https://github.com/rollup/rollup-plugin-typescript/issues/4))
- Add `jsx` support ([#11](https://github.com/rollup/rollup-plugin-typescript/issues/11))

## 0.3.0

- Author plugin in TypeScript
- Report diagnostics
- Resolve identifiers using `ts.nodeModuleNameResolver`

## 0.2.1

- Upgrade to TypeScript ^1.7.5
- Enable source maps per default

## 0.2.0

- Use (_prerelease version of_) TypeScript 1.7.0 to generate ES5 while preserving ES2015 imports for efficient bundling.

## 0.1.0

- Initial release
145 changes: 145 additions & 0 deletions packages/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
[npm]: https://img.shields.io/npm/v/@rollup/plugin-typescript
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-typescript
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-typescript
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-typescript

[![npm][npm]][npm-url]
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)

# @rollup/plugin-typescript

🍣 A Rollup plugin for seamless integration between Rollup and Typescript.

## Requirements

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).

## Install

Using npm:

```console
npm install @rollup/plugin-typescript --save-dev
```

Note that both `typescript` and `tslib` are peer dependencies of this plugin that need to be installed separately.

## Why?

See [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).

## Usage

Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:

```js
// rollup.config.js
import typescript from '@rollup/plugin-typescript';

export default {
input: 'src/index.ts',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [typescript()]
};
```

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).

## Options

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:

```js
...
export default {
input: './main.ts',
plugins: [
typescript({lib: ["es5", "es6", "dom"], target: "es5"})
]
}
```

The following options are unique to `rollup-plugin-typescript`:

### `exclude`

Type: `String` | `Array[...String]`
Default: `null`

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.

### `include`

Type: `String` | `Array(String)`
Default: `null`

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.

### `tsconfig`

Type: `String` | `Boolean`
Default: `true`

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.

### `typescript`

Type: `import('typescript')`
Default: _peer dependency_

Overrides the TypeScript module used for transpilation.

```js
typescript({
typescript: require('some-fork-of-typescript')
});
```

### `tslib`

Type: `import('tslib')`
Default: _peer dependency_

Overrides the injected TypeScript helpers with a custom version

```js
typescript({
tslib: require('some-fork-of-tslib')
});
```

### Importing CommonJS

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.

```js
// rollup.config.js
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';

export default {
input: './main.ts',
plugins: [
typescript({ module: 'CommonJS' }),
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
]
};
```

Note that this will often result in less optimal output.

## Issues

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.

This also causes issues with emit-less types, see [rollup/rollup-plugin-typescript#28](https://github.com/rollup/rollup-plugin-typescript/issues/28).

## Meta

[CONTRIBUTING](/.github/CONTRIBUTING.md)

[LICENSE (MIT)](/LICENSE)
45 changes: 45 additions & 0 deletions packages/typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Plugin } from 'rollup';
import { CompilerOptionsValue, TsConfigSourceFile } from 'typescript';

interface RollupTypescriptOptions {
/**
* Determine which files are transpiled by Typescript (all `.ts` and
* `.tsx` files by default).
*/
include?: string | RegExp | ReadonlyArray<string | RegExp> | null;
/**
* Determine which files are transpiled by Typescript (all `.ts` and
* `.tsx` files by default).
*/
exclude?: string | RegExp | ReadonlyArray<string | RegExp> | null;
/**
* 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.
*/
tsconfig?: string | false;
/**
* Overrides TypeScript used for transpilation
*/
typescript?: typeof import('typescript');
/**
* Overrides the injected TypeScript helpers with a custom version
*/
tslib?: typeof import('tslib');

/**
* Other Typescript compiler options
*/
[option: string]:
| CompilerOptionsValue
| TsConfigSourceFile
| RollupTypescriptOptions['include']
| RollupTypescriptOptions['typescript']
| RollupTypescriptOptions['tslib']
| undefined;
}

/**
* Seamless integration between Rollup and Typescript.
*/
export default function typescript(options?: RollupTypescriptOptions): Plugin;
74 changes: 74 additions & 0 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "@rollup/plugin-typescript",
"version": "2.0.0",
"publishConfig": {
"access": "public"
},
"description": "Seamless integration between Rollup and TypeScript.",
"license": "MIT",
"repository": "rollup/plugins",
"author": "Oskar Segersvärd",
"homepage": "https://github.com/rollup/plugins/packages/typescript/#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "dist/index.js",
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"build": "rollup -c",
"ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm run build && pnpm run lint && pnpm run security",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --write README.md",
"lint:js": "eslint --fix --cache src test",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
"prepare": "pnpm run build",
"prepublishOnly": "pnpm run lint",
"pretest": "pnpm run build",
"security": "echo 'pnpm needs `npm audit` support'",
"test": "ava"
},
"files": [
"dist",
"index.d.ts",
"README.md",
"LICENSE"
],
"keywords": [
"rollup",
"plugin",
"typescript",
"es2015"
],
"peerDependencies": {
"rollup": "^1.20.0",
"tslib": "*",
"typescript": ">=2.1.0"
},
"dependencies": {
"@rollup/pluginutils": "^3.0.0",
"resolve": "^1.12.2"
},
"devDependencies": {
"@rollup/plugin-buble": "^0.20.0",
"buble": "^0.19.8",
"rollup": "^1.27.5",
"rollup-plugin-commonjs": "^9.3.4",
"tslib": "^1.10.0",
"typescript": "^3.7.2"
},
"ava": {
"files": [
"!**/fixtures/**",
"!**/output/**",
"!**/helpers/**",
"!**/recipes/**",
"!**/types.ts"
]
},
"jsnext:main": "dist/index.es.js",
"module": "dist/index.es.js"
}
Loading

0 comments on commit d6f988c

Please sign in to comment.