Repository navigation
Expand file tree
/
Copy pathlazyRushModules.ts
More file actions
47 lines (38 loc) · 2.13 KB
/
Copy pathlazyRushModules.ts
File metadata and controls
47 lines (38 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
// The warm daemon connect path must not load the @microsoft/rush-lib bundle (hundreds of milliseconds).
// Modules that depend on it are loaded here on demand, only by fallback, rushx, startup and version selection.
import * as fs from 'node:fs';
import * as path from 'node:path';
import type * as RushLibModule from '@microsoft/rush-lib';
import type * as EnvironmentConfigurationModule from '@microsoft/rush-lib/lib/api/EnvironmentConfiguration';
import type * as MinimalRushConfigurationModule from '@microsoft/rush/lib/MinimalRushConfiguration';
import type * as VersionSelectedDaemonLauncherModule from '@rushstack/rush-daemon/lib/VersionSelectedDaemonLauncher';
export function loadRushLib(): typeof RushLibModule {
return require('@microsoft/rush-lib');
}
export function loadEnvironmentConfiguration(): typeof EnvironmentConfigurationModule {
return require('@microsoft/rush-lib/lib/api/EnvironmentConfiguration');
}
export function loadMinimalRushConfiguration(): typeof MinimalRushConfigurationModule {
return require('@microsoft/rush/lib/MinimalRushConfiguration');
}
export function loadVersionSelectedDaemonLauncher(): typeof VersionSelectedDaemonLauncherModule {
return require('@rushstack/rush-daemon/lib/VersionSelectedDaemonLauncher');
}
/** Equals `Rush.version`. */
export function getBundledRushVersion(): string {
return (require('@microsoft/rush-lib/package.json') as { version: string }).version;
}
/** Same search as `RushConfiguration.tryFindRushJsonLocation({ startingFolder })`. */
export function tryFindRushJsonLocation(startingFolder: string): string | undefined {
let currentFolder: string = startingFolder;
let parentFolder: string = path.dirname(currentFolder);
while (parentFolder && parentFolder !== currentFolder) {
const rushJsonFilename: string = path.join(currentFolder, 'rush.json');
if (fs.existsSync(rushJsonFilename)) return rushJsonFilename;
currentFolder = parentFolder;
parentFolder = path.dirname(currentFolder);
}
return undefined;
}