utils.ts — vite Source File
Architecture documentation for utils.ts, a typescript file in the vite codebase. 1 imports, 56 dependents.
Entity Profile
Dependency Diagram
graph LR abfc9e70_3c15_b3f0_a595_3cf27afb7e64["utils.ts"] ffe942a0_fdea_ef58_0f68_6f1fec25f285["constants.ts"] abfc9e70_3c15_b3f0_a595_3cf27afb7e64 --> ffe942a0_fdea_ef58_0f68_6f1fec25f285 d957f785_adef_de7a_92dc_045f724e6d34["createImportMeta.ts"] d957f785_adef_de7a_92dc_045f724e6d34 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 18923f93_cfa8_2d16_b71c_25bd600b0c6a["esmEvaluator.ts"] 18923f93_cfa8_2d16_b71c_25bd600b0c6a --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 9f67d7a4_f300_a592_a5b0_c8f97c2d3564["evaluatedModules.ts"] 9f67d7a4_f300_a592_a5b0_c8f97c2d3564 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 569b12a9_015e_564e_efd3_205cedee54dd["hmrHandler.ts"] 569b12a9_015e_564e_efd3_205cedee54dd --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 29e248d2_9983_1037_00e6_8bcd9ee87840["runner.ts"] 29e248d2_9983_1037_00e6_8bcd9ee87840 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 95cae2f2_ad8c_91c1_5a74_93d939dbc47b["interceptor.ts"] 95cae2f2_ad8c_91c1_5a74_93d939dbc47b --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 81939ddb_795d_a69b_d1ea_fb1af459ccc2["utils.ts"] 81939ddb_795d_a69b_d1ea_fb1af459ccc2 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 b126a12b_207a_1dea_fbf4_d8a321104f39["dev.spec.ts"] b126a12b_207a_1dea_fbf4_d8a321104f39 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 bd61be4f_3dcc_2549_1583_12f4a8f96cd1["parse.spec.ts"] bd61be4f_3dcc_2549_1583_12f4a8f96cd1 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 3fd9950b_bcb7_a128_9aed_592d2aca94e6["hooks.spec.ts"] 3fd9950b_bcb7_a128_9aed_592d2aca94e6 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 8e5be4f8_47ed_25d2_b54a_787696793bf1["runnerImport.spec.ts"] 8e5be4f8_47ed_25d2_b54a_787696793bf1 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 979f8150_4348_7be4_3132_a56e679f89db["utils.spec.ts"] 979f8150_4348_7be4_3132_a56e679f89db --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"] 7da774f9_eca5_d54e_6e01_6bee7d460a2b --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64 style abfc9e70_3c15_b3f0_a595_3cf27afb7e64 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX } from './constants'
export const isWindows: boolean =
typeof process !== 'undefined' && process.platform === 'win32'
/**
* Prepend `/@id/` and replace null byte so the id is URL-safe.
* This is prepended to resolved ids that are not valid browser
* import specifiers by the importAnalysis plugin.
*/
export function wrapId(id: string): string {
return id.startsWith(VALID_ID_PREFIX)
? id
: VALID_ID_PREFIX + id.replace('\0', NULL_BYTE_PLACEHOLDER)
}
/**
* Undo {@link wrapId}'s `/@id/` and null byte replacements.
*/
export function unwrapId(id: string): string {
return id.startsWith(VALID_ID_PREFIX)
? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, '\0')
: id
}
const windowsSlashRE = /\\/g
export function slash(p: string): string {
return p.replace(windowsSlashRE, '/')
}
const postfixRE = /[?#].*$/
export function cleanUrl(url: string): string {
return url.replace(postfixRE, '')
}
export function splitFileAndPostfix(path: string): {
file: string
postfix: string
} {
const file = cleanUrl(path)
return { file, postfix: path.slice(file.length) }
}
export function isPrimitive(value: unknown): boolean {
return !value || (typeof value !== 'object' && typeof value !== 'function')
}
export function withTrailingSlash(path: string): string {
if (path[path.length - 1] !== '/') {
return `${path}/`
}
return path
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const AsyncFunction = async function () {}.constructor as typeof Function
// https://github.com/nodejs/node/issues/43047#issuecomment-1564068099
let asyncFunctionDeclarationPaddingLineCount: number | undefined
export function getAsyncFunctionDeclarationPaddingLineCount(): number {
if (typeof asyncFunctionDeclarationPaddingLineCount === 'undefined') {
const body = '/*code*/'
const source = new AsyncFunction('a', 'b', body).toString()
asyncFunctionDeclarationPaddingLineCount =
source.slice(0, source.indexOf(body)).split('\n').length - 1
}
return asyncFunctionDeclarationPaddingLineCount
}
export interface PromiseWithResolvers<T> {
promise: Promise<T>
resolve: (value: T | PromiseLike<T>) => void
reject: (reason?: any) => void
}
export function promiseWithResolvers<T>(): PromiseWithResolvers<T> {
let resolve: any
let reject: any
const promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve
reject = _reject
})
return { promise, resolve, reject }
}
Domain
Subdomains
Functions
Types
Dependencies
Imported By
- packages/vite/src/node/plugins/asset.ts
- packages/vite/src/node/plugins/assetImportMetaUrl.ts
- packages/vite/src/node/server/middlewares/base.ts
- packages/vite/src/node/plugins/clientInjections.ts
- packages/vite/src/node/config.ts
- packages/vite/src/module-runner/createImportMeta.ts
- packages/vite/src/node/plugins/css.ts
- packages/vite/src/node/__tests__/dev.spec.ts
- packages/vite/src/node/server/environment.ts
- packages/vite/src/node/plugins/esbuild.ts
- packages/vite/src/node/plugins/esbuildBannerFooterCompatPlugin.ts
- packages/vite/src/module-runner/esmEvaluator.ts
- packages/vite/src/module-runner/evaluatedModules.ts
- packages/vite/src/node/ssr/fetchModule.ts
- packages/vite/src/node/server/hmr.ts
- packages/vite/src/module-runner/hmrHandler.ts
- packages/vite/src/node/__tests__/plugins/hooks.spec.ts
- packages/vite/src/node/plugins/html.ts
- packages/vite/src/node/server/middlewares/htmlFallback.ts
- packages/vite/src/node/plugins/importAnalysis.ts
- packages/vite/src/node/plugins/importMetaGlob.ts
- packages/vite/src/node/optimizer/index.ts
- packages/vite/src/node/server/middlewares/indexHtml.ts
- packages/vite/src/module-runner/sourcemap/interceptor.ts
- packages/vite/src/node/server/middlewares/memoryFiles.ts
- packages/vite/src/node/server/moduleGraph.ts
- packages/vite/src/shared/moduleRunnerTransport.ts
- packages/vite/src/node/plugins/optimizedDeps.ts
- packages/vite/src/node/optimizer/optimizer.ts
- packages/vite/src/node/plugins/oxc.ts
- packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.spec.ts
- packages/vite/src/node/server/pluginContainer.ts
- packages/vite/src/node/plugins/pluginFilter.ts
- packages/vite/src/node/plugins/preAlias.ts
- packages/vite/src/node/plugins/prepareOutDir.ts
- packages/vite/src/node/publicDir.ts
- packages/vite/src/node/plugins/reporter.ts
- packages/vite/src/node/optimizer/resolve.ts
- packages/vite/src/node/plugins/resolve.ts
- packages/vite/src/node/optimizer/rolldownDepPlugin.ts
- packages/vite/src/module-runner/runner.ts
- packages/vite/src/node/__tests__/runnerImport.spec.ts
- packages/vite/src/node/optimizer/scan.ts
- packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts
- packages/vite/src/node/server/sourcemap.ts
- packages/vite/src/node/ssr/ssrModuleLoader.ts
- packages/vite/src/node/server/middlewares/static.ts
- packages/vite/src/node/server/middlewares/transform.ts
- packages/vite/src/node/server/transformRequest.ts
- packages/vite/src/node/__tests__/utils.spec.ts
- packages/vite/src/module-runner/utils.ts
- packages/vite/src/node/utils.ts
- packages/vite/src/node/plugins/wasm.ts
- packages/vite/src/node/watch.ts
- packages/vite/src/node/plugins/worker.ts
- packages/vite/src/node/plugins/workerImportMetaUrl.ts
Source
Frequently Asked Questions
What does utils.ts do?
utils.ts is a source file in the vite codebase, written in typescript. It belongs to the HMRClient domain, HotRuntime subdomain.
What functions are defined in utils.ts?
utils.ts defines 12 function(s): AsyncFunction, cleanUrl, getAsyncFunctionDeclarationPaddingLineCount, isPrimitive, promiseWithResolvers, reason, slash, splitFileAndPostfix, unwrapId, value, and 2 more.
What does utils.ts depend on?
utils.ts imports 1 module(s): constants.ts.
What files import utils.ts?
utils.ts is imported by 56 file(s): asset.ts, assetImportMetaUrl.ts, base.ts, clientInjections.ts, config.ts, createImportMeta.ts, css.ts, dev.spec.ts, and 48 more.
Where is utils.ts in the architecture?
utils.ts is located at packages/vite/src/shared/utils.ts (domain: HMRClient, subdomain: HotRuntime, directory: packages/vite/src/shared).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free