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

Add .d.ts typings file #363

Merged
merged 4 commits into from Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions index.d.ts
@@ -0,0 +1,50 @@
import { Plugin } from 'rollup';

interface RollupCommonJSOptions {
/**
* non-CommonJS modules will be ignored, but you can also
* specifically include/exclude files
* @default undefined
*/
include?: string | RegExp,
/**
* non-CommonJS modules will be ignored, but you can also
* specifically include/exclude files
* @default undefined
*/
exclude?: ReadonlyArray<string | RegExp>
/**
* search for files other than .js files (must already
* be transpiled by a previous plugin!)
* @default [ '.js' ]
*/
extensions: ReadonlyArray<string | RegExp>,
/**
* if true then uses of `global` won't be dealt with by this plugin
* @default false
*/
ignoreGlobal?: boolean,
/**
* if false then skip sourceMap generation for CommonJS modules
* @default true
*/
sourceMap?: boolean,
/**
* explicitly specify unresolvable named exports
* ([see below for more details](https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports))
* @default undefined
*/
namedExports?: { [package: string]: ReadonlyArray<string> },
/**
* sometimes you have to leave require statements
* unconverted. Pass an array containing the IDs
* or a `id => boolean` function. Only use this
* option if you know what you're doing!
*/
ignore?: ReadonlyArray<string | ((id: string) => boolean)>,
}

/**
* Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
*/
export default function commonjs(options?: RollupCommonJSOptions): Plugin;
8 changes: 7 additions & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"jsnext:main": "dist/rollup-plugin-commonjs.es.js",
"scripts": {
"test": "npm run test:only",
"test:only": "mocha",
"test:only": "mocha && tsc",
"pretest": "npm run build",
"build": "shx rm -rf dist/* && rollup -c",
"dev": "rollup -c -w",
Expand Down Expand Up @@ -44,7 +44,8 @@
"rollup-plugin-node-resolve": "^4.0.1",
"shx": "^0.3.2",
"source-map": "^0.7.3",
"source-map-support": "^0.5.11"
"source-map-support": "^0.5.11",
"typescript": "^3.4.1"
},
"repository": "rollup/rollup-plugin-commonjs",
"author": "Rich Harris",
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"noEmit": true,
"allowJs": true
},
"files": [
"index.d.ts",
"typings-test.js"
]
}
24 changes: 24 additions & 0 deletions typings-test.js
@@ -0,0 +1,24 @@
// @ts-check
import commonjs from '.';

/** @type {import("rollup").RollupOptions} */
const config = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
commonjs({
include: 'node_modules/**',
exclude: [ 'node_modules/foo/**', 'node_modules/bar/**', /node_modules/ ],
extensions: [ '.js', '.coffee' ],
ignoreGlobal: false,
sourceMap: false,
namedExports: { './module.js': ['foo', 'bar' ] },
ignore: [ 'conditional-runtime-dependency' ]
})
]
};

export default config;