Skip to content

Commit

Permalink
1.0: deprecations (#2409)
Browse files Browse the repository at this point in the history
* emit watch changes as a plugin hook

* fix path require

* deprecate asset dependencies

* renderChunk hook to replace transformChunk

* renderChunk to follow all transformBundle tests, type definition

* 1.0 deprecations

* legacy deprecations

* new deprecation tests

* type fix, output options deprecations

* type fixes

* deprecation deprecations
  • Loading branch information
guybedford authored and lukastaegert committed Dec 15, 2018
1 parent ac8a238 commit e1858ed
Show file tree
Hide file tree
Showing 29 changed files with 347 additions and 459 deletions.
10 changes: 1 addition & 9 deletions bin/src/run/batchWarnings.ts
Expand Up @@ -87,14 +87,6 @@ const immediateHandlers: {
stderr(warning.message);
},

DEPRECATED_OPTIONS: warning => {
title(`Some options have been renamed`);
info(`https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32`);
warning.deprecations.forEach(option => {
stderr(`${tc.bold(option.old)} is now ${option.new}`);
});
},

MISSING_NODE_BUILTINS: warning => {
title(`Missing shims for Node.js built-ins`);

Expand All @@ -103,7 +95,7 @@ const immediateHandlers: {
? `'${warning.modules[0]}'`
: `${warning.modules
.slice(0, -1)
.map(name => `'${name}'`)
.map((name: string) => `'${name}'`)
.join(', ')} and '${warning.modules.slice(-1)}'`;
stderr(
`Creating a browser bundle that depends on ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins`
Expand Down
12 changes: 1 addition & 11 deletions bin/src/run/index.ts
Expand Up @@ -97,22 +97,12 @@ function execute(configFile: string, configs: InputOptions[], command: any) {
for (const config of configs) {
promise = promise.then(() => {
const warnings = batchWarnings();
const { inputOptions, outputOptions, deprecations, optionError } = mergeOptions({
const { inputOptions, outputOptions, optionError } = mergeOptions({
config,
command,
defaultOnWarnHandler: warnings.add
});

if (deprecations.length) {
inputOptions.onwarn({
code: 'DEPRECATED_OPTIONS',
message: `The following options have been renamed — please update your config: ${deprecations
.map(option => `${option.old} -> ${option.new}`)
.join(', ')}`,
deprecations
});
}

if (optionError) inputOptions.onwarn({ code: 'UNKNOWN_OPTION', message: optionError });
return build(inputOptions, outputOptions, warnings, command.silent);
});
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Expand Up @@ -31,6 +31,8 @@ const banner = `/*
*/`;

const onwarn = warning => {
if (warning.pluginCode === 'ONWRITE_HOOK_DEPRECATED')
return;
// eslint-disable-next-line no-console
console.error(
'Building Rollup produced warnings that need to be resolved. ' +
Expand Down
48 changes: 6 additions & 42 deletions src/rollup/index.ts
Expand Up @@ -5,7 +5,6 @@ import { createAddons } from '../utils/addons';
import { createAssetPluginHooks, finaliseAsset } from '../utils/assetHooks';
import { assignChunkIds } from '../utils/assignChunkIds';
import commondir from '../utils/commondir';
import { Deprecation } from '../utils/deprecateOptions';
import { error } from '../utils/error';
import { writeFile } from '../utils/fs';
import getExportMode from '../utils/getExportMode';
Expand All @@ -22,29 +21,9 @@ import {
Plugin,
RollupBuild,
RollupOutput,
RollupWatcher,
WarningHandler
RollupWatcher
} from './types';

function addDeprecations(deprecations: Deprecation[], warn: WarningHandler) {
const message = `The following options have been renamed — please update your config: ${deprecations
.map(option => `${option.old} -> ${option.new}`)
.join(', ')}`;
warn({
code: 'DEPRECATED_OPTIONS',
message,
deprecations
});
}

function checkInputOptions(options: InputOptions) {
if (options.transform || options.load || options.resolveId || options.resolveExternal) {
throw new Error(
'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See "https://rollupjs.org/guide/en#plugins" for details'
);
}
}

function checkOutputOptions(options: OutputOptions) {
if (<string>options.format === 'es6') {
error({
Expand All @@ -59,10 +38,6 @@ function checkOutputOptions(options: OutputOptions) {
url: `https://rollupjs.org/guide/en#output-format-f-format`
});
}

if (options.moduleId) {
if (options.amd) throw new Error('Cannot have both output.amd and output.moduleId');
}
}

function getAbsoluteEntryModulePaths(chunks: Chunk[]): string[] {
Expand Down Expand Up @@ -93,15 +68,12 @@ function getInputOptions(rawInputOptions: GenericConfigObject): any {
if (!rawInputOptions) {
throw new Error('You must supply an options object to rollup');
}
let { inputOptions, deprecations, optionError } = mergeOptions({
config: rawInputOptions,
deprecateConfig: { input: true }
let { inputOptions, optionError } = mergeOptions({
config: rawInputOptions
});

if (optionError) inputOptions.onwarn({ message: optionError, code: 'UNKNOWN_OPTION' });
if (deprecations.length) addDeprecations(deprecations, inputOptions.onwarn);

checkInputOptions(inputOptions);
const plugins = inputOptions.plugins;
inputOptions.plugins = Array.isArray(plugins)
? plugins.filter(Boolean)
Expand Down Expand Up @@ -442,25 +414,17 @@ function normalizeOutputOptions(
if (!rawOutputOptions) {
throw new Error('You must supply an options object');
}
// since deprecateOptions, adds the output properties
// to `inputOptions` so adding that lastly
const consolidatedOutputOptions = {
output: { ...rawOutputOptions, ...rawOutputOptions.output, ...inputOptions.output }
};
const mergedOptions = mergeOptions({
// just for backward compatiblity to fallback on root
// if the option isn't present in `output`
config: consolidatedOutputOptions,
deprecateConfig: { output: true }
config: {
output: { ...rawOutputOptions, ...rawOutputOptions.output, ...inputOptions.output }
}
});

if (mergedOptions.optionError) throw new Error(mergedOptions.optionError);

// now outputOptions is an array, but rollup.rollup API doesn't support arrays
const outputOptions = mergedOptions.outputOptions[0];
const deprecations = mergedOptions.deprecations;

if (deprecations.length) addDeprecations(deprecations, inputOptions.onwarn);
checkOutputOptions(outputOptions);

if (typeof outputOptions.file === 'string') {
Expand Down
79 changes: 18 additions & 61 deletions src/rollup/types.d.ts
Expand Up @@ -7,23 +7,28 @@ export interface IdMap {
[key: string]: string;
}

export interface RollupError {
message: string;
export interface RollupError extends RollupLogProps {
message?: string;
stack?: string;
}

export interface RollupWarning extends RollupLogProps {
message?: string;
}

export interface RollupLogProps {
code?: string;
name?: string;
url?: string;
id?: string;
plugin?: string;
pluginCode?: string;
hook?: string;
loc?: {
file?: string;
line: number;
column: number;
};
stack?: string;
frame?: string;
pos?: number;
plugin?: string;
pluginCode?: string;
hook?: string;
[key: string]: any;
}

export interface ExistingRawSourceMap {
Expand Down Expand Up @@ -89,7 +94,7 @@ export interface PluginCache {
}

export interface PluginContext {
// TODO deprecate:
/** @deprecated */
watcher: EventEmitter;
addWatchFile: (id: string) => void;
cache: PluginCache;
Expand Down Expand Up @@ -185,6 +190,7 @@ export interface Plugin {
transform?: TransformHook;
/** @deprecated */
transformBundle?: TransformChunkHook;
/** @deprecated */
transformChunk?: TransformChunkHook;
renderChunk?: RenderChunkHook;
buildStart?: (this: PluginContext, options: InputOptions) => Promise<void> | void;
Expand Down Expand Up @@ -234,6 +240,7 @@ export interface InputOptions {

onwarn?: WarningHandler;
cache?: false | RollupCache;
perf?: boolean;
experimentalCacheExpiry?: number;

acorn?: {};
Expand All @@ -243,27 +250,12 @@ export interface InputOptions {
moduleContext?: string | ((id: string) => string) | { [id: string]: string };
watch?: WatcherOptions;
inlineDynamicImports?: boolean;
preferConst?: boolean;
preserveSymlinks?: boolean;
preserveModules?: boolean;
experimentalOptimizeChunks?: boolean;
chunkGroupingSize?: number;
shimMissingExports?: boolean;

// undocumented?
pureExternalModules?: boolean;
preferConst?: boolean;
perf?: boolean;

/** @deprecated */
entry?: string;
/** @deprecated */
transform?: TransformHook;
/** @deprecated */
load?: LoadHook;
/** @deprecated */
resolveId?: ResolveIdHook;
/** @deprecated */
resolveExternal?: any;
}

export type ModuleFormat = 'amd' | 'cjs' | 'system' | 'es' | 'esm' | 'iife' | 'umd';
Expand Down Expand Up @@ -308,41 +300,7 @@ export interface OutputOptions {
namespaceToStringTag?: boolean;
compact?: boolean;

/** @deprecated */
noConflict?: boolean;
/** @deprecated */
dest?: string;
/** @deprecated */
moduleId?: string;
}

export interface RollupWarning {
message?: string;
code?: string;
loc?: {
file: string;
line: number;
column: number;
};
deprecations?: { old: string; new: string }[];
modules?: string[];
names?: string[];
source?: string;
importer?: string;
frame?: any;
missing?: string;
exporter?: string;
exportName?: string;
name?: string;
sources?: string[];
reexporter?: string;
guess?: string;
url?: string;
id?: string;
plugin?: string;
pos?: number;
pluginCode?: string;
hook?: string;
}

export type WarningHandler = (warning: string | RollupWarning) => void;
Expand Down Expand Up @@ -415,7 +373,6 @@ export interface RollupOptions extends InputOptions {
}

export function rollup(options: RollupOptions): Promise<RollupBuild>;

// chokidar watch options
export interface WatchOptions {
persistent?: boolean;
Expand Down

0 comments on commit e1858ed

Please sign in to comment.