Skip to content

Commit

Permalink
[v3.0] Remove actively deprecated features, show warnings for other d…
Browse files Browse the repository at this point in the history
…eprecated features (#4552)

* Remove all active deprecations

* Make all inactive deprecations active

* Try to make test more stable

* Update CLI help screen
  • Loading branch information
lukastaegert committed Jul 29, 2022
1 parent 16b0cbb commit 8dfcd36
Show file tree
Hide file tree
Showing 418 changed files with 381 additions and 3,494 deletions.
6 changes: 4 additions & 2 deletions cli/help.md
Expand Up @@ -37,16 +37,18 @@ Basic options:
--failAfterWarnings Exit with an error if the build produced warnings
--footer <text> Code to insert at end of bundle (outside wrapper)
--no-freeze Do not freeze namespace objects
--generatedCode <preset> Which code features to use (es5/es2015)
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
--no-indent Don't indent result
--no-interop Do not include interop block
--inlineDynamicImports Create single bundle when using dynamic imports
--intro <text> Code to insert at top of bundle (inside wrapper)
--no-makeAbsoluteExternalsRelative Prevent normalization of external imports
--maxParallelFileReads <value> How many files to read in parallel
--minifyInternalExports Force or disable minification of internal exports
--namespaceToStringTag Create proper `.toString` methods for namespaces
--noConflict Generate a noConflict method for UMD globals
--outro <text> Code to insert at end of bundle (inside wrapper)
--preferConst Use `const` instead of `var` for exports
--perf Display performance timings
--no-preserveEntrySignatures Avoid facade chunks for entry points
--preserveModules Preserve module structure
--preserveModulesRoot Put preserved modules under this path at root level
Expand Down
3 changes: 1 addition & 2 deletions cli/run/waitForInput.ts
@@ -1,5 +1,4 @@
import type { PluginContext } from 'rollup';
import type { NormalizedInputOptions, Plugin } from '../../src/rollup/types';
import type { NormalizedInputOptions, Plugin, PluginContext } from '../../src/rollup/types';
import { bold } from '../../src/utils/colors';
import { stderr } from '../logging';

Expand Down
6 changes: 4 additions & 2 deletions docs/01-command-line-reference.md
Expand Up @@ -372,16 +372,18 @@ Many options have command line equivalents. In those cases, any arguments passed
--failAfterWarnings Exit with an error if the build produced warnings
--footer <text> Code to insert at end of bundle (outside wrapper)
--no-freeze Do not freeze namespace objects
--generatedCode <preset> Which code features to use (es5/es2015)
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
--no-indent Don't indent result
--no-interop Do not include interop block
--inlineDynamicImports Create single bundle when using dynamic imports
--intro <text> Code to insert at top of bundle (inside wrapper)
--no-makeAbsoluteExternalsRelative Prevent normalization of external imports
--maxParallelFileReads <value> How many files to read in parallel
--minifyInternalExports Force or disable minification of internal exports
--namespaceToStringTag Create proper `.toString` methods for namespaces
--noConflict Generate a noConflict method for UMD globals
--outro <text> Code to insert at end of bundle (inside wrapper)
--preferConst Use `const` instead of `var` for exports
--perf Display performance timings
--no-preserveEntrySignatures Avoid facade chunks for entry points
--preserveModules Preserve module structure
--preserveModulesRoot Put preserved modules under this path at root level
Expand Down
28 changes: 0 additions & 28 deletions docs/05-plugin-development.md
Expand Up @@ -554,14 +554,6 @@ Note that since this hook has access to the filename of the current chunk, its r

Called only at the end of `bundle.write()` once all files have been written. Similar to the [`generateBundle`](guide/en/#generatebundle) hook, `bundle` provides the full list of files being written along with their details.

### Deprecated Hooks

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

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

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

### Plugin Context

A number of utility functions and informational bits can be accessed from within most [hooks](guide/en/#build-hooks) via `this`:
Expand Down Expand Up @@ -945,24 +937,6 @@ The `position` argument is a character index where the warning was raised. If pr
☢️ These context utility functions have been deprecated and may be removed in a future Rollup version.
- `this.emitAsset(assetName: string, source: string) => string` - _**Use [`this.emitFile`](guide/en/#thisemitfile)**_ - Emits a custom file that is included in the build output, returning a `referenceId` that can be used to reference the emitted file. You can defer setting the source if you provide it later via [`this.setAssetSource(referenceId, source)`](guide/en/#thissetassetsource). A string or `Uint8Array`/`Buffer` source must be set for each asset through either method or an error will be thrown on generate completion.
Emitted assets will follow the [`output.assetFileNames`](guide/en/#outputassetfilenames) naming scheme. You can reference the URL of the file in any code returned by a [`load`](guide/en/#load) or [`transform`](guide/en/#transform) plugin hook via `import.meta.ROLLUP_ASSET_URL_referenceId`.
The generated code that replaces `import.meta.ROLLUP_ASSET_URL_referenceId` can be customized via the [`resolveFileUrl`](guide/en/#resolvefileurl) plugin hook. Once the asset has been finalized during `generate`, you can also use [`this.getFileName(referenceId)`](guide/en/#thisgetfilename) to determine the file name.
- `this.emitChunk(moduleId: string, options?: {name?: string}) => string` - _**Use [`this.emitFile`](guide/en/#thisemitfile)**_ - Emits a new chunk with the given module as entry point. This will not result in duplicate modules in the graph, instead if necessary, existing chunks will be split. It returns a `referenceId` that can be used to later access the generated file name of the chunk.
Emitted chunks will follow the [`output.chunkFileNames`](guide/en/#outputchunkfilenames), [`output.entryFileNames`](guide/en/#outputentryfilenames) naming scheme. If a `name` is provided, this will be used for the `[name]` file name placeholder, otherwise the name will be derived from the file name. If a `name` is provided, this name must not conflict with any other entry point names unless the entry points reference the same entry module. You can reference the URL of the emitted chunk in any code returned by a [`load`](guide/en/#load) or [`transform`](guide/en/#transform) plugin hook via `import.meta.ROLLUP_CHUNK_URL_referenceId`.
The generated code that replaces `import.meta.ROLLUP_CHUNK_URL_referenceId` can be customized via the [`resolveFileUrl`](guide/en/#resolvefileurl) plugin hook. Once the chunk has been rendered during `generate`, you can also use [`this.getFileName(referenceId)`](guide/en/#thisgetfilename) to determine the file name.
- `this.getAssetFileName(referenceId: string) => string` - _**Use [`this.getFileName`](guide/en/#thisgetfilename)**_ - Get the file name of an asset, according to the `assetFileNames` output option pattern. The file name will be relative to `outputOptions.dir`.
- `this.getChunkFileName(referenceId: string) => string` - _**Use [`this.getFileName`](guide/en/#thisgetfilename)**_ - Get the file name of an emitted chunk. The file name will be relative to `outputOptions.dir`.
- `this.isExternal(id: string, importer: string | undefined, isResolved: boolean) => boolean` - _**Use [`this.resolve`](guide/en/#thisresolve)**_ - Determine if a given module ID is external when imported by `importer`. When `isResolved` is false, Rollup will try to resolve the id before testing if it is external.
- `this.moduleIds: IterableIterator<string>` - _**Use [`this.getModuleIds`](guide/en/#thisgetmoduleids)**_ - An `Iterator` that gives access to all module ids in the current graph. It can be iterated via
```js
Expand All @@ -973,8 +947,6 @@ The `position` argument is a character index where the warning was raised. If pr
or converted into an Array via `Array.from(this.moduleIds)`.
- `this.resolveId(source: string, importer?: string) => Promise<string | null>` - _**Use [`this.resolve`](guide/en/#thisresolve)**_ - Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved.
### File URLs
To reference a file URL reference from within JS code, use the `import.meta.ROLLUP_FILE_URL_referenceId` replacement. This will generate code that depends on the output format and generates a URL that points to the emitted file in the target environment. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available.
Expand Down
33 changes: 0 additions & 33 deletions docs/999-big-list-of-options.md
Expand Up @@ -1457,12 +1457,6 @@ Type: `boolean`<br> CLI: `--noConflict`/`--no-noConflict`<br> Default: `false`

This will generate an additional `noConflict` export to UMD bundles. When called in an IIFE scenario, this method will return the bundle exports while restoring the corresponding global variable to its previous value.

#### output.preferConst

Type: `boolean`<br> CLI: `--preferConst`/`--no-preferConst`<br> Default: `false`

Generate `const` declarations for exports rather than `var` declarations.

#### output.sanitizeFileName

Type: `boolean | (string) => string`<br> CLI: `--sanitizeFileName`/`no-sanitizeFileName` Default: `true`
Expand Down Expand Up @@ -1887,33 +1881,6 @@ _Use the [`output.generatedCode.constBindings`](guide/en/#outputgeneratedcode) o

Generate `const` declarations for exports rather than `var` declarations.

#### treeshake.pureExternalModules

_Use [`treeshake.moduleSideEffects: 'no-external'`](guide/en/#treeshake) instead._<br> Type: `boolean | string[] | (id: string) => boolean | null`<br> CLI: `--treeshake.pureExternalModules`/`--no-treeshake.pureExternalModules`<br> Default: `false`

If `true`, assume external dependencies from which nothing is imported do not have other side effects like mutating global variables or logging.

```javascript
// input file
import { unused } from 'external-a';
import 'external-b';
console.log(42);
```

```javascript
// output with treeshake.pureExternalModules === false
import 'external-a';
import 'external-b';
console.log(42);
```

```javascript
// output with treeshake.pureExternalModules === true
console.log(42);
```

You can also supply a list of external ids to be considered pure or a function that is called whenever an external import could be removed.

#### output.namespaceToStringTag

_Use [`output.generatedCode.symbols`](guide/en/#outputgeneratedcode) instead._<br> Type: `boolean`<br> CLI: `--namespaceToStringTag`/`--no-namespaceToStringTag`<br> Default: `false`
Expand Down
12 changes: 1 addition & 11 deletions src/Bundle.ts
Expand Up @@ -6,7 +6,6 @@ import type {
GetManualChunk,
NormalizedInputOptions,
NormalizedOutputOptions,
OutputAsset,
OutputBundle,
OutputBundleWithPlaceholders,
OutputChunk,
Expand All @@ -21,8 +20,7 @@ import {
errCannotAssignModuleToChunk,
errChunkInvalid,
errInvalidOption,
error,
warnDeprecation
error
} from './utils/error';
import { sortByExecutionOrder } from './utils/executionOrder';
import { type GenerateCodeSnippets, getGenerateCodeSnippets } from './utils/generateCodeSnippets';
Expand Down Expand Up @@ -181,14 +179,6 @@ export default class Bundle {

private finaliseAssets(outputBundle: OutputBundleWithPlaceholders): void {
for (const file of Object.values(outputBundle)) {
if (!file.type) {
warnDeprecation(
'A plugin is directly adding properties to the bundle object in the "generateBundle" hook. This is deprecated and will be removed in a future Rollup version, please use "this.emitFile" instead.',
true,
this.inputOptions
);
(file as OutputAsset).type = 'asset';
}
if (this.outputOptions.validate && 'code' in file) {
try {
this.graph.contextParse(file.code, {
Expand Down
2 changes: 1 addition & 1 deletion src/ExternalModule.ts
Expand Up @@ -51,7 +51,7 @@ export default class ExternalModule {
get hasModuleSideEffects() {
warnDeprecation(
'Accessing ModuleInfo.hasModuleSideEffects from plugins is deprecated. Please use ModuleInfo.moduleSideEffects instead.',
false,
true,
options
);
return info.moduleSideEffects;
Expand Down
2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -297,7 +297,7 @@ export default class Module {
get hasModuleSideEffects() {
warnDeprecation(
'Accessing ModuleInfo.hasModuleSideEffects from plugins is deprecated. Please use ModuleInfo.moduleSideEffects instead.',
false,
true,
options
);
return this.moduleSideEffects;
Expand Down
68 changes: 10 additions & 58 deletions src/ast/nodes/MetaProperty.ts
@@ -1,7 +1,6 @@
import type MagicString from 'magic-string';
import type { InternalModuleFormat } from '../../rollup/types';
import type { PluginDriver } from '../../utils/PluginDriver';
import { warnDeprecation } from '../../utils/error';
import type { GenerateCodeSnippets } from '../../utils/generateCodeSnippets';
import { dirname, normalize, relative } from '../../utils/path';
import { INTERACTION_ACCESSED, NodeInteraction } from '../NodeInteractions';
Expand All @@ -12,8 +11,6 @@ import MemberExpression from './MemberExpression';
import type * as NodeType from './NodeType';
import { NodeBase } from './shared/Node';

const ASSET_PREFIX = 'ROLLUP_ASSET_URL_';
const CHUNK_PREFIX = 'ROLLUP_CHUNK_URL_';
const FILE_PREFIX = 'ROLLUP_FILE_URL_';

export default class MetaProperty extends NodeBase {
Expand All @@ -29,10 +26,7 @@ export default class MetaProperty extends NodeBase {
): void {
const metaProperty = this.metaProperty;
const accessedGlobals = (
metaProperty &&
(metaProperty.startsWith(FILE_PREFIX) ||
metaProperty.startsWith(ASSET_PREFIX) ||
metaProperty.startsWith(CHUNK_PREFIX))
metaProperty && metaProperty.startsWith(FILE_PREFIX)
? accessedFileUrlGlobals
: accessedMetaUrlGlobals
)[format];
Expand Down Expand Up @@ -81,64 +75,22 @@ export default class MetaProperty extends NodeBase {
const parent = this.parent;
const metaProperty = this.metaProperty as string | null;

if (
metaProperty &&
(metaProperty.startsWith(FILE_PREFIX) ||
metaProperty.startsWith(ASSET_PREFIX) ||
metaProperty.startsWith(CHUNK_PREFIX))
) {
if (metaProperty && metaProperty.startsWith(FILE_PREFIX)) {
let referenceId: string | null = null;
let assetReferenceId: string | null = null;
let chunkReferenceId: string | null = null;
let fileName: string;
if (metaProperty.startsWith(FILE_PREFIX)) {
referenceId = metaProperty.substring(FILE_PREFIX.length);
fileName = outputPluginDriver.getFileName(referenceId);
} else if (metaProperty.startsWith(ASSET_PREFIX)) {
warnDeprecation(
`Using the "${ASSET_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
true,
this.context.options
);
assetReferenceId = metaProperty.substring(ASSET_PREFIX.length);
fileName = outputPluginDriver.getFileName(assetReferenceId);
} else {
warnDeprecation(
`Using the "${CHUNK_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
true,
this.context.options
);
chunkReferenceId = metaProperty.substring(CHUNK_PREFIX.length);
fileName = outputPluginDriver.getFileName(chunkReferenceId);
}
referenceId = metaProperty.substring(FILE_PREFIX.length);
const fileName = outputPluginDriver.getFileName(referenceId);
const relativePath = normalize(relative(dirname(chunkId), fileName));
let replacement;
if (assetReferenceId !== null) {
replacement = outputPluginDriver.hookFirstSync('resolveAssetUrl', [
const replacement =
outputPluginDriver.hookFirstSync('resolveFileUrl', [
{
assetFileName: fileName,
chunkId,
fileName,
format,
moduleId: this.context.module.id,
relativeAssetPath: relativePath
referenceId,
relativePath
}
]);
}
if (!replacement) {
replacement =
outputPluginDriver.hookFirstSync('resolveFileUrl', [
{
assetReferenceId,
chunkId,
chunkReferenceId,
fileName,
format,
moduleId: this.context.module.id,
referenceId: referenceId || assetReferenceId || chunkReferenceId!,
relativePath
}
]) || relativeUrlMechanisms[format](relativePath);
}
]) || relativeUrlMechanisms[format](relativePath);

code.overwrite(
(parent as MemberExpression).start,
Expand Down

0 comments on commit 8dfcd36

Please sign in to comment.