@lage-run/config 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@lage-run/config",
3
+ "entries": [
4
+ {
5
+ "date": "Wed, 29 Mar 2023 22:41:31 GMT",
6
+ "tag": "@lage-run/config_v0.1.1",
7
+ "version": "0.1.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/config",
13
+ "commit": "ec458f83e5adb784019efaa06f902ec75f85990c",
14
+ "comment": "moving config to its own package"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@lage-run/config",
19
+ "comment": "Bump @lage-run/scheduler-types to v0.3.5",
20
+ "commit": "ec458f83e5adb784019efaa06f902ec75f85990c"
21
+ }
22
+ ]
23
+ }
24
+ }
25
+ ]
26
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log - @lage-run/config
2
+
3
+ This log was last generated on Wed, 29 Mar 2023 22:41:31 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.1.1
8
+
9
+ Wed, 29 Mar 2023 22:41:31 GMT
10
+
11
+ ### Patches
12
+
13
+ - moving config to its own package (kchau@microsoft.com)
14
+ - Bump @lage-run/scheduler-types to v0.3.5
package/jest.config.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("monorepo-scripts/config/jest.config.js");
@@ -0,0 +1 @@
1
+ export declare function getConcurrency(optionsConcurrency: number | undefined, configConcurrency: number | undefined): number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getConcurrency", {
6
+ enumerable: true,
7
+ get: ()=>getConcurrency
8
+ });
9
+ const _os = /*#__PURE__*/ _interopRequireDefault(require("os"));
10
+ function _interopRequireDefault(obj) {
11
+ return obj && obj.__esModule ? obj : {
12
+ default: obj
13
+ };
14
+ }
15
+ function getConcurrency(optionsConcurrency, configConcurrency) {
16
+ return optionsConcurrency || configConcurrency || _os.default.cpus().length - 1;
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { ConfigOptions } from "./types/ConfigOptions.js";
2
+ export declare function getConfig(cwd: string): Promise<ConfigOptions>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getConfig", {
6
+ enumerable: true,
7
+ get: ()=>getConfig
8
+ });
9
+ const _os = /*#__PURE__*/ _interopRequireDefault(require("os"));
10
+ const _cosmiconfig = require("cosmiconfig");
11
+ const _workspaceTools = require("workspace-tools");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ async function getConfig(cwd) {
18
+ // Verify presence of git
19
+ const root = (0, _workspaceTools.getWorkspaceRoot)(cwd);
20
+ if (!root) {
21
+ throw new Error("This must be called inside a codebase that is part of a JavaScript workspace.");
22
+ }
23
+ // Search for lage.config.js file
24
+ const ConfigModuleName = "lage";
25
+ const configExplorer = await (0, _cosmiconfig.cosmiconfig)(ConfigModuleName);
26
+ const results = await configExplorer.search(root ?? cwd);
27
+ const config = results?.config;
28
+ return {
29
+ cacheOptions: config?.cacheOptions ?? {},
30
+ ignore: config?.ignore ?? [],
31
+ npmClient: config?.npmClient ?? "npm",
32
+ pipeline: config?.pipeline ?? {},
33
+ priorities: config?.priorities ?? [],
34
+ repoWideChanges: config?.repoWideChanges ?? [
35
+ "lage.config.js",
36
+ "package-lock.json",
37
+ "yarn.lock",
38
+ "pnpm-lock.yaml",
39
+ "lerna.json",
40
+ "rush.json"
41
+ ],
42
+ loggerOptions: config?.loggerOptions ?? {},
43
+ runners: config?.runners ?? {},
44
+ workerIdleMemoryLimit: config?.workerIdleMemoryLimit ?? _os.default.totalmem(),
45
+ concurrency: config?.concurrency ?? _os.default.cpus().length - 1,
46
+ allowNoTargetRuns: config?.allowNoTargetRuns ?? false
47
+ };
48
+ }
@@ -0,0 +1,3 @@
1
+ import type { ConfigOptions } from "./types/ConfigOptions.js";
2
+ export declare function getMaxWorkersPerTask(pipelineConfig: ConfigOptions["pipeline"], concurrency: number): Map<string, number>;
3
+ export declare function getMaxWorkersPerTaskFromOptions(maxWorkersPerTask: string[]): Map<string, number>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getMaxWorkersPerTask: ()=>getMaxWorkersPerTask,
13
+ getMaxWorkersPerTaskFromOptions: ()=>getMaxWorkersPerTaskFromOptions
14
+ });
15
+ function getMaxWorkersPerTask(pipelineConfig, concurrency) {
16
+ const maxWorkersPerTask = new Map();
17
+ let generalPoolCount = 0;
18
+ let generatelPoolMaxWorkers = 0;
19
+ let dedicatedPoolCount = 0;
20
+ let dedicatedPoolMaxWorkers = 0;
21
+ for (const [task, taskConfig] of Object.entries(pipelineConfig)){
22
+ if (!Array.isArray(taskConfig) && !task.includes("#")) {
23
+ const maxWorkerOption = taskConfig.maxWorkers ?? taskConfig.options?.maxWorkers;
24
+ if (typeof maxWorkerOption === "undefined") {
25
+ generalPoolCount++;
26
+ continue;
27
+ }
28
+ let maxWorkers = 0;
29
+ if (typeof maxWorkerOption !== "number") {
30
+ throw new Error(`Invalid maxWorkers value: ${maxWorkerOption}`);
31
+ } else {
32
+ maxWorkers = maxWorkerOption;
33
+ }
34
+ maxWorkersPerTask.set(task, maxWorkers);
35
+ dedicatedPoolCount++;
36
+ dedicatedPoolMaxWorkers += maxWorkers;
37
+ }
38
+ }
39
+ if (dedicatedPoolCount > 0 && generalPoolCount > 0) {
40
+ const avgMaxWorkers = dedicatedPoolMaxWorkers / dedicatedPoolCount;
41
+ generatelPoolMaxWorkers = Math.max(1, Math.floor(avgMaxWorkers * generalPoolCount));
42
+ }
43
+ const grandTotal = dedicatedPoolMaxWorkers + generatelPoolMaxWorkers;
44
+ // try to adjust the maxWorkersPerTask to fit the concurrency
45
+ if (grandTotal > concurrency) {
46
+ let newTotal = 0;
47
+ for (const [task, maxWorkers] of maxWorkersPerTask.entries()){
48
+ const newMaxWorkers = Math.max(1, Math.floor(maxWorkers / grandTotal * concurrency));
49
+ newTotal += newMaxWorkers;
50
+ maxWorkersPerTask.set(task, newMaxWorkers);
51
+ }
52
+ if (newTotal > concurrency) {
53
+ throw new Error("Could not adjust maxWorkers per task to fit the concurrency, try reducing the maxWorkers, or increasing the --concurrency CLI argument, or separate the tasks to be run");
54
+ }
55
+ }
56
+ return maxWorkersPerTask;
57
+ }
58
+ function getMaxWorkersPerTaskFromOptions(maxWorkersPerTask) {
59
+ return new Map([
60
+ ...maxWorkersPerTask.map((setting)=>{
61
+ const [task, maxWorkers] = setting.split(/[=:]/);
62
+ return [
63
+ task,
64
+ parseInt(maxWorkers, 10)
65
+ ];
66
+ })
67
+ ]);
68
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { getConfig } from "./getConfig.js";
2
+ export { getConcurrency } from "./getConcurrency.js";
3
+ export { getMaxWorkersPerTask, getMaxWorkersPerTaskFromOptions } from "./getMaxWorkersPerTask.js";
4
+ export type { PipelineDefinition } from "./types/PipelineDefinition.js";
5
+ export type { ConfigOptions } from "./types/ConfigOptions.js";
6
+ export type { CacheOptions } from "./types/CacheOptions.js";
7
+ export type { LoggerOptions } from "./types/LoggerOptions.js";
8
+ export type { Priority } from "./types/Priority.js";
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getConfig: ()=>_getConfigJs.getConfig,
13
+ getConcurrency: ()=>_getConcurrencyJs.getConcurrency,
14
+ getMaxWorkersPerTask: ()=>_getMaxWorkersPerTaskJs.getMaxWorkersPerTask,
15
+ getMaxWorkersPerTaskFromOptions: ()=>_getMaxWorkersPerTaskJs.getMaxWorkersPerTaskFromOptions
16
+ });
17
+ const _getConfigJs = require("./getConfig.js");
18
+ const _getConcurrencyJs = require("./getConcurrency.js");
19
+ const _getMaxWorkersPerTaskJs = require("./getMaxWorkersPerTask.js");
@@ -0,0 +1,7 @@
1
+ import type { Config as BackfillCacheOptions } from "backfill-config";
2
+ export type CacheOptions = BackfillCacheOptions & {
3
+ environmentGlob: string[];
4
+ cacheKey: string;
5
+ writeRemoteCache: boolean;
6
+ skipLocalCache: boolean;
7
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,56 @@
1
+ import type { CacheOptions } from "./CacheOptions.js";
2
+ import type { Priority } from "./Priority.js";
3
+ import type { PipelineDefinition } from "./PipelineDefinition.js";
4
+ import type { LoggerOptions } from "./LoggerOptions.js";
5
+ import type { TargetRunnerPickerOptions } from "@lage-run/scheduler-types";
6
+ export type NpmClient = "npm" | "yarn" | "pnpm";
7
+ export interface ConfigOptions {
8
+ /**
9
+ * Defines the task pipeline, prefix with "^" character to denote a direct topological dependency,
10
+ * prefix with ^^ to denote a transitive topological dependency.
11
+ *
12
+ * Example:
13
+ *
14
+ * ```
15
+ * {
16
+ * build: ["^build"],
17
+ * test: ["build"],
18
+ * lint: []
19
+ * bundle: ["^^transpile"],
20
+ * transpile: [],
21
+ * }
22
+ * ```
23
+ */
24
+ pipeline: PipelineDefinition;
25
+ /** Backfill cache options */
26
+ cacheOptions: CacheOptions;
27
+ /** Which files to ignore when calculating scopes with --since */
28
+ ignore: string[];
29
+ /** disables --since flag when any of this list of files changed */
30
+ repoWideChanges: string[];
31
+ /** Which NPM Client to use when running npm lifecycle scripts */
32
+ npmClient: NpmClient;
33
+ /** Optional priority to set on tasks in a package to make the scheduler give priority to tasks on the critical path for high priority tasks */
34
+ priorities: Priority[];
35
+ /**
36
+ * Options that will be sent to all log reporters.
37
+ */
38
+ loggerOptions: LoggerOptions;
39
+ /**
40
+ * Custom runners for tasks in the pipeline. The key is the task name, and the value is a configuration describing what would be
41
+ * passed to the runner constructor.
42
+ */
43
+ runners: TargetRunnerPickerOptions;
44
+ /**
45
+ * Maximum worker idle memory, this would cause workers to restart if they exceed this limit. This is useful to prevent memory leaks.
46
+ */
47
+ workerIdleMemoryLimit: number;
48
+ /**
49
+ * Maximum number of concurrent tasks to run
50
+ */
51
+ concurrency: number;
52
+ /**
53
+ * Allows for no targets run
54
+ */
55
+ allowNoTargetRuns: boolean;
56
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,15 @@
1
+ import type { LogLevel } from "@lage-run/logger";
2
+ export interface LoggerOptions {
3
+ disp?: {
4
+ [level: string]: string;
5
+ };
6
+ style?: {
7
+ [level: string]: {
8
+ fg?: string;
9
+ bg?: string;
10
+ };
11
+ };
12
+ levels?: {
13
+ [level: string]: LogLevel;
14
+ };
15
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,12 @@
1
+ import type { TargetConfig } from "@lage-run/target-graph";
2
+ import type { ConfigOptions } from "./ConfigOptions.js";
3
+ export interface FactoryArgs {
4
+ cwd: string;
5
+ config: ConfigOptions;
6
+ }
7
+ export interface TargetConfigFactory {
8
+ (args: FactoryArgs): TargetConfig | TargetConfig[];
9
+ }
10
+ export interface PipelineDefinition {
11
+ [task: string]: string[] | TargetConfig;
12
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,8 @@
1
+ export interface Priority {
2
+ /** package name, as in package.json */
3
+ package?: string;
4
+ /** task name, as listed in the `scripts` section of package.json */
5
+ task: string;
6
+ /** priority, the higher the more priority; undefined priority means lowest priority*/
7
+ priority: number;
8
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@lage-run/config",
3
+ "version": "0.1.1",
4
+ "description": "Config management for Lage",
5
+ "repository": {
6
+ "url": "https://github.com/microsoft/lage"
7
+ },
8
+ "bin": {
9
+ "lage": "./bin/lage"
10
+ },
11
+ "license": "MIT",
12
+ "main": "lib/index.js",
13
+ "types": "lib/index.d.ts",
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "start": "tsc -w --preserveWatchOutput",
17
+ "test": "jest",
18
+ "lint": "monorepo-scripts lint"
19
+ },
20
+ "dependencies": {
21
+ "@lage-run/logger": "^1.2.2",
22
+ "@lage-run/scheduler-types": "^0.3.5",
23
+ "@lage-run/target-graph": "^0.8.1",
24
+ "workspace-tools": "^0.30.0",
25
+ "cosmiconfig": "^7.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "monorepo-scripts": "*",
29
+ "backfill-config": "6.3.1"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig.lage2.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib"
5
+ },
6
+ "include": ["src"]
7
+ }