diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index fc9dfdf1d..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,165 +0,0 @@ -module.exports = { - env: { - browser: true, - es6: true, - node: true - }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'plugin:prettier/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'plugin:unicorn/recommended' - ], - ignorePatterns: [ - 'node_modules', - 'dist', - 'perf', - 'tmp', - 'coverage', - '_tmp', - 'cache', - 'native.d.ts', - '/test/*/samples/**/*.*', - '!/test/*/samples/**/_config.js', - '!/test/*/samples/**/rollup.config.js', - '!.vitepress', - '/wasm/', - '/wasm-node/' - ], - overrides: [ - { - files: ['*.js'], - rules: { - '@typescript-eslint/explicit-module-boundary-types': 'off', - 'unicorn/no-process-exit': 'off', - 'unicorn/prefer-module': 'off' - } - }, - { - files: ['./*.ts', 'cli/**/*.ts'], - rules: { - 'unicorn/no-process-exit': 'off' - } - }, - { - files: ['*.js', 'cli/**/*.ts'], - rules: { - '@typescript-eslint/no-var-requires': 'off' - } - }, - { - env: { - mocha: true - }, - files: ['test/**/*.js'], - rules: { - 'sort-keys': 'off' - } - }, - { - extends: [ - 'plugin:vue/vue3-essential', - '@vue/eslint-config-typescript/recommended', - '@vue/eslint-config-prettier' - ], - files: ['*.vue'] - }, - { - files: ['docs/repl/examples/**/*.js'], - rules: { - 'import/namespace': 'off', - 'import/no-unresolved': 'off', - 'no-undef': 'off', - 'unicorn/prevent-abbreviations': 'off' - } - }, - { - files: ['test/**/_config.js'], - rules: { - 'no-undef': 'off' - } - } - ], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - rules: { - '@typescript-eslint/consistent-type-assertions': [ - 'error', - { assertionStyle: 'as', objectLiteralTypeAssertions: 'allow' } - ], - '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], - '@typescript-eslint/consistent-type-imports': 'error', - '@typescript-eslint/member-ordering': [ - 'error', - { - default: { - memberTypes: [], - order: 'alphabetically' - } - } - ], - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-unused-vars': [ - 'error', - { argsIgnorePattern: '^_', ignoreRestSiblings: true, varsIgnorePattern: '^_' } - ], - 'arrow-body-style': ['error', 'as-needed'], - 'dot-notation': 'error', - 'import/no-unresolved': [ - 'error', - { - // 'fsevents' is only available on macOS, and not installed on linux/windows - ignore: [ - 'fsevents', - 'help.md', - 'is-reference', - 'package.json', - 'types', - 'examples.json', - 'locate-character' - ] - } - ], - 'import/order': ['error', { alphabetize: { order: 'asc' } }], - 'no-constant-condition': ['error', { checkLoops: false }], - 'no-prototype-builtins': 'off', - 'object-shorthand': 'error', - 'prefer-const': ['error', { destructuring: 'all' }], - 'prefer-object-spread': 'error', - 'sort-imports': [ - 'error', - { - ignoreCase: true, - ignoreDeclarationSort: true, - ignoreMemberSort: false - } - ], - 'sort-keys': ['error', 'asc', { caseSensitive: false }], - 'unicorn/consistent-destructuring': 'off', - 'unicorn/filename-case': 'off', - 'unicorn/no-array-callback-reference': 'off', - 'unicorn/no-array-reduce': 'off', - 'unicorn/no-await-expression-member': 'off', - 'unicorn/no-empty-file': 'off', - 'unicorn/no-for-loop': 'off', - 'unicorn/no-nested-ternary': 'off', - 'unicorn/no-null': 'off', - 'unicorn/no-this-assignment': 'off', - 'unicorn/no-useless-undefined': 'off', - 'unicorn/number-literal-case': 'off', - 'unicorn/prefer-at': 'off', - 'unicorn/prefer-code-point': 'off', - 'unicorn/prefer-math-trunc': 'off', - 'unicorn/prefer-number-properties': 'off', - 'unicorn/prefer-string-raw': 'off', - 'unicorn/prefer-string-replace-all': 'off', - 'unicorn/prefer-structured-clone': 'off', - 'unicorn/prefer-top-level-await': 'off', - 'unicorn/prevent-abbreviations': ['error', { replacements: { dir: false } }] - } -}; diff --git a/.lintstagedrc.js b/.lintstagedrc.js index c2d421426..0eecedc99 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,4 +1,4 @@ module.exports = { - '*.{ts,js}': ['eslint --fix --cache'], '*.md': ['prettier --write'], + '*.{ts,js}': ['eslint --fix --cache'] }; diff --git a/.prettierrc.json b/.prettierrc.json index c1e4a6747..0de43bbd5 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -13,5 +13,6 @@ "proseWrap": "never" } } - ] + ], + "plugins": ["prettier-plugin-organize-imports"] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 934a74fb0..4f53fe57f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # rollup changelog +## 4.21.0 + +_2024-08-18_ + +### Features + +- Add option to configure directory for virtual modules when preserving modules (#5602) + +### Pull Requests + +- [#5602](https://github.com/rollup/rollup/pull/5602): feat: introduce the virtualDirname option to customize the virtual directory name (@TrickyPi) +- [#5607](https://github.com/rollup/rollup/pull/5607): chore(deps): update typescript-eslint monorepo to v8 (major) (@renovate[bot], @lukastaegert) +- [#5608](https://github.com/rollup/rollup/pull/5608): chore(deps): lock file maintenance minor/patch updates (@renovate[bot]) +- [#5611](https://github.com/rollup/rollup/pull/5611): chore: fix the `noConflict` option in REPL. (@7086cmd) +- [#5613](https://github.com/rollup/rollup/pull/5613): chore(deps): lock file maintenance minor/patch updates (@renovate[bot]) +- [#5614](https://github.com/rollup/rollup/pull/5614): chore(deps): lock file maintenance (@renovate[bot]) + +## 4.20.0 + +_2024-08-03_ + +### Features + +- Allow plugins to specify the original file name when emitting assets (#5596) + +### Pull Requests + +- [#5596](https://github.com/rollup/rollup/pull/5596): Add originalFIleName property to emitted assets (@lukastaegert) +- [#5599](https://github.com/rollup/rollup/pull/5599): chore(deps): update dependency eslint-plugin-unicorn to v55 (@renovate[bot], @lukastaegert) +- [#5600](https://github.com/rollup/rollup/pull/5600): chore(deps): lock file maintenance minor/patch updates (@renovate[bot], @lukastaegert) + ## 4.19.2 _2024-08-01_ diff --git a/browser/package.json b/browser/package.json index a10909c56..11261ccaf 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/browser", - "version": "4.19.2", + "version": "4.21.0", "description": "Next-generation ES module bundler browser build", "main": "dist/rollup.browser.js", "module": "dist/es/rollup.browser.js", diff --git a/browser/src/initWasm.ts b/browser/src/initWasm.ts index ccd5e8d56..c39332521 100644 --- a/browser/src/initWasm.ts +++ b/browser/src/initWasm.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line import/no-unresolved import init from '../../wasm/bindings_wasm'; export default async function initWasm() { diff --git a/browser/src/wasm.ts b/browser/src/wasm.ts index e0249605a..c663b8ebd 100644 --- a/browser/src/wasm.ts +++ b/browser/src/wasm.ts @@ -1,8 +1,7 @@ -// eslint-disable-next-line import/no-unresolved -export { parse, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../wasm/bindings_wasm.js'; +export { parse, xxhashBase16, xxhashBase36, xxhashBase64Url } from '../../wasm/bindings_wasm.js'; -// eslint-disable-next-line import/no-unresolved import { parse } from '../../wasm/bindings_wasm.js'; + export async function parseAsync( code: string, allowReturnOutsideFunction: boolean, diff --git a/build-plugins/fs-events-replacement.ts b/build-plugins/fs-events-replacement.ts index 141c5bd0f..0b8d118d1 100644 --- a/build-plugins/fs-events-replacement.ts +++ b/build-plugins/fs-events-replacement.ts @@ -1,6 +1,6 @@ +import type { RollupReplaceOptions } from '@rollup/plugin-replace'; import { readFile } from 'node:fs/promises'; import { exit } from 'node:process'; -import type { RollupReplaceOptions } from '@rollup/plugin-replace'; const FSEVENTS_HANDLER = 'node_modules/chokidar/lib/fsevents-handler.js'; const FSEVENTS_REQUIRE = "require('fsevents')"; diff --git a/cli/cli.ts b/cli/cli.ts index 915427485..2f4f105a5 100644 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import process from 'node:process'; import help from 'help.md'; +import process from 'node:process'; import { version } from 'package.json'; import argParser from 'yargs-parser'; import { commandAliases } from '../src/utils/options/mergeOptions'; @@ -17,7 +17,7 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) { console.log(`rollup v${version}`); } else { try { - // eslint-disable-next-line unicorn/prefer-module + // eslint-disable-next-line @typescript-eslint/no-require-imports require('source-map-support').install(); } catch { // do nothing @@ -25,7 +25,6 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) { const promise = run(command); if (command.forceExit) { - // eslint-disable-next-line unicorn/no-process-exit promise.then(() => process.exit()); } } diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index ea4961143..7d28da401 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -92,9 +92,7 @@ export default function batchWarnings(command: Record): BatchWarnin }; } -const immediateHandlers: { - [code: string]: (warning: RollupLog) => void; -} = { +const immediateHandlers: Record void> = { MISSING_NODE_BUILTINS(warning) { title(`Missing shims for Node.js built-ins`); @@ -111,9 +109,7 @@ const immediateHandlers: { } }; -const deferredHandlers: { - [code: string]: (warnings: RollupLog[]) => void; -} = { +const deferredHandlers: Record void> = { CIRCULAR_DEPENDENCY(warnings) { title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`); const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings; diff --git a/cli/run/commandPlugins.ts b/cli/run/commandPlugins.ts index f2ee1e9c3..15e5125a1 100644 --- a/cli/run/commandPlugins.ts +++ b/cli/run/commandPlugins.ts @@ -114,7 +114,7 @@ function getCamelizedPluginBaseName(pluginText: string): string { async function requireOrImport(pluginPath: string): Promise { try { - // eslint-disable-next-line unicorn/prefer-module + // eslint-disable-next-line @typescript-eslint/no-require-imports return require(pluginPath); } catch { return import(pluginPath); diff --git a/cli/run/getConfigPath.ts b/cli/run/getConfigPath.ts index be72bffb4..6cc1a80bd 100644 --- a/cli/run/getConfigPath.ts +++ b/cli/run/getConfigPath.ts @@ -13,11 +13,9 @@ export async function getConfigPath(commandConfig: string | true): Promise>>>>>> 262a38850870a0ef585aaa093883025dcd389d65 因此,如果你直接想从这些文件中引入,不建议盲目地使用这个选项将整个文件结构转换为另一种格式,因为预期的输出可能会丢失。在这种情况下,你应该把所有文件明确指定为入口,把它们添加到 [`input` 选项对象](#input) 中,可以查看那里的例子。 @@ -1681,7 +1686,21 @@ export default { 如果代码是无效的,将抛出警告。请注意,如果没有错误被抛出,你就可以检查输出代码。要把这个警告提升为错误,你可以在 [`onwarn`](#onwarn) 中查询。 +<<<<<<< HEAD ### preserveEntrySignatures {#preserveentrysignatures} +======= +### output.virtualDirname + +| | | +| -------: | :--------------------------- | +| Type: | `string` | +| CLI: | `--virtualDirname ` | +| Default: | `_virtual` | + +This option specifies the directory name for "virtual" files that might be emitted by plugins (like `@rollup/plugin-commonjs`). It is only validated when [`output.preserveModules`](#output-preservemodules) is enabled. + +### preserveEntrySignatures +>>>>>>> 262a38850870a0ef585aaa093883025dcd389d65 | | | | --: | :-- | diff --git a/docs/plugin-development/index.md b/docs/plugin-development/index.md index 19c650296..84fede051 100644 --- a/docs/plugin-development/index.md +++ b/docs/plugin-development/index.md @@ -670,7 +670,11 @@ interface SourceDescription { 可以被用来转换单个模块。为了防止额外的解析开销,例如,这个钩子已经使用 [`this.parse`](#this-parse) 生成了一个 AST,这个钩子可以选择返回一个 `{ code, ast, map }` 对象。`ast` 必须是一个标准的 ESTree AST,每个节点都有 `start` 和 `end` 属性。如果转换不移动代码,你可以通过将 `map` 设置为 `null` 来保留现有的 sourcemaps。否则,你可能需要生成源映射。请参阅 [源代码转换](#source-code-transformations) 部分。 +<<<<<<< HEAD 请注意,在观察模式下或明确使用缓存时,当重新构建时,此钩子的结果会被缓存,仅当模块的 `code` 发生更改或上次触发此钩子时添加了通过 `this.addWatchFile` 添加的文件时,才会再次触发该模块的钩子。 +======= +Note that in watch mode or when using the cache explicitly, the result of this hook is cached when rebuilding and the hook is only triggered again for a module `id` if either the `code` of the module has changed or a file has changed that was added via `this.addWatchFile` or `this.emitFile` the last time the hook was triggered for this module. +>>>>>>> 262a38850870a0ef585aaa093883025dcd389d65 在所有其他情况下,将触发 [`shouldTransformCachedModule`](#shouldtransformcachedmodule) 钩子,该钩子可以访问缓存的模块。从 `shouldTransformCachedModule` 返回 `true` 将从缓存中删除该模块,并再次调用 `transform`。 @@ -908,8 +912,9 @@ function augmentWithDatePlugin() { ```typescript interface OutputAsset { fileName: string; - name?: string; + name: string | undefined; needsCodeReference: boolean; + originalFileName: string | null; source: string | Uint8Array; type: 'asset'; } @@ -1244,7 +1249,13 @@ function importMetaUrlCurrentModulePlugin() { 添加额外的文件以在监视模式下监视,以便更改这些文件将触发重建。`id` 可以是文件或目录的绝对路径,也可以是相对于当前工作目录的路径。此上下文函数可以在所有插件钩子中使用,除了 `closeBundle`。但是,如果 [`watch.skipWrite`](../configuration-options/index.md#watch-skipwrite) 设置为 `true`,则在 [输出生成钩子](#output-generation-hooks) 中使用它将不起作用。 +<<<<<<< HEAD **注意**:通常在监视模式下,为了提高重建速度,`transform` 钩子只会在给定模块的内容实际更改时触发。从 `transform` 钩子中使用 `this.addWatchFile` 将确保如果监视的文件更改,则也将重新评估此模块的 `transform` 钩子。 +======= +Note that when emitting assets that correspond to an existing file, it is recommended to set the `originalFileName` property in the [`this.emitFile`](#this-emitfile) call instead as that will not only watch the file but also make the connection transparent to other plugins. + +**Note:** Usually in watch mode to improve rebuild speed, the `transform` hook will only be triggered for a given module if its contents actually changed. Using `this.addWatchFile` from within the `transform` hook will make sure the `transform` hook is also reevaluated for this module if the watched file changes. +>>>>>>> 262a38850870a0ef585aaa093883025dcd389d65 通常建议从依赖于监视文件的钩子中使用 `this.addWatchFile`。 @@ -1305,6 +1316,7 @@ interface EmittedAsset { type: 'asset'; name?: string; needsCodeReference?: boolean; + originalFileName?: string; fileName?: string; source?: string | Uint8Array; } @@ -1445,7 +1457,15 @@ import { foo } from './my-prebuilt-chunk.js'; 目前,产出预构建的块是一个基本功能。期待你的反馈。 +<<<<<<< HEAD 如果 `type` 是 _`asset`_,则它会产出一个具有给定 `source` 作为内容的任意新文件。可以通过 [`this.setAssetSource(referenceId, source)`](#this-setassetsource) 推迟设置 `source` 到稍后的时间,以便在构建阶段引用文件,同时在生成阶段为每个输出单独设置源。具有指定 `fileName` 的资产将始终生成单独的文件,而其他产出的资产可能会与现有资产进行去重,即使 `name` 不匹配。如果这样的资产没有被去重,则会使用 [`output.assetFileNames`](../configuration-options/index.md#output-assetfilenames) 名称模式。如果 `needsCodeReference` 设置为 `true`,并且此资产在输出中没有任何代码通过 `import.meta.ROLLUP_FILE_URL_referenceId` 引用,则 Rollup 将不会产出它。同时这也遵从通过除屑优化删除的引用,即如果相应的 `import.meta.ROLLUP_FILE_URL_referenceId` 是源代码的一部分,但实际上没有使用,引用被除屑优化给删除掉,也不会打包出相关的资源文件。 +======= +If the `type` is _`asset`_, then this emits an arbitrary new file with the given `source` as content. It is possible to defer setting the `source` via [`this.setAssetSource(referenceId, source)`](#this-setassetsource) to a later time to be able to reference a file during the build phase while setting the source separately for each output during the generate phase. Assets with a specified `fileName` will always generate separate files while other emitted assets may be deduplicated with existing assets if they have the same source even if the `name` does not match. If an asset without a `fileName` is not deduplicated, the [`output.assetFileNames`](../configuration-options/index.md#output-assetfilenames) name pattern will be used. + +If this asset corresponds to an actual file on disk, then `originalFileName` should be set to the absolute path of the file. In that case, this property will be passed on to subsequent plugin hooks that receive a `PreRenderedAsset` or an `OutputAsset` like [`generateBundle`](#generatebundle). In watch mode, Rollup will also automatically watch this file for changes and trigger a rebuild if it changes. Therefore, it is not necessary to call `this.addWatchFile` for this file. + +If `needsCodeReference` is set to `true` and this asset is not referenced by any code in the output via `import.meta.ROLLUP_FILE_URL_referenceId`, then Rollup will not emit it. This also respects references removed via tree-shaking, i.e. if the corresponding `import.meta.ROLLUP_FILE_URL_referenceId` is part of the source code but is not actually used and the reference is removed by tree-shaking, then the asset is not emitted. +>>>>>>> 262a38850870a0ef585aaa093883025dcd389d65 ### this.error diff --git a/docs/repl/components/BundleOptions.vue b/docs/repl/components/BundleOptions.vue index 0f552b5ca..d1eeaa78c 100644 --- a/docs/repl/components/BundleOptions.vue +++ b/docs/repl/components/BundleOptions.vue @@ -35,8 +35,8 @@ @input="optionsStore.set(option.name, Number($event.target.value))" />
diff --git a/docs/repl/components/InputHeader.vue b/docs/repl/components/InputHeader.vue index 09441c3f7..a9b2aed20 100644 --- a/docs/repl/components/InputHeader.vue +++ b/docs/repl/components/InputHeader.vue @@ -11,7 +11,6 @@