[Pkg-javascript-commits] [node-rollup-plugin-commonjs] 01/03: New upstream version 8.3.0

Julien Puydt julien.puydt at laposte.net
Tue Jan 30 13:31:41 UTC 2018


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-rollup-plugin-commonjs.

commit cb1b2a4c645144f05ee8ef3e9f8a642b9e5164c4
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Tue Jan 30 13:56:48 2018 +0100

    New upstream version 8.3.0
---
 .travis.yml                                   |  2 ++
 CHANGELOG.md                                  |  7 +++++
 appveyor.yml                                  |  1 +
 package-lock.json                             | 16 +++++------
 package.json                                  | 12 +++++----
 rollup.config.js                              |  7 ++---
 src/index.js                                  | 24 ++++++++---------
 src/transform.js                              | 12 ++++-----
 test/form/constant-template-literal/input.js  |  2 ++
 test/form/constant-template-literal/output.js | 11 ++++++++
 test/form/dynamic-template-literal/input.js   |  3 +++
 test/form/dynamic-template-literal/output.js  | 12 +++++++++
 test/samples/multiple-entry-points/2.js       |  4 +++
 test/samples/multiple-entry-points/3.js       |  5 ++++
 test/samples/multiple-entry-points/4.js       |  3 +++
 test/samples/multiple-entry-points/b.js       |  5 ++++
 test/samples/multiple-entry-points/c.js       |  7 +++++
 test/test.js                                  | 39 ++++++++++++++++++++++++---
 18 files changed, 135 insertions(+), 37 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 007e08f..3519303 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,3 +6,5 @@ env:
   global:
     - BUILD_TIMEOUT=10000
 install: npm install
+before_install:
+  - if [[ $TRAVIS_NODE_VERSION -lt 7 ]]; then npm install --global npm at 4; fi
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dacf108..f0a031a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # rollup-plugin-commonjs changelog
 
+## 8.3.0
+
+* Handle multiple entry points ([#283](https://github.com/rollup/rollup-plugin-commonjs/issues/283))
+* Extract named exports from exported object literals ([#272](https://github.com/rollup/rollup-plugin-commonjs/issues/272))
+* Fix when `options.external` is modified by other plugins ([#264](https://github.com/rollup/rollup-plugin-commonjs/issues/264))
+* Recognize static template strings in require statements ([#271](https://github.com/rollup/rollup-plugin-commonjs/issues/271))
+
 ## 8.2.4
 
 * Don't import default from ES modules that don't export default ([#206](https://github.com/rollup/rollup-plugin-commonjs/issues/206))
diff --git a/appveyor.yml b/appveyor.yml
index 64ab3aa..0e41b72 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -14,6 +14,7 @@ environment:
 
 install:
   - ps: Install-Product node $env:nodejs_version
+  - IF %nodejs_version% LSS 7 npm -g install npm at 4
   - npm install
 
 build: off
diff --git a/package-lock.json b/package-lock.json
index bb7748c..93cd28b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,13 +1,13 @@
 {
   "name": "rollup-plugin-commonjs",
-  "version": "8.2.3",
+  "version": "8.3.0",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
     "acorn": {
-      "version": "5.1.2",
-      "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.1.2.tgz",
-      "integrity": "sha512-o96FZLJBPY1lvTuJylGA9Bk3t/GKPPJG8H0ydQQl01crzwJgspa4AEIq/pVTXigmK0PHVQhiAtn8WMBLL9D2WA=="
+      "version": "5.2.1",
+      "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz",
+      "integrity": "sha512-jG0u7c4Ly+3QkkW18V+NRDN+4bWHdln30NL1ZL2AvFZZmQe/BfopYCtghCKKVBUSetZ4QKcyA0pY6/4Gw8Pv8w=="
     },
     "acorn-jsx": {
       "version": "3.0.1",
@@ -525,7 +525,7 @@
       "integrity": "sha1-DJiLirRttTEAoZVK5LqZXd0n2H4=",
       "dev": true,
       "requires": {
-        "acorn": "5.1.2",
+        "acorn": "5.2.1",
         "acorn-jsx": "3.0.1"
       }
     },
@@ -1435,9 +1435,9 @@
       }
     },
     "rollup": {
-      "version": "0.50.0",
-      "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.50.0.tgz",
-      "integrity": "sha512-7RqCBQ9iwsOBPkjYgoIaeUij606mSkDMExP0NT7QDI3bqkHYQHrQ83uoNIXwPcQm/vP2VbsUz3kiyZZ1qPlLTQ==",
+      "version": "0.55.0",
+      "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.55.0.tgz",
+      "integrity": "sha512-uCwDXz2qHQ0XsPekrLIeIEORSF32Zfk1H057ENgb+sj84m10pWaG2YGQSvF8kvyf0WLcrzk2TzYuC/+iZP4hyA==",
       "dev": true
     },
     "rollup-plugin-buble": {
diff --git a/package.json b/package.json
index 3321c83..fd0d3d3 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,19 @@
 {
   "name": "rollup-plugin-commonjs",
-  "version": "8.2.4",
+  "version": "8.3.0",
   "description": "Convert CommonJS modules to ES2015",
   "main": "dist/rollup-plugin-commonjs.cjs.js",
   "module": "dist/rollup-plugin-commonjs.es.js",
   "jsnext:main": "dist/rollup-plugin-commonjs.es.js",
   "scripts": {
-    "test": "mocha",
+    "test": "npm run test:only",
+    "test:only": "mocha",
     "pretest": "npm run build",
     "build": "shx rm -rf dist/* && rollup -c",
     "dev": "rollup -c -w",
     "lint": "eslint src/*.js test/*.js",
-    "prepublish": "npm run lint && npm test"
+    "prepublishOnly": "npm run lint && npm run test:only",
+    "prepare": "npm run build"
   },
   "files": [
     "src",
@@ -19,7 +21,7 @@
     "README.md"
   ],
   "dependencies": {
-    "acorn": "^5.1.2",
+    "acorn": "^5.2.1",
     "estree-walker": "^0.5.0",
     "magic-string": "^0.22.4",
     "resolve": "^1.4.0",
@@ -30,7 +32,7 @@
     "locate-character": "^2.0.1",
     "mocha": "^4.0.1",
     "require-relative": "^0.8.7",
-    "rollup": "^0.50.0",
+    "rollup": "^0.55.0",
     "rollup-plugin-buble": "^0.16.0",
     "rollup-plugin-node-resolve": "^3.0.0",
     "shx": "^0.2.2",
diff --git a/rollup.config.js b/rollup.config.js
index 95c6aef..c9bd226 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -9,15 +9,16 @@ export default {
 		})
 	],
 	external: Object.keys( pkg.dependencies ).concat([ 'fs', 'path' ]),
-	sourcemap: true,
 	output: [
 		{
 			format: 'es',
-			file: pkg.module
+			file: pkg.module,
+			sourcemap: true
 		},
 		{
 			format: 'cjs',
-			file: pkg.main
+			file: pkg.main,
+			sourcemap: true
 		}
 	]
 };
diff --git a/src/index.js b/src/index.js
index 07950ac..f9c4f60 100644
--- a/src/index.js
+++ b/src/index.js
@@ -67,8 +67,7 @@ export default function commonjs ( options = {} ) {
 		Array.isArray( options.ignore ) ? id => ~options.ignore.indexOf( id ) :
 			() => false;
 
-	let entryModuleIdPromise = null;
-	let entryModuleId = null;
+	let entryModuleIdsPromise = null;
 
 	function resolveId ( importee, importer ) {
 		if ( importee === HELPERS_ID ) return importee;
@@ -124,18 +123,19 @@ export default function commonjs ( options = {} ) {
 				})
 				.filter( Boolean );
 
-			const isExternal = options.external ?
-				Array.isArray( options.external ) ? id => ~options.external.indexOf( id ) :
-					options.external :
-				() => false;
+			const isExternal = id => options.external ?
+				Array.isArray( options.external ) ? ~options.external.indexOf( id ) :
+					options.external(id) :
+				false;
 
 			resolvers.unshift( id => isExternal( id ) ? false : null );
 
 			resolveUsingOtherResolvers = first( resolvers );
 
-			entryModuleIdPromise = resolveId( options.input || options.entry ).then( resolved => {
-				entryModuleId = resolved;
-			});
+			const entryModules = [].concat( options.input || options.entry );
+			entryModuleIdsPromise = Promise.all(
+				entryModules.map( entry => resolveId( entry ))
+			);
 		},
 
 		resolveId,
@@ -157,7 +157,7 @@ export default function commonjs ( options = {} ) {
 
 				if (commonjsModules.has( actualId ))
 					return `import { __moduleExports } from ${JSON.stringify( actualId )}; export default __moduleExports;`;
-				else if (esModulesWithoutDefaultExport.includes(actualId))
+				else if (esModulesWithoutDefaultExport.indexOf(actualId) !== -1)
 					return `import * as ${name} from ${JSON.stringify( actualId )}; export default ${name};`;
 				else
 					return `import * as ${name} from ${JSON.stringify( actualId )}; export default ( ${name} && ${name}['default'] ) || ${name};`;
@@ -168,7 +168,7 @@ export default function commonjs ( options = {} ) {
 			if ( !filter( id ) ) return null;
 			if ( extensions.indexOf( extname( id ) ) === -1 ) return null;
 
-			return entryModuleIdPromise.then( () => {
+			return entryModuleIdsPromise.then( (entryModuleIds) => {
 				const {isEsModule, hasDefaultExport, ast} = checkEsModule( code, id );
 				if ( isEsModule ) {
 					if ( !hasDefaultExport )
@@ -182,7 +182,7 @@ export default function commonjs ( options = {} ) {
 					return;
 				}
 
-				const transformed = transformCommonjs( code, id, id === entryModuleId, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
+				const transformed = transformCommonjs( code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
 				if ( !transformed ) return;
 
 				commonjsModules.set( id, true );
diff --git a/src/transform.js b/src/transform.js
index eb12e45..817a163 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -91,14 +91,14 @@ export function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequi
 		if ( !node ) return;
 		if ( node.type !== 'CallExpression' ) return;
 		if ( node.callee.name !== 'require' || scope.contains( 'require' ) ) return;
-		if ( node.arguments.length !== 1 || node.arguments[0].type !== 'Literal' ) return; // TODO handle these weird cases?
+		if ( node.arguments.length !== 1 || (node.arguments[0].type !== 'Literal' && (node.arguments[0].type !== 'TemplateLiteral' || node.arguments[0].expressions.length > 0) ) ) return; // TODO handle these weird cases?
 		if ( ignoreRequire( node.arguments[0].value ) ) return;
 
 		return true;
 	}
 
 	function getRequired ( node, name ) {
-		const source = node.arguments[0].value;
+		const source = node.arguments[0].type === 'Literal' ? node.arguments[0].value : node.arguments[0].quasis[0].value.cooked;
 
 		const existing = required[ source ];
 		if ( existing === undefined ) {
@@ -359,10 +359,6 @@ export function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequi
 
 		wrapperStart = `var ${moduleName} = ${HELPERS_NAME}.createCommonjsModule(function (${args}) {\n`;
 		wrapperEnd = `\n});`;
-
-		Object.keys( namedExports )
-			.filter( key => !blacklist[ key ] )
-			.forEach( addExport );
 	} else {
 		const names = [];
 
@@ -396,6 +392,7 @@ export function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequi
 							str: declaration,
 							name
 						});
+						delete namedExports[name];
 					}
 
 					defaultExportPropertyAssignments.push( `${moduleName}.${name} = ${deconflicted};` );
@@ -409,6 +406,9 @@ export function transformCommonjs ( code, id, isEntry, ignoreGlobal, ignoreRequi
 			}\n};`;
 		}
 	}
+	Object.keys( namedExports )
+		.filter( key => !blacklist[ key ] )
+		.forEach( addExport );
 
 	const defaultExport = /__esModule/.test( code ) ?
 		`export default ${HELPERS_NAME}.unwrapExports(${moduleName});` :
diff --git a/test/form/constant-template-literal/input.js b/test/form/constant-template-literal/input.js
new file mode 100644
index 0000000..2a43283
--- /dev/null
+++ b/test/form/constant-template-literal/input.js
@@ -0,0 +1,2 @@
+var foo = require(`tape`);
+console.log(foo);
diff --git a/test/form/constant-template-literal/output.js b/test/form/constant-template-literal/output.js
new file mode 100644
index 0000000..781cf36
--- /dev/null
+++ b/test/form/constant-template-literal/output.js
@@ -0,0 +1,11 @@
+import 'tape';
+import foo from 'commonjs-proxy:tape';
+
+console.log(foo);
+
+var input = {
+
+};
+
+export default input;
+export { input as __moduleExports };
diff --git a/test/form/dynamic-template-literal/input.js b/test/form/dynamic-template-literal/input.js
new file mode 100644
index 0000000..12767b6
--- /dev/null
+++ b/test/form/dynamic-template-literal/input.js
@@ -0,0 +1,3 @@
+var pe = 'pe';
+var foo = require(`ta${pe}`);
+console.log(foo);
diff --git a/test/form/dynamic-template-literal/output.js b/test/form/dynamic-template-literal/output.js
new file mode 100644
index 0000000..514eb55
--- /dev/null
+++ b/test/form/dynamic-template-literal/output.js
@@ -0,0 +1,12 @@
+import * as commonjsHelpers from 'commonjsHelpers';
+
+var pe = 'pe';
+var foo = commonjsHelpers.commonjsRequire(`ta${pe}`);
+console.log(foo);
+
+var input = {
+
+};
+
+export default input;
+export { input as __moduleExports };
diff --git a/test/samples/multiple-entry-points/2.js b/test/samples/multiple-entry-points/2.js
new file mode 100644
index 0000000..0875d7d
--- /dev/null
+++ b/test/samples/multiple-entry-points/2.js
@@ -0,0 +1,4 @@
+function second () {
+	console.log('second');
+}
+exports.second = second;
\ No newline at end of file
diff --git a/test/samples/multiple-entry-points/3.js b/test/samples/multiple-entry-points/3.js
new file mode 100644
index 0000000..340f55e
--- /dev/null
+++ b/test/samples/multiple-entry-points/3.js
@@ -0,0 +1,5 @@
+function third () {
+	console.log('third');
+}
+
+exports.third = third;
diff --git a/test/samples/multiple-entry-points/4.js b/test/samples/multiple-entry-points/4.js
new file mode 100644
index 0000000..04404fe
--- /dev/null
+++ b/test/samples/multiple-entry-points/4.js
@@ -0,0 +1,3 @@
+export function fourth () {
+	console.log('fourth');
+}
diff --git a/test/samples/multiple-entry-points/b.js b/test/samples/multiple-entry-points/b.js
new file mode 100644
index 0000000..d348811
--- /dev/null
+++ b/test/samples/multiple-entry-points/b.js
@@ -0,0 +1,5 @@
+import { second } from './2';
+import { third } from './3';
+
+second();
+third();
diff --git a/test/samples/multiple-entry-points/c.js b/test/samples/multiple-entry-points/c.js
new file mode 100644
index 0000000..3025ef7
--- /dev/null
+++ b/test/samples/multiple-entry-points/c.js
@@ -0,0 +1,7 @@
+import { second } from './2';
+import { third } from './3';
+import { fourth } from './4';
+
+second();
+third();
+fourth();
diff --git a/test/test.js b/test/test.js
index 37655c2..f7f8723 100644
--- a/test/test.js
+++ b/test/test.js
@@ -130,17 +130,36 @@ describe( 'rollup-plugin-commonjs', () => {
 
 			let generatedLoc = locator( '42' );
 			let loc = smc.originalPositionFor( generatedLoc ); // 42
-			assert.equal( loc.source, 'samples/sourcemap/foo.js' );
+			assert.equal( loc.source, 'foo.js' );
 			assert.equal( loc.line, 1 );
 			assert.equal( loc.column, 15 );
 
 			generatedLoc = locator( 'log' );
 			loc = smc.originalPositionFor( generatedLoc ); // log
-			assert.equal( loc.source, 'samples/sourcemap/main.js' );
+			assert.equal( loc.source, 'main.js' );
 			assert.equal( loc.line, 2 );
 			assert.equal( loc.column, 8 );
 		});
 
+		it( 'supports multiple entry points for experimentalCodeSplitting', async () => {
+			const bundle = await rollup({
+				input: [
+					'samples/multiple-entry-points/b.js',
+					'samples/multiple-entry-points/c.js'
+				],
+				experimentalCodeSplitting: true,
+				plugins: [ commonjs() ]
+			});
+
+			const generated = await bundle.generate({
+				format: 'cjs',
+			});
+
+			assert.equal(Object.keys(generated).length, 3);
+			assert.equal(generated.hasOwnProperty('./b.js'), true);
+			assert.equal(generated.hasOwnProperty('./c.js'), true);
+		});
+
 		it( 'handles references to `global`', async () => {
 			const bundle = await rollup({
 				input: 'samples/global/main.js',
@@ -252,6 +271,20 @@ describe( 'rollup-plugin-commonjs', () => {
 			assert.equal( (await executeBundle( bundle )).exports, 42 );
 		});
 
+		it( 'identifies named exports from object literals', async () => {
+			const bundle = await rollup({
+				input: 'samples/named-exports-from-object-literal/main.js',
+				plugins: [ commonjs() ]
+			});
+
+			const { code } = await bundle.generate({
+				format: 'cjs'
+			});
+
+			const fn = new Function ( 'module', 'assert', code );
+			fn( {}, assert );
+		});
+
 		it( 'can ignore references to `global`', async () => {
 			const bundle = await rollup({
 				input: 'samples/ignore-global/main.js',
@@ -450,4 +483,4 @@ describe( 'rollup-plugin-commonjs', () => {
 			assert.equal( warns.length, 0 );
 		});
 	});
-});
\ No newline at end of file
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-rollup-plugin-commonjs.git



More information about the Pkg-javascript-commits mailing list