Skip to content

Commit

Permalink
deprecation deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 16, 2018
1 parent b61de79 commit 0632cde
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 176 deletions.
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
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 @@ -67,7 +61,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 @@ -473,7 +466,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 @@ -237,14 +242,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 @@ -299,35 +302,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;
}
15 changes: 1 addition & 14 deletions src/watch/index.ts
Expand Up @@ -103,8 +103,6 @@ export class Task {
private outputs: OutputOptions[];
private invalidated = true;

private deprecations: { old: string; new: string }[];

private filter: (id: string) => boolean;

constructor(watcher: Watcher, config: RollupWatchOptions) {
Expand All @@ -114,7 +112,7 @@ export class Task {
this.closed = false;
this.watched = new Set();

const { inputOptions, outputOptions, deprecations } = mergeOptions({
const { inputOptions, outputOptions } = mergeOptions({
config
});
this.inputOptions = inputOptions;
Expand Down Expand Up @@ -144,7 +142,6 @@ export class Task {
this.chokidarOptionsHash = JSON.stringify(chokidarOptions);

this.filter = createFilter(watchOptions.include, watchOptions.exclude);
this.deprecations = [...deprecations, ...(watchOptions._deprecations || [])];
}

close() {
Expand Down Expand Up @@ -185,16 +182,6 @@ export class Task {
output: this.outputFiles
});

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

setWatcher(this.watcher);
return rollup(options)
.then(result => {
Expand Down
4 changes: 2 additions & 2 deletions test/misc/optionList.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0632cde

Please sign in to comment.