Repository: vitejs/vite
File: packages/vite/src/node/plugins/importMetaGlob.ts (TypeScript)

Code before:
          const staticImports: string[] = []

          const resolvePaths = (file: string) => {
            if (!dir) {
              if (!options.base && isRelative)
                throw new Error(
                  "In virtual modules, all globs must start with '/'",
                )
              const importPath = `/${relative(root, file)}`
              let filePath = options.base
                ? `${relative(posix.join(root, options.base), file)}`
                : importPath
              if (options.base && filePath[0] !== '.') {
                filePath = `./${filePath}`
              }
              return { filePath, importPath }
            }

            let importPath = relative(dir, file)
            if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
              importPath = `./${importPath}`
            }

            let filePath: string
            if (options.base) {
              const resolvedBasePath = options.base[0] === '/' ? root : dir
              filePath = relative(
                posix.join(resolvedBasePath, options.base),
                file,
              )
              if (filePath[0] !== '.') filePath = `./${filePath}`
              if (options.base[0] === '/') {
                importPath = `/${relative(root, file)}`
              }
            } else if (isRelative) {
              filePath = importPath
            } else {
              filePath = relative(root, file)
              if (filePath[0] !== '.') filePath = `/${filePath}`
            }

            return { filePath, importPath }
          }

          files.forEach((file, i) => {
            const paths = resolvePaths(file)
            const filePath = paths.filePath
            let importPath = paths.importPath
            let importQuery = options.query ?? ''

            if (onlyKeys) {

Review comment (suggestion):
@copilot there's other places that `filePath[0] !== '.'` is used. fix them and add a test case for each one.

Code after:
          const staticImports: string[] = []

          const resolvePaths = (file: string) => {
            if (!dir) {
              if (!options.base && isRelative)
                throw new Error(
                  "In virtual modules, all globs must start with '/'",
                )
              const importPath = `/${relative(root, file)}`
              let filePath = options.base
                ? `${relative(posix.join(root, options.base), file)}`
                : importPath
              if (
                options.base &&
                !filePath.startsWith('./') &&
                !filePath.startsWith('../')
              ) {
                filePath = `./${filePath}`
              }
              return { filePath, importPath }
            }

            let importPath = relative(dir, file)
            if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
              importPath = `./${importPath}`
            }

            let filePath: string
            if (options.base) {
              const resolvedBasePath = options.base[0] === '/' ? root : dir
              filePath = relative(
                posix.join(resolvedBasePath, options.base),
                file,
              )
              if (!filePath.startsWith('./') && !filePath.startsWith('../')) {
                filePath = `./${filePath}`
              }
              if (options.base[0] === '/') {
                importPath = `/${relative(root, file)}`
              }
            } else if (isRelative) {
              filePath = importPath
            } else {
              filePath = relative(root, file)
              if (!filePath.startsWith('./') && !filePath.startsWith('../')) {
                filePath = `/${filePath}`
              }
            }

            return { filePath, importPath }
          }