Skip to content

Commit

Permalink
[v2.0.0] Remove active deprecations (#3352)
Browse files Browse the repository at this point in the history
* Remove active deprecations

* Make inactive deprecations active

* Improve coverage

* Improve coverage

* Refine transformer

* Improve coverage

* Refactoring option normalization

* Improve coverage
  • Loading branch information
lukastaegert committed Feb 14, 2020
1 parent fc9efb1 commit 254fe4f
Show file tree
Hide file tree
Showing 138 changed files with 724 additions and 1,895 deletions.
1 change: 0 additions & 1 deletion cli/help.md
Expand Up @@ -55,7 +55,6 @@ Basic options:
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
--no-treeshake.propertyReadSideEffects Ignore property access side-effects
--treeshake.pureExternalModules Assume side-effect free externals

Examples:

Expand Down
16 changes: 5 additions & 11 deletions cli/run/index.ts
@@ -1,7 +1,7 @@
import { realpathSync } from 'fs';
import relative from 'require-relative';
import { WarningHandler } from '../../src/rollup/types';
import mergeOptions, { GenericConfigObject } from '../../src/utils/mergeOptions';
import { mergeOptions } from '../../src/utils/mergeOptions';
import { GenericConfigObject } from '../../src/utils/parseOptions';
import { getAliasName } from '../../src/utils/relativeId';
import { handleError } from '../logging';
import batchWarnings from './batchWarnings';
Expand All @@ -16,7 +16,7 @@ export default function runRollup(command: any) {
if (command.input) {
handleError({
code: 'DUPLICATE_IMPORT_OPTIONS',
message: 'use --input, or pass input path as argument'
message: 'Either use --input, or pass input path as argument'
});
}
inputSource = command._;
Expand Down Expand Up @@ -107,14 +107,8 @@ async function execute(
} else {
for (const config of configs) {
const warnings = batchWarnings();
const { inputOptions, outputOptions, optionError } = mergeOptions({
command,
config,
defaultOnWarnHandler: warnings.add
});
if (optionError) {
(inputOptions.onwarn as WarningHandler)({ code: 'UNKNOWN_OPTION', message: optionError });
}
const { inputOptions, outputOptions } = mergeOptions(config, command,
warnings.add);
if (command.stdin !== false) {
inputOptions.plugins!.push(stdinPlugin());
}
Expand Down
4 changes: 2 additions & 2 deletions cli/run/loadConfigFile.ts
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import tc from 'turbocolor';
import * as rollup from '../../src/node-entry';
import { RollupBuild, RollupOutput } from '../../src/rollup/types';
import { GenericConfigObject } from '../../src/utils/mergeOptions';
import { GenericConfigObject } from '../../src/utils/parseOptions';
import relativeId from '../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import batchWarnings from './batchWarnings';
Expand Down Expand Up @@ -73,4 +73,4 @@ export default function loadConfigFile(
return Array.isArray(configs) ? configs : [configs];
});
});
}
}
42 changes: 11 additions & 31 deletions cli/run/watch.ts
Expand Up @@ -4,12 +4,9 @@ import ms from 'pretty-ms';
import onExit from 'signal-exit';
import tc from 'turbocolor';
import * as rollup from '../../src/node-entry';
import {
RollupWatcher,
RollupWatchOptions,
WarningHandler
} from '../../src/rollup/types';
import mergeOptions, { GenericConfigObject } from '../../src/utils/mergeOptions';
import { RollupWatcher, RollupWatchOptions } from '../../src/rollup/types';
import { mergeOptions } from '../../src/utils/mergeOptions';
import { GenericConfigObject } from '../../src/utils/parseOptions';
import relativeId from '../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import batchWarnings from './batchWarnings';
Expand All @@ -26,35 +23,20 @@ export default function watch(
const isTTY = Boolean(process.stderr.isTTY);
const warnings = batchWarnings();
const initialConfigs = processConfigs(configs);
const clearScreen = initialConfigs.every(
config => config.watch!.clearScreen !== false
);
const clearScreen = initialConfigs.every(config => config.watch!.clearScreen !== false);

const resetScreen = getResetScreen(isTTY && clearScreen);
let watcher: RollupWatcher;
let configWatcher: RollupWatcher;

function processConfigs(configs: GenericConfigObject[]): RollupWatchOptions[] {
return configs.map(options => {
const merged = mergeOptions({
command,
config: options,
defaultOnWarnHandler: warnings.add
});

const { inputOptions, outputOptions } = mergeOptions(options, command, warnings.add);
const result: RollupWatchOptions = {
...merged.inputOptions,
output: merged.outputOptions
...inputOptions,
output: outputOptions
};

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

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

return result;
});
}
Expand Down Expand Up @@ -87,9 +69,7 @@ export default function watch(
}
stderr(
tc.cyan(
`bundles ${tc.bold(input)}${tc.bold(
event.output.map(relativeId).join(', ')
)}...`
`bundles ${tc.bold(input)}${tc.bold(event.output.map(relativeId).join(', '))}...`
)
);
}
Expand All @@ -100,9 +80,9 @@ export default function watch(
if (!silent)
stderr(
tc.green(
`created ${tc.bold(
event.output.map(relativeId).join(', ')
)} in ${tc.bold(ms(event.duration))}`
`created ${tc.bold(event.output.map(relativeId).join(', '))} in ${tc.bold(
ms(event.duration)
)}`
)
);
if (event.result && event.result.getTimings) {
Expand Down
15 changes: 1 addition & 14 deletions docs/05-plugin-development.md
Expand Up @@ -397,22 +397,9 @@ Called only at the end of `bundle.write()` once all files have been written. Sim

☢️ These hooks have been deprecated and may be removed in a future Rollup version.

- `ongenerate` - _**Use [`generateBundle`](guide/en/#generatebundle)**_ - Function hook
called when `bundle.generate()` is being executed.

- `onwrite` - _**Use [`generateBundle`](guide/en/#generatebundle)**_ - Function hook
called when `bundle.write()` is being executed, after the file has been written
to disk.

- `resolveAssetUrl` - _**Use [`resolveFileUrl`](guide/en/#resolvefileurl)**_ - Function hook that allows to customize the generated code for asset URLs.

- `transformBundle`_**Use [`renderChunk`](guide/en/#renderchunk)**_ - A `( source, { format } ) =>
code` or `( source, { format } ) => { code, map }` bundle transformer function.

- `transformChunk`_**Use [`renderChunk`](guide/en/#renderchunk)**_ - A `( source, outputOptions,
chunk ) => code | { code, map}` chunk transformer function.

More properties may be supported in future, as and when they prove necessary.
More properties may be supported in the future, as and when they prove necessary.

### Plugin Context

Expand Down
1 change: 0 additions & 1 deletion src/Chunk.ts
Expand Up @@ -733,7 +733,6 @@ export default class Chunk {
const chunkSourcemapChain: DecodedSourceMapOrMissing[] = [];

return renderChunk({
chunk: this,
code: prevCode,
options,
outputPluginDriver,
Expand Down
25 changes: 3 additions & 22 deletions src/Graph.ts
Expand Up @@ -30,17 +30,6 @@ import { PluginDriver } from './utils/PluginDriver';
import relativeId from './utils/relativeId';
import { timeEnd, timeStart } from './utils/timers';

function makeOnwarn() {
const warned = Object.create(null);

return (warning: any) => {
const str = warning.toString();
if (str in warned) return;
console.error(str);
warned[str] = true;
};
}

function normalizeEntryModules(
entryModules: string | string[] | Record<string, string>
): UnresolvedModule[] {
Expand Down Expand Up @@ -84,7 +73,7 @@ export default class Graph {
private strictDeprecations: boolean;

constructor(options: InputOptions, watcher: RollupWatcher | null) {
this.onwarn = (options.onwarn as WarningHandler) || makeOnwarn();
this.onwarn = options.onwarn as WarningHandler;
this.deoptimizationTracker = new PathTracker();
this.cachedModules = new Map();
if (options.cache) {
Expand Down Expand Up @@ -126,7 +115,7 @@ export default class Graph {
if (typeof this.treeshakingOptions.pureExternalModules !== 'undefined') {
this.warnDeprecation(
`The "treeshake.pureExternalModules" option is deprecated. The "treeshake.moduleSideEffects" option should be used instead. "treeshake.pureExternalModules: true" is equivalent to "treeshake.moduleSideEffects: 'no-external'"`,
false
true
);
}
}
Expand All @@ -142,8 +131,7 @@ export default class Graph {
this,
options.plugins!,
this.pluginCache,
options.preserveSymlinks === true,
watcher
options.preserveSymlinks === true
);

if (watcher) {
Expand Down Expand Up @@ -240,13 +228,6 @@ export default class Graph {
// Phase 3 – marking. We include all statements that should be included
timeStart('mark included statements', 2);

if (inlineDynamicImports) {
if (entryModules.length > 1) {
throw new Error(
'Internal Error: can only inline dynamic imports for single-file builds.'
);
}
}
for (const module of entryModules) {
module.includeAllExports();
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/MetaProperty.ts
Expand Up @@ -80,14 +80,14 @@ export default class MetaProperty extends NodeBase {
} else if (metaProperty.startsWith(ASSET_PREFIX)) {
this.context.warnDeprecation(
`Using the "${ASSET_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
false
true
);
assetReferenceId = metaProperty.substr(ASSET_PREFIX.length);
fileName = outputPluginDriver.getFileName(assetReferenceId);
} else {
this.context.warnDeprecation(
`Using the "${CHUNK_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
false
true
);
chunkReferenceId = metaProperty.substr(CHUNK_PREFIX.length);
fileName = outputPluginDriver.getFileName(chunkReferenceId);
Expand Down

0 comments on commit 254fe4f

Please sign in to comment.