Skip to content

Commit 7e16e07

Browse files
mischnicsokraclaude
authored
[backport] Turbopack: switch from base40 to base38 hash encoding (#93932)
Backport of #91832 For #93790 and #92711 Co-authored-by: Tobias Koppers <[email protected]> Co-authored-by: Tobias Koppers <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 6139f4b commit 7e16e07

546 files changed

Lines changed: 701 additions & 704 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎test/e2e/app-dir-export/test/utils.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ export const expectedWhenTrailingSlashTrue = [
3030
// Turbopack and plain next.js have different hash output for the file name
3131
// Turbopack will output favicon in the _next/static/media folder
3232
...(process.env.IS_TURBOPACK_TEST
33-
? [
34-
expect.stringMatching(
35-
/_next\/static\/media\/favicon\.[0-9a-z_.~-]+\.ico/
36-
),
37-
]
33+
? [expect.stringMatching(/_next\/static\/media\/favicon\.[0-9a-z_-]+\.ico/)]
3834
: []),
39-
expect.stringMatching(/_next\/static\/media\/test\.[0-9a-z_.~-]+\.png/),
35+
expect.stringMatching(/_next\/static\/media\/test\.[0-9a-z_-]+\.png/),
4036
expect.stringMatching(/_next\/static\/[A-Za-z0-9_-]+\/_buildManifest.js/),
4137
...(process.env.IS_TURBOPACK_TEST
4238
? [
@@ -113,13 +109,9 @@ const expectedWhenTrailingSlashFalse = [
113109
'__next._tree.txt',
114110
// Turbopack will output favicon in the _next/static/media folder
115111
...(process.env.IS_TURBOPACK_TEST
116-
? [
117-
expect.stringMatching(
118-
/_next\/static\/media\/favicon\.[0-9a-z_.~-]+\.ico/
119-
),
120-
]
112+
? [expect.stringMatching(/_next\/static\/media\/favicon\.[0-9a-z_-]+\.ico/)]
121113
: []),
122-
expect.stringMatching(/_next\/static\/media\/test\.[0-9a-z_.~-]+\.png/),
114+
expect.stringMatching(/_next\/static\/media\/test\.[0-9a-z_-]+\.png/),
123115
expect.stringMatching(/_next\/static\/[A-Za-z0-9_-]+\/_buildManifest.js/),
124116
...(process.env.IS_TURBOPACK_TEST
125117
? [

‎test/e2e/app-dir/app/index.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ describe('app dir - basic', () => {
451451
const html = await next.render('/dashboard/index')
452452
expect(html).toMatch(
453453
process.env.IS_TURBOPACK_TEST
454-
? /<script src="\/_next\/static\/chunks\/([\w-]*polyfill-nomodule|[0-9a-z_.~-]+)\.js(\?[^"]+)?" noModule="">/
454+
? /<script src="\/_next\/static\/chunks\/([\w-]*polyfill-nomodule|[0-9a-z_-]+)\.js(\?[^"]+)?" noModule="">/
455455
: /<script src="\/_next\/static\/chunks\/polyfills(-\w+)?\.js(\?[^"]+)?" noModule="">/
456456
)
457457
})

‎test/e2e/app-dir/next-image/next-image-proxy.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('next-image-proxy', () => {
7878

7979
const local = await browser.elementByCss('#app-page').getAttribute('src')
8080
expect(
81-
local.replace(/test\.[0-9a-z_.~-]{4,}\.png/g, 'test.HASH.png')
81+
local.replace(/test\.[0-9a-z_-]{4,}\.png/g, 'test.HASH.png')
8282
).toEqual(
8383
`/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.HASH.png&w=828&q=90${next.getAssetQuery(true)}`
8484
)

‎test/e2e/app-dir/next-image/next-image.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,5 @@ describe('app dir - next-image', () => {
291291
})
292292

293293
function stripTestHash(text: string) {
294-
return text.replace(/test\.[0-9a-z_.~-]{4,}\.(png|jpe?g)/g, 'test.HASH.$1')
294+
return text.replace(/test\.[0-9a-z_-]{4,}\.(png|jpe?g)/g, 'test.HASH.$1')
295295
}

‎test/e2e/app-dir/node-worker-threads/node-worker-threads.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('node-worker-threads', () => {
8484

8585
const url = new URL(data.pngInfo.url, 'http://localhost')
8686
expect(url.pathname).toMatch(
87-
/\/_next\/static.*\/test-image\.[0-9a-z_.~-]+\.png/
87+
/\/_next\/static.*\/test-image\.[0-9a-z_-]+\.png/
8888
)
8989
if (!isNextDev) {
9090
expect(next.assetToken).toMatch(/.+/)

‎test/e2e/app-dir/webpack-loader-module-type/webpack-loader-module-type.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('webpack-loader-module-type', () => {
1515
const $ = await next.render$('/')
1616
const src = $('#svg-url').text()
1717
// asset/resource should emit the file and return URL path
18-
expect(src).toMatch(/\/_next\/static\/media\/test\.[0-9a-z_.~-]+\.svg$/)
18+
expect(src).toMatch(/\/_next\/static\/media\/test\.[0-9a-z_-]+\.svg$/)
1919
})
2020

2121
itTurbopackOnly(

‎test/e2e/edge-compiler-can-import-blob-assets/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ describe('Edge Compiler can import asset assets', () => {
7070
expect(orderedAssets).toMatchObject([
7171
{
7272
name: expect.stringMatching(
73-
/server\/edge\/assets\/text-file\.[0-9a-z_.~-]+\.txt$/
73+
/server\/edge\/assets\/text-file\.[0-9a-z_-]+\.txt$/
7474
),
7575
filePath: expect.stringMatching(/^server\/edge\/assets\/text-file/),
7676
},
7777
{
7878
name: expect.stringMatching(
79-
/^server\/edge\/assets\/vercel\.[0-9a-z_.~-]+\.png$/
79+
/^server\/edge\/assets\/vercel\.[0-9a-z_-]+\.png$/
8080
),
8181
filePath: expect.stringMatching(/^server\/edge\/assets\/vercel/),
8282
},
8383
{
8484
name: expect.stringMatching(
85-
/^server\/edge\/assets\/world\.[0-9a-z_.~-]+\.json/
85+
/^server\/edge\/assets\/world\.[0-9a-z_-]+\.json/
8686
),
8787
filePath: expect.stringMatching(/^server\/edge\/assets\/world/),
8888
},

‎test/e2e/url-imports/url-imports.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { join } from 'path'
4343
}
4444

4545
const expectedServer =
46-
/Hello <!-- -->42<!-- -->\+<!-- -->42<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-z_.~-]+\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-z_.~-]+\.png/
46+
/Hello <!-- -->42<!-- -->\+<!-- -->42<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-z_-]+\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-z_-]+\.png/
4747
const expectedClient = new RegExp(
4848
expectedServer.source.replace(/<!-- -->/g, '')
4949
)
@@ -69,7 +69,7 @@ import { join } from 'path'
6969
expect(
7070
await browser.elementByCss('#static-image').getAttribute('src')
7171
).toMatch(
72-
/^\/_next\/image\?url=%2F_next%2Fstatic%2Fmedia%2Fvercel\.[0-9a-z_.~-]+\.png&/
72+
/^\/_next\/image\?url=%2F_next%2Fstatic%2Fmedia%2Fvercel\.[0-9a-z_-]+\.png&/
7373
)
7474
)
7575
})
@@ -84,7 +84,7 @@ import { join } from 'path'
8484
.elementByCss('#static-css')
8585
.getComputedCss('background-image')
8686
).toMatch(
87-
/^url\("http(s)?:\/\/.+\/_next\/static\/media\/vercel\.[0-9a-z_.~-]+\.png(?:\?.*)?"\)$/
87+
/^url\("http(s)?:\/\/.+\/_next\/static\/media\/vercel\.[0-9a-z_-]+\.png(?:\?.*)?"\)$/
8888
)
8989
)
9090
})

‎test/e2e/url/url.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,5 @@ describe(`Handle new URL asset references`, () => {
200200
})
201201

202202
function stripVercelPngHash(text: string) {
203-
return text.replace(/vercel\.[0-9a-z_.~-]{4,}\.png/g, 'vercel.HASH.png')
203+
return text.replace(/vercel\.[0-9a-z_-]{4,}\.png/g, 'vercel.HASH.png')
204204
}

‎test/integration/css/test/basic-global-support.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -564,17 +564,17 @@ module.exports = {
564564
expect(cssContent).toMatchInlineSnapshot(`
565565
[
566566
"/_next/static/chunks/HASH.css:
567-
.red-text{color:red;background-image:url(../media/dark.0bi3upmbca6o8.svg),url(../media/dark2.0bi3upmbca6o8.svg)}
568-
.blue-text{color:orange;background-image:url(../media/light.0-fs_bhu4mhnn.svg);font-weight:bolder}
567+
.red-text{color:red;background-image:url(../media/dark.0-9yl04ewdb5w.svg),url(../media/dark2.0-9yl04ewdb5w.svg)}
568+
.blue-text{color:orange;background-image:url(../media/light.37p36_ay21lu_.svg);font-weight:bolder}
569569
.blue-text{color:#00f}",
570570
]
571571
`)
572572
} else if (process.env.IS_TURBOPACK_TEST && !useLightningcss) {
573573
expect(cssContent).toMatchInlineSnapshot(`
574574
[
575575
"/_next/static/chunks/HASH.css:
576-
.red-text{color:red;background-image:url(../media/dark.0bi3upmbca6o8.svg),url(../media/dark2.0bi3upmbca6o8.svg)}
577-
.blue-text{color:orange;background-image:url(../media/light.0-fs_bhu4mhnn.svg);font-weight:bolder}
576+
.red-text{color:red;background-image:url(../media/dark.0-9yl04ewdb5w.svg),url(../media/dark2.0-9yl04ewdb5w.svg)}
577+
.blue-text{color:orange;background-image:url(../media/light.37p36_ay21lu_.svg);font-weight:bolder}
578578
.blue-text{color:#00f}",
579579
]
580580
`)
@@ -640,8 +640,8 @@ describe('CSS URL via `file-loader` and asset prefix (1)', () => {
640640
expect(cssContent).toMatchInlineSnapshot(`
641641
[
642642
"/_next/static/chunks/HASH.css:
643-
.red-text{color:red;background-image:url(../media/dark.0bi3upmbca6o8.svg) url(../media/dark2.0bi3upmbca6o8.svg)}
644-
.blue-text{color:orange;background-image:url(../media/light.0-fs_bhu4mhnn.svg);font-weight:bolder}
643+
.red-text{color:red;background-image:url(../media/dark.0-9yl04ewdb5w.svg) url(../media/dark2.0-9yl04ewdb5w.svg)}
644+
.blue-text{color:orange;background-image:url(../media/light.37p36_ay21lu_.svg);font-weight:bolder}
645645
.blue-text{color:#00f}",
646646
]
647647
`)
@@ -692,8 +692,8 @@ describe('CSS URL via `file-loader` and asset prefix (2)', () => {
692692
expect(cssContent).toMatchInlineSnapshot(`
693693
[
694694
"/_next/static/chunks/HASH.css:
695-
.red-text{color:red;background-image:url(../media/dark.0bi3upmbca6o8.svg) url(../media/dark2.0bi3upmbca6o8.svg)}
696-
.blue-text{color:orange;background-image:url(../media/light.0-fs_bhu4mhnn.svg);font-weight:bolder}
695+
.red-text{color:red;background-image:url(../media/dark.0-9yl04ewdb5w.svg) url(../media/dark2.0-9yl04ewdb5w.svg)}
696+
.blue-text{color:orange;background-image:url(../media/light.37p36_ay21lu_.svg);font-weight:bolder}
697697
.blue-text{color:#00f}",
698698
]
699699
`)
@@ -721,7 +721,7 @@ async function getStylesheetContents($, appPort, items) {
721721
const pathname = new URL(href, `http://localhost:${appPort}`).pathname
722722
const text = await res.text()
723723
results.push(
724-
`${pathname.replace(/\/([0-9a-z_.~-]{7,})\.(css|js)\b/g, '/HASH.$2')}:\n${text
724+
`${pathname.replace(/\/([0-9a-z_-]{7,})\.(css|js)\b/g, '/HASH.$2')}:\n${text
725725
.replace(/\/\*.*?\*\/\n?/g, '')
726726
.replace(/(\?dpl=[^)"']+)/g, '')
727727
.trim()}`

0 commit comments

Comments
 (0)