diff --git a/packages/vite/bin/vite.js b/packages/vite/bin/vite.js index 23d11390d73dff..79c49ab70f624e 100755 --- a/packages/vite/bin/vite.js +++ b/packages/vite/bin/vite.js @@ -24,7 +24,7 @@ const profileIndex = process.argv.indexOf('--profile') if (debugIndex > 0) { let value = process.argv[debugIndex + 1] - if (!value || value.startsWith('-')) { + if (!value || value[0] === '-') { value = 'vite:*' } else { // support debugging multiple flags with comma-separated list @@ -39,7 +39,7 @@ if (debugIndex > 0) { if (filterIndex > 0) { const filter = process.argv[filterIndex + 1] - if (filter && !filter.startsWith('-')) { + if (filter && filter[0] !== '-') { process.env.VITE_DEBUG_FILTER = filter } } @@ -65,7 +65,7 @@ function start() { if (profileIndex > 0) { process.argv.splice(profileIndex, 1) const next = process.argv[profileIndex] - if (next && !next.startsWith('-')) { + if (next && next[0] !== '-') { process.argv.splice(profileIndex, 1) } const inspector = await import('node:inspector').then((r) => r.default) diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index 74af98cc62a6f0..48c48c3b495d5b 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -87,7 +87,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { const templateLiteral = (ast as any).body[0].expression if (templateLiteral.expressions.length) { const pattern = buildGlobPattern(templateLiteral) - if (pattern.startsWith('*')) { + if (pattern[0] === '*') { // don't transform for patterns like this // because users won't intend to do that in most cases continue diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 774b4f56c4536b..50613331bcb162 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -626,7 +626,7 @@ export async function toAbsoluteGlob( root = globSafePath(root) let dir if (base) { - if (base.startsWith('/')) { + if (base[0] === '/') { dir = posix.join(root, base) } else { dir = posix.resolve( diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 351c3a6d068b31..d5ba51735ca07b 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -228,7 +228,7 @@ export function transformMiddleware( const result = await environment.transformRequest(url, { allowId(id) { return ( - id.startsWith('\0') || + id[0] === '\0' || !isServerAccessDeniedForTransform(server.config, id) ) },