From f660c34d27453f6e87555577569d47fc2840e038 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 29 Mar 2025 06:34:18 +0100 Subject: [PATCH 1/4] chore(deps): update dependency eslint-plugin-unicorn to v58 (#5895) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package-lock.json | 57 +++++++++++++---------------------------------- package.json | 2 +- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index cc38172f9..dd960478f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,7 +56,7 @@ "eslint": "^9.23.0", "eslint-config-prettier": "^10.1.1", "eslint-plugin-prettier": "^5.2.4", - "eslint-plugin-unicorn": "^57.0.0", + "eslint-plugin-unicorn": "^58.0.0", "eslint-plugin-vue": "^10.0.0", "fixturify": "^3.0.0", "flru": "^1.0.2", @@ -7244,21 +7244,22 @@ } }, "node_modules/eslint-plugin-unicorn": { - "version": "57.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-57.0.0.tgz", - "integrity": "sha512-zUYYa6zfNdTeG9BISWDlcLmz16c+2Ck2o5ZDHh0UzXJz3DEP7xjmlVDTzbyV0W+XksgZ0q37WEWzN2D2Ze+g9Q==", + "version": "58.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-58.0.0.tgz", + "integrity": "sha512-fc3iaxCm9chBWOHPVjn+Czb/wHS0D2Mko7wkOdobqo9R2bbFObc4LyZaLTNy0mhZOP84nKkLhTUQxlLOZ7EjKw==", "dev": true, "license": "MIT", "dependencies": { "@babel/helper-validator-identifier": "^7.25.9", - "@eslint-community/eslint-utils": "^4.4.1", - "ci-info": "^4.1.0", + "@eslint-community/eslint-utils": "^4.5.1", + "@eslint/plugin-kit": "^0.2.7", + "ci-info": "^4.2.0", "clean-regexp": "^1.0.0", - "core-js-compat": "^3.40.0", + "core-js-compat": "^3.41.0", "esquery": "^1.6.0", - "globals": "^15.15.0", + "globals": "^16.0.0", "indent-string": "^5.0.0", - "is-builtin-module": "^4.0.0", + "is-builtin-module": "^5.0.0", "jsesc": "^3.1.0", "pluralize": "^8.0.0", "read-package-up": "^11.0.0", @@ -7268,26 +7269,13 @@ "strip-indent": "^4.0.0" }, "engines": { - "node": ">=18.18" + "node": "^18.20.0 || ^20.10.0 || >=21.0.0" }, "funding": { "url": "https://github.com/sindresorhus/eslint-plugin-unicorn?sponsor=1" }, "peerDependencies": { - "eslint": ">=9.20.0" - } - }, - "node_modules/eslint-plugin-unicorn/node_modules/globals": { - "version": "15.15.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz", - "integrity": "sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "eslint": ">=9.22.0" } }, "node_modules/eslint-plugin-vue": { @@ -8735,13 +8723,13 @@ } }, "node_modules/is-builtin-module": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-4.0.0.tgz", - "integrity": "sha512-rWP3AMAalQSesXO8gleROyL2iKU73SX5Er66losQn9rWOWL4Gef0a/xOEOVqjWGMuR2vHG3FJ8UUmT700O8oFg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-5.0.0.tgz", + "integrity": "sha512-f4RqJKBUe5rQkJ2eJEJBXSticB3hGbN9j0yxxMQFqIW89Jp9WYFtzfTcRlstDKVUTRzSOTLKRfO9vIztenwtxA==", "dev": true, "license": "MIT", "dependencies": { - "builtin-modules": "^4.0.0" + "builtin-modules": "^5.0.0" }, "engines": { "node": ">=18.20" @@ -8750,19 +8738,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-builtin-module/node_modules/builtin-modules": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-4.0.0.tgz", - "integrity": "sha512-p1n8zyCkt1BVrKNFymOHjcDSAl7oq/gUvfgULv2EblgpPVQlQr9yHnWjg9IJ2MhfwPqiYqMMrr01OY7yQoK2yA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-core-module": { "version": "2.16.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", diff --git a/package.json b/package.json index f61e6e5d4..70acef877 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "eslint": "^9.23.0", "eslint-config-prettier": "^10.1.1", "eslint-plugin-prettier": "^5.2.4", - "eslint-plugin-unicorn": "^57.0.0", + "eslint-plugin-unicorn": "^58.0.0", "eslint-plugin-vue": "^10.0.0", "fixturify": "^3.0.0", "flru": "^1.0.2", From 41a0b6f89900dd2b3915e5cda1f9fdffb7220259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 29 Mar 2025 14:39:30 +0900 Subject: [PATCH 2/4] Add support for hook filters (#5882) * Add support for hook filters * chore: remove solo: true * test: add empty filter cases * test: add another empty filter case * chore: tweak comment * refactor: use `getOrCreate` and inline methods * refactor: rename to `expectedCalledHooks` * fix: only convert to relative path for glob matcher * fix: port changes from rolldown * test: update typescript test * test: add test with normalize --- browser/LICENSE.md | 29 ++++ docs/plugin-development/index.md | 38 +++- package-lock.json | 9 + package.json | 2 + src/rollup/types.d.ts | 25 ++- src/utils/PluginDriver.ts | 33 ++++ src/utils/getOrCreate.ts | 12 +- src/utils/pluginFilter.ts | 140 +++++++++++++++ .../samples/plugin-hook-filters/_config.js | 162 ++++++++++++++++++ .../samples/plugin-hook-filters/bar.js | 1 + .../samples/plugin-hook-filters/baz.js | 1 + .../samples/plugin-hook-filters/foo.js | 1 + .../samples/plugin-hook-filters/main.js | 3 + test/typescript/index.ts | 27 +++ 14 files changed, 480 insertions(+), 3 deletions(-) create mode 100644 src/utils/pluginFilter.ts create mode 100644 test/function/samples/plugin-hook-filters/_config.js create mode 100644 test/function/samples/plugin-hook-filters/bar.js create mode 100644 test/function/samples/plugin-hook-filters/baz.js create mode 100644 test/function/samples/plugin-hook-filters/foo.js create mode 100644 test/function/samples/plugin-hook-filters/main.js diff --git a/browser/LICENSE.md b/browser/LICENSE.md index b589d68c9..c95d54d64 100644 --- a/browser/LICENSE.md +++ b/browser/LICENSE.md @@ -134,3 +134,32 @@ Repository: https://github.com/rich-harris/magic-string > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + +## picomatch +License: MIT +By: Jon Schlinkert +Repository: micromatch/picomatch + +> The MIT License (MIT) +> +> Copyright (c) 2017-present, Jon Schlinkert. +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/docs/plugin-development/index.md b/docs/plugin-development/index.md index 3b96ba785..0bdef13bd 100644 --- a/docs/plugin-development/index.md +++ b/docs/plugin-development/index.md @@ -93,7 +93,7 @@ To interact with the build process, your plugin object includes "hooks". Hooks a - `sequential`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is `async`, subsequent hooks of this kind will wait until the current hook is resolved. - `parallel`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is `async`, subsequent hooks of this kind will be run in parallel and not wait for the current hook. -Instead of a function, hooks can also be objects. In that case, the actual hook function (or value for `banner/footer/intro/outro`) must be specified as `handler`. This allows you to provide additional optional properties that change hook execution: +Instead of a function, hooks can also be objects. In that case, the actual hook function (or value for `banner/footer/intro/outro`) must be specified as `handler`. This allows you to provide additional optional properties that change hook execution or skip hook execution: - `order: "pre" | "post" | null`
If there are several plugins implementing this hook, either run this plugin first (`"pre"`), last (`"post"`), or in the user-specified position (no value or `null`). @@ -145,6 +145,42 @@ Instead of a function, hooks can also be objects. In that case, the actual hook } ``` +- `filter`
Run this plugin hook only when the specified filter returns true. This property is only available for `resolveId`, `load`, `transform`. The `code` filter is only available for `transform` hook. The `id` filter supports [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features) except for `resolveId` hook. + + ```ts + type StringOrRegExp = string | RegExp; + type StringFilter = + | MaybeArray + | { + include?: MaybeArray; + exclude?: MaybeArray; + }; + + interface HookFilter { + id?: StringFilter; + code?: StringFilter; + } + ``` + + ```js twoslash + /** @returns {import('rollup').Plugin} */ + // ---cut--- + export default function jsxAdditionalTransform() { + return { + name: 'jsxAdditionalTransform', + transform: { + filter: { + id: '*.jsx', + code: ' here + } + } + }; + } + ``` + Build hooks are run during the build phase, which is triggered by `rollup.rollup(inputOptions)`. They are mainly concerned with locating, providing and transforming input files before they are processed by Rollup. The first hook of the build phase is [`options`](#options), the last one is always [`buildEnd`](#buildend). If there is a build error, [`closeBundle`](#closebundle) will be called after that.