Skip to content

Commit 5547095

Browse files
committed
refactor: import path methods individually
Minor style change
1 parent 98a61ff commit 5547095

File tree

1 file changed

+12
-12
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+12
-12
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import assert from 'node:assert';
1515
import { randomUUID } from 'node:crypto';
1616
import { readFile } from 'node:fs/promises';
1717
import { ServerResponse } from 'node:http';
18-
import path from 'node:path';
18+
import { dirname, extname, join, relative } from 'node:path';
1919
import type { Connect, DepOptimizationConfig, InlineConfig, ViteDevServer } from 'vite';
2020
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-context';
2121
import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer';
@@ -200,7 +200,7 @@ export async function* serveWithVite(
200200
}
201201

202202
const { root = '' } = await context.getProjectMetadata(projectName);
203-
const projectRoot = path.join(context.workspaceRoot, root as string);
203+
const projectRoot = join(context.workspaceRoot, root as string);
204204
const browsers = getSupportedBrowsers(projectRoot, context.logger);
205205
const target = transformSupportedBrowsersToTargets(browsers);
206206

@@ -262,7 +262,7 @@ function handleUpdate(
262262
if (record.updated) {
263263
updatedFiles.push(file);
264264
const updatedModules = server.moduleGraph.getModulesByFile(
265-
normalizePath(path.join(server.config.root, file)),
265+
normalizePath(join(server.config.root, file)),
266266
);
267267
updatedModules?.forEach((m) => server?.moduleGraph.invalidateModule(m));
268268
}
@@ -389,15 +389,15 @@ export async function setupServer(
389389

390390
// Path will not exist on disk and only used to provide separate path for Vite requests
391391
const virtualProjectRoot = normalizePath(
392-
path.join(serverOptions.workspaceRoot, `.angular/vite-root/${randomUUID()}/`),
392+
join(serverOptions.workspaceRoot, `.angular/vite-root/${randomUUID()}/`),
393393
);
394394

395395
const { builtinModules } = await import('node:module');
396396

397397
const configuration: InlineConfig = {
398398
configFile: false,
399399
envFile: false,
400-
cacheDir: path.join(serverOptions.cacheOptions.path, 'vite'),
400+
cacheDir: join(serverOptions.cacheOptions.path, 'vite'),
401401
root: virtualProjectRoot,
402402
publicDir: false,
403403
esbuild: false,
@@ -462,20 +462,20 @@ export async function setupServer(
462462
const [importerFile] = importer.split('?', 1);
463463

464464
source = normalizePath(
465-
path.join(path.dirname(path.relative(virtualProjectRoot, importerFile)), source),
465+
join(dirname(relative(virtualProjectRoot, importerFile)), source),
466466
);
467467
}
468468
if (source[0] === '/') {
469469
source = source.slice(1);
470470
}
471471
const [file] = source.split('?', 1);
472472
if (outputFiles.has(file)) {
473-
return path.join(virtualProjectRoot, source);
473+
return join(virtualProjectRoot, source);
474474
}
475475
},
476476
load(id) {
477477
const [file] = id.split('?', 1);
478-
const relativeFile = normalizePath(path.relative(virtualProjectRoot, file));
478+
const relativeFile = normalizePath(relative(virtualProjectRoot, file));
479479
const codeContents = outputFiles.get(relativeFile)?.contents;
480480
if (codeContents === undefined) {
481481
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
@@ -530,7 +530,7 @@ export async function setupServer(
530530
// Parse the incoming request.
531531
// The base of the URL is unused but required to parse the URL.
532532
const pathname = pathnameWithoutServePath(req.url, serverOptions);
533-
const extension = path.extname(pathname);
533+
const extension = extname(pathname);
534534

535535
// Rewrite all build assets to a vite raw fs URL
536536
const assetSourcePath = assets.get(pathname);
@@ -586,7 +586,7 @@ export async function setupServer(
586586
!url ||
587587
// Skip if path is like a file.
588588
// NOTE: We use a regexp to mitigate against matching requests like: /browse/pl.0ef59752c0cd457dbf1391f08cbd936f
589-
/^\.[a-z]{2,4}$/i.test(path.extname(url.split('?')[0]))
589+
/^\.[a-z]{2,4}$/i.test(extname(url.split('?')[0]))
590590
) {
591591
next();
592592

@@ -607,9 +607,9 @@ export async function setupServer(
607607
document: html,
608608
route,
609609
serverContext: 'ssr',
610-
loadBundle: (path: string) =>
610+
loadBundle: (uri: string) =>
611611
// eslint-disable-next-line @typescript-eslint/no-explicit-any
612-
server.ssrLoadModule(path.slice(1)) as any,
612+
server.ssrLoadModule(uri.slice(1)) as any,
613613
// Files here are only needed for critical CSS inlining.
614614
outputFiles: {},
615615
// TODO: add support for critical css inlining.

0 commit comments

Comments
 (0)