From 9800c738b53f09da6d8f996255a831303983a376 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 22 Mar 2024 20:34:01 +0800 Subject: [PATCH] chore: `utf8` replaced with `utf-8` (#16232) --- packages/vite/rollupLicensePlugin.ts | 2 +- packages/vite/src/node/config.ts | 2 +- playground/csp/vite.config.js | 2 +- playground/json/server.js | 2 +- playground/resolve-config/__tests__/resolve-config.spec.ts | 2 +- playground/resolve-config/__tests__/serve.ts | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/vite/rollupLicensePlugin.ts b/packages/vite/rollupLicensePlugin.ts index d3dce56a7dfeb6..aa08c64f2903ff 100644 --- a/packages/vite/rollupLicensePlugin.ts +++ b/packages/vite/rollupLicensePlugin.ts @@ -88,7 +88,7 @@ export default function licensePlugin( `${sortLicenses(licenses).join(', ')}\n\n` + `# Bundled dependencies:\n` + dependencyLicenseTexts - const existingLicenseText = fs.readFileSync(licenseFilePath, 'utf8') + const existingLicenseText = fs.readFileSync(licenseFilePath, 'utf-8') if (existingLicenseText !== licenseText) { fs.writeFileSync(licenseFilePath, licenseText) console.warn( diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 83a5e455609a0c..178e73b8137428 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1174,7 +1174,7 @@ async function bundleConfigFile( name: 'inject-file-scope-variables', setup(build) { build.onLoad({ filter: /\.[cm]?[jt]s$/ }, async (args) => { - const contents = await fsp.readFile(args.path, 'utf8') + const contents = await fsp.readFile(args.path, 'utf-8') const injectValues = `const ${dirnameVarName} = ${JSON.stringify( path.dirname(args.path), diff --git a/playground/csp/vite.config.js b/playground/csp/vite.config.js index 08d2b74f9dde3c..84d6d92ba0d0bb 100644 --- a/playground/csp/vite.config.js +++ b/playground/csp/vite.config.js @@ -28,7 +28,7 @@ const setNonceHeader = (res, nonce) => { const createMiddleware = (file, transform) => async (req, res) => { const nonce = createNonce() setNonceHeader(res, nonce) - const content = await fs.readFile(path.join(__dirname, file), 'utf8') + const content = await fs.readFile(path.join(__dirname, file), 'utf-8') const transformedContent = await transform(content, req.originalUrl) res.setHeader('Content-Type', 'text/html') res.end(transformedContent.replaceAll(noncePlaceholder, nonce)) diff --git a/playground/json/server.js b/playground/json/server.js index 982b7dcc09d30b..fea792d4e6ab91 100644 --- a/playground/json/server.js +++ b/playground/json/server.js @@ -69,7 +69,7 @@ export async function createServer(root = process.cwd(), hmrPort) { } const htmlLoc = resolve(`.${url}`) - let html = fs.readFileSync(htmlLoc, 'utf8') + let html = fs.readFileSync(htmlLoc, 'utf-8') html = await vite.transformIndexHtml(url, html) res.status(200).set({ 'Content-Type': 'text/html' }).end(html) diff --git a/playground/resolve-config/__tests__/resolve-config.spec.ts b/playground/resolve-config/__tests__/resolve-config.spec.ts index eeb4f2c79edcbb..12f00aa168f142 100644 --- a/playground/resolve-config/__tests__/resolve-config.spec.ts +++ b/playground/resolve-config/__tests__/resolve-config.spec.ts @@ -13,7 +13,7 @@ const build = (configName: string) => { const getDistFile = (configName: string, extension: string) => { return fs.readFileSync( fromTestDir(`${configName}/dist/index.${extension}`), - 'utf8', + 'utf-8', ) } diff --git a/playground/resolve-config/__tests__/serve.ts b/playground/resolve-config/__tests__/serve.ts index 39e84860cfadfb..76172577f690c3 100644 --- a/playground/resolve-config/__tests__/serve.ts +++ b/playground/resolve-config/__tests__/serve.ts @@ -21,7 +21,7 @@ export async function serve() { await fs.rename(fromTestDir(configName, 'vite.config.ts'), pathToConf) if (['cjs', 'cts'].includes(configName)) { - const conf = await fs.readFile(pathToConf, 'utf8') + const conf = await fs.readFile(pathToConf, 'utf-8') await fs.writeFile( pathToConf, conf.replace('export default', 'module.exports = '), @@ -30,7 +30,7 @@ export async function serve() { // Remove TS annotation for plain JavaScript file. if (configName.endsWith('js')) { - const conf = await fs.readFile(pathToConf, 'utf8') + const conf = await fs.readFile(pathToConf, 'utf-8') await fs.writeFile(pathToConf, conf.replace(': boolean', '')) }