From 942e5e470aa10235d8681b9a8ce9ac799049a210 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: Sat, 9 Mar 2024 02:35:25 +0800 Subject: [PATCH 1/2] feat: rolldown --- package.json | 5 ++ pnpm-lock.yaml | 99 +++++++++++++++++++++++ src/rolldown.ts | 22 +++++ tests/__snapshots__/rolldown.test.ts.snap | 12 +++ tests/rolldown.test.ts | 21 +++++ tests/rollup.test.ts | 1 - 6 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/rolldown.ts create mode 100644 tests/__snapshots__/rolldown.test.ts.snap create mode 100644 tests/rolldown.test.ts diff --git a/package.json b/package.json index a6d6b45..bc5e907 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,10 @@ "require": "./dist/rollup.js", "import": "./dist/rollup.mjs" }, + "./rolldown": { + "require": "./dist/rolldown.js", + "import": "./dist/rolldown.mjs" + }, "./esbuild": { "require": "./dist/esbuild.js", "import": "./dist/esbuild.mjs" @@ -88,6 +92,7 @@ "eslint": "^8.57.0", "fast-glob": "^3.3.2", "prettier": "^3.2.5", + "rolldown": "0.10.0-canary-862ce3a-20240325012650", "rollup": "^4.13.0", "tsup": "^8.0.2", "tsx": "^4.7.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0872320..5680f53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,6 +43,9 @@ devDependencies: prettier: specifier: ^3.2.5 version: 3.2.5 + rolldown: + specifier: 0.10.0-canary-862ce3a-20240325012650 + version: 0.10.0-canary-862ce3a-20240325012650 rollup: specifier: ^4.13.0 version: 4.13.0 @@ -942,6 +945,86 @@ packages: tslib: 2.6.2 dev: true + /@rolldown/binding-darwin-arm64@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-jHrXFlMWFp33aOfzfkEdk75iMpi7U4McJ5dOE/RCdZQin9U7ug6TdxCLaYMFSnwR/b6dKwsRM4vA0pXH7PRC6A==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-darwin-x64@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-zuRFaNmSyP9boUH2uEQyPpTDQBavL97Fio/hNRlM3Gx0tzibiEAIdfeCqOjTBXvcVcYpxPHDwtgyWEUC9ZmHlQ==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-linux-arm-gnueabihf@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-BWDK0NyL5rZu6LjVsTAhKcTJmjk4wg5kfAmVE1BKvzIx6FXHn4be+rj44AADUvQ7snWTRfEARjwvh0wLY1Zc6g==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-linux-arm64-gnu@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-O3pPUkG/YWVmVni089zjmxq6xNywPgqd/VVySG9Khia5aa5VP6JPIwoZ0k0+fAtvEa3MhnvgLnQrbZ4eJgTYoA==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-linux-arm64-musl@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-W5WiCM5zlR7QOSjDK/aSusm4wd6j5uipOO18aRTkOK7sS31uRI1Hrthx5xciA/lOKh14PgzV9R7tzaR8yzMH6w==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-linux-x64-gnu@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-pbRswA8zCbl+PXQWzQXn/cB94KGLUY2zxATlaGQUObFbJWnjYV7mGhmGqrEdAWtXlUS0GKSVBptSv7SWpCBt7Q==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-linux-x64-musl@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-dNgEdI94pTiovQHY8os/U/RUaMAw2pWy6g5A7hDZAVQ0sMcUIU4QNcG/XWZ7htge6NNCUlq7JLm8be7LuZpd8A==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-win32-arm64-msvc@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-a9CESngBA+t6CvU4/vAeMC9Qo2S30CjT7T44X74ojPQ7fYV8qb33ZFOVINmT7hblTKMAxWewe5iqCVVxJ8RgdQ==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-win32-ia32-msvc@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-nCzJsbf4fXnXJo3l89IIRHGtBhFawxdV/OdQ16/R31TOdJeMyHbSVEiuDclR/TZpr19/cXbE1DoZUth6Gjiu+w==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rolldown/binding-win32-x64-msvc@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-NIAQ2W/dtTjs9rPGH8j8sms0dijUa7zUCrppsrSUwdgIFDdDzVG9joI6pkdd2g8Ul4FAC3Agi/aS8gMvb/j2mA==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@rollup/plugin-json@6.1.0(rollup@4.13.0): resolution: {integrity: sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==} engines: {node: '>=14.0.0'} @@ -3908,6 +3991,22 @@ packages: glob: 7.2.3 dev: true + /rolldown@0.10.0-canary-862ce3a-20240325012650: + resolution: {integrity: sha512-JgelntXit0jM6e+Pdd+nKF+RXGTYsK6SK0OjAhgN2HV4KQsvyIIhP+Bq/6v9Gi0kHzz3WROiuxaMJrVte2R+dg==} + hasBin: true + optionalDependencies: + '@rolldown/binding-darwin-arm64': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-darwin-x64': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-linux-arm-gnueabihf': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-linux-arm64-gnu': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-linux-arm64-musl': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-linux-x64-gnu': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-linux-x64-musl': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-win32-arm64-msvc': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-win32-ia32-msvc': 0.10.0-canary-862ce3a-20240325012650 + '@rolldown/binding-win32-x64-msvc': 0.10.0-canary-862ce3a-20240325012650 + dev: true + /rollup-plugin-esbuild@6.1.1(esbuild@0.20.2)(rollup@4.13.0): resolution: {integrity: sha512-CehMY9FAqJD5OUaE/Mi1r5z0kNeYxItmRO2zG4Qnv2qWKF09J2lTy5GUzjJR354ZPrLkCj4fiBN41lo8PzBUhw==} engines: {node: '>=14.18.0'} diff --git a/src/rolldown.ts b/src/rolldown.ts new file mode 100644 index 0000000..ba97d4a --- /dev/null +++ b/src/rolldown.ts @@ -0,0 +1,22 @@ +/** + * This entry file is for Rolldown plugin. + * + * @module + */ + +import unplugin from './index' + +/** + * Rolldown plugin + * + * @example + * ```ts + * // rolldown.config.js + * import Replace from 'unplugin-replace/rolldown' + * + * export default { + * plugins: [Replace()], + * } + * ``` + */ +export default unplugin.rolldown diff --git a/tests/__snapshots__/rolldown.test.ts.snap b/tests/__snapshots__/rolldown.test.ts.snap new file mode 100644 index 0000000..3952be4 --- /dev/null +++ b/tests/__snapshots__/rolldown.test.ts.snap @@ -0,0 +1,12 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`rolldown 1`] = ` +"import { default as process } from "node:process"; + +// tests/fixtures/main.js +const platform = 'darwin'; +console.log('hello "darwin"', platform); +console.log(DEV); + +export { platform };" +`; diff --git a/tests/rolldown.test.ts b/tests/rolldown.test.ts new file mode 100644 index 0000000..a4ad9b6 --- /dev/null +++ b/tests/rolldown.test.ts @@ -0,0 +1,21 @@ +import path from 'node:path' +import { expect, test } from 'vitest' +import { rolldown } from '@rolldown/node' +import UnpluginReplace from '../src/rolldown' + +test('rolldown', async () => { + const build = await rolldown({ + input: path.resolve(__dirname, 'fixtures/main.js'), + external: ['node:process'], + plugins: [ + UnpluginReplace({ + 'process.platform': '"darwin"', + }), + ], + }) + const { output } = await build.generate({ format: 'esm' }) + const code = output[0].code + expect(code).toMatchSnapshot() + expect(code).not.contains('process.platform') + expect(code).contains('"darwin"') +}) diff --git a/tests/rollup.test.ts b/tests/rollup.test.ts index 575ad09..ccec8cc 100644 --- a/tests/rollup.test.ts +++ b/tests/rollup.test.ts @@ -1,7 +1,6 @@ import path from 'node:path' import { describe, expect, test } from 'vitest' import { rollupBuild } from '@vue-macros/test-utils' - import UnpluginReplace from '../src/rollup' describe('rollup', () => { From 81714cd2cf75dc96117a88bc7f562e28390a3217 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: Mon, 25 Mar 2024 22:24:18 +0800 Subject: [PATCH 2/2] test: fix --- tests/rolldown.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rolldown.test.ts b/tests/rolldown.test.ts index a4ad9b6..435e816 100644 --- a/tests/rolldown.test.ts +++ b/tests/rolldown.test.ts @@ -1,6 +1,6 @@ import path from 'node:path' import { expect, test } from 'vitest' -import { rolldown } from '@rolldown/node' +import { rolldown } from 'rolldown' import UnpluginReplace from '../src/rolldown' test('rolldown', async () => { @@ -13,7 +13,7 @@ test('rolldown', async () => { }), ], }) - const { output } = await build.generate({ format: 'esm' }) + const { output } = await build.generate({ format: 'es' }) const code = output[0].code expect(code).toMatchSnapshot() expect(code).not.contains('process.platform')