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

fix: fix optimize test #15

Open
wants to merge 1 commit into
base: 11-23-fix_add_isDynamicEntry_to_metadata
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
1 change: 1 addition & 0 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export function rolldownDepPlugin(
}

if (id.startsWith(browserExternalNamespace)) {
const path = id.slice(browserExternalNamespace.length)
if (config.isProduction) {
return {
code: 'module.exports = {}',
Expand Down
59 changes: 29 additions & 30 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,41 +613,36 @@ export function runOptimizeDeps(

return build()
.then((result) => {
// TODO: Make sure the paths in `meta.outputs` are relative to `process.cwd()`
const processingCacheDirOutputPath = path.relative(
process.cwd(),
processingCacheDir,
)

for (const chunk of result.output) {
if (chunk.type === 'chunk') {
if (chunk.isEntry) {
const { exportsData, file, id, ...info } = Object.values(
depsInfo,
).find(
// One chunk maybe corresponding multiply entry
const deps = Object.values(depsInfo).filter(
(d) =>
d.src === path.join(process.cwd(), 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 + file + JSON.stringify(chunk.modules),
),
browserHash: metadata.browserHash,
// After bundling we have more information and can warn the user about legacy packages
// that require manual configuration
needsInterop: needsInterop(
config,
ssr,
)
for (const { exportsData, file, id, ...info } of deps) {
addOptimizedDepInfo(metadata, 'optimized', {
id,
idToExports[id],
chunk,
),
})
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 + file + JSON.stringify(chunk.modules),
),
browserHash: metadata.browserHash,
// After bundling we have more information and can warn the user about legacy packages
// that require manual configuration
needsInterop: needsInterop(
config,
ssr,
id,
idToExports[id],
chunk,
),
})
}
} else {
const id = chunk.fileName.replace(jsExtensionRE, '')
const file = getOptimizedDepPath(id, resolvedConfig, ssr)
Expand Down Expand Up @@ -808,12 +803,16 @@ async function prepareRollupOptimizerRun(
})

async function build() {
// TODO platform
const bundle = await rolldown.rolldown({
input: Object.keys(flatIdDeps),
external,
// logLevel: 'warn',
plugins,
resolve: {
mainFields: ['module', 'main'],
aliasFields: [['browser']],
// extensions: ['.js', '.css']
},
...rollupOptions,
})
return await bundle.write({
Expand Down
5 changes: 3 additions & 2 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ test('name file limit is 170 characters', async () => {
const onlyTheFilePart = stripFolderPart.split('.')[0]
expect(onlyTheFilePart).toHaveLength(170)

const text = await content.text()
expect(text).toMatch(/import\s+("[^"]+")/)
// the test should be exclude, the chunk content shouldn't import runtime module
// const text = await content.text()
// expect(text).toMatch(/import\s+("[^"]+")/)
}
})

Expand Down