Skip to content

Commit

Permalink
fix: update javascript mime type to text/javascript (#15427)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jan 8, 2024
1 parent 17ab48a commit a621de8
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 69 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"@types/micromatch": "^4.0.6",
"@types/node": "^20.10.4",
"@types/picomatch": "^2.3.3",
"@types/semver": "^7.5.6",
"@types/sass": "~1.43.1",
"@types/semver": "^7.5.6",
"@types/stylus": "^0.48.42",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.14.0",
Expand Down Expand Up @@ -118,13 +118,18 @@
"acorn-walk": {
"peerDependencies": {
"acorn": "*"
},
"peerDependenciesMeta": {
"acorn": {
"optional": true
}
}
}
},
"patchedDependencies": {
"chokidar@3.5.3": "patches/chokidar@3.5.3.patch",
"sirv@2.0.3": "patches/sirv@2.0.3.patch",
"dotenv-expand@10.0.0": "patches/dotenv-expand@10.0.0.patch"
"dotenv-expand@10.0.0": "patches/dotenv-expand@10.0.0.patch",
"sirv@2.0.4": "patches/sirv@2.0.4.patch"
},
"peerDependencyRules": {
"allowedVersions": {
Expand Down
22 changes: 0 additions & 22 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,28 +463,6 @@ License: MIT
By: Luke Edwards
Repository: lukeed/polka

> The MIT License (MIT)
>
> Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (https://lukeed.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.
---------------------------------------

## @rollup/plugin-alias
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"magic-string": "^0.30.5",
"micromatch": "^4.0.5",
"mlly": "^1.4.2",
"mrmime": "^1.0.1",
"mrmime": "^2.0.0",
"okie": "^1.0.1",
"open": "^8.4.2",
"parse5": "^7.1.2",
Expand All @@ -131,7 +131,7 @@
"resolve.exports": "^2.0.2",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-license": "^3.2.0",
"sirv": "^2.0.3",
"sirv": "^2.0.4",
"source-map-support": "^0.5.21",
"strip-ansi": "^7.1.0",
"strip-literal": "^2.0.0",
Expand Down
4 changes: 0 additions & 4 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export function registerCustomMime(): void {
mrmime.mimes['ico'] = 'image/x-icon'
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers#flac
mrmime.mimes['flac'] = 'audio/flac'
// mrmime and mime-db is not released yet: https://github.com/jshttp/mime-db/commit/c9242a9b7d4bb25d7a0c9244adec74aeef08d8a1
mrmime.mimes['aac'] = 'audio/aac'
// https://wiki.xiph.org/MIME_Types_and_File_Extensions#.opus_-_audio/ogg
mrmime.mimes['opus'] = 'audio/ogg'
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
mrmime.mimes['eot'] = 'application/vnd.ms-fontobject'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
return worker;
} catch(e) {
return new ${workerConstructor}(
"data:application/javascript;base64," + encodedJs,
"data:text/javascript;base64," + encodedJs,
${workerTypeOption}
);
}${
Expand All @@ -340,7 +340,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
: `${encodedJs}
export default function WorkerWrapper(options) {
return new ${workerConstructor}(
"data:application/javascript;base64," + encodedJs,
"data:text/javascript;base64," + encodedJs,
${workerTypeOption}
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const sirvOptions = ({
// these files to be TypeScript files, and for Vite to serve them with
// this Content-Type.
if (knownJavascriptExtensionRE.test(pathname)) {
res.setHeader('Content-Type', 'application/javascript')
res.setHeader('Content-Type', 'text/javascript')
}
const headers = getHeaders()
if (headers) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const debug = createDebugger('vite:send', {
})

const alias: Record<string, string | undefined> = {
js: 'application/javascript',
js: 'text/javascript',
css: 'text/css',
html: 'text/html',
json: 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion patches/sirv@2.0.3.patch → patches/sirv@2.0.4.patch
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ index c05040fc6ec504a1828a7badd39f669981acd0ee..e9597e8b5bf24613a09565f0e13024ae
+ shouldServe?: (absoluteFilePath: string) => void;
}

export default function(dir?: string, opts?: Options): RequestHandler;
export default function(dir?: string, opts?: Options): RequestHandler;
12 changes: 4 additions & 8 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ test('?url import', async () => {
const src = readFile('foo.js')
expect(await page.textContent('.url')).toMatch(
isBuild
? `data:application/javascript;base64,${Buffer.from(src).toString(
'base64',
)}`
? `data:text/javascript;base64,${Buffer.from(src).toString('base64')}`
: `/foo/bar/foo.js`,
)
})
Expand All @@ -375,9 +373,7 @@ describe('unicode url', () => {
const src = readFile('テスト-測試-white space.js')
expect(await page.textContent('.unicode-url')).toMatch(
isBuild
? `data:application/javascript;base64,${Buffer.from(src).toString(
'base64',
)}`
? `data:text/javascript;base64,${Buffer.from(src).toString('base64')}`
: `/foo/bar/テスト-測試-white space.js`,
)
})
Expand Down Expand Up @@ -408,7 +404,7 @@ test('new URL("/...", import.meta.url)', async () => {

test('new URL(..., import.meta.url) without extension', async () => {
expect(await page.textContent('.import-meta-url-without-extension')).toMatch(
isBuild ? 'data:application/javascript' : 'nested/test.js',
isBuild ? 'data:text/javascript' : 'nested/test.js',
)
expect(
await page.textContent('.import-meta-url-content-without-extension'),
Expand All @@ -423,7 +419,7 @@ test('new URL(`${dynamic}`, import.meta.url)', async () => {
assetMatch,
)
expect(await page.textContent('.dynamic-import-meta-url-js')).toMatch(
isBuild ? 'data:application/javascript;base64' : '/foo/bar/nested/test.js',
isBuild ? 'data:text/javascript;base64' : '/foo/bar/nested/test.js',
)
})

Expand Down
2 changes: 1 addition & 1 deletion playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test('should load dynamic import with vars raw', async () => {
test('should load dynamic import with vars url', async () => {
await untilUpdated(
() => page.textContent('.dynamic-import-with-vars-url'),
isBuild ? 'data:application/javascript' : '/alias/url.js',
isBuild ? 'data:text/javascript' : '/alias/url.js',
true,
)
})
Expand Down
2 changes: 1 addition & 1 deletion playground/external/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const serveNpmCodeDirectlyMiddleware = async (req, res, next) => {
const code = await fs.readFile(
new URL(`./node_modules/${file}`, import.meta.url),
)
res.setHeader('Content-Type', 'application/javascript')
res.setHeader('Content-Type', 'text/javascript')
res.end(code)
return
}
Expand Down
4 changes: 2 additions & 2 deletions playground/legacy/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test('generates assets', async () => {
'index-legacy: text/html',
'chunk-async: text/html',
'chunk-async-legacy: text/html',
'immutable-chunk: application/javascript',
'immutable-chunk-legacy: application/javascript',
'immutable-chunk: text/javascript',
'immutable-chunk-legacy: text/javascript',
'polyfills-legacy: text/html',
].join('\n')
: [
Expand Down
2 changes: 1 addition & 1 deletion playground/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"preview": "vite preview"
},
"devDependencies": {
"sirv": "^2.0.3"
"sirv": "^2.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/worker/__tests__/es/es-worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe.runIf(isBuild)('build', () => {
)
// inlined shared worker
expect(content).toMatch(
`return new SharedWorker("data:application/javascript;base64,"+`,
`return new SharedWorker("data:text/javascript;base64,"+`,
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe.runIf(isBuild)('build', () => {
expect(content).toMatch(
`new Worker("/iife-sourcemap-hidden/assets/my-worker`,
)
expect(content).toMatch(`new Worker("data:application/javascript;base64`)
expect(content).toMatch(`new Worker("data:text/javascript;base64`)
expect(content).toMatch(
`new Worker("/iife-sourcemap-hidden/assets/possible-ts-output-worker`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe.runIf(isBuild)('build', () => {
expect(content).toMatch(
`new Worker("/iife-sourcemap-inline/assets/my-worker`,
)
expect(content).toMatch(`new Worker("data:application/javascript;base64`)
expect(content).toMatch(`new Worker("data:text/javascript;base64`)
expect(content).toMatch(
`new Worker("/iife-sourcemap-inline/assets/possible-ts-output-worker`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe.runIf(isBuild)('build', () => {

// chunk
expect(content).toMatch(`new Worker("/iife-sourcemap/assets/my-worker`)
expect(content).toMatch(`new Worker("data:application/javascript;base64`)
expect(content).toMatch(`new Worker("data:text/javascript;base64`)
expect(content).toMatch(
`new Worker("/iife-sourcemap/assets/possible-ts-output-worker`,
)
Expand Down
40 changes: 24 additions & 16 deletions pnpm-lock.yaml

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

0 comments on commit a621de8

Please sign in to comment.