From 2e53ec2fa1eb30a4df88555bd2748005965055bd Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Thu, 13 Dec 2018 00:06:46 -0800 Subject: [PATCH 1/3] Add .d.ts typings file --- index.d.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ typings-test.js | 24 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 index.d.ts create mode 100644 typings-test.js 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/typings-test.js b/typings-test.js new file mode 100644 index 0000000..5967ed4 --- /dev/null +++ b/typings-test.js @@ -0,0 +1,24 @@ +// @ts-check +import commonjs from '.'; + +/** @type {import("rollup").RollupFileOptions} */ +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; From 373fbd2272a23de05c788bfb86c7ab997897af69 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Mon, 1 Apr 2019 22:26:49 -0700 Subject: [PATCH 2/3] Run typecheck in test script --- package-lock.json | 8 +++++++- package.json | 8 +++++--- typings-test.js => test/typings-test.js | 4 ++-- tsconfig.json | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) rename typings-test.js => test/typings-test.js (85%) create mode 100644 tsconfig.json diff --git a/package-lock.json b/package-lock.json index 0cd9719..91a58ef 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 97cf96f..c722e1f 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,14 @@ "module": "dist/rollup-plugin-commonjs.es.js", "jsnext:main": "dist/rollup-plugin-commonjs.es.js", "scripts": { - "test": "npm run test:only", + "test": "npm run test:only && npm run test:ts", "test:only": "mocha", + "test:ts": "tsc", "pretest": "npm run build", "build": "shx rm -rf dist/* && rollup -c", "dev": "rollup -c -w", "lint": "prettier --write src/**/*.js test/test.js test/**/_config.js && eslint --fix src/**/*.js test/test.js test/**/_config.js", - "prepublishOnly": "npm run lint && npm run test:only", + "prepublishOnly": "npm run lint && npm run test:only && npm run test:ts", "prepare": "npm run build" }, "files": [ @@ -44,7 +45,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/typings-test.js b/test/typings-test.js similarity index 85% rename from typings-test.js rename to test/typings-test.js index 5967ed4..949ea73 100644 --- a/typings-test.js +++ b/test/typings-test.js @@ -1,7 +1,7 @@ // @ts-check -import commonjs from '.'; +import commonjs from '..'; -/** @type {import("rollup").RollupFileOptions} */ +/** @type {import("rollup").RollupOptions} */ const config = { input: 'main.js', output: { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a827545 --- /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", + "test/typings-test.js" + ] +} From 3e6c3290273c6ea7240ad338cdbcc9328cbf0a0b Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Mon, 1 Apr 2019 22:29:10 -0700 Subject: [PATCH 3/3] Move typings-test back out so jest isn't triggered --- package.json | 7 +++---- tsconfig.json | 2 +- test/typings-test.js => typings-test.js | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) rename test/typings-test.js => typings-test.js (94%) diff --git a/package.json b/package.json index c722e1f..455c8c3 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,13 @@ "module": "dist/rollup-plugin-commonjs.es.js", "jsnext:main": "dist/rollup-plugin-commonjs.es.js", "scripts": { - "test": "npm run test:only && npm run test:ts", - "test:only": "mocha", - "test:ts": "tsc", + "test": "npm run test:only", + "test:only": "mocha && tsc", "pretest": "npm run build", "build": "shx rm -rf dist/* && rollup -c", "dev": "rollup -c -w", "lint": "prettier --write src/**/*.js test/test.js test/**/_config.js && eslint --fix src/**/*.js test/test.js test/**/_config.js", - "prepublishOnly": "npm run lint && npm run test:only && npm run test:ts", + "prepublishOnly": "npm run lint && npm run test:only", "prepare": "npm run build" }, "files": [ diff --git a/tsconfig.json b/tsconfig.json index a827545..842f6de 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,6 @@ }, "files": [ "index.d.ts", - "test/typings-test.js" + "typings-test.js" ] } diff --git a/test/typings-test.js b/typings-test.js similarity index 94% rename from test/typings-test.js rename to typings-test.js index 949ea73..fa0eef1 100644 --- a/test/typings-test.js +++ b/typings-test.js @@ -1,5 +1,5 @@ // @ts-check -import commonjs from '..'; +import commonjs from '.'; /** @type {import("rollup").RollupOptions} */ const config = {