Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: using rolldown #11

Open
wants to merge 1 commit into
base: 11-08-feat_add_jsx_transfrom
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,23 @@ Repository: gulpjs/glob-parent

---------------------------------------

## has-flag
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/has-flag

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
>
> 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.

---------------------------------------

## http-proxy
License: MIT
By: Charlie Robbins, jcrugzz <jcrugzz@gmail.com>
Expand Down Expand Up @@ -3106,6 +3123,23 @@ Repository: git+https://github.com/antfu/strip-literal.git

---------------------------------------

## supports-color
License: MIT
By: Sindre Sorhus
Repository: chalk/supports-color

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
>
> 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.

---------------------------------------

## to-regex-range
License: MIT
By: Jon Schlinkert, Rouven Weßling
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"dependencies": {
"esbuild": "^0.19.3",
"postcss": "^8.4.31",
"rollup": "^4.2.0"
"rollup": "^4.2.0",
"@rolldown/node": "/Users/likui/Github/rolldown/packages/node"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
Expand All @@ -90,7 +91,6 @@
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/pluginutils": "^5.0.5",
"@types/escape-html": "^1.0.3",
"@types/pnpapi": "^0.0.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import type { ImportKind } from 'esbuild'
import type { Plugin } from 'rollup'
import type { Plugin } from '@rolldown/node'
import { KNOWN_ASSET_TYPES } from '../constants'
import type { PackageCache } from '../packages'
import { getDepOptimizationConfig } from '../config'
Expand Down Expand Up @@ -149,7 +149,7 @@ export function rollupDepPlugin(
},
resolveId: async function (id, importer, options) {
// TODO rolldown: kind is not available in rollup
const kind: ImportKind = options.custom?.kind
const kind: ImportKind = options.kind
// externalize assets and commonly known non-js file types
// See #8459 for more details about this require-import conversion
if (allExternalTypesReg.test(id)) {
Expand Down Expand Up @@ -296,7 +296,7 @@ export function rollupCjsExternalPlugin(

if (filter.test(id)) {
// TODO rolldown: kind is not available in rollup
const kind: ImportKind = options.custom?.kind
const kind: ImportKind = options.kind
if (kind === 'require-call' && platform !== 'node') {
return {
id: cjsExternalFacadeNamespace + id,
Expand Down
44 changes: 21 additions & 23 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import { promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import type { RollupOutput } from 'rollup'
import type { RollupOptions, RollupOutput } from '@rolldown/node'
import rollupPluginReplace from '@rollup/plugin-replace'
import rollup from 'rollup'
import * as rolldown from '@rolldown/node'
import colors from 'picocolors'
import type { BuildOptions as EsbuildBuildOptions } from 'esbuild'
import { build } from 'esbuild'
Expand All @@ -28,10 +28,8 @@ import {
removeLeadingSlash,
tryStatSync,
} from '../utils'
import { transformWithEsbuild } from '../plugins/esbuild'
import { prettifyMessage, transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET } from '../constants'
import { Rollup } from '..'
import { definePlugin } from '../plugins/define'
import { rollupCjsExternalPlugin, rollupDepPlugin } from './esbuildDepPlugin'
import { scanImports } from './scan'
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
Expand Down Expand Up @@ -115,7 +113,7 @@ export interface DepOptimizationConfig {
| 'metafile'
>

rollupOptions: rollup.RollupOptions
rollupOptions?: RollupOptions
/**
* List of file extensions that can be optimized. A corresponding esbuild
* plugin must exist to handle the specific extension.
Expand Down Expand Up @@ -626,17 +624,17 @@ export function runOptimizeDeps(
for (const chunk of result.output) {
if (chunk.type === 'chunk' && chunk.isEntry) {
if (chunk.isEntry) {
const id = chunk.facadeModuleId!

const { exportsData, ...info } = depsInfo[id]
const { exportsData, file, id, ...info } = Object.values(
depsInfo,
).find((d) => d.src?.endsWith(chunk.facadeModuleId!))!
addOptimizedDepInfo(metadata, 'optimized', {
id,
file,
...info,
// We only need to hash the output.imports in to check for stability, but adding the hash
// and file path gives us a unique hash that may be useful for other things in the future
fileHash: getHash(
metadata.hash +
depsInfo[id].file +
JSON.stringify(chunk.imports),
metadata.hash + file + JSON.stringify(chunk.modules),
),
browserHash: metadata.browserHash,
// After bundling we have more information and can warn the user about legacy packages
Expand Down Expand Up @@ -790,7 +788,6 @@ async function prepareRollupOptimizerRun(
plugins.push(rollupCjsExternalPlugin(external, platform))
}
plugins.push(rollupDepPlugin(flatIdDeps, external, config, ssr))
plugins.push(rollupPluginReplace(define))
plugins.push({
name: 'optimizer-transform',
async transform(code, id) {
Expand All @@ -799,6 +796,7 @@ async function prepareRollupOptimizerRun(
sourcemap: true,
sourcefile: id,
loader: jsxLoader && /\.js$/.test(id) ? 'jsx' : undefined,
define,
target: isBuild
? config.build.target || undefined
: ESBUILD_MODULES_TARGET,
Expand All @@ -816,25 +814,25 @@ async function prepareRollupOptimizerRun(

async function build() {
// TODO platform
const bundle = await rollup.rollup({
const bundle = await rolldown.rolldown({
input: Object.keys(flatIdDeps),
external,
logLevel: 'warn',
// logLevel: 'warn',
plugins,
...rollupOptions,
})
return await bundle.write({
format: 'esm',
sourcemap: true,
// sourcemap: true,
dir: processingCacheDir,
// See https://github.com/evanw/esbuild/issues/1921#issuecomment-1152991694
banner:
platform === 'node'
? (chunk) =>
chunk.fileName.endsWith('.js')
? `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
: ''
: undefined,
// banner:
// platform === 'node'
// ? (chunk) =>
// chunk.fileName.endsWith('.js')
// ? `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
// : ''
// : undefined,
...rollupOptions.output,
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export function resolveEsbuildTranspileOptions(
}
}

function prettifyMessage(m: Message, code: string): string {
export function prettifyMessage(m: Message, code: string): string {
let res = colors.yellow(m.text)
if (m.location) {
const lines = code.split(/\r?\n/g)
Expand Down
47 changes: 3 additions & 44 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.