From 7a2724cf0f5b6b8622156c6c8c5487ba3614303f Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Sun, 9 Feb 2020 13:21:40 +0200 Subject: [PATCH 01/12] Implemented support for dynamic requires (transferred PR) Moved from https://github.com/rollup/rollup-plugin-commonjs/pull/331 --- packages/commonjs/README.md | 27 ++++ packages/commonjs/package.json | 1 + .../commonjs/src/dynamic-require-paths.js | 27 ++++ packages/commonjs/src/helpers.js | 116 +++++++++++++- packages/commonjs/src/index.js | 151 +++++++++++++++--- packages/commonjs/src/resolve-id.js | 10 +- packages/commonjs/src/transform.js | 140 +++++++++++++--- .../unambiguous-with-default-export/foo.js | 3 + .../unambiguous-with-default-export/output.js | 3 +- .../form/unambiguous-with-import/output.js | 3 +- .../unambiguous-with-named-export/output.js | 3 +- .../_config.js | 10 ++ .../dynamic-require-absolute-import/main.js | 7 + .../node_modules/parent-module/parent.js | 1 + .../sub/node_modules/module/direct.js | 1 + .../sub/node_modules/module/nested/nested.js | 1 + .../sub/submodule.js | 9 ++ .../dynamic-require-absolute-paths/_config.js | 8 + .../dynamic-require-absolute-paths/main.js | 6 + .../submodule.js | 1 + .../dynamic-require-es-entry/_config.js | 6 + .../dynamic-require-es-entry/importer.js | 7 + .../function/dynamic-require-es-entry/main.js | 5 + .../dynamic-require-es-entry/submodule.js | 1 + .../dynamic-require-extensions/_config.js | 6 + .../dynamic-require-extensions/main.js | 15 ++ .../dynamic-require-extensions/submodule.js | 1 + .../function/dynamic-require-globs/_config.js | 10 ++ .../dynamic-require-globs/extramodule1.js | 1 + .../dynamic-require-globs/extramodule2.js | 1 + .../function/dynamic-require-globs/main.js | 18 +++ .../dynamic-require-globs/submodule1.js | 1 + .../dynamic-require-globs/submodule2.js | 1 + .../dynamic-require-instances/_config.js | 16 ++ .../dynamic-require-instances/direct/index.js | 1 + .../dynamic-require-instances/main.js | 13 ++ .../dynamic-require-instances/package/main.js | 1 + .../package/package.json | 3 + .../function/dynamic-require-json/_config.js | 11 ++ .../dynamic-require-json/dynamic.json | 3 + .../function/dynamic-require-json/main.js | 8 + .../dynamic-require-package-sub/_config.js | 15 ++ .../node_modules/custom-module/entry.js | 1 + .../node_modules/custom-module/package.json | 1 + .../dynamic-require-package-sub/package.json | 3 + .../dynamic-require-package-sub/sub/entry.js | 2 + .../dynamic-require-package/_config.js | 16 ++ .../function/dynamic-require-package/entry.js | 1 + .../function/dynamic-require-package/main.js | 14 ++ .../node_modules/custom-module/entry.js | 1 + .../node_modules/custom-module/package.json | 1 + .../dynamic-require-package/package.json | 3 + .../dynamic-require-package/sub/entry.js | 1 + .../dynamic-require-package/sub/package.json | 3 + .../dynamic-require-package/sub/sub.js | 10 ++ .../dynamic-require-relative-paths/_config.js | 9 ++ .../dynamic-require-relative-paths/main.js | 10 ++ .../sub/submodule.js | 1 + .../sub/subsub/subsubmodule.js | 1 + .../dynamic-require-resolve-index/_config.js | 15 ++ .../dynamic-require-resolve-index/index.js | 1 + .../dynamic-require-resolve-index/main.js | 14 ++ .../node_modules/custom-module/index.js | 1 + .../sub/index.js | 1 + .../dynamic-require-resolve-index/sub/sub.js | 10 ++ .../function/dynamic-require/_config.js | 6 + .../fixtures/function/dynamic-require/main.js | 16 ++ .../function/dynamic-require/submodule.js | 3 + packages/commonjs/test/function.js | 2 +- packages/commonjs/test/types.ts | 3 +- packages/commonjs/types/index.d.ts | 11 ++ 71 files changed, 784 insertions(+), 49 deletions(-) create mode 100644 packages/commonjs/src/dynamic-require-paths.js create mode 100644 packages/commonjs/test/fixtures/form/unambiguous-with-default-export/foo.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/submodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-es-entry/importer.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-es-entry/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-extensions/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule2.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-instances/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-instances/package/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-json/dynamic.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-json/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package-sub/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub/entry.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/entry.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/entry.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/sub/entry.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/sub/package.json create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-package/sub/sub.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/index.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module/index.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/index.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub/sub.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require/submodule.js diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md index f648cfb14..53584064c 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: This feature may result in some paths being rendered as absolute in the final bundle. That may require replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`. We may find a way to do this automatically in the future._ + +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 88787046d..58dd5aff6 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -51,6 +51,7 @@ "dependencies": { "@rollup/pluginutils": "^3.0.8", "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..8c7ed2dfc 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -6,6 +6,10 @@ 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 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,8 +17,8 @@ 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 commonjsRegister (path, loader) { + DYNAMIC_REQUIRE_LOADERS[path] = loader; } export function unwrapExports (x) { @@ -27,4 +31,110 @@ export function createCommonjsModule(fn, module) { export function getCjsExportFromNamespace (n) { return n && n['default'] || n; -}`; +} + +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..ba197e350 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -1,12 +1,16 @@ -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 { peerDependencies } from '../package.json'; import { + DYNAMIC_JSON_PREFIX, + DYNAMIC_PACKAGES_ID, + DYNAMIC_REGISTER_PREFIX, EXTERNAL_SUFFIX, getIdFromExternalProxyId, getIdFromProxyId, @@ -14,9 +18,10 @@ import { HELPERS_ID, 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 +29,11 @@ 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 customNamedExports = {}; if (options.namedExports) { Object.keys(options.namedExports).forEach((id) => { @@ -60,8 +70,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' @@ -74,16 +82,22 @@ export default function commonjs(options = {}) { const sourceMap = options.sourceMap !== false; + let mainModuleId = null; + 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 +108,21 @@ export default function commonjs(options = {}) { code, id, this.getModuleInfo(id).isEntry, - ignoreGlobal, + isEsModule, + ignoreGlobal || isEsModule, ignoreRequire, customNamedExports[normalizedId], sourceMap, - allowDynamicRequire, + isDynamicRequireModulesEnabled, + dynamicRequireModuleSet, ast ); + + setIsCjsPromise(id, isEsModule ? false : Boolean(transformed)); + if (!transformed) { - esModulesWithoutDefaultExport.add(id); + if (!isEsModule || isDynamicRequireModule) + esModulesWithoutDefaultExport.add(id); return null; } @@ -133,15 +153,77 @@ export default function commonjs(options = {}) { 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( + dir + )}, 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( + normalizedPath + )}, 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( + normalizedPath + )}, 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( + normalizePathSlashes(actualId) + )}); export default (${name} && ${name}['default']) || ${name}`; + else if (isCjs) return `import { __moduleExports } from ${JSON.stringify( actualId )}; export default __moduleExports;`; @@ -156,13 +238,44 @@ export default function commonjs(options = {}) { }); } + // TODO: For code splitting, the runtime probably needs to be imported by each entry point + + if (!mainModuleId && isDynamicRequireModulesEnabled) { + mainModuleId = actualId; + + 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 +283,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..c90fda1bd 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -1,11 +1,14 @@ -/* 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, 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 +45,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 +98,13 @@ export function transformCommonjs( code, id, isEntry, + isEsModule, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, - allowDynamicRequire, + isDynamicRequireModulesEnabled, + dynamicRequireModuleSet, astCache ) { const ast = astCache || tryParse(parse, code, id); @@ -124,6 +133,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 +155,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 +169,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 +187,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); + } + + 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 +315,25 @@ 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, + ',' + + // TODO stringify(null) looks very wrong; find a test + JSON.stringify( + dirname(id) === '.' ? null : normalizePathSlashes(dirname(id)) + ) + ); + } + magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, { storeName: true }); + usesDynamicHelpers = true } uses[node.name] = true; @@ -325,7 +400,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 +412,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 +428,22 @@ 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( + normalizePathSlashes(required.source) + )}, ${JSON.stringify( + // TODO check if null is what we want + dirname(id) === '.' ? null : normalizePathSlashes(dirname(id)) + )})` + ); + usesDynamicHelpers = true; + } else { + magicString.overwrite(node.start, node.end, required.name); + } } node.callee._skip = true; @@ -403,7 +496,7 @@ 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}';`] : [] @@ -427,7 +520,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 +558,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 +599,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 +620,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 +631,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..0dc8e84a5 --- /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..ac86de0a5 --- /dev/null +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js @@ -0,0 +1,8 @@ +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-es-entry/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js new file mode 100755 index 000000000..d560bc443 --- /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..d7ca973e4 --- /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..93facd3da --- /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..f592c6f5a --- /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..8f03ed18b --- /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..f94ccc1e7 --- /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..bf46e72df --- /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..925ba1534 --- /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..7b6084aac --- /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..35f637ff0 --- /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..f02cff08c --- /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..7c0648c9b 100644 --- a/packages/commonjs/test/function.js +++ b/packages/commonjs/test/function.js @@ -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 || {}, { 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..2c3094b72 100644 --- a/packages/commonjs/types/index.d.ts +++ b/packages/commonjs/types/index.d.ts @@ -43,6 +43,17 @@ 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: This feature may result in some paths being rendered as absolute in the final bundle. + * That may require replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`. + * We may find a way to do this automatically in the future. + */ + dynamicRequireTargets?: string|ReadonlyArray; } /** From 1be3838369a9e1afa1a248fae58ce7a759d6f858 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Sun, 9 Feb 2020 18:20:24 +0200 Subject: [PATCH 02/12] Only add dynamic loader code when dynamic feature is enabled --- packages/commonjs/src/helpers.js | 19 +++++++++++++++---- packages/commonjs/src/index.js | 14 +++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/commonjs/src/helpers.js b/packages/commonjs/src/helpers.js index 8c7ed2dfc..4a8219abd 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -17,10 +17,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 commonjsRegister (path, loader) { - DYNAMIC_REQUIRE_LOADERS[path] = loader; -} - export function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } @@ -32,6 +28,18 @@ 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); @@ -63,6 +71,7 @@ function normalize (path) { path = '.'; return path; } + function join () { if (arguments.length === 0) return '.'; @@ -81,6 +90,7 @@ function join () { return joined; } + function isPossibleNodeModulesPath (modulePath) { let c0 = modulePath[0]; if (c0 === '/' || c0 === '\\\\') return false; @@ -91,6 +101,7 @@ function isPossibleNodeModulesPath (modulePath) { return false; return true; } + export function commonjsRequire (path, originalModuleDir) { const shouldTryNodeModules = isPossibleNodeModulesPath(path); path = normalize(path); diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index ba197e350..7cc76e621 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -16,6 +16,8 @@ import { getIdFromProxyId, HELPERS, HELPERS_ID, + HELPER_NON_DYNAMIC, + HELPERS_DYNAMIC, PROXY_SUFFIX } from './helpers'; @@ -146,7 +148,17 @@ 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)) { From 15ee285fa81f038efbaa9ab67d0591bcd7581ef4 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 25 Feb 2020 07:19:38 +0100 Subject: [PATCH 03/12] test(commonjs): update snapshots for easier diffing --- .../commonjs/test/snapshots/function.js.md | 2084 ++++++++++++++++- .../commonjs/test/snapshots/function.js.snap | Bin 2989 -> 6709 bytes 2 files changed, 2080 insertions(+), 4 deletions(-) diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index 4bee7d666..f68aee088 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -215,6 +215,2082 @@ Generated by [AVA](https://ava.li). t.is(_var, 'VAR');␊ ` +## dynamic-require + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js", function (module, exports) {␊ + module.exports = function () {␊ + return 'Hello there';␊ + };␊ + });␊ + ␊ + const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + let message;␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js", function (module, exports) {␊ + module.exports = 'direct';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js", function (module, exports) {␊ + module.exports = 'nested';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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␊ + };␊ + ␊ + const direct = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ + ␊ + const nested = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ + ␊ + const parent = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + t.deepEqual(submodule, {␊ + moduleDirect: 'direct',␊ + moduleNested: 'nested',␊ + parentModule: 'parent'␊ + });␊ + ` + +## dynamic-require-absolute-paths + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || 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`),"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths"), 'submodule');␊ + ` + +## dynamic-require-es-entry + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule (withName) {␊ + return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry");␊ + }␊ + ␊ + var importer = takeModule('submodule.js');␊ + ␊ + t.is(importer, 'submodule');␊ + ` + +## dynamic-require-extensions + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js", function (module, exports) {␊ + module.exports = {name: 'submodule', value: null};␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js", function (module, exports) {␊ + module.exports = 'submodule1';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js", function (module, exports) {␊ + module.exports = 'submodule2';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js", function (module, exports) {␊ + module.exports = 'extramodule1';␊ + ␊ + });␊ + ␊ + const submodule1 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ + ␊ + const submodule2 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ + ␊ + const extramodule1 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || extramodule1;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js", function (module, exports) {␊ + module.exports = { name: 'direct', value: null };␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js", function (module, exports) {␊ + module.exorts = { name: 'package', value: null };␊ + ␊ + });␊ + ␊ + const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct", function (module, exports) {␊ + module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js", null);␊ + });␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package", function (module, exports) {␊ + module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js", null);␊ + });␊ + ␊ + const direct = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ + ␊ + const main = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModule(withName) {␊ + return commonjsRequire(withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances").value, 'package-instance');␊ + ` + +## dynamic-require-json + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-json");␊ + }␊ + ␊ + t.deepEqual(takeModule('dynamic.json'), {value: 'present'});␊ + t.deepEqual(takeModule('dynamic'), {value: 'present'});␊ + ` + +## dynamic-require-package + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package", function (module, exports) {␊ + module.exports = entry;␊ + });␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package/sub", function (module, exports) {␊ + module.exports = entry$1;␊ + });␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module", function (module, exports) {␊ + module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", null);␊ + });␊ + ␊ + const entry = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ + ␊ + t.is(commonjsRequire("custom-module", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ + ` + +## dynamic-require-relative-paths + +> Snapshot 1 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js", function (module, exports) {␊ + module.exports = 'submodule';␊ + ␊ + });␊ + ␊ + _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js", function (module, exports) {␊ + module.exports = 'subsubmodule';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + const subsubmodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || subsubmodule;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + function takeModuleWithDelimiter(name, delimiter) {␊ + return commonjsRequire('.' + delimiter + name.replace(/=/g, delimiter),"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 + + `'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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index", function (module, exports) {␊ + module.exports = dynamicRequireResolveIndex;␊ + });␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub", function (module, exports) {␊ + module.exports = sub;␊ + });␊ + commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/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 @@ -638,14 +2714,14 @@ Generated by [AVA](https://ava.li). `'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;␊ }␊ ␊ + 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;␊ diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index 60848ee9dd3afe20294375fa6d9a0c7793d72c61..e9eed2b015f5ff978ee4bc362ec470eeba746b1c 100644 GIT binary patch literal 6709 zcmZwJQ&=Sow+Haawq28Lo0BHn#$->f36rrW+qP?GyPY-JwX=QRbMDUjed}Uf{GMn1 zFV?zQ;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- packages/commonjs/package.json | 1 + packages/commonjs/src/helpers.js | 7 + packages/commonjs/src/index.js | 14 +- packages/commonjs/src/transform.js | 21 ++- .../commonjs/test/snapshots/function.js.md | 120 +++++++++--------- .../commonjs/test/snapshots/function.js.snap | Bin 6709 -> 6655 bytes packages/commonjs/types/index.d.ts | 8 +- 8 files changed, 99 insertions(+), 74 deletions(-) diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md index 53584064c..6dfaeeec5 100644 --- a/packages/commonjs/README.md +++ b/packages/commonjs/README.md @@ -52,7 +52,7 @@ 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: This feature may result in some paths being rendered as absolute in the final bundle. That may require replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`. We may find a way to do this automatically in the future._ +_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: diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json index 58dd5aff6..8d5f106aa 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -50,6 +50,7 @@ }, "dependencies": { "@rollup/pluginutils": "^3.0.8", + "commondir": "^1.0.1", "estree-walker": "^1.0.1", "glob": "^7.1.2", "is-reference": "^1.1.2", diff --git a/packages/commonjs/src/helpers.js b/packages/commonjs/src/helpers.js index 4a8219abd..b2181ad94 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -6,6 +6,13 @@ 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'; diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index 7cc76e621..1720844b8 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -4,6 +4,7 @@ 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'; @@ -11,6 +12,7 @@ import { DYNAMIC_JSON_PREFIX, DYNAMIC_PACKAGES_ID, DYNAMIC_REGISTER_PREFIX, + getVirtualPathForDynamicRequirePath, EXTERNAL_SUFFIX, getIdFromExternalProxyId, getIdFromProxyId, @@ -35,6 +37,9 @@ export default function commonjs(options = {}) { options.dynamicRequireTargets ); const isDynamicRequireModulesEnabled = dynamicRequireModuleSet.size > 0; + const commonDir = isDynamicRequireModulesEnabled + ? getCommonDir(null, Array.from(dynamicRequireModuleSet).concat(process.cwd())) + : null; const customNamedExports = {}; if (options.namedExports) { @@ -117,6 +122,7 @@ export default function commonjs(options = {}) { sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, + commonDir, ast ); @@ -188,7 +194,7 @@ export default function commonjs(options = {}) { } code += `\ncommonjsRegister(${JSON.stringify( - dir + getVirtualPathForDynamicRequirePath(dir, commonDir) )}, function (module, exports) { module.exports = require(${JSON.stringify( normalizePathSlashes(join(dir, entryPoint)) @@ -209,7 +215,7 @@ export default function commonjs(options = {}) { if (isDynamicJson) { return `require('${HELPERS_ID}').commonjsRegister(${JSON.stringify( - normalizedPath + getVirtualPathForDynamicRequirePath(normalizedPath, commonDir) )}, function (module, exports) { module.exports = require(${JSON.stringify(normalizedPath)}); });`; @@ -220,7 +226,7 @@ export default function commonjs(options = {}) { // The commonjs polyfill should take care of circular references. return `require('${HELPERS_ID}').commonjsRegister(${JSON.stringify( - normalizedPath + getVirtualPathForDynamicRequirePath(normalizedPath, commonDir) )}, function (module, exports) { ${readFileSync(normalizedPath, { encoding: 'utf8' })} });`; @@ -233,7 +239,7 @@ export default function commonjs(options = {}) { return getIsCjsPromise(actualId).then((isCjs) => { if (dynamicRequireModuleSet.has(normalizePathSlashes(actualId)) && !actualId.endsWith('.json')) return `import {commonjsRequire} from '${HELPERS_ID}'; const ${name} = commonjsRequire(${JSON.stringify( - normalizePathSlashes(actualId) + getVirtualPathForDynamicRequirePath(normalizePathSlashes(actualId), commonDir) )}); export default (${name} && ${name}['default']) || ${name}`; else if (isCjs) return `import { __moduleExports } from ${JSON.stringify( diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js index c90fda1bd..15308e3ad 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -4,7 +4,13 @@ import MagicString from 'magic-string'; import { attachScopes, extractAssignedNames, makeLegalIdentifier } from '@rollup/pluginutils'; import { flatten, isFalsy, isReference, isTruthy } from './ast-utils'; -import { getProxyId, HELPERS_ID, DYNAMIC_REGISTER_PREFIX, DYNAMIC_JSON_PREFIX } 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? @@ -105,6 +111,7 @@ export function transformCommonjs( sourceMap, isDynamicRequireModulesEnabled, dynamicRequireModuleSet, + commonDir, astCache ) { const ast = astCache || tryParse(parse, code, id); @@ -323,9 +330,10 @@ export function transformCommonjs( magicString.appendLeft( parent.end - 1, ',' + - // TODO stringify(null) looks very wrong; find a test JSON.stringify( - dirname(id) === '.' ? null : normalizePathSlashes(dirname(id)) + dirname(id) === '.' + ? null /* default behavior */ + : getVirtualPathForDynamicRequirePath(normalizePathSlashes(dirname(id)), commonDir) ) ); } @@ -434,10 +442,11 @@ export function transformCommonjs( node.start, node.end, `${HELPERS_NAME}.commonjsRequire(${JSON.stringify( - normalizePathSlashes(required.source) + getVirtualPathForDynamicRequirePath(normalizePathSlashes(required.source), commonDir) )}, ${JSON.stringify( - // TODO check if null is what we want - dirname(id) === '.' ? null : normalizePathSlashes(dirname(id)) + dirname(id) === '.' + ? null /* default behavior */ + : getVirtualPathForDynamicRequirePath(normalizePathSlashes(dirname(id)), commonDir) )})` ); usesDynamicHelpers = true; diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index f68aee088..8fb890d2a 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -356,20 +356,20 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js", function (module, exports) {␊ module.exports = function () {␊ return 'Hello there';␊ };␊ });␊ ␊ - const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ let message;␊ ␊ function takeModule(withName) {␊ - return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require");␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require");␊ }␊ ␊ try {␊ @@ -523,17 +523,17 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js", function (module, exports) {␊ module.exports = 'direct';␊ ␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js", function (module, exports) {␊ + _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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js", function (module, exports) {␊ module.exports = 'parent';␊ ␊ });␊ @@ -541,7 +541,7 @@ Generated by [AVA](https://ava.li). /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(name) {␊ - return commonjsRequire(name,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub");␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub");␊ }␊ ␊ var moduleDirect = takeModule('module/direct');␊ @@ -554,11 +554,11 @@ Generated by [AVA](https://ava.li). parentModule: parentModule␊ };␊ ␊ - const direct = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ + const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ ␊ - const nested = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ + const nested = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ ␊ - const parent = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ + const parent = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ @@ -714,19 +714,19 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js", function (module, exports) {␊ module.exports = 'submodule';␊ ␊ });␊ ␊ - const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || submodule;␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || 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`),"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths"), 'submodule');␊ + t.is(commonjsRequire(path.resolve(`${basePath}/submodule.js`),"/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths"), 'submodule');␊ ` ## dynamic-require-es-entry @@ -870,17 +870,17 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js", function (module, exports) {␊ module.exports = 'submodule';␊ ␊ });␊ ␊ - const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || submodule;␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || submodule;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule (withName) {␊ - return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-es-entry");␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-es-entry");␊ }␊ ␊ var importer = takeModule('submodule.js');␊ @@ -1029,17 +1029,17 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js", function (module, exports) {␊ module.exports = {name: 'submodule', value: null};␊ ␊ });␊ ␊ - const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ - return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-extensions");␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-extensions");␊ }␊ ␊ const withExtension = takeModule('submodule.js');␊ @@ -1194,31 +1194,31 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js", function (module, exports) {␊ module.exports = 'submodule1';␊ ␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js", function (module, exports) {␊ module.exports = 'submodule2';␊ ␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js", function (module, exports) {␊ module.exports = 'extramodule1';␊ ␊ });␊ ␊ - const submodule1 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ + const submodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ ␊ - const submodule2 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ + const submodule2 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ ␊ - const extramodule1 = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || extramodule1;␊ + const extramodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || extramodule1;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ - return commonjsRequire('./' + withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-globs");␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-globs");␊ }␊ ␊ t.is(takeModule('submodule1.js'), 'submodule1');␊ @@ -1376,41 +1376,41 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js", function (module, exports) {␊ module.exports = { name: 'direct', value: null };␊ ␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js", function (module, exports) {␊ + _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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct", function (module, exports) {␊ - module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js", null);␊ + 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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package", function (module, exports) {␊ - module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.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);␊ });␊ ␊ - const direct = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ + const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ ␊ - const main = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ + const main = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ - return commonjsRequire(withName,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances");␊ + 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", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances").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", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-instances").value, 'package-instance');␊ + t.is(commonjsRequire("./package/main.js", "/$$rollup_base$$/fixtures/function/dynamic-require-instances").value, 'package-instance');␊ ` ## dynamic-require-json @@ -1567,14 +1567,14 @@ Generated by [AVA](https://ava.li). ␊ var require$$1 = getCjsExportFromNamespace(dynamic$1);␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-json/dynamic.json", function (module, exports) {␊ + _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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-json");␊ + return commonjsRequire('./' + withName,"/$$rollup_base$$/fixtures/function/dynamic-require-json");␊ }␊ ␊ t.deepEqual(takeModule('dynamic.json'), {value: 'present'});␊ @@ -1729,20 +1729,20 @@ Generated by [AVA](https://ava.li). var entry$2 = 'custom-module';␊ ␊ const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package", function (module, exports) {␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package", function (module, exports) {␊ module.exports = entry;␊ });␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package/sub", function (module, exports) {␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-package/sub", function (module, exports) {␊ module.exports = entry$1;␊ });␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package/node_modules/custom-module", function (module, exports) {␊ + 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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package/sub");␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-package/sub");␊ }␊ ␊ var sub = {␊ @@ -1753,7 +1753,7 @@ Generated by [AVA](https://ava.li). /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule$1(name) {␊ - return commonjsRequire(name,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package");␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-package");␊ }␊ ␊ t.is(takeModule$1('.'), 'same-directory');␊ @@ -1907,7 +1907,7 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", function (module, exports) {␊ module.exports = 'custom-module';␊ ␊ });␊ @@ -1925,18 +1925,18 @@ Generated by [AVA](https://ava.li). ␊ var require$$1 = getCjsExportFromNamespace(_package$1);␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/package.json", function (module, exports) {␊ + _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("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module", function (module, exports) {␊ - module.exports = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", null);␊ + 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);␊ });␊ ␊ - const entry = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ + const entry = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ ␊ - t.is(commonjsRequire("custom-module", "/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ + t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ ` ## dynamic-require-relative-paths @@ -2080,24 +2080,24 @@ Generated by [AVA](https://ava.li). commonjsRequire: commonjsRequire␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js", function (module, exports) {␊ module.exports = 'submodule';␊ ␊ });␊ ␊ - _commonjsHelpers.commonjsRegister("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js", function (module, exports) {␊ + _commonjsHelpers.commonjsRegister("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js", function (module, exports) {␊ module.exports = 'subsubmodule';␊ ␊ });␊ ␊ - const submodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ ␊ - const subsubmodule = commonjsRequire("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || subsubmodule;␊ + const subsubmodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || subsubmodule;␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModuleWithDelimiter(name, delimiter) {␊ - return commonjsRequire('.' + delimiter + name.replace(/=/g, delimiter),"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths");␊ + return commonjsRequire('.' + delimiter + name.replace(/=/g, delimiter),"/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths");␊ }␊ ␊ t.is(takeModuleWithDelimiter('sub=submodule.js', '/'), 'submodule');␊ @@ -2254,20 +2254,20 @@ Generated by [AVA](https://ava.li). var customModule = 'custom-module';␊ ␊ const { commonjsRegister: commonjsRegister$1 } = _commonjsHelpers;␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index", function (module, exports) {␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index", function (module, exports) {␊ module.exports = dynamicRequireResolveIndex;␊ });␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub", function (module, exports) {␊ + commonjsRegister$1("/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub", function (module, exports) {␊ module.exports = sub;␊ });␊ - commonjsRegister$1("/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/node_modules/custom-module", function (module, exports) {␊ + 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,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/sub");␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index/sub");␊ }␊ ␊ var sub$1 = {␊ @@ -2278,7 +2278,7 @@ Generated by [AVA](https://ava.li). /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule$1(name) {␊ - return commonjsRequire(name,"/Users/lukastaegert/test/dynamic-require-plugins/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index");␊ + return commonjsRequire(name,"/$$rollup_base$$/fixtures/function/dynamic-require-resolve-index");␊ }␊ ␊ t.is(takeModule$1('.'), 'same-directory');␊ diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index e9eed2b015f5ff978ee4bc362ec470eeba746b1c..d8cdc4e806b8164cded45cd9f4b90118a5c0d6c8 100644 GIT binary patch literal 6655 zcmZY7Ra6uT*9Kr3X&AaeLK^8DQeq^eL%JKJJEW2BmhK!Fx*57*C@GO1x{*-+v;Mnt zzJ2-J?6u$hO6y3|X*!#Iakq8xp!4FzL_!#d4H=&RA27SbRt}$*ZG&iI-yr<|AfFjw zTmsZ((-{Xp1Edc}W_4$MJcIQ!=7J@unL%qut|nBycQ05! zMa~saolb7NC$s!uEFeFxC7YF6#}rDNp1YZq263M)$%!n#L)H|JCr-^XKFODzxZoj%qElB#*`_AZ{ z#W6-*%3|x)9{P+)^YL!Q-`m?uZD{MBmGU3=L`EyF*Qkr0FB*&boFO6k&9v3j# zK?!Tt50?{yofnfhKLrIGv0GRvI~g*79JYJ|r!|FumuK{-J-(|isWj<4cQ<0cnomt= z)R+5yv|k|IjbsMOtdjqj&;O3wi|a!u~2S&5(ZKu0sXwWWAniM!vk_Xa3}Qj6}( zh;1sQ5|=Kcy*?8iCc%fBzxeQeDvT_y|GJr5fp1)#N(NiKGV=L){QW)6TW;(tX`A!g z4SE1S6c6gJGYNjaj&wOs;<@WZXN0#>a<#kea5osd4sr{<@bvt2HLz4xdHI;~F|$qr z=nHoc+UV|PC(M4>{pYqnJOMjb`w=%ZesIY|txU@`ahSO zL)FiJ{Wo~f|LN~~Sjz2LXV+bz5N=(KQ~u@Ud;t){SZdLR2B{#(ZTR;FR&K*sPg{Wc z-<#GGOXWYuLMafF(NM~Q$Kg~Ls(_c%2l;Nl3pw8M?@tDx&eN@XWZk^JSBJ^++Rnch zUBRyZe4l;0B+wI17%YDF&>)XT9<;7)Fe@Q5vUmhd;Sc)zN1=!3EITaG?jN|9vI-a}YmUeEm<>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kd8Ue+K9Y-kin0^>SD+_qRgwz*RfN(EKg}ssH2KsM*iHk z3rBU1uqC_;spQMt^0T)4!!PY#%`#~zFrmB-5DGhYMV&k{5#JONf`#YrEYaDaq!KVm zu$nq|4u9yQcLDTa)tcMPV=0Ea$l&#!ESr9e11<0b;SHKROCB_xC|B(B7@Ua1T2X$$ zHO_CF=vf!k1a+1Bx&_aVB2`V|zcCr-148D4*VYm_?f06Yjya)f8H7)%p2=>)j@Vid z2@vQ^TrE)+3h5f%Er@kB`%GYVbWVskECl;>bJu6prMW0x@?D5w2@O|35$Mc~MuKW<%21+sYs|BxEX366~8W0x^q}DMUuQp_8-O zB+g^vthJjzlBA)09)1PJa@8DGxb-vIH5|GC+HiHZ1pt@A|W? z>wt^dE(~kx{Ko>*y0&CXd4XwqH)q{S>_DRWo4&c-%{?AZFM3nRLTj5zjs!5NTm4vk zBOdj6pGi*KI6+m>+ZSBMdtOOF+2R#P21LdMjoBvGY>M69#dp)jJl8kE%wodc zpW*cRxp37gD4rWy9(22i90rCpX74M>f^hva!#D4J-o9u#qkhv?rg)tQAEf-4_I8J3 zPskU+#>R(A(f%#ecdZP~CH@qdNcgbc7?9{pE@k)B_#D%OtC^h#9Ir<*sKA`J4Doiw z92sPv_x2-CjP1~x9h3JVMubqMnu}diEgy$z{9r01DqZq1NI6{D1~C8(fGNS^-z4Oh zuwNlSF@su{KC}c8GyoqC!RYIhhkgIB31DLZUzI+NtJO#BNv`hlHTr8JO{mP)%JaSb z#q;JY@qI7EjN=+;_P1@hO1%eSy-o}dlY)6Vr_V3nby$U`W?Fi~6A6zMg)oS;_@1I4 zHH0>z8Qj1t>${Rg44d&+P}zob*Nc$UxODYmkudU1DrUi$NJ%<*ga4+VPkDoXm5aC?~VxX&?AJ rL%8d;H@US{NSf`#9y!!Y&e?kC-2o`ebA-?<%=s*c+ diff --git a/packages/commonjs/types/index.d.ts b/packages/commonjs/types/index.d.ts index 2c3094b72..1ae223166 100644 --- a/packages/commonjs/types/index.d.ts +++ b/packages/commonjs/types/index.d.ts @@ -49,9 +49,11 @@ interface RollupCommonJSOptions { * Including those modules as `dynamicRequireTargets` will simulate a CommonJS (NodeJS-like) * environment for them with support for dynamic and circular dependencies. * - * Note: This feature may result in some paths being rendered as absolute in the final bundle. - * That may require replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`. - * We may find a way to do this automatically in the future. + * 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; } From e2b7907cef83e3dad7ff78d8ad7bb664d6ff341a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 9 Mar 2020 08:53:40 +0100 Subject: [PATCH 05/12] test(commonjs): Prepare tests to support code-splitting --- .../_config.js | 16 +- .../dynamic-require-absolute-paths/_config.js | 10 +- .../dynamic-require-es-entry/_config.js | 8 +- .../dynamic-require-extensions/_config.js | 8 +- .../function/dynamic-require-globs/_config.js | 16 +- .../dynamic-require-instances/_config.js | 24 +- .../function/dynamic-require-json/_config.js | 14 +- .../dynamic-require-package-sub/_config.js | 20 +- .../dynamic-require-package/_config.js | 22 +- .../function/dynamic-require-package/main.js | 2 +- .../dynamic-require-relative-paths/_config.js | 14 +- .../dynamic-require-resolve-index/_config.js | 22 +- .../function/dynamic-require/_config.js | 8 +- packages/commonjs/test/function.js | 16 +- packages/commonjs/test/helpers/util.js | 102 +- .../commonjs/test/snapshots/function.js.md | 5090 +++++++++-------- .../commonjs/test/snapshots/function.js.snap | Bin 6655 -> 6755 bytes packages/commonjs/test/test.js | 20 +- 18 files changed, 2766 insertions(+), 2646 deletions(-) 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 index 0dc8e84a5..e4019f2cc 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/_config.js @@ -1,10 +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' - ] - } + 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-paths/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js index ac86de0a5..8a62ba220 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js @@ -1,8 +1,6 @@ module.exports = { - description: 'resolves both windows and posix absolute paths', - pluginOptions: { - dynamicRequireTargets: [ - 'fixtures/function/dynamic-require-absolute-paths/submodule.js' - ] - } + 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-es-entry/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js index d560bc443..d0d7c2449 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-es-entry/_config.js @@ -1,6 +1,6 @@ module.exports = { - description: 'works when the entry point is an es module', - pluginOptions: { - dynamicRequireTargets: ['fixtures/function/dynamic-require-es-entry/submodule.js'] - } + 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-extensions/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js index d7ca973e4..22699451d 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-extensions/_config.js @@ -1,6 +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'] - } + 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-globs/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js index 93facd3da..af8cbe2d8 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-globs/_config.js @@ -1,10 +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' - ] - } + 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-instances/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js index f592c6f5a..5aa08f64e 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-instances/_config.js @@ -1,16 +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' - ] - } + 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-json/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js index 8f03ed18b..fd466d91a 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-json/_config.js @@ -1,11 +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'] - } + 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-package-sub/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js index f94ccc1e7..07396e09d 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package-sub/_config.js @@ -2,14 +2,14 @@ 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/**' - ] - } + 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/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js index bf46e72df..1f532f4d2 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/_config.js @@ -2,15 +2,15 @@ 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' - ] - } + 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/main.js b/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js index 925ba1534..d494ef228 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-package/main.js @@ -1,7 +1,7 @@ /* eslint-disable import/no-dynamic-require, global-require */ function takeModule(name) { - return require(name); + return require(name); } t.is(takeModule('.'), 'same-directory'); 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 index 7b6084aac..9c96ce599 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-relative-paths/_config.js @@ -1,9 +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' - ] - } + 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-resolve-index/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js index 35f637ff0..d1ec94a0e 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-resolve-index/_config.js @@ -1,15 +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' - ] - } + 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/_config.js b/packages/commonjs/test/fixtures/function/dynamic-require/_config.js index f02cff08c..ef30bb342 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require/_config.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require/_config.js @@ -1,6 +1,6 @@ module.exports = { - description: 'supports dynamic require', - pluginOptions: { - dynamicRequireTargets: ['fixtures/function/dynamic-require/submodule.js'] - } + description: 'supports dynamic require', + pluginOptions: { + dynamicRequireTargets: ['fixtures/function/dynamic-require/submodule.js'] + } }; diff --git a/packages/commonjs/test/function.js b/packages/commonjs/test/function.js index 7c0648c9b..73502b6e7 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); @@ -33,15 +33,19 @@ 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); + for (const chunkName of Object.keys(codeMap)) { + console.group(chunkName); + console.error(codeMap[chunkName]); + console.groupEnd(); + console.error(); + } } - - 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..31b41d2c0 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 + 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 8fb890d2a..80fef584c 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -8,2727 +8,2819 @@ 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 - `'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';␊ - };␊ - });␊ - ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ - /* 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' );␊ - ` + { + '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';␊ + };␊ + });␊ + ␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + /* 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 - `'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␊ - };␊ - ␊ - const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ - ␊ - const nested = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ - ␊ - const parent = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ - ␊ - /* eslint-disable import/no-dynamic-require, global-require */␊ - ␊ - t.deepEqual(submodule, {␊ - moduleDirect: 'direct',␊ - moduleNested: 'nested',␊ - parentModule: 'parent'␊ - });␊ - ` + { + '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␊ + };␊ + ␊ + const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ + ␊ + const nested = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ + ␊ + const parent = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ + ␊ + /* eslint-disable import/no-dynamic-require, global-require */␊ + ␊ + t.deepEqual(submodule, {␊ + moduleDirect: 'direct',␊ + moduleNested: 'nested',␊ + parentModule: 'parent'␊ + });␊ + `, + } ## dynamic-require-absolute-paths > Snapshot 1 - `'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';␊ - ␊ - });␊ - ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || 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');␊ - ` + { + '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';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || 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-es-entry > Snapshot 1 - `'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';␊ - ␊ - });␊ - ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || 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');␊ - ` + { + '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';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || 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 - `'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};␊ - ␊ - });␊ - ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ - /* 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');␊ - ` + { + '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};␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + /* 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 - `'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';␊ - ␊ - });␊ - ␊ - const submodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ - ␊ - const submodule2 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ - ␊ - const extramodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || 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);␊ - ` + { + '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';␊ + ␊ + });␊ + ␊ + const submodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ + ␊ + const submodule2 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ + ␊ + const extramodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || 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 - `'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);␊ - });␊ - ␊ - const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ - ␊ - const main = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ - ␊ - /* 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');␊ - ` + { + '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);␊ + });␊ + ␊ + const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ + ␊ + const main = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ + ␊ + /* 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 - `'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'});␊ - ` + { + '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 - `'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' });␊ - ` + { + '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 - `'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);␊ - });␊ - ␊ - const entry = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ - ␊ - t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ - ` + { + '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);␊ + });␊ + ␊ + const entry = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ + ␊ + t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ + `, + } ## dynamic-require-relative-paths > Snapshot 1 - `'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';␊ - ␊ - });␊ - ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ - const subsubmodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || 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');␊ - ` + { + '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';␊ + ␊ + });␊ + ␊ + const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ + ␊ + const subsubmodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || 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 - `'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' });␊ - ` + { + '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 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);␊ - ` + { + '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 d8cdc4e806b8164cded45cd9f4b90118a5c0d6c8..aa7e35c89a6f9217a767a9f3d510936c848c4339 100644 GIT binary patch literal 6755 zcmaLbMNk|HkOtrkFgOHT=+?5>}=7aAEAd(y7Y_4pf^S#=3EQc%-@x%WX?1dgm zCeC2m?~uq^A~FG0@3rl|i7|m?KpQV5fl12eL?GrBfcIhQ?h<|K0Xi>u&TJAT6*P9h zdCDTiQsTH1tt&s98&0Ui23Yv>XHY^yVfyjb+kPyZ=ICkM=l-<%@8jLLKp-iD{caP#!il*c`*R`QHrO;jw{Wqp7pdedc= z>UZYdUPt@c(@zsw5)S$JY`xnRmnEJtwA)Qj^GAk{->wwci(RvsrB&=QEHm$S@MCP& ze7)Zm?@SX+WjEM0;)VVgZWzAb-X7JY-EW`8KvBrv5}{?G7V*v(g$@;O-#ylp$g*1u zk91J>{u>d+^;LNfLG5}?D6Pw8?*fIHEJ+hTnXRcyEq<4!^WiB;KZ~=i*|)-bbt9Y* zq%uAJMft3G{<7O*BRwYPWn86T5xSg~#Kz?p45q4i8UEeHN+)1(yuY)y`Et-eWGef* zOD(8ikaGCySvc;WfRYKuka2NZ>P7`oa=exWQ=g(y}L)LpGIzc+J6Q< zNlaPn;y0H68}g_=;o-e;-(PMb>$9T~-*}m|v?S;;{<;O7u$H65lk=1vTBvf9o;zZA zyTCM^&p;DrMqL+poPY9*W8-pZ0Si9P;|>~KxR}eXxIB36)SZQnr9OjROohI^EyPT{ zFU``}JntFTfXVFs+o=5BAkX^k_Pp+-YWThR(AsDC;o|p5>Z*MVIO^SCHot$#b<=HZ z{OFrz!$r-RsjQx34Y;cN<<$-%{M^dMeLQ~u*!B8k1yV640-wwiVbiF~y&PnoEx!N7 zba8tpr!_8j&H;D&iBHxAM{PY_`^B`s5j>?Gk;SszpKi&_)vxuTSa-Kxv@yc*7H&R|E~J( zM(%Pq&ctt))ADq+=H_>MlU(CRVSEZCqB@DrVD9o*wezh%3Er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lR`K$Y2dv%XO zcg)04bW4&hcJj;Q(ya@i{8{<@6%PIZcM-2mijT$F1&85+=*%)GXgH=Sxl$(9G8IuQ zrLN7c6nBm4{9M8UQQ>7OJ;ueTNDqY~0UNDrp0>5jYr-YZ^!q1B0WKr~H6>}-O~jEH zJo6SZr`rdX0-f-9HN<+c>83}NFW#mbEF6Yg*D0|z|}$-;#{UR0*j6jq+Pp&PFjIsgVWHNMKu4eVJl>9R2xMf|FTwYF1>?b8@ynAn;oj_f#}Kma$z;-PGu0`VaBh2Wfi|z z@@U~}Xh^XTIB%9kg%xgG5T+BYslg~~$`mVPixk@~Jae>Oj)7GM^{N^-C5C~o+Z5lN zUewKQ{?OEZh&znBaILBAkwA!TBOO}D+BrkLx)1g7m+tPN+cL&?;g0?no8bldn|)Dz zq?~Ky=flz;3(UnpmYX;}?>o{_eDB(DZmAHF1fBDpr7n4s_4jR^_9wdcmd`{O$I>F& z8sXFe>#eD9dPv~`eC;|8d1sg{PYC}Z<#svi$gig&2tTbnXbt{3vrSy}WT0KYqiLX~ zT{>GPHp~IQNLv4lbL=YcXurzqE;OR`W3dt z5QTAMBz1x0M>^LPvW0rfRp^b_gY_SJ*hKSt$4yWy5t^_pOU;AiuQ$w<{%ItteqLoT zh%HB_@<+;<-Wd;|f5`|FSWhD{{Di|&Ik`=7yB?rD0p+5kFpUY=ZJW*2#+u-Y`cW4o zm;8|Q004+5^CZS=NpRqqzdd$bwXJQtA%Dp)=^c#6_#=o32^kQK^_Nb=n+g9m?i z-n-KNf(yq8B6ET1Mx-4aVnRJO?z`IDg@ zsjb?v5fKQ66E;tzma5s~TT$roCpk!U?S5Tw^L|W7Zz@<{Gr-Gu65BNP?S|AB^`R@j O(!MxWNp(>nBK#l9tkpIE diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js index d3e09297b..be62d8d99 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 From f332cea8844b7a0c5dd1bc0107ad948d3bbf43c5 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 9 Mar 2020 12:54:38 +0100 Subject: [PATCH 06/12] test(commonjs): Try to add a code-splitting test --- .../dynamic-require-code-splitting/_config.js | 12 ++++++++++++ .../function/dynamic-require-code-splitting/lib1.js | 12 ++++++++++++ .../function/dynamic-require-code-splitting/lib2.js | 12 ++++++++++++ .../function/dynamic-require-code-splitting/main.js | 2 ++ .../function/dynamic-require-code-splitting/main2.js | 1 + .../dynamic-require-code-splitting/target1.js | 1 + .../dynamic-require-code-splitting/target2.js | 1 + packages/commonjs/test/function.js | 6 ++++-- 8 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/_config.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main.js create mode 100755 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/main2.js create mode 100644 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target1.js create mode 100644 packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/target2.js 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..f63fa2d38 --- /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, '1'); +} 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..f63fa2d38 --- /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, '1'); +} 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/function.js b/packages/commonjs/test/function.js index 73502b6e7..13dc8c745 100644 --- a/packages/commonjs/test/function.js +++ b/packages/commonjs/test/function.js @@ -35,11 +35,13 @@ readdirSync('./fixtures/function').forEach((dir) => { const bundle = await rollup(options); const codeMap = await getCodeMapFromBundle(bundle); if (config.show || config.solo) { + console.error(); for (const chunkName of Object.keys(codeMap)) { - console.group(chunkName); + console.error(); + console.error(`===> ${chunkName}`); + console.group(); console.error(codeMap[chunkName]); console.groupEnd(); - console.error(); } } const { exports, global } = runCodeSplitTest(codeMap, t, config.context); From a6a96e257be08f495b2217fffa063369093983bc Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Wed, 11 Mar 2020 14:00:36 +0200 Subject: [PATCH 07/12] Fixed code-splitting support --- packages/commonjs/src/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index 1720844b8..6f746378f 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -89,8 +89,6 @@ export default function commonjs(options = {}) { const sourceMap = options.sourceMap !== false; - let mainModuleId = null; - function transformAndCheckExports(code, id) { const { isEsModule, hasDefaultExport, ast } = checkEsModule(this.parse, code, id); @@ -256,11 +254,7 @@ export default function commonjs(options = {}) { }); } - // TODO: For code splitting, the runtime probably needs to be imported by each entry point - - if (!mainModuleId && isDynamicRequireModulesEnabled) { - mainModuleId = actualId; - + if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) { let code; try { From 1da21fd9c87609f059f07e89ff42245cc7658b97 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Wed, 11 Mar 2020 14:03:32 +0200 Subject: [PATCH 08/12] Cleanup: avoid importing commonjs-proxy when we only need to register --- packages/commonjs/src/transform.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js index 15308e3ad..b6432b654 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -199,7 +199,7 @@ export function transformCommonjs( } if (isDynamicRegister || !isDynamic || sourceId.endsWith('.json')) { - sources.push(sourceId); + sources.push([sourceId, !isDynamicRegister]); } required[sourceId] = { source: sourceId, name, importsDefault: false, isDynamic }; @@ -512,15 +512,17 @@ export function transformCommonjs( ) .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(([_source, importProxy]) => importProxy) + .map(([source]) => { + const { name, importsDefault } = required[source]; + return `import ${importsDefault ? `${name} from ` : ``}'${getProxyId(source)}';`; + }) ) .join('\n')}\n\n`; From 4686e793932c7c80c797e310ecaae77c53e4de5c Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Wed, 11 Mar 2020 14:09:48 +0200 Subject: [PATCH 09/12] Fixed test --- .../fixtures/function/dynamic-require-code-splitting/lib1.js | 2 +- .../fixtures/function/dynamic-require-code-splitting/lib2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index f63fa2d38..54136fdd2 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib1.js @@ -8,5 +8,5 @@ for (const index of [1, 2]) { } catch (err) { ({ message } = err); } - t.is(message, '1'); + 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 index f63fa2d38..54136fdd2 100755 --- a/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js +++ b/packages/commonjs/test/fixtures/function/dynamic-require-code-splitting/lib2.js @@ -8,5 +8,5 @@ for (const index of [1, 2]) { } catch (err) { ({ message } = err); } - t.is(message, '1'); + t.is(message, index.toString()); } From 88ef70d05348fe8f33f9241b3add378490efbafe Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Thu, 12 Mar 2020 07:16:55 +0200 Subject: [PATCH 10/12] Updated pnpm-lock --- pnpm-lock.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 94351a7da..7c68f476a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -108,7 +108,9 @@ importers: packages/commonjs: dependencies: '@rollup/pluginutils': 3.0.8_rollup@1.29.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 @@ -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 @@ -2529,7 +2533,6 @@ packages: resolution: integrity: sha1-zVL28HEuC6q5fW+XModPIvR3UsA= /commondir/1.0.1: - dev: true resolution: integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= /concat-map/0.0.1: From ad72b8c4a397140938bfcc8afe41e031b367c7bc Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Thu, 12 Mar 2020 07:17:43 +0200 Subject: [PATCH 11/12] Updated snapshots --- .../commonjs/test/snapshots/function.js.md | 221 +++++++++++++++--- .../commonjs/test/snapshots/function.js.snap | Bin 6755 -> 6794 bytes 2 files changed, 191 insertions(+), 30 deletions(-) diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index 80fef584c..35b985829 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -387,8 +387,6 @@ Generated by [AVA](https://ava.li). };␊ });␊ ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ let message;␊ @@ -581,12 +579,6 @@ Generated by [AVA](https://ava.li). parentModule: parentModule␊ };␊ ␊ - const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/direct.js"); (direct && direct['default']) || direct;␊ - ␊ - const nested = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/sub/node_modules/module/nested/nested.js"); (nested && nested['default']) || nested;␊ - ␊ - const parent = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-import/node_modules/parent-module/parent.js"); (parent && parent['default']) || parent;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ t.deepEqual(submodule, {␊ @@ -748,8 +740,6 @@ Generated by [AVA](https://ava.li). ␊ });␊ ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-absolute-paths/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ ␊ @@ -759,6 +749,197 @@ Generated by [AVA](https://ava.li). `, } +## 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 @@ -906,8 +1087,6 @@ Generated by [AVA](https://ava.li). ␊ });␊ ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-es-entry/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule (withName) {␊ @@ -1067,8 +1246,6 @@ Generated by [AVA](https://ava.li). ␊ });␊ ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-extensions/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ @@ -1244,12 +1421,6 @@ Generated by [AVA](https://ava.li). ␊ });␊ ␊ - const submodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule1.js"); (submodule1 && submodule1['default']) || submodule1;␊ - ␊ - const submodule2 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/submodule2.js"); (submodule2 && submodule2['default']) || submodule2;␊ - ␊ - const extramodule1 = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-globs/extramodule1.js"); (extramodule1 && extramodule1['default']) || extramodule1;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ @@ -1431,10 +1602,6 @@ Generated by [AVA](https://ava.li). module.exports = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js", null);␊ });␊ ␊ - const direct = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/direct/index.js"); (direct && direct['default']) || direct;␊ - ␊ - const main = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-instances/package/main.js"); (main && main['default']) || main;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModule(withName) {␊ @@ -1977,8 +2144,6 @@ Generated by [AVA](https://ava.li). module.exports = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js", null);␊ });␊ ␊ - const entry = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/node_modules/custom-module/entry.js"); (entry && entry['default']) || entry;␊ - ␊ t.is(commonjsRequire("custom-module", "/$$rollup_base$$/fixtures/function/dynamic-require-package-sub/sub"), 'custom-module');␊ `, } @@ -2135,10 +2300,6 @@ Generated by [AVA](https://ava.li). ␊ });␊ ␊ - const submodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/submodule.js"); (submodule && submodule['default']) || submodule;␊ - ␊ - const subsubmodule = commonjsRequire("/$$rollup_base$$/fixtures/function/dynamic-require-relative-paths/sub/subsub/subsubmodule.js"); (subsubmodule && subsubmodule['default']) || subsubmodule;␊ - ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ function takeModuleWithDelimiter(name, delimiter) {␊ diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index aa7e35c89a6f9217a767a9f3d510936c848c4339..70c4b04a7326f3e33943b9d749d890fe76e502fe 100644 GIT binary patch literal 6794 zcmaLVRZtWRvF(}ax@AFP>F(}aS{kHNT1s;1uBAg-U3vkD1r(GHVM&oj;C^%8 zt`GM-o%zjw&YYQZK*k^@gEw~GelA}AOo75UFHi`n!mHTZ`s|0;wq!n|n=~+{V4?hP zp`BP^7m+O$w7g)QR%A`MG24{8QVkMAFeRYk@{0BB?uV z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From: Daniel Cohen Gindi Date: Thu, 12 Mar 2020 08:06:35 +0200 Subject: [PATCH 12/12] Satisfy linter --- packages/commonjs/src/transform.js | 2 +- packages/commonjs/test/helpers/util.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js index b6432b654..be8145575 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -518,7 +518,7 @@ export function transformCommonjs( `import '${source}';` ), sources - .filter(([_source, importProxy]) => importProxy) + .filter(([, importProxy]) => importProxy) .map(([source]) => { const { name, importsDefault } = required[source]; return `import ${importsDefault ? `${name} from ` : ``}'${getProxyId(source)}';`; diff --git a/packages/commonjs/test/helpers/util.js b/packages/commonjs/test/helpers/util.js index 31b41d2c0..e688a0c00 100644 --- a/packages/commonjs/test/helpers/util.js +++ b/packages/commonjs/test/helpers/util.js @@ -34,7 +34,7 @@ function runCodeSplitTest(codeMap, t, configContext = {}) { Object.assign({ require: requireFromOutputVia(outputId) }, context) ); } - // eslint-disable-next-line import/no-dynamic-require + // eslint-disable-next-line import/no-dynamic-require, global-require return require(importee); };