Skip to content

Commit 42816de

Browse files
authored
refactor: replace startsWith with strict equality (#20603)
1 parent 4851cab commit 42816de

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

packages/vite/bin/vite.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const profileIndex = process.argv.indexOf('--profile')
2424

2525
if (debugIndex > 0) {
2626
let value = process.argv[debugIndex + 1]
27-
if (!value || value.startsWith('-')) {
27+
if (!value || value[0] === '-') {
2828
value = 'vite:*'
2929
} else {
3030
// support debugging multiple flags with comma-separated list
@@ -39,7 +39,7 @@ if (debugIndex > 0) {
3939

4040
if (filterIndex > 0) {
4141
const filter = process.argv[filterIndex + 1]
42-
if (filter && !filter.startsWith('-')) {
42+
if (filter && filter[0] !== '-') {
4343
process.env.VITE_DEBUG_FILTER = filter
4444
}
4545
}
@@ -65,7 +65,7 @@ function start() {
6565
if (profileIndex > 0) {
6666
process.argv.splice(profileIndex, 1)
6767
const next = process.argv[profileIndex]
68-
if (next && !next.startsWith('-')) {
68+
if (next && next[0] !== '-') {
6969
process.argv.splice(profileIndex, 1)
7070
}
7171
const inspector = await import('node:inspector').then((r) => r.default)

packages/vite/src/node/plugins/assetImportMetaUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
8787
const templateLiteral = (ast as any).body[0].expression
8888
if (templateLiteral.expressions.length) {
8989
const pattern = buildGlobPattern(templateLiteral)
90-
if (pattern.startsWith('*')) {
90+
if (pattern[0] === '*') {
9191
// don't transform for patterns like this
9292
// because users won't intend to do that in most cases
9393
continue

packages/vite/src/node/plugins/importMetaGlob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ export async function toAbsoluteGlob(
626626
root = globSafePath(root)
627627
let dir
628628
if (base) {
629-
if (base.startsWith('/')) {
629+
if (base[0] === '/') {
630630
dir = posix.join(root, base)
631631
} else {
632632
dir = posix.resolve(

packages/vite/src/node/server/middlewares/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export function transformMiddleware(
228228
const result = await environment.transformRequest(url, {
229229
allowId(id) {
230230
return (
231-
id.startsWith('\0') ||
231+
id[0] === '\0' ||
232232
!isServerAccessDeniedForTransform(server.config, id)
233233
)
234234
},

0 commit comments

Comments
 (0)