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

feat(babel): add typings #462

Merged
merged 10 commits into from Jul 7, 2020
10 changes: 7 additions & 3 deletions packages/babel/package.json
Expand Up @@ -25,12 +25,14 @@
"lint:js": "eslint --fix --cache src test",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run build",
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run build && pnpm run test:ts",
"pretest": "pnpm run build",
"test": "ava"
"test": "ava",
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
},
"files": [
"dist",
"types",
"README.md",
"LICENSE"
],
Expand Down Expand Up @@ -58,6 +60,7 @@
"@babel/plugin-transform-runtime": "^7.7.4",
"@babel/preset-env": "^7.9.0",
"@rollup/plugin-json": "^4.0.0",
"@types/babel__core": "^7.1.8",
AndrewLeedham marked this conversation as resolved.
Show resolved Hide resolved
"rollup": "^2.0.0",
"source-map": "^0.6.1"
},
Expand All @@ -73,5 +76,6 @@
"Bogdan Chadkin <trysound@yandex.ru>",
"Mateusz Burzyński <mateuszburzynski@gmail.com> (https://github.com/Andarist)"
],
"module": "dist/index.es.js"
"module": "dist/index.es.js",
"types": "types/index.d.ts"
}
22 changes: 22 additions & 0 deletions packages/babel/test/types.ts
@@ -0,0 +1,22 @@
import babel from '../types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import babel from '../types';
import babel from '../';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


const config: import('rollup').RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
babel({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**', /node_modules/],
extensions: ['.js', '.coffee'],
babelHelpers: 'runtime',
skipPreflightCheck: true,
babelrc: false,
plugins: []
})
]
};

export default config;
38 changes: 38 additions & 0 deletions packages/babel/types/index.d.ts
@@ -0,0 +1,38 @@
import { Plugin } from 'rollup';
import { FilterPattern } from '@rollup/pluginutils';
import { TransformOptions } from '@babel/core';

interface RollupBabelOptions extends Omit<TransformOptions, 'include' | 'exclude'> {
AndrewLeedham marked this conversation as resolved.
Show resolved Hide resolved
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. When relying on Babel configuration files you cannot include files already excluded there.
* @default undefined;
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. When relaying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.
* @default undefined;
*/
exclude?: FilterPattern;
/**
* An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include .ts and .tsx in this option.
* @default ['.js', '.jsx', '.es6', '.es', '.mjs']
*/
extensions?: string[];
/**
* It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
* @default 'bundled'
*/
babelHelpers?: 'bundled' | 'runtime' | 'inline' | 'extends';
AndrewLeedham marked this conversation as resolved.
Show resolved Hide resolved
/**
* Before transpiling your input files this plugin also transpile a short piece of code for each input file. This is used to validate some misconfiguration errors, but for sufficiently big projects it can slow your build times so if you are confident about your configuration then you might disable those checks with this option.
* @default false
*/
skipPreflightCheck?: boolean;
}

/**
* A Rollup plugin for seamless integration between Rollup and Babel.
* @param options - Plugin options.
* @returns Plugin instance.
*/
export default function babel(options?: RollupBabelOptions): Plugin;
AndrewLeedham marked this conversation as resolved.
Show resolved Hide resolved
114 changes: 86 additions & 28 deletions pnpm-lock.yaml

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