diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..3677161 --- /dev/null +++ b/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 + /** + * search for files other than .js files (must already + * be transpiled by a previous plugin!) + * @default [ '.js' ] + */ + extensions: ReadonlyArray, + /** + * 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 }, + /** + * 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 boolean)>, +} + +/** + * Convert CommonJS modules to ES6, so they can be included in a Rollup bundle + */ +export default function commonjs(options?: RollupCommonJSOptions): Plugin; diff --git a/package-lock.json b/package-lock.json index a159b05..4c949c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2537,7 +2537,7 @@ "glob": "7.1.3", "growl": "1.10.5", "he": "1.2.0", - "js-yaml": "^3.13.0", + "js-yaml": "3.12.0", "log-symbols": "2.2.0", "minimatch": "3.0.4", "mkdirp": "0.5.1", @@ -3816,6 +3816,12 @@ "prelude-ls": "~1.1.2" } }, + "typescript": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.1.tgz", + "integrity": "sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q==", + "dev": true + }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", diff --git a/package.json b/package.json index 680b55a..3590854 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..842f6de --- /dev/null +++ b/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" + ] +} diff --git a/typings-test.js b/typings-test.js new file mode 100644 index 0000000..fa0eef1 --- /dev/null +++ b/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;