chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:38:36 +08:00
commit 8e2a6eb840
10194 changed files with 1593658 additions and 0 deletions
@@ -0,0 +1,16 @@
// Mock for `@nx/devkit/internal`. Mirrors the `@nx/devkit` mock pattern: only
// the symbols the plugin code imports are provided, and behavior is the
// minimum each test path needs.
//
// `assertSupportedInstalledPackageVersion` is a no-op here because no current
// test exercises the runtime floor guard. In production, the helper would
// read the installed version via `getInstalledPackageVersion` and throw when
// below floor; making the mock a no-op lets tests transitively load the
// guard without depending on a built devkit/nx dist.
export function assertSupportedInstalledPackageVersion(
_packageName: string,
_minSupportedVersion: string
): void {
/* no-op */
}
@@ -0,0 +1,47 @@
import * as path from 'path';
import { PathLike, statSync } from 'node:fs';
export function fileExists(path: PathLike): boolean {
try {
return statSync(path).isFile();
} catch {
return false;
}
}
/**
* The root of the workspace
*/
export let workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());
// Required for integration tests in projects which depend on Nx at runtime, such as lerna and angular-eslint
export function setWorkspaceRoot(root: string): void {
workspaceRoot = root;
}
export function workspaceRootInner(
dir: string,
candidateRoot: string | null
): string {
if (process.env.NX_WORKSPACE_ROOT_PATH)
return process.env.NX_WORKSPACE_ROOT_PATH;
if (path.dirname(dir) === dir) return candidateRoot;
const matches = [
path.join(dir, 'nx.json'),
path.join(dir, 'nx'),
path.join(dir, 'nx.bat'),
];
if (matches.some((x) => fileExists(x))) {
return dir;
// This handles the case where we have a workspace which uses npm / yarn / pnpm
// workspaces, and has a project which contains Nx in its dependency tree.
// e.g. packages/my-lib/package.json contains @nx/devkit, which references Nx and is
// thus located in //packages/my-lib/node_modules/nx/package.json
} else if (fileExists(path.join(dir, 'node_modules', 'nx', 'package.json'))) {
return workspaceRootInner(path.dirname(dir), dir);
} else {
return workspaceRootInner(path.dirname(dir), candidateRoot);
}
}