diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md index f648cfb14..6dfaeeec5 100644 --- a/packages/commonjs/README.md +++ b/packages/commonjs/README.md @@ -44,6 +44,33 @@ Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#comma ## Options +### `dynamicRequireTargets` + +Type: `String|Array[String]`
+Default: `[]` + +Some modules contain dynamic `require` calls, or require modules that contain circular dependencies, which are not handled well by static imports. +Including those modules as `dynamicRequireTargets` will simulate a CommonJS (NodeJS-like) environment for them with support for dynamic and circular dependencies. + +_Note: In extreme cases, this feature may result in some paths being rendered as absolute in the final bundle. The plugin tries to avoid exposing paths from the local machine, but if you are `dynamicRequirePaths` with paths that are far away from your project's folder, that may require replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`._ + +Example: + +```js +commonjs({ + dynamicRequireTargets: [ + // include using a glob pattern (either a string or an array of strings) + 'node_modules/logform/*.js', + + // exclude files that are known to not be required dynamically, this allows for better optimizations + '!node_modules/logform/index.js', + '!node_modules/logform/format.js', + '!node_modules/logform/levels.js', + '!node_modules/logform/browser.js' + ] +}); +``` + ### `exclude` Type: `String` | `Array[...String]`
diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json index 452fef54f..a536816fe 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -50,7 +50,9 @@ }, "dependencies": { "@rollup/pluginutils": "^3.0.8", + "commondir": "^1.0.1", "estree-walker": "^1.0.1", + "glob": "^7.1.2", "is-reference": "^1.1.2", "magic-string": "^0.25.2", "resolve": "^1.11.0" diff --git a/packages/commonjs/src/dynamic-require-paths.js b/packages/commonjs/src/dynamic-require-paths.js new file mode 100644 index 000000000..d635123ad --- /dev/null +++ b/packages/commonjs/src/dynamic-require-paths.js @@ -0,0 +1,27 @@ +import { statSync } from 'fs'; +import glob from 'glob'; +import { resolve } from 'path'; +import { normalizePathSlashes } from './transform'; + +export default function getDynamicRequirePaths(patterns) { + const dynamicRequireModuleSet = new Set(); + for (const pattern of (!patterns || Array.isArray(patterns)) ? patterns || [] : [patterns]) { + const isNegated = pattern.startsWith('!'); + const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind( + dynamicRequireModuleSet + ); + for (const path of glob.sync(isNegated ? pattern.substr(1) : pattern)) { + modifySet(normalizePathSlashes(resolve(path))); + } + } + const dynamicRequireModuleDirPaths = Array.from(dynamicRequireModuleSet.values()).filter(path => { + try { + if (statSync(path).isDirectory()) + return true; + } catch (ignored) { + // Nothing to do here + } + return false; + }); + return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths }; +} diff --git a/packages/commonjs/src/helpers.js b/packages/commonjs/src/helpers.js index d99788129..b2181ad94 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -6,6 +6,17 @@ export const EXTERNAL_SUFFIX = '?commonjs-external'; export const getExternalProxyId = (id) => `\0${id}${EXTERNAL_SUFFIX}`; export const getIdFromExternalProxyId = (proxyId) => proxyId.slice(1, -EXTERNAL_SUFFIX.length); +export const VIRTUAL_PATH_BASE = '/$$rollup_base$$'; +export const getVirtualPathForDynamicRequirePath = (path, commonDir) => { + if (path.startsWith(commonDir)) + return VIRTUAL_PATH_BASE + path.slice(commonDir.length); + return path; +}; + +export const DYNAMIC_REGISTER_PREFIX = '\0commonjs-dynamic-register:'; +export const DYNAMIC_JSON_PREFIX = '\0commonjs-dynamic-json:'; +export const DYNAMIC_PACKAGES_ID = '\0commonjs-dynamic-packages'; + export const HELPERS_ID = '\0commonjsHelpers.js'; // `x['default']` is used instead of `x.default` for backward compatibility with ES3 browsers. @@ -13,10 +24,6 @@ export const HELPERS_ID = '\0commonjsHelpers.js'; export const HELPERS = ` export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; -export function commonjsRequire () { - throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); -} - export function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } @@ -27,4 +34,125 @@ export function createCommonjsModule(fn, module) { export function getCjsExportFromNamespace (n) { return n && n['default'] || n; -}`; +} +`; + +export const HELPER_NON_DYNAMIC = ` +export function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); +} +`; + +export const HELPERS_DYNAMIC = ` +export function commonjsRegister (path, loader) { + DYNAMIC_REQUIRE_LOADERS[path] = loader; +} + +const DYNAMIC_REQUIRE_LOADERS = Object.create(null); +const DYNAMIC_REQUIRE_CACHE = Object.create(null); +const DEFAULT_PARENT_MODULE = { + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: [] +}; +const CHECKED_EXTENSIONS = ['', '.js', '.json']; + +function normalize (path) { + path = path.replace(/\\\\/g, '/'); + const parts = path.split('/'); + const slashed = parts[0] === ''; + for (let i = 1; i < parts.length; i++) { + if (parts[i] === '.' || parts[i] === '') { + parts.splice(i--, 1); + } + } + for (let i = 1; i < parts.length; i++) { + if (parts[i] !== '..') continue; + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') { + parts.splice(--i, 2); + i--; + } + } + path = parts.join('/'); + if (slashed && path[0] !== '/') + path = '/' + path; + else if (path.length === 0) + path = '.'; + return path; +} + +function join () { + if (arguments.length === 0) + return '.'; + let joined; + for (let i = 0; i < arguments.length; ++i) { + let arg = arguments[i]; + if (arg.length > 0) { + if (joined === undefined) + joined = arg; + else + joined += '/' + arg; + } + } + if (joined === undefined) + return '.'; + + return joined; +} + +function isPossibleNodeModulesPath (modulePath) { + let c0 = modulePath[0]; + if (c0 === '/' || c0 === '\\\\') return false; + let c1 = modulePath[1], c2 = modulePath[2]; + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) || + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false; + if (c1 === ':' && (c2 === '/' || c2 === '\\\\')) + return false; + return true; +} + +export function commonjsRequire (path, originalModuleDir) { + const shouldTryNodeModules = isPossibleNodeModulesPath(path); + path = normalize(path); + let relPath; + while (true) { + if (!shouldTryNodeModules) { + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path; + } else if (originalModuleDir) { + relPath = normalize(originalModuleDir + '/node_modules/' + path); + } else { + relPath = normalize(join('node_modules', path)); + } + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) { + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex]; + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath]; + if (cachedModule) return cachedModule.exports; + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath]; + if (loader) { + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = { + id: resolvedPath, + filename: resolvedPath, + exports: {}, + parent: DEFAULT_PARENT_MODULE, + loaded: false, + children: [], + paths: [] + }; + try { + loader.call(commonjsGlobal, cachedModule, cachedModule.exports); + } catch (error) { + delete DYNAMIC_REQUIRE_CACHE[resolvedPath]; + throw error; + } + cachedModule.loaded = true; + return cachedModule.exports; + }; + } + if (!shouldTryNodeModules) break; + const nextDir = normalize(originalModuleDir + '/..'); + if (nextDir === originalModuleDir) break; + originalModuleDir = nextDir; + } + return require(path); +} + +commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE; +`; diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index 176a573a1..6f746378f 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -1,22 +1,31 @@ -import { realpathSync, existsSync } from 'fs'; -import { extname, resolve, normalize } from 'path'; +import { realpathSync, existsSync, readFileSync } from 'fs'; +import { extname, resolve, normalize, join } from 'path'; import { sync as nodeResolveSync, isCore } from 'resolve'; import { createFilter } from '@rollup/pluginutils'; +import getDynamicRequirePaths from './dynamic-require-paths'; +import getCommonDir from 'commondir'; import { peerDependencies } from '../package.json'; import { + DYNAMIC_JSON_PREFIX, + DYNAMIC_PACKAGES_ID, + DYNAMIC_REGISTER_PREFIX, + getVirtualPathForDynamicRequirePath, EXTERNAL_SUFFIX, getIdFromExternalProxyId, getIdFromProxyId, HELPERS, HELPERS_ID, + HELPER_NON_DYNAMIC, + HELPERS_DYNAMIC, PROXY_SUFFIX } from './helpers'; + import { getIsCjsPromise, setIsCjsPromise } from './is-cjs'; import getResolveId from './resolve-id'; -import { checkEsModule, hasCjsKeywords, transformCommonjs } from './transform'; +import { checkEsModule, normalizePathSlashes, hasCjsKeywords, transformCommonjs } from './transform'; import { getName } from './utils'; export default function commonjs(options = {}) { @@ -24,6 +33,14 @@ export default function commonjs(options = {}) { const filter = createFilter(options.include, options.exclude); const { ignoreGlobal } = options; + const { dynamicRequireModuleSet, dynamicRequireModuleDirPaths } = getDynamicRequirePaths( + options.dynamicRequireTargets + ); + const isDynamicRequireModulesEnabled = dynamicRequireModuleSet.size > 0; + const commonDir = isDynamicRequireModulesEnabled + ? getCommonDir(null, Array.from(dynamicRequireModuleSet).concat(process.cwd())) + : null; + const customNamedExports = {}; if (options.namedExports) { Object.keys(options.namedExports).forEach((id) => { @@ -60,8 +77,6 @@ export default function commonjs(options = {}) { const esModulesWithoutDefaultExport = new Set(); const esModulesWithDefaultExport = new Set(); - // TODO maybe this should be configurable? - const allowDynamicRequire = !!options.ignore; const ignoreRequire = typeof options.ignore === 'function' @@ -76,14 +91,18 @@ export default function commonjs(options = {}) { function transformAndCheckExports(code, id) { const { isEsModule, hasDefaultExport, ast } = checkEsModule(this.parse, code, id); - if (isEsModule) { + + const isDynamicRequireModule = dynamicRequireModuleSet.has( + normalizePathSlashes(id) + ); + + if (isEsModule && !isDynamicRequireModule) { (hasDefaultExport ? esModulesWithDefaultExport : esModulesWithoutDefaultExport).add(id); - return null; } - // it is not an ES module but it does not have CJS-specific elements. - if (!hasCjsKeywords(code, ignoreGlobal)) { + else if (!hasCjsKeywords(code, ignoreGlobal)) { esModulesWithoutDefaultExport.add(id); + setIsCjsPromise(id, false); return null; } @@ -94,15 +113,22 @@ export default function commonjs(options = {}) { code, id, this.getModuleInfo(id).isEntry, - ignoreGlobal, + isEsModule, + ignoreGlobal || isEsModule, ignoreRequire, customNamedExports[normalizedId], sourceMap, - allowDynamicRequire, + isDynamicRequireModulesEnabled, + dynamicRequireModuleSet, + commonDir, ast ); + + setIsCjsPromise(id, isEsModule ? false : Boolean(transformed)); + if (!transformed) { - esModulesWithoutDefaultExport.add(id); + if (!isEsModule || isDynamicRequireModule) + esModulesWithoutDefaultExport.add(id); return null; } @@ -126,22 +152,94 @@ export default function commonjs(options = {}) { resolveId, load(id) { - if (id === HELPERS_ID) return HELPERS; + if (id === HELPERS_ID) { + let code = HELPERS; + + // Do not bloat everyone's code with the module manager code + if (isDynamicRequireModulesEnabled) + code += HELPERS_DYNAMIC; + else + code += HELPER_NON_DYNAMIC; + + return code; + } // generate proxy modules if (id.endsWith(EXTERNAL_SUFFIX)) { const actualId = getIdFromExternalProxyId(id); const name = getName(actualId); + if (actualId === HELPERS_ID || actualId === DYNAMIC_PACKAGES_ID) + // These do not export default + return `import * as ${name} from ${JSON.stringify(actualId)}; export default ${name};`; + return `import ${name} from ${JSON.stringify(actualId)}; export default ${name};`; } - if (id.endsWith(PROXY_SUFFIX)) { - const actualId = getIdFromProxyId(id); + if (id === DYNAMIC_PACKAGES_ID) { + let code = `const { commonjsRegister } = require('${HELPERS_ID}');`; + for (const dir of dynamicRequireModuleDirPaths) { + let entryPoint = 'index.js'; + + try { + if (existsSync(join(dir, 'package.json'))) { + entryPoint = JSON.parse( + readFileSync(join(dir, 'package.json'), { encoding: 'utf8' }) + ).main || entryPoint; + } + } catch (ignored) { + // ignored + } + + code += `\ncommonjsRegister(${JSON.stringify( + getVirtualPathForDynamicRequirePath(dir, commonDir) + )}, function (module, exports) { + module.exports = require(${JSON.stringify( + normalizePathSlashes(join(dir, entryPoint)) + )}); +});`; + } + return code; + } + + let actualId = id; + + const isDynamicJson = actualId.startsWith(DYNAMIC_JSON_PREFIX); + if (isDynamicJson) { + actualId = actualId.slice(DYNAMIC_JSON_PREFIX.length); + } + + const normalizedPath = normalizePathSlashes(actualId); + + if (isDynamicJson) { + return `require('${HELPERS_ID}').commonjsRegister(${JSON.stringify( + getVirtualPathForDynamicRequirePath(normalizedPath, commonDir) + )}, function (module, exports) { + module.exports = require(${JSON.stringify(normalizedPath)}); +});`; + } + + if (dynamicRequireModuleSet.has(normalizedPath) && !normalizedPath.endsWith('.json')) { + // Try our best to still export the module fully. + // The commonjs polyfill should take care of circular references. + + return `require('${HELPERS_ID}').commonjsRegister(${JSON.stringify( + getVirtualPathForDynamicRequirePath(normalizedPath, commonDir) + )}, function (module, exports) { + ${readFileSync(normalizedPath, { encoding: 'utf8' })} +});`; + } + + if (actualId.endsWith(PROXY_SUFFIX)) { + actualId = getIdFromProxyId(actualId); const name = getName(actualId); return getIsCjsPromise(actualId).then((isCjs) => { - if (isCjs) + if (dynamicRequireModuleSet.has(normalizePathSlashes(actualId)) && !actualId.endsWith('.json')) + return `import {commonjsRequire} from '${HELPERS_ID}'; const ${name} = commonjsRequire(${JSON.stringify( + getVirtualPathForDynamicRequirePath(normalizePathSlashes(actualId), commonDir) + )}); export default (${name} && ${name}['default']) || ${name}`; + else if (isCjs) return `import { __moduleExports } from ${JSON.stringify( actualId )}; export default __moduleExports;`; @@ -156,13 +254,40 @@ export default function commonjs(options = {}) { }); } + if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) { + let code; + + try { + code = readFileSync(actualId, {encoding: 'utf8'}); + } catch (ex) { + this.warn(`Failed to read file ${actualId}, dynamic modules might not work correctly`); + return null; + } + + let dynamicImports = Array.from(dynamicRequireModuleSet) + .map(dynamicId => `require(${JSON.stringify(DYNAMIC_REGISTER_PREFIX + dynamicId)});`) + .join('\n'); + + if (dynamicRequireModuleDirPaths.length) { + dynamicImports += `require(${JSON.stringify( + DYNAMIC_REGISTER_PREFIX + DYNAMIC_PACKAGES_ID + )});`; + } + + code = dynamicImports + '\n' + code; + + return code; + } + return null; }, transform(code, id) { - if (!filter(id) || extensions.indexOf(extname(id)) === -1) { - setIsCjsPromise(id, null); - return null; + if (id !== DYNAMIC_PACKAGES_ID && !id.startsWith(DYNAMIC_JSON_PREFIX)) { + if (!filter(id) || extensions.indexOf(extname(id)) === -1) { + setIsCjsPromise(id, null); + return null; + } } let transformed; @@ -170,10 +295,10 @@ export default function commonjs(options = {}) { transformed = transformAndCheckExports.call(this, code, id); } catch (err) { transformed = null; + setIsCjsPromise(id, false); this.error(err, err.loc); } - setIsCjsPromise(id, Boolean(transformed)); return transformed; } }; diff --git a/packages/commonjs/src/resolve-id.js b/packages/commonjs/src/resolve-id.js index f60c79fd8..4da4312fc 100644 --- a/packages/commonjs/src/resolve-id.js +++ b/packages/commonjs/src/resolve-id.js @@ -3,6 +3,8 @@ import { statSync } from 'fs'; import { dirname, resolve, sep } from 'path'; import { + DYNAMIC_JSON_PREFIX, + DYNAMIC_PACKAGES_ID, getExternalProxyId, getIdFromProxyId, getProxyId, @@ -46,12 +48,18 @@ export default function getResolveId(extensions) { if (isProxyModule) { importee = getIdFromProxyId(importee); } else if (importee.startsWith('\0')) { - if (importee === HELPERS_ID) { + if (importee === HELPERS_ID || + importee === DYNAMIC_PACKAGES_ID || + importee.startsWith(DYNAMIC_JSON_PREFIX)) { return importee; } return null; } + if (importee.startsWith(DYNAMIC_JSON_PREFIX)) { + return importee; + } + if (importer && importer.endsWith(PROXY_SUFFIX)) { importer = getIdFromProxyId(importer); } diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js index 792cf6c1b..be8145575 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -1,11 +1,20 @@ -/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle */ +/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */ import { walk } from 'estree-walker'; import MagicString from 'magic-string'; import { attachScopes, extractAssignedNames, makeLegalIdentifier } from '@rollup/pluginutils'; import { flatten, isFalsy, isReference, isTruthy } from './ast-utils'; -import { getProxyId, HELPERS_ID } from './helpers'; +import { + getProxyId, + getVirtualPathForDynamicRequirePath, + HELPERS_ID, + DYNAMIC_REGISTER_PREFIX, + DYNAMIC_JSON_PREFIX, +} from './helpers'; import { getName } from './utils'; +import { resolve, dirname } from 'path'; +// TODO can this be async? +import { sync as nodeResolveSync } from 'resolve'; const reserved = 'process location abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for from function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield'.split( ' ' @@ -42,6 +51,10 @@ function tryParse(parse, code, id) { } } +export function normalizePathSlashes(path) { + return path.replace(/\\/g, '/'); +} + export function hasCjsKeywords(code, ignoreGlobal) { const firstpass = ignoreGlobal ? firstpassNoGlobal : firstpassGlobal; return firstpass.test(code); @@ -91,11 +104,14 @@ export function transformCommonjs( code, id, isEntry, + isEsModule, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, - allowDynamicRequire, + isDynamicRequireModulesEnabled, + dynamicRequireModuleSet, + commonDir, astCache ) { const ast = astCache || tryParse(parse, code, id); @@ -124,6 +140,7 @@ export function transformCommonjs( // TODO handle transpiled modules let shouldWrap = /__esModule/.test(code); + let usesDynamicHelpers = false; function isRequireStatement(node) { if (!node) return false; @@ -145,10 +162,13 @@ export function transformCommonjs( function isStaticRequireStatement(node) { if (!isRequireStatement(node)) return false; if (hasDynamicArguments(node)) return false; - if (ignoreRequire(node.arguments[0].value)) return false; return true; } + function isIgnoredRequireStatement(requiredNode) { + return ignoreRequire(requiredNode.arguments[0].value); + } + function getRequireStringArg(node) { return node.arguments[0].type === 'Literal' ? node.arguments[0].value @@ -156,10 +176,17 @@ export function transformCommonjs( } function getRequired(node, name) { - const sourceId = getRequireStringArg(node); + let sourceId = getRequireStringArg(node); + const isDynamicRegister = sourceId.startsWith(DYNAMIC_REGISTER_PREFIX); + if (isDynamicRegister) { + sourceId = sourceId.substr(DYNAMIC_REGISTER_PREFIX.length); + } + const existing = required[sourceId]; // eslint-disable-next-line no-undefined if (existing === undefined) { + const isDynamic = hasDynamicModuleForPath(sourceId); + if (!name) { do { name = `require$$${uid}`; @@ -167,13 +194,53 @@ export function transformCommonjs( } while (scope.contains(name)); } - sources.push(sourceId); - required[sourceId] = { source: sourceId, name, importsDefault: false }; + if (isDynamicRegister && sourceId.endsWith('.json')) { + sourceId = DYNAMIC_JSON_PREFIX + sourceId; + } + + if (isDynamicRegister || !isDynamic || sourceId.endsWith('.json')) { + sources.push([sourceId, !isDynamicRegister]); + } + + required[sourceId] = { source: sourceId, name, importsDefault: false, isDynamic }; } return required[sourceId]; } + function hasDynamicModuleForPath(source) { + if (!/[/\\]/.test(source)) { + try { + const resolvedPath = normalizePathSlashes( + nodeResolveSync(source, { basedir: dirname(id) }) + ); + if (dynamicRequireModuleSet.has(resolvedPath)) { + return true; + } + } catch (ex) { + // Probably a node.js internal module + return false; + } + + return false; + } + + for (const attemptExt of ['', '.js', '.json']) { + const resolvedPath = normalizePathSlashes(resolve(dirname(id), source + attemptExt)); + if (dynamicRequireModuleSet.has(resolvedPath)) { + return true; + } + } + + return false; + } + + function shouldUseSimulatedRequire(required) { + return hasDynamicModuleForPath(required.source) && + // We only do `commonjsRequire` for json if it's the `commonjsRegister` call. + (required.source.startsWith(DYNAMIC_REGISTER_PREFIX) || !required.source.endsWith('.json')); + } + // do a first pass, see which names are assigned to. This is necessary to prevent // illegally replacing `var foo = require('foo')` with `import foo from 'foo'`, // where `foo` is later reassigned. (This happens in the wild. CommonJS, sigh) @@ -255,10 +322,26 @@ export function transformCommonjs( if (isReference(node, parent) && !scope.contains(node.name)) { if (node.name in uses) { if (node.name === 'require') { - if (allowDynamicRequire) return; + if (!isDynamicRequireModulesEnabled && isStaticRequireStatement(parent)) { + return; + } + + if (isDynamicRequireModulesEnabled && isRequireStatement(parent)) { + magicString.appendLeft( + parent.end - 1, + ',' + + JSON.stringify( + dirname(id) === '.' + ? null /* default behavior */ + : getVirtualPathForDynamicRequirePath(normalizePathSlashes(dirname(id)), commonDir) + ) + ); + } + magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, { storeName: true }); + usesDynamicHelpers = true } uses[node.name] = true; @@ -325,7 +408,8 @@ export function transformCommonjs( if ( node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && - isStaticRequireStatement(node.init) + isStaticRequireStatement(node.init) && + !isIgnoredRequireStatement(node.init) ) { // for now, only do this for top-level requires. maybe fix this in future if (scope.parent) return; @@ -336,12 +420,14 @@ export function transformCommonjs( const required = getRequired(node.init, node.id.name); required.importsDefault = true; - if (required.name === node.id.name) { + if (required.name === node.id.name && !required.isDynamic) { node._shouldRemove = true; } } - if (!isStaticRequireStatement(node)) return; + if (!isStaticRequireStatement(node) || isIgnoredRequireStatement(node)) { + return; + } const required = getRequired(node); @@ -350,7 +436,23 @@ export function transformCommonjs( magicString.remove(parent.start, parent.end); } else { required.importsDefault = true; - magicString.overwrite(node.start, node.end, required.name); + + if (shouldUseSimulatedRequire(required)) { + magicString.overwrite( + node.start, + node.end, + `${HELPERS_NAME}.commonjsRequire(${JSON.stringify( + getVirtualPathForDynamicRequirePath(normalizePathSlashes(required.source), commonDir) + )}, ${JSON.stringify( + dirname(id) === '.' + ? null /* default behavior */ + : getVirtualPathForDynamicRequirePath(normalizePathSlashes(dirname(id)), commonDir) + )})` + ); + usesDynamicHelpers = true; + } else { + magicString.overwrite(node.start, node.end, required.name); + } } node.callee._skip = true; @@ -403,22 +505,24 @@ export function transformCommonjs( return null; } - const includeHelpers = shouldWrap || uses.global || uses.require; + const includeHelpers = usesDynamicHelpers || shouldWrap || uses.global || uses.require; const importBlock = `${(includeHelpers ? [`import * as ${HELPERS_NAME} from '${HELPERS_ID}';`] : [] ) .concat( sources.map( - (source) => + ([source]) => // import the actual module before the proxy, so that we know // what kind of proxy to build `import '${source}';` ), - sources.map((source) => { - const { name, importsDefault } = required[source]; - return `import ${importsDefault ? `${name} from ` : ``}'${getProxyId(source)}';`; - }) + sources + .filter(([, importProxy]) => importProxy) + .map(([source]) => { + const { name, importsDefault } = required[source]; + return `import ${importsDefault ? `${name} from ` : ``}'${getProxyId(source)}';`; + }) ) .join('\n')}\n\n`; @@ -427,7 +531,7 @@ export function transformCommonjs( let wrapperEnd = ''; const moduleName = deconflict(scope, globals, getName(id)); - if (!isEntry) { + if (!isEntry && !isEsModule) { const exportModuleExports = { str: `export { ${moduleName} as __moduleExports };`, name: '__moduleExports' @@ -465,15 +569,19 @@ export function transformCommonjs( } else { const names = []; - ast.body.forEach((node) => { + for (const node of ast.body) { if (node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression') { const { left } = node.expression; const flattened = flatten(left); - if (!flattened) return; + if (!flattened) { + continue; + } const match = exportsPattern.exec(flattened.keypath); - if (!match) return; + if (!match) { + continue; + } if (flattened.keypath === 'module.exports') { hasDefaultExport = true; @@ -502,14 +610,15 @@ export function transformCommonjs( defaultExportPropertyAssignments.push(`${moduleName}.${name} = ${deconflicted};`); } } - }); + } - if (!hasDefaultExport && (names.length || !isEntry)) { + if (!hasDefaultExport && (names.length || (!isEntry && !isEsModule))) { wrapperEnd = `\n\nvar ${moduleName} = {\n${names .map(({ name, deconflicted }) => `\t${name}: ${deconflicted}`) .join(',\n')}\n};`; } } + Object.keys(namedExports) .filter((key) => !blacklist[key]) .forEach(addExport); @@ -522,7 +631,7 @@ export function transformCommonjs( .filter((x) => x.name !== 'default' || !hasDefaultExport) .map((x) => x.str); - const exportBlock = `\n\n${[defaultExport] + const exportBlock = `\n\n${(isEsModule ? [] : [defaultExport]) .concat(named) .concat(hasDefaultExport ? defaultExportPropertyAssignments : []) .join('\n')}`; @@ -533,7 +642,7 @@ export function transformCommonjs( .trim() .append(wrapperEnd); - if (hasDefaultExport || named.length > 0 || shouldWrap || !isEntry) { + if (hasDefaultExport || named.length > 0 || shouldWrap || (!isEntry && !isEsModule)) { magicString.append(exportBlock); } diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/foo.js b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/foo.js new file mode 100644 index 000000000..1cfa22790 --- /dev/null +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/foo.js @@ -0,0 +1,3 @@ +const test = 'abc'; + +module.exports = test; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js index 3d5f6da1c..af86babb3 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-default-export/output.js @@ -1,3 +1,4 @@ -require( './foo.js' ); +import './foo.js'; +import '_./foo.js?commonjs-proxy'; export default {}; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js index 324f256a2..ab5213af4 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-import/output.js @@ -1,3 +1,4 @@ -require( './foo.js' ); +import './foo.js'; +import '_./foo.js?commonjs-proxy'; import './bar.js'; diff --git a/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js b/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js index 64af25289..21d5dd24c 100644 --- a/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js +++ b/packages/commonjs/test/fixtures/form/unambiguous-with-named-export/output.js @@ -1,3 +1,4 @@ -require( './foo.js' ); +import './foo.js'; +import '_./foo.js?commonjs-proxy'; export {}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js new file mode 100755 index 000000000..e4019f2cc --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: 'resolves non-relative paths via node_modules', + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js', + 'fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js', + 'fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/main.js new file mode 100755 index 000000000..d101c03f4 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/main.js @@ -0,0 +1,7 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +t.deepEqual(require('./sub/submodule'), { + moduleDirect: 'direct', + moduleNested: 'nested', + parentModule: 'parent' +}); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js new file mode 100755 index 000000000..d633e3c2b --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js @@ -0,0 +1 @@ +module.exports = 'parent'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js new file mode 100755 index 000000000..0025ad023 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js @@ -0,0 +1 @@ +module.exports = 'direct'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js new file mode 100755 index 000000000..210d41cbb --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js @@ -0,0 +1 @@ +module.exports = 'nested'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/submodule.js new file mode 100755 index 000000000..fb9540db0 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/submodule.js @@ -0,0 +1,9 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(name) { + return require(name); +} + +exports.moduleDirect = takeModule('module/direct'); +exports.moduleNested = takeModule('module/nested/nested'); +exports.parentModule = takeModule('parent-module/parent'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js new file mode 100755 index 000000000..8a62ba220 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'resolves both windows and posix absolute paths', + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require-absolute-paths/submodule.js'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js new file mode 100755 index 000000000..43bce0645 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js @@ -0,0 +1,6 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +const Path = require('path'); +let basePath = process.cwd() + '/fixtures/function/dynamic-require-absolute-paths'; + +t.is(require(Path.resolve(`${basePath}/submodule.js`)), 'submodule'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js new file mode 100755 index 000000000..c285d34bc --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js @@ -0,0 +1 @@ +module.exports = 'submodule'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js new file mode 100755 index 000000000..566def9c0 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: 'supports dynamic require with code-splitting', + options: { + input: [ + 'fixtures/function/dynamic-require-code-splitting/main', + 'fixtures/function/dynamic-require-code-splitting/main2' + ] + }, + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require-code-splitting/target?.js'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js new file mode 100755 index 000000000..54136fdd2 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js @@ -0,0 +1,12 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +let message; + +for (const index of [1, 2]) { + try { + message = require(`./target${index}.js`); + } catch (err) { + ({ message } = err); + } + t.is(message, index.toString()); +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js new file mode 100755 index 000000000..54136fdd2 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js @@ -0,0 +1,12 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +let message; + +for (const index of [1, 2]) { + try { + message = require(`./target${index}.js`); + } catch (err) { + ({ message } = err); + } + t.is(message, index.toString()); +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main.js new file mode 100755 index 000000000..303290b29 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main.js @@ -0,0 +1,2 @@ +import './lib1.js'; +import './lib2.js'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main2.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main2.js new file mode 100755 index 000000000..f3174152b --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main2.js @@ -0,0 +1 @@ +import './lib2.js'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target1.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target1.js new file mode 100644 index 000000000..4ac32c713 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target1.js @@ -0,0 +1 @@ +module.exports = '1'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target2.js b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target2.js new file mode 100644 index 000000000..2db2c90b9 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target2.js @@ -0,0 +1 @@ +module.exports = '2'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js new file mode 100755 index 000000000..d0d7c2449 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'works when the entry point is an es module', + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require-es-entry/submodule.js'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/importer.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/importer.js new file mode 100755 index 000000000..2dcdfb2a1 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/importer.js @@ -0,0 +1,7 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule (withName) { + return require('./' + withName); +} + +module.exports = takeModule('submodule.js'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/main.js new file mode 100755 index 000000000..8f9bcc1cb --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/main.js @@ -0,0 +1,5 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +import result from './importer'; + +t.is(result, 'submodule'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js new file mode 100755 index 000000000..c285d34bc --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js @@ -0,0 +1 @@ +module.exports = 'submodule'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js new file mode 100755 index 000000000..22699451d --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'returns the same module instance if requiring with and without extension', + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require-extensions/submodule.js'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-extensions/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/main.js new file mode 100755 index 000000000..e7dc75dce --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/main.js @@ -0,0 +1,15 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(withName) { + return require('./' + withName); +} + +const withExtension = takeModule('submodule.js'); +const withoutExtension = takeModule('submodule'); + +t.is(withExtension.name, 'submodule'); +t.is(withoutExtension.name, 'submodule'); + +withExtension.value = 'mutated'; + +t.is(withoutExtension.value, 'mutated'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js new file mode 100755 index 000000000..ab1ff5191 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js @@ -0,0 +1 @@ +module.exports = {name: 'submodule', value: null}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js new file mode 100755 index 000000000..af8cbe2d8 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: 'supports glob patterns', + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-globs/s*.js', + 'fixtures/function/dynamic-require-globs/e*.*', + '!fixtures/function/dynamic-require-globs/e*2.js' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js new file mode 100755 index 000000000..07f08d262 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js @@ -0,0 +1 @@ +module.exports = 'extramodule1'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule2.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule2.js new file mode 100755 index 000000000..806649ebd --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule2.js @@ -0,0 +1 @@ +module.exports = 'extramodule2'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/main.js new file mode 100755 index 000000000..5b603d708 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/main.js @@ -0,0 +1,18 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(withName) { + return require('./' + withName); +} + +t.is(takeModule('submodule1.js'), 'submodule1'); +t.is(takeModule('submodule2.js'), 'submodule2'); +t.is(takeModule('extramodule1.js'), 'extramodule1'); + +let hasThrown = false; +try { + takeModule('extramodule2.js'); +} catch (error) { + t.truthy(/Cannot find module '\.\/extramodule2\.js'/.test(error.message)); + hasThrown = true; +} +t.truthy(hasThrown); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js new file mode 100755 index 000000000..5e52db490 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js @@ -0,0 +1 @@ +module.exports = 'submodule1'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js new file mode 100755 index 000000000..cf81f8cb6 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js @@ -0,0 +1 @@ +module.exports = 'submodule2'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js new file mode 100755 index 000000000..5aa08f64e --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js @@ -0,0 +1,16 @@ +const nodeResolve = require('@rollup/plugin-node-resolve'); + +module.exports = { + description: 'returns the same module instance if required directly or via package.json/index.js', + options: { + plugins: [nodeResolve()] + }, + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-instances/direct', + 'fixtures/function/dynamic-require-instances/direct/index.js', + 'fixtures/function/dynamic-require-instances/package', + 'fixtures/function/dynamic-require-instances/package/main.js' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js b/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js new file mode 100755 index 000000000..66163adf7 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js @@ -0,0 +1 @@ +module.exports = { name: 'direct', value: null }; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-instances/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-instances/main.js new file mode 100755 index 000000000..ce628ebe3 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/main.js @@ -0,0 +1,13 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(withName) { + return require(withName); +} + +takeModule('./direct').value = 'direct-instance'; +t.is(takeModule('./direct/index.js').value, 'direct-instance'); +t.is(require('./direct/index.js').value, 'direct-instance'); + +takeModule('./package').value = 'package-instance'; +t.is(takeModule('./package/main.js').value, 'package-instance'); +t.is(require('./package/main.js').value, 'package-instance'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js new file mode 100755 index 000000000..94793d1e1 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js @@ -0,0 +1 @@ +module.exorts = { name: 'package', value: null }; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/package.json new file mode 100755 index 000000000..2af9e0d19 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/package.json @@ -0,0 +1,3 @@ +{ + "main": "./main.js" +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js new file mode 100755 index 000000000..fd466d91a --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js @@ -0,0 +1,11 @@ +const json = require('@rollup/plugin-json'); + +module.exports = { + description: 'dynamically requires json files', + options: { + plugins: [json()] + }, + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require-json/dynamic.json'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-json/dynamic.json b/packages/commonjs/test/fixtures/function/dynamic-require-json/dynamic.json new file mode 100755 index 000000000..f6bb7b1c0 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-json/dynamic.json @@ -0,0 +1,3 @@ +{ + "value": "present" +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-json/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-json/main.js new file mode 100755 index 000000000..42daca2b2 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-json/main.js @@ -0,0 +1,8 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(withName) { + return require('./' + withName); +} + +t.deepEqual(takeModule('dynamic.json'), {value: 'present'}); +t.deepEqual(takeModule('dynamic'), {value: 'present'}); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js new file mode 100755 index 000000000..07396e09d --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js @@ -0,0 +1,15 @@ +const json = require('@rollup/plugin-json'); +const nodeResolve = require('@rollup/plugin-node-resolve'); + +module.exports = { + input: 'sub/entry.js', + description: 'resolves imports of node_modules from subdirectories', + options: { + plugins: [nodeResolve(), json()] + }, + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-package-sub/node_modules/custom-module/**' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js new file mode 100755 index 000000000..f67b07340 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js @@ -0,0 +1 @@ +module.exports = 'custom-module'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json new file mode 100755 index 000000000..382adf764 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json @@ -0,0 +1 @@ +{"main": "./entry.js"} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/package.json new file mode 100755 index 000000000..2173d0506 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/package.json @@ -0,0 +1,3 @@ +{ + "main": "./sub/entry.js" +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub/entry.js b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub/entry.js new file mode 100755 index 000000000..809a4f748 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub/entry.js @@ -0,0 +1,2 @@ + +t.is(require('custom-module'), 'custom-module'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js new file mode 100755 index 000000000..1f532f4d2 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js @@ -0,0 +1,16 @@ +const json = require('@rollup/plugin-json'); +const nodeResolve = require('@rollup/plugin-node-resolve'); + +module.exports = { + description: 'resolves imports of directories via package.json files', + options: { + plugins: [nodeResolve(), json()] + }, + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-package', + 'fixtures/function/dynamic-require-package/sub', + 'fixtures/function/dynamic-require-package/node_modules/custom-module' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/entry.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/entry.js new file mode 100755 index 000000000..496245dfd --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/entry.js @@ -0,0 +1 @@ +module.exports = 'same-directory'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js new file mode 100755 index 000000000..d494ef228 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js @@ -0,0 +1,14 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(name) { + return require(name); +} + +t.is(takeModule('.'), 'same-directory'); +t.is(takeModule('./'), 'same-directory'); +t.is(takeModule('.//'), 'same-directory'); + +t.is(takeModule('./sub'), 'sub'); + +t.is(takeModule('custom-module'), 'custom-module'); +t.deepEqual(require('./sub/sub'), { parent: 'same-directory', customModule: 'custom-module' }); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/entry.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/entry.js new file mode 100755 index 000000000..f67b07340 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/entry.js @@ -0,0 +1 @@ +module.exports = 'custom-module'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/package.json new file mode 100755 index 000000000..382adf764 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/package.json @@ -0,0 +1 @@ +{"main": "./entry.js"} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-package/package.json new file mode 100755 index 000000000..7b764af16 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/package.json @@ -0,0 +1,3 @@ +{ + "main": "./entry.js" +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/entry.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/entry.js new file mode 100755 index 000000000..e74342ce6 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/entry.js @@ -0,0 +1 @@ +module.exports = 'sub'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/package.json b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/package.json new file mode 100755 index 000000000..7b764af16 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/package.json @@ -0,0 +1,3 @@ +{ + "main": "./entry.js" +} diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/sub.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/sub.js new file mode 100755 index 000000000..8946fe2b0 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/sub/sub.js @@ -0,0 +1,10 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(name) { + return require(name); +} + +module.exports = { + parent: takeModule('..'), + customModule: takeModule('custom-module') +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js new file mode 100755 index 000000000..9c96ce599 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'resolves both windows and posix paths', + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-relative-paths/sub/submodule.js', + 'fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/main.js new file mode 100755 index 000000000..0f0c290b7 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/main.js @@ -0,0 +1,10 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModuleWithDelimiter(name, delimiter) { + return require('.' + delimiter + name.replace(/=/g, delimiter)); +} + +t.is(takeModuleWithDelimiter('sub=submodule.js', '/'), 'submodule'); +t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '/'), 'subsubmodule'); +t.is(takeModuleWithDelimiter('sub=submodule.js', '\\'), 'submodule'); +t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '\\'), 'subsubmodule'); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js new file mode 100755 index 000000000..c285d34bc --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js @@ -0,0 +1 @@ +module.exports = 'submodule'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js new file mode 100755 index 000000000..00f4bc743 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js @@ -0,0 +1 @@ +module.exports = 'subsubmodule'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js new file mode 100755 index 000000000..d1ec94a0e --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js @@ -0,0 +1,15 @@ +const nodeResolve = require('@rollup/plugin-node-resolve'); + +module.exports = { + description: 'resolves imports of directories via index.js', + options: { + plugins: [nodeResolve()] + }, + pluginOptions: { + dynamicRequireTargets: [ + 'fixtures/function/dynamic-require-resolve-index', + 'fixtures/function/dynamic-require-resolve-index/sub', + 'fixtures/function/dynamic-require-resolve-index/node_modules/custom-module' + ] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/index.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/index.js new file mode 100755 index 000000000..496245dfd --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/index.js @@ -0,0 +1 @@ +module.exports = 'same-directory'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/main.js new file mode 100755 index 000000000..925ba1534 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/main.js @@ -0,0 +1,14 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(name) { + return require(name); +} + +t.is(takeModule('.'), 'same-directory'); +t.is(takeModule('./'), 'same-directory'); +t.is(takeModule('.//'), 'same-directory'); + +t.is(takeModule('./sub'), 'sub'); + +t.is(takeModule('custom-module'), 'custom-module'); +t.deepEqual(require('./sub/sub'), { parent: 'same-directory', customModule: 'custom-module' }); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module/index.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module/index.js new file mode 100755 index 000000000..f67b07340 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module/index.js @@ -0,0 +1 @@ +module.exports = 'custom-module'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/index.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/index.js new file mode 100755 index 000000000..e74342ce6 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/index.js @@ -0,0 +1 @@ +module.exports = 'sub'; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/sub.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/sub.js new file mode 100755 index 000000000..8946fe2b0 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/sub.js @@ -0,0 +1,10 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +function takeModule(name) { + return require(name); +} + +module.exports = { + parent: takeModule('..'), + customModule: takeModule('custom-module') +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require/_config.js new file mode 100755 index 000000000..ef30bb342 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'supports dynamic require', + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require/submodule.js'] + } +}; diff --git a/packages/commonjs/test/fixtures/function/dynamic-require/main.js b/packages/commonjs/test/fixtures/function/dynamic-require/main.js new file mode 100755 index 000000000..a3e1a8a99 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require/main.js @@ -0,0 +1,16 @@ +/* eslint-disable import/no-dynamic-require, global-require */ + +let message; + +function takeModule(withName) { + return require('./' + withName); +} + +try { + const submodule = takeModule('submodule'); + message = submodule(); +} catch ( err ) { + ({ message } = err); +} + +t.is( message, 'Hello there' ); diff --git a/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js b/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js new file mode 100755 index 000000000..94738ad61 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js @@ -0,0 +1,3 @@ +module.exports = function () { + return 'Hello there'; +}; \ No newline at end of file diff --git a/packages/commonjs/test/function.js b/packages/commonjs/test/function.js index 0ffee28c0..13dc8c745 100644 --- a/packages/commonjs/test/function.js +++ b/packages/commonjs/test/function.js @@ -5,7 +5,7 @@ import { readdirSync } from 'fs'; import test from 'ava'; import { rollup } from 'rollup'; -import { commonjs, getCodeFromBundle, execute } from './helpers/util'; +import { commonjs, getCodeMapFromBundle, runCodeSplitTest } from './helpers/util'; process.chdir(__dirname); @@ -21,7 +21,7 @@ readdirSync('./fixtures/function').forEach((dir) => { (config.solo ? test.only : test)(dir, async (t) => { const options = Object.assign( { - input: `fixtures/function/${dir}/main.js` + input: `fixtures/function/${dir}/${config.input || 'main.js'}` }, config.options || {}, { @@ -33,15 +33,21 @@ readdirSync('./fixtures/function').forEach((dir) => { ); const bundle = await rollup(options); - const code = await getCodeFromBundle(bundle); + const codeMap = await getCodeMapFromBundle(bundle); if (config.show || config.solo) { - console.error(code); + console.error(); + for (const chunkName of Object.keys(codeMap)) { + console.error(); + console.error(`===> ${chunkName}`); + console.group(); + console.error(codeMap[chunkName]); + console.groupEnd(); + } } - - const { exports, global } = execute(code, config.context, t); + const { exports, global } = runCodeSplitTest(codeMap, t, config.context); if (config.exports) config.exports(exports, t); if (config.global) config.global(global, t); - t.snapshot(code); + t.snapshot(codeMap); }); }); diff --git a/packages/commonjs/test/helpers/util.js b/packages/commonjs/test/helpers/util.js index 1a1eed8e4..e688a0c00 100644 --- a/packages/commonjs/test/helpers/util.js +++ b/packages/commonjs/test/helpers/util.js @@ -1,4 +1,4 @@ -const relative = require('require-relative'); +const path = require('path'); const commonjsPlugin = require('../../dist/index'); @@ -7,59 +7,83 @@ function commonjs(options) { return commonjsPlugin(options); } -function execute(code, context = {}, t) { - let fn; - const contextKeys = Object.keys(context); - const argNames = contextKeys.concat( - 'module', - 'exports', - 'require', - 'global', - 't', - 'globalThis', - code - ); - +function requireWithContext(code, context) { + const module = { exports: {} }; + const contextWithExports = Object.assign({}, context, { module, exports: module.exports }); + const contextKeys = Object.keys(contextWithExports); + const contextValues = contextKeys.map((key) => contextWithExports[key]); try { - fn = new Function(...argNames); // eslint-disable-line no-new-func - } catch (err) { - // syntax error - console.log(code); // eslint-disable-line no-console - throw err; + // eslint-disable-next-line no-new-func + const fn = new Function(contextKeys, code); + fn.apply({}, contextValues); + } catch (error) { + error.exports = module.exports; + throw error; } + return contextWithExports.module.exports; +} - const module = { exports: {} }; - const global = {}; - - const argValues = contextKeys - .map((key) => context[key]) - .concat(module, module.exports, (name) => relative(name, 'test/x.js'), global, t, global); - - fn(...argValues); - - return { - code, - exports: module.exports, - global +function runCodeSplitTest(codeMap, t, configContext = {}) { + const requireFromOutputVia = (importer) => (importee) => { + const outputId = path.posix.join(path.posix.dirname(importer), importee); + const code = codeMap[outputId]; + if (typeof code !== 'undefined') { + return requireWithContext( + code, + // eslint-disable-next-line no-use-before-define + Object.assign({ require: requireFromOutputVia(outputId) }, context) + ); + } + // eslint-disable-next-line import/no-dynamic-require, global-require + return require(importee); }; + + const chunkNames = Object.keys(codeMap); + const entryName = chunkNames.length === 1 ? chunkNames[0] : 'main.js'; + if (!codeMap[entryName]) { + throw new Error( + `Could not find entry "${entryName}" in generated output.\nChunks:\n${Object.keys( + codeMap + ).join('\n')}` + ); + } + const global = {}; + const context = Object.assign({ t, global, globalThis: global }, configContext); + let exports; + try { + exports = requireWithContext( + codeMap[entryName], + Object.assign({ require: requireFromOutputVia('main.js') }, context) + ); + } catch (error) { + return { error, exports: error.exports }; + } + return { exports, global }; } -const getOutputFromGenerated = (generated) => (generated.output ? generated.output[0] : generated); +async function getCodeMapFromBundle(bundle, options = {}) { + const generated = await bundle.generate(Object.assign({ format: 'cjs' }, options)); + const codeMap = {}; + for (const chunk of generated.output) { + codeMap[chunk.fileName] = chunk.code; + } + return codeMap; +} async function getCodeFromBundle(bundle, customOptions = {}) { const options = Object.assign({ format: 'cjs' }, customOptions); - return getOutputFromGenerated(await bundle.generate(options)).code; + return (await bundle.generate(options)).output[0].code; } async function executeBundle(bundle, t, { context, exports } = {}) { - const code = await getCodeFromBundle(bundle, exports ? { exports } : {}); - return execute(code, context, t); + const codeMap = await getCodeMapFromBundle(bundle, exports ? { exports } : {}); + return runCodeSplitTest(codeMap, t, context); } module.exports = { commonjs, - execute, - getOutputFromGenerated, + executeBundle, getCodeFromBundle, - executeBundle + getCodeMapFromBundle, + runCodeSplitTest }; diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index 4bee7d666..35b985829 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -8,651 +8,2980 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - `'use strict';␊ - ␊ - function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var answer = createCommonjsModule(function (module, exports) {␊ - /* eslint-disable no-underscore-dangle */␊ - exports.__esModule = true;␊ - exports.answer = 42;␊ - });␊ - ␊ - var answer$1 = unwrapExports(answer);␊ - var answer_1 = answer.answer;␊ - ␊ - var x = /*#__PURE__*/Object.freeze({␊ - __proto__: null,␊ - 'default': answer$1,␊ - __moduleExports: answer,␊ - answer: answer_1␊ - });␊ - ␊ - t.truthy('answer' in x);␊ - t.truthy('default' in x);␊ - t.truthy(!('__esModule' in x));␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + var answer = createCommonjsModule(function (module, exports) {␊ + /* eslint-disable no-underscore-dangle */␊ + exports.__esModule = true;␊ + exports.answer = 42;␊ + });␊ + ␊ + var answer$1 = unwrapExports(answer);␊ + var answer_1 = answer.answer;␊ + ␊ + var x = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + 'default': answer$1,␊ + __moduleExports: answer,␊ + answer: answer_1␊ + });␊ + ␊ + t.truthy('answer' in x);␊ + t.truthy('default' in x);␊ + t.truthy(!('__esModule' in x));␊ + `, + } ## assign-properties-to-default-export > Snapshot 1 - `'use strict';␊ - ␊ - const foo = {};␊ - ␊ - var foo_1 = foo;␊ - var bar = 1;␊ - var baz = 2;␊ - foo_1.bar = bar;␊ - foo_1.baz = baz;␊ - ␊ - t.is(foo_1.bar, 1);␊ - t.is(foo_1.baz, 2);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + const foo = {};␊ + ␊ + var foo_1 = foo;␊ + var bar = 1;␊ + var baz = 2;␊ + foo_1.bar = bar;␊ + foo_1.baz = baz;␊ + ␊ + t.is(foo_1.bar, 1);␊ + t.is(foo_1.baz, 2);␊ + `, + } ## assumed-globals > Snapshot 1 - `'use strict';␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var document_1 = createCommonjsModule(function (module) {␊ - /* eslint-disable */␊ - if (typeof document !== 'undefined') {␊ - module.exports = document;␊ - } else {␊ - module.exports = { fake: true };␊ - }␊ - });␊ - var document_2 = document_1.fake;␊ - ␊ - t.deepEqual(document_1, { real: true });␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + var document_1 = createCommonjsModule(function (module) {␊ + /* eslint-disable */␊ + if (typeof document !== 'undefined') {␊ + module.exports = document;␊ + } else {␊ + module.exports = { fake: true };␊ + }␊ + });␊ + var document_2 = document_1.fake;␊ + ␊ + t.deepEqual(document_1, { real: true });␊ + `, + } ## bare-import > Snapshot 1 - `'use strict';␊ - ␊ - Math.bar = 42;␊ - ␊ - t.is(Math.bar, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + Math.bar = 42;␊ + ␊ + t.is(Math.bar, 42);␊ + `, + } ## bare-import-comment > Snapshot 1 - `'use strict';␊ - ␊ - // Great module␊ - Math.bar = 42;␊ - ␊ - t.is(Math.bar, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + // Great module␊ + Math.bar = 42;␊ + ␊ + t.is(Math.bar, 42);␊ + `, + } ## basic > Snapshot 1 - `'use strict';␊ - ␊ - var foo = 21;␊ - ␊ - var main = foo * 2;␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var foo = 21;␊ + ␊ + var main = foo * 2;␊ + ␊ + module.exports = main;␊ + `, + } ## dash-name > Snapshot 1 - `'use strict';␊ - ␊ - var dashName = true;␊ - ␊ - t.truthy(dashName);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var dashName = true;␊ + ␊ + t.truthy(dashName);␊ + `, + } ## deconflict-export-and-local > Snapshot 1 - `'use strict';␊ - ␊ - var someValue_1 = 10;␊ - ␊ - var someValue = {␊ - someValue: someValue_1␊ - };␊ - ␊ - var someValue$1 = someValue.someValue;␊ - ␊ - t.is(someValue$1, 10);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var someValue_1 = 10;␊ + ␊ + var someValue = {␊ + someValue: someValue_1␊ + };␊ + ␊ + var someValue$1 = someValue.someValue;␊ + ␊ + t.is(someValue$1, 10);␊ + `, + } ## dot > Snapshot 1 - `'use strict';␊ - ␊ - var foo_bar = 'fubar';␊ - ␊ - t.is(foo_bar, 'fubar');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var foo_bar = 'fubar';␊ + ␊ + t.is(foo_bar, 'fubar');␊ + `, + } ## duplicate-default-exports > Snapshot 1 - `'use strict';␊ - ␊ - const x = {};␊ - ␊ - var x_1 = x;␊ - var _default = x;␊ - x_1.default = _default;␊ - ␊ - t.is(x_1.default, x_1);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + const x = {};␊ + ␊ + var x_1 = x;␊ + var _default = x;␊ + x_1.default = _default;␊ + ␊ + t.is(x_1.default, x_1);␊ + `, + } ## duplicate-default-exports-b > Snapshot 1 - `'use strict';␊ - ␊ - const x = {};␊ - ␊ - var x_1 = x;␊ - var _default = 42;␊ - x_1.default = _default;␊ - ␊ - t.deepEqual(x_1, { default: 42 });␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + const x = {};␊ + ␊ + var x_1 = x;␊ + var _default = 42;␊ + x_1.default = _default;␊ + ␊ + t.deepEqual(x_1, { default: 42 });␊ + `, + } ## duplicate-default-exports-c > Snapshot 1 - `'use strict';␊ - ␊ - var Foo = 1;␊ - var _var = 'VAR';␊ - var _default = {␊ - Foo: 2,␊ - default: 3␊ - };␊ - ␊ - var exports$1 = {␊ - Foo: Foo,␊ - var: _var,␊ - default: _default␊ - };␊ - ␊ - /* eslint-disable */␊ - ␊ - t.is(exports$1.Foo, 1);␊ - t.is(exports$1.var, 'VAR');␊ - t.deepEqual(exports$1.default, { Foo: 2, default: 3 });␊ - t.is(exports$1.default.Foo, 2);␊ - t.is(exports$1.default.default, 3);␊ - t.is(Foo, 1);␊ - t.is(_var, 'VAR');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var Foo = 1;␊ + var _var = 'VAR';␊ + var _default = {␊ + Foo: 2,␊ + default: 3␊ + };␊ + ␊ + var exports$1 = {␊ + Foo: Foo,␊ + var: _var,␊ + default: _default␊ + };␊ + ␊ + /* eslint-disable */␊ + ␊ + t.is(exports$1.Foo, 1);␊ + t.is(exports$1.var, 'VAR');␊ + t.deepEqual(exports$1.default, { Foo: 2, default: 3 });␊ + t.is(exports$1.default.Foo, 2);␊ + t.is(exports$1.default.default, 3);␊ + t.is(Foo, 1);␊ + t.is(_var, 'VAR');␊ + `, + } + +## dynamic-require + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js", function (module, exports) {␊ + module.exports = function () {␊ + return 'Hello there';␊ + };␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + let message;␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require");␊ + }␊ + ␊ + try {␊ + const submodule = takeModule('submodule');␊ + message = submodule();␊ + } catch ( err ) {␊ + ({ message } = err);␊ + }␊ + ␊ + t.is( message, 'Hello there' );␊ + `, + } + +## dynamic-require-absolute-import + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js", function (module, exports) {␊ + module.exports = 'direct';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js", function (module, exports) {␊ + module.exports = 'nested';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js", function (module, exports) {␊ + module.exports = 'parent';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(name) {␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub");␊ + }␊ + ␊ + var moduleDirect = takeModule('module/direct');␊ + var moduleNested = takeModule('module/nested/nested');␊ + var parentModule = takeModule('parent-module/parent');␊ + ␊ + var submodule = {␊ + moduleDirect: moduleDirect,␊ + moduleNested: moduleNested,␊ + parentModule: parentModule␊ + };␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + t.deepEqual(submodule, {␊ + moduleDirect: 'direct',␊ + moduleNested: 'nested',␊ + parentModule: 'parent'␊ + });␊ + `, + } + +## dynamic-require-absolute-paths + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }␊ + ␊ + var path = _interopDefault(require('path'));␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + ␊ + let basePath = process.cwd() + '/fixtures/function/dynamic-require-absolute-paths';␊ + ␊ + t.is(commonjsRequire(path.resolve(`${basePath}/submodule.js`),"/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths"), 'submodule');␊ + `, + } + +## dynamic-require-code-splitting + +> Snapshot 1 + + { + 'lib2-e9990dfe.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-code-splitting/target1.js", function (module, exports) {␊ + module.exports = '1';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-code-splitting/target2.js", function (module, exports) {␊ + module.exports = '2';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + let message;␊ + ␊ + for (const index of [1, 2]) {␊ + try {␊ + message = commonjsRequire(`./target${index}.js`,"/$$rollup_base$$/fixtures/function/dynamic-require-code-splitting");␊ + } catch (err) {␊ + ({ message } = err);␊ + }␊ + t.is(message, index.toString());␊ + }␊ + ␊ + exports.commonjsRequire = commonjsRequire;␊ + `, + 'main.js': `'use strict';␊ + ␊ + var lib2 = require('./lib2-e9990dfe.js');␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + let message;␊ + ␊ + for (const index of [1, 2]) {␊ + try {␊ + message = lib2.commonjsRequire(`./target${index}.js`,"/$$rollup_base$$/fixtures/function/dynamic-require-code-splitting");␊ + } catch (err) {␊ + ({ message } = err);␊ + }␊ + t.is(message, index.toString());␊ + }␊ + `, + 'main2.js': `'use strict';␊ + ␊ + require('./lib2-e9990dfe.js');␊ + ␊ + `, + } + +## dynamic-require-es-entry + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule (withName) {␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-es-entry");␊ + }␊ + ␊ + var importer = takeModule('submodule.js');␊ + ␊ + t.is(importer, 'submodule');␊ + `, + } + +## dynamic-require-extensions + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js", function (module, exports) {␊ + module.exports = {name: 'submodule', value: null};␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-extensions");␊ + }␊ + ␊ + const withExtension = takeModule('submodule.js');␊ + const withoutExtension = takeModule('submodule');␊ + ␊ + t.is(withExtension.name, 'submodule');␊ + t.is(withoutExtension.name, 'submodule');␊ + ␊ + withExtension.value = 'mutated';␊ + ␊ + t.is(withoutExtension.value, 'mutated');␊ + `, + } + +## dynamic-require-globs + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js", function (module, exports) {␊ + module.exports = 'submodule1';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js", function (module, exports) {␊ + module.exports = 'submodule2';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js", function (module, exports) {␊ + module.exports = 'extramodule1';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-globs");␊ + }␊ + ␊ + t.is(takeModule('submodule1.js'), 'submodule1');␊ + t.is(takeModule('submodule2.js'), 'submodule2');␊ + t.is(takeModule('extramodule1.js'), 'extramodule1');␊ + ␊ + let hasThrown = false;␊ + try {␊ + takeModule('extramodule2.js');␊ + } catch (error) {␊ + t.truthy(/Cannot find module '\\.\\/extramodule2\\.js'/.test(error.message));␊ + hasThrown = true;␊ + }␊ + t.truthy(hasThrown);␊ + `, + } + +## dynamic-require-instances + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js", function (module, exports) {␊ + module.exports = { name: 'direct', value: null };␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js", function (module, exports) {␊ + module.exorts = { name: 'package', value: null };␊ + ␊ + });␊ + ␊ + const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct", function (module, exports) {␊ + module.exports = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js", null);␊ + });␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package", function (module, exports) {␊ + module.exports = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js", null);␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire(withName,"/$$rollup_base$$/fixtures/function/dynamic-require-instances");␊ + }␊ + ␊ + takeModule('./direct').value = 'direct-instance';␊ + t.is(takeModule('./direct/index.js').value, 'direct-instance');␊ + t.is(commonjsRequire("./direct/index.js", "/$$rollup_base$$/fixtures/function/dynamic-require-instances").value, 'direct-instance');␊ + ␊ + takeModule('./package').value = 'package-instance';␊ + t.is(takeModule('./package/main.js').value, 'package-instance');␊ + t.is(commonjsRequire("./package/main.js", "/$$rollup_base$$/fixtures/function/dynamic-require-instances").value, 'package-instance');␊ + `, + } + +## dynamic-require-json + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + var value = "present";␊ + var dynamic = {␊ + value: value␊ + };␊ + ␊ + var dynamic$1 = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + value: value,␊ + 'default': dynamic␊ + });␊ + ␊ + var require$$1 = getCjsExportFromNamespace(dynamic$1);␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-json/dynamic.json", function (module, exports) {␊ + module.exports = require$$1;␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-json");␊ + }␊ + ␊ + t.deepEqual(takeModule('dynamic.json'), {value: 'present'});␊ + t.deepEqual(takeModule('dynamic'), {value: 'present'});␊ + `, + } + +## dynamic-require-package + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + var entry = 'same-directory';␊ + ␊ + var entry$1 = 'sub';␊ + ␊ + var entry$2 = 'custom-module';␊ + ␊ + const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package", function (module, exports) {␊ + module.exports = entry;␊ + });␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package/sub", function (module, exports) {␊ + module.exports = entry$1;␊ + });␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package/node_modules/custom-module", function (module, exports) {␊ + module.exports = entry$2;␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(name) {␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-package/sub");␊ + }␊ + ␊ + var sub = {␊ + parent: takeModule('..'),␊ + customModule: takeModule('custom-module')␊ + };␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule$1(name) {␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-package");␊ + }␊ + ␊ + t.is(takeModule$1('.'), 'same-directory');␊ + t.is(takeModule$1('./'), 'same-directory');␊ + t.is(takeModule$1('.//'), 'same-directory');␊ + ␊ + t.is(takeModule$1('./sub'), 'sub');␊ + ␊ + t.is(takeModule$1('custom-module'), 'custom-module');␊ + t.deepEqual(sub, { parent: 'same-directory', customModule: 'custom-module' });␊ + `, + } + +## dynamic-require-package-sub + +> Snapshot 1 + + { + 'entry.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", function (module, exports) {␊ + module.exports = 'custom-module';␊ + ␊ + });␊ + ␊ + var main = "./entry.js";␊ + var _package = {␊ + main: main␊ + };␊ + ␊ + var _package$1 = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + main: main,␊ + 'default': _package␊ + });␊ + ␊ + var require$$1 = getCjsExportFromNamespace(_package$1);␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json", function (module, exports) {␊ + module.exports = require$$1;␊ + });␊ + ␊ + const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module", function (module, exports) {␊ + module.exports = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", null);␊ + });␊ + ␊ + t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ + `, + } + +## dynamic-require-relative-paths + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js", function (module, exports) {␊ + module.exports = 'subsubmodule';␊ + ␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModuleWithDelimiter(name, delimiter) {␊ + return commonjsRequire('.' + delimiter + name.replace(/=/g, delimiter),"/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths");␊ + }␊ + ␊ + t.is(takeModuleWithDelimiter('sub=submodule.js', '/'), 'submodule');␊ + t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '/'), 'subsubmodule');␊ + t.is(takeModuleWithDelimiter('sub=submodule.js', '\\\\'), 'submodule');␊ + t.is(takeModuleWithDelimiter('sub=subsub=subsubmodule.js', '\\\\'), 'subsubmodule');␊ + `, + } + +## dynamic-require-resolve-index + +> Snapshot 1 + + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + function commonjsRegister (path, loader) {␊ + DYNAMIC_REQUIRE_LOADERS[path] = loader;␊ + }␊ + ␊ + const DYNAMIC_REQUIRE_LOADERS = Object.create(null);␊ + const DYNAMIC_REQUIRE_CACHE = Object.create(null);␊ + const DEFAULT_PARENT_MODULE = {␊ + id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []␊ + };␊ + const CHECKED_EXTENSIONS = ['', '.js', '.json'];␊ + ␊ + function normalize (path) {␊ + path = path.replace(/\\\\/g, '/');␊ + const parts = path.split('/');␊ + const slashed = parts[0] === '';␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] === '.' || parts[i] === '') {␊ + parts.splice(i--, 1);␊ + }␊ + }␊ + for (let i = 1; i < parts.length; i++) {␊ + if (parts[i] !== '..') continue;␊ + if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {␊ + parts.splice(--i, 2);␊ + i--;␊ + }␊ + }␊ + path = parts.join('/');␊ + if (slashed && path[0] !== '/')␊ + path = '/' + path;␊ + else if (path.length === 0)␊ + path = '.';␊ + return path;␊ + }␊ + ␊ + function join () {␊ + if (arguments.length === 0)␊ + return '.';␊ + let joined;␊ + for (let i = 0; i < arguments.length; ++i) {␊ + let arg = arguments[i];␊ + if (arg.length > 0) {␊ + if (joined === undefined)␊ + joined = arg;␊ + else␊ + joined += '/' + arg;␊ + }␊ + }␊ + if (joined === undefined)␊ + return '.';␊ + ␊ + return joined;␊ + }␊ + ␊ + function isPossibleNodeModulesPath (modulePath) {␊ + let c0 = modulePath[0];␊ + if (c0 === '/' || c0 === '\\\\') return false;␊ + let c1 = modulePath[1], c2 = modulePath[2];␊ + if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||␊ + (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;␊ + if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))␊ + return false;␊ + return true;␊ + }␊ + ␊ + function commonjsRequire (path, originalModuleDir) {␊ + const shouldTryNodeModules = isPossibleNodeModulesPath(path);␊ + path = normalize(path);␊ + let relPath;␊ + while (true) {␊ + if (!shouldTryNodeModules) {␊ + relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;␊ + } else if (originalModuleDir) {␊ + relPath = normalize(originalModuleDir + '/node_modules/' + path);␊ + } else {␊ + relPath = normalize(join('node_modules', path));␊ + }␊ + for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {␊ + const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];␊ + let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + if (cachedModule) return cachedModule.exports;␊ + const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];␊ + if (loader) {␊ + DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {␊ + id: resolvedPath,␊ + filename: resolvedPath,␊ + exports: {},␊ + parent: DEFAULT_PARENT_MODULE,␊ + loaded: false,␊ + children: [],␊ + paths: []␊ + };␊ + try {␊ + loader.call(commonjsGlobal, cachedModule, cachedModule.exports);␊ + } catch (error) {␊ + delete DYNAMIC_REQUIRE_CACHE[resolvedPath];␊ + throw error;␊ + }␊ + cachedModule.loaded = true;␊ + return cachedModule.exports;␊ + } }␊ + if (!shouldTryNodeModules) break;␊ + const nextDir = normalize(originalModuleDir + '/..');␊ + if (nextDir === originalModuleDir) break;␊ + originalModuleDir = nextDir;␊ + }␊ + return require(path);␊ + }␊ + ␊ + commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;␊ + ␊ + var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + commonjsGlobal: commonjsGlobal,␊ + unwrapExports: unwrapExports,␊ + createCommonjsModule: createCommonjsModule,␊ + getCjsExportFromNamespace: getCjsExportFromNamespace,␊ + commonjsRegister: commonjsRegister,␊ + commonjsRequire: commonjsRequire␊ + });␊ + ␊ + var dynamicRequireResolveIndex = 'same-directory';␊ + ␊ + var sub = 'sub';␊ + ␊ + var customModule = 'custom-module';␊ + ␊ + const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index", function (module, exports) {␊ + module.exports = dynamicRequireResolveIndex;␊ + });␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub", function (module, exports) {␊ + module.exports = sub;␊ + });␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module", function (module, exports) {␊ + module.exports = customModule;␊ + });␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(name) {␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub");␊ + }␊ + ␊ + var sub$1 = {␊ + parent: takeModule('..'),␊ + customModule: takeModule('custom-module')␊ + };␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule$1(name) {␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index");␊ + }␊ + ␊ + t.is(takeModule$1('.'), 'same-directory');␊ + t.is(takeModule$1('./'), 'same-directory');␊ + t.is(takeModule$1('.//'), 'same-directory');␊ + ␊ + t.is(takeModule$1('./sub'), 'sub');␊ + ␊ + t.is(takeModule$1('custom-module'), 'custom-module');␊ + t.deepEqual(sub$1, { parent: 'same-directory', customModule: 'custom-module' });␊ + `, + } ## export-default-from > Snapshot 1 - `'use strict';␊ - ␊ - var require$$0 = 'default export';␊ - ␊ - t.is(require$$0, 'default export');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var require$$0 = 'default export';␊ + ␊ + t.is(require$$0, 'default export');␊ + `, + } ## exports > Snapshot 1 - `'use strict';␊ - ␊ - var bar = 'BAR';␊ - var baz = 'BAZ';␊ - ␊ - var foo = {␊ - bar: bar,␊ - baz: baz␊ - };␊ - ␊ - const { bar: bar$1 } = foo;␊ - const { baz: baz$1 } = foo;␊ - ␊ - var main = bar$1 + baz$1;␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var bar = 'BAR';␊ + var baz = 'BAZ';␊ + ␊ + var foo = {␊ + bar: bar,␊ + baz: baz␊ + };␊ + ␊ + const { bar: bar$1 } = foo;␊ + const { baz: baz$1 } = foo;␊ + ␊ + var main = bar$1 + baz$1;␊ + ␊ + module.exports = main;␊ + `, + } ## external-imports > Snapshot 1 - `'use strict';␊ - ␊ - function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }␊ - ␊ - var foo = _interopDefault(require('foo'));␊ - ␊ - var main = foo;␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }␊ + ␊ + var foo = _interopDefault(require('foo'));␊ + ␊ + var main = foo;␊ + ␊ + module.exports = main;␊ + `, + } ## fallback-no-default > Snapshot 1 - `'use strict';␊ - ␊ - /* eslint-disable */␊ - var one = 1;␊ - ␊ - var two = 2;␊ - ␊ - var foo = /*#__PURE__*/Object.freeze({␊ - __proto__: null,␊ - one: one,␊ - two: two␊ - });␊ - ␊ - t.is(foo.one, 1);␊ - t.is(foo.two, 2);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + /* eslint-disable */␊ + var one = 1;␊ + ␊ + var two = 2;␊ + ␊ + var foo = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + one: one,␊ + two: two␊ + });␊ + ␊ + t.is(foo.one, 1);␊ + t.is(foo.two, 2);␊ + `, + } ## global-not-overwritten > Snapshot 1 - `'use strict';␊ - ␊ - Object.defineProperty(exports, '__esModule', { value: true });␊ - ␊ - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var encode = createCommonjsModule(function (module, exports) {␊ - exports.encodeURIComponent = function() {␊ - return encodeURIComponent(this.str);␊ - };␊ - ␊ - // to ensure module is wrapped␊ - commonjsGlobal.foo = exports;␊ - });␊ - var encode_1 = encode.encodeURIComponent;␊ - ␊ - /* eslint-disable */␊ - ␊ - const foo = {␊ - str: 'test string',␊ - encodeURIComponent: encode_1␊ - };␊ - ␊ - var encoded = foo.encodeURIComponent();␊ - ␊ - exports.encoded = encoded;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + Object.defineProperty(exports, '__esModule', { value: true });␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + var encode = createCommonjsModule(function (module, exports) {␊ + exports.encodeURIComponent = function() {␊ + return encodeURIComponent(this.str);␊ + };␊ + ␊ + // to ensure module is wrapped␊ + commonjsGlobal.foo = exports;␊ + });␊ + var encode_1 = encode.encodeURIComponent;␊ + ␊ + /* eslint-disable */␊ + ␊ + const foo = {␊ + str: 'test string',␊ + encodeURIComponent: encode_1␊ + };␊ + ␊ + var encoded = foo.encodeURIComponent();␊ + ␊ + exports.encoded = encoded;␊ + `, + } ## global-var > Snapshot 1 - `'use strict';␊ - ␊ - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ - ␊ - /* eslint-disable */␊ - function foo() {␊ - const global = {};␊ - global.modified = true;␊ - return global;␊ - }␊ - ␊ - const notGlobal = foo();␊ - t.truthy(notGlobal.modified);␊ - t.truthy(!commonjsGlobal.modified);␊ - ␊ - var main = {};␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + /* eslint-disable */␊ + function foo() {␊ + const global = {};␊ + global.modified = true;␊ + return global;␊ + }␊ + ␊ + const notGlobal = foo();␊ + t.truthy(notGlobal.modified);␊ + t.truthy(!commonjsGlobal.modified);␊ + ␊ + var main = {};␊ + ␊ + module.exports = main;␊ + `, + } ## index > Snapshot 1 - `'use strict';␊ - ␊ - var foo = 42;␊ - ␊ - t.is(foo, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var foo = 42;␊ + ␊ + t.is(foo, 42);␊ + `, + } ## inline > Snapshot 1 - `'use strict';␊ - ␊ - var multiply = function(a, b) {␊ - return a * b;␊ - };␊ - ␊ - var foo = 1;␊ - ␊ - /* eslint-disable global-require */␊ - var main = function() {␊ - return multiply(2, foo);␊ - };␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var multiply = function(a, b) {␊ + return a * b;␊ + };␊ + ␊ + var foo = 1;␊ + ␊ + /* eslint-disable global-require */␊ + var main = function() {␊ + return multiply(2, foo);␊ + };␊ + ␊ + module.exports = main;␊ + `, + } ## named-exports > Snapshot 1 - `'use strict';␊ - ␊ - var a = 1;␊ - var b = 2;␊ - ␊ - t.is(a, 1);␊ - t.is(b, 2);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var a = 1;␊ + var b = 2;␊ + ␊ + t.is(a, 1);␊ + t.is(b, 2);␊ + `, + } ## ordering > Snapshot 1 - `'use strict';␊ - ␊ - var shared = {␊ - fooLoaded: false␊ - };␊ - ␊ - // Mutate the shared module␊ - shared.fooLoaded = true;␊ - ␊ - var bar = shared.fooLoaded;␊ - ␊ - t.truthy(bar);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var shared = {␊ + fooLoaded: false␊ + };␊ + ␊ + // Mutate the shared module␊ + shared.fooLoaded = true;␊ + ␊ + var bar = shared.fooLoaded;␊ + ␊ + t.truthy(bar);␊ + `, + } ## react-apollo > Snapshot 1 - `'use strict';␊ - ␊ - function unwrapExports (x) {␊ - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var commonjsBar = createCommonjsModule(function (module, exports) {␊ - /* eslint-disable no-underscore-dangle */␊ - function Bar() {␊ - this.x = 42;␊ - }␊ - ␊ - exports.__esModule = true;␊ - exports.default = Bar;␊ - });␊ - ␊ - unwrapExports(commonjsBar);␊ - ␊ - var commonjsFoo = createCommonjsModule(function (module, exports) {␊ - /* eslint-disable no-underscore-dangle */␊ - ␊ - ␊ - exports.__esModule = true;␊ - exports.Bar = commonjsBar.default;␊ - });␊ - ␊ - unwrapExports(commonjsFoo);␊ - var commonjsFoo_1 = commonjsFoo.Bar;␊ - ␊ - t.is(new commonjsFoo_1().x, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function unwrapExports (x) {␊ + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ + }␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + var commonjsBar = createCommonjsModule(function (module, exports) {␊ + /* eslint-disable no-underscore-dangle */␊ + function Bar() {␊ + this.x = 42;␊ + }␊ + ␊ + exports.__esModule = true;␊ + exports.default = Bar;␊ + });␊ + ␊ + unwrapExports(commonjsBar);␊ + ␊ + var commonjsFoo = createCommonjsModule(function (module, exports) {␊ + /* eslint-disable no-underscore-dangle */␊ + ␊ + ␊ + exports.__esModule = true;␊ + exports.Bar = commonjsBar.default;␊ + });␊ + ␊ + unwrapExports(commonjsFoo);␊ + var commonjsFoo_1 = commonjsFoo.Bar;␊ + ␊ + t.is(new commonjsFoo_1().x, 42);␊ + `, + } ## reassignment > Snapshot 1 - `'use strict';␊ - ␊ - function foo() {}␊ - foo.something = false;␊ - ␊ - var foo_1 = foo;␊ - ␊ - let foo$1 = foo_1;␊ - ␊ - if (!foo$1.something) {␊ - foo$1 = function somethingElse() {};␊ - foo$1.something = true;␊ - }␊ - ␊ - t.truthy(foo$1.something);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function foo() {}␊ + foo.something = false;␊ + ␊ + var foo_1 = foo;␊ + ␊ + let foo$1 = foo_1;␊ + ␊ + if (!foo$1.something) {␊ + foo$1 = function somethingElse() {};␊ + foo$1.something = true;␊ + }␊ + ␊ + t.truthy(foo$1.something);␊ + `, + } ## reexports > Snapshot 1 - `'use strict';␊ - ␊ - var named = 42;␊ - ␊ - var bar = {␊ - named: named␊ - };␊ - ␊ - var foo = bar;␊ - var foo_1 = foo.named;␊ - ␊ - t.is(foo_1, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var named = 42;␊ + ␊ + var bar = {␊ + named: named␊ + };␊ + ␊ + var foo = bar;␊ + var foo_1 = foo.named;␊ + ␊ + t.is(foo_1, 42);␊ + `, + } ## resolve-is-cjs-extension > Snapshot 1 - `'use strict';␊ - ␊ - const result = 'second';␊ - ␊ - var second = /*#__PURE__*/Object.freeze({␊ - __proto__: null,␊ - result: result␊ - });␊ - ␊ - function getCjsExportFromNamespace (n) {␊ - return n && n['default'] || n;␊ - }␊ - ␊ - var require$$0 = getCjsExportFromNamespace(second);␊ - ␊ - t.is(require$$0.result, 'second');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + const result = 'second';␊ + ␊ + var second = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + result: result␊ + });␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + var require$$0 = getCjsExportFromNamespace(second);␊ + ␊ + t.is(require$$0.result, 'second');␊ + `, + } ## resolve-is-cjs-filtered > Snapshot 1 - `'use strict';␊ - ␊ - const result = 'second';␊ - ␊ - var second = /*#__PURE__*/Object.freeze({␊ - __proto__: null,␊ - result: result␊ - });␊ - ␊ - function getCjsExportFromNamespace (n) {␊ - return n && n['default'] || n;␊ - }␊ - ␊ - var require$$0 = getCjsExportFromNamespace(second);␊ - ␊ - t.is(require$$0.result, 'second');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + const result = 'second';␊ + ␊ + var second = /*#__PURE__*/Object.freeze({␊ + __proto__: null,␊ + result: result␊ + });␊ + ␊ + function getCjsExportFromNamespace (n) {␊ + return n && n['default'] || n;␊ + }␊ + ␊ + var require$$0 = getCjsExportFromNamespace(second);␊ + ␊ + t.is(require$$0.result, 'second');␊ + `, + } ## shadowing > Snapshot 1 - `'use strict';␊ - ␊ - function foo(require) {␊ - require('not-an-actual-require-statement');␊ - }␊ - ␊ - let result;␊ - ␊ - foo((msg) => {␊ - result = msg;␊ - });␊ - ␊ - t.is(result, 'not-an-actual-require-statement');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function foo(require) {␊ + require('not-an-actual-require-statement');␊ + }␊ + ␊ + let result;␊ + ␊ + foo((msg) => {␊ + result = msg;␊ + });␊ + ␊ + t.is(result, 'not-an-actual-require-statement');␊ + `, + } ## skips-dead-branches > Snapshot 1 - `'use strict';␊ - ␊ - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ - ␊ - commonjsGlobal.b = 2;␊ - var b = 'b';␊ - ␊ - var main = b ;␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + commonjsGlobal.b = 2;␊ + var b = 'b';␊ + ␊ + var main = b ;␊ + ␊ + module.exports = main;␊ + `, + } ## this > Snapshot 1 - `'use strict';␊ - ␊ - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ - ␊ - var foo = function augmentThis() {␊ - this.x = 'x';␊ - };␊ - ␊ - commonjsGlobal.y = 'y';␊ - ␊ - const obj = {};␊ - foo.call(obj);␊ - ␊ - t.is(obj.x, 'x');␊ - t.is(commonjsGlobal.y, 'y');␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ + ␊ + var foo = function augmentThis() {␊ + this.x = 'x';␊ + };␊ + ␊ + commonjsGlobal.y = 'y';␊ + ␊ + const obj = {};␊ + foo.call(obj);␊ + ␊ + t.is(obj.x, 'x');␊ + t.is(commonjsGlobal.y, 'y');␊ + `, + } ## toplevel-return > Snapshot 1 - `'use strict';␊ - ␊ - /* eslint-disable */␊ - ␊ - ␊ - var main = 'foo';␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + /* eslint-disable */␊ + ␊ + ␊ + var main = 'foo';␊ + ␊ + module.exports = main;␊ + `, + } ## toplevel-return-complex > Snapshot 1 - `'use strict';␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var foo = createCommonjsModule(function (module) {␊ - module.exports = 'bar';␊ - {␊ - return;␊ - }␊ - });␊ - ␊ - var main = foo;␊ - ␊ - module.exports = main;␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + var foo = createCommonjsModule(function (module) {␊ + module.exports = 'bar';␊ + {␊ + return;␊ + }␊ + });␊ + ␊ + var main = foo;␊ + ␊ + module.exports = main;␊ + `, + } ## trailing-slash > Snapshot 1 - `'use strict';␊ - ␊ - var foo = 42;␊ - ␊ - t.is(foo, 42);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + var foo = 42;␊ + ␊ + t.is(foo, 42);␊ + `, + } ## typeof-require > Snapshot 1 - `'use strict';␊ - ␊ - function commonjsRequire () {␊ - throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');␊ - }␊ - ␊ - function createCommonjsModule(fn, module) {␊ - return module = { exports: {} }, fn(module, module.exports), module.exports;␊ - }␊ - ␊ - var foo = createCommonjsModule(function (module) {␊ - if (typeof commonjsRequire === 'function' && commonjsRequire) {␊ - module.exports = 1;␊ - } else {␊ - module.exports = 2;␊ - }␊ - });␊ - ␊ - t.is(foo, 1);␊ - ` + { + 'main.js': `'use strict';␊ + ␊ + function createCommonjsModule(fn, module) {␊ + return module = { exports: {} }, fn(module, module.exports), module.exports;␊ + }␊ + ␊ + function commonjsRequire () {␊ + throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');␊ + }␊ + ␊ + var foo = createCommonjsModule(function (module) {␊ + if (typeof commonjsRequire === 'function' && commonjsRequire) {␊ + module.exports = 1;␊ + } else {␊ + module.exports = 2;␊ + }␊ + });␊ + ␊ + t.is(foo, 1);␊ + `, + } diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index 60848ee9d..70c4b04a7 100644 Binary files a/packages/commonjs/test/snapshots/function.js.snap and b/packages/commonjs/test/snapshots/function.js.snap differ diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js index 327ddd97f..6dd9b8b8f 100644 --- a/packages/commonjs/test/test.js +++ b/packages/commonjs/test/test.js @@ -10,7 +10,7 @@ import resolve from '@rollup/plugin-node-resolve'; import { testBundle } from '../../../util/test'; -import { commonjs, getCodeFromBundle, getOutputFromGenerated, executeBundle } from './helpers/util'; +import { commonjs, executeBundle, getCodeFromBundle } from './helpers/util'; install(); @@ -23,13 +23,13 @@ test('generates a sourcemap', async (t) => { plugins: [commonjs({ sourceMap: true })] }); - const { code, map } = getOutputFromGenerated( - await bundle.generate({ - format: 'cjs', - sourcemap: true, - sourcemapFile: path.resolve('bundle.js') - }) - ); + const { + output: [{ code, map }] + } = await bundle.generate({ + format: 'cjs', + sourcemap: true, + sourcemapFile: path.resolve('bundle.js') + }); const smc = new SourceMapConsumer(map); const locator = getLocator(code, { offsetLine: 1 }); @@ -357,7 +357,9 @@ test('typeof transforms: sinon', async (t) => { plugins: [commonjs()] }); - const { code } = getOutputFromGenerated(await bundle.generate({ format: 'es' })); + const { + output: [{ code }] + } = await bundle.generate({ format: 'es' }); t.is(code.indexOf('typeof require'), -1, code); // t.not( code.indexOf( 'typeof module' ), -1, code ); // #151 breaks this test diff --git a/packages/commonjs/test/types.ts b/packages/commonjs/test/types.ts index a6e99e207..3835ef375 100644 --- a/packages/commonjs/test/types.ts +++ b/packages/commonjs/test/types.ts @@ -14,7 +14,8 @@ const config: import('rollup').RollupOptions = { ignoreGlobal: false, sourceMap: false, namedExports: { './module.js': ['foo', 'bar'] }, - ignore: ['conditional-runtime-dependency'] + ignore: ['conditional-runtime-dependency'], + dynamicRequireTargets: [ 'node_modules/logform/*.js' ] }) ] }; diff --git a/packages/commonjs/types/index.d.ts b/packages/commonjs/types/index.d.ts index f57388fe1..1ae223166 100644 --- a/packages/commonjs/types/index.d.ts +++ b/packages/commonjs/types/index.d.ts @@ -43,6 +43,19 @@ interface RollupCommonJSOptions { * option if you know what you're doing! */ ignore?: ReadonlyArray boolean)>; + /** + * Some modules contain dynamic `require` calls, or require modules that contain + * circular dependencies, which are not handled well by static imports. + * Including those modules as `dynamicRequireTargets` will simulate a CommonJS (NodeJS-like) + * environment for them with support for dynamic and circular dependencies. + * + * Note: In extreme cases, this feature may result in some paths being rendered as + * absolute in the final bundle. The plugin tries to avoid exposing paths from + * the local machine, but if you are `dynamicRequirePaths` with paths that are + * far away from your project's folder, that may require replacing strings + * like `"/Users/John/Desktop/foo-project/"` -> `"/"`. + */ + dynamicRequireTargets?: string|ReadonlyArray; } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc73c202c..21f0f40ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,7 +20,7 @@ importers: pnpm: 4.7.2 prettier: 1.19.1 prettier-plugin-package: 0.3.1_prettier@1.19.1 - rollup: 2.0.0 + rollup: 2.2.0 ts-node: 8.6.2_typescript@3.7.5 tsconfig-paths: 3.9.0 tslib: 1.10.0 @@ -55,10 +55,10 @@ importers: dependencies: slash: 3.0.0 devDependencies: - '@rollup/plugin-node-resolve': 7.1.1_rollup@2.0.0 - '@rollup/plugin-typescript': 3.1.0_rollup@2.0.0 + '@rollup/plugin-node-resolve': 7.1.1_rollup@2.2.0 + '@rollup/plugin-typescript': 3.0.0_rollup@2.2.0 del-cli: 3.0.0 - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/plugin-node-resolve': ^7.0.0 '@rollup/plugin-typescript': ^3.0.0 @@ -67,11 +67,11 @@ importers: slash: ^3.0.0 packages/auto-install: devDependencies: - '@rollup/plugin-node-resolve': 7.1.1_rollup@2.0.0 - '@rollup/plugin-typescript': 3.1.0_rollup@2.0.0 + '@rollup/plugin-node-resolve': 7.1.1_rollup@2.2.0 + '@rollup/plugin-typescript': 3.0.0_rollup@2.2.0 del: 5.1.0 node-noop: 1.0.0 - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/plugin-node-resolve': ^7.0.0 '@rollup/plugin-typescript': ^3.0.0 @@ -80,20 +80,20 @@ importers: rollup: ^2.0.0 packages/beep: devDependencies: - rollup: 2.0.0 + rollup: 2.2.0 strip-ansi: 5.2.0 specifiers: rollup: ^2.0.0 strip-ansi: ^5.2.0 packages/buble: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 '@types/buble': 0.19.2 buble: 0.19.8 devDependencies: - '@rollup/plugin-typescript': 3.1.0_rollup@2.0.0+typescript@3.7.5 + '@rollup/plugin-typescript': 3.0.0_rollup@2.2.0+typescript@3.7.5 del-cli: 3.0.0 - rollup: 2.0.0 + rollup: 2.2.0 source-map: 0.7.3 typescript: 3.7.5 specifiers: @@ -107,23 +107,25 @@ importers: typescript: ^3.7.4 packages/commonjs: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 + commondir: 1.0.1 estree-walker: 1.0.1 + glob: 7.1.6 is-reference: 1.1.4 magic-string: 0.25.6 - resolve: 1.14.2 + resolve: 1.15.0 devDependencies: '@babel/core': 7.8.3 '@babel/preset-env': 7.8.3_@babel+core@7.8.3 '@babel/register': 7.8.3_@babel+core@7.8.3 - '@rollup/plugin-json': 4.0.2_rollup@2.0.0 - '@rollup/plugin-node-resolve': 7.1.1_rollup@2.0.0 + '@rollup/plugin-json': 4.0.1_rollup@2.2.0 + '@rollup/plugin-node-resolve': 7.1.1_rollup@2.2.0 acorn: 7.1.0 locate-character: 2.0.5 prettier: 1.19.1 require-relative: 0.8.7 - rollup: 2.0.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.0.0 + rollup: 2.2.0 + rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.2.0 shx: 0.3.2 source-map: 0.6.1 source-map-support: 0.5.16 @@ -136,7 +138,9 @@ importers: '@rollup/plugin-node-resolve': ^7.0.0 '@rollup/pluginutils': ^3.0.8 acorn: ^7.1.0 + commondir: ^1.0.1 estree-walker: ^1.0.1 + glob: ^7.1.2 is-reference: ^1.1.2 locate-character: ^2.0.5 magic-string: ^0.25.2 @@ -151,9 +155,9 @@ importers: typescript: ^3.7.4 packages/data-uri: devDependencies: - '@rollup/plugin-typescript': 3.1.0_rollup@2.0.0+typescript@3.7.5 - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 - rollup: 2.0.0 + '@rollup/plugin-typescript': 3.0.0_rollup@2.2.0+typescript@3.7.5 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 + rollup: 2.2.0 typescript: 3.7.5 specifiers: '@rollup/plugin-typescript': ^3.0.0 @@ -162,12 +166,12 @@ importers: typescript: ^3.7.4 packages/dsv: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 d3-dsv: 1.2.0 tosource: 1.0.0 devDependencies: del-cli: 3.0.0 - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/pluginutils': ^3.0.4 d3-dsv: 1.2.0 @@ -176,18 +180,18 @@ importers: tosource: ^1.0.0 packages/html: devDependencies: - rollup: 2.0.0 + rollup: 2.2.0 rollup-plugin-postcss: 2.0.3 specifiers: rollup: ^2.0.0 rollup-plugin-postcss: ^2.0.3 packages/image: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 mini-svg-data-uri: 1.1.3 devDependencies: - '@rollup/plugin-buble': 0.21.1_rollup@2.0.0 - rollup: 2.0.0 + '@rollup/plugin-buble': 0.21.0_rollup@2.2.0 + rollup: 2.2.0 specifiers: '@rollup/plugin-buble': ^0.21.0 '@rollup/pluginutils': ^3.0.4 @@ -195,14 +199,14 @@ importers: rollup: ^2.0.0 packages/inject: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 estree-walker: 1.0.1 magic-string: 0.25.6 devDependencies: - '@rollup/plugin-buble': 0.21.1_rollup@2.0.0 + '@rollup/plugin-buble': 0.21.0_rollup@2.2.0 del-cli: 3.0.0 locate-character: 2.0.5 - rollup: 2.0.0 + rollup: 2.2.0 source-map: 0.7.3 typescript: 3.7.5 specifiers: @@ -229,9 +233,9 @@ importers: source-map-support: ^0.5.16 packages/legacy: devDependencies: - '@rollup/plugin-buble': 0.20.0_rollup@2.0.0 + '@rollup/plugin-buble': 0.20.0_rollup@2.2.0 del-cli: 3.0.0 - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/plugin-buble': ^0.20.0 del-cli: ^3.0.0 @@ -242,8 +246,8 @@ importers: devDependencies: '@babel/core': 7.8.3 '@babel/preset-env': 7.8.3_@babel+core@7.8.3 - rollup: 2.0.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.0.0 + rollup: 2.2.0 + rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.2.0 specifiers: '@babel/core': ^7.2.0 '@babel/preset-env': ^7.2.0 @@ -252,19 +256,19 @@ importers: rollup-plugin-babel: ^4.0.3 packages/node-resolve: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 '@types/resolve': 0.0.8 builtin-modules: 3.1.0 is-module: 1.0.0 - resolve: 1.14.2 + resolve: 1.15.0 devDependencies: '@babel/core': 7.8.3 '@babel/preset-env': 7.8.3_@babel+core@7.8.3 - '@rollup/plugin-json': 4.0.2_rollup@2.0.0 + '@rollup/plugin-json': 4.0.1_rollup@2.2.0 es5-ext: 0.10.53 - rollup: 2.0.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.0.0 - rollup-plugin-commonjs: 10.1.0_rollup@2.0.0 + rollup: 2.2.0 + rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.2.0 + rollup-plugin-commonjs: 10.1.0_rollup@2.2.0 source-map: 0.7.3 string-capitalize: 1.0.1 specifiers: @@ -293,7 +297,7 @@ importers: '@rollup/plugin-typescript': 3.0.0_typescript@3.7.5 '@types/jest': 24.9.0 '@types/micromatch': 3.1.1 - '@types/node': 12.12.25 + '@types/node': 12.12.28 typescript: 3.7.5 specifiers: '@rollup/plugin-commonjs': ^11.0.2 @@ -308,13 +312,13 @@ importers: typescript: ^3.7.5 packages/replace: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 magic-string: 0.25.6 devDependencies: - '@rollup/plugin-buble': 0.21.1_rollup@2.0.0 + '@rollup/plugin-buble': 0.21.0_rollup@2.2.0 del-cli: 3.0.0 locate-character: 2.0.5 - rollup: 2.0.0 + rollup: 2.2.0 source-map: 0.7.3 typescript: 3.7.5 specifiers: @@ -330,7 +334,7 @@ importers: devDependencies: '@types/node': 13.1.6 del: 5.1.0 - rollup: 2.0.0 + rollup: 2.2.0 sinon: 8.0.4 specifiers: '@types/node': 13.1.6 @@ -339,12 +343,12 @@ importers: sinon: 8.0.4 packages/strip: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 estree-walker: 1.0.1 magic-string: 0.25.6 devDependencies: acorn: 7.1.0 - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/pluginutils': ^3.0.4 acorn: 7.1.0 @@ -353,24 +357,24 @@ importers: rollup: ^2.0.0 packages/sucrase: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 sucrase: 3.12.1 devDependencies: - rollup: 2.0.0 + rollup: 2.2.0 specifiers: '@rollup/pluginutils': ^3.0.1 rollup: ^2.0.0 sucrase: ^3.10.1 packages/typescript: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 - resolve: 1.14.2 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 + resolve: 1.15.0 devDependencies: - '@rollup/plugin-buble': 0.21.1_rollup@2.0.0 - '@rollup/plugin-commonjs': 11.0.2_rollup@2.0.0 - '@rollup/plugin-typescript': 3.1.0_906bf73aac2a7717ec0c8c901fd0cdee + '@rollup/plugin-buble': 0.21.0_rollup@2.2.0 + '@rollup/plugin-commonjs': 11.0.2_rollup@2.2.0 + '@rollup/plugin-typescript': 3.0.0_b32f28c91b7d5afb3a4e5593fb670831 buble: 0.19.8 - rollup: 2.0.0 + rollup: 2.2.0 tslib: 1.10.0 typescript: 3.7.5 specifiers: @@ -385,7 +389,7 @@ importers: typescript: ^3.7.4 packages/url: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 make-dir: 3.0.0 mime: 2.4.4 devDependencies: @@ -394,8 +398,8 @@ importers: '@babel/register': 7.8.3_@babel+core@7.8.3 del: 5.1.0 globby: 10.0.2 - rollup: 2.0.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.0.0 + rollup: 2.2.0 + rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.2.0 specifiers: '@babel/core': ^7.7.7 '@babel/preset-env': ^7.7.7 @@ -409,15 +413,15 @@ importers: rollup-plugin-babel: ^4.3.3 packages/virtual: devDependencies: - '@rollup/plugin-node-resolve': 7.1.1_rollup@2.0.0 - rollup: 2.0.0 + '@rollup/plugin-node-resolve': 7.1.1_rollup@2.2.0 + rollup: 2.2.0 specifiers: '@rollup/plugin-node-resolve': ^7.0.0 rollup: ^2.0.0 packages/wasm: devDependencies: del-cli: 3.0.0 - rollup: 2.0.0 + rollup: 2.2.0 source-map: 0.7.3 specifiers: del-cli: ^3.0.0 @@ -425,16 +429,16 @@ importers: source-map: ^0.7.3 packages/yaml: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 js-yaml: 3.13.1 tosource: 1.0.0 devDependencies: '@babel/core': 7.8.3 '@babel/preset-env': 7.8.3_@babel+core@7.8.3 - '@rollup/plugin-node-resolve': 6.1.0_rollup@2.0.0 + '@rollup/plugin-node-resolve': 6.1.0_rollup@2.2.0 del-cli: 3.0.0 - rollup: 2.0.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.0.0 + rollup: 2.2.0 + rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@2.2.0 source-map-support: 0.5.16 specifiers: '@babel/core': ^7.7.7 @@ -506,7 +510,7 @@ packages: gensync: 1.0.0-beta.1 json5: 2.1.1 lodash: 4.17.15 - resolve: 1.14.2 + resolve: 1.15.0 semver: 5.7.1 source-map: 0.5.7 dev: true @@ -1323,10 +1327,10 @@ packages: node: '>= 8' resolution: integrity: sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ== - /@rollup/plugin-buble/0.20.0_rollup@2.0.0: + /@rollup/plugin-buble/0.20.0_rollup@2.2.0: dependencies: buble: 0.19.8 - rollup: 2.0.0 + rollup: 2.2.0 rollup-pluginutils: 2.8.2 typescript: 3.7.5 dev: true @@ -1344,24 +1348,24 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-n6N311RCrVvnsWGyo/if6K2kFoDW+x9r+/hkp+fI73MryLFGxN50Y3zJDg3k0ZTDjRHmveVzM6Nzwv9+plWiLA== - /@rollup/plugin-buble/0.21.1_rollup@2.0.0: + /@rollup/plugin-buble/0.21.0_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 '@types/buble': 0.19.2 buble: 0.19.8 - rollup: 2.0.0 + rollup: 2.2.0 + rollup-pluginutils: 2.8.2 dev: true peerDependencies: rollup: ^1.20.0 resolution: - integrity: sha512-Tmd4V95cVyGTwh7qc9ZNkg53E/isFY4q/sqZK7mSyGajYp9Wb0gbJyZWAzYlg9kZxEHmwCDlvcHDcn56SpOCCQ== + integrity: sha512-n6N311RCrVvnsWGyo/if6K2kFoDW+x9r+/hkp+fI73MryLFGxN50Y3zJDg3k0ZTDjRHmveVzM6Nzwv9+plWiLA== /@rollup/plugin-commonjs/11.0.2: dependencies: - '@rollup/pluginutils': 3.0.4 + '@rollup/pluginutils': 3.0.8 estree-walker: 1.0.1 is-reference: 1.1.4 magic-string: 0.25.6 - resolve: 1.14.2 + resolve: 1.15.0 dev: true engines: node: '>= 8.0.0' @@ -1369,14 +1373,14 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-MPYGZr0qdbV5zZj8/2AuomVpnRVXRU5XKXb3HVniwRoRCreGlf5kOE081isNWeiLIi6IYkwTX9zE0/c7V8g81g== - /@rollup/plugin-commonjs/11.0.2_rollup@2.0.0: + /@rollup/plugin-commonjs/11.0.2_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.4_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 estree-walker: 1.0.1 is-reference: 1.1.4 magic-string: 0.25.6 - resolve: 1.14.2 - rollup: 2.0.0 + resolve: 1.15.0 + rollup: 2.2.0 dev: true engines: node: '>= 8.0.0' @@ -1384,23 +1388,23 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-MPYGZr0qdbV5zZj8/2AuomVpnRVXRU5XKXb3HVniwRoRCreGlf5kOE081isNWeiLIi6IYkwTX9zE0/c7V8g81g== - /@rollup/plugin-json/4.0.2_rollup@2.0.0: + /@rollup/plugin-json/4.0.1_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 - rollup: 2.0.0 + rollup: 2.2.0 + rollup-pluginutils: 2.8.2 dev: true peerDependencies: rollup: ^1.20.0 resolution: - integrity: sha512-t4zJMc98BdH42mBuzjhQA7dKh0t4vMJlUka6Fz0c+iO5IVnWaEMiYBy1uBj9ruHZzXBW23IPDGL9oCzBkQ9Udg== - /@rollup/plugin-node-resolve/6.1.0_rollup@2.0.0: + integrity: sha512-soxllkhOGgchswBAAaTe7X9G80U2tjjHvXv0sBrriLJcC/89PkP59iTrKPOfbz3SjX088mKDmMhAscuyLz8ZSg== + /@rollup/plugin-node-resolve/6.1.0_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.4_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 '@types/resolve': 0.0.8 builtin-modules: 3.1.0 is-module: 1.0.0 - resolve: 1.14.2 - rollup: 2.0.0 + resolve: 1.15.0 + rollup: 2.2.0 dev: true engines: node: '>= 8.0.0' @@ -1414,7 +1418,7 @@ packages: '@types/resolve': 0.0.8 builtin-modules: 3.1.0 is-module: 1.0.0 - resolve: 1.14.2 + resolve: 1.15.0 dev: true engines: node: '>= 8.0.0' @@ -1422,14 +1426,14 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-14ddhD7TnemeHE97a4rLOhobfYvUVcaYuqTnL8Ti7Jxi9V9Jr5LY7Gko4HZ5k4h4vqQM0gBQt6tsp9xXW94WPA== - /@rollup/plugin-node-resolve/7.1.1_rollup@2.0.0: + /@rollup/plugin-node-resolve/7.1.1_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 '@types/resolve': 0.0.8 builtin-modules: 3.1.0 is-module: 1.0.0 - resolve: 1.14.2 - rollup: 2.0.0 + resolve: 1.15.0 + rollup: 2.2.0 dev: true engines: node: '>= 8.0.0' @@ -1437,10 +1441,12 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-14ddhD7TnemeHE97a4rLOhobfYvUVcaYuqTnL8Ti7Jxi9V9Jr5LY7Gko4HZ5k4h4vqQM0gBQt6tsp9xXW94WPA== - /@rollup/plugin-typescript/3.0.0_typescript@3.7.5: + /@rollup/plugin-typescript/3.0.0_b32f28c91b7d5afb3a4e5593fb670831: dependencies: - '@rollup/pluginutils': 3.0.8 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 resolve: 1.15.0 + rollup: 2.2.0 + tslib: 1.10.0 typescript: 3.7.5 dev: true engines: @@ -1451,13 +1457,11 @@ packages: typescript: '>=2.1.0' resolution: integrity: sha512-O6915Ril3+Q0B4P898PULAcPFZfPuatEB/4nox7bnK48ekGrmamMYhMB5tOqWjihEWrw4oz/NL+c+/kS3Fk95g== - /@rollup/plugin-typescript/3.1.0_906bf73aac2a7717ec0c8c901fd0cdee: + /@rollup/plugin-typescript/3.0.0_rollup@2.2.0: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 resolve: 1.15.0 - rollup: 2.0.0 - tslib: 1.10.0 - typescript: 3.7.5 + rollup: 2.2.0 dev: true engines: node: '>=8.0.0' @@ -1466,12 +1470,13 @@ packages: tslib: '*' typescript: '>=2.1.0' resolution: - integrity: sha512-ChNRozzMydushztZ95eXwUBBMhctKyXU61TdDf8iZF02zkB2uhOH0Pe2lQmvyek7Fdh7OZQrj3Vt1mzJCT9+MA== - /@rollup/plugin-typescript/3.1.0_rollup@2.0.0: + integrity: sha512-O6915Ril3+Q0B4P898PULAcPFZfPuatEB/4nox7bnK48ekGrmamMYhMB5tOqWjihEWrw4oz/NL+c+/kS3Fk95g== + /@rollup/plugin-typescript/3.0.0_rollup@2.2.0+typescript@3.7.5: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8_rollup@2.2.0 resolve: 1.15.0 - rollup: 2.0.0 + rollup: 2.2.0 + typescript: 3.7.5 dev: true engines: node: '>=8.0.0' @@ -1480,12 +1485,11 @@ packages: tslib: '*' typescript: '>=2.1.0' resolution: - integrity: sha512-ChNRozzMydushztZ95eXwUBBMhctKyXU61TdDf8iZF02zkB2uhOH0Pe2lQmvyek7Fdh7OZQrj3Vt1mzJCT9+MA== - /@rollup/plugin-typescript/3.1.0_rollup@2.0.0+typescript@3.7.5: + integrity: sha512-O6915Ril3+Q0B4P898PULAcPFZfPuatEB/4nox7bnK48ekGrmamMYhMB5tOqWjihEWrw4oz/NL+c+/kS3Fk95g== + /@rollup/plugin-typescript/3.0.0_typescript@3.7.5: dependencies: - '@rollup/pluginutils': 3.0.8_rollup@2.0.0 + '@rollup/pluginutils': 3.0.8 resolve: 1.15.0 - rollup: 2.0.0 typescript: 3.7.5 dev: true engines: @@ -1495,28 +1499,7 @@ packages: tslib: '*' typescript: '>=2.1.0' resolution: - integrity: sha512-ChNRozzMydushztZ95eXwUBBMhctKyXU61TdDf8iZF02zkB2uhOH0Pe2lQmvyek7Fdh7OZQrj3Vt1mzJCT9+MA== - /@rollup/pluginutils/3.0.4: - dependencies: - estree-walker: 0.6.1 - dev: true - engines: - node: '>= 8.0.0' - peerDependencies: - rollup: ^1.20.0 - resolution: - integrity: sha512-buc0oeq2zqQu2mpMyvZgAaQvitikYjT/4JYhA4EXwxX8/g0ZGHoGiX+0AwmfhrNqH4oJv67gn80sTZFQ/jL1bw== - /@rollup/pluginutils/3.0.4_rollup@2.0.0: - dependencies: - estree-walker: 0.6.1 - rollup: 2.0.0 - dev: true - engines: - node: '>= 8.0.0' - peerDependencies: - rollup: ^1.20.0 - resolution: - integrity: sha512-buc0oeq2zqQu2mpMyvZgAaQvitikYjT/4JYhA4EXwxX8/g0ZGHoGiX+0AwmfhrNqH4oJv67gn80sTZFQ/jL1bw== + integrity: sha512-O6915Ril3+Q0B4P898PULAcPFZfPuatEB/4nox7bnK48ekGrmamMYhMB5tOqWjihEWrw4oz/NL+c+/kS3Fk95g== /@rollup/pluginutils/3.0.8: dependencies: estree-walker: 1.0.1 @@ -1526,10 +1509,10 @@ packages: rollup: ^1.20.0 resolution: integrity: sha512-rYGeAc4sxcZ+kPG/Tw4/fwJODC3IXHYDH4qusdN/b6aLw5LPUbzpecYbEJh4sVQGPFJxd2dBU4kc1H3oy9/bnw== - /@rollup/pluginutils/3.0.8_rollup@2.0.0: + /@rollup/pluginutils/3.0.8_rollup@2.2.0: dependencies: estree-walker: 1.0.1 - rollup: 2.0.0 + rollup: 2.2.0 engines: node: '>= 8.0.0' peerDependencies: @@ -1656,11 +1639,8 @@ packages: dev: true resolution: integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== - /@types/node/12.12.25: - dev: true - resolution: - integrity: sha512-nf1LMGZvgFX186geVZR1xMZKKblJiRfiASTHw85zED2kI1yDKHDwTKMdkaCbTlXoRKlGKaDfYywt+V0As30q3w== /@types/node/12.12.28: + dev: true resolution: integrity: sha512-g73GJYJDXgf0jqg+P9S8h2acWbDXNkoCX8DLtJVu7Fkn788pzQ/oJsrdJz/2JejRf/SjfZaAhsw+3nd1D5EWGg== /@types/node/13.1.6: @@ -1668,7 +1648,6 @@ packages: resolution: integrity: sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg== /@types/node/13.1.8: - dev: true resolution: integrity: sha512-6XzyyNM9EKQW4HKuzbo/CkOIjn/evtCmsU+MUM1xDfJ+3/rNjBttM1NgN7AOQvN6tP1Sl1D1PIKMreTArnxM9A== /@types/normalize-package-data/2.4.0: @@ -1681,7 +1660,7 @@ packages: integrity: sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw== /@types/resolve/0.0.8: dependencies: - '@types/node': 12.12.28 + '@types/node': 13.1.8 resolution: integrity: sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== /@types/yargs-parser/15.0.0: @@ -2528,7 +2507,6 @@ packages: resolution: integrity: sha1-zVL28HEuC6q5fW+XModPIvR3UsA= /commondir/1.0.1: - dev: true resolution: integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= /concat-map/0.0.1: @@ -3230,7 +3208,7 @@ packages: /eslint-import-resolver-node/0.3.3: dependencies: debug: 2.6.9 - resolve: 1.14.2 + resolve: 1.15.0 dev: true resolution: integrity: sha512-b8crLDo0M5RSe5YG8Pu2DYBj71tSB6OvXkfzwbJU2w7y8P4/yo0MyF8jU26IEuEuHF2K5/gcAJE3LhQGqBBbVg== @@ -3257,7 +3235,7 @@ packages: minimatch: 3.0.4 object.values: 1.1.1 read-pkg-up: 2.0.0 - resolve: 1.14.2 + resolve: 1.15.0 dev: true engines: node: '>=4' @@ -5020,6 +4998,7 @@ packages: /mkdirp/0.5.1: dependencies: minimist: 0.0.8 + deprecated: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) dev: true hasBin: true resolution: @@ -5089,7 +5068,7 @@ packages: /normalize-package-data/2.5.0: dependencies: hosted-git-info: 2.8.5 - resolve: 1.14.2 + resolve: 1.15.0 semver: 5.7.1 validate-npm-package-license: 3.0.4 resolution: @@ -6201,7 +6180,7 @@ packages: integrity: sha512-zz0pAkSPOXXm1viEwygWIPSPkcBYjW1xU5j/JBh5t9bGCJwa6f9+BJa6VaB2g+b55yVrmXzqkyLf4xaWYM0IkQ== /rechoir/0.6.2: dependencies: - resolve: 1.14.2 + resolve: 1.15.0 dev: true engines: node: '>= 0.10' @@ -6380,15 +6359,9 @@ packages: node: '>=8' resolution: integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== - /resolve/1.14.2: - dependencies: - path-parse: 1.0.6 - resolution: - integrity: sha512-EjlOBLBO1kxsUxsKjLt7TAECyKW6fOh1VRkykQkKGzcBbjjPIxBqGh0jf7GJ3k/f5mxMqW3htMD3WdTUVtW8HQ== /resolve/1.15.0: dependencies: path-parse: 1.0.6 - dev: true resolution: integrity: sha512-+hTmAldEGE80U2wJJDC1lebb5jWqvTYAfm3YZ1ckk1gBr0MnCqUKlwK1e+anaFljIl+F5tR5IoZcm4ZDA1zMQw== /responselike/1.0.2: @@ -6451,11 +6424,11 @@ packages: hasBin: true resolution: integrity: sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg== - /rollup-plugin-babel/4.3.3_@babel+core@7.8.3+rollup@2.0.0: + /rollup-plugin-babel/4.3.3_@babel+core@7.8.3+rollup@2.2.0: dependencies: '@babel/core': 7.8.3 '@babel/helper-module-imports': 7.8.3 - rollup: 2.0.0 + rollup: 2.2.0 rollup-pluginutils: 2.8.2 dev: true peerDependencies: @@ -6463,13 +6436,13 @@ packages: rollup: '>=0.60.0 <2' resolution: integrity: sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw== - /rollup-plugin-commonjs/10.1.0_rollup@2.0.0: + /rollup-plugin-commonjs/10.1.0_rollup@2.2.0: dependencies: estree-walker: 0.6.1 is-reference: 1.1.4 magic-string: 0.25.6 - resolve: 1.14.2 - rollup: 2.0.0 + resolve: 1.15.0 + rollup: 2.2.0 rollup-pluginutils: 2.8.2 deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-commonjs. dev: true @@ -6490,7 +6463,7 @@ packages: postcss-modules: 1.5.0 promise.series: 0.2.0 reserved-words: 0.1.2 - resolve: 1.14.2 + resolve: 1.15.0 rollup-pluginutils: 2.8.2 style-inject: 0.3.0 dev: true @@ -6504,14 +6477,14 @@ packages: dev: true resolution: integrity: sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== - /rollup/2.0.0: + /rollup/2.2.0: engines: node: '>=10.0.0' hasBin: true optionalDependencies: fsevents: 2.1.2 resolution: - integrity: sha512-tbvWownITR+0ebaX6iRr7IcLkziTCJacRpmWz03NIj3CZDmGlergYSwdG8wPx68LT0ms1YzqmbjUQHb6ut8pdw== + integrity: sha512-iAu/j9/WJ0i+zT0sAMuQnsEbmOKzdQ4Yxu5rbPs9aUCyqveI1Kw3H4Fi9NWfCOpb8luEySD2lDyFWL9CrLE8iw== /run-async/2.3.0: dependencies: is-promise: 2.1.0