Skip to content

Commit

Permalink
deprecation deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and lukastaegert committed Sep 7, 2018
1 parent 56d8044 commit 014a10d
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 247 deletions.
2 changes: 1 addition & 1 deletion bin/src/run/batchWarnings.ts
Expand Up @@ -95,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 @@ -105,22 +105,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
1 change: 0 additions & 1 deletion src/ast/nodes/Identifier.ts
Expand Up @@ -10,7 +10,6 @@ import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker'
import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } from '../values';
import LocalVariable from '../variables/LocalVariable';
import Variable from '../variables/Variable';
import AssignmentExpression from './AssignmentExpression';
import AssignmentPattern from './AssignmentPattern';
import * as NodeType from './NodeType';
import Property from './Property';
Expand Down
10 changes: 1 addition & 9 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 @@ -21,14 +20,9 @@ import {
OutputOptions,
Plugin,
RollupBuild,
RollupSingleFileBuild,
WarningHandler
RollupSingleFileBuild
} from './types';

function checkInputOptions(_options: any) {
// no deprecations currently
}

function checkOutputOptions(options: OutputOptions) {
if (<string>options.format === 'es6') {
error({
Expand Down Expand Up @@ -68,7 +62,6 @@ function getInputOptions(rawInputOptions: GenericConfigObject): any {

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

checkInputOptions(inputOptions);
const plugins = inputOptions.plugins;
inputOptions.plugins = Array.isArray(plugins) ? plugins : plugins ? [plugins] : [];
inputOptions = inputOptions.plugins.reduce(applyOptionHook, inputOptions);
Expand Down Expand Up @@ -481,7 +474,6 @@ function normalizeOutputOptions(

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

checkOutputOptions(outputOptions);

Expand Down
56 changes: 15 additions & 41 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 @@ -242,14 +247,12 @@ export interface InputOptions {
experimentalDynamicImport?: boolean;
experimentalTopLevelAwait?: boolean;
inlineDynamicImports?: boolean;
preferConst?: boolean;
preserveSymlinks?: boolean;
experimentalPreserveModules?: boolean;
optimizeChunks?: boolean;
chunkGroupingSize?: number;
shimMissingExports?: boolean;

/** @deprecated */
preferConst?: boolean;
}

export type ModuleFormat = 'amd' | 'cjs' | 'system' | 'es' | 'esm' | 'iife' | 'umd';
Expand Down Expand Up @@ -304,35 +307,6 @@ export interface OutputOptionsDir extends OutputOptions {
dir?: 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;

export interface SerializedTimings {
Expand Down
40 changes: 0 additions & 40 deletions src/utils/deprecateOptions.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/utils/mergeOptions.ts
@@ -1,5 +1,4 @@
import { InputOptions, OutputOptions, WarningHandler } from '../rollup/types';
import deprecateOptions, { Deprecation } from './deprecateOptions';

export interface GenericConfigObject {
[key: string]: any;
Expand Down Expand Up @@ -82,20 +81,16 @@ export const commandAliases: { [key: string]: string } = {
export default function mergeOptions({
config = {},
command: rawCommandOptions = {},
deprecateConfig,
defaultOnWarnHandler
}: {
config: GenericConfigObject;
command?: GenericConfigObject;
deprecateConfig?: GenericConfigObject;
defaultOnWarnHandler?: WarningHandler;
}): {
inputOptions: any;
outputOptions: any;
deprecations: Deprecation[];
optionError: string | null;
} {
const deprecations = deprecate(config, rawCommandOptions, deprecateConfig);
const command = getCommandOptions(rawCommandOptions);
const inputOptions = getInputOptions(config, command, defaultOnWarnHandler);

Expand Down Expand Up @@ -145,7 +140,6 @@ export default function mergeOptions({
return {
inputOptions,
outputOptions,
deprecations,
optionError: unknownOptionErrors.length > 0 ? unknownOptionErrors.join('\n') : null
};
}
Expand Down Expand Up @@ -221,18 +215,6 @@ function getInputOptions(
watch: config.watch
};

// legacy to make sure certain plugins still work
if (Array.isArray(inputOptions.input)) {
inputOptions.entry = inputOptions.input[0];
} else if (typeof inputOptions.input === 'object') {
for (const name in inputOptions.input) {
inputOptions.entry = inputOptions.input[name];
break;
}
} else {
inputOptions.entry = inputOptions.input;
}

return inputOptions;
}

Expand Down Expand Up @@ -272,40 +254,3 @@ function getOutputOptions(
strict: getOption('strict', true)
};
}

function deprecate(
config: GenericConfigObject,
command: GenericConfigObject = {},
deprecateConfig: GenericConfigObject = { input: true, output: true }
): Deprecation[] {
const deprecations = [];

// CLI
if (command.id) {
deprecations.push({
old: '-u/--id',
new: '--amd.id'
});
(command.amd || (command.amd = {})).id = command.id;
}

if (typeof command.output === 'string') {
deprecations.push({
old: '--output',
new: '--file'
});
command.output = { file: command.output };
}

if (command.d) {
deprecations.push({
old: '-d',
new: '--indent'
});
command.indent = command.d;
}

// config file
deprecations.push(...deprecateOptions(config, deprecateConfig));
return deprecations;
}
29 changes: 27 additions & 2 deletions src/utils/pluginDriver.ts
@@ -1,7 +1,15 @@
import { EventEmitter } from 'events';
import { version as rollupVersion } from 'package.json';
import Graph from '../Graph';
import { InputOptions, Plugin, PluginCache, PluginContext, RollupError, RollupWarning, SerializablePluginCache } from '../rollup/types';
import {
InputOptions,
Plugin,
PluginCache,
PluginContext,
RollupError,
RollupWarning,
SerializablePluginCache
} from '../rollup/types';
import { createAssetPluginHooks, EmitAsset } from './assetHooks';
import { getRollupDefaultPlugin } from './default-plugin';
import error from './error';
Expand Down Expand Up @@ -80,6 +88,17 @@ export function createPluginDriver(
cacheInstance = uncacheablePlugin(plugin.name);
}

const firstWatchHandler = true;

function deprecatedWatchListener(event: string, handler: () => void) {
if (firstWatchHandler)
context.warn({
code: 'PLUGIN_WATCHER_DEPRECATED',
message: `this.watcher usage is deprecated in plugins. Use the watchChange plugin hook instead.`
});
return watcher.on(event, handler);
}

const context: PluginContext = {
addWatchFile(id: string) {
if (graph.finished) this.error('addWatchFile can only be called during the build.');
Expand Down Expand Up @@ -113,7 +132,13 @@ export function createPluginDriver(
warning.plugin = plugin.name || `Plugin at position ${pidx + 1}`;
graph.warn(warning);
},
watcher
watcher: watcher
? <EventEmitter>{
...watcher,
on: deprecatedWatchListener,
addListener: deprecatedWatchListener
}
: undefined
};
return context;
});
Expand Down

0 comments on commit 014a10d

Please sign in to comment.