Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0: deprecations #2409

Merged
merged 12 commits into from Sep 7, 2018
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 @@ -100,22 +100,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
4 changes: 0 additions & 4 deletions bin/src/run/watch.ts
Expand Up @@ -69,10 +69,6 @@ export default function watch(

if (!result.watch) result.watch = {};

if (merged.deprecations.length) {
(<{ _deprecations: any }>result.watch)._deprecations = merged.deprecations;
}

if (merged.optionError)
merged.inputOptions.onwarn({
message: merged.optionError,
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Expand Up @@ -29,6 +29,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
33 changes: 2 additions & 31 deletions src/rollup/index.ts
Expand Up @@ -4,7 +4,6 @@ import Graph from '../Graph';
import { createAddons } from '../utils/addons';
import { createAssetPluginHooks, finaliseAsset } from '../utils/assetHooks';
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 @@ -20,29 +19,9 @@ import {
OutputOptions,
Plugin,
RollupBuild,
RollupOutput,
WarningHandler
RollupOutput
} 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://github.com/rollup/rollup/wiki/Plugins" for details'
);
}
}

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

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

const throwAsyncGenerateError = {
Expand All @@ -79,15 +54,13 @@ function getInputOptions(rawInputOptions: GenericConfigObject): any {
if (!rawInputOptions) {
throw new Error('You must supply an options object to rollup');
}
let { inputOptions, deprecations, optionError } = mergeOptions({
let { inputOptions, optionError } = mergeOptions({
config: rawInputOptions,
deprecateConfig: { input: true }
});

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 : plugins ? [plugins] : [];
inputOptions = inputOptions.plugins.reduce(applyOptionHook, inputOptions);
Expand Down Expand Up @@ -450,9 +423,7 @@ function normalizeOutputOptions(

// 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;
optimizeChunks?: 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 @@ -306,41 +298,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 @@ -409,7 +367,6 @@ export interface RollupOptions extends InputOptions {
}

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

// chokidar watch options
export interface WatchOptions {
persistent?: boolean;
Expand Down
108 changes: 0 additions & 108 deletions src/utils/deprecateOptions.ts

This file was deleted.