diff --git a/browser/error.ts b/browser/error.ts index c594d9bb8a9..bafb1eb19a7 100644 --- a/browser/error.ts +++ b/browser/error.ts @@ -1,9 +1,4 @@ -import { error } from '../src/utils/error'; +import { errNoFileSystemInBrowser, error } from '../src/utils/error'; -export const throwNoFileSystem = (method: string) => (): never => { - error({ - code: 'NO_FS_IN_BROWSER', - message: `Cannot access the file system (via "${method}") when using the browser build of Rollup. Make sure you supply a plugin with custom resolveId and load hooks to Rollup.`, - url: 'https://rollupjs.org/guide/en/#a-simple-example' - }); -}; +export const throwNoFileSystem = (method: string) => (): never => + error(errNoFileSystemInBrowser(method)); diff --git a/cli/logging.ts b/cli/logging.ts index 149b7355b19..9a319c27a61 100644 --- a/cli/logging.ts +++ b/cli/logging.ts @@ -7,9 +7,10 @@ import relativeId from '../src/utils/relativeId'; export const stderr = (...args: readonly unknown[]) => process.stderr.write(`${args.join('')}\n`); export function handleError(err: RollupError, recover = false): void { - let description = err.message || err; - if (err.name) description = `${err.name}: ${description}`; - const message = (err.plugin ? `(plugin ${err.plugin}) ${description}` : description) || err; + const name = err.name || err.cause?.name; + const nameSection = name ? `${name}: ` : ''; + const pluginSection = err.plugin ? `(plugin ${err.plugin}) ` : ''; + const message = `${pluginSection}${nameSection}${err.message}`; stderr(bold(red(`[!] ${bold(message.toString())}`))); diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index 2bc57688509..f1adcda6e49 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -31,7 +31,7 @@ export default function batchWarnings(): BatchWarnings { if (warning.url) info(warning.url); - const id = (warning.loc && warning.loc.file) || warning.id; + const id = warning.loc?.file || warning.id; if (id) { const loc = warning.loc ? `${relativeId(id)} (${warning.loc.line}:${warning.loc.column})` @@ -77,7 +77,7 @@ const immediateHandlers: { stderr( `Creating a browser bundle that depends on ${printQuotedStringList( - warning.modules! + warning.ids! )}. You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node` ); }, @@ -95,7 +95,7 @@ const deferredHandlers: { title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`); const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings; for (const warning of displayed) { - stderr(warning.cycle!.join(' -> ')); + stderr(warning.ids!.map(relativeId).join(' -> ')); } if (warnings.length > displayed.length) { stderr(`...and ${warnings.length - displayed.length} more`); @@ -108,7 +108,7 @@ const deferredHandlers: { warnings.length > 1 ? 'chunks' : 'chunk' }` ); - stderr(warnings.map(warning => warning.chunkName!).join(', ')); + stderr(printQuotedStringList(warnings.map(warning => warning.names![0]))); }, EVAL(warnings) { @@ -122,19 +122,20 @@ const deferredHandlers: { info('https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module'); for (const warning of warnings) { - stderr(bold(warning.importer!)); - stderr(`${warning.missing} is not exported by ${warning.exporter}`); + stderr(bold(relativeId(warning.id!))); + stderr(`${warning.binding} is not exported by ${relativeId(warning.exporter!)}`); stderr(gray(warning.frame!)); } }, MISSING_GLOBAL_NAME(warnings) { title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`); + info('https://rollupjs.org/guide/en/#outputglobals'); stderr( - `Use output.globals to specify browser global variable names corresponding to external modules` + `Use "output.globals" to specify browser global variable names corresponding to external modules:` ); for (const warning of warnings) { - stderr(`${bold(warning.source!)} (guessing '${warning.guess}')`); + stderr(`${bold(warning.id!)} (guessing "${warning.names![0]}")`); } }, @@ -151,7 +152,7 @@ const deferredHandlers: { stderr(`...and ${warnings.length - displayedWarnings.length} other entry modules`); } stderr( - `\nConsumers of your bundle will have to use chunk['default'] to access their default export, which may not be what you want. Use \`output.exports: 'named'\` to disable this warning` + `\nConsumers of your bundle will have to use chunk.default to access their default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.` ); }, @@ -160,19 +161,14 @@ const deferredHandlers: { for (const warning of warnings) { stderr( `"${bold(relativeId(warning.reexporter!))}" re-exports "${ - warning.name - }" from both "${relativeId(warning.sources![0])}" and "${relativeId( - warning.sources![1] - )}" (will be ignored)` + warning.binding + }" from both "${relativeId(warning.ids![0])}" and "${relativeId( + warning.ids![1] + )}" (will be ignored).` ); } }, - NON_EXISTENT_EXPORT(warnings) { - title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`); - showTruncatedWarnings(warnings); - }, - PLUGIN_WARNING(warnings) { const nestedByPlugin = nest(warnings, 'plugin'); @@ -208,12 +204,12 @@ const deferredHandlers: { stderr( `Plugins that transform code (such as ${printQuotedStringList( plugins - )}) should generate accompanying sourcemaps` + )}) should generate accompanying sourcemaps.` ); }, THIS_IS_UNDEFINED(warnings) { - title('`this` has been rewritten to `undefined`'); + title('"this" has been rewritten to "undefined"'); info('https://rollupjs.org/guide/en/#error-this-is-undefined'); showTruncatedWarnings(warnings); }, @@ -224,11 +220,13 @@ const deferredHandlers: { const dependencies = new Map(); for (const warning of warnings) { - getOrCreate(dependencies, warning.source, () => []).push(warning.importer!); + getOrCreate(dependencies, relativeId(warning.exporter!), () => []).push( + relativeId(warning.id!) + ); } for (const [dependency, importers] of dependencies) { - stderr(`${bold(dependency)} (imported by ${importers.join(', ')})`); + stderr(`${bold(dependency)} (imported by ${printQuotedStringList(importers)})`); } }, @@ -238,9 +236,10 @@ const deferredHandlers: { stderr( warning.names + ' imported from external module "' + - warning.source + + warning.exporter + '" but never used in ' + - printQuotedStringList(warning.sources!.map(id => relativeId(id))) + printQuotedStringList(warning.ids!.map(relativeId)) + + '.' ); } } diff --git a/cli/run/build.ts b/cli/run/build.ts index c3b94ea546a..1e2213b0090 100644 --- a/cli/run/build.ts +++ b/cli/run/build.ts @@ -3,6 +3,7 @@ import ms from 'pretty-ms'; import { rollup } from '../../src/node-entry'; import type { MergedRollupOptions } from '../../src/rollup/types'; import { bold, cyan, green } from '../../src/utils/colors'; +import { errOnlyInlineSourcemapsForStdout } from '../../src/utils/error'; import relativeId from '../../src/utils/relativeId'; import { SOURCEMAPPING_URL } from '../../src/utils/sourceMappingURL'; import { handleError, stderr } from '../logging'; @@ -34,10 +35,7 @@ export default async function build( if (useStdout) { const output = outputOptions[0]; if (output.sourcemap && output.sourcemap !== 'inline') { - handleError({ - code: 'ONLY_INLINE_SOURCEMAPS', - message: 'Only inline sourcemaps are supported when bundling to stdout.' - }); + handleError(errOnlyInlineSourcemapsForStdout()); } const { output: outputs } = await bundle.generate(output); diff --git a/cli/run/getConfigPath.ts b/cli/run/getConfigPath.ts index c9a29dba737..55ef7f2ca17 100644 --- a/cli/run/getConfigPath.ts +++ b/cli/run/getConfigPath.ts @@ -1,6 +1,7 @@ import { promises as fs } from 'fs'; import { resolve } from 'path'; import { cwd } from 'process'; +import { errMissingExternalConfig } from '../../src/utils/error'; import { handleError } from '../logging'; const DEFAULT_CONFIG_BASE = 'rollup.config'; @@ -18,10 +19,7 @@ export async function getConfigPath(commandConfig: string | true): Promise): Promise 0) { if (command.input) { - handleError({ - code: 'DUPLICATE_IMPORT_OPTIONS', - message: 'Either use --input, or pass input path as argument' - }); + handleError(errDuplicateImportOptions()); } inputSource = command._; } else if (typeof command.input === 'string') { @@ -67,10 +65,7 @@ export default async function runRollup(command: Record): Promise { 'Building Rollup produced warnings that need to be resolved. ' + 'Please keep in mind that the browser build may never have external dependencies!' ); - throw new Error(warning.message); + throw Object.assign(new Error(), warning); }; const moduleAliases = { diff --git a/src/Chunk.ts b/src/Chunk.ts index 323a05bebd2..8aba399e993 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -30,6 +30,8 @@ import { createAddons } from './utils/addons'; import { deconflictChunk, type DependenciesToBeDeconflicted } from './utils/deconflictChunk'; import { errCyclicCrossChunkReexport, + errEmptyChunk, + errMissingGlobalName, error, errUnexpectedNamedImport, errUnexpectedNamespaceReexport @@ -137,12 +139,7 @@ function getGlobalName( } if (hasExports) { - warn({ - code: 'MISSING_GLOBAL_NAME', - guess: chunk.variableName, - message: `No name was provided for external module '${chunk.id}' in output.globals – guessing '${chunk.variableName}'`, - source: chunk.id - }); + warn(errMissingGlobalName(chunk.id, chunk.variableName)); return chunk.variableName; } } @@ -1147,12 +1144,7 @@ export default class Chunk { const renderedSource = compact ? magicString : magicString.trim(); if (isEmpty && this.getExportNames().length === 0 && dependencies.size === 0) { - const chunkName = this.getChunkName(); - onwarn({ - chunkName, - code: 'EMPTY_BUNDLE', - message: `Generated an empty chunk: "${chunkName}"` - }); + onwarn(errEmptyChunk(this.getChunkName())); } return { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait }; } diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index d2157cbcde4..b80a1aac79a 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -1,10 +1,8 @@ import ExternalVariable from './ast/variables/ExternalVariable'; import type { CustomPluginOptions, ModuleInfo, NormalizedInputOptions } from './rollup/types'; import { EMPTY_ARRAY } from './utils/blank'; -import { warnDeprecation } from './utils/error'; +import { errUnusedExternalImports, warnDeprecation } from './utils/error'; import { makeLegal } from './utils/identifierHelpers'; -import { printQuotedStringList } from './utils/printStringList'; -import relativeId from './utils/relativeId'; export default class ExternalModule { readonly dynamicImporters: string[] = []; @@ -105,16 +103,6 @@ export default class ExternalModule { } } const importersArray = [...importersSet]; - this.options.onwarn({ - code: 'UNUSED_EXTERNAL_IMPORT', - message: `${printQuotedStringList(unused, ['is', 'are'])} imported from external module "${ - this.id - }" but never used in ${printQuotedStringList( - importersArray.map(importer => relativeId(importer)) - )}.`, - names: unused, - source: this.id, - sources: importersArray - }); + this.options.onwarn(errUnusedExternalImports(this.id, unused, importersArray)); } } diff --git a/src/Graph.ts b/src/Graph.ts index 65505ccf738..eda8e66e2dd 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -16,10 +16,14 @@ import type { import { PluginDriver } from './utils/PluginDriver'; import Queue from './utils/Queue'; import { BuildPhase } from './utils/buildPhase'; -import { errImplicitDependantIsNotIncluded, error } from './utils/error'; +import { + errCircularDependency, + errImplicitDependantIsNotIncluded, + errMissingExport, + error +} from './utils/error'; import { analyseModuleExecution } from './utils/executionOrder'; import { addAnnotations } from './utils/pureComments'; -import relativeId from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import { markModuleAndImpureDependenciesAsExecuted } from './utils/traverseStaticDependencies'; @@ -223,12 +227,7 @@ export default class Graph { private sortModules(): void { const { orderedModules, cyclePaths } = analyseModuleExecution(this.entryModules); for (const cyclePath of cyclePaths) { - this.options.onwarn({ - code: 'CIRCULAR_DEPENDENCY', - cycle: cyclePath, - importer: cyclePath[0], - message: `Circular dependency: ${cyclePath.join(' -> ')}` - }); + this.options.onwarn(errCircularDependency(cyclePath)); } this.modules = orderedModules; for (const module of this.modules) { @@ -245,14 +244,7 @@ export default class Graph { !importDescription.module.getVariableForExportName(importDescription.name)[0] ) { module.warn( - { - code: 'NON_EXISTENT_EXPORT', - message: `Non-existent export '${ - importDescription.name - }' is imported from ${relativeId(importDescription.module.id)}`, - name: importDescription.name, - source: importDescription.module.id - }, + errMissingExport(importDescription.name, module.id, importDescription.module.id), importDescription.start ); } diff --git a/src/Module.ts b/src/Module.ts index bd6280fcdcd..12da5bbdd11 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -41,7 +41,7 @@ import type { ResolvedId, ResolvedIdMap, RollupError, - RollupLogProps, + RollupLog, RollupWarning, TransformModuleJSON } from './rollup/types'; @@ -52,9 +52,12 @@ import { errAmbiguousExternalNamespaces, errCircularReexport, errInvalidFormatForTopLevelAwait, + errInvalidSourcemapForError, errMissingExport, errNamespaceConflict, error, + errParseError, + errShimmedExport, errSyntheticNamedExportsNeedNamespaceExport, warnDeprecation } from './utils/error'; @@ -63,7 +66,6 @@ import { getOrCreate } from './utils/getOrCreate'; import { getOriginalLocation } from './utils/getOriginalLocation'; import { makeLegal } from './utils/identifierHelpers'; import { basename, extname } from './utils/path'; -import relativeId from './utils/relativeId'; import type { RenderOptions } from './utils/renderHelpers'; import { timeEnd, timeStart } from './utils/timers'; import { markModuleAndImpureDependenciesAsExecuted } from './utils/traverseStaticDependencies'; @@ -97,7 +99,7 @@ export interface AstContext { addImportMeta: (node: MetaProperty) => void; code: string; deoptimizationTracker: PathTracker; - error: (props: RollupError, pos: number) => never; + error: (props: RollupLog, pos: number) => never; fileName: string; getExports: () => string[]; getModuleExecIndex: () => number; @@ -849,20 +851,7 @@ export default class Module { try { return this.graph.contextParse(this.info.code!); } catch (err: any) { - let message = err.message.replace(/ \(\d+:\d+\)$/, ''); - if (this.id.endsWith('.json')) { - message += ' (Note that you need @rollup/plugin-json to import JSON files)'; - } else if (!this.id.endsWith('.js')) { - message += ' (Note that you need plugins to import files that are not JavaScript)'; - } - return this.error( - { - code: 'PARSE_ERROR', - message, - parserError: err - }, - err.pos - ); + return this.error(errParseError(err, this.id), err.pos); } } @@ -990,7 +979,7 @@ export default class Module { this.importMetas.push(node); } - private addLocationToLogProps(props: RollupLogProps, pos: number): void { + private addLocationToLogProps(props: RollupLog, pos: number): void { props.id = this.id; props.pos = pos; let code = this.info.code; @@ -1001,17 +990,7 @@ export default class Module { ({ column, line } = getOriginalLocation(this.sourcemapChain, { column, line })); code = this.originalCode; } catch (err: any) { - this.options.onwarn({ - code: 'SOURCEMAP_ERROR', - id: this.id, - loc: { - column, - file: this.id, - line - }, - message: `Error when using sourcemap for reporting an error: ${err.message}`, - pos - }); + this.options.onwarn(errInvalidSourcemapForError(err, this.id, column, line, pos)); } augmentCodeLocation(props, { column, line }, code!, this.id); } @@ -1191,12 +1170,7 @@ export default class Module { } private shimMissingExport(name: string): void { - this.options.onwarn({ - code: 'SHIMMED_EXPORT', - exporter: relativeId(this.id), - exportName: name, - message: `Missing export "${name}" has been shimmed in module ${relativeId(this.id)}.` - }); + this.options.onwarn(errShimmedExport(this.id, name)); this.exports.set(name, MISSING_EXPORT_SHIM_DESCRIPTION); } } diff --git a/src/ast/nodes/CallExpression.ts b/src/ast/nodes/CallExpression.ts index b4f0b1f45f5..a4b743cccb4 100644 --- a/src/ast/nodes/CallExpression.ts +++ b/src/ast/nodes/CallExpression.ts @@ -1,6 +1,7 @@ import type MagicString from 'magic-string'; import type { NormalizedTreeshakingOptions } from '../../rollup/types'; import { BLANK } from '../../utils/blank'; +import { errCannotCallNamespace, errEval } from '../../utils/error'; import { renderCallArguments } from '../../utils/renderCallArguments'; import { type NodeRenderOptions, type RenderOptions } from '../../utils/renderHelpers'; import type { DeoptimizableEntity } from '../DeoptimizableEntity'; @@ -33,24 +34,11 @@ export default class CallExpression extends CallExpressionBase implements Deopti const variable = this.scope.findVariable(this.callee.name); if (variable.isNamespace) { - this.context.warn( - { - code: 'CANNOT_CALL_NAMESPACE', - message: `Cannot call a namespace ('${this.callee.name}')` - }, - this.start - ); + this.context.warn(errCannotCallNamespace(this.callee.name), this.start); } if (this.callee.name === 'eval') { - this.context.warn( - { - code: 'EVAL', - message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`, - url: 'https://rollupjs.org/guide/en/#avoiding-eval' - }, - this.start - ); + this.context.warn(errEval(this.context.module.id), this.start); } } this.interaction = { diff --git a/src/ast/nodes/ExpressionStatement.ts b/src/ast/nodes/ExpressionStatement.ts index e6dc4d6bf67..6bf4373658d 100644 --- a/src/ast/nodes/ExpressionStatement.ts +++ b/src/ast/nodes/ExpressionStatement.ts @@ -1,4 +1,5 @@ import type MagicString from 'magic-string'; +import { errModuleLevelDirective } from '../../utils/error'; import type { RenderOptions } from '../../utils/renderHelpers'; import type { InclusionContext } from '../ExecutionContext'; import * as NodeType from './NodeType'; @@ -16,10 +17,7 @@ export default class ExpressionStatement extends StatementBase { ) { this.context.warn( // This is necessary, because either way (deleting or not) can lead to errors. - { - code: 'MODULE_LEVEL_DIRECTIVE', - message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.` - }, + errModuleLevelDirective(this.directive, this.context.module.id), this.start ); } diff --git a/src/ast/nodes/Identifier.ts b/src/ast/nodes/Identifier.ts index b4ddde25c0f..e5ef84be3d5 100644 --- a/src/ast/nodes/Identifier.ts +++ b/src/ast/nodes/Identifier.ts @@ -2,6 +2,7 @@ import isReference, { type NodeWithFieldDefinition } from 'is-reference'; import type MagicString from 'magic-string'; import type { NormalizedTreeshakingOptions } from '../../rollup/types'; import { BLANK } from '../../utils/blank'; +import { errIllegalImportReassignment } from '../../utils/error'; import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import type { DeoptimizableEntity } from '../DeoptimizableEntity'; import type { HasEffectsContext, InclusionContext } from '../ExecutionContext'; @@ -265,10 +266,7 @@ export default class Identifier extends NodeBase implements PatternNode { private disallowImportReassignment(): never { return this.context.error( - { - code: 'ILLEGAL_REASSIGNMENT', - message: `Illegal reassignment to import '${this.name}'` - }, + errIllegalImportReassignment(this.name, this.context.module.id), this.start ); } diff --git a/src/ast/nodes/MemberExpression.ts b/src/ast/nodes/MemberExpression.ts index 93922eb0e2c..cf525fe17a5 100644 --- a/src/ast/nodes/MemberExpression.ts +++ b/src/ast/nodes/MemberExpression.ts @@ -2,7 +2,7 @@ import type MagicString from 'magic-string'; import { AstContext } from '../../Module'; import type { NormalizedTreeshakingOptions } from '../../rollup/types'; import { BLANK } from '../../utils/blank'; -import relativeId from '../../utils/relativeId'; +import { errIllegalImportReassignment, errMissingExport } from '../../utils/error'; import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import type { DeoptimizableEntity } from '../DeoptimizableEntity'; import type { HasEffectsContext, InclusionContext } from '../ExecutionContext'; @@ -380,10 +380,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE this.context.includeVariableInModule(this.variable); } this.context.warn( - { - code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', - message: `Illegal reassignment to import '${this.object.name}'` - }, + errIllegalImportReassignment(this.object.name, this.context.module.id), this.start ); } @@ -440,17 +437,7 @@ function resolveNamespaceVariables( const variable = (baseVariable as NamespaceVariable).context.traceExport(exportName); if (!variable) { const fileName = (baseVariable as NamespaceVariable).context.fileName; - astContext.warn( - { - code: 'MISSING_EXPORT', - exporter: relativeId(fileName), - importer: relativeId(astContext.fileName), - message: `'${exportName}' is not exported by '${relativeId(fileName)}'`, - missing: exportName, - url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` - }, - path[0].pos - ); + astContext.warn(errMissingExport(exportName, astContext.module.id, fileName), path[0].pos); return 'undefined'; } return resolveNamespaceVariables(variable, path.slice(1), astContext); diff --git a/src/ast/nodes/TaggedTemplateExpression.ts b/src/ast/nodes/TaggedTemplateExpression.ts index 10a7dfda304..9cebc62edc9 100644 --- a/src/ast/nodes/TaggedTemplateExpression.ts +++ b/src/ast/nodes/TaggedTemplateExpression.ts @@ -1,4 +1,5 @@ import type MagicString from 'magic-string'; +import { errCannotCallNamespace } from '../../utils/error'; import { type RenderOptions } from '../../utils/renderHelpers'; import type { HasEffectsContext } from '../ExecutionContext'; import { InclusionContext } from '../ExecutionContext'; @@ -29,13 +30,7 @@ export default class TaggedTemplateExpression extends CallExpressionBase { const variable = this.scope.findVariable(name); if (variable.isNamespace) { - this.context.warn( - { - code: 'CANNOT_CALL_NAMESPACE', - message: `Cannot call a namespace ('${name}')` - }, - this.start - ); + this.context.warn(errCannotCallNamespace(name), this.start); } } } diff --git a/src/ast/nodes/ThisExpression.ts b/src/ast/nodes/ThisExpression.ts index 0ae54d12be1..7f34b6264e1 100644 --- a/src/ast/nodes/ThisExpression.ts +++ b/src/ast/nodes/ThisExpression.ts @@ -1,4 +1,5 @@ import type MagicString from 'magic-string'; +import { errThisIsUndefined } from '../../utils/error'; import type { HasEffectsContext } from '../ExecutionContext'; import type { NodeInteraction, NodeInteractionWithThisArg } from '../NodeInteractions'; import { INTERACTION_ACCESSED } from '../NodeInteractions'; @@ -56,14 +57,7 @@ export default class ThisExpression extends NodeBase { this.alias = this.scope.findLexicalBoundary() instanceof ModuleScope ? this.context.moduleContext : null; if (this.alias === 'undefined') { - this.context.warn( - { - code: 'THIS_IS_UNDEFINED', - message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`, - url: `https://rollupjs.org/guide/en/#error-this-is-undefined` - }, - this.start - ); + this.context.warn(errThisIsUndefined(), this.start); } } diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index cd425f1268f..ec011dfd80f 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -1,6 +1,10 @@ import type { Bundle as MagicStringBundle } from 'magic-string'; import type { NormalizedOutputOptions } from '../rollup/types'; -import { error } from '../utils/error'; +import { + errIllegalIdentifierAsName, + errMissingNameOptionForIifeExport, + error +} from '../utils/error'; import { isLegal } from '../utils/identifierHelpers'; import { getExportBlock, getNamespaceMarkers } from './shared/getExportBlock'; import getInteropBlock from './shared/getInteropBlock'; @@ -42,10 +46,7 @@ export default function iife( const useVariableAssignment = !extend && !isNamespaced; if (name && useVariableAssignment && !isLegal(name)) { - return error({ - code: 'ILLEGAL_IDENTIFIER_AS_NAME', - message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".` - }); + return error(errIllegalIdentifierAsName(name)); } warnOnBuiltins(onwarn, dependencies); @@ -55,10 +56,7 @@ export default function iife( const args = external.map(m => m.name); if (hasExports && !name) { - onwarn({ - code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', - message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.` - }); + onwarn(errMissingNameOptionForIifeExport()); } if (namedExportsMode && hasExports) { diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index dd8b0655bb0..5cbb0b94da2 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -1,6 +1,6 @@ import { ChunkDependency } from '../../Chunk'; import type { RollupWarning } from '../../rollup/types'; -import { printQuotedStringList } from '../../utils/printStringList'; +import { errMissingNodeBuiltins } from '../../utils/error'; const builtins = { assert: true, @@ -36,11 +36,5 @@ export default function warnOnBuiltins( if (!externalBuiltins.length) return; - warn({ - code: 'MISSING_NODE_BUILTINS', - message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList( - externalBuiltins - )}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`, - modules: externalBuiltins - }); + warn(errMissingNodeBuiltins(externalBuiltins)); } diff --git a/src/finalisers/umd.ts b/src/finalisers/umd.ts index 1be32dc5651..b4a886d6e1a 100644 --- a/src/finalisers/umd.ts +++ b/src/finalisers/umd.ts @@ -1,6 +1,6 @@ import type { Bundle as MagicStringBundle } from 'magic-string'; import type { NormalizedOutputOptions } from '../rollup/types'; -import { error } from '../utils/error'; +import { errMissingNameOptionForUmdExport, error } from '../utils/error'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import getCompleteAmdId from './shared/getCompleteAmdId'; import { getExportBlock, getNamespaceMarkers } from './shared/getExportBlock'; @@ -68,11 +68,7 @@ export default function umd( const globalVar = compact ? 'g' : 'global'; if (hasExports && !name) { - return error({ - code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', - message: - 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.' - }); + return error(errMissingNameOptionForUmdExport()); } warnOnBuiltins(onwarn, dependencies); diff --git a/src/rollup/rollup.ts b/src/rollup/rollup.ts index 36532b21ff6..bf71ce3ddbe 100644 --- a/src/rollup/rollup.ts +++ b/src/rollup/rollup.ts @@ -4,7 +4,12 @@ import Graph from '../Graph'; import type { PluginDriver } from '../utils/PluginDriver'; import { getSortedValidatedPlugins } from '../utils/PluginDriver'; import { ensureArray } from '../utils/ensureArray'; -import { errAlreadyClosed, errCannotEmitFromOptionsHook, error } from '../utils/error'; +import { + errAlreadyClosed, + errCannotEmitFromOptionsHook, + errMissingFileOrDirOption, + error +} from '../utils/error'; import { promises as fs } from '../utils/fs'; import { catchUnfinishedHookActions } from '../utils/hookActions'; import { normalizeInputOptions } from '../utils/options/normalizeInputOptions'; @@ -173,10 +178,7 @@ function handleGenerateWrite( if (isWrite) { timeStart('WRITE', 1); if (!outputOptions.dir && !outputOptions.file) { - return error({ - code: 'MISSING_OPTION', - message: 'You must specify "output.file" or "output.dir" for the build.' - }); + return error(errMissingFileOrDirOption()); } await Promise.all( Object.values(generated).map(chunk => diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index e9e8aa8b92c..2600129111f 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -1,41 +1,33 @@ export const VERSION: string; -export interface RollupError extends RollupLogProps { - parserError?: Error; +export interface RollupError extends RollupLog { + name?: string; stack?: string; watchFiles?: string[]; } -export interface RollupWarning extends RollupLogProps { - chunkName?: string; - cycle?: string[]; - exportName?: string; - exporter?: string; - guess?: string; - importer?: string; - missing?: string; - modules?: string[]; - names?: string[]; - reexporter?: string; - source?: string; - sources?: string[]; -} +export type RollupWarning = RollupLog; -export interface RollupLogProps { +export interface RollupLog { + binding?: string; + cause?: Error; code?: string; + exporter?: string; frame?: string; hook?: string; id?: string; + ids?: string[]; loc?: { column: number; file?: string; line: number; }; message: string; - name?: string; + names?: string[]; plugin?: string; pluginCode?: string; pos?: number; + reexporter?: string; url?: string; } diff --git a/src/utils/PluginCache.ts b/src/utils/PluginCache.ts index 65e3fb90d45..88127c55c8c 100644 --- a/src/utils/PluginCache.ts +++ b/src/utils/PluginCache.ts @@ -1,5 +1,5 @@ import type { PluginCache, SerializablePluginCache } from '../rollup/types'; -import { error } from './error'; +import { errAnonymousPluginCache, errDuplicatePluginName, error } from './error'; import { ANONYMOUS_OUTPUT_PLUGIN_PREFIX, ANONYMOUS_PLUGIN_PREFIX } from './pluginUtils'; export function createPluginCache(cache: SerializablePluginCache): PluginCache { @@ -64,16 +64,9 @@ function uncacheablePluginError(pluginName: string): never { pluginName.startsWith(ANONYMOUS_PLUGIN_PREFIX) || pluginName.startsWith(ANONYMOUS_OUTPUT_PLUGIN_PREFIX) ) { - return error({ - code: 'ANONYMOUS_PLUGIN_CACHE', - message: - 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.' - }); + return error(errAnonymousPluginCache()); } - return error({ - code: 'DUPLICATE_PLUGIN_NAME', - message: `The plugin name ${pluginName} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).` - }); + return error(errDuplicatePluginName(pluginName)); } export function getCacheForUncacheablePlugin(pluginName: string): PluginCache { diff --git a/src/utils/PluginContext.ts b/src/utils/PluginContext.ts index 11b1073ecbe..8a871c4e734 100644 --- a/src/utils/PluginContext.ts +++ b/src/utils/PluginContext.ts @@ -11,12 +11,13 @@ import type { FileEmitter } from './FileEmitter'; import { createPluginCache, getCacheForUncacheablePlugin, NO_CACHE } from './PluginCache'; import { BLANK } from './blank'; import { BuildPhase } from './buildPhase'; -import { errInvalidRollupPhaseForAddWatchFile, warnDeprecation } from './error'; import { - ANONYMOUS_OUTPUT_PLUGIN_PREFIX, - ANONYMOUS_PLUGIN_PREFIX, - throwPluginError -} from './pluginUtils'; + errInvalidRollupPhaseForAddWatchFile, + error, + errPluginError, + warnDeprecation +} from './error'; +import { ANONYMOUS_OUTPUT_PLUGIN_PREFIX, ANONYMOUS_PLUGIN_PREFIX } from './pluginUtils'; export function getPluginContext( plugin: Plugin, @@ -61,7 +62,7 @@ export function getPluginContext( cache: cacheInstance, emitFile: fileEmitter.emitFile.bind(fileEmitter), error(err): never { - return throwPluginError(err, plugin.name); + return error(errPluginError(err, plugin.name)); }, getFileName: fileEmitter.getFileName, getModuleIds: () => graph.modulesById.keys(), diff --git a/src/utils/PluginDriver.ts b/src/utils/PluginDriver.ts index c42fe9e461d..7df2037e740 100644 --- a/src/utils/PluginDriver.ts +++ b/src/utils/PluginDriver.ts @@ -24,11 +24,11 @@ import { errInputHookInOutputPlugin, errInvalidAddonPluginHook, errInvalidFunctionPluginHook, - error + error, + errPluginError } from './error'; import { getOrCreate } from './getOrCreate'; import { OutputBundleWithPlaceholders } from './outputBundle'; -import { throwPluginError } from './pluginUtils'; /** * Coerce a promise union to always be a promise. @@ -350,7 +350,7 @@ export class PluginDriver { // action considered to be fulfilled since error being handled this.unfulfilledActions.delete(action); } - return throwPluginError(err, plugin.name, { hook: hookName }); + return error(errPluginError(err, plugin.name, { hook: hookName })); }); } @@ -379,7 +379,7 @@ export class PluginDriver { // eslint-disable-next-line @typescript-eslint/ban-types return (handler as Function).apply(context, args); } catch (err: any) { - return throwPluginError(err, plugin.name, { hook: hookName }); + return error(errPluginError(err, plugin.name, { hook: hookName })); } } } diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index e4c87734cd1..7d5170f770a 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -6,7 +6,7 @@ import type { SourceMapSegment, WarningHandler } from '../rollup/types'; -import { error } from './error'; +import { error, errSourcemapBroken } from './error'; import { basename, dirname, relative, resolve } from './path'; class Source { @@ -155,15 +155,7 @@ function getLinkMap(warn: WarningHandler) { return new Link(map, [source]); } - warn({ - code: 'SOURCEMAP_BROKEN', - message: - `Sourcemap is likely to be incorrect: a plugin (${map.plugin}) was used to transform ` + - "files, but didn't generate a sourcemap for the transformation. Consult the plugin " + - 'documentation for help', - plugin: map.plugin, - url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect` - }); + warn(errSourcemapBroken(map.plugin)); return new Link( { diff --git a/src/utils/error.ts b/src/utils/error.ts index 9fa88ce3fdf..e20ecb63eac 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -3,8 +3,7 @@ import type Module from '../Module'; import type { InternalModuleFormat, NormalizedInputOptions, - RollupError, - RollupLogProps, + RollupLog, RollupWarning, WarningHandler } from '../rollup/types'; @@ -12,13 +11,16 @@ import getCodeFrame from './getCodeFrame'; import { printQuotedStringList } from './printStringList'; import relativeId from './relativeId'; -export function error(base: Error | RollupError): never { - if (!(base instanceof Error)) base = Object.assign(new Error(base.message), base); +export function error(base: Error | RollupLog): never { + if (!(base instanceof Error)) { + base = Object.assign(new Error(base.message), base); + Object.defineProperty(base, 'name', { value: 'RollupError' }); + } throw base; } export function augmentCodeLocation( - props: RollupLogProps, + props: RollupLog, pos: number | { column: number; line: number }, source: string, id: string @@ -38,23 +40,35 @@ export function augmentCodeLocation( } } -export const enum Errors { - ADDON_ERROR = 'ADDON_ERROR', +// Error codes should be sorted alphabetically while errors should be sorted by +// error code below +const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', + AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', + ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', + CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', + CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', + DUPLICATE_IMPORT_OPTIONS = 'DUPLICATE_IMPORT_OPTIONS', + DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', + EMPTY_BUNDLE = 'EMPTY_BUNDLE', + EVAL = 'EVAL', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', + FAIL_AFTER_WARNINGS = 'FAIL_AFTER_WARNINGS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', + ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', + ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', @@ -62,51 +76,134 @@ export const enum Errors { INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', + INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', + MISSING_CONFIG = 'MISSING_CONFIG', MISSING_EXPORT = 'MISSING_EXPORT', + MISSING_EXTERNAL_CONFIG = 'MISSING_EXTERNAL_CONFIG', + MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', + MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', + MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', + MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', + MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', - AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', + NO_FS_IN_BROWSER = 'NO_FS_IN_BROWSER', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', + ONLY_INLINE_SOURCEMAPS = 'ONLY_INLINE_SOURCEMAPS', + PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', PREFER_NAMED_EXPORTS = 'PREFER_NAMED_EXPORTS', + SHIMMED_EXPORT = 'SHIMMED_EXPORT', + SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', + SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', + THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', + TRANSPILED_ESM_CONFIG = 'TRANSPILED_ESM_CONFIG', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', + UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', - VALIDATION_ERROR = 'VALIDATION_ERROR' -} + UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', + VALIDATION_ERROR = 'VALIDATION_ERROR'; -export function errAddonNotGenerated( - message: string, - hook: string, - plugin: string -): RollupLogProps { +export function errAddonNotGenerated(message: string, hook: string, plugin: string): RollupLog { return { - code: Errors.ADDON_ERROR, - message: `Could not retrieve ${hook}. Check configuration of plugin ${plugin}. + code: ADDON_ERROR, + message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}". \tError Message: ${message}` }; } -export function errAssetNotFinalisedForFileName(name: string): RollupLogProps { +export function errAlreadyClosed(): RollupLog { return { - code: Errors.ASSET_NOT_FINALISED, + code: ALREADY_CLOSED, + message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.' + }; +} + +export function errAmbiguousExternalNamespaces( + binding: string, + reexportingModule: string, + usedModule: string, + sources: string[] +): RollupLog { + return { + binding, + code: AMBIGUOUS_EXTERNAL_NAMESPACES, + ids: sources, + message: `Ambiguous external namespace resolution: "${relativeId( + reexportingModule + )}" re-exports "${binding}" from one of the external modules ${printQuotedStringList( + sources.map(module => relativeId(module)) + )}, guessing "${relativeId(usedModule)}".`, + reexporter: reexportingModule + }; +} + +export function errAnonymousPluginCache(): RollupLog { + return { + code: ANONYMOUS_PLUGIN_CACHE, + message: + 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.' + }; +} + +export function errAssetNotFinalisedForFileName(name: string): RollupLog { + return { + code: ASSET_NOT_FINALISED, message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.` }; } -export function errCannotEmitFromOptionsHook(): RollupLogProps { +export function errAssetReferenceIdNotFoundForSetSource(assetReferenceId: string): RollupLog { + return { + code: ASSET_NOT_FOUND, + message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".` + }; +} + +export function errAssetSourceAlreadySet(name: string): RollupLog { + return { + code: ASSET_SOURCE_ALREADY_SET, + message: `Unable to set the source for asset "${name}", source already set.` + }; +} + +export function errNoAssetSourceSet(assetName: string): RollupLog { + return { + code: ASSET_SOURCE_MISSING, + message: `Plugin error creating asset "${assetName}" - no asset source set.` + }; +} + +export function errBadLoader(id: string): RollupLog { + return { + code: BAD_LOADER, + message: `Error loading "${relativeId( + id + )}": plugin load hook should return a string, a { code, map } object, or nothing/null.` + }; +} + +export function errCannotCallNamespace(name: string): RollupLog { + return { + code: CANNOT_CALL_NAMESPACE, + message: `Cannot call a namespace ("${name}").` + }; +} + +export function errCannotEmitFromOptionsHook(): RollupLog { return { - code: Errors.CANNOT_EMIT_FROM_OPTIONS_HOOK, + code: CANNOT_EMIT_FROM_OPTIONS_HOOK, message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.` }; } -export function errChunkNotGeneratedForFileName(name: string): RollupLogProps { +export function errChunkNotGeneratedForFileName(name: string): RollupLog { return { - code: Errors.CHUNK_NOT_GENERATED, + code: CHUNK_NOT_GENERATED, message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.` }; } @@ -114,22 +211,30 @@ export function errChunkNotGeneratedForFileName(name: string): RollupLogProps { export function errChunkInvalid( { fileName, code }: { code: string; fileName: string }, exception: { loc: { column: number; line: number }; message: string } -): RollupLogProps { +): RollupLog { const errorProps = { - code: Errors.CHUNK_INVALID, + code: CHUNK_INVALID, message: `Chunk "${fileName}" is not valid JavaScript: ${exception.message}.` }; augmentCodeLocation(errorProps, exception.loc, code, fileName); return errorProps; } -export function errCircularReexport(exportName: string, importedModule: string): RollupLogProps { +export function errCircularDependency(cyclePath: string[]): RollupLog { + return { + code: CIRCULAR_DEPENDENCY, + ids: cyclePath, + message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}` + }; +} + +export function errCircularReexport(exportName: string, exporter: string): RollupLog { return { - code: Errors.CIRCULAR_REEXPORT, - id: importedModule, - message: `"${exportName}" cannot be exported from ${relativeId( - importedModule - )} as it is a reexport that references itself.` + code: CIRCULAR_REEXPORT, + exporter, + message: `"${exportName}" cannot be exported from "${relativeId( + exporter + )}" as it is a reexport that references itself.` }; } @@ -138,76 +243,111 @@ export function errCyclicCrossChunkReexport( exporter: string, reexporter: string, importer: string -): RollupWarning { +): RollupLog { return { - code: Errors.CYCLIC_CROSS_CHUNK_REEXPORT, + code: CYCLIC_CROSS_CHUNK_REEXPORT, exporter, - importer, - message: `Export "${exportName}" of module ${relativeId( + id: importer, + message: `Export "${exportName}" of module "${relativeId( exporter - )} was reexported through module ${relativeId( + )}" was reexported through module "${relativeId( reexporter - )} while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in ${relativeId( + )}" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "${relativeId( importer - )} to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`, + )}" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.`, reexporter }; } -export function errAssetReferenceIdNotFoundForSetSource(assetReferenceId: string): RollupLogProps { +export function errDeprecation(deprecation: string | RollupWarning): RollupLog { return { - code: Errors.ASSET_NOT_FOUND, - message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".` + code: DEPRECATED_FEATURE, + ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation) }; } -export function errAssetSourceAlreadySet(name: string): RollupLogProps { +export function errDuplicateImportOptions(): RollupLog { return { - code: Errors.ASSET_SOURCE_ALREADY_SET, - message: `Unable to set the source for asset "${name}", source already set.` + code: DUPLICATE_IMPORT_OPTIONS, + message: 'Either use --input, or pass input path as argument' }; } -export function errNoAssetSourceSet(assetName: string): RollupLogProps { +export function errDuplicatePluginName(plugin: string): RollupLog { return { - code: Errors.ASSET_SOURCE_MISSING, - message: `Plugin error creating asset "${assetName}" - no asset source set.` + code: DUPLICATE_PLUGIN_NAME, + message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).` }; } -export function errBadLoader(id: string): RollupLogProps { +export function errEmptyChunk(chunkName: string): RollupLog { return { - code: Errors.BAD_LOADER, - message: `Error loading ${relativeId( + code: EMPTY_BUNDLE, + message: `Generated an empty chunk: "${chunkName}".`, + names: [chunkName] + }; +} + +export function errEval(id: string): RollupLog { + return { + code: EVAL, + id, + message: `Use of eval in "${relativeId( id - )}: plugin load hook should return a string, a { code, map } object, or nothing/null` + )}" is strongly discouraged as it poses security risks and may cause issues with minification.`, + url: 'https://rollupjs.org/guide/en/#avoiding-eval' }; } -export function errDeprecation(deprecation: string | RollupWarning): RollupLogProps { +export function errExternalSyntheticExports(id: string, importer: string): RollupLog { return { - code: Errors.DEPRECATED_FEATURE, - ...(typeof deprecation === 'string' ? { message: deprecation } : deprecation) + code: EXTERNAL_SYNTHETIC_EXPORTS, + exporter: id, + message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId( + importer + )}").` }; } -export function errFileReferenceIdNotFoundForFilename(assetReferenceId: string): RollupLogProps { +export function errFailAfterWarnings(): RollupLog { return { - code: Errors.FILE_NOT_FOUND, - message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".` + code: FAIL_AFTER_WARNINGS, + message: 'Warnings occurred and --failAfterWarnings flag present.' }; } -export function errFileNameConflict(fileName: string): RollupLogProps { +export function errFileNameConflict(fileName: string): RollupLog { return { - code: Errors.FILE_NAME_CONFLICT, + code: FILE_NAME_CONFLICT, message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.` }; } -export function errInputHookInOutputPlugin(pluginName: string, hookName: string): RollupLogProps { +export function errFileReferenceIdNotFoundForFilename(assetReferenceId: string): RollupLog { return { - code: Errors.INPUT_HOOK_IN_OUTPUT_PLUGIN, + code: FILE_NOT_FOUND, + message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".` + }; +} + +export function errIllegalIdentifierAsName(name: string): RollupLog { + return { + code: ILLEGAL_IDENTIFIER_AS_NAME, + message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`, + url: 'https://rollupjs.org/guide/en/#outputextend' + }; +} + +export function errIllegalImportReassignment(name: string, importingId: string): RollupLog { + return { + code: ILLEGAL_REASSIGNMENT, + message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".` + }; +} + +export function errInputHookInOutputPlugin(pluginName: string, hookName: string): RollupLog { + return { + code: INPUT_HOOK_IN_OUTPUT_PLUGIN, message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.` }; } @@ -216,19 +356,19 @@ export function errCannotAssignModuleToChunk( moduleId: string, assignToAlias: string, currentAlias: string -): RollupLogProps { +): RollupLog { return { - code: Errors.INVALID_CHUNK, - message: `Cannot assign ${relativeId( + code: INVALID_CHUNK, + message: `Cannot assign "${relativeId( moduleId - )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` + )}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` }; } -export function errInvalidExportOptionValue(optionValue: string): RollupLogProps { +export function errInvalidExportOptionValue(optionValue: string): RollupLog { return { - code: Errors.INVALID_EXPORT_OPTION, - message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}"`, + code: INVALID_EXPORT_OPTION, + message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`, url: `https://rollupjs.org/guide/en/#outputexports` }; } @@ -237,21 +377,22 @@ export function errIncompatibleExportOptionValue( optionValue: string, keys: readonly string[], entryModule: string -): RollupLogProps { +): RollupLog { return { - code: 'INVALID_EXPORT_OPTION', + code: INVALID_EXPORT_OPTION, message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId( entryModule - )}" has the following exports: ${keys.join(', ')}` + )}" has the following exports: ${printQuotedStringList(keys)}`, + url: 'https://rollupjs.org/guide/en/#outputexports' }; } -export function errInternalIdCannotBeExternal(source: string, importer: string): RollupLogProps { +export function errInternalIdCannotBeExternal(source: string, importer: string): RollupLog { return { - code: Errors.INVALID_EXTERNAL_ID, - message: `'${source}' is imported as an external by ${relativeId( + code: INVALID_EXTERNAL_ID, + message: `"${source}" is imported as an external by "${relativeId( importer - )}, but is already an existing non-external module id.` + )}", but is already an existing non-external module id.` }; } @@ -260,9 +401,9 @@ export function errInvalidOption( urlHash: string, explanation: string, value?: string | boolean | null -): RollupLogProps { +): RollupLog { return { - code: Errors.INVALID_OPTION, + code: INVALID_OPTION, message: `Invalid value ${ value !== undefined ? `${JSON.stringify(value)} ` : '' }for option "${option}" - ${explanation}.`, @@ -270,69 +411,104 @@ export function errInvalidOption( }; } -export function errInvalidAddonPluginHook(hook: string, plugin: string): RollupLogProps { +export function errInvalidAddonPluginHook(hook: string, plugin: string): RollupLog { return { - code: Errors.INVALID_PLUGIN_HOOK, + code: INVALID_PLUGIN_HOOK, hook, - message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a string, a function hook or an object with a "handler" string or function.`, + message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`, plugin }; } -export function errInvalidFunctionPluginHook(hook: string, plugin: string): RollupLogProps { +export function errInvalidFunctionPluginHook(hook: string, plugin: string): RollupLog { return { - code: Errors.INVALID_PLUGIN_HOOK, + code: INVALID_PLUGIN_HOOK, hook, - message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a function hook or an object with a "handler" function.`, + message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`, plugin }; } -export function errInvalidRollupPhaseForAddWatchFile(): RollupLogProps { +export function errInvalidRollupPhaseForAddWatchFile(): RollupLog { return { - code: Errors.INVALID_ROLLUP_PHASE, - message: `Cannot call addWatchFile after the build has finished.` + code: INVALID_ROLLUP_PHASE, + message: `Cannot call "addWatchFile" after the build has finished.` }; } -export function errInvalidRollupPhaseForChunkEmission(): RollupLogProps { +export function errInvalidRollupPhaseForChunkEmission(): RollupLog { return { - code: Errors.INVALID_ROLLUP_PHASE, + code: INVALID_ROLLUP_PHASE, message: `Cannot emit chunks after module loading has finished.` }; } +export function errInvalidSetAssetSourceCall(): RollupLog { + return { + code: INVALID_SETASSETSOURCE, + message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.` + }; +} + export function errInvalidFormatForTopLevelAwait( id: string, format: InternalModuleFormat -): RollupLogProps { +): RollupLog { return { - code: Errors.INVALID_TLA_FORMAT, + code: INVALID_TLA_FORMAT, id, - message: `Module format ${format} does not support top-level await. Use the "es" or "system" output formats rather.` + message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.` + }; +} + +export function errMissingConfig(): RollupLog { + return { + code: MISSING_CONFIG, + message: 'Config file must export an options object, or an array of options objects', + url: 'https://rollupjs.org/guide/en/#configuration-files' }; } export function errMissingExport( - exportName: string, + binding: string, importingModule: string, - importedModule: string -): RollupLogProps { + exporter: string +): RollupLog { return { - code: Errors.MISSING_EXPORT, - message: `'${exportName}' is not exported by ${relativeId( - importedModule - )}, imported by ${relativeId(importingModule)}`, + binding, + code: MISSING_EXPORT, + exporter, + id: importingModule, + message: `"${binding}" is not exported by "${relativeId(exporter)}", imported by "${relativeId( + importingModule + )}".`, url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` }; } +export function errMissingExternalConfig(file: string): RollupLog { + return { + code: MISSING_EXTERNAL_CONFIG, + message: `Could not resolve config file "${file}"` + }; +} + +export function errMissingGlobalName(externalId: string, guess: string): RollupLog { + return { + code: MISSING_GLOBAL_NAME, + id: externalId, + message: `No name was provided for external module "${externalId}" in "output.globals" – guessing "${guess}".`, + names: [guess], + url: 'https://rollupjs.org/guide/en/#outputglobals' + }; +} + export function errImplicitDependantCannotBeExternal( unresolvedId: string, implicitlyLoadedBefore: string -): RollupLogProps { +): RollupLog { return { - code: Errors.MISSING_IMPLICIT_DEPENDANT, + code: MISSING_IMPLICIT_DEPENDANT, message: `Module "${relativeId( unresolvedId )}" that should be implicitly loaded before "${relativeId( @@ -344,9 +520,9 @@ export function errImplicitDependantCannotBeExternal( export function errUnresolvedImplicitDependant( unresolvedId: string, implicitlyLoadedBefore: string -): RollupLogProps { +): RollupLog { return { - code: Errors.MISSING_IMPLICIT_DEPENDANT, + code: MISSING_IMPLICIT_DEPENDANT, message: `Module "${relativeId( unresolvedId )}" that should be implicitly loaded before "${relativeId( @@ -355,12 +531,12 @@ export function errUnresolvedImplicitDependant( }; } -export function errImplicitDependantIsNotIncluded(module: Module): RollupLogProps { +export function errImplicitDependantIsNotIncluded(module: Module): RollupLog { const implicitDependencies = Array.from(module.implicitlyLoadedBefore, dependency => relativeId(dependency.id) ).sort(); return { - code: Errors.MISSING_IMPLICIT_DEPENDANT, + code: MISSING_IMPLICIT_DEPENDANT, message: `Module "${relativeId( module.id )}" that should be implicitly loaded before ${printQuotedStringList( @@ -369,87 +545,202 @@ export function errImplicitDependantIsNotIncluded(module: Module): RollupLogProp }; } -export function errMixedExport(facadeModuleId: string, name?: string): RollupLogProps { +export function errMissingNameOptionForIifeExport(): RollupLog { return { - code: Errors.MIXED_EXPORTS, + code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT, + message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`, + url: 'https://rollupjs.org/guide/en/#outputname' + }; +} + +export function errMissingNameOptionForUmdExport(): RollupLog { + return { + code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT, + message: + 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.', + url: 'https://rollupjs.org/guide/en/#outputname' + }; +} + +export function errMissingNodeBuiltins(externalBuiltins: string[]): RollupLog { + return { + code: MISSING_NODE_BUILTINS, + ids: externalBuiltins, + message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList( + externalBuiltins + )}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node` + }; +} + +export function errMissingFileOrDirOption(): RollupLog { + return { + code: MISSING_OPTION, + message: 'You must specify "output.file" or "output.dir" for the build.', + url: 'https://rollupjs.org/guide/en/#outputdir' + }; +} + +export function errMixedExport(facadeModuleId: string, name?: string): RollupLog { + return { + code: MIXED_EXPORTS, id: facadeModuleId, message: `Entry module "${relativeId( facadeModuleId )}" is using named and default exports together. Consumers of your bundle will have to use \`${ name || 'chunk' - }["default"]\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning`, + }.default\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`, url: `https://rollupjs.org/guide/en/#outputexports` }; } +export function errModuleLevelDirective(directive: string, id: string): RollupLog { + return { + code: MODULE_LEVEL_DIRECTIVE, + id, + message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId( + id + )}" was ignored.` + }; +} + export function errNamespaceConflict( - name: string, + binding: string, reexportingModuleId: string, sources: string[] -): RollupWarning { +): RollupLog { return { - code: Errors.NAMESPACE_CONFLICT, + binding, + code: NAMESPACE_CONFLICT, + ids: sources, message: `Conflicting namespaces: "${relativeId( reexportingModuleId - )}" re-exports "${name}" from one of the modules ${printQuotedStringList( + )}" re-exports "${binding}" from one of the modules ${printQuotedStringList( sources.map(moduleId => relativeId(moduleId)) - )} (will be ignored)`, - name, - reexporter: reexportingModuleId, - sources + )} (will be ignored).`, + reexporter: reexportingModuleId }; } -export function errAmbiguousExternalNamespaces( - name: string, - reexportingModule: string, - usedModule: string, - sources: string[] -): RollupWarning { +export function errNoFileSystemInBrowser(method: string): RollupLog { return { - code: Errors.AMBIGUOUS_EXTERNAL_NAMESPACES, - message: `Ambiguous external namespace resolution: "${relativeId( - reexportingModule - )}" re-exports "${name}" from one of the external modules ${printQuotedStringList( - sources.map(module => relativeId(module)) - )}, guessing "${relativeId(usedModule)}".`, - name, - reexporter: reexportingModule, - sources + code: NO_FS_IN_BROWSER, + message: `Cannot access the file system (via "${method}") when using the browser build of Rollup. Make sure you supply a plugin with custom resolveId and load hooks to Rollup.`, + url: 'https://rollupjs.org/guide/en/#a-simple-example' }; } -export function errNoTransformMapOrAstWithoutCode(pluginName: string): RollupLogProps { +export function errNoTransformMapOrAstWithoutCode(pluginName: string): RollupLog { return { - code: Errors.NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE, + code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE, message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` + 'a "code". This will be ignored.' }; } -export function errPreferNamedExports(facadeModuleId: string): RollupLogProps { +export function errOnlyInlineSourcemapsForStdout(): RollupLog { + return { + code: ONLY_INLINE_SOURCEMAPS, + message: 'Only inline sourcemaps are supported when bundling to stdout.' + }; +} + +export function errParseError(error: Error, moduleId: string): RollupLog { + let message = error.message.replace(/ \(\d+:\d+\)$/, ''); + if (moduleId.endsWith('.json')) { + message += ' (Note that you need @rollup/plugin-json to import JSON files)'; + } else if (!moduleId.endsWith('.js')) { + message += ' (Note that you need plugins to import files that are not JavaScript)'; + } + return { + cause: error, + code: PARSE_ERROR, + id: moduleId, + message + }; +} + +export function errPluginError( + error: string | RollupLog, + plugin: string, + { hook, id }: { hook?: string; id?: string } = {} +): RollupLog { + if (typeof error === 'string') error = { message: error }; + if (error.code && error.code !== PLUGIN_ERROR) { + error.pluginCode = error.code; + } + error.code = PLUGIN_ERROR; + error.plugin = plugin; + if (hook) { + error.hook = hook; + } + if (id) { + error.id = id; + } + return error; +} + +export function errPreferNamedExports(facadeModuleId: string): RollupLog { const file = relativeId(facadeModuleId); return { - code: Errors.PREFER_NAMED_EXPORTS, + code: PREFER_NAMED_EXPORTS, id: facadeModuleId, message: `Entry module "${file}" is implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output will not be interchangeable with the original ES module. If this is intended, explicitly set "output.exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "${file}" to use named exports only.`, url: `https://rollupjs.org/guide/en/#outputexports` }; } +export function errShimmedExport(id: string, binding: string): RollupLog { + return { + binding, + code: SHIMMED_EXPORT, + exporter: id, + message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".` + }; +} + +export function errSourcemapBroken(plugin: string): RollupLog { + return { + code: SOURCEMAP_BROKEN, + message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`, + plugin, + url: `https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect` + }; +} + +export function errInvalidSourcemapForError( + error: Error, + id: string, + column: number, + line: number, + pos: number +): RollupLog { + return { + cause: error, + code: SOURCEMAP_ERROR, + id, + loc: { + column, + file: id, + line + }, + message: `Error when using sourcemap for reporting an error: ${error.message}`, + pos + }; +} + export function errSyntheticNamedExportsNeedNamespaceExport( id: string, syntheticNamedExportsOption: boolean | string -): RollupLogProps { +): RollupLog { return { - code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT, - id, + code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT, + exporter: id, message: `Module "${relativeId( id - )}" that is marked with 'syntheticNamedExports: ${JSON.stringify( + )}" that is marked with \`syntheticNamedExports: ${JSON.stringify( syntheticNamedExportsOption - )}' needs ${ + )}\` needs ${ typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default' ? `an explicit export named "${syntheticNamedExportsOption}"` : 'a default export' @@ -457,89 +748,121 @@ export function errSyntheticNamedExportsNeedNamespaceExport( }; } +export function errThisIsUndefined(): RollupLog { + return { + code: THIS_IS_UNDEFINED, + message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`, + url: `https://rollupjs.org/guide/en/#error-this-is-undefined` + }; +} + +export function errTranspiledEsmConfig(fileName: string): RollupLog { + return { + code: TRANSPILED_ESM_CONFIG, + message: `While loading the Rollup configuration from "${relativeId( + fileName + )}", Node tried to require an ES module from a CommonJS file, which is not supported. A common cause is if there is a package.json file with "type": "module" in the same folder. You can try to fix this by changing the extension of your configuration file to ".cjs" or ".mjs" depending on the content, which will prevent Rollup from trying to preprocess the file but rather hand it to Node directly.` + }; +} + export function errUnexpectedNamedImport( id: string, imported: string, isReexport: boolean -): RollupLogProps { +): RollupLog { const importType = isReexport ? 'reexport' : 'import'; return { - code: Errors.UNEXPECTED_NAMED_IMPORT, - id, - message: `The named export "${imported}" was ${importType}ed from the external module ${relativeId( + code: UNEXPECTED_NAMED_IMPORT, + exporter: id, + message: `The named export "${imported}" was ${importType}ed from the external module "${relativeId( id - )} even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`, + )}" even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`, url: 'https://rollupjs.org/guide/en/#outputinterop' }; } -export function errUnexpectedNamespaceReexport(id: string): RollupLogProps { +export function errUnexpectedNamespaceReexport(id: string): RollupLog { return { - code: Errors.UNEXPECTED_NAMED_IMPORT, - id, - message: `There was a namespace "*" reexport from the external module ${relativeId( + code: UNEXPECTED_NAMED_IMPORT, + exporter: id, + message: `There was a namespace "*" reexport from the external module "${relativeId( id - )} even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`, + )}" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`, url: 'https://rollupjs.org/guide/en/#outputinterop' }; } -export function errEntryCannotBeExternal(unresolvedId: string): RollupLogProps { +export function errUnknownOption( + optionType: string, + unknownOptions: string[], + validOptions: string[] +): RollupLog { return { - code: Errors.UNRESOLVED_ENTRY, - message: `Entry module cannot be external (${relativeId(unresolvedId)}).` + code: UNKNOWN_OPTION, + message: `Unknown ${optionType}: ${unknownOptions.join( + ', ' + )}. Allowed options: ${validOptions.join(', ')}` }; } -export function errUnresolvedEntry(unresolvedId: string): RollupLogProps { +export function errEntryCannotBeExternal(unresolvedId: string): RollupLog { return { - code: Errors.UNRESOLVED_ENTRY, - message: `Could not resolve entry module (${relativeId(unresolvedId)}).` + code: UNRESOLVED_ENTRY, + message: `Entry module "${relativeId(unresolvedId)}" cannot be external.` }; } -export function errUnresolvedImport(source: string, importer: string): RollupLogProps { +export function errUnresolvedEntry(unresolvedId: string): RollupLog { return { - code: Errors.UNRESOLVED_IMPORT, - message: `Could not resolve '${source}' from ${relativeId(importer)}` + code: UNRESOLVED_ENTRY, + message: `Could not resolve entry module "${relativeId(unresolvedId)}".` }; } -export function errUnresolvedImportTreatedAsExternal( - source: string, - importer: string -): RollupWarning { +export function errUnresolvedImport(source: string, importer: string): RollupLog { return { - code: Errors.UNRESOLVED_IMPORT, - importer: relativeId(importer), - message: `'${source}' is imported by ${relativeId( - importer - )}, but could not be resolved – treating it as an external dependency`, - source, - url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency' + code: UNRESOLVED_IMPORT, + exporter: source, + id: importer, + message: `Could not resolve "${source}" from "${relativeId(importer)}"` }; } -export function errExternalSyntheticExports(source: string, importer: string): RollupWarning { +export function errUnresolvedImportTreatedAsExternal(source: string, importer: string): RollupLog { return { - code: Errors.EXTERNAL_SYNTHETIC_EXPORTS, - importer: relativeId(importer), - message: `External '${source}' can not have 'syntheticNamedExports' enabled.`, - source + code: UNRESOLVED_IMPORT, + exporter: source, + id: importer, + message: `"${source}" is imported by "${relativeId( + importer + )}", but could not be resolved – treating it as an external dependency.`, + url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency' }; } -export function errFailedValidation(message: string): RollupLogProps { +export function errUnusedExternalImports( + externalId: string, + names: string[], + importers: string[] +): RollupLog { return { - code: Errors.VALIDATION_ERROR, - message + code: UNUSED_EXTERNAL_IMPORT, + exporter: externalId, + ids: importers, + message: `${printQuotedStringList(names, [ + 'is', + 'are' + ])} imported from external module "${externalId}" but never used in ${printQuotedStringList( + importers.map(importer => relativeId(importer)) + )}.`, + names }; } -export function errAlreadyClosed(): RollupLogProps { +export function errFailedValidation(message: string): RollupLog { return { - code: Errors.ALREADY_CLOSED, - message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.' + code: VALIDATION_ERROR, + message }; } diff --git a/src/utils/executionOrder.ts b/src/utils/executionOrder.ts index 005313dadc5..2eb1fde541f 100644 --- a/src/utils/executionOrder.ts +++ b/src/utils/executionOrder.ts @@ -1,6 +1,5 @@ import type ExternalModule from '../ExternalModule'; import Module from '../Module'; -import relativeId from './relativeId'; interface OrderedExecutionUnit { execIndex: number; @@ -74,12 +73,12 @@ function getCyclePath( parents: ReadonlyMap ): string[] { const cycleSymbol = Symbol(module.id); - const path = [relativeId(module.id)]; + const path = [module.id]; let nextModule = parent; module.cycles.add(cycleSymbol); while (nextModule !== module) { nextModule.cycles.add(cycleSymbol); - path.push(relativeId(nextModule.id)); + path.push(nextModule.id); nextModule = parents.get(nextModule)!; } path.push(path[0]); diff --git a/src/utils/options/options.ts b/src/utils/options/options.ts index cf480915b1d..1349b5f549c 100644 --- a/src/utils/options/options.ts +++ b/src/utils/options/options.ts @@ -6,7 +6,7 @@ import type { OutputOptions, WarningHandler } from '../../rollup/types'; -import { errInvalidOption, error } from '../error'; +import { errInvalidOption, error, errUnknownOption } from '../error'; import { printQuotedStringList } from '../printStringList'; export interface GenericConfigObject { @@ -27,14 +27,7 @@ export function warnUnknownOptions( key => !(validOptionSet.has(key) || ignoredKeys.test(key)) ); if (unknownOptions.length > 0) { - warn({ - code: 'UNKNOWN_OPTION', - message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${[ - ...validOptionSet - ] - .sort() - .join(', ')}` - }); + warn(errUnknownOption(optionType, unknownOptions, [...validOptionSet].sort())); } } diff --git a/src/utils/pluginUtils.ts b/src/utils/pluginUtils.ts index ab55417731c..7ee68f4367a 100644 --- a/src/utils/pluginUtils.ts +++ b/src/utils/pluginUtils.ts @@ -1,25 +1,2 @@ -import type { RollupError } from '../rollup/types'; -import { error, Errors } from './error'; - export const ANONYMOUS_PLUGIN_PREFIX = 'at position '; export const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = 'at output position '; - -export function throwPluginError( - err: string | RollupError, - plugin: string, - { hook, id }: { hook?: string; id?: string } = {} -): never { - if (typeof err === 'string') err = { message: err }; - if (err.code && err.code !== Errors.PLUGIN_ERROR) { - err.pluginCode = err.code; - } - err.code = Errors.PLUGIN_ERROR; - err.plugin = plugin; - if (hook) { - err.hook = hook; - } - if (id) { - err.id = id; - } - return error(err); -} diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 6b7d3aad0d6..ecc2cab9cbc 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -18,8 +18,13 @@ import { getTrackedPluginCache } from './PluginCache'; import type { PluginDriver } from './PluginDriver'; import { collapseSourcemap } from './collapseSourcemaps'; import { decodedSourcemap } from './decodedSourcemap'; -import { augmentCodeLocation, errNoTransformMapOrAstWithoutCode } from './error'; -import { throwPluginError } from './pluginUtils'; +import { + augmentCodeLocation, + errInvalidSetAssetSourceCall, + errNoTransformMapOrAstWithoutCode, + error, + errPluginError +} from './error'; export default async function transform( source: SourceDescription, @@ -129,10 +134,7 @@ export default async function transform( }); }, setAssetSource() { - return this.error({ - code: 'INVALID_SETASSETSOURCE', - message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.` - }); + return this.error(errInvalidSetAssetSourceCall()); }, warn(warning: RollupWarning | string, pos?: number | { column: number; line: number }) { if (typeof warning === 'string') warning = { message: warning }; @@ -145,7 +147,7 @@ export default async function transform( } ); } catch (err: any) { - throwPluginError(err, pluginName, { hook: 'transform', id }); + return error(errPluginError(err, pluginName, { hook: 'transform', id })); } if (!customTransformCache) { diff --git a/test/browser/samples/missing-dependency-resolution/_config.js b/test/browser/samples/missing-dependency-resolution/_config.js index 123ab0a95e2..a2c0c5febcd 100644 --- a/test/browser/samples/missing-dependency-resolution/_config.js +++ b/test/browser/samples/missing-dependency-resolution/_config.js @@ -10,7 +10,7 @@ console.log(foo);` }, error: { message: - "Unexpected warnings (UNRESOLVED_IMPORT): 'dep' is imported by main, but could not be resolved – treating it as an external dependency\nIf you expect warnings, list their codes in config.expectedWarnings", + 'Unexpected warnings (UNRESOLVED_IMPORT): "dep" is imported by "main", but could not be resolved – treating it as an external dependency.\nIf you expect warnings, list their codes in config.expectedWarnings', watchFiles: ['main'] } }; diff --git a/test/browser/samples/missing-entry-resolution/_config.js b/test/browser/samples/missing-entry-resolution/_config.js index 727dfa793a2..d575c881f01 100644 --- a/test/browser/samples/missing-entry-resolution/_config.js +++ b/test/browser/samples/missing-entry-resolution/_config.js @@ -2,6 +2,6 @@ module.exports = { description: 'fails if an entry cannot be resolved', error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry module (main).' + message: 'Could not resolve entry module "main".' } }; diff --git a/test/cli/samples/config-no-module/_config.js b/test/cli/samples/config-no-module/_config.js index d2ab16674de..21411297daa 100644 --- a/test/cli/samples/config-no-module/_config.js +++ b/test/cli/samples/config-no-module/_config.js @@ -8,10 +8,9 @@ module.exports = { stderr: stderr => assertIncludes( stderr, - '[!] Error: While loading the Rollup configuration from "rollup.config.js", Node tried to require an ES module from a CommonJS ' + + '[!] RollupError: While loading the Rollup configuration from "rollup.config.js", Node tried to require an ES module from a CommonJS ' + 'file, which is not supported. A common cause is if there is a package.json file with "type": "module" in the same folder. You can ' + 'try to fix this by changing the extension of your configuration file to ".cjs" or ".mjs" depending on the content, which will ' + - 'prevent Rollup from trying to preprocess the file but rather hand it to Node directly.\n' + - 'https://rollupjs.org/guide/en/#using-untranspiled-config-files' + 'prevent Rollup from trying to preprocess the file but rather hand it to Node directly.' ) }; diff --git a/test/cli/samples/empty-chunk-multiple/_config.js b/test/cli/samples/empty-chunk-multiple/_config.js index d20e2f09500..5b343d1f0c9 100644 --- a/test/cli/samples/empty-chunk-multiple/_config.js +++ b/test/cli/samples/empty-chunk-multiple/_config.js @@ -4,5 +4,5 @@ module.exports = { description: 'shows warning when multiple chunks empty', command: 'rollup -c', error: () => true, - stderr: stderr => assertIncludes(stderr, '(!) Generated empty chunks\na, b') + stderr: stderr => assertIncludes(stderr, '(!) Generated empty chunks\n"a" and "b"') }; diff --git a/test/cli/samples/empty-chunk/_config.js b/test/cli/samples/empty-chunk/_config.js index 29694a07f72..88e55b8b0c0 100644 --- a/test/cli/samples/empty-chunk/_config.js +++ b/test/cli/samples/empty-chunk/_config.js @@ -4,5 +4,5 @@ module.exports = { description: 'shows warning when chunk empty', command: 'rollup -c', error: () => true, - stderr: stderr => assertIncludes(stderr, '(!) Generated an empty chunk\nmain') + stderr: stderr => assertIncludes(stderr, '(!) Generated an empty chunk\n"main"') }; diff --git a/test/cli/samples/generated-code-unknown-preset/_config.js b/test/cli/samples/generated-code-unknown-preset/_config.js index f45b6b5f57a..c5802f62b18 100644 --- a/test/cli/samples/generated-code-unknown-preset/_config.js +++ b/test/cli/samples/generated-code-unknown-preset/_config.js @@ -7,7 +7,7 @@ module.exports = { stderr: stderr => { assertIncludes( stderr, - '[!] Error: Invalid value "unknown" for option "output.generatedCode" - valid values are "es2015" and "es5". You can also supply an object for more fine-grained control.\n' + + '[!] RollupError: Invalid value "unknown" for option "output.generatedCode" - valid values are "es2015" and "es5". You can also supply an object for more fine-grained control.\n' + 'https://rollupjs.org/guide/en/#outputgeneratedcode' ); } diff --git a/test/cli/samples/treeshake-unknown-preset/_config.js b/test/cli/samples/treeshake-unknown-preset/_config.js index 5abb57313d1..5e9c0741b7b 100644 --- a/test/cli/samples/treeshake-unknown-preset/_config.js +++ b/test/cli/samples/treeshake-unknown-preset/_config.js @@ -7,7 +7,7 @@ module.exports = { stderr: stderr => { assertIncludes( stderr, - '[!] Error: Invalid value "unknown" for option "treeshake" - valid values are false, true, "recommended", "safest" and "smallest". You can also supply an object for more fine-grained control.\n' + + '[!] RollupError: Invalid value "unknown" for option "treeshake" - valid values are false, true, "recommended", "safest" and "smallest". You can also supply an object for more fine-grained control.\n' + 'https://rollupjs.org/guide/en/#treeshake' ); } diff --git a/test/cli/samples/warn-broken-sourcemap/_config.js b/test/cli/samples/warn-broken-sourcemap/_config.js index 7ec82baaf01..ecd8e659379 100644 --- a/test/cli/samples/warn-broken-sourcemap/_config.js +++ b/test/cli/samples/warn-broken-sourcemap/_config.js @@ -12,7 +12,7 @@ module.exports = { stderr, '(!) Broken sourcemap\n' + 'https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect\n' + - 'Plugins that transform code (such as "test-plugin1") should generate accompanying sourcemaps\n' + 'Plugins that transform code (such as "test-plugin1") should generate accompanying sourcemaps.\n' ); } }; diff --git a/test/cli/samples/warn-import-export/_config.js b/test/cli/samples/warn-import-export/_config.js index 202692684d1..7cb1e413184 100644 --- a/test/cli/samples/warn-import-export/_config.js +++ b/test/cli/samples/warn-import-export/_config.js @@ -11,22 +11,12 @@ module.exports = { 'The following entry modules are using named and default exports together:\n' + 'main.js\n' + '\n' + - "Consumers of your bundle will have to use chunk['default'] to access their default export, which may not be what you want. Use `output.exports: 'named'` to disable this warning\n" + 'Consumers of your bundle will have to use chunk.default to access their default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.\n' ); assertIncludes( stderr, '(!) Unused external imports\n' + - `default imported from external module "external" but never used in "main.js"\n` - ); - assertIncludes( - stderr, - '(!) Import of non-existent export\n' + - 'main.js\n' + - "1: import unused from 'external';\n" + - "2: import * as dep from './dep.js';\n" + - "3: import alsoUnused from './dep.js';\n" + - ' ^\n' + - "4: import 'unresolvedExternal';\n" + `default imported from external module "external" but never used in "main.js".\n` ); assertIncludes( stderr, @@ -38,20 +28,27 @@ module.exports = { '5: \n' + '6: export const missing = dep.missing;\n' + ' ^\n' + - '7: export default 42;\n' + '7: export default 42;\n' + + 'main.js\n' + + 'default is not exported by dep.js\n' + + "1: import unused from 'external';\n" + + "2: import * as dep from './dep.js';\n" + + "3: import alsoUnused from './dep.js';\n" + + ' ^\n' + + "4: import 'unresolvedExternal';\n" ); assertIncludes( stderr, '(!) Conflicting re-exports\n' + - '"main.js" re-exports "foo" from both "dep.js" and "dep2.js" (will be ignored)\n' + - '"main.js" re-exports "bar" from both "dep.js" and "dep2.js" (will be ignored)\n' + '"main.js" re-exports "foo" from both "dep.js" and "dep2.js" (will be ignored).\n' + + '"main.js" re-exports "bar" from both "dep.js" and "dep2.js" (will be ignored).\n' ); assertIncludes( stderr, '(!) Unresolved dependencies\n' + 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency\n' + - 'unresolvedExternal (imported by main.js, dep.js)\n' + - 'otherUnresolvedExternal (imported by dep.js)\n' + 'unresolvedExternal (imported by "main.js" and "dep.js")\n' + + 'otherUnresolvedExternal (imported by "dep.js")\n' ); } }; diff --git a/test/cli/samples/warn-missing-global-multiple/_config.js b/test/cli/samples/warn-missing-global-multiple/_config.js index ecb11f71e5e..af8d5830ca4 100644 --- a/test/cli/samples/warn-missing-global-multiple/_config.js +++ b/test/cli/samples/warn-missing-global-multiple/_config.js @@ -7,9 +7,10 @@ module.exports = { assertIncludes( stderr, '(!) Missing global variable names\n' + - 'Use output.globals to specify browser global variable names corresponding to external modules\n' + - "external1 (guessing 'foo1')\n" + - "external2 (guessing 'foo2')\n" + - "external3 (guessing 'foo3')" + 'https://rollupjs.org/guide/en/#outputglobals\n' + + 'Use "output.globals" to specify browser global variable names corresponding to external modules:\n' + + 'external1 (guessing "foo1")\n' + + 'external2 (guessing "foo2")\n' + + 'external3 (guessing "foo3")' ) }; diff --git a/test/cli/samples/warn-missing-global/_config.js b/test/cli/samples/warn-missing-global/_config.js index ffa8470c384..8f134cf0ae1 100644 --- a/test/cli/samples/warn-missing-global/_config.js +++ b/test/cli/samples/warn-missing-global/_config.js @@ -7,7 +7,8 @@ module.exports = { assertIncludes( stderr, '(!) Missing global variable name\n' + - 'Use output.globals to specify browser global variable names corresponding to external modules\n' + - "external (guessing 'foo')" + 'https://rollupjs.org/guide/en/#outputglobals\n' + + 'Use "output.globals" to specify browser global variable names corresponding to external modules:\n' + + 'external (guessing "foo")' ) }; diff --git a/test/cli/samples/warn-mixed-exports-multiple/_config.js b/test/cli/samples/warn-mixed-exports-multiple/_config.js index 45b131800d1..88e0e14124e 100644 --- a/test/cli/samples/warn-mixed-exports-multiple/_config.js +++ b/test/cli/samples/warn-mixed-exports-multiple/_config.js @@ -14,7 +14,7 @@ module.exports = { 'lib3.js\n' + '...and 3 other entry modules\n' + '\n' + - "Consumers of your bundle will have to use chunk['default'] to access their default export, which may not be what you want. Use `output.exports: 'named'` to disable this warning\n" + 'Consumers of your bundle will have to use chunk.default to access their default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.\n' ); } }; diff --git a/test/cli/samples/warn-multiple/_config.js b/test/cli/samples/warn-multiple/_config.js index 45e8770b975..13293224781 100644 --- a/test/cli/samples/warn-multiple/_config.js +++ b/test/cli/samples/warn-multiple/_config.js @@ -11,20 +11,29 @@ module.exports = { ); assertIncludes( stderr, - '(!) Import of non-existent exports\n' + + '(!) Missing exports\n' + + 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module\n' + 'main.js\n' + + 'doesNotExist is not exported by dep.js\n' + "4: import assert from 'assert';\n" + "5: import path from 'path';\n" + "6: import {doesNotExist, alsoNotFound} from './dep.js';\n" + ' ^\n' + '7: \n' + '8: export {url, assert, path};\n' + - '...and 1 other occurrence\n' + 'main.js\n' + + 'alsoNotFound is not exported by dep.js\n' + + "4: import assert from 'assert';\n" + + "5: import path from 'path';\n" + + "6: import {doesNotExist, alsoNotFound} from './dep.js';\n" + + ' ^\n' + + '7: \n' + + '8: export {url, assert, path};' ); assertIncludes( stderr, - "(!) Module level directives cause errors when bundled, 'use stuff' was ignored.\n" + + '(!) Module level directives cause errors when bundled, "use stuff" in "main.js" was ignored.\n' + 'main.js (1:0)\n' + "1: 'use stuff';\n" + ' ^\n' + diff --git a/test/cli/samples/warn-this/_config.js b/test/cli/samples/warn-this/_config.js index 8b6990286bd..620b806097e 100644 --- a/test/cli/samples/warn-this/_config.js +++ b/test/cli/samples/warn-this/_config.js @@ -6,7 +6,7 @@ module.exports = { stderr: stderr => assertIncludes( stderr, - '(!) `this` has been rewritten to `undefined`\n' + + '(!) "this" has been rewritten to "undefined"\n' + 'https://rollupjs.org/guide/en/#error-this-is-undefined\n' + 'main.js\n' + '1: console.log(this);\n' + diff --git a/test/cli/samples/watch/close-on-generate-error/_config.js b/test/cli/samples/watch/close-on-generate-error/_config.js index a94f8646c41..c39fb2fe398 100644 --- a/test/cli/samples/watch/close-on-generate-error/_config.js +++ b/test/cli/samples/watch/close-on-generate-error/_config.js @@ -11,7 +11,7 @@ module.exports = { stderr(stderr) { assertIncludes( stderr, - '[!] Error: You must specify "output.file" or "output.dir" for the build.' + '[!] RollupError: You must specify "output.file" or "output.dir" for the build.' ); assertIncludes(stderr, 'Bundle closed'); return false; diff --git a/test/cli/samples/watch/no-watched-config/_config.js b/test/cli/samples/watch/no-watched-config/_config.js index fbf10ff6755..a1bc0153478 100644 --- a/test/cli/samples/watch/no-watched-config/_config.js +++ b/test/cli/samples/watch/no-watched-config/_config.js @@ -7,7 +7,7 @@ module.exports = { stderr(stderr) { assertIncludes( stderr, - '[!] Error: Invalid value for option "watch" - there must be at least one config where "watch" is not set to "false".' + '[!] RollupError: Invalid value for option "watch" - there must be at least one config where "watch" is not set to "false".' ); } }; diff --git a/test/function/samples/add-watch-file-generate/_config.js b/test/function/samples/add-watch-file-generate/_config.js index 49d71307ea2..190b1243d04 100644 --- a/test/function/samples/add-watch-file-generate/_config.js +++ b/test/function/samples/add-watch-file-generate/_config.js @@ -13,7 +13,7 @@ module.exports = { generateError: { code: 'PLUGIN_ERROR', hook: 'renderStart', - message: 'Cannot call addWatchFile after the build has finished.', + message: 'Cannot call "addWatchFile" after the build has finished.', plugin: 'test-plugin', pluginCode: 'INVALID_ROLLUP_PHASE' } diff --git a/test/function/samples/already-deshadowed-import/_config.js b/test/function/samples/already-deshadowed-import/_config.js index b8ce432d1ac..dea919409dd 100644 --- a/test/function/samples/already-deshadowed-import/_config.js +++ b/test/function/samples/already-deshadowed-import/_config.js @@ -1,11 +1,14 @@ +const path = require('path'); +const ID_BOB = path.join(__dirname, 'bob.js'); +const ID_ALICE = path.join(__dirname, 'alice.js'); + module.exports = { description: 'handle already module import names correctly if they are have already been deshadowed', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['bob.js', 'alice.js', 'bob.js'], - importer: 'bob.js', + ids: [ID_BOB, ID_ALICE, ID_BOB], message: 'Circular dependency: bob.js -> alice.js -> bob.js' } ] diff --git a/test/function/samples/assign-namespace-to-var/_config.js b/test/function/samples/assign-namespace-to-var/_config.js index 4a5e6b0a579..1a7e54ffc20 100644 --- a/test/function/samples/assign-namespace-to-var/_config.js +++ b/test/function/samples/assign-namespace-to-var/_config.js @@ -2,9 +2,9 @@ module.exports = { description: 'allows a namespace to be assigned to a variable', warnings: [ { - chunkName: 'main', code: 'EMPTY_BUNDLE', - message: 'Generated an empty chunk: "main"' + message: 'Generated an empty chunk: "main".', + names: ['main'] } ] }; diff --git a/test/function/samples/banner-and-footer/_config.js b/test/function/samples/banner-and-footer/_config.js index 40d3b05b3c8..6d2b514849b 100644 --- a/test/function/samples/banner-and-footer/_config.js +++ b/test/function/samples/banner-and-footer/_config.js @@ -29,6 +29,7 @@ module.exports = { generateError: { code: 'ADDON_ERROR', message: - 'Could not retrieve banner. Check configuration of plugin at position 3.\n\tError Message: Could not generate banner.' + 'Could not retrieve "banner". Check configuration of plugin "at position 3".\n' + + '\tError Message: Could not generate banner.' } }; diff --git a/test/function/samples/can-import-self-treeshake/_config.js b/test/function/samples/can-import-self-treeshake/_config.js index 7873b58b34a..cdc8d4dccb0 100644 --- a/test/function/samples/can-import-self-treeshake/_config.js +++ b/test/function/samples/can-import-self-treeshake/_config.js @@ -1,16 +1,18 @@ +const path = require('path'); +const ID_LIB = path.join(__dirname, 'lib.js'); + module.exports = { description: 'direct self import', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['lib.js', 'lib.js'], - importer: 'lib.js', + ids: [ID_LIB, ID_LIB], message: 'Circular dependency: lib.js -> lib.js' }, { - chunkName: 'main', code: 'EMPTY_BUNDLE', - message: `Generated an empty chunk: "main"` + message: 'Generated an empty chunk: "main".', + names: ['main'] } ] }; diff --git a/test/function/samples/can-import-self/_config.js b/test/function/samples/can-import-self/_config.js index f49dfc06ef3..23deb66c059 100644 --- a/test/function/samples/can-import-self/_config.js +++ b/test/function/samples/can-import-self/_config.js @@ -1,4 +1,6 @@ const assert = require('assert'); +const path = require('path'); +const ID_LIB = path.join(__dirname, 'lib.js'); module.exports = { description: 'a module importing its own bindings', @@ -8,8 +10,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['lib.js', 'lib.js'], - importer: 'lib.js', + ids: [ID_LIB, ID_LIB], message: 'Circular dependency: lib.js -> lib.js' } ] diff --git a/test/function/samples/cannot-call-external-namespace/_config.js b/test/function/samples/cannot-call-external-namespace/_config.js index 20b6a35ada5..ec37783e859 100644 --- a/test/function/samples/cannot-call-external-namespace/_config.js +++ b/test/function/samples/cannot-call-external-namespace/_config.js @@ -7,8 +7,8 @@ module.exports = { }, warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ - "main.js (4:1) Cannot call a namespace ('foo')", - "main.js (8:1) Cannot call a namespace ('foo')" + 'main.js (4:1) Cannot call a namespace ("foo").', + 'main.js (8:1) Cannot call a namespace ("foo").' ]); } }; diff --git a/test/function/samples/cannot-call-internal-namespace/_config.js b/test/function/samples/cannot-call-internal-namespace/_config.js index b61157e6158..ff0ef1b81ad 100644 --- a/test/function/samples/cannot-call-internal-namespace/_config.js +++ b/test/function/samples/cannot-call-internal-namespace/_config.js @@ -4,8 +4,8 @@ module.exports = { description: 'warns if code calls an internal namespace', warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ - "main.js (4:1) Cannot call a namespace ('foo')", - "main.js (8:1) Cannot call a namespace ('foo')" + 'main.js (4:1) Cannot call a namespace ("foo").', + 'main.js (8:1) Cannot call a namespace ("foo").' ]); } }; diff --git a/test/function/samples/cannot-resolve-sourcemap-warning/_config.js b/test/function/samples/cannot-resolve-sourcemap-warning/_config.js index 3ec5a853772..4a368813b67 100644 --- a/test/function/samples/cannot-resolve-sourcemap-warning/_config.js +++ b/test/function/samples/cannot-resolve-sourcemap-warning/_config.js @@ -13,6 +13,9 @@ module.exports = { }, warnings: [ { + cause: { + message: "Can't resolve original location of error." + }, code: 'SOURCEMAP_ERROR', id: ID_MAIN, loc: { diff --git a/test/function/samples/check-resolve-for-entry/_config.js b/test/function/samples/check-resolve-for-entry/_config.js index 88ef2dd83be..b2120f29507 100644 --- a/test/function/samples/check-resolve-for-entry/_config.js +++ b/test/function/samples/check-resolve-for-entry/_config.js @@ -5,6 +5,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry module (not/a/path/that/actually/really/exists).' + message: 'Could not resolve entry module "not/a/path/that/actually/really/exists".' } }; diff --git a/test/function/samples/circular-default-exports/_config.js b/test/function/samples/circular-default-exports/_config.js index 37b93142200..347ae7ae41a 100644 --- a/test/function/samples/circular-default-exports/_config.js +++ b/test/function/samples/circular-default-exports/_config.js @@ -1,10 +1,12 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); + module.exports = { description: 'handles circular default exports', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_MAIN], message: 'Circular dependency: main.js -> main.js' } ] diff --git a/test/function/samples/circular-missed-reexports-2/_config.js b/test/function/samples/circular-missed-reexports-2/_config.js index 7bcba6b92ce..80bfe91a8ff 100644 --- a/test/function/samples/circular-missed-reexports-2/_config.js +++ b/test/function/samples/circular-missed-reexports-2/_config.js @@ -1,5 +1,8 @@ const assert = require('assert'); const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_DEP1 = path.join(__dirname, 'dep1.js'); +const ID_DEP2 = path.join(__dirname, 'dep2.js'); module.exports = { description: 'handles circular reexports', @@ -8,13 +11,9 @@ module.exports = { }, error: { code: 'CIRCULAR_REEXPORT', - id: path.join(__dirname, 'dep1.js'), + exporter: ID_DEP1, message: - '"doesNotExist" cannot be exported from dep1.js as it is a reexport that references itself.', - watchFiles: [ - path.join(__dirname, 'dep1.js'), - path.join(__dirname, 'dep2.js'), - path.join(__dirname, 'main.js') - ] + '"doesNotExist" cannot be exported from "dep1.js" as it is a reexport that references itself.', + watchFiles: [ID_DEP1, ID_DEP2, ID_MAIN] } }; diff --git a/test/function/samples/circular-missed-reexports/_config.js b/test/function/samples/circular-missed-reexports/_config.js index 3e576566bca..c8d44035b94 100644 --- a/test/function/samples/circular-missed-reexports/_config.js +++ b/test/function/samples/circular-missed-reexports/_config.js @@ -3,6 +3,7 @@ const path = require('path'); const ID_MAIN = path.join(__dirname, 'main.js'); const ID_DEP1 = path.join(__dirname, 'dep1.js'); +const ID_DEP2 = path.join(__dirname, 'dep2.js'); module.exports = { description: 'handles circular reexports', @@ -12,22 +13,20 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['dep1.js', 'dep2.js', 'dep1.js'], - importer: 'dep1.js', + ids: [ID_DEP1, ID_DEP2, ID_DEP1], message: 'Circular dependency: dep1.js -> dep2.js -> dep1.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['dep1.js', 'dep1.js'], - importer: 'dep1.js', + ids: [ID_DEP1, ID_DEP1], message: 'Circular dependency: dep1.js -> dep1.js' }, { - code: 'NON_EXISTENT_EXPORT', - message: "Non-existent export 'doesNotExist' is imported from dep1.js", - name: 'doesNotExist', - source: ID_DEP1, + binding: 'doesNotExist', + code: 'MISSING_EXPORT', id: ID_MAIN, + message: '"doesNotExist" is not exported by "dep1.js", imported by "main.js".', + exporter: ID_DEP1, pos: 17, loc: { file: ID_MAIN, @@ -37,7 +36,8 @@ module.exports = { frame: ` 1: import { exists, doesNotExist } from './dep1.js'; ^ -2: export { exists };` +2: export { exists };`, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module' } ] }; diff --git a/test/function/samples/circular-preserve-modules/_config.js b/test/function/samples/circular-preserve-modules/_config.js index 097090160d3..6463627bb16 100644 --- a/test/function/samples/circular-preserve-modules/_config.js +++ b/test/function/samples/circular-preserve-modules/_config.js @@ -11,30 +11,28 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'first.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_FIRST, ID_MAIN], message: 'Circular dependency: main.js -> first.js -> main.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'second.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_SECOND, ID_MAIN], message: 'Circular dependency: main.js -> second.js -> main.js' }, { code: 'CYCLIC_CROSS_CHUNK_REEXPORT', exporter: ID_SECOND, - importer: ID_FIRST, + id: ID_FIRST, message: - 'Export "second" of module second.js was reexported through module main.js while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in first.js to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.', + 'Export "second" of module "second.js" was reexported through module "main.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "first.js" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.', reexporter: ID_MAIN }, { code: 'CYCLIC_CROSS_CHUNK_REEXPORT', exporter: ID_FIRST, - importer: ID_SECOND, + id: ID_SECOND, message: - 'Export "first" of module first.js was reexported through module main.js while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in second.js to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.', + 'Export "first" of module "first.js" was reexported through module "main.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "second.js" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.', reexporter: ID_MAIN } ] diff --git a/test/function/samples/circular-reexport/_config.js b/test/function/samples/circular-reexport/_config.js index 6379705fca7..18016191afa 100644 --- a/test/function/samples/circular-reexport/_config.js +++ b/test/function/samples/circular-reexport/_config.js @@ -5,8 +5,8 @@ module.exports = { description: 'throws proper error for circular reexports', error: { code: 'CIRCULAR_REEXPORT', - id: ID_MAIN, - message: '"foo" cannot be exported from main.js as it is a reexport that references itself.', + exporter: ID_MAIN, + message: '"foo" cannot be exported from "main.js" as it is a reexport that references itself.', watchFiles: [ID_MAIN] } }; diff --git a/test/function/samples/compact/_config.js b/test/function/samples/compact/_config.js index af768500312..eb73c80398b 100644 --- a/test/function/samples/compact/_config.js +++ b/test/function/samples/compact/_config.js @@ -1,3 +1,6 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); + module.exports = { description: 'compact output with compact: true', options: { @@ -10,8 +13,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_MAIN], message: 'Circular dependency: main.js -> main.js' } ], diff --git a/test/function/samples/conflicting-reexports/named-import-external/_config.js b/test/function/samples/conflicting-reexports/named-import-external/_config.js index ca9bfc542de..4dc0b08a362 100644 --- a/test/function/samples/conflicting-reexports/named-import-external/_config.js +++ b/test/function/samples/conflicting-reexports/named-import-external/_config.js @@ -1,24 +1,24 @@ const path = require('path'); -const REEXPORT_ID = path.join(__dirname, 'reexport.js'); +const ID_REEXPORT = path.join(__dirname, 'reexport.js'); module.exports = { description: 'warns when a conflicting binding is imported via a named import from external namespaces', warnings: [ { + binding: 'foo', code: 'AMBIGUOUS_EXTERNAL_NAMESPACES', + ids: ['first', 'second'], message: 'Ambiguous external namespace resolution: "reexport.js" re-exports "foo" from one of the external modules "first" and "second", guessing "first".', - name: 'foo', - reexporter: REEXPORT_ID, - sources: ['first', 'second'] + reexporter: ID_REEXPORT }, { code: 'UNUSED_EXTERNAL_IMPORT', + exporter: 'second', + ids: [ID_REEXPORT], message: '"foo" is imported from external module "second" but never used in "reexport.js".', - names: ['foo'], - source: 'second', - sources: [REEXPORT_ID] + names: ['foo'] } ], options: { external: ['first', 'second'] }, diff --git a/test/function/samples/conflicting-reexports/named-import/_config.js b/test/function/samples/conflicting-reexports/named-import/_config.js index 751c3eb90a2..e6f2362c996 100644 --- a/test/function/samples/conflicting-reexports/named-import/_config.js +++ b/test/function/samples/conflicting-reexports/named-import/_config.js @@ -1,30 +1,30 @@ const path = require('path'); const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_REEXPORT = path.join(__dirname, 'reexport.js'); +const ID_FIRST = path.join(__dirname, 'first.js'); +const ID_SECOND = path.join(__dirname, 'second.js'); module.exports = { description: 'throws when a conflicting binding is imported via a named import', error: { + binding: 'foo', code: 'MISSING_EXPORT', - frame: ` -1: import { foo } from './reexport.js'; - ^ -2: -3: assert.strictEqual(foo, 1);`, + exporter: ID_REEXPORT, id: ID_MAIN, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', + pos: 9, loc: { column: 9, file: ID_MAIN, line: 1 }, - message: "'foo' is not exported by reexport.js, imported by main.js", - pos: 9, - url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', - watchFiles: [ - path.join(__dirname, 'first.js'), - ID_MAIN, - path.join(__dirname, 'reexport.js'), - path.join(__dirname, 'second.js') - ] + frame: ` + 1: import { foo } from './reexport.js'; + ^ + 2: + 3: assert.strictEqual(foo, 1);`, + watchFiles: [ID_FIRST, ID_MAIN, ID_REEXPORT, ID_SECOND], + message: '"foo" is not exported by "reexport.js", imported by "main.js".' } }; diff --git a/test/function/samples/conflicting-reexports/namespace-import/_config.js b/test/function/samples/conflicting-reexports/namespace-import/_config.js index def8efa6927..343027ba2d5 100644 --- a/test/function/samples/conflicting-reexports/namespace-import/_config.js +++ b/test/function/samples/conflicting-reexports/namespace-import/_config.js @@ -1,35 +1,38 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FIRST = path.join(__dirname, 'first.js'); +const ID_SECOND = path.join(__dirname, 'second.js'); +const ID_REEXPORT = path.join(__dirname, 'reexport.js'); module.exports = { description: 'warns when a conflicting binding is imported via a namespace import', warnings: [ { + binding: 'foo', code: 'NAMESPACE_CONFLICT', + ids: [ID_FIRST, ID_SECOND], message: - 'Conflicting namespaces: "reexport.js" re-exports "foo" from one of the modules "first.js" and "second.js" (will be ignored)', - name: 'foo', - reexporter: path.join(__dirname, 'reexport.js'), - sources: [path.join(__dirname, 'first.js'), path.join(__dirname, 'second.js')] + 'Conflicting namespaces: "reexport.js" re-exports "foo" from one of the modules "first.js" and "second.js" (will be ignored).', + reexporter: ID_REEXPORT }, { + binding: 'foo', code: 'MISSING_EXPORT', - exporter: 'reexport.js', - frame: ` -2: -3: assert.deepStrictEqual(ns, { __proto__: null, bar: 1, baz: 2 }); -4: assert.strictEqual(ns.foo, undefined) - ^`, - id: path.join(__dirname, 'main.js'), - importer: 'main.js', + exporter: ID_REEXPORT, + id: ID_MAIN, + message: '"foo" is not exported by "reexport.js", imported by "main.js".', + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', + pos: 125, loc: { column: 22, - file: path.join(__dirname, 'main.js'), + file: ID_MAIN, line: 4 }, - message: "'foo' is not exported by 'reexport.js'", - missing: 'foo', - pos: 125, - url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module' + frame: ` + 2: + 3: assert.deepStrictEqual(ns, { __proto__: null, bar: 1, baz: 2 }); + 4: assert.strictEqual(ns.foo, undefined) + ^` } ] }; diff --git a/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js b/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js index 60e42dcfb98..2c58be7d581 100644 --- a/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js +++ b/test/function/samples/cycles-default-anonymous-function-hoisted/_config.js @@ -1,10 +1,13 @@ +const path = require('path'); +const ID_F = path.join(__dirname, 'f.js'); +const ID_G = path.join(__dirname, 'g.js'); + module.exports = { description: 'Anonymous function declarations are hoisted', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['f.js', 'g.js', 'f.js'], - importer: 'f.js', + ids: [ID_F, ID_G, ID_F], message: 'Circular dependency: f.js -> g.js -> f.js' } ] diff --git a/test/function/samples/cycles-defaults/_config.js b/test/function/samples/cycles-defaults/_config.js index 84969a977d2..5941632ea0c 100644 --- a/test/function/samples/cycles-defaults/_config.js +++ b/test/function/samples/cycles-defaults/_config.js @@ -1,10 +1,13 @@ +const path = require('path'); +const ID_A = path.join(__dirname, 'a.js'); +const ID_B = path.join(__dirname, 'b.js'); + module.exports = { description: 'cycles work with default exports', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['a.js', 'b.js', 'a.js'], - importer: 'a.js', + ids: [ID_A, ID_B, ID_A], message: 'Circular dependency: a.js -> b.js -> a.js' } ] diff --git a/test/function/samples/cycles-export-star/_config.js b/test/function/samples/cycles-export-star/_config.js index b1f63718246..86ce6e30ccc 100644 --- a/test/function/samples/cycles-export-star/_config.js +++ b/test/function/samples/cycles-export-star/_config.js @@ -1,4 +1,7 @@ const assert = require('assert'); +const path = require('path'); +const ID_A = path.join(__dirname, 'a.js'); +const ID_B = path.join(__dirname, 'b.js'); module.exports = { description: 'does not stack overflow on `export * from X` cycles', @@ -11,8 +14,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['a.js', 'b.js', 'a.js'], - importer: 'a.js', + ids: [ID_A, ID_B, ID_A], message: 'Circular dependency: a.js -> b.js -> a.js' } ] diff --git a/test/function/samples/cycles-immediate/_config.js b/test/function/samples/cycles-immediate/_config.js index 8c4b9235fd3..90a4475ef29 100644 --- a/test/function/samples/cycles-immediate/_config.js +++ b/test/function/samples/cycles-immediate/_config.js @@ -1,10 +1,13 @@ +const path = require('path'); +const ID_EVENS = path.join(__dirname, 'evens.js'); +const ID_ODDS = path.join(__dirname, 'odds.js'); + module.exports = { description: 'handles cycles where imports are immediately used', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['evens.js', 'odds.js', 'evens.js'], - importer: 'evens.js', + ids: [ID_EVENS, ID_ODDS, ID_EVENS], message: 'Circular dependency: evens.js -> odds.js -> evens.js' } ] diff --git a/test/function/samples/cycles-pathological-2/_config.js b/test/function/samples/cycles-pathological-2/_config.js index e57e6d43318..101e7968a35 100644 --- a/test/function/samples/cycles-pathological-2/_config.js +++ b/test/function/samples/cycles-pathological-2/_config.js @@ -1,22 +1,25 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_B = path.join(__dirname, 'b.js'); +const ID_C = path.join(__dirname, 'c.js'); +const ID_D = path.join(__dirname, 'd.js'); + module.exports = { description: 'resolves even more pathological cyclical dependencies gracefully', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'b.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_B, ID_MAIN], message: 'Circular dependency: main.js -> b.js -> main.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['b.js', 'd.js', 'c.js', 'b.js'], - importer: 'b.js', + ids: [ID_B, ID_D, ID_C, ID_B], message: 'Circular dependency: b.js -> d.js -> c.js -> b.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'b.js', 'd.js', 'c.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_B, ID_D, ID_C, ID_MAIN], message: 'Circular dependency: main.js -> b.js -> d.js -> c.js -> main.js' } ] diff --git a/test/function/samples/cycles-stack-overflow/_config.js b/test/function/samples/cycles-stack-overflow/_config.js index 7c01540e491..3c544c66c0b 100644 --- a/test/function/samples/cycles-stack-overflow/_config.js +++ b/test/function/samples/cycles-stack-overflow/_config.js @@ -1,16 +1,19 @@ +const path = require('path'); +const ID_B = path.join(__dirname, 'b.js'); +const ID_C = path.join(__dirname, 'c.js'); +const ID_D = path.join(__dirname, 'd.js'); + module.exports = { description: 'does not stack overflow on crazy cyclical dependencies', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['c.js', 'd.js', 'b.js', 'c.js'], - importer: 'c.js', + ids: [ID_C, ID_D, ID_B, ID_C], message: 'Circular dependency: c.js -> d.js -> b.js -> c.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['c.js', 'd.js', 'c.js'], - importer: 'c.js', + ids: [ID_C, ID_D, ID_C], message: 'Circular dependency: c.js -> d.js -> c.js' } ] diff --git a/test/function/samples/default-not-reexported/_config.js b/test/function/samples/default-not-reexported/_config.js index cfb7296fad2..8cd60799edd 100644 --- a/test/function/samples/default-not-reexported/_config.js +++ b/test/function/samples/default-not-reexported/_config.js @@ -1,19 +1,20 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); +const ID_BAR = path.join(__dirname, 'bar.js'); module.exports = { description: 'default export is not re-exported with export *', error: { + binding: 'default', code: 'MISSING_EXPORT', - message: `'default' is not exported by foo.js, imported by main.js`, - id: path.join(__dirname, 'main.js'), + exporter: ID_FOO, + message: '"default" is not exported by "foo.js", imported by "main.js".', + id: ID_MAIN, pos: 7, - watchFiles: [ - path.join(__dirname, 'bar.js'), - path.join(__dirname, 'foo.js'), - path.join(__dirname, 'main.js') - ], + watchFiles: [ID_BAR, ID_FOO, ID_MAIN], loc: { - file: path.join(__dirname, 'main.js'), + file: ID_MAIN, line: 1, column: 7 }, diff --git a/test/function/samples/default-on-warn/_config.js b/test/function/samples/default-on-warn/_config.js index 2ad6c83bb07..e353a41de2f 100644 --- a/test/function/samples/default-on-warn/_config.js +++ b/test/function/samples/default-on-warn/_config.js @@ -20,8 +20,8 @@ module.exports = { after() { console.warn = oldConsoleWarn; assert.deepStrictEqual(warnings, [ - 'Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification', - 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning' + 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.' ]); } }; diff --git a/test/function/samples/deprecated/compact/_config.js b/test/function/samples/deprecated/compact/_config.js index 08b0fa589f2..e46e4ce5999 100644 --- a/test/function/samples/deprecated/compact/_config.js +++ b/test/function/samples/deprecated/compact/_config.js @@ -1,3 +1,6 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); + module.exports = { description: 'compact output with compact: true', options: { @@ -11,8 +14,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_MAIN], message: 'Circular dependency: main.js -> main.js' }, { diff --git a/test/function/samples/deprecated/manual-chunks-conflict/_config.js b/test/function/samples/deprecated/manual-chunks-conflict/_config.js index 0784b63bbb2..04e0839bcca 100644 --- a/test/function/samples/deprecated/manual-chunks-conflict/_config.js +++ b/test/function/samples/deprecated/manual-chunks-conflict/_config.js @@ -12,7 +12,7 @@ module.exports = { }, generateError: { code: 'INVALID_CHUNK', - message: `Cannot assign dep.js to the "dep2" chunk as it is already in the "dep1" chunk.` + message: 'Cannot assign "dep.js" to the "dep2" chunk as it is already in the "dep1" chunk.' }, warnings: [] }; diff --git a/test/function/samples/deprecated/preserveModules/invalid-default-export-mode/_config.js b/test/function/samples/deprecated/preserveModules/invalid-default-export-mode/_config.js index 88944569e52..0d22d286705 100644 --- a/test/function/samples/deprecated/preserveModules/invalid-default-export-mode/_config.js +++ b/test/function/samples/deprecated/preserveModules/invalid-default-export-mode/_config.js @@ -11,6 +11,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"default" was specified for "output.exports", but entry module "lib.js" has the following exports: value' + '"default" was specified for "output.exports", but entry module "lib.js" has the following exports: "value"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/deprecated/preserveModules/invalid-none-export-mode/_config.js b/test/function/samples/deprecated/preserveModules/invalid-none-export-mode/_config.js index e9fadad6a3e..a28084d1be5 100644 --- a/test/function/samples/deprecated/preserveModules/invalid-none-export-mode/_config.js +++ b/test/function/samples/deprecated/preserveModules/invalid-none-export-mode/_config.js @@ -11,6 +11,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"none" was specified for "output.exports", but entry module "lib.js" has the following exports: value' + '"none" was specified for "output.exports", but entry module "lib.js" has the following exports: "value"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/deprecated/preserveModules/mixed-exports/_config.js b/test/function/samples/deprecated/preserveModules/mixed-exports/_config.js index be4b11c9385..753ff18daa2 100644 --- a/test/function/samples/deprecated/preserveModules/mixed-exports/_config.js +++ b/test/function/samples/deprecated/preserveModules/mixed-exports/_config.js @@ -1,4 +1,6 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_LIB1 = path.join(__dirname, 'lib1.js'); module.exports = { description: 'warns for mixed exports in all chunks when preserving modules', @@ -15,16 +17,16 @@ module.exports = { }, { code: 'MIXED_EXPORTS', - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, message: - 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning', + 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.', url: 'https://rollupjs.org/guide/en/#outputexports' }, { code: 'MIXED_EXPORTS', - id: path.join(__dirname, 'lib1.js'), + id: ID_LIB1, message: - 'Entry module "lib1.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning', + 'Entry module "lib1.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.', url: 'https://rollupjs.org/guide/en/#outputexports' } ] diff --git a/test/function/samples/does-not-hang-on-missing-module/_config.js b/test/function/samples/does-not-hang-on-missing-module/_config.js index 7adccb63dd1..913a5851e76 100644 --- a/test/function/samples/does-not-hang-on-missing-module/_config.js +++ b/test/function/samples/does-not-hang-on-missing-module/_config.js @@ -1,14 +1,17 @@ const assert = require('assert'); +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'does not hang on missing module (#53)', warnings: [ { code: 'UNRESOLVED_IMPORT', - importer: 'main.js', - source: 'unlessYouCreatedThisFileForSomeReason', - message: `'unlessYouCreatedThisFileForSomeReason' is imported by main.js, but could not be resolved – treating it as an external dependency`, - url: `https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency` + exporter: 'unlessYouCreatedThisFileForSomeReason', + id: ID_MAIN, + message: + '"unlessYouCreatedThisFileForSomeReason" is imported by "main.js", but could not be resolved – treating it as an external dependency.', + url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency' } ], runtimeError(error) { diff --git a/test/function/samples/double-default-export/_config.js b/test/function/samples/double-default-export/_config.js index ba5b0fc007d..50b7557aad7 100644 --- a/test/function/samples/double-default-export/_config.js +++ b/test/function/samples/double-default-export/_config.js @@ -1,12 +1,11 @@ const path = require('path'); +const ID_FOO = path.join(__dirname, 'foo.js'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'throws on double default exports', error: { - code: 'PARSE_ERROR', - message: `Duplicate export 'default'`, - id: path.join(__dirname, 'foo.js'), - parserError: { + cause: { loc: { column: 7, line: 2 @@ -15,10 +14,13 @@ module.exports = { pos: 25, raisedAt: 34 }, + code: 'PARSE_ERROR', + message: `Duplicate export 'default'`, + id: ID_FOO, pos: 25, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], + watchFiles: [ID_FOO, ID_MAIN], loc: { - file: path.join(__dirname, 'foo.js'), + file: ID_FOO, line: 2, column: 7 }, diff --git a/test/function/samples/double-named-export/_config.js b/test/function/samples/double-named-export/_config.js index e3cd81614b7..210f9fa1da0 100644 --- a/test/function/samples/double-named-export/_config.js +++ b/test/function/samples/double-named-export/_config.js @@ -1,12 +1,11 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'throws on duplicate named exports', error: { - code: 'PARSE_ERROR', - message: `Duplicate export 'foo'`, - id: path.join(__dirname, 'foo.js'), - parserError: { + cause: { loc: { column: 9, line: 3 @@ -15,10 +14,13 @@ module.exports = { pos: 38, raisedAt: 43 }, + code: 'PARSE_ERROR', + message: `Duplicate export 'foo'`, + id: ID_FOO, pos: 38, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], + watchFiles: [ID_FOO, ID_MAIN], loc: { - file: path.join(__dirname, 'foo.js'), + file: ID_FOO, line: 3, column: 9 }, diff --git a/test/function/samples/double-named-reexport/_config.js b/test/function/samples/double-named-reexport/_config.js index 1521e9eb0d8..725af1a226e 100644 --- a/test/function/samples/double-named-reexport/_config.js +++ b/test/function/samples/double-named-reexport/_config.js @@ -1,12 +1,11 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'throws on duplicate named exports', error: { - code: 'PARSE_ERROR', - message: `Duplicate export 'foo'`, - id: path.join(__dirname, 'foo.js'), - parserError: { + cause: { loc: { column: 9, line: 3 @@ -15,10 +14,13 @@ module.exports = { pos: 38, raisedAt: 43 }, + code: 'PARSE_ERROR', + message: `Duplicate export 'foo'`, + id: ID_FOO, pos: 38, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], + watchFiles: [ID_FOO, ID_MAIN], loc: { - file: path.join(__dirname, 'foo.js'), + file: ID_FOO, line: 3, column: 9 }, diff --git a/test/function/samples/duplicate-import-fails/_config.js b/test/function/samples/duplicate-import-fails/_config.js index 71345e647c7..faca8f584de 100644 --- a/test/function/samples/duplicate-import-fails/_config.js +++ b/test/function/samples/duplicate-import-fails/_config.js @@ -1,12 +1,10 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'disallows duplicate imports', error: { - code: 'PARSE_ERROR', - message: `Identifier 'a' has already been declared`, - id: path.join(__dirname, 'main.js'), - parserError: { + cause: { loc: { column: 9, line: 2 @@ -15,10 +13,13 @@ module.exports = { pos: 36, raisedAt: 39 }, + code: 'PARSE_ERROR', + message: `Identifier 'a' has already been declared`, + id: ID_MAIN, pos: 36, - watchFiles: [path.join(__dirname, 'main.js')], + watchFiles: [ID_MAIN], loc: { - file: path.join(__dirname, 'main.js'), + file: ID_MAIN, line: 2, column: 9 }, diff --git a/test/function/samples/duplicate-import-specifier-fails/_config.js b/test/function/samples/duplicate-import-specifier-fails/_config.js index 64d88e09991..362162b7390 100644 --- a/test/function/samples/duplicate-import-specifier-fails/_config.js +++ b/test/function/samples/duplicate-import-specifier-fails/_config.js @@ -1,12 +1,10 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'disallows duplicate import specifiers', error: { - code: 'PARSE_ERROR', - message: `Identifier 'a' has already been declared`, - id: path.join(__dirname, 'main.js'), - parserError: { + cause: { loc: { column: 12, line: 1 @@ -15,10 +13,13 @@ module.exports = { pos: 12, raisedAt: 15 }, + code: 'PARSE_ERROR', + message: `Identifier 'a' has already been declared`, + id: ID_MAIN, pos: 12, - watchFiles: [path.join(__dirname, 'main.js')], + watchFiles: [ID_MAIN], loc: { - file: path.join(__dirname, 'main.js'), + file: ID_MAIN, line: 1, column: 12 }, diff --git a/test/function/samples/dynamic-import-not-found/_config.js b/test/function/samples/dynamic-import-not-found/_config.js index d97d427d0f7..7b365ac9340 100644 --- a/test/function/samples/dynamic-import-not-found/_config.js +++ b/test/function/samples/dynamic-import-not-found/_config.js @@ -1,3 +1,6 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); + module.exports = { description: 'warns if a dynamic import is not found', context: { @@ -10,10 +13,10 @@ module.exports = { warnings: [ { code: 'UNRESOLVED_IMPORT', - importer: 'main.js', + exporter: 'mod', + id: ID_MAIN, message: - "'mod' is imported by main.js, but could not be resolved – treating it as an external dependency", - source: 'mod', + '"mod" is imported by "main.js", but could not be resolved – treating it as an external dependency.', url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency' } ] diff --git a/test/function/samples/dynamic-import-relative-not-found/_config.js b/test/function/samples/dynamic-import-relative-not-found/_config.js index 5b8631590c6..bbf05776fcb 100644 --- a/test/function/samples/dynamic-import-relative-not-found/_config.js +++ b/test/function/samples/dynamic-import-relative-not-found/_config.js @@ -1,10 +1,13 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'throws if a dynamic relative import is not found', error: { code: 'UNRESOLVED_IMPORT', - message: `Could not resolve './mod' from main.js`, - watchFiles: [path.join(__dirname, 'main.js')] + exporter: './mod', + id: ID_MAIN, + message: 'Could not resolve "./mod" from "main.js"', + watchFiles: [ID_MAIN] } }; diff --git a/test/function/samples/emit-file/chunk-not-found/_config.js b/test/function/samples/emit-file/chunk-not-found/_config.js index 9c0df8d775d..5c1d4443d1e 100644 --- a/test/function/samples/emit-file/chunk-not-found/_config.js +++ b/test/function/samples/emit-file/chunk-not-found/_config.js @@ -1,4 +1,5 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'Throws if an emitted entry chunk cannot be resolved', @@ -12,7 +13,7 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry module (not-found.js).', - watchFiles: [path.join(__dirname, 'main.js')] + watchFiles: [ID_MAIN], + message: 'Could not resolve entry module "not-found.js".' } }; diff --git a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js index 2bc6bf9bff6..efbee59b76e 100644 --- a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js +++ b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js @@ -1,5 +1,7 @@ const path = require('path'); const MagicString = require('magic-string'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_EMPTY = path.join(__dirname, 'empty.js'); module.exports = { description: 'error after transform should throw with correct location of file', @@ -19,15 +21,16 @@ module.exports = { ] }, error: { + binding: 'default', code: 'MISSING_EXPORT', - message: `'default' is not exported by empty.js, imported by main.js`, - id: path.join(__dirname, 'main.js'), + exporter: ID_EMPTY, + id: ID_MAIN, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', pos: 44, - watchFiles: [path.join(__dirname, 'empty.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 1, - column: 7 + column: 7, + file: ID_MAIN, + line: 1 }, frame: ` 1: import a from './empty.js'; @@ -35,6 +38,7 @@ module.exports = { 2: 3: Object.assign({}, a); `, - url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` + watchFiles: [ID_EMPTY, ID_MAIN], + message: '"default" is not exported by "empty.js", imported by "main.js".' } }; diff --git a/test/function/samples/error-missing-umd-name/_config.js b/test/function/samples/error-missing-umd-name/_config.js index 3a722d59f6d..3a8bda77821 100644 --- a/test/function/samples/error-missing-umd-name/_config.js +++ b/test/function/samples/error-missing-umd-name/_config.js @@ -4,6 +4,7 @@ module.exports = { generateError: { code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', message: - 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.' + 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.', + url: 'https://rollupjs.org/guide/en/#outputname' } }; diff --git a/test/function/samples/error-parse-json/_config.js b/test/function/samples/error-parse-json/_config.js index 118bb6df977..e22195450f4 100644 --- a/test/function/samples/error-parse-json/_config.js +++ b/test/function/samples/error-parse-json/_config.js @@ -1,33 +1,35 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_JSON = path.join(__dirname, 'file.json'); module.exports = { description: 'throws with an extended error message when failing to parse a file with ".json" extension', error: { - code: 'PARSE_ERROR', - message: 'Unexpected token (Note that you need @rollup/plugin-json to import JSON files)', - id: path.join(__dirname, 'file.json'), - parserError: { + cause: { + pos: 10, loc: { - column: 8, - line: 2 + line: 2, + column: 8 }, - message: 'Unexpected token (2:8)', - pos: 10, - raisedAt: 11 + raisedAt: 11, + message: 'Unexpected token (2:8)' }, + code: 'PARSE_ERROR', + id: ID_JSON, pos: 10, - watchFiles: [path.join(__dirname, 'file.json'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'file.json'), - line: 2, - column: 8 + column: 8, + file: ID_JSON, + line: 2 }, frame: ` 1: { 2: "JSON": "is not really JavaScript" ^ 3: } - ` + `, + watchFiles: [ID_JSON, ID_MAIN], + message: 'Unexpected token (Note that you need @rollup/plugin-json to import JSON files)' } }; diff --git a/test/function/samples/error-parse-unknown-extension/_config.js b/test/function/samples/error-parse-unknown-extension/_config.js index eca522178fe..3ff17521c30 100644 --- a/test/function/samples/error-parse-unknown-extension/_config.js +++ b/test/function/samples/error-parse-unknown-extension/_config.js @@ -1,34 +1,35 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_CSS = path.join(__dirname, 'file.css'); module.exports = { description: 'throws with an extended error message when failing to parse a file without .(m)js extension', error: { - code: 'PARSE_ERROR', - message: - 'Unexpected token (Note that you need plugins to import files that are not JavaScript)', - id: path.join(__dirname, 'file.css'), - parserError: { + cause: { + pos: 0, loc: { - column: 0, - line: 1 + line: 1, + column: 0 }, - message: 'Unexpected token (1:0)', - pos: 0, - raisedAt: 1 + raisedAt: 1, + message: 'Unexpected token (1:0)' }, + code: 'PARSE_ERROR', + id: ID_CSS, pos: 0, - watchFiles: [path.join(__dirname, 'file.css'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'file.css'), - line: 1, - column: 0 + column: 0, + file: ID_CSS, + line: 1 }, frame: ` 1: .special-class { ^ 2: color: black; 3: } - ` + `, + watchFiles: [ID_CSS, ID_MAIN], + message: 'Unexpected token (Note that you need plugins to import files that are not JavaScript)' } }; diff --git a/test/function/samples/export-not-at-top-level-fails/_config.js b/test/function/samples/export-not-at-top-level-fails/_config.js index da4885365aa..fa3abf35eec 100644 --- a/test/function/samples/export-not-at-top-level-fails/_config.js +++ b/test/function/samples/export-not-at-top-level-fails/_config.js @@ -1,32 +1,33 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'disallows non-top-level exports', error: { - code: 'PARSE_ERROR', - message: `'import' and 'export' may only appear at the top level`, - id: path.join(__dirname, 'main.js'), - parserError: { + cause: { + pos: 19, loc: { - column: 2, - line: 2 + line: 2, + column: 2 }, - message: "'import' and 'export' may only appear at the top level (2:2)", - pos: 19, - raisedAt: 25 + raisedAt: 25, + message: "'import' and 'export' may only appear at the top level (2:2)" }, + code: 'PARSE_ERROR', + id: ID_MAIN, pos: 19, - watchFiles: [path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 2, - column: 2 + column: 2, + file: ID_MAIN, + line: 2 }, frame: ` 1: function foo() { 2: export { foo }; ^ 3: } - ` + `, + watchFiles: [ID_MAIN], + message: "'import' and 'export' may only appear at the top level" } }; diff --git a/test/function/samples/export-type-mismatch-b/_config.js b/test/function/samples/export-type-mismatch-b/_config.js index 08b7d704027..c20e8a48bec 100644 --- a/test/function/samples/export-type-mismatch-b/_config.js +++ b/test/function/samples/export-type-mismatch-b/_config.js @@ -3,8 +3,8 @@ module.exports = { options: { output: { exports: 'blah' } }, generateError: { code: 'INVALID_EXPORT_OPTION', + url: 'https://rollupjs.org/guide/en/#outputexports', message: - '"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "blah"', - url: 'https://rollupjs.org/guide/en/#outputexports' + '"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "blah".' } }; diff --git a/test/function/samples/export-type-mismatch-c/_config.js b/test/function/samples/export-type-mismatch-c/_config.js index 4c19ef8fc39..5e74c756719 100644 --- a/test/function/samples/export-type-mismatch-c/_config.js +++ b/test/function/samples/export-type-mismatch-c/_config.js @@ -4,6 +4,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"none" was specified for "output.exports", but entry module "main.js" has the following exports: default' + '"none" was specified for "output.exports", but entry module "main.js" has the following exports: "default"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/export-type-mismatch/_config.js b/test/function/samples/export-type-mismatch/_config.js index 1020793bb76..86f644c4f46 100644 --- a/test/function/samples/export-type-mismatch/_config.js +++ b/test/function/samples/export-type-mismatch/_config.js @@ -4,6 +4,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"default" was specified for "output.exports", but entry module "main.js" has the following exports: foo' + '"default" was specified for "output.exports", but entry module "main.js" has the following exports: "foo"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/external-conflict/_config.js b/test/function/samples/external-conflict/_config.js index e2c34dc1f36..92f9481add8 100644 --- a/test/function/samples/external-conflict/_config.js +++ b/test/function/samples/external-conflict/_config.js @@ -1,4 +1,5 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'external paths from custom resolver remain external (#633)', @@ -17,8 +18,8 @@ module.exports = { }, error: { code: 'INVALID_EXTERNAL_ID', + watchFiles: [ID_MAIN, 'dep'], message: - "'dep' is imported as an external by dep, but is already an existing non-external module id.", - watchFiles: [path.join(__dirname, 'main.js'), 'dep'] + '"dep" is imported as an external by "dep", but is already an existing non-external module id.' } }; diff --git a/test/function/samples/external-entry-point-object/_config.js b/test/function/samples/external-entry-point-object/_config.js index 5f27f7b99ac..5b74aaf2dc9 100644 --- a/test/function/samples/external-entry-point-object/_config.js +++ b/test/function/samples/external-entry-point-object/_config.js @@ -9,6 +9,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external (main.js).` + message: 'Entry module "main.js" cannot be external.' } }; diff --git a/test/function/samples/external-entry-point/_config.js b/test/function/samples/external-entry-point/_config.js index ce44d387343..1e7921b6115 100644 --- a/test/function/samples/external-entry-point/_config.js +++ b/test/function/samples/external-entry-point/_config.js @@ -9,6 +9,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external (main.js).` + message: 'Entry module "main.js" cannot be external.' } }; diff --git a/test/function/samples/fallback-on-warn/_config.js b/test/function/samples/fallback-on-warn/_config.js index ee7da5de099..38faf960af0 100644 --- a/test/function/samples/fallback-on-warn/_config.js +++ b/test/function/samples/fallback-on-warn/_config.js @@ -14,7 +14,7 @@ module.exports = { after() { console.warn = oldConsoleWarn; assert.deepStrictEqual(warnings, [ - 'Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification' + 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.' ]); } }; diff --git a/test/function/samples/import-not-at-top-level-fails/_config.js b/test/function/samples/import-not-at-top-level-fails/_config.js index 7fd52d4cde7..069886f99f1 100644 --- a/test/function/samples/import-not-at-top-level-fails/_config.js +++ b/test/function/samples/import-not-at-top-level-fails/_config.js @@ -1,32 +1,33 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'disallows non-top-level imports', error: { - code: 'PARSE_ERROR', - message: `'import' and 'export' may only appear at the top level`, - id: path.join(__dirname, 'main.js'), - parserError: { + cause: { + pos: 19, loc: { - column: 2, - line: 2 + line: 2, + column: 2 }, - message: "'import' and 'export' may only appear at the top level (2:2)", - pos: 19, - raisedAt: 25 + raisedAt: 25, + message: "'import' and 'export' may only appear at the top level (2:2)" }, + code: 'PARSE_ERROR', + id: ID_MAIN, pos: 19, - watchFiles: [path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 2, - column: 2 + column: 2, + file: ID_MAIN, + line: 2 }, frame: ` 1: function foo() { 2: import foo from './foo.js'; ^ 3: } - ` + `, + watchFiles: [ID_MAIN], + message: "'import' and 'export' may only appear at the top level" } }; diff --git a/test/function/samples/import-of-unexported-fails/_config.js b/test/function/samples/import-of-unexported-fails/_config.js index 285d0e71d07..5abe6d62979 100644 --- a/test/function/samples/import-of-unexported-fails/_config.js +++ b/test/function/samples/import-of-unexported-fails/_config.js @@ -1,17 +1,20 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_EMPTY = path.join(__dirname, 'empty.js'); module.exports = { description: 'marking an imported, but unexported, identifier should throw', error: { + binding: 'default', code: 'MISSING_EXPORT', - message: `'default' is not exported by empty.js, imported by main.js`, - id: path.join(__dirname, 'main.js'), + exporter: ID_EMPTY, + id: ID_MAIN, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', pos: 7, - watchFiles: [path.join(__dirname, 'empty.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 1, - column: 7 + column: 7, + file: ID_MAIN, + line: 1 }, frame: ` 1: import a from './empty.js'; @@ -19,6 +22,7 @@ module.exports = { 2: 3: a(); `, - url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` + watchFiles: [ID_EMPTY, ID_MAIN], + message: '"default" is not exported by "empty.js", imported by "main.js".' } }; diff --git a/test/function/samples/interop-default-only-named-import/_config.js b/test/function/samples/interop-default-only-named-import/_config.js index bc378cbebf9..ddaef7ac2c9 100644 --- a/test/function/samples/interop-default-only-named-import/_config.js +++ b/test/function/samples/interop-default-only-named-import/_config.js @@ -8,9 +8,9 @@ module.exports = { }, generateError: { code: 'UNEXPECTED_NAMED_IMPORT', - id: 'external', + exporter: 'external', + url: 'https://rollupjs.org/guide/en/#outputinterop', message: - 'The named export "foo" was imported from the external module external even though its interop type is "defaultOnly". Either remove or change this import or change the value of the "output.interop" option.', - url: 'https://rollupjs.org/guide/en/#outputinterop' + 'The named export "foo" was imported from the external module "external" even though its interop type is "defaultOnly". Either remove or change this import or change the value of the "output.interop" option.' } }; diff --git a/test/function/samples/interop-default-only-named-reexport/_config.js b/test/function/samples/interop-default-only-named-reexport/_config.js index aab5666562e..fe0433e13c4 100644 --- a/test/function/samples/interop-default-only-named-reexport/_config.js +++ b/test/function/samples/interop-default-only-named-reexport/_config.js @@ -8,9 +8,9 @@ module.exports = { }, generateError: { code: 'UNEXPECTED_NAMED_IMPORT', - id: 'external', + exporter: 'external', + url: 'https://rollupjs.org/guide/en/#outputinterop', message: - 'The named export "foo" was reexported from the external module external even though its interop type is "defaultOnly". Either remove or change this reexport or change the value of the "output.interop" option.', - url: 'https://rollupjs.org/guide/en/#outputinterop' + 'The named export "foo" was reexported from the external module "external" even though its interop type is "defaultOnly". Either remove or change this reexport or change the value of the "output.interop" option.' } }; diff --git a/test/function/samples/interop-default-only-namespace-reexport/_config.js b/test/function/samples/interop-default-only-namespace-reexport/_config.js index 71486618f9c..0ad7f4e0d52 100644 --- a/test/function/samples/interop-default-only-namespace-reexport/_config.js +++ b/test/function/samples/interop-default-only-namespace-reexport/_config.js @@ -9,9 +9,9 @@ module.exports = { warnings: [ { code: 'UNEXPECTED_NAMED_IMPORT', - id: 'external', + exporter: 'external', message: - 'There was a namespace "*" reexport from the external module external even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.', + 'There was a namespace "*" reexport from the external module "external" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.', url: 'https://rollupjs.org/guide/en/#outputinterop' } ] diff --git a/test/function/samples/invalid-addon-hook/_config.js b/test/function/samples/invalid-addon-hook/_config.js index 95617db72ea..beb5cdea593 100644 --- a/test/function/samples/invalid-addon-hook/_config.js +++ b/test/function/samples/invalid-addon-hook/_config.js @@ -8,6 +8,6 @@ module.exports = { generateError: { code: 'ADDON_ERROR', message: - 'Could not retrieve intro. Check configuration of plugin at position 1.\n\tError Message: Error running plugin hook intro for plugin at position 1, expected a string, a function hook or an object with a "handler" string or function.' + 'Could not retrieve "intro". Check configuration of plugin "at position 1".\n\tError Message: Error running plugin hook "intro" for plugin "at position 1", expected a string, a function hook or an object with a "handler" string or function.' } }; diff --git a/test/function/samples/invalid-default-export-mode/_config.js b/test/function/samples/invalid-default-export-mode/_config.js index 84f919bc080..ba6ccd9e84a 100644 --- a/test/function/samples/invalid-default-export-mode/_config.js +++ b/test/function/samples/invalid-default-export-mode/_config.js @@ -8,6 +8,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"default" was specified for "output.exports", but entry module "main.js" has the following exports: default, foo' + '"default" was specified for "output.exports", but entry module "main.js" has the following exports: "default" and "foo"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/invalid-top-level-await/_config.js b/test/function/samples/invalid-top-level-await/_config.js index f7ed11adada..387bada591a 100644 --- a/test/function/samples/invalid-top-level-await/_config.js +++ b/test/function/samples/invalid-top-level-await/_config.js @@ -1,11 +1,12 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'throws for invalid top-level-await format', generateError: { code: 'INVALID_TLA_FORMAT', + id: ID_MAIN, message: - 'Module format cjs does not support top-level await. Use the "es" or "system" output formats rather.', - id: path.join(__dirname, 'main.js') + 'Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather.' } }; diff --git a/test/function/samples/load-resolve-dependencies/_config.js b/test/function/samples/load-resolve-dependencies/_config.js index dcf1a498f7d..9351563a1b9 100644 --- a/test/function/samples/load-resolve-dependencies/_config.js +++ b/test/function/samples/load-resolve-dependencies/_config.js @@ -1,5 +1,8 @@ const assert = require('assert'); const path = require('path'); +const ID_FIRST = path.join(__dirname, 'first.js'); +const ID_SECOND = path.join(__dirname, 'second.js'); +const ID_THIRD = path.join(__dirname, 'third.js'); const DYNAMIC_IMPORT_PROXY_PREFIX = '\0dynamic-import:'; const chunks = []; @@ -9,12 +12,10 @@ module.exports = { async exports(exports) { assert.deepStrictEqual(chunks, []); const { importSecond } = await exports.importFirst(); - const expectedFirstChunk = ['first.js', 'second.js', 'third.js'].map(name => - path.join(__dirname, name) - ); + const expectedFirstChunk = [ID_FIRST, ID_SECOND, ID_THIRD]; assert.deepStrictEqual(chunks, [expectedFirstChunk]); await importSecond(); - const expectedSecondChunk = ['second.js', 'third.js'].map(name => path.join(__dirname, name)); + const expectedSecondChunk = [ID_SECOND, ID_THIRD]; assert.deepStrictEqual(chunks, [expectedFirstChunk, expectedSecondChunk]); }, options: { @@ -85,8 +86,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['second.js', 'third.js', 'second.js'], - importer: 'second.js', + ids: [ID_SECOND, ID_THIRD, ID_SECOND], message: 'Circular dependency: second.js -> third.js -> second.js' } ] diff --git a/test/function/samples/load-returns-string-or-null/_config.js b/test/function/samples/load-returns-string-or-null/_config.js index 112cf25d691..f5c7c522b7f 100644 --- a/test/function/samples/load-returns-string-or-null/_config.js +++ b/test/function/samples/load-returns-string-or-null/_config.js @@ -1,4 +1,5 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'throws error if load returns something wacky', @@ -14,7 +15,8 @@ module.exports = { }, error: { code: 'BAD_LOADER', - message: `Error loading main.js: plugin load hook should return a string, a { code, map } object, or nothing/null`, - watchFiles: [path.join(__dirname, 'main.js')] + watchFiles: [ID_MAIN], + message: + 'Error loading "main.js": plugin load hook should return a string, a { code, map } object, or nothing/null.' } }; diff --git a/test/function/samples/manual-chunks-conflict/_config.js b/test/function/samples/manual-chunks-conflict/_config.js index a3f06ae895c..4773d7a0fad 100644 --- a/test/function/samples/manual-chunks-conflict/_config.js +++ b/test/function/samples/manual-chunks-conflict/_config.js @@ -11,6 +11,6 @@ module.exports = { }, generateError: { code: 'INVALID_CHUNK', - message: `Cannot assign dep.js to the "dep2" chunk as it is already in the "dep1" chunk.` + message: 'Cannot assign "dep.js" to the "dep2" chunk as it is already in the "dep1" chunk.' } }; diff --git a/test/function/samples/module-level-directive/_config.js b/test/function/samples/module-level-directive/_config.js index fd2268f6589..3706f613343 100644 --- a/test/function/samples/module-level-directive/_config.js +++ b/test/function/samples/module-level-directive/_config.js @@ -1,21 +1,25 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'module level directives should produce warnings', warnings: [ { code: 'MODULE_LEVEL_DIRECTIVE', - message: "Module level directives cause errors when bundled, 'use asm' was ignored.", + id: ID_MAIN, + message: + 'Module level directives cause errors when bundled, "use asm" in "main.js" was ignored.', pos: 0, - id: path.join(__dirname, 'main.js'), loc: { - file: path.join(__dirname, 'main.js'), - line: 1, - column: 0 + column: 0, + file: ID_MAIN, + line: 1 }, frame: ` - 1: "use asm";\n ^\n2:\n3: export default 1; - ` + 1: "use asm"; + ^ + 2: + 3: export default 1;` } ] }; diff --git a/test/function/samples/module-side-effects/external-false/_config.js b/test/function/samples/module-side-effects/external-false/_config.js index e54cba85b91..95584df048d 100644 --- a/test/function/samples/module-side-effects/external-false/_config.js +++ b/test/function/samples/module-side-effects/external-false/_config.js @@ -1,5 +1,7 @@ const assert = require('assert'); const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); + const sideEffects = []; module.exports = { @@ -45,10 +47,10 @@ module.exports = { warnings: [ { code: 'UNRESOLVED_IMPORT', - importer: 'main.js', + exporter: 'implicit-external', + id: ID_MAIN, message: - "'implicit-external' is imported by main.js, but could not be resolved – treating it as an external dependency", - source: 'implicit-external', + '"implicit-external" is imported by "main.js", but could not be resolved – treating it as an external dependency.', url: 'https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency' } ] diff --git a/test/function/samples/module-tree/_config.js b/test/function/samples/module-tree/_config.js index b525df038a4..b98a56964bb 100644 --- a/test/function/samples/module-tree/_config.js +++ b/test/function/samples/module-tree/_config.js @@ -34,9 +34,9 @@ module.exports = { }, warnings: [ { - chunkName: 'main', code: 'EMPTY_BUNDLE', - message: 'Generated an empty chunk: "main"' + message: 'Generated an empty chunk: "main".', + names: ['main'] } ] }; diff --git a/test/function/samples/namespace-missing-export/_config.js b/test/function/samples/namespace-missing-export/_config.js index 9381fe1d17a..6712e8868b3 100644 --- a/test/function/samples/namespace-missing-export/_config.js +++ b/test/function/samples/namespace-missing-export/_config.js @@ -1,28 +1,28 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_EMPTY = path.join(__dirname, 'empty.js'); module.exports = { description: 'replaces missing namespace members with undefined and warns about them', warnings: [ { + binding: 'foo', code: 'MISSING_EXPORT', - exporter: 'empty.js', - importer: 'main.js', - id: path.join(__dirname, 'main.js'), - missing: 'foo', - message: `'foo' is not exported by 'empty.js'`, + exporter: ID_EMPTY, + id: ID_MAIN, + message: '"foo" is not exported by "empty.js", imported by "main.js".', + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', pos: 61, loc: { - file: require('path').resolve(__dirname, 'main.js'), - line: 3, - column: 25 + column: 25, + file: ID_MAIN, + line: 3 }, frame: ` 1: import * as mod from './empty.js'; 2: 3: assert.equal( typeof mod.foo, 'undefined' ); - ^ - `, - url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` + ^` } ] }; diff --git a/test/function/samples/namespace-reassign-import-fails/_config.js b/test/function/samples/namespace-reassign-import-fails/_config.js index 752f319698f..4f89a5e533e 100644 --- a/test/function/samples/namespace-reassign-import-fails/_config.js +++ b/test/function/samples/namespace-reassign-import-fails/_config.js @@ -1,8 +1,8 @@ const assert = require('assert'); const path = require('path'); const { assertIncludes } = require('../../../utils.js'); - const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'warns for reassignments to namespace exports', @@ -12,60 +12,56 @@ module.exports = { }, warnings: [ { + binding: 'bar', code: 'MISSING_EXPORT', - exporter: 'foo.js', - frame: ` - 2: - 3: exp.foo = 2; - 4: exp.bar = 3; - ^ - `, + exporter: ID_FOO, id: ID_MAIN, - importer: 'main.js', + message: '"bar" is not exported by "foo.js", imported by "main.js".', + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', + pos: 48, loc: { column: 4, file: ID_MAIN, line: 4 }, - message: "'bar' is not exported by 'foo.js'", - missing: 'bar', - pos: 48, - url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module' + frame: ` + 2: + 3: exp.foo = 2; + 4: exp.bar = 3; + ^` }, { - code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', - message: `Illegal reassignment to import 'exp'`, + code: 'ILLEGAL_REASSIGNMENT', + message: 'Illegal reassignment of import "exp" in "main.js".', id: ID_MAIN, pos: 31, loc: { + column: 0, file: ID_MAIN, - line: 3, - column: 0 + line: 3 }, frame: ` - 1: import * as exp from './foo'; - 2: - 3: exp.foo = 2; - ^ - 4: exp.bar = 3; - ` + 1: import * as exp from './foo'; + 2: + 3: exp.foo = 2; + ^ + 4: exp.bar = 3;` }, { - code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', - message: `Illegal reassignment to import 'exp'`, + code: 'ILLEGAL_REASSIGNMENT', + message: 'Illegal reassignment of import "exp" in "main.js".', id: ID_MAIN, pos: 44, loc: { + column: 0, file: ID_MAIN, - line: 4, - column: 0 + line: 4 }, frame: ` - 2: - 3: exp.foo = 2; - 4: exp.bar = 3; - ^ - ` + 2: + 3: exp.foo = 2; + 4: exp.bar = 3; + ^` } ], runtimeError(error) { diff --git a/test/function/samples/namespace-update-import-fails/_config.js b/test/function/samples/namespace-update-import-fails/_config.js index 5edbe40fca3..e6f344aa95d 100644 --- a/test/function/samples/namespace-update-import-fails/_config.js +++ b/test/function/samples/namespace-update-import-fails/_config.js @@ -1,6 +1,7 @@ const assert = require('assert'); const path = require('path'); const { assertIncludes } = require('../../../utils.js'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'disallows updates to namespace exports', @@ -9,21 +10,20 @@ module.exports = { }, warnings: [ { - code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', - message: `Illegal reassignment to import 'exp'`, - id: path.join(__dirname, 'main.js'), + code: 'ILLEGAL_REASSIGNMENT', + message: 'Illegal reassignment of import "exp" in "main.js".', + id: ID_MAIN, pos: 31, loc: { - file: path.join(__dirname, 'main.js'), - line: 3, - column: 0 + column: 0, + file: ID_MAIN, + line: 3 }, frame: ` - 1: import * as exp from './foo'; - 2: - 3: exp['foo']++; - ^ - ` + 1: import * as exp from './foo'; + 2: + 3: exp['foo']++; + ^` } ], runtimeError(error) { diff --git a/test/function/samples/nested-inlined-dynamic-import-2/_config.js b/test/function/samples/nested-inlined-dynamic-import-2/_config.js index 4a9ba8ce0f3..55b58c38e48 100644 --- a/test/function/samples/nested-inlined-dynamic-import-2/_config.js +++ b/test/function/samples/nested-inlined-dynamic-import-2/_config.js @@ -1,12 +1,14 @@ const assert = require('assert'); +const path = require('path'); +const ID_LIB1 = path.join(__dirname, 'lib1.js'); +const ID_LIB2 = path.join(__dirname, 'lib2.js'); module.exports = { description: 'deconflicts variables when nested dynamic imports are inlined', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['lib1.js', 'lib2.js', 'lib1.js'], - importer: 'lib1.js', + ids: [ID_LIB1, ID_LIB2, ID_LIB1], message: 'Circular dependency: lib1.js -> lib2.js -> lib1.js' } ], diff --git a/test/function/samples/no-relative-external/_config.js b/test/function/samples/no-relative-external/_config.js index 44f535fc148..cf7c21a5850 100644 --- a/test/function/samples/no-relative-external/_config.js +++ b/test/function/samples/no-relative-external/_config.js @@ -1,10 +1,13 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'missing relative imports are an error, not a warning', error: { code: 'UNRESOLVED_IMPORT', - message: `Could not resolve './missing.js' from main.js`, - watchFiles: [path.join(__dirname, 'main.js')] + exporter: './missing.js', + id: ID_MAIN, + watchFiles: [ID_MAIN], + message: 'Could not resolve "./missing.js" from "main.js"' } }; diff --git a/test/function/samples/non-function-hook-async/_config.js b/test/function/samples/non-function-hook-async/_config.js index bfba8d840ea..800df0aaa90 100644 --- a/test/function/samples/non-function-hook-async/_config.js +++ b/test/function/samples/non-function-hook-async/_config.js @@ -9,7 +9,7 @@ module.exports = { code: 'INVALID_PLUGIN_HOOK', hook: 'resolveId', message: - 'Error running plugin hook resolveId for plugin at position 1, expected a function hook or an object with a "handler" function.', + 'Error running plugin hook "resolveId" for plugin "at position 1", expected a function hook or an object with a "handler" function.', plugin: 'at position 1' } }; diff --git a/test/function/samples/non-function-hook-sync/_config.js b/test/function/samples/non-function-hook-sync/_config.js index 0349ba53f78..78f9af86212 100644 --- a/test/function/samples/non-function-hook-sync/_config.js +++ b/test/function/samples/non-function-hook-sync/_config.js @@ -9,7 +9,7 @@ module.exports = { code: 'INVALID_PLUGIN_HOOK', hook: 'outputOptions', message: - 'Error running plugin hook outputOptions for plugin at position 1, expected a function hook or an object with a "handler" function.', + 'Error running plugin hook "outputOptions" for plugin "at position 1", expected a function hook or an object with a "handler" function.', plugin: 'at position 1' } }; diff --git a/test/function/samples/paths-are-case-sensitive/_config.js b/test/function/samples/paths-are-case-sensitive/_config.js index b881cc3e830..c5b55e82323 100644 --- a/test/function/samples/paths-are-case-sensitive/_config.js +++ b/test/function/samples/paths-are-case-sensitive/_config.js @@ -1,10 +1,13 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'insists on correct casing for imports', error: { code: 'UNRESOLVED_IMPORT', - message: `Could not resolve './foo.js' from main.js`, - watchFiles: [path.join(__dirname, 'main.js')] + exporter: './foo.js', + id: ID_MAIN, + watchFiles: [ID_MAIN], + message: 'Could not resolve "./foo.js" from "main.js"' } }; diff --git a/test/function/samples/preload-cyclic-module/_config.js b/test/function/samples/preload-cyclic-module/_config.js index aa2d3c56173..ae981e2865b 100644 --- a/test/function/samples/preload-cyclic-module/_config.js +++ b/test/function/samples/preload-cyclic-module/_config.js @@ -1,10 +1,13 @@ +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_PROXY = path.join(__dirname, 'main.js?proxy'); + module.exports = { description: 'handles pre-loading a cyclic module in the resolveId hook', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'main.js?proxy', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_PROXY, ID_MAIN], message: 'Circular dependency: main.js -> main.js?proxy -> main.js' } ], diff --git a/test/function/samples/preserve-modules-circular-order/_config.js b/test/function/samples/preserve-modules-circular-order/_config.js index 7bd9f5d3bc5..ea633e7b8ac 100644 --- a/test/function/samples/preserve-modules-circular-order/_config.js +++ b/test/function/samples/preserve-modules-circular-order/_config.js @@ -1,4 +1,8 @@ const assert = require('assert'); +const path = require('path'); +const ID_INDEX = path.join(__dirname, 'index.js'); +const ID_DATA = path.join(__dirname, 'data.js'); +const ID_TAG = path.join(__dirname, 'tag.js'); const executionOrder = []; module.exports = { @@ -20,20 +24,17 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['data.js', 'tag.js', 'data.js'], - importer: 'data.js', + ids: [ID_DATA, ID_TAG, ID_DATA], message: 'Circular dependency: data.js -> tag.js -> data.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['data.js', 'tag.js', 'index.js', 'data.js'], - importer: 'data.js', + ids: [ID_DATA, ID_TAG, ID_INDEX, ID_DATA], message: 'Circular dependency: data.js -> tag.js -> index.js -> data.js' }, { code: 'CIRCULAR_DEPENDENCY', - cycle: ['tag.js', 'index.js', 'tag.js'], - importer: 'tag.js', + ids: [ID_TAG, ID_INDEX, ID_TAG], message: 'Circular dependency: tag.js -> index.js -> tag.js' } ] diff --git a/test/function/samples/preserve-modules/invalid-default-export-mode/_config.js b/test/function/samples/preserve-modules/invalid-default-export-mode/_config.js index 3256f5ca2b8..4b5155bbddb 100644 --- a/test/function/samples/preserve-modules/invalid-default-export-mode/_config.js +++ b/test/function/samples/preserve-modules/invalid-default-export-mode/_config.js @@ -10,6 +10,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"default" was specified for "output.exports", but entry module "lib.js" has the following exports: value' + '"default" was specified for "output.exports", but entry module "lib.js" has the following exports: "value"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/preserve-modules/invalid-none-export-mode/_config.js b/test/function/samples/preserve-modules/invalid-none-export-mode/_config.js index 8dfb14e480d..89dbdb2c820 100644 --- a/test/function/samples/preserve-modules/invalid-none-export-mode/_config.js +++ b/test/function/samples/preserve-modules/invalid-none-export-mode/_config.js @@ -10,6 +10,7 @@ module.exports = { generateError: { code: 'INVALID_EXPORT_OPTION', message: - '"none" was specified for "output.exports", but entry module "lib.js" has the following exports: value' + '"none" was specified for "output.exports", but entry module "lib.js" has the following exports: "value"', + url: 'https://rollupjs.org/guide/en/#outputexports' } }; diff --git a/test/function/samples/preserve-modules/mixed-exports/_config.js b/test/function/samples/preserve-modules/mixed-exports/_config.js index 523d0c0f19e..83d0b2baa36 100644 --- a/test/function/samples/preserve-modules/mixed-exports/_config.js +++ b/test/function/samples/preserve-modules/mixed-exports/_config.js @@ -1,4 +1,6 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_LIB1 = path.join(__dirname, 'lib1.js'); module.exports = { description: 'warns for mixed exports in all chunks when preserving modules', @@ -9,16 +11,16 @@ module.exports = { warnings: [ { code: 'MIXED_EXPORTS', - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, message: - 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning', + 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.', url: 'https://rollupjs.org/guide/en/#outputexports' }, { code: 'MIXED_EXPORTS', - id: path.join(__dirname, 'lib1.js'), + id: ID_LIB1, message: - 'Entry module "lib1.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning', + 'Entry module "lib1.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.', url: 'https://rollupjs.org/guide/en/#outputexports' } ] diff --git a/test/function/samples/reassign-import-fails/_config.js b/test/function/samples/reassign-import-fails/_config.js index 131fd8cf6c7..1fec3f1ed1b 100644 --- a/test/function/samples/reassign-import-fails/_config.js +++ b/test/function/samples/reassign-import-fails/_config.js @@ -1,24 +1,25 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'disallows assignments to imported bindings', error: { code: 'ILLEGAL_REASSIGNMENT', - message: `Illegal reassignment to import 'x'`, - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, pos: 113, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 8, - column: 0 + column: 0, + file: ID_MAIN, + line: 8 }, frame: ` 6: }); 7: 8: x = 10; - ^ - ` + ^`, + watchFiles: [ID_FOO, ID_MAIN], + message: 'Illegal reassignment of import "x" in "main.js".' } }; diff --git a/test/function/samples/reassign-import-not-at-top-level-fails/_config.js b/test/function/samples/reassign-import-not-at-top-level-fails/_config.js index 2292fb59041..a19fece2f1a 100644 --- a/test/function/samples/reassign-import-not-at-top-level-fails/_config.js +++ b/test/function/samples/reassign-import-not-at-top-level-fails/_config.js @@ -1,25 +1,26 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'disallows assignments to imported bindings not at the top level', error: { code: 'ILLEGAL_REASSIGNMENT', - message: `Illegal reassignment to import 'x'`, - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, pos: 95, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 7, - column: 2 + column: 2, + file: ID_MAIN, + line: 7 }, frame: ` 5: } 6: export function bar () { 7: x = 1; ^ - 8: } - ` + 8: }`, + watchFiles: [ID_FOO, ID_MAIN], + message: 'Illegal reassignment of import "x" in "main.js".' } }; diff --git a/test/function/samples/recursive-reexports/_config.js b/test/function/samples/recursive-reexports/_config.js index 1e1ce84b159..5814095b269 100644 --- a/test/function/samples/recursive-reexports/_config.js +++ b/test/function/samples/recursive-reexports/_config.js @@ -1,4 +1,8 @@ const assert = require('assert'); +const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_OTHER = path.join(__dirname, 'other.js'); + module.exports = { description: 'handles recursive namespace reexports', exports(exports) { @@ -7,8 +11,7 @@ module.exports = { warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['main.js', 'other.js', 'main.js'], - importer: 'main.js', + ids: [ID_MAIN, ID_OTHER, ID_MAIN], message: 'Circular dependency: main.js -> other.js -> main.js' } ] diff --git a/test/function/samples/reexport-missing-error/_config.js b/test/function/samples/reexport-missing-error/_config.js index d8922519654..33496d6b90d 100644 --- a/test/function/samples/reexport-missing-error/_config.js +++ b/test/function/samples/reexport-missing-error/_config.js @@ -1,22 +1,25 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_EMPTY = path.join(__dirname, 'empty.js'); module.exports = { description: 'reexporting a missing identifier should print an error', error: { + binding: 'foo', code: 'MISSING_EXPORT', - message: `'foo' is not exported by empty.js, imported by main.js`, - id: path.join(__dirname, 'main.js'), + exporter: ID_EMPTY, + id: ID_MAIN, + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', pos: 9, - watchFiles: [path.join(__dirname, 'empty.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 1, - column: 9 + column: 9, + file: ID_MAIN, + line: 1 }, frame: ` 1: export { foo as bar } from './empty.js'; - ^ - `, - url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module' + ^`, + watchFiles: [ID_EMPTY, ID_MAIN], + message: '"foo" is not exported by "empty.js", imported by "main.js".' } }; diff --git a/test/function/samples/shims-missing-exports/_config.js b/test/function/samples/shims-missing-exports/_config.js index 2f7d274efb3..4de19187328 100644 --- a/test/function/samples/shims-missing-exports/_config.js +++ b/test/function/samples/shims-missing-exports/_config.js @@ -1,3 +1,6 @@ +const path = require('path'); +const ID_DEP1 = path.join(__dirname, 'dep1.js'); + module.exports = { description: 'shims missing exports', options: { @@ -5,10 +8,10 @@ module.exports = { }, warnings: [ { + binding: 'missing', code: 'SHIMMED_EXPORT', - message: 'Missing export "missing" has been shimmed in module dep1.js.', - exporter: 'dep1.js', - exportName: 'missing' + exporter: ID_DEP1, + message: 'Missing export "missing" has been shimmed in module "dep1.js".' } ] }; diff --git a/test/function/samples/synthetic-named-exports/circular-synthetic-exports/_config.js b/test/function/samples/synthetic-named-exports/circular-synthetic-exports/_config.js index 2b492df4c07..f254197f828 100644 --- a/test/function/samples/synthetic-named-exports/circular-synthetic-exports/_config.js +++ b/test/function/samples/synthetic-named-exports/circular-synthetic-exports/_config.js @@ -1,4 +1,6 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_DEP = path.join(__dirname, 'dep.js'); module.exports = { description: 'handles circular synthetic exports', @@ -14,8 +16,9 @@ module.exports = { }, error: { code: 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', - id: path.join(__dirname, 'main.js'), - message: `Module "main.js" that is marked with 'syntheticNamedExports: "__synthetic"' needs an explicit export named "__synthetic" that does not reexport an unresolved named export of the same module.`, - watchFiles: [path.join(__dirname, 'dep.js'), path.join(__dirname, 'main.js')] + exporter: ID_MAIN, + watchFiles: [ID_DEP, ID_MAIN], + message: + 'Module "main.js" that is marked with `syntheticNamedExports: "__synthetic"` needs an explicit export named "__synthetic" that does not reexport an unresolved named export of the same module.' } }; diff --git a/test/function/samples/synthetic-named-exports/circular-synthetic-exports2/_config.js b/test/function/samples/synthetic-named-exports/circular-synthetic-exports2/_config.js index 5ed72a4ae8a..0d1b07a7aa4 100644 --- a/test/function/samples/synthetic-named-exports/circular-synthetic-exports2/_config.js +++ b/test/function/samples/synthetic-named-exports/circular-synthetic-exports2/_config.js @@ -1,10 +1,13 @@ +const path = require('path'); +const ID_DEP1 = path.join(__dirname, 'dep1.js'); +const ID_DEP2 = path.join(__dirname, 'dep2.js'); + module.exports = { description: 'handles circular synthetic exports', warnings: [ { code: 'CIRCULAR_DEPENDENCY', - cycle: ['dep1.js', 'dep2.js', 'dep1.js'], - importer: 'dep1.js', + ids: [ID_DEP1, ID_DEP2, ID_DEP1], message: 'Circular dependency: dep1.js -> dep2.js -> dep1.js' } ] diff --git a/test/function/samples/synthetic-named-exports/external-synthetic-exports/_config.js b/test/function/samples/synthetic-named-exports/external-synthetic-exports/_config.js index bd60de83d00..81b0089ad86 100644 --- a/test/function/samples/synthetic-named-exports/external-synthetic-exports/_config.js +++ b/test/function/samples/synthetic-named-exports/external-synthetic-exports/_config.js @@ -18,9 +18,8 @@ module.exports = { warnings: [ { code: 'EXTERNAL_SYNTHETIC_EXPORTS', - importer: 'main.js', - source: 'dep', - message: "External 'dep' can not have 'syntheticNamedExports' enabled." + exporter: 'dep', + message: 'External "dep" cannot have "syntheticNamedExports" enabled (imported by "main.js").' } ], context: { diff --git a/test/function/samples/synthetic-named-exports/synthetic-exports-need-default/_config.js b/test/function/samples/synthetic-named-exports/synthetic-exports-need-default/_config.js index 61282f02510..1922308a5f2 100644 --- a/test/function/samples/synthetic-named-exports/synthetic-exports-need-default/_config.js +++ b/test/function/samples/synthetic-named-exports/synthetic-exports-need-default/_config.js @@ -1,4 +1,6 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_DEP = path.join(__dirname, 'dep.js'); module.exports = { description: 'synthetic named exports modules need a default export', @@ -13,8 +15,9 @@ module.exports = { }, error: { code: 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', - id: path.join(__dirname, 'dep.js'), - message: `Module "dep.js" that is marked with 'syntheticNamedExports: true' needs a default export that does not reexport an unresolved named export of the same module.`, - watchFiles: [path.join(__dirname, 'dep.js'), path.join(__dirname, 'main.js')] + exporter: ID_DEP, + watchFiles: [ID_DEP, ID_MAIN], + message: + 'Module "dep.js" that is marked with `syntheticNamedExports: true` needs a default export that does not reexport an unresolved named export of the same module.' } }; diff --git a/test/function/samples/synthetic-named-exports/synthetic-exports-need-fallback-export/_config.js b/test/function/samples/synthetic-named-exports/synthetic-exports-need-fallback-export/_config.js index 0613924e218..f5003b95ccd 100644 --- a/test/function/samples/synthetic-named-exports/synthetic-exports-need-fallback-export/_config.js +++ b/test/function/samples/synthetic-named-exports/synthetic-exports-need-fallback-export/_config.js @@ -1,5 +1,6 @@ const path = require('path'); -const DEP_ID = path.join(__dirname, 'dep.js'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_DEP = path.join(__dirname, 'dep.js'); module.exports = { description: 'synthetic named exports modules need their fallback export', @@ -16,8 +17,9 @@ module.exports = { }, error: { code: 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', - id: DEP_ID, - message: `Module "dep.js" that is marked with 'syntheticNamedExports: "__synthetic"' needs an explicit export named "__synthetic" that does not reexport an unresolved named export of the same module.`, - watchFiles: [DEP_ID, path.join(__dirname, 'main.js')] + exporter: ID_DEP, + watchFiles: [ID_DEP, ID_MAIN], + message: + 'Module "dep.js" that is marked with `syntheticNamedExports: "__synthetic"` needs an explicit export named "__synthetic" that does not reexport an unresolved named export of the same module.' } }; diff --git a/test/function/samples/throws-not-found-module/_config.js b/test/function/samples/throws-not-found-module/_config.js index 5df6a0b9f81..e8802d59f05 100644 --- a/test/function/samples/throws-not-found-module/_config.js +++ b/test/function/samples/throws-not-found-module/_config.js @@ -1,10 +1,13 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'throws error if module is not found', error: { code: 'UNRESOLVED_IMPORT', - message: `Could not resolve './mod' from main.js`, - watchFiles: [path.join(__dirname, 'main.js')] + exporter: './mod', + id: ID_MAIN, + watchFiles: [ID_MAIN], + message: 'Could not resolve "./mod" from "main.js"' } }; diff --git a/test/function/samples/unused-import/_config.js b/test/function/samples/unused-import/_config.js index 683bec4976a..cf28e131ccf 100644 --- a/test/function/samples/unused-import/_config.js +++ b/test/function/samples/unused-import/_config.js @@ -1,4 +1,5 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'warns on unused imports ([#595])', @@ -13,10 +14,11 @@ module.exports = { warnings: [ { code: 'UNUSED_EXTERNAL_IMPORT', - source: 'external', - names: ['notused', 'neverused'], - message: `"notused" and "neverused" are imported from external module "external" but never used in "main.js".`, - sources: [path.resolve(__dirname, './main.js')] + exporter: 'external', + ids: [ID_MAIN], + message: + '"notused" and "neverused" are imported from external module "external" but never used in "main.js".', + names: ['notused', 'neverused'] } ] }; diff --git a/test/function/samples/update-expression-of-import-fails/_config.js b/test/function/samples/update-expression-of-import-fails/_config.js index d540cf5ca28..e913aa298ce 100644 --- a/test/function/samples/update-expression-of-import-fails/_config.js +++ b/test/function/samples/update-expression-of-import-fails/_config.js @@ -1,24 +1,25 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'disallows updates to imported bindings', error: { code: 'ILLEGAL_REASSIGNMENT', - message: `Illegal reassignment to import 'a'`, - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, pos: 28, - watchFiles: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'main.js')], loc: { - file: path.join(__dirname, 'main.js'), - line: 3, - column: 0 + column: 0, + file: ID_MAIN, + line: 3 }, frame: ` 1: import { a } from './foo'; 2: 3: a++; - ^ - ` + ^`, + watchFiles: [ID_FOO, ID_MAIN], + message: 'Illegal reassignment of import "a" in "main.js".' } }; diff --git a/test/function/samples/vars-with-init-in-dead-branch/_config.js b/test/function/samples/vars-with-init-in-dead-branch/_config.js index 897cf3d7a13..f0b620aaeb2 100644 --- a/test/function/samples/vars-with-init-in-dead-branch/_config.js +++ b/test/function/samples/vars-with-init-in-dead-branch/_config.js @@ -2,9 +2,9 @@ module.exports = { description: 'handles vars with init in dead branch (#1198)', warnings: [ { - chunkName: 'main', code: 'EMPTY_BUNDLE', - message: 'Generated an empty chunk: "main"' + message: 'Generated an empty chunk: "main".', + names: ['main'] } ] }; diff --git a/test/function/samples/warn-missing-iife-name/_config.js b/test/function/samples/warn-missing-iife-name/_config.js index 07c9331fb90..7019d565365 100644 --- a/test/function/samples/warn-missing-iife-name/_config.js +++ b/test/function/samples/warn-missing-iife-name/_config.js @@ -5,7 +5,8 @@ module.exports = { { code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', message: - 'If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.' + 'If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.', + url: 'https://rollupjs.org/guide/en/#outputname' } ] }; diff --git a/test/function/samples/warn-on-auto-named-default-exports/_config.js b/test/function/samples/warn-on-auto-named-default-exports/_config.js index a35384c07eb..40cb00bc46f 100644 --- a/test/function/samples/warn-on-auto-named-default-exports/_config.js +++ b/test/function/samples/warn-on-auto-named-default-exports/_config.js @@ -1,13 +1,14 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'warns if default and named exports are used in auto mode', warnings: [ { code: 'MIXED_EXPORTS', - id: path.join(__dirname, 'main.js'), + id: ID_MAIN, message: - 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning', + 'Entry module "main.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.', url: 'https://rollupjs.org/guide/en/#outputexports' } ] diff --git a/test/function/samples/warn-on-empty-bundle/_config.js b/test/function/samples/warn-on-empty-bundle/_config.js index 2b7303d550f..b4416af6431 100644 --- a/test/function/samples/warn-on-empty-bundle/_config.js +++ b/test/function/samples/warn-on-empty-bundle/_config.js @@ -2,9 +2,9 @@ module.exports = { description: 'warns if empty bundle is generated (#444)', warnings: [ { - chunkName: 'main', code: 'EMPTY_BUNDLE', - message: 'Generated an empty chunk: "main"' + message: 'Generated an empty chunk: "main".', + names: ['main'] } ] }; diff --git a/test/function/samples/warn-on-eval/_config.js b/test/function/samples/warn-on-eval/_config.js index ee1b2f5b875..cb68cad0d29 100644 --- a/test/function/samples/warn-on-eval/_config.js +++ b/test/function/samples/warn-on-eval/_config.js @@ -1,23 +1,24 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); module.exports = { description: 'warns about use of eval', warnings: [ { code: 'EVAL', - id: path.join(__dirname, 'main.js'), - message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`, + id: ID_MAIN, + message: + 'Use of eval in "main.js" is strongly discouraged as it poses security risks and may cause issues with minification.', + url: 'https://rollupjs.org/guide/en/#avoiding-eval', pos: 13, loc: { column: 13, - file: require('path').resolve(__dirname, 'main.js'), + file: ID_MAIN, line: 1 }, frame: ` 1: var result = eval( '1 + 1' ); - ^ - `, - url: 'https://rollupjs.org/guide/en/#avoiding-eval' + ^` } ] }; diff --git a/test/function/samples/warn-on-namespace-conflict/_config.js b/test/function/samples/warn-on-namespace-conflict/_config.js index 0f6139a3501..3d61fe17723 100644 --- a/test/function/samples/warn-on-namespace-conflict/_config.js +++ b/test/function/samples/warn-on-namespace-conflict/_config.js @@ -1,14 +1,18 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); +const ID_BAR = path.join(__dirname, 'bar.js'); module.exports = { description: 'warns on duplicate export * from', warnings: [ { + binding: 'foo', code: 'NAMESPACE_CONFLICT', - name: 'foo', - reexporter: path.join(__dirname, 'main.js'), - sources: [path.join(__dirname, 'foo.js'), path.join(__dirname, 'bar.js')], - message: `Conflicting namespaces: "main.js" re-exports "foo" from one of the modules "foo.js" and "bar.js" (will be ignored)` + ids: [ID_FOO, ID_BAR], + message: + 'Conflicting namespaces: "main.js" re-exports "foo" from one of the modules "foo.js" and "bar.js" (will be ignored).', + reexporter: ID_MAIN } ] }; diff --git a/test/function/samples/warn-on-unused-missing-imports/_config.js b/test/function/samples/warn-on-unused-missing-imports/_config.js index 1869ed89cc3..be9ea3d464f 100644 --- a/test/function/samples/warn-on-unused-missing-imports/_config.js +++ b/test/function/samples/warn-on-unused-missing-imports/_config.js @@ -1,26 +1,28 @@ const path = require('path'); +const ID_MAIN = path.join(__dirname, 'main.js'); +const ID_FOO = path.join(__dirname, 'foo.js'); module.exports = { description: 'warns on missing (but unused) imports', warnings: [ { - code: 'NON_EXISTENT_EXPORT', - id: path.join(__dirname, 'main.js'), - source: path.join(__dirname, 'foo.js'), - name: 'b', - message: `Non-existent export 'b' is imported from foo.js`, + binding: 'b', + code: 'MISSING_EXPORT', + exporter: ID_FOO, + id: ID_MAIN, + message: '"b" is not exported by "foo.js", imported by "main.js".', + url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', pos: 12, loc: { - file: path.join(__dirname, 'main.js'), - line: 1, - column: 12 + column: 12, + file: ID_MAIN, + line: 1 }, frame: ` 1: import { a, b } from './foo.js'; ^ 2: - 3: assert.equal( a, 42 ); - ` + 3: assert.equal( a, 42 );` } ] }; diff --git a/test/function/samples/warnings-to-string/_config.js b/test/function/samples/warnings-to-string/_config.js index fc39492df8b..8dfa16140b1 100644 --- a/test/function/samples/warnings-to-string/_config.js +++ b/test/function/samples/warnings-to-string/_config.js @@ -13,7 +13,7 @@ module.exports = { warnings(warnings) { assert.deepStrictEqual(warnings.map(String), [ '(test-plugin plugin) main.js (1:6) This might be removed', - 'Generated an empty chunk: "main"' + 'Generated an empty chunk: "main".' ]); } }; diff --git a/test/misc/iife.js b/test/misc/iife.js index d66eb65210f..74854ae2af3 100644 --- a/test/misc/iife.js +++ b/test/misc/iife.js @@ -106,7 +106,8 @@ describe('The IIFE wrapper with an illegal name', () => { compareError(error, { code: 'ILLEGAL_IDENTIFIER_AS_NAME', message: - 'Given name "1name" is not a legal JS identifier. If you need this, you can try "output.extend: true".' + 'Given name "1name" is not a legal JS identifier. If you need this, you can try "output.extend: true".', + url: 'https://rollupjs.org/guide/en/#outputextend' }) )); @@ -119,7 +120,8 @@ describe('The IIFE wrapper with an illegal name', () => { compareError(error, { code: 'ILLEGAL_IDENTIFIER_AS_NAME', message: - 'Given name "my=name" is not a legal JS identifier. If you need this, you can try "output.extend: true".' + 'Given name "my=name" is not a legal JS identifier. If you need this, you can try "output.extend: true".', + url: 'https://rollupjs.org/guide/en/#outputextend' }) )); diff --git a/test/misc/misc.js b/test/misc/misc.js index cf3210ec8c7..4bd9a93cb64 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -80,10 +80,11 @@ describe('misc', () => { assert.deepEqual(warnings, [ { code: 'MISSING_GLOBAL_NAME', - guess: '_', + id: 'lodash', message: - "No name was provided for external module 'lodash' in output.globals – guessing '_'", - source: 'lodash' + 'No name was provided for external module "lodash" in "output.globals" – guessing "_".', + names: ['_'], + url: 'https://rollupjs.org/guide/en/#outputglobals' } ]); }); @@ -271,7 +272,7 @@ console.log(x); }); } catch (err) { assert.notDeepStrictEqual(err.message, 'Maximum call stack size exceeded'); - assert.strictEqual(err.name, 'Error'); + assert.strictEqual(err.name, 'RollupError'); } }); diff --git a/test/misc/sanity-checks.js b/test/misc/sanity-checks.js index 1a36f02f680..1b4d8549a76 100644 --- a/test/misc/sanity-checks.js +++ b/test/misc/sanity-checks.js @@ -33,7 +33,7 @@ describe('sanity checks', () => { assert.equal(args[0].code, 'EVAL'); assert.equal( args[0].message, - 'Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification' + 'Use of eval in "x" is strongly discouraged as it poses security risks and may cause issues with minification.' ); assert.equal(typeof args[1], 'function'); }); diff --git a/test/utils.js b/test/utils.js index 13ea3014c99..71386d189f2 100644 --- a/test/utils.js +++ b/test/utils.js @@ -21,44 +21,32 @@ exports.wait = function wait(ms) { }; function normaliseError(error) { - delete error.stack; - delete error.toString; - if (error.watchFiles) { - error.watchFiles.sort(); + const clone = { ...error, message: error.message }; + delete clone.stack; + delete clone.toString; + if (clone.watchFiles) { + clone.watchFiles.sort(); } - return { ...error, message: error.message }; + if (clone.frame) { + clone.frame = clone.frame.replace(/\s+$/gm, ''); + } + if (clone.cause) { + clone.cause = normaliseError(clone.cause); + } + return clone; } exports.compareError = function compareError(actual, expected) { actual = normaliseError(actual); - - if (actual.parserError) { - actual.parserError = normaliseError(actual.parserError); - } - - if (actual.frame) { - actual.frame = actual.frame.replace(/\s+$/gm, ''); - } - if (expected.frame) { expected.frame = deindent(expected.frame); } - assert.deepEqual(actual, expected); }; exports.compareWarnings = function compareWarnings(actual, expected) { assert.deepEqual( - actual.map(warning => { - const clone = { ...warning }; - delete clone.toString; - - if (clone.frame) { - clone.frame = clone.frame.replace(/\s+$/gm, ''); - } - - return clone; - }), + actual.map(normaliseError), expected.map(warning => { if (warning.frame) { warning.frame = deindent(warning.frame);