Skip to content

Commit e32714d

Browse files
authored
refactor(angular-rspack): inline helpers from nx package (#36)
1 parent 9e8d94e commit e32714d

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

Diff for: packages/angular-rspack/eslint.next.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = [
2323
'{projectRoot}/vitest*.config.{js,ts,mjs,mts}',
2424
],
2525
ignoredDependencies: [
26-
'nx',
2726
'css-loader',
2827
'less-loader',
2928
'sass-loader',

Diff for: packages/angular-rspack/src/lib/models/normalize-options.ts

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FileReplacement } from '@nx/angular-rspack-compiler';
22
import {
3+
normalizePath,
34
readCachedProjectGraph,
45
type ProjectGraphProjectNode,
56
} from '@nx/devkit';
@@ -14,10 +15,6 @@ import {
1415
relative,
1516
resolve,
1617
} from 'node:path';
17-
import {
18-
createProjectRootMappings,
19-
findProjectForPath,
20-
} from 'nx/src/project-graph/utils/find-project-for-path';
2118
import type {
2219
AngularRspackPluginOptions,
2320
AssetElement,
@@ -523,3 +520,44 @@ function getProject(root: string): ProjectGraphProjectNode | undefined {
523520

524521
return projectGraph.nodes[projectName];
525522
}
523+
524+
function createProjectRootMappings(
525+
nodes: Record<string, ProjectGraphProjectNode>
526+
): Map<string, string> {
527+
const projectRootMappings = new Map<string, string>();
528+
for (const projectName of Object.keys(nodes)) {
529+
const root = nodes[projectName].data.root;
530+
531+
projectRootMappings.set(normalizeProjectRoot(root), projectName);
532+
}
533+
return projectRootMappings;
534+
}
535+
536+
function findProjectForPath(
537+
filePath: string,
538+
projectRootMap: Map<string, string>
539+
): string | undefined {
540+
/**
541+
* Project Mappings are in UNIX-style file paths
542+
* Windows may pass Win-style file paths
543+
* Ensure filePath is in UNIX-style
544+
*/
545+
let currentPath = normalizePath(filePath);
546+
for (
547+
;
548+
currentPath != dirname(currentPath);
549+
currentPath = dirname(currentPath)
550+
) {
551+
const p = projectRootMap.get(currentPath);
552+
if (p) {
553+
return p;
554+
}
555+
}
556+
557+
return projectRootMap.get(currentPath);
558+
}
559+
560+
function normalizeProjectRoot(root: string) {
561+
root = root === '' ? '.' : root;
562+
return root && root.endsWith('/') ? root.substring(0, root.length - 1) : root;
563+
}

0 commit comments

Comments
 (0)