From f1e6c79e633f3bdfb29970f1e58dc570994f8ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Fri, 8 Mar 2024 23:06:19 +0800 Subject: [PATCH] feat: add rolldown support --- package.json | 1 + pnpm-lock.yaml | 135 ++++++++++++++++++++++++++++++++++++++++++ src/define.ts | 10 ++++ src/rolldown/index.ts | 24 ++++++++ src/types.ts | 6 +- 5 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 src/rolldown/index.ts diff --git a/package.json b/package.json index a90c1fa5..90dd23ab 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@ampproject/remapping": "^2.3.0", "@antfu/eslint-config": "^2.8.0", "@antfu/ni": "^0.21.12", + "@rolldown/node": "^0.0.5", "@rspack/cli": "^0.5.6", "@rspack/core": "^0.5.6", "@types/fs-extra": "^11.0.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebdd3212..de9368bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,6 +28,9 @@ devDependencies: '@antfu/ni': specifier: ^0.21.12 version: 0.21.12 + '@rolldown/node': + specifier: ^0.0.5 + version: 0.0.5 '@rspack/cli': specifier: ^0.5.6 version: 0.5.6(@rspack/core@0.5.6)(webpack-cli@4.10.0)(webpack@5.90.3) @@ -888,6 +891,138 @@ packages: resolution: {integrity: sha512-2LuNTFBIO0m7kKIQvvPHN6UE63VjpmL9rnEEaOOaiSPbZK+zUOYIzBAWcED+3XYzhYsd/0mD57VdxAEqqV52CQ==} dev: true + /@rolldown/node-binding-android-arm-eabi@0.0.5: + resolution: {integrity: sha512-cucXe7VPxPX/bCZfd6fvmTHB5TWTkO3+w7MF9jcHwIGmiv46prcaBSQsWCLOS7CsQCwMlcxEHvctHsaSQJ1iGA==} + engines: {node: '>= 10'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-android-arm64@0.0.5: + resolution: {integrity: sha512-wzngkRlDxkNDXXwDgxuueiOQHlqP4Bwum4gz0QdvfnK4V6Z1EsTDmfGFf2O4re2eLbeGwEmQehWqX8qwxYxm3g==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-darwin-arm64@0.0.5: + resolution: {integrity: sha512-oACvfvHaq73BLRTHAtvQudU5mZoqWe2w++uFsohC2/i/sef0J979HhB2yt2FQ6AUwsjduQ2qYyzRqKc5j8X4tQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-darwin-x64@0.0.5: + resolution: {integrity: sha512-ZjqyxfubPlnMjiLaRh44jfmyEcyfZgT4yu0sUOxmBsq2BFCuI9FHA8qA0DSNQPvXS2T7nyWzl0GH+CxqSi1qPw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-linux-arm-gnueabihf@0.0.5: + resolution: {integrity: sha512-Vgaab13foxfs/fdruEfGXweS9xqWULMOQPzdA2zJKRw9YaaA/CW5E1IG7qkVXelolCRqe25inqcxAdva965t0w==} + engines: {node: '>= 10'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-linux-arm64-gnu@0.0.5: + resolution: {integrity: sha512-x605Z2Nz1C1YVDTKhBOBWhDmq0+32aSGuyrslLMvsQYMU5ETZ7ScpyrZFvZRHoukbcPHrCHiPsCmip4EQBspqg==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-linux-arm64-musl@0.0.5: + resolution: {integrity: sha512-biz9cAL1dTkIL1XzG95gliq+HzNQNKd5TdkONUJcyHn4hflPKvSbftk/bPiLvN3VpiFopuay6z6vzpDJ2ibyXw==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-linux-x64-gnu@0.0.5: + resolution: {integrity: sha512-6tbXWsyvD0NrdVrIxP61obbdkNt2osb7ANqkTI07QD82zS1q2z5tM5ehFSO2Jz9cv0NZTkrIngUF77xtMD5tRA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-linux-x64-musl@0.0.5: + resolution: {integrity: sha512-XtO2ivmbFB+N+ZhrRD2LndipSbaMI00jZFtb/3clIe8+AG5axGPnRnoRlNYWSyowa0yx5FjkfQoA3sXfYxjthA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-win32-arm64-msvc@0.0.5: + resolution: {integrity: sha512-oncJYwGG1FeIHbw7SueBrpwTIePtkozyyVQCUIDQM6wBSNd0vUicqLmh/oEEeAca2YOWOVWd9B8mnsakCaEPaQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-win32-ia32-msvc@0.0.5: + resolution: {integrity: sha512-g7pVkwdQdzfw8V8Kbf+EThqjz3Co6ZTac91+nr60Kn/xLjXwZ4ymakyHMhHNxkM9NAK1+U1b/WI6L4PJNEgU8g==} + engines: {node: '>= 10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding-win32-x64-msvc@0.0.5: + resolution: {integrity: sha512-PvMwPt1rti+BlsujYXT25Kpz+VkwYb7VfuHE5yIWx7mLaNUwstoN4v6ScQnTugRhHeiu9QP/Ab/SiiIHYUsiyw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rolldown/node-binding@0.0.5: + resolution: {integrity: sha512-khCsf4WEik/Ri3Buk2slxJV59EKwRwvXCXrmBpkiLMBK8VspVKq4I5pzMCn6ck+ulfSBwl7DEA+rAM5YoNtp+A==} + engines: {node: '>= 10'} + optionalDependencies: + '@rolldown/node-binding-android-arm-eabi': 0.0.5 + '@rolldown/node-binding-android-arm64': 0.0.5 + '@rolldown/node-binding-darwin-arm64': 0.0.5 + '@rolldown/node-binding-darwin-x64': 0.0.5 + '@rolldown/node-binding-linux-arm-gnueabihf': 0.0.5 + '@rolldown/node-binding-linux-arm64-gnu': 0.0.5 + '@rolldown/node-binding-linux-arm64-musl': 0.0.5 + '@rolldown/node-binding-linux-x64-gnu': 0.0.5 + '@rolldown/node-binding-linux-x64-musl': 0.0.5 + '@rolldown/node-binding-win32-arm64-msvc': 0.0.5 + '@rolldown/node-binding-win32-ia32-msvc': 0.0.5 + '@rolldown/node-binding-win32-x64-msvc': 0.0.5 + dev: true + + /@rolldown/node@0.0.5: + resolution: {integrity: sha512-2/1nvX9yJtlqDw0y1aPGfvtmCCDEWCw0TpRquWWzGWdJAaRfYHyBYpKPdUYizLc1naSaT/O3k2WyU+qfGa4hkw==} + dependencies: + '@rolldown/node-binding': 0.0.5 + dev: true + /@rollup/rollup-android-arm-eabi@4.12.1: resolution: {integrity: sha512-iU2Sya8hNn1LhsYyf0N+L4Gf9Qc+9eBTJJJsaOGUp+7x4n2M9dxTt8UvhJl3oeftSjblSlpCfvjA/IfP3g5VjQ==} cpu: [arm] diff --git a/src/define.ts b/src/define.ts index 4b7e73cf..d8a39f0e 100644 --- a/src/define.ts +++ b/src/define.ts @@ -1,4 +1,5 @@ import { getEsbuildPlugin } from './esbuild' +import { getRolldownPlugin } from './rolldown' import { getRollupPlugin } from './rollup' import { getRspackPlugin } from './rspack' import type { UnpluginFactory, UnpluginInstance } from './types' @@ -18,6 +19,9 @@ export function createUnplugin( get vite() { return getVitePlugin(factory) }, + get rolldown() { + return getRolldownPlugin(factory) + }, get webpack() { return getWebpackPlugin(factory) }, @@ -49,6 +53,12 @@ export function createVitePlugin( return getVitePlugin(factory) } +export function createRolldownPlugin( + factory: UnpluginFactory, +) { + return getRolldownPlugin(factory) +} + export function createWebpackPlugin( factory: UnpluginFactory, ) { diff --git a/src/rolldown/index.ts b/src/rolldown/index.ts new file mode 100644 index 00000000..03fe524a --- /dev/null +++ b/src/rolldown/index.ts @@ -0,0 +1,24 @@ +import { toRollupPlugin } from '../rollup' +import type { RolldownPlugin, UnpluginContextMeta, UnpluginFactory, UnpluginInstance } from '../types' +import { toArray } from '../utils' + +export function getRolldownPlugin, Nested extends boolean = boolean>( + factory: UnpluginFactory, +) { + return ((userOptions?: UserOptions) => { + const meta: UnpluginContextMeta = { + framework: 'rolldown', + } + const rawPlugins = toArray(factory(userOptions!, meta)) + + const plugins = rawPlugins.map((rawPlugin) => { + const plugin = toRollupPlugin(rawPlugin, false) as RolldownPlugin + if (rawPlugin.rolldown) + Object.assign(plugin, rawPlugin.rolldown) + + return plugin + }) + + return plugins.length === 1 ? plugins[0] : plugins + }) as UnpluginInstance['rolldown'] +} diff --git a/src/types.ts b/src/types.ts index ab3df9d0..2616bbf8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import type { AstNode, EmittedAsset, PluginContextMeta as RollupContextMeta, Plugin as RollupPlugin, SourceMapInput } from 'rollup' import type { Compiler as WebpackCompiler, WebpackPluginInstance } from 'webpack' import type { Plugin as VitePlugin } from 'vite' +import type { Plugin as RolldownPlugin } from '@rolldown/node' import type { BuildOptions, Plugin as EsbuildPlugin, Loader } from 'esbuild' import type { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core' import type VirtualModulesPlugin from 'webpack-virtual-modules' @@ -9,6 +10,7 @@ import type { EsbuildPluginBuild } from './esbuild' export { EsbuildPlugin, RollupPlugin, + RolldownPlugin, VitePlugin, WebpackPluginInstance, RspackPluginInstance, @@ -71,6 +73,7 @@ export interface UnpluginOptions { webpack?: (compiler: WebpackCompiler) => void rspack?: (compiler: RspackCompiler) => void vite?: Partial + rolldown?: Partial esbuild?: { // using regexp in esbuild improves performance onResolveFilter?: RegExp @@ -99,6 +102,7 @@ export type UnpluginFactoryOutput = undefined extends UserO export interface UnpluginInstance { rollup: UnpluginFactoryOutput : RollupPlugin> vite: UnpluginFactoryOutput : VitePlugin> + rolldown: UnpluginFactoryOutput : RolldownPlugin> webpack: UnpluginFactoryOutput rspack: UnpluginFactoryOutput esbuild: UnpluginFactoryOutput @@ -106,7 +110,7 @@ export interface UnpluginInstance } export type UnpluginContextMeta = Partial & ({ - framework: 'rollup' | 'vite' + framework: 'rollup' | 'vite' | 'rolldown' } | { framework: 'webpack' webpack: {