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

Generate hash for chunk #308

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function buildOutputConfigs(
strict: false,
sourcemap: options.sourcemap,
manualChunks: splitChunks,
chunkFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
entryFileNames: basename(outputFile),
}
}
Expand Down
37 changes: 29 additions & 8 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,41 @@ const testCases: {
name: 'server-components',
args: [],
async expected(dir) {
const distFiles = [
const distFiles = await fs.readdir(join(dir, 'dist'))

const requiredFiles = [
join(dir, 'dist/index.js'),
join(dir, 'dist/actions-server.js'),
join(dir, 'dist/ui-client.js'),
join(dir, 'dist/index.cjs'),
join(dir, 'dist/ui.js'),
join(dir, 'dist/ui.cjs'),
]
for (const f of distFiles) {
for (const f of requiredFiles) {
expect(await existsFile(f)).toBe(true)
}

const clientChunkFiles = distFiles.filter(f => f.includes('-client-'))
const serverChunkFiles = distFiles.filter(f => f.includes('-server-'))

// split chunks
expect(await fs.readFile(distFiles[1], 'utf-8')).toContain('use server')
expect(await fs.readFile(distFiles[2], 'utf-8')).toContain('use client')
// client component as an entry will remain the directive
expect(await fs.readFile(distFiles[3], 'utf-8')).toContain('use client')
const indexContent = await fs.readFile(join(dir, 'dist/index.js'), 'utf-8')
expect(indexContent).not.toContain('use server')
expect(indexContent).not.toContain('use client')

// client component chunks will remain the directive
clientChunkFiles.forEach(async f => {
const content = await fs.readFile(join(dir, 'dist', f), 'utf-8')
expect(content).toContain('use client')
expect(content).not.toContain('use server')
})
expect(clientChunkFiles.length).toBe(2) // cjs and esm

// server component chunks will remain the directive
serverChunkFiles.forEach(async f => {
const content = await fs.readFile(join(dir, 'dist', f), 'utf-8')
expect(content).toContain('use server')
expect(content).not.toContain('use client')
})
expect(serverChunkFiles.length).toBe(2) // cjs and esm
},
}
]
Expand Down
10 changes: 8 additions & 2 deletions test/integration/server-components/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"type": "module",
"exports": {
".": "./dist/index.js",
"./ui": "./dist/ui.js"
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./ui": {
"import": "./dist/ui.js",
"require": "./dist/ui.cjs"
}
},
"peerDependencies": {
"react": "*"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/use-client/__snapshot__/use-client.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { c as client } from './client-client.js';
import { c as client } from './client-client-0x7cvmaL.js';

var input = (()=>{
return client();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"use strict";import{c as t}from"./client-client.js";var e=()=>t();export{e as default};
"use strict";import{c as t}from"./client-client-w7FbcvRI.js";var e=()=>t();export{e as default};