Skip to content

Commit

Permalink
fix: workaround sync banner fn issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jul 18, 2024
1 parent b79cb94 commit 9fdf94a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import {
tryStatSync,
unique,
} from '../utils'
import {
transformWithEsbuild,
} from '../plugins/esbuild'
import { transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET, METADATA_FILENAME } from '../constants'
import { isWindows } from '../../shared/utils'
import { rolldownCjsExternalPlugin, rolldownDepPlugin } from './rolldownDepPlugin'
import {
rolldownCjsExternalPlugin,
rolldownDepPlugin,
} from './rolldownDepPlugin'
import { scanImports } from './scan'
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
export {
Expand Down Expand Up @@ -617,8 +618,7 @@ export function runOptimizeDeps(
if (chunk.isEntry) {
// One chunk maybe corresponding multiply entry
const deps = Object.values(depsInfo).filter(
(d) =>
d.src === chunk.facadeModuleId!,
(d) => d.src === chunk.facadeModuleId!,
)
for (const { exportsData, file, id, ...info } of deps) {
addOptimizedDepInfo(metadata, 'optimized', {
Expand Down Expand Up @@ -810,7 +810,7 @@ async function prepareRolldownOptimizerRun(
resolve: {
mainFields: ['module', 'main'],
aliasFields: [['browser']],
extensions: ['.js', '.css']
extensions: ['.js', '.css'],
},
...rollupOptions,
})
Expand All @@ -820,7 +820,8 @@ async function prepareRolldownOptimizerRun(
dir: processingCacheDir,
banner:
platform === 'node'
? (chunk) =>
? // TODO: use async to workaround https://github.com/rolldown/rolldown/issues/1655
async (chunk) =>
chunk.fileName.endsWith('.js')
? `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
: ''
Expand Down Expand Up @@ -1037,13 +1038,16 @@ function stringifyDepsOptimizerMetadata(
file,
fileHash,
needsInterop,
isDynamicEntry
isDynamicEntry,
},
],
),
),
chunks: Object.fromEntries(
Object.values(chunks).map(({ id, file, isDynamicEntry }) => [id, { file, isDynamicEntry }]),
Object.values(chunks).map(({ id, file, isDynamicEntry }) => [
id,
{ file, isDynamicEntry },
]),
),
},
(key: string, value: string) => {
Expand Down Expand Up @@ -1075,11 +1079,11 @@ export async function extractExportsData(
const rolldownBuild = await rolldown.rolldown({
...rollupOptions,
input: [filePath],
});
})
const result = await rolldownBuild.generate({
...rollupOptions.output,
format: 'esm',
});
})
const [, exports, , hasModuleSyntax] = parse(result.output[0].code)
return {
hasModuleSyntax,
Expand Down

0 comments on commit 9fdf94a

Please sign in to comment.