diff --git a/bin/src/index.ts b/bin/src/index.ts
index 8f6d0c0c9b2..95f26a55998 100644
--- a/bin/src/index.ts
+++ b/bin/src/index.ts
@@ -9,9 +9,9 @@ const command = minimist(process.argv.slice(2), {
});
if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
- console.log(`\n${help.replace('__VERSION__', version)}\n`); // eslint-disable-line no-console
+ console.log(`\n${help.replace('__VERSION__', version)}\n`);
} else if (command.version) {
- console.log(`rollup v${version}`); // eslint-disable-line no-console
+ console.log(`rollup v${version}`);
} else {
try {
require('source-map-support').install();
diff --git a/bin/src/logging.ts b/bin/src/logging.ts
index beabafab69f..bc4e6c846ff 100644
--- a/bin/src/logging.ts
+++ b/bin/src/logging.ts
@@ -3,7 +3,7 @@ import { RollupError } from '../../src/rollup/types';
import relativeId from '../../src/utils/relativeId';
// log to stderr to keep `rollup main.js > bundle.js` from breaking
-export const stderr = console.error.bind(console); // eslint-disable-line no-console
+export const stderr = console.error.bind(console);
export function handleError(err: RollupError, recover = false) {
let description = err.message || err;
diff --git a/docs/05-plugins.md b/docs/05-plugins.md
index a7deaaeaf42..7d3ee34d7a5 100644
--- a/docs/05-plugins.md
+++ b/docs/05-plugins.md
@@ -195,13 +195,35 @@ If you return an object, then it is possible to resolve an import to a different
```js
resolveId(id) {
- if (id === 'my-dependency') {
- return {id: 'my-dependency-develop', external: true};
- }
- return null;
+ if (id === 'my-dependency') {
+ return {id: 'my-dependency-develop', external: true};
+ }
+ return null;
}
```
+#### `resolveImportMeta`
+Type: `(property: string | null, {chunkId: string, moduleId: string, format: string}) => string | null`
+Kind: `sync, first`
+
+Allows to customize how Rollup handles `import.meta` and `import.meta.someProperty`, in particular `import.meta.url`. In ES modules, `import.meta` is an object and `import.meta.url` contains the URL of the current module, e.g. `http://server.net/bundle.js` for browsers or `file:///path/to/bundle.js` in Node.
+
+By default for formats other than ES modules, Rollup replaces `import.meta.url` with code that attempts to match this behaviour by returning the dynamic URL of the current chunk. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. For other properties, `import.meta.someProperty` is replaced with `undefined` while `import.meta` is replaced with an object containing a `url` property.
+
+ This behaviour can be changed—also for ES modules—via this hook. For each occurrence of `import.meta<.someProperty>`, this hook is called with the name of the property or `null` if `import.meta` is accessed directly. For example, the following code will resolve `import.meta.url` using the relative path of the original module to the current working directory and again resolve this path against the base URL of the current document at runtime:
+
+```javascript
+// rollup.config.js
+resolveImportMeta(property, {moduleId}) {
+ if (property === 'url') {
+ return `new URL('${path.relative(process.cwd(), moduleId)}', document.baseURI).href`;
+ }
+ return null;
+}
+```
+
+Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk.
+
#### `transform`
Type: `(code: string, id: string) => string | { code: string, map?: string | SourceMap, ast? : ESTree.Program } | null`
diff --git a/package-lock.json b/package-lock.json
index 154bf7858a9..97e7835f0c6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3327,7 +3327,7 @@
"glob": "7.1.3",
"growl": "1.10.5",
"he": "1.2.0",
- "js-yaml": "3.13.0",
+ "js-yaml": "^3.13.0",
"log-symbols": "2.2.0",
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
@@ -3769,7 +3769,7 @@
},
"os-tmpdir": {
"version": "1.0.2",
- "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
+ "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"osenv": {
@@ -4218,6 +4218,12 @@
"integrity": "sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=",
"dev": true
},
+ "requirejs": {
+ "version": "2.3.6",
+ "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.6.tgz",
+ "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==",
+ "dev": true
+ },
"requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
@@ -4931,6 +4937,12 @@
"integrity": "sha512-TyOuWLwkmtPL49LHCX1caIwHjRzcVd62+GF6h8W/jHOeZUFHpnd2XJDVuUlaTaLPH1nuu2M69mfHr5XbQJnf/g==",
"dev": true
},
+ "systemjs": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/systemjs/-/systemjs-3.1.0.tgz",
+ "integrity": "sha512-91NK7BcuqGbfP/CjL4N3uaT+pupmNp7nCtEQr0gzCfn7SrpPpl6j0EIidLGnuO/E4NfWIDbQkTK2X2Pmdfw+kg==",
+ "dev": true
+ },
"table": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/table/-/table-5.2.3.tgz",
@@ -5014,7 +5026,7 @@
},
"through": {
"version": "2.3.8",
- "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
+ "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true
},
diff --git a/package.json b/package.json
index 3e847c15c32..fc1fdd23935 100644
--- a/package.json
+++ b/package.json
@@ -97,6 +97,7 @@
"pretty-ms": "^4.0.0",
"remap-istanbul": "^0.13.0",
"require-relative": "^0.8.7",
+ "requirejs": "^2.3.6",
"rollup": "^1.9.1",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-buble": "^0.19.6",
@@ -114,6 +115,7 @@
"source-map": "^0.6.1",
"source-map-support": "^0.5.12",
"sourcemap-codec": "^1.4.4",
+ "systemjs": "^3.1.0",
"terser": "^3.17.0",
"tslib": "^1.9.3",
"tslint": "^5.15.0",
diff --git a/src/Chunk.ts b/src/Chunk.ts
index c489b10d10e..f150f22d74b 100644
--- a/src/Chunk.ts
+++ b/src/Chunk.ts
@@ -800,8 +800,11 @@ export default class Chunk {
const module = this.orderedModules[i];
const code = this.renderedModuleSources[i];
for (const importMeta of module.importMetas) {
- if (importMeta.renderFinalMechanism(code, this.id, options.format, options.compact))
+ if (
+ importMeta.renderFinalMechanism(code, this.id, options.format, this.graph.pluginDriver)
+ ) {
usesMechanism = true;
+ }
}
}
return usesMechanism;
diff --git a/src/Graph.ts b/src/Graph.ts
index 395ba66f39d..2657d6ef9ff 100644
--- a/src/Graph.ts
+++ b/src/Graph.ts
@@ -41,7 +41,7 @@ function makeOnwarn() {
return (warning: any) => {
const str = warning.toString();
if (str in warned) return;
- console.error(str); //eslint-disable-line no-console
+ console.error(str);
warned[str] = true;
};
}
diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts
index a38a31f37da..e532a8a0adb 100644
--- a/src/ast/nodes/MetaProperty.ts
+++ b/src/ast/nodes/MetaProperty.ts
@@ -1,109 +1,88 @@
import MagicString from 'magic-string';
import { dirname, normalize, relative } from '../../utils/path';
-import { RenderOptions } from '../../utils/renderHelpers';
+import { PluginDriver } from '../../utils/pluginDriver';
import Identifier from './Identifier';
-import Literal from './Literal';
import MemberExpression from './MemberExpression';
import * as NodeType from './NodeType';
import { NodeBase } from './shared/Node';
-const globalImportMetaUrlMechanism = `(typeof document !== 'undefined' ? document.currentScript && document.currentScript.src || document.baseURI : new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)('file:' + __filename).href)`;
-const importMetaUrlMechanisms: Record = {
- amd: `new URL((typeof process !== 'undefined' && process.versions && process.versions.node ? 'file:' : '') + module.uri).href`,
- cjs: `new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)((process.browser ? '' : 'file:') + __filename, process.browser && document.baseURI).href`,
- iife: globalImportMetaUrlMechanism,
- umd: globalImportMetaUrlMechanism
-};
+const getResolveUrl = (path: string, URL: string = 'URL') => `new ${URL}(${path}).href`;
-const globalImportMetaUrlMechanismCompact = `(typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href)`;
-const importMetaUrlMechanismsCompact: Record = {
- amd: `new URL((typeof process!=='undefined'&&process.versions&&process.versions.node?'file:':'')+module.uri).href`,
- cjs: `new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)((process.browser?'':'file:')+__filename,process.browser&&document.baseURI).href`,
- iife: globalImportMetaUrlMechanismCompact,
- umd: globalImportMetaUrlMechanismCompact
-};
+const amdModuleUrl = `(typeof process !== 'undefined' && process.versions && process.versions.node ? 'file:' : '') + module.uri`;
-const globalRelUrlMechanism = (relPath: string, compact: boolean) => {
- const _ = compact ? '' : ' ';
- return `new${_}(typeof URL${_}!==${_}'undefined'${_}?${_}URL${_}:${_}require('ur'+'l').URL)((typeof document${_}!==${_}'undefined'${_}?${_}document.currentScript${_}&&${_}document.currentScript.src${_}||${_}document.baseURI${_}:${_}'file:'${_}+${_}__filename)${_}+${_}'/../${relPath}').href`;
+const globalRelUrlMechanism = (relPath: string) => {
+ return getResolveUrl(
+ `(typeof document !== 'undefined' ? document.currentScript && document.currentScript.src || document.baseURI : 'file:' + __filename) + '/../${relPath}'`,
+ `(typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)`
+ );
};
-const relUrlMechanisms: Record string> = {
- amd: (relPath: string, compact: boolean) => {
- const _ = compact ? '' : ' ';
- return `new URL((typeof process${_}!==${_}'undefined'${_}&&${_}process.versions${_}&&${_}process.versions.node${_}?${_}'file:'${_}:${_}'')${_}+${_}module.uri${_}+${_}'/../${relPath}').href`;
- },
- cjs: (relPath: string, compact: boolean) => {
- const _ = compact ? '' : ' ';
- return `new${_}(typeof URL${_}!==${_}'undefined'${_}?${_}URL${_}:${_}require('ur'+'l').URL)((process.browser${_}?${_}''${_}:${_}'file:')${_}+${_}__dirname${_}+${_}'/${relPath}',${_}process.browser${_}&&${_}document.baseURI).href`;
- },
- es: (relPath: string, compact: boolean) => {
- const _ = compact ? '' : ' ';
- return `new URL('../${relPath}',${_}import.meta.url).href`;
- },
+const relUrlMechanisms: Record string> = {
+ amd: (relPath: string) => getResolveUrl(`${amdModuleUrl} + '/../${relPath}'`),
+ cjs: (relPath: string) =>
+ getResolveUrl(
+ `(process.browser ? '' : 'file:') + __dirname + '/${relPath}', process.browser && document.baseURI`,
+ `(typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)`
+ ),
+ es: (relPath: string) => getResolveUrl(`'../${relPath}', import.meta.url`),
iife: globalRelUrlMechanism,
- system: (relPath: string, compact: boolean) => {
- const _ = compact ? '' : ' ';
- return `new URL('../${relPath}',${_}module.url).href`;
- },
+ system: (relPath: string) => getResolveUrl(`'../${relPath}', module.url`),
umd: globalRelUrlMechanism
};
export default class MetaProperty extends NodeBase {
meta: Identifier;
property: Identifier;
- rendered: boolean;
type: NodeType.tMetaProperty;
initialise() {
if (this.meta.name === 'import') {
- this.rendered = false;
this.context.addImportMeta(this);
}
this.included = false;
}
- render(code: MagicString, options: RenderOptions) {
- if (this.meta.name === 'import') this.rendered = true;
- super.render(code, options);
- }
-
renderFinalMechanism(
code: MagicString,
chunkId: string,
format: string,
- compact: boolean
+ pluginDriver: PluginDriver
): boolean {
- if (!this.rendered) return false;
-
- if (this.parent instanceof MemberExpression === false) return false;
-
- const parent = this.parent;
-
- let importMetaProperty: string;
- if (parent.property instanceof Identifier) importMetaProperty = parent.property.name;
- else if (parent.property instanceof Literal && typeof parent.property.value === 'string')
- importMetaProperty = parent.property.value;
- else return false;
+ if (!this.included) return false;
+ const parent = this.parent;
+ const importMetaProperty =
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
+ ? parent.propertyKey
+ : null;
// support import.meta.ROLLUP_ASSET_URL_[ID]
- if (importMetaProperty.startsWith('ROLLUP_ASSET_URL_')) {
+ if (importMetaProperty && importMetaProperty.startsWith('ROLLUP_ASSET_URL_')) {
const assetFileName = this.context.getAssetFileName(importMetaProperty.substr(17));
const relPath = normalize(relative(dirname(chunkId), assetFileName));
- code.overwrite(parent.start, parent.end, relUrlMechanisms[format](relPath, compact));
+ code.overwrite(
+ (parent as MemberExpression).start,
+ (parent as MemberExpression).end,
+ relUrlMechanisms[format](relPath)
+ );
return true;
}
- if (format === 'system') {
- code.overwrite(this.meta.start, this.meta.end, 'module');
- } else if (importMetaProperty === 'url') {
- const importMetaUrlMechanism = (compact
- ? importMetaUrlMechanismsCompact
- : importMetaUrlMechanisms)[format];
- if (importMetaUrlMechanism) code.overwrite(parent.start, parent.end, importMetaUrlMechanism);
+ const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [
+ importMetaProperty,
+ {
+ chunkId,
+ format,
+ moduleId: this.context.module.id
+ }
+ ]);
+ if (typeof replacement === 'string') {
+ if (parent instanceof MemberExpression) {
+ code.overwrite(parent.start, parent.end, replacement);
+ } else {
+ code.overwrite(this.start, this.end, replacement);
+ }
return true;
}
-
return false;
}
}
diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts
index 189c49e8265..316666f3c1f 100644
--- a/src/rollup/types.d.ts
+++ b/src/rollup/types.d.ts
@@ -191,6 +191,12 @@ export type ResolveDynamicImportHook = (
parentId: string
) => Promise | string | void;
+export type ResolveImportMetaHook = (
+ this: PluginContext,
+ prop: string | null,
+ options: { chunkId: string; format: string; moduleId: string }
+) => string | void;
+
export type AddonHook = string | ((this: PluginContext) => string | Promise);
/**
@@ -244,6 +250,7 @@ export interface Plugin {
renderStart?: (this: PluginContext) => Promise | void;
resolveDynamicImport?: ResolveDynamicImportHook;
resolveId?: ResolveIdHook;
+ resolveImportMeta?: ResolveImportMetaHook;
transform?: TransformHook;
/** @deprecated */
transformBundle?: TransformChunkHook;
diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts
index 6478e6a3410..4cc1c4bda4f 100644
--- a/src/utils/defaultPlugin.ts
+++ b/src/utils/defaultPlugin.ts
@@ -1,6 +1,6 @@
import { InputOptions, Plugin } from '../rollup/types';
import { error } from './error';
-import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs'; // eslint-disable-line
+import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs';
import { basename, dirname, isAbsolute, resolve } from './path';
export function getRollupDefaultPlugin(options: InputOptions): Plugin {
@@ -13,6 +13,12 @@ export function getRollupDefaultPlugin(options: InputOptions): Plugin {
resolveDynamicImport(specifier, parentId) {
if (typeof specifier === 'string' && !this.isExternal(specifier, parentId, false))
return >this.resolveId(specifier, parentId);
+ },
+ resolveImportMeta(prop, { chunkId, format }) {
+ const mechanism = importMetaUrlMechanisms[format] && importMetaUrlMechanisms[format](chunkId);
+ if (mechanism) {
+ return prop === null ? `({ url: ${mechanism} })` : prop === 'url' ? mechanism : 'undefined';
+ }
}
};
}
@@ -67,3 +73,24 @@ function createResolveId(options: InputOptions) {
);
};
}
+
+const getResolveUrl = (path: string, URL: string = 'URL') => `new ${URL}(${path}).href`;
+
+const getUrlFromDocument = (chunkId: string) =>
+ `(document.currentScript && document.currentScript.src || new URL('${chunkId}', document.baseURI).href)`;
+
+const importMetaUrlMechanisms: Record string> = {
+ amd: () => getResolveUrl(`module.uri, document.baseURI`),
+ cjs: chunkId =>
+ `(typeof document === 'undefined' ? ${getResolveUrl(
+ `'file:' + __filename`,
+ `(require('u' + 'rl').URL)`
+ )} : ${getUrlFromDocument(chunkId)})`,
+ iife: chunkId => getUrlFromDocument(chunkId),
+ system: () => `module.meta.url`,
+ umd: chunkId =>
+ `(typeof document === 'undefined' ? ${getResolveUrl(
+ `'file:' + __filename`,
+ `(require('u' + 'rl').URL)`
+ )} : ${getUrlFromDocument(chunkId)})`
+};
diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts
index 00455edc6e9..a91739eb166 100644
--- a/src/utils/mergeOptions.ts
+++ b/src/utils/mergeOptions.ts
@@ -39,9 +39,9 @@ const getObjectOption = (
const defaultOnWarn: WarningHandler = warning => {
if (typeof warning === 'string') {
- console.warn(warning); // eslint-disable-line no-console
+ console.warn(warning);
} else {
- console.warn(warning.message); // eslint-disable-line no-console
+ console.warn(warning.message);
}
};
diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts
index be80d7e3cff..2c32d9403d5 100644
--- a/src/utils/pluginDriver.ts
+++ b/src/utils/pluginDriver.ts
@@ -22,6 +22,7 @@ export interface PluginDriver {
hasLoadersOrTransforms: boolean;
getAssetFileName(assetId: string): string;
hookFirst(hook: string, args?: any[], hookContext?: HookContext): Promise;
+ hookFirstSync(hook: string, args?: any[], hookContext?: HookContext): T;
hookParallel(hook: string, args?: any[], hookContext?: HookContext): Promise;
hookReduceArg0(
hook: string,
@@ -171,22 +172,22 @@ export function createPluginDriver(
function runHookSync(
hookName: string,
args: any[],
- pidx: number,
+ pluginIndex: number,
permitValues = false,
hookContext?: HookContext
- ): Promise {
- const plugin = plugins[pidx];
- let context = pluginContexts[pidx];
+ ): T {
+ const plugin = plugins[pluginIndex];
+ let context = pluginContexts[pluginIndex];
const hook = (plugin)[hookName];
if (!hook) return;
const deprecatedHookNewName = deprecatedHookNames[hookName];
if (deprecatedHookNewName)
- context.warn(hookDeprecationWarning(hookName, deprecatedHookNewName, plugin, pidx));
+ context.warn(hookDeprecationWarning(hookName, deprecatedHookNewName, plugin, pluginIndex));
if (hookContext) {
context = hookContext(context, plugin);
- if (!context || context === pluginContexts[pidx])
+ if (!context || context === pluginContexts[pluginIndex])
throw new Error('Internal Rollup error: hookContext must return a new context object.');
}
try {
@@ -196,7 +197,7 @@ export function createPluginDriver(
error({
code: 'INVALID_PLUGIN_HOOK',
message: `Error running plugin hook ${hookName} for ${plugin.name ||
- `Plugin at position ${pidx + 1}`}, expected a function hook.`
+ `Plugin at position ${pluginIndex + 1}`}, expected a function hook.`
});
}
return hook.apply(context, args);
@@ -206,7 +207,7 @@ export function createPluginDriver(
if (err.code) err.pluginCode = err.code;
err.code = 'PLUGIN_ERROR';
}
- err.plugin = plugin.name || `Plugin at position ${pidx + 1}`;
+ err.plugin = plugin.name || `Plugin at position ${pluginIndex + 1}`;
err.hook = hookName;
error(err);
}
@@ -215,22 +216,22 @@ export function createPluginDriver(
function runHook(
hookName: string,
args: any[],
- pidx: number,
+ pluginIndex: number,
permitValues = false,
hookContext?: HookContext
): Promise {
- const plugin = plugins[pidx];
- let context = pluginContexts[pidx];
+ const plugin = plugins[pluginIndex];
+ let context = pluginContexts[pluginIndex];
const hook = (plugin)[hookName];
if (!hook) return;
const deprecatedHookNewName = deprecatedHookNames[hookName];
if (deprecatedHookNewName)
- context.warn(hookDeprecationWarning(hookName, deprecatedHookNewName, plugin, pidx));
+ context.warn(hookDeprecationWarning(hookName, deprecatedHookNewName, plugin, pluginIndex));
if (hookContext) {
context = hookContext(context, plugin);
- if (!context || context === pluginContexts[pidx])
+ if (!context || context === pluginContexts[pluginIndex])
throw new Error('Internal Rollup error: hookContext must return a new context object.');
}
return Promise.resolve()
@@ -241,7 +242,7 @@ export function createPluginDriver(
error({
code: 'INVALID_PLUGIN_HOOK',
message: `Error running plugin hook ${hookName} for ${plugin.name ||
- `Plugin at position ${pidx + 1}`}, expected a function hook.`
+ `Plugin at position ${pluginIndex + 1}`}, expected a function hook.`
});
}
return hook.apply(context, args);
@@ -252,7 +253,7 @@ export function createPluginDriver(
if (err.code) err.pluginCode = err.code;
err.code = 'PLUGIN_ERROR';
}
- err.plugin = plugin.name || `Plugin at position ${pidx + 1}`;
+ err.plugin = plugin.name || `Plugin at position ${pluginIndex + 1}`;
err.hook = hookName;
error(err);
});
@@ -289,6 +290,16 @@ export function createPluginDriver(
}
return promise;
},
+
+ // chains synchronously, first non-null result stops and returns
+ hookFirstSync(name, args?, hookContext?) {
+ for (let i = 0; i < plugins.length; i++) {
+ const result = runHookSync(name, args, i, false, hookContext);
+ if (result != null) return result as any;
+ }
+ return null;
+ },
+
// parallel, ignores returns
hookParallel(name, args, hookContext) {
const promises: Promise[] = [];
@@ -299,6 +310,7 @@ export function createPluginDriver(
}
return Promise.all(promises).then(() => {});
},
+
// chains, reduces returns of type R, to type T, handling the reduced value as the first hook argument
hookReduceArg0(name, [arg0, ...args], reduce, hookContext) {
let promise = Promise.resolve(arg0);
@@ -313,7 +325,8 @@ export function createPluginDriver(
}
return promise;
},
- // chains, synchronically reduces returns of type R, to type T, handling the reduced value as the first hook argument
+
+ // chains synchronously, reduces returns of type R, to type T, handling the reduced value as the first hook argument
hookReduceArg0Sync(name, [arg0, ...args], reduce, hookContext) {
for (let i = 0; i < plugins.length; i++) {
const result = runHookSync(name, [arg0, ...args], i, false, hookContext);
@@ -321,6 +334,7 @@ export function createPluginDriver(
}
return arg0;
},
+
// chains, reduces returns of type R, to type T, handling the reduced value separately. permits hooks as values.
hookReduceValue(name, initial, args, reduce, hookContext) {
let promise = Promise.resolve(initial);
@@ -431,10 +445,15 @@ const uncacheablePlugin: (pluginName: string) => PluginCache = pluginName => ({
}
});
-function hookDeprecationWarning(name: string, newName: string, plugin: Plugin, pidx: number) {
+function hookDeprecationWarning(
+ name: string,
+ newName: string,
+ plugin: Plugin,
+ pluginIndex: number
+) {
return {
code: name.toUpperCase() + '_HOOK_DEPRECATED',
message: `The ${name} hook used by plugin ${plugin.name ||
- `at position ${pidx + 1}`} is deprecated. The ${newName} hook should be used instead.`
+ `at position ${pluginIndex + 1}`} is deprecated. The ${newName} hook should be used instead.`
};
}
diff --git a/test/chunking-form/samples/asset-emission/_config.js b/test/chunking-form/samples/asset-emission/_config.js
index 92ad95419af..c430dd28952 100644
--- a/test/chunking-form/samples/asset-emission/_config.js
+++ b/test/chunking-form/samples/asset-emission/_config.js
@@ -1,9 +1,9 @@
module.exports = {
- description: 'simple chunking',
+ description: 'supports emitting assets from plugin hooks',
options: {
input: ['main.js'],
plugins: {
- transform (code, id) {
+ transform() {
const assetId = this.emitAsset('test.ext', 'hello world');
return `export default import.meta.ROLLUP_ASSET_URL_${assetId};`;
}
diff --git a/test/chunking-form/samples/asset-emission/index.html b/test/chunking-form/samples/asset-emission/index.html
new file mode 100644
index 00000000000..58ae4a61527
--- /dev/null
+++ b/test/chunking-form/samples/asset-emission/index.html
@@ -0,0 +1,10 @@
+
+
+
+
+ Title
+
+
+
+
+
diff --git a/test/chunking-form/samples/import-meta-url/_config.js b/test/chunking-form/samples/import-meta-url/_config.js
new file mode 100644
index 00000000000..0de1384302d
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_config.js
@@ -0,0 +1,8 @@
+module.exports = {
+ description: 'supports import.meta.url',
+ options: {
+ output: {
+ chunkFileNames: 'nested/chunk.js'
+ }
+ }
+};
diff --git a/test/chunking-form/samples/import-meta-url/_expected/amd/main.js b/test/chunking-form/samples/import-meta-url/_expected/amd/main.js
new file mode 100644
index 00000000000..d95c0efb5a9
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/amd/main.js
@@ -0,0 +1,6 @@
+define(['module', 'require', './nested/chunk.js'], function (module, require, __chunk_1) { 'use strict';
+
+ __chunk_1.log('main: ' + new URL(module.uri, document.baseURI).href);
+ new Promise(function (resolve, reject) { require(['./nested/chunk2.js'], resolve, reject) });
+
+});
diff --git a/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk.js b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk.js
new file mode 100644
index 00000000000..8df72136505
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk.js
@@ -0,0 +1,13 @@
+define(['exports'], function (exports) { 'use strict';
+
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerHTML += url + '
';
+ }
+ }
+
+ exports.log = log;
+
+});
diff --git a/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js
new file mode 100644
index 00000000000..0c78bb0ac8b
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js
@@ -0,0 +1,5 @@
+define(['module', './chunk.js'], function (module, __chunk_1) { 'use strict';
+
+ __chunk_1.log('nested: ' + new URL(module.uri, document.baseURI).href);
+
+});
diff --git a/test/chunking-form/samples/import-meta-url/_expected/cjs/main.js b/test/chunking-form/samples/import-meta-url/_expected/cjs/main.js
new file mode 100644
index 00000000000..d4619267ada
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/cjs/main.js
@@ -0,0 +1,6 @@
+'use strict';
+
+var __chunk_1 = require('./nested/chunk.js');
+
+__chunk_1.log('main: ' + (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href)));
+Promise.resolve(require('./nested/chunk2.js'));
diff --git a/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk.js b/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk.js
new file mode 100644
index 00000000000..b1d04a7cdab
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk.js
@@ -0,0 +1,11 @@
+'use strict';
+
+function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerHTML += url + '
';
+ }
+}
+
+exports.log = log;
diff --git a/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk2.js b/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk2.js
new file mode 100644
index 00000000000..ad2c0bb4da0
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/cjs/nested/chunk2.js
@@ -0,0 +1,5 @@
+'use strict';
+
+var __chunk_1 = require('./chunk.js');
+
+__chunk_1.log('nested: ' + (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('nested/chunk2.js', document.baseURI).href)));
diff --git a/test/chunking-form/samples/import-meta-url/_expected/es/main.js b/test/chunking-form/samples/import-meta-url/_expected/es/main.js
new file mode 100644
index 00000000000..85486cf6309
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/es/main.js
@@ -0,0 +1,4 @@
+import { a as log } from './nested/chunk.js';
+
+log('main: ' + import.meta.url);
+import('./nested/chunk2.js');
diff --git a/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk.js b/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk.js
new file mode 100644
index 00000000000..b666269f35d
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk.js
@@ -0,0 +1,9 @@
+function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerHTML += url + '
';
+ }
+}
+
+export { log as a };
diff --git a/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk2.js b/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk2.js
new file mode 100644
index 00000000000..4dc8950a08f
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/es/nested/chunk2.js
@@ -0,0 +1,3 @@
+import { a as log } from './chunk.js';
+
+log('nested: ' + import.meta.url);
diff --git a/test/chunking-form/samples/import-meta-url/_expected/system/main.js b/test/chunking-form/samples/import-meta-url/_expected/system/main.js
new file mode 100644
index 00000000000..b0fd79d49ee
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/system/main.js
@@ -0,0 +1,15 @@
+System.register(['./nested/chunk.js'], function (exports, module) {
+ 'use strict';
+ var log;
+ return {
+ setters: [function (module) {
+ log = module.a;
+ }],
+ execute: function () {
+
+ log('main: ' + module.meta.url);
+ module.import('./nested/chunk2.js');
+
+ }
+ };
+});
diff --git a/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk.js b/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk.js
new file mode 100644
index 00000000000..37d15663c1f
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk.js
@@ -0,0 +1,18 @@
+System.register([], function (exports, module) {
+ 'use strict';
+ return {
+ execute: function () {
+
+ exports('a', log);
+
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerHTML += url + '
';
+ }
+ }
+
+ }
+ };
+});
diff --git a/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk2.js b/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk2.js
new file mode 100644
index 00000000000..4c893092da0
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/_expected/system/nested/chunk2.js
@@ -0,0 +1,14 @@
+System.register(['./chunk.js'], function (exports, module) {
+ 'use strict';
+ var log;
+ return {
+ setters: [function (module) {
+ log = module.a;
+ }],
+ execute: function () {
+
+ log('nested: ' + module.meta.url);
+
+ }
+ };
+});
diff --git a/test/chunking-form/samples/import-meta-url/index-amd.html b/test/chunking-form/samples/import-meta-url/index-amd.html
new file mode 100644
index 00000000000..476b9ce3df1
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/index-amd.html
@@ -0,0 +1,10 @@
+
+
+
+
+ AMD
+
+
+
+
+
diff --git a/test/chunking-form/samples/import-meta-url/index-es.html b/test/chunking-form/samples/import-meta-url/index-es.html
new file mode 100644
index 00000000000..413e6fb0801
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/index-es.html
@@ -0,0 +1,10 @@
+
+
+
+
+ ES Module
+
+
+
+
+
diff --git a/test/chunking-form/samples/import-meta-url/index-system.html b/test/chunking-form/samples/import-meta-url/index-system.html
new file mode 100644
index 00000000000..96c687c1eb7
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/index-system.html
@@ -0,0 +1,11 @@
+
+
+
+
+ SystemJS
+
+
+
+
+
+
diff --git a/test/chunking-form/samples/import-meta-url/log.js b/test/chunking-form/samples/import-meta-url/log.js
new file mode 100644
index 00000000000..569e3e6f390
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/log.js
@@ -0,0 +1,7 @@
+export function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerHTML += url + '
';
+ }
+}
diff --git a/test/chunking-form/samples/import-meta-url/main.js b/test/chunking-form/samples/import-meta-url/main.js
new file mode 100644
index 00000000000..7cacbf31f83
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/main.js
@@ -0,0 +1,4 @@
+import {log} from './log';
+
+log('main: ' + import.meta.url);
+import('./nested.js');
diff --git a/test/chunking-form/samples/import-meta-url/nested.js b/test/chunking-form/samples/import-meta-url/nested.js
new file mode 100644
index 00000000000..6c04c450934
--- /dev/null
+++ b/test/chunking-form/samples/import-meta-url/nested.js
@@ -0,0 +1,3 @@
+import {log} from './log';
+
+log('nested: ' + import.meta.url);
diff --git a/test/form/samples/configure-import-meta-url/_config.js b/test/form/samples/configure-import-meta-url/_config.js
new file mode 100644
index 00000000000..d0db2f15cc8
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_config.js
@@ -0,0 +1,27 @@
+module.exports = {
+ description: 'allows to configure import.meta.url',
+ options: {
+ plugins: [
+ {
+ resolveImportMeta(prop, { chunkId, moduleId }) {
+ if (!moduleId.endsWith('resolved.js')) {
+ return `'${prop}=${chunkId}:${moduleId
+ .replace(/\\/g, '/')
+ .split('/')
+ .slice(-2)
+ .join('/')}'`;
+ }
+ return null;
+ }
+ },
+ {
+ resolveImportMeta(prop, { moduleId }) {
+ if (!moduleId.endsWith('unresolved.js')) {
+ return `'resolved'`;
+ }
+ return null;
+ }
+ }
+ ]
+ }
+};
diff --git a/test/form/samples/configure-import-meta-url/_expected/amd.js b/test/form/samples/configure-import-meta-url/_expected/amd.js
new file mode 100644
index 00000000000..38d40a1bcb1
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/amd.js
@@ -0,0 +1,15 @@
+define(['module'], function (module) { 'use strict';
+
+ console.log('resolved');
+ console.log('resolved');
+ console.log('resolved');
+
+ console.log(new URL(module.uri, document.baseURI).href);
+ console.log(undefined);
+ console.log(({ url: new URL(module.uri, document.baseURI).href }));
+
+ console.log('url=amd.js:configure-import-meta-url/main.js');
+ console.log('privateProp=amd.js:configure-import-meta-url/main.js');
+ console.log('null=amd.js:configure-import-meta-url/main.js');
+
+});
diff --git a/test/form/samples/configure-import-meta-url/_expected/cjs.js b/test/form/samples/configure-import-meta-url/_expected/cjs.js
new file mode 100644
index 00000000000..f6ab33ad5e5
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/cjs.js
@@ -0,0 +1,13 @@
+'use strict';
+
+console.log('resolved');
+console.log('resolved');
+console.log('resolved');
+
+console.log((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('cjs.js', document.baseURI).href)));
+console.log(undefined);
+console.log(({ url: (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('cjs.js', document.baseURI).href)) }));
+
+console.log('url=cjs.js:configure-import-meta-url/main.js');
+console.log('privateProp=cjs.js:configure-import-meta-url/main.js');
+console.log('null=cjs.js:configure-import-meta-url/main.js');
diff --git a/test/form/samples/configure-import-meta-url/_expected/es.js b/test/form/samples/configure-import-meta-url/_expected/es.js
new file mode 100644
index 00000000000..65363fbdc91
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/es.js
@@ -0,0 +1,11 @@
+console.log('resolved');
+console.log('resolved');
+console.log('resolved');
+
+console.log(import.meta.url);
+console.log(import.meta.privateProp);
+console.log(import.meta);
+
+console.log('url=es.js:configure-import-meta-url/main.js');
+console.log('privateProp=es.js:configure-import-meta-url/main.js');
+console.log('null=es.js:configure-import-meta-url/main.js');
diff --git a/test/form/samples/configure-import-meta-url/_expected/iife.js b/test/form/samples/configure-import-meta-url/_expected/iife.js
new file mode 100644
index 00000000000..2914b6951c8
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/iife.js
@@ -0,0 +1,16 @@
+(function () {
+ 'use strict';
+
+ console.log('resolved');
+ console.log('resolved');
+ console.log('resolved');
+
+ console.log((document.currentScript && document.currentScript.src || new URL('iife.js', document.baseURI).href));
+ console.log(undefined);
+ console.log(({ url: (document.currentScript && document.currentScript.src || new URL('iife.js', document.baseURI).href) }));
+
+ console.log('url=iife.js:configure-import-meta-url/main.js');
+ console.log('privateProp=iife.js:configure-import-meta-url/main.js');
+ console.log('null=iife.js:configure-import-meta-url/main.js');
+
+}());
diff --git a/test/form/samples/configure-import-meta-url/_expected/system.js b/test/form/samples/configure-import-meta-url/_expected/system.js
new file mode 100644
index 00000000000..0023ad18505
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/system.js
@@ -0,0 +1,20 @@
+System.register([], function (exports, module) {
+ 'use strict';
+ return {
+ execute: function () {
+
+ console.log('resolved');
+ console.log('resolved');
+ console.log('resolved');
+
+ console.log(module.meta.url);
+ console.log(undefined);
+ console.log(({ url: module.meta.url }));
+
+ console.log('url=system.js:configure-import-meta-url/main.js');
+ console.log('privateProp=system.js:configure-import-meta-url/main.js');
+ console.log('null=system.js:configure-import-meta-url/main.js');
+
+ }
+ };
+});
diff --git a/test/form/samples/configure-import-meta-url/_expected/umd.js b/test/form/samples/configure-import-meta-url/_expected/umd.js
new file mode 100644
index 00000000000..187f2c2e07e
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/_expected/umd.js
@@ -0,0 +1,18 @@
+(function (factory) {
+ typeof define === 'function' && define.amd ? define(factory) :
+ factory();
+}(function () { 'use strict';
+
+ console.log('resolved');
+ console.log('resolved');
+ console.log('resolved');
+
+ console.log((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('umd.js', document.baseURI).href)));
+ console.log(undefined);
+ console.log(({ url: (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('umd.js', document.baseURI).href)) }));
+
+ console.log('url=umd.js:configure-import-meta-url/main.js');
+ console.log('privateProp=umd.js:configure-import-meta-url/main.js');
+ console.log('null=umd.js:configure-import-meta-url/main.js');
+
+}));
diff --git a/test/form/samples/configure-import-meta-url/main.js b/test/form/samples/configure-import-meta-url/main.js
new file mode 100644
index 00000000000..a4a0af99305
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/main.js
@@ -0,0 +1,6 @@
+import './resolved';
+import './unresolved';
+
+console.log(import.meta.url);
+console.log(import.meta.privateProp);
+console.log(import.meta);
diff --git a/test/form/samples/configure-import-meta-url/resolved.js b/test/form/samples/configure-import-meta-url/resolved.js
new file mode 100644
index 00000000000..0a555e5ad35
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/resolved.js
@@ -0,0 +1,3 @@
+console.log(import.meta.url);
+console.log(import.meta.privateProp);
+console.log(import.meta);
diff --git a/test/form/samples/configure-import-meta-url/unresolved.js b/test/form/samples/configure-import-meta-url/unresolved.js
new file mode 100644
index 00000000000..0a555e5ad35
--- /dev/null
+++ b/test/form/samples/configure-import-meta-url/unresolved.js
@@ -0,0 +1,3 @@
+console.log(import.meta.url);
+console.log(import.meta.privateProp);
+console.log(import.meta);
diff --git a/test/form/samples/import-meta-url/_config.js b/test/form/samples/import-meta-url/_config.js
index 54247a7362d..7acc8dce0e5 100644
--- a/test/form/samples/import-meta-url/_config.js
+++ b/test/form/samples/import-meta-url/_config.js
@@ -1,3 +1,3 @@
module.exports = {
- description: 'import.meta.url support'
+ description: 'supports import.meta.url'
};
diff --git a/test/form/samples/import-meta-url/_expected/amd.js b/test/form/samples/import-meta-url/_expected/amd.js
index 886b5799570..3ea98d3db9b 100644
--- a/test/form/samples/import-meta-url/_expected/amd.js
+++ b/test/form/samples/import-meta-url/_expected/amd.js
@@ -1,5 +1,13 @@
define(['module'], function (module) { 'use strict';
- console.log(new URL((typeof process !== 'undefined' && process.versions && process.versions.node ? 'file:' : '') + module.uri).href);
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+ }
+
+ log(new URL(module.uri, document.baseURI).href);
});
diff --git a/test/form/samples/import-meta-url/_expected/cjs.js b/test/form/samples/import-meta-url/_expected/cjs.js
index 10d13fa8dc0..58fb168b483 100644
--- a/test/form/samples/import-meta-url/_expected/cjs.js
+++ b/test/form/samples/import-meta-url/_expected/cjs.js
@@ -1,3 +1,11 @@
'use strict';
-console.log(new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)((process.browser ? '' : 'file:') + __filename, process.browser && document.baseURI).href);
\ No newline at end of file
+function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+}
+
+log((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('cjs.js', document.baseURI).href)));
diff --git a/test/form/samples/import-meta-url/_expected/es.js b/test/form/samples/import-meta-url/_expected/es.js
index d9536a69b3f..9390079070b 100644
--- a/test/form/samples/import-meta-url/_expected/es.js
+++ b/test/form/samples/import-meta-url/_expected/es.js
@@ -1 +1,9 @@
-console.log(import.meta.url);
+function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+}
+
+log(import.meta.url);
diff --git a/test/form/samples/import-meta-url/_expected/iife.js b/test/form/samples/import-meta-url/_expected/iife.js
index 65de53720fa..2ceafdeef6b 100644
--- a/test/form/samples/import-meta-url/_expected/iife.js
+++ b/test/form/samples/import-meta-url/_expected/iife.js
@@ -1,6 +1,14 @@
(function () {
'use strict';
- console.log((typeof document !== 'undefined' ? document.currentScript && document.currentScript.src || document.baseURI : new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)('file:' + __filename).href));
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+ }
+
+ log((document.currentScript && document.currentScript.src || new URL('iife.js', document.baseURI).href));
}());
diff --git a/test/form/samples/import-meta-url/_expected/system.js b/test/form/samples/import-meta-url/_expected/system.js
index b617d5bd624..85f9c9532f7 100644
--- a/test/form/samples/import-meta-url/_expected/system.js
+++ b/test/form/samples/import-meta-url/_expected/system.js
@@ -3,7 +3,15 @@ System.register([], function (exports, module) {
return {
execute: function () {
- console.log(module.meta.url);
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+ }
+
+ log(module.meta.url);
}
};
diff --git a/test/form/samples/import-meta-url/_expected/umd.js b/test/form/samples/import-meta-url/_expected/umd.js
index 6b3b6baa031..8ea4b1f845b 100644
--- a/test/form/samples/import-meta-url/_expected/umd.js
+++ b/test/form/samples/import-meta-url/_expected/umd.js
@@ -3,6 +3,14 @@
factory();
}(function () { 'use strict';
- console.log((typeof document !== 'undefined' ? document.currentScript && document.currentScript.src || document.baseURI : new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)('file:' + __filename).href));
+ function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+ }
+
+ log((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('umd.js', document.baseURI).href)));
}));
diff --git a/test/form/samples/import-meta-url/index-amd.html b/test/form/samples/import-meta-url/index-amd.html
new file mode 100644
index 00000000000..e89cb396ea2
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-amd.html
@@ -0,0 +1,10 @@
+
+
+
+
+ AMD
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-cjs.html b/test/form/samples/import-meta-url/index-cjs.html
new file mode 100644
index 00000000000..c5b18ec148f
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-cjs.html
@@ -0,0 +1,10 @@
+
+
+
+
+ CommonJS
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-es.html b/test/form/samples/import-meta-url/index-es.html
new file mode 100644
index 00000000000..5079fce53d8
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-es.html
@@ -0,0 +1,10 @@
+
+
+
+
+ ES Module
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-iife.html b/test/form/samples/import-meta-url/index-iife.html
new file mode 100644
index 00000000000..aaf475f1505
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-iife.html
@@ -0,0 +1,10 @@
+
+
+
+
+ IIFE
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-system.html b/test/form/samples/import-meta-url/index-system.html
new file mode 100644
index 00000000000..bef9897957b
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-system.html
@@ -0,0 +1,11 @@
+
+
+
+
+ SystemJS
+
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-umd-amd.html b/test/form/samples/import-meta-url/index-umd-amd.html
new file mode 100644
index 00000000000..e644ea36370
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-umd-amd.html
@@ -0,0 +1,10 @@
+
+
+
+
+ UMD (AMD)
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/index-umd-iife.html b/test/form/samples/import-meta-url/index-umd-iife.html
new file mode 100644
index 00000000000..202c1dad8f0
--- /dev/null
+++ b/test/form/samples/import-meta-url/index-umd-iife.html
@@ -0,0 +1,10 @@
+
+
+
+
+ UMD (IIFE)
+
+
+
+
+
diff --git a/test/form/samples/import-meta-url/main.js b/test/form/samples/import-meta-url/main.js
index 0c4061a00d3..9390079070b 100644
--- a/test/form/samples/import-meta-url/main.js
+++ b/test/form/samples/import-meta-url/main.js
@@ -1 +1,9 @@
-console.log(import.meta.url);
\ No newline at end of file
+function log(url) {
+ if (typeof document === 'undefined') {
+ console.log(url);
+ } else {
+ document.body.innerText = url;
+ }
+}
+
+log(import.meta.url);
diff --git a/test/function/samples/import-meta-url-compact/_config.js b/test/function/samples/import-meta-url-compact/_config.js
deleted file mode 100644
index bd433231ebe..00000000000
--- a/test/function/samples/import-meta-url-compact/_config.js
+++ /dev/null
@@ -1,18 +0,0 @@
-const assert = require('assert');
-const path = require('path');
-const URL = global.URL || require('url-parse');
-
-module.exports = {
- description: 'import.meta.url support',
- options: { output: { compact: true } },
- context: {
- __filename: path.resolve(__dirname, 'test.js'),
- require: name => {
- assert.equal(name, 'url');
- return { URL };
- }
- },
- exports(exports) {
- assert.equal(exports, new URL('file:' + path.resolve(__dirname, 'test.js')).href);
- }
-};
diff --git a/test/function/samples/import-meta-url-compact/main.js b/test/function/samples/import-meta-url-compact/main.js
deleted file mode 100644
index faad9bdcec9..00000000000
--- a/test/function/samples/import-meta-url-compact/main.js
+++ /dev/null
@@ -1 +0,0 @@
-export default import.meta.url;
\ No newline at end of file
diff --git a/test/function/samples/import-meta-url/_config.js b/test/function/samples/import-meta-url/_config.js
new file mode 100644
index 00000000000..93f48df9feb
--- /dev/null
+++ b/test/function/samples/import-meta-url/_config.js
@@ -0,0 +1,13 @@
+const path = require('path');
+const assert = require('assert');
+const URL = require('url').URL;
+
+module.exports = {
+ description: 'resolves import.meta.url',
+ context: {
+ __filename: path.resolve(__dirname, 'main.js')
+ },
+ exports(exports) {
+ assert.strictEqual(exports, new URL('file:' + path.resolve(__dirname, 'main.js')).href);
+ }
+};
diff --git a/test/function/samples/import-meta-url/main.js b/test/function/samples/import-meta-url/main.js
new file mode 100644
index 00000000000..37b3f8565ea
--- /dev/null
+++ b/test/function/samples/import-meta-url/main.js
@@ -0,0 +1 @@
+export default import.meta.url;