Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 79151ef

Browse files
NotWoodslukastaegert
authored andcommitted
Add .d.ts typings file (#363)
* Add .d.ts typings file * Run typecheck in test script * Move typings-test back out so jest isn't triggered
1 parent 1081282 commit 79151ef

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

index.d.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Plugin } from 'rollup';
2+
3+
interface RollupCommonJSOptions {
4+
/**
5+
* non-CommonJS modules will be ignored, but you can also
6+
* specifically include/exclude files
7+
* @default undefined
8+
*/
9+
include?: string | RegExp,
10+
/**
11+
* non-CommonJS modules will be ignored, but you can also
12+
* specifically include/exclude files
13+
* @default undefined
14+
*/
15+
exclude?: ReadonlyArray<string | RegExp>
16+
/**
17+
* search for files other than .js files (must already
18+
* be transpiled by a previous plugin!)
19+
* @default [ '.js' ]
20+
*/
21+
extensions: ReadonlyArray<string | RegExp>,
22+
/**
23+
* if true then uses of `global` won't be dealt with by this plugin
24+
* @default false
25+
*/
26+
ignoreGlobal?: boolean,
27+
/**
28+
* if false then skip sourceMap generation for CommonJS modules
29+
* @default true
30+
*/
31+
sourceMap?: boolean,
32+
/**
33+
* explicitly specify unresolvable named exports
34+
* ([see below for more details](https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports))
35+
* @default undefined
36+
*/
37+
namedExports?: { [package: string]: ReadonlyArray<string> },
38+
/**
39+
* sometimes you have to leave require statements
40+
* unconverted. Pass an array containing the IDs
41+
* or a `id => boolean` function. Only use this
42+
* option if you know what you're doing!
43+
*/
44+
ignore?: ReadonlyArray<string | ((id: string) => boolean)>,
45+
}
46+
47+
/**
48+
* Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
49+
*/
50+
export default function commonjs(options?: RollupCommonJSOptions): Plugin;

package-lock.json

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"jsnext:main": "dist/rollup-plugin-commonjs.es.js",
88
"scripts": {
99
"test": "npm run test:only",
10-
"test:only": "mocha",
10+
"test:only": "mocha && tsc",
1111
"pretest": "npm run build",
1212
"build": "shx rm -rf dist/* && rollup -c",
1313
"dev": "rollup -c -w",
@@ -44,7 +44,8 @@
4444
"rollup-plugin-node-resolve": "^4.0.1",
4545
"shx": "^0.3.2",
4646
"source-map": "^0.7.3",
47-
"source-map-support": "^0.5.11"
47+
"source-map-support": "^0.5.11",
48+
"typescript": "^3.4.1"
4849
},
4950
"repository": "rollup/rollup-plugin-commonjs",
5051
"author": "Rich Harris",

tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"es6"
5+
],
6+
"noImplicitAny": true,
7+
"noImplicitThis": true,
8+
"strict": true,
9+
"noEmit": true,
10+
"allowJs": true
11+
},
12+
"files": [
13+
"index.d.ts",
14+
"typings-test.js"
15+
]
16+
}

typings-test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @ts-check
2+
import commonjs from '.';
3+
4+
/** @type {import("rollup").RollupOptions} */
5+
const config = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
commonjs({
13+
include: 'node_modules/**',
14+
exclude: [ 'node_modules/foo/**', 'node_modules/bar/**', /node_modules/ ],
15+
extensions: [ '.js', '.coffee' ],
16+
ignoreGlobal: false,
17+
sourceMap: false,
18+
namedExports: { './module.js': ['foo', 'bar' ] },
19+
ignore: [ 'conditional-runtime-dependency' ]
20+
})
21+
]
22+
};
23+
24+
export default config;

0 commit comments

Comments
 (0)