From 7837fc58cf19850636428039b6915493ce10e36b Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 5 Apr 2019 08:47:04 +0200 Subject: [PATCH] Test that rollup-plugin-commonjs works with preserveModules (#2792) * Extend filename sanitation and test that rollup-plugin-commonjs works with preserveModules * Just adapt tests as replacing : does not work nicely on windows --- package-lock.json | 82 +++++++++++++++++-- package.json | 2 +- .../preserve-modules-commonjs/_config.js | 11 +++ .../amd/_virtual/_commonjs-external-external | 9 ++ .../_expected/amd/_virtual/other.js | 7 ++ .../_expected/amd/commonjs.js | 14 ++++ .../_expected/amd/main.js | 7 ++ .../_expected/amd/other.js | 12 +++ .../cjs/_virtual/_commonjs-external-external | 9 ++ .../_expected/cjs/_virtual/other.js | 7 ++ .../_expected/cjs/commonjs.js | 15 ++++ .../_expected/cjs/main.js | 8 ++ .../_expected/cjs/other.js | 10 +++ .../es/_virtual/_commonjs-external-external | 5 ++ .../_expected/es/_virtual/other.js | 5 ++ .../_expected/es/commonjs.js | 13 +++ .../_expected/es/main.js | 4 + .../_expected/es/other.js | 7 ++ .../_virtual/_commonjs-external-external | 14 ++++ .../_expected/system/_virtual/other.js | 14 ++++ .../_expected/system/commonjs.js | 21 +++++ .../_expected/system/main.js | 16 ++++ .../_expected/system/other.js | 14 ++++ .../preserve-modules-commonjs/commonjs.js | 6 ++ .../samples/preserve-modules-commonjs/main.js | 4 + .../preserve-modules-commonjs/other.js | 1 + 26 files changed, 307 insertions(+), 10 deletions(-) create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_config.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_commonjs-external-external create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/_commonjs-external-external create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/commonjs.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/_commonjs-external-external create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/es/commonjs.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/es/main.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/es/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/_commonjs-external-external create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/system/commonjs.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/system/main.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/_expected/system/other.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/commonjs.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/main.js create mode 100644 test/chunking-form/samples/preserve-modules-commonjs/other.js diff --git a/package-lock.json b/package-lock.json index 0dfbc632000..dd6035a1f2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1869,7 +1869,50 @@ "has-unicode": "^2.0.0", "object-assign": "^4.1.0", "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", "wide-align": "^1.1.0" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "dev": true, + "optional": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "dev": true, + "optional": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "optional": true, + "requires": { + "ansi-regex": "^2.0.0" + } + } } }, "get-caller-file": { @@ -3338,7 +3381,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", @@ -3467,12 +3510,26 @@ "detect-libc": "^1.0.2", "mkdirp": "^0.5.1", "needle": "^2.2.1", + "nopt": "^4.0.1", "npm-packlist": "^1.1.6", "npmlog": "^4.0.2", "rc": "^1.2.7", "rimraf": "^2.6.1", "semver": "^5.3.0", "tar": "^4" + }, + "dependencies": { + "nopt": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", + "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "dev": true, + "optional": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + } } }, "nopt": { @@ -3708,8 +3765,7 @@ "os-homedir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" }, "os-locale": { "version": "3.1.0", @@ -3725,8 +3781,16 @@ "os-tmpdir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", - "dev": true + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } }, "p-defer": { "version": "1.0.0", @@ -4264,15 +4328,15 @@ } }, "rollup-plugin-commonjs": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-9.3.1.tgz", - "integrity": "sha512-RuOmsomyM9gbgV4OikMSdB3Nq5aqi7MOIXje6nT5JeRPrwWlT/qZ7Ve4xxh5i08W6BxTLS9T8P2B+KcSj2sSTw==", + "version": "9.3.3", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-9.3.3.tgz", + "integrity": "sha512-p/zVsRv/Vp67CRuDjtpF7LTlRze+CZFSwdDJFUtWfk4Pd6HLypZHRm/XuxmsBKUJ8cjgDSgE0bVymAn2kg5mvg==", "dev": true, "requires": { "estree-walker": "^0.6.0", "magic-string": "^0.25.2", "resolve": "^1.10.0", - "rollup-pluginutils": "^2.5.0" + "rollup-pluginutils": "^2.6.0" }, "dependencies": { "resolve": { diff --git a/package.json b/package.json index c8dece50d67..0ecd564da7f 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "rollup": "^1.8.0", "rollup-plugin-alias": "^1.5.1", "rollup-plugin-buble": "^0.19.6", - "rollup-plugin-commonjs": "^9.3.1", + "rollup-plugin-commonjs": "^9.3.3", "rollup-plugin-json": "^4.0.0", "rollup-plugin-node-resolve": "^4.0.1", "rollup-plugin-replace": "^2.1.1", diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_config.js b/test/chunking-form/samples/preserve-modules-commonjs/_config.js new file mode 100644 index 00000000000..39b0a3c6e4a --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_config.js @@ -0,0 +1,11 @@ +const commonjs = require('rollup-plugin-commonjs'); + +module.exports = { + description: 'Handles output from rollup-plugin-commonjs', + options: { + input: 'main.js', + preserveModules: true, + external: ['external'], + plugins: [commonjs()] + } +}; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_commonjs-external-external b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_commonjs-external-external new file mode 100644 index 00000000000..a066f897989 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_commonjs-external-external @@ -0,0 +1,9 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + + + exports.default = external; + +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js new file mode 100644 index 00000000000..2f18de25c3c --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js @@ -0,0 +1,7 @@ +define(['exports', '../other.js'], function (exports, __chunk_1) { 'use strict'; + + + + exports.default = __chunk_1.__moduleExports; + +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js new file mode 100644 index 00000000000..84e944e5ced --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js @@ -0,0 +1,14 @@ +define(['exports', 'external', './other.js', './_virtual/_commonjs-external-external', './_virtual/other.js'], function (exports, external, __chunk_1, __chunk_2, __chunk_3) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + const { value } = __chunk_3.default; + + console.log(__chunk_2.default, value); + + var commonjs = 42; + + exports.__moduleExports = commonjs; + exports.default = commonjs; + +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js new file mode 100644 index 00000000000..a8edbd239a5 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(['external', './commonjs.js'], function (external, __chunk_4) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + console.log(__chunk_4.default, external); + +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/other.js new file mode 100644 index 00000000000..1a2f6aee042 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/other.js @@ -0,0 +1,12 @@ +define(['exports'], function (exports) { 'use strict'; + + var value = 43; + + var other = { + value: value + }; + + exports.__moduleExports = other; + exports.value = value; + +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/_commonjs-external-external b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/_commonjs-external-external new file mode 100644 index 00000000000..574ae3aa425 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/_commonjs-external-external @@ -0,0 +1,9 @@ +'use strict'; + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var external = _interopDefault(require('external')); + + + +exports.default = external; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/other.js new file mode 100644 index 00000000000..fbf759c7e91 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/_virtual/other.js @@ -0,0 +1,7 @@ +'use strict'; + +var __chunk_1 = require('../other.js'); + + + +exports.default = __chunk_1.__moduleExports; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/commonjs.js new file mode 100644 index 00000000000..7c96eb6a376 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/commonjs.js @@ -0,0 +1,15 @@ +'use strict'; + +require('external'); +require('./other.js'); +var __chunk_2 = require('./_virtual/_commonjs-external-external'); +var __chunk_3 = require('./_virtual/other.js'); + +const { value } = __chunk_3.default; + +console.log(__chunk_2.default, value); + +var commonjs = 42; + +exports.__moduleExports = commonjs; +exports.default = commonjs; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/main.js new file mode 100644 index 00000000000..52510c0ebe7 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/main.js @@ -0,0 +1,8 @@ +'use strict'; + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var external = _interopDefault(require('external')); +var __chunk_4 = require('./commonjs.js'); + +console.log(__chunk_4.default, external); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/other.js new file mode 100644 index 00000000000..e105dd53271 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/other.js @@ -0,0 +1,10 @@ +'use strict'; + +var value = 43; + +var other = { + value: value +}; + +exports.__moduleExports = other; +exports.value = value; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/_commonjs-external-external b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/_commonjs-external-external new file mode 100644 index 00000000000..43be5de5e7e --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/_commonjs-external-external @@ -0,0 +1,5 @@ +import external from 'external'; + + + +export default external; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/other.js new file mode 100644 index 00000000000..e1f8c6eb7c2 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/_virtual/other.js @@ -0,0 +1,5 @@ +import { __moduleExports as other } from '../other.js'; + + + +export default other; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/commonjs.js new file mode 100644 index 00000000000..ea84d5cb164 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/commonjs.js @@ -0,0 +1,13 @@ +import 'external'; +import './other.js'; +import external from './_virtual/_commonjs-external-external'; +import require$$0 from './_virtual/other.js'; + +const { value } = require$$0; + +console.log(external, value); + +var commonjs = 42; + +export default commonjs; +export { commonjs as __moduleExports }; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/main.js new file mode 100644 index 00000000000..bb1cdbb2d38 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/main.js @@ -0,0 +1,4 @@ +import external from 'external'; +import value from './commonjs.js'; + +console.log(value, external); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/other.js new file mode 100644 index 00000000000..da9404fec78 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/es/other.js @@ -0,0 +1,7 @@ +var value = 43; + +var other = { + value: value +}; + +export { other as __moduleExports, value }; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/_commonjs-external-external b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/_commonjs-external-external new file mode 100644 index 00000000000..73856d3d3b4 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/_commonjs-external-external @@ -0,0 +1,14 @@ +System.register(['external'], function (exports, module) { + 'use strict'; + var external; + return { + setters: [function (module) { + external = module.default; + }], + execute: function () { + + exports('default', external); + + } + }; +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/other.js new file mode 100644 index 00000000000..719361064a5 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/_virtual/other.js @@ -0,0 +1,14 @@ +System.register(['../other.js'], function (exports, module) { + 'use strict'; + var other; + return { + setters: [function (module) { + other = module.__moduleExports; + }], + execute: function () { + + exports('default', other); + + } + }; +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/commonjs.js new file mode 100644 index 00000000000..c1211d221a5 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/commonjs.js @@ -0,0 +1,21 @@ +System.register(['external', './other.js', './_virtual/_commonjs-external-external', './_virtual/other.js'], function (exports, module) { + 'use strict'; + var external, require$$0; + return { + setters: [function () {}, function () {}, function (module) { + external = module.default; + }, function (module) { + require$$0 = module.default; + }], + execute: function () { + + const { value } = require$$0; + + console.log(external, value); + + var commonjs = exports('__moduleExports', 42); + exports('default', commonjs); + + } + }; +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/main.js new file mode 100644 index 00000000000..0ae2dd25672 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/main.js @@ -0,0 +1,16 @@ +System.register(['external', './commonjs.js'], function (exports, module) { + 'use strict'; + var external, value; + return { + setters: [function (module) { + external = module.default; + }, function (module) { + value = module.default; + }], + execute: function () { + + console.log(value, external); + + } + }; +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/other.js new file mode 100644 index 00000000000..85844f804a2 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/system/other.js @@ -0,0 +1,14 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var value = exports('value', 43); + + var other = exports('__moduleExports', { + value: value + }); + + } + }; +}); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/commonjs.js new file mode 100644 index 00000000000..b9bf49c3fc5 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/commonjs.js @@ -0,0 +1,6 @@ +const external = require('external'); +const { value } = require('./other'); + +console.log(external, value); + +module.exports = 42; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/main.js b/test/chunking-form/samples/preserve-modules-commonjs/main.js new file mode 100644 index 00000000000..cfef423da0c --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/main.js @@ -0,0 +1,4 @@ +import value from './commonjs'; +import external from 'external'; + +console.log(value, external); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/other.js b/test/chunking-form/samples/preserve-modules-commonjs/other.js new file mode 100644 index 00000000000..cd9dcc83b69 --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-commonjs/other.js @@ -0,0 +1 @@ +exports.value = 43;