ts-repo-utils 10.1.8 → 10.2.0
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/README.md +2 -2
- package/dist/cmd/assert-repo-is-clean.mjs +0 -0
- package/dist/cmd/check-should-run-type-checks.mjs +0 -0
- package/dist/cmd/format-diff-from.mjs +0 -0
- package/dist/cmd/format-uncommitted.mjs +0 -0
- package/dist/cmd/gen-index-ts.mjs +0 -0
- package/dist/entry-point.mjs +1 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functions/index.mjs +1 -0
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/workspace-utils/get-workspace-packages.d.mts +5 -2
- package/dist/functions/workspace-utils/get-workspace-packages.d.mts.map +1 -1
- package/dist/functions/workspace-utils/get-workspace-packages.mjs +7 -6
- package/dist/functions/workspace-utils/get-workspace-packages.mjs.map +1 -1
- package/dist/functions/workspace-utils/index.mjs +1 -0
- package/dist/functions/workspace-utils/index.mjs.map +1 -1
- package/dist/functions/workspace-utils/run-cmd-in-stages.d.mts +7 -1
- package/dist/functions/workspace-utils/run-cmd-in-stages.d.mts.map +1 -1
- package/dist/functions/workspace-utils/run-cmd-in-stages.mjs +7 -2
- package/dist/functions/workspace-utils/run-cmd-in-stages.mjs.map +1 -1
- package/dist/functions/workspace-utils/types.d.mts +13 -0
- package/dist/functions/workspace-utils/types.d.mts.map +1 -1
- package/dist/functions/workspace-utils/types.mjs +6 -0
- package/dist/functions/workspace-utils/types.mjs.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +56 -75
- package/src/cmd/assert-repo-is-clean.mts +0 -0
- package/src/cmd/check-should-run-type-checks.mts +0 -0
- package/src/cmd/format-diff-from.mts +0 -0
- package/src/cmd/format-uncommitted.mts +0 -0
- package/src/cmd/gen-index-ts.mts +0 -0
- package/src/functions/workspace-utils/get-workspace-packages.mts +14 -6
- package/src/functions/workspace-utils/run-cmd-in-stages.mts +11 -1
- package/src/functions/workspace-utils/types.mts +20 -0
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
- API reference: <https://noshiro-pf.github.io/ts-repo-utils/>
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/ts-repo-utils)
|
|
10
|
-
[](
|
|
11
|
-
[](https://github.com/noshiro-pf/mono/blob/main/libs/ts-repo-utils/LICENSE)
|
|
11
|
+
[](https://codecov.io/gh/noshiro-pf/mono)
|
|
12
12
|
|
|
13
13
|
Utilities for TypeScript Repositories.
|
|
14
14
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/entry-point.mjs
CHANGED
|
@@ -15,4 +15,5 @@ export { executeParallel, executeStages } from './functions/workspace-utils/exec
|
|
|
15
15
|
export { getWorkspacePackages } from './functions/workspace-utils/get-workspace-packages.mjs';
|
|
16
16
|
export { runCmdInParallelAcrossWorkspaces } from './functions/workspace-utils/run-cmd-in-parallel.mjs';
|
|
17
17
|
export { runCmdInStagesAcrossWorkspaces } from './functions/workspace-utils/run-cmd-in-stages.mjs';
|
|
18
|
+
export { defaultDependencyFields } from './functions/workspace-utils/types.mjs';
|
|
18
19
|
//# sourceMappingURL=entry-point.mjs.map
|
package/dist/entry-point.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
|
package/dist/functions/index.mjs
CHANGED
|
@@ -14,4 +14,5 @@ export { executeParallel, executeStages } from './workspace-utils/execute-parall
|
|
|
14
14
|
export { getWorkspacePackages } from './workspace-utils/get-workspace-packages.mjs';
|
|
15
15
|
export { runCmdInParallelAcrossWorkspaces } from './workspace-utils/run-cmd-in-parallel.mjs';
|
|
16
16
|
export { runCmdInStagesAcrossWorkspaces } from './workspace-utils/run-cmd-in-stages.mjs';
|
|
17
|
+
export { defaultDependencyFields } from './workspace-utils/types.mjs';
|
|
17
18
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { type Package } from './types.mjs';
|
|
1
|
+
import { type DependencyField, type Package } from './types.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves all workspace packages from a monorepo based on the workspace
|
|
4
4
|
* patterns defined in the root package.json file.
|
|
5
5
|
*
|
|
6
6
|
* @param rootPackageJsonDir - The directory containing the root package.json
|
|
7
7
|
* file
|
|
8
|
+
* @param dependencyFields - Which `package.json` fields contribute to each
|
|
9
|
+
* package's `dependencies` map. Defaults to
|
|
10
|
+
* {@link defaultDependencyFields}.
|
|
8
11
|
* @returns A promise that resolves to an array of Package objects containing
|
|
9
12
|
* package metadata
|
|
10
13
|
*/
|
|
11
|
-
export declare const getWorkspacePackages: (rootPackageJsonDir: string) => Promise<readonly Package[]>;
|
|
14
|
+
export declare const getWorkspacePackages: (rootPackageJsonDir: string, dependencyFields?: readonly DependencyField[]) => Promise<readonly Package[]>;
|
|
12
15
|
//# sourceMappingURL=get-workspace-packages.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-workspace-packages.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/get-workspace-packages.mts"],"names":[],"mappings":"AAiBA,OAAO,
|
|
1
|
+
{"version":3,"file":"get-workspace-packages.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/get-workspace-packages.mts"],"names":[],"mappings":"AAiBA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,OAAO,EACb,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,uBACX,MAAM,qBACR,SAAS,eAAe,EAAE,KAC3C,OAAO,CAAC,SAAS,OAAO,EAAE,CAqE5B,CAAC"}
|
|
@@ -2,8 +2,9 @@ import * as fs from 'node:fs/promises';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { Result, Json, isNotUndefined, isRecord, hasKey, Arr, isString } from 'ts-data-forge';
|
|
4
4
|
import { glob } from '../glob.mjs';
|
|
5
|
+
import { defaultDependencyFields } from './types.mjs';
|
|
5
6
|
|
|
6
|
-
const getWorkspacePackages = async (rootPackageJsonDir) => {
|
|
7
|
+
const getWorkspacePackages = async (rootPackageJsonDir, dependencyFields = defaultDependencyFields) => {
|
|
7
8
|
const rootPackageJson = JSON.parse(
|
|
8
9
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
9
10
|
await fs.readFile(path.join(rootPackageJsonDir, "package.json"), "utf8")
|
|
@@ -40,11 +41,11 @@ const getWorkspacePackages = async (rootPackageJsonDir) => {
|
|
|
40
41
|
name: getStrFromJsonValue(packageJson, "name"),
|
|
41
42
|
path: path.dirname(packagePath),
|
|
42
43
|
packageJson,
|
|
43
|
-
dependencies:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
dependencies: Object.fromEntries(
|
|
45
|
+
dependencyFields.flatMap(
|
|
46
|
+
(field) => Object.entries(getKeyValueRecordFromJsonValue(packageJson, field))
|
|
47
|
+
)
|
|
48
|
+
)
|
|
48
49
|
}));
|
|
49
50
|
return packageInfos;
|
|
50
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-workspace-packages.mjs","sources":["../../../src/functions/workspace-utils/get-workspace-packages.mts"],"sourcesContent":["import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport {\n Arr,\n hasKey,\n isNotUndefined,\n isRecord,\n isString,\n Json,\n Result,\n} from 'ts-data-forge';\nimport {\n type JsonValue,\n type MutableFixedLengthTuple,\n type ReadonlyRecord,\n} from 'ts-type-forge';\nimport { glob } from '../glob.mjs';\nimport { type Package
|
|
1
|
+
{"version":3,"file":"get-workspace-packages.mjs","sources":["../../../src/functions/workspace-utils/get-workspace-packages.mts"],"sourcesContent":["import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport {\n Arr,\n hasKey,\n isNotUndefined,\n isRecord,\n isString,\n Json,\n Result,\n} from 'ts-data-forge';\nimport {\n type JsonValue,\n type MutableFixedLengthTuple,\n type ReadonlyRecord,\n} from 'ts-type-forge';\nimport { glob } from '../glob.mjs';\nimport {\n defaultDependencyFields,\n type DependencyField,\n type Package,\n} from './types.mjs';\n\n/**\n * Retrieves all workspace packages from a monorepo based on the workspace\n * patterns defined in the root package.json file.\n *\n * @param rootPackageJsonDir - The directory containing the root package.json\n * file\n * @param dependencyFields - Which `package.json` fields contribute to each\n * package's `dependencies` map. Defaults to\n * {@link defaultDependencyFields}.\n * @returns A promise that resolves to an array of Package objects containing\n * package metadata\n */\nexport const getWorkspacePackages = async (\n rootPackageJsonDir: string,\n dependencyFields: readonly DependencyField[] = defaultDependencyFields,\n): Promise<readonly Package[]> => {\n // Read root package.json\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const rootPackageJson: JsonValue = JSON.parse(\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await fs.readFile(path.join(rootPackageJsonDir, 'package.json'), 'utf8'),\n );\n\n const workspacePatterns: readonly string[] = getStrArrayFromJsonValue(\n rootPackageJson,\n 'workspaces',\n );\n\n const packagePromises = workspacePatterns.map(async (pattern) => {\n const globResult = await glob(pattern, {\n cwd: rootPackageJsonDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n absolute: true,\n });\n\n if (Result.isErr(globResult)) {\n return [];\n }\n\n const matches = globResult.value;\n\n const packageJsonList: readonly (\n readonly [string, JsonValue] | undefined\n )[] = await Promise.all(\n matches.map(async (match) => {\n const maybePackagePath = path.join(match, 'package.json');\n\n const result = await Result.fromPromise(\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n fs.readFile(maybePackagePath, 'utf8'),\n );\n\n if (Result.isErr(result)) return undefined;\n\n const parsed = Json.parse(result.value);\n\n if (Result.isErr(parsed)) return undefined;\n\n return [maybePackagePath, parsed.value] as const;\n }),\n );\n\n const packageInfos: readonly Package[] = packageJsonList\n .filter(isNotUndefined)\n .map(([packagePath, packageJson]) => ({\n name: getStrFromJsonValue(packageJson, 'name'),\n path: path.dirname(packagePath),\n packageJson,\n dependencies: Object.fromEntries(\n dependencyFields.flatMap((field) =>\n Object.entries(getKeyValueRecordFromJsonValue(packageJson, field)),\n ),\n ),\n }));\n\n return packageInfos;\n });\n\n const allPackageArrays = await Promise.all(packagePromises);\n\n const finalPackages = allPackageArrays.flat();\n\n return finalPackages;\n};\n\nconst getStrFromJsonValue = (value: JsonValue, key: string): string =>\n isRecord(value) && hasKey(value, key) && isString(value[key])\n ? value[key]\n : '';\n\nconst getStrArrayFromJsonValue = (\n value: JsonValue,\n key: string,\n): readonly string[] =>\n isRecord(value) &&\n hasKey(value, key) &&\n Arr.isArray(value[key]) &&\n value[key].every(isString)\n ? value[key]\n : ([] as const);\n\nconst getKeyValueRecordFromJsonValue = (\n value: JsonValue,\n key: string,\n): ReadonlyRecord<string, string> => {\n if (!isRecord(value) || !hasKey(value, key)) {\n return {};\n }\n\n const obj = value[key];\n\n if (!isRecord(obj)) {\n return {};\n }\n\n const entries = Object.entries(obj).filter(\n (entry): entry is MutableFixedLengthTuple<2, string> => isString(entry[1]),\n );\n\n return Object.fromEntries(entries);\n};\n"],"names":[],"mappings":"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"}
|
|
@@ -2,4 +2,5 @@ export { executeParallel, executeStages } from './execute-parallel.mjs';
|
|
|
2
2
|
export { getWorkspacePackages } from './get-workspace-packages.mjs';
|
|
3
3
|
export { runCmdInParallelAcrossWorkspaces } from './run-cmd-in-parallel.mjs';
|
|
4
4
|
export { runCmdInStagesAcrossWorkspaces } from './run-cmd-in-stages.mjs';
|
|
5
|
+
export { defaultDependencyFields } from './types.mjs';
|
|
5
6
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DependencyField } from './types.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Executes a npm script command across all workspace packages in dependency
|
|
3
4
|
* order stages. Packages are grouped into stages where each stage contains
|
|
@@ -12,13 +13,18 @@
|
|
|
12
13
|
* simultaneously within each stage (default: 3)
|
|
13
14
|
* @param options.filterWorkspacePattern - Optional function to filter packages
|
|
14
15
|
* by name
|
|
16
|
+
* @param options.dependencyFields - Which `package.json` fields the ordering
|
|
17
|
+
* is derived from. Defaults to {@link defaultDependencyFields}; pass
|
|
18
|
+
* `['dependencies', 'peerDependencies']` to order by what has to be built
|
|
19
|
+
* first and ignore development-only edges.
|
|
15
20
|
* @returns A promise that resolves when all stages have completed execution
|
|
16
21
|
* successfully, or rejects immediately on first failure
|
|
17
22
|
*/
|
|
18
|
-
export declare const runCmdInStagesAcrossWorkspaces: ({ rootPackageJsonDir, cmd, concurrency, filterWorkspacePattern, }: Readonly<{
|
|
23
|
+
export declare const runCmdInStagesAcrossWorkspaces: ({ rootPackageJsonDir, cmd, concurrency, filterWorkspacePattern, dependencyFields, }: Readonly<{
|
|
19
24
|
rootPackageJsonDir: string;
|
|
20
25
|
cmd: string;
|
|
21
26
|
concurrency?: number;
|
|
22
27
|
filterWorkspacePattern?: (packageName: string) => boolean;
|
|
28
|
+
dependencyFields?: readonly DependencyField[];
|
|
23
29
|
}>) => Promise<void>;
|
|
24
30
|
//# sourceMappingURL=run-cmd-in-stages.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cmd-in-stages.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/run-cmd-in-stages.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-cmd-in-stages.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/run-cmd-in-stages.mts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,8BAA8B,wFAMxC,QAAQ,CAAC;IACV,kBAAkB,EAAE,MAAM,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1D,gBAAgB,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CAC/C,CAAC,KAAG,OAAO,CAAC,IAAI,CA8BhB,CAAC"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { isError } from '@sindresorhus/is';
|
|
2
2
|
import { executeStages } from './execute-parallel.mjs';
|
|
3
3
|
import { getWorkspacePackages } from './get-workspace-packages.mjs';
|
|
4
|
+
import { defaultDependencyFields } from './types.mjs';
|
|
4
5
|
|
|
5
6
|
const runCmdInStagesAcrossWorkspaces = async ({
|
|
6
7
|
rootPackageJsonDir,
|
|
7
8
|
cmd,
|
|
8
9
|
concurrency = 3,
|
|
9
|
-
filterWorkspacePattern
|
|
10
|
+
filterWorkspacePattern,
|
|
11
|
+
dependencyFields = defaultDependencyFields
|
|
10
12
|
}) => {
|
|
11
13
|
try {
|
|
12
|
-
const packages = await getWorkspacePackages(
|
|
14
|
+
const packages = await getWorkspacePackages(
|
|
15
|
+
rootPackageJsonDir,
|
|
16
|
+
dependencyFields
|
|
17
|
+
);
|
|
13
18
|
const filteredPackages = filterWorkspacePattern === void 0 ? packages : packages.filter((pkg) => filterWorkspacePattern(pkg.name));
|
|
14
19
|
console.info(
|
|
15
20
|
`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cmd-in-stages.mjs","sources":["../../../src/functions/workspace-utils/run-cmd-in-stages.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { executeStages } from './execute-parallel.mjs';\nimport { getWorkspacePackages } from './get-workspace-packages.mjs';\n\n/**\n * Executes a npm script command across all workspace packages in dependency\n * order stages. Packages are grouped into stages where each stage contains\n * packages whose dependencies have been completed in previous stages. Uses\n * fail-fast behavior - stops execution immediately when any package fails.\n *\n * @param options - Configuration options for the staged execution\n * @param options.rootPackageJsonDir - The directory containing the root\n * package.json file\n * @param options.cmd - The npm script command to execute in each package\n * @param options.concurrency - Maximum number of packages to process\n * simultaneously within each stage (default: 3)\n * @param options.filterWorkspacePattern - Optional function to filter packages\n * by name\n * @returns A promise that resolves when all stages have completed execution\n * successfully, or rejects immediately on first failure\n */\nexport const runCmdInStagesAcrossWorkspaces = async ({\n rootPackageJsonDir,\n cmd,\n concurrency = 3,\n filterWorkspacePattern,\n}: Readonly<{\n rootPackageJsonDir: string;\n cmd: string;\n concurrency?: number;\n filterWorkspacePattern?: (packageName: string) => boolean;\n}>): Promise<void> => {\n try {\n const packages = await getWorkspacePackages(rootPackageJsonDir);\n\n const filteredPackages =\n filterWorkspacePattern === undefined\n ? packages\n : packages.filter((pkg) => filterWorkspacePattern(pkg.name));\n\n console.info(\n `\\nStarting ${cmd} across ${filteredPackages.length} packages (fail-fast mode)...`,\n );\n\n await executeStages(filteredPackages, cmd, concurrency);\n\n console.info(`\\n✅ ${cmd} completed successfully (all stages)`);\n } catch (error) {\n const errorMessage = isError(error)\n ? error.message\n : (error?.toString() ?? '');\n\n console.error(`\\n❌ ${cmd} failed (fail-fast mode stopped execution):`);\n\n console.error(errorMessage);\n\n process.exit(1);\n }\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-cmd-in-stages.mjs","sources":["../../../src/functions/workspace-utils/run-cmd-in-stages.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { executeStages } from './execute-parallel.mjs';\nimport { getWorkspacePackages } from './get-workspace-packages.mjs';\nimport { defaultDependencyFields, type DependencyField } from './types.mjs';\n\n/**\n * Executes a npm script command across all workspace packages in dependency\n * order stages. Packages are grouped into stages where each stage contains\n * packages whose dependencies have been completed in previous stages. Uses\n * fail-fast behavior - stops execution immediately when any package fails.\n *\n * @param options - Configuration options for the staged execution\n * @param options.rootPackageJsonDir - The directory containing the root\n * package.json file\n * @param options.cmd - The npm script command to execute in each package\n * @param options.concurrency - Maximum number of packages to process\n * simultaneously within each stage (default: 3)\n * @param options.filterWorkspacePattern - Optional function to filter packages\n * by name\n * @param options.dependencyFields - Which `package.json` fields the ordering\n * is derived from. Defaults to {@link defaultDependencyFields}; pass\n * `['dependencies', 'peerDependencies']` to order by what has to be built\n * first and ignore development-only edges.\n * @returns A promise that resolves when all stages have completed execution\n * successfully, or rejects immediately on first failure\n */\nexport const runCmdInStagesAcrossWorkspaces = async ({\n rootPackageJsonDir,\n cmd,\n concurrency = 3,\n filterWorkspacePattern,\n dependencyFields = defaultDependencyFields,\n}: Readonly<{\n rootPackageJsonDir: string;\n cmd: string;\n concurrency?: number;\n filterWorkspacePattern?: (packageName: string) => boolean;\n dependencyFields?: readonly DependencyField[];\n}>): Promise<void> => {\n try {\n const packages = await getWorkspacePackages(\n rootPackageJsonDir,\n dependencyFields,\n );\n\n const filteredPackages =\n filterWorkspacePattern === undefined\n ? packages\n : packages.filter((pkg) => filterWorkspacePattern(pkg.name));\n\n console.info(\n `\\nStarting ${cmd} across ${filteredPackages.length} packages (fail-fast mode)...`,\n );\n\n await executeStages(filteredPackages, cmd, concurrency);\n\n console.info(`\\n✅ ${cmd} completed successfully (all stages)`);\n } catch (error) {\n const errorMessage = isError(error)\n ? error.message\n : (error?.toString() ?? '');\n\n console.error(`\\n❌ ${cmd} failed (fail-fast mode stopped execution):`);\n\n console.error(errorMessage);\n\n process.exit(1);\n }\n};\n"],"names":[],"mappings":";;;;;AA0BO,MAAM,iCAAiC,OAAO;AAAA,EACnD,kBAAA;AAAA,EACA,GAAA;AAAA,EACA,WAAA,GAAc,CAAA;AAAA,EACd,sBAAA;AAAA,EACA,gBAAA,GAAmB;AACrB,CAAA,KAMsB;AACpB,EAAA,IAAI;AACF,IAAA,MAAM,WAAW,MAAM,oBAAA;AAAA,MACrB,kBAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,MAAM,gBAAA,GACJ,sBAAA,KAA2B,KAAA,CAAA,GACvB,QAAA,GACA,QAAA,CAAS,MAAA,CAAO,CAAC,GAAA,KAAQ,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAC,CAAA;AAE/D,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,SAAA,EAAc,GAAG,CAAA,QAAA,EAAW,gBAAA,CAAiB,MAAM,CAAA,6BAAA;AAAA,KACrD;AAEA,IAAA,MAAM,aAAA,CAAc,gBAAA,EAAkB,GAAA,EAAK,WAAW,CAAA;AAEtD,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,OAAA,EAAO,GAAG,CAAA,oCAAA,CAAsC,CAAA;AAAA,EAC/D,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,YAAA,GAAe,QAAQ,KAAK,CAAA,GAC9B,MAAM,OAAA,GACL,KAAA,EAAO,UAAS,IAAK,EAAA;AAE1B,IAAA,OAAA,CAAQ,KAAA,CAAM;AAAA,OAAA,EAAO,GAAG,CAAA,2CAAA,CAA6C,CAAA;AAErE,IAAA,OAAA,CAAQ,MAAM,YAAY,CAAA;AAE1B,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF;;;;"}
|
|
@@ -5,4 +5,17 @@ export type Package = Readonly<{
|
|
|
5
5
|
packageJson: JsonValue;
|
|
6
6
|
dependencies: ReadonlyRecord<string, string>;
|
|
7
7
|
}>;
|
|
8
|
+
/** A `package.json` field that can contribute edges to the dependency graph. */
|
|
9
|
+
export type DependencyField = 'dependencies' | 'devDependencies' | 'peerDependencies';
|
|
10
|
+
/**
|
|
11
|
+
* Fields merged into {@link Package.dependencies} when none are specified.
|
|
12
|
+
*
|
|
13
|
+
* Including `devDependencies` means a package that only *develops* against a
|
|
14
|
+
* sibling still has to wait for it. That is the safe default, but in a
|
|
15
|
+
* repository where the toolchain is itself a workspace package it makes the
|
|
16
|
+
* graph cyclic, since the toolchain depends on the packages it serves. Pass
|
|
17
|
+
* `['dependencies', 'peerDependencies']` when the ordering should reflect only
|
|
18
|
+
* what has to be built first.
|
|
19
|
+
*/
|
|
20
|
+
export declare const defaultDependencyFields: readonly ["dependencies", "devDependencies", "peerDependencies"];
|
|
8
21
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/types.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpE,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,CAAC;IACvB,YAAY,EAAE,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/functions/workspace-utils/types.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpE,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,CAAC;IACvB,YAAY,EAAE,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,MAAM,eAAe,GACzB,cAAc,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAE1D;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,kEAIW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":["../../../src/functions/workspace-utils/types.mts"],"sourcesContent":["import { type JsonValue, type ReadonlyRecord } from 'ts-type-forge';\n\n// Get all workspace packages\nexport type Package = Readonly<{\n name: string;\n path: string;\n packageJson: JsonValue;\n dependencies: ReadonlyRecord<string, string>;\n}>;\n\n/** A `package.json` field that can contribute edges to the dependency graph. */\nexport type DependencyField =\n 'dependencies' | 'devDependencies' | 'peerDependencies';\n\n/**\n * Fields merged into {@link Package.dependencies} when none are specified.\n *\n * Including `devDependencies` means a package that only *develops* against a\n * sibling still has to wait for it. That is the safe default, but in a\n * repository where the toolchain is itself a workspace package it makes the\n * graph cyclic, since the toolchain depends on the packages it serves. Pass\n * `['dependencies', 'peerDependencies']` when the ordering should reflect only\n * what has to be built first.\n */\nexport const defaultDependencyFields = [\n 'dependencies',\n 'devDependencies',\n 'peerDependencies',\n] as const satisfies readonly DependencyField[];\n"],"names":[],"mappings":"AAwBO,MAAM,uBAAA,GAA0B;AAAA,EACrC,cAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -14,4 +14,5 @@ export { executeParallel, executeStages } from './functions/workspace-utils/exec
|
|
|
14
14
|
export { getWorkspacePackages } from './functions/workspace-utils/get-workspace-packages.mjs';
|
|
15
15
|
export { runCmdInParallelAcrossWorkspaces } from './functions/workspace-utils/run-cmd-in-parallel.mjs';
|
|
16
16
|
export { runCmdInStagesAcrossWorkspaces } from './functions/workspace-utils/run-cmd-in-stages.mjs';
|
|
17
|
+
export { defaultDependencyFields } from './functions/workspace-utils/types.mjs';
|
|
17
18
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-repo-utils",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
7
7
|
],
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/noshiro-pf/
|
|
10
|
+
"url": "git+https://github.com/noshiro-pf/mono.git",
|
|
11
|
+
"directory": "libs/ts-repo-utils"
|
|
11
12
|
},
|
|
12
13
|
"license": "Apache-2.0",
|
|
13
14
|
"author": "noshiro-pf <noshiro.pf@gmail.com>",
|
|
@@ -40,55 +41,6 @@
|
|
|
40
41
|
"README.md",
|
|
41
42
|
"LICENSE"
|
|
42
43
|
],
|
|
43
|
-
"scripts": {
|
|
44
|
-
"agents:gen": "tsx ./scripts/cmd/gen-agents-md.mts",
|
|
45
|
-
"agents:sync": "tsx ./scripts/cmd/sync-agent-config.mts",
|
|
46
|
-
"build": "tsx ./scripts/cmd/build.mts",
|
|
47
|
-
"build:min": "tsx ./scripts/cmd/build.mts --skip-check",
|
|
48
|
-
"check:ext": "tsx ./scripts/cmd/check-ext.mts",
|
|
49
|
-
"check-all": "tsx ./scripts/cmd/check-all.mts",
|
|
50
|
-
"codemod": "run-s codemod:uncommitted:as-const fmt codemod:uncommitted:readonly fmt",
|
|
51
|
-
"codemod:diff": "run-s codemod:diff:as-const fmt codemod:diff:readonly fmt",
|
|
52
|
-
"codemod:diff:as-const": "append-as-const --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
53
|
-
"codemod:diff:readonly": "convert-to-readonly --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
54
|
-
"codemod:full": "run-s codemod:full:as-const fmt codemod:full:readonly fmt",
|
|
55
|
-
"codemod:full:as-const": "append-as-const '{src,scripts,samples}/**/*.mts'",
|
|
56
|
-
"codemod:full:readonly": "convert-to-readonly '{src,scripts,samples}/**/*.mts'",
|
|
57
|
-
"codemod:uncommitted:as-const": "append-as-const --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
58
|
-
"codemod:uncommitted:readonly": "convert-to-readonly --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
59
|
-
"cspell": "cspell \"{**,.changeset/**/*,.github/**/*}\" --gitignore --gitignore-root ./ --no-progress",
|
|
60
|
-
"doc": "tsx ./scripts/cmd/gen-docs.mts",
|
|
61
|
-
"doc:embed": "tsx ./scripts/cmd/embed-examples.mts",
|
|
62
|
-
"doc:preview": "vite preview --config ./configs/vite.doc.config.mts",
|
|
63
|
-
"doc:watch": "typedoc --options ./configs/typedoc.config.mjs --watch",
|
|
64
|
-
"fmt": "pnpm run z:format-uncommitted",
|
|
65
|
-
"fmt:diff": "pnpm run z:format-diff-from origin/main",
|
|
66
|
-
"fmt:full": "prettier --write .",
|
|
67
|
-
"gi": "run-s gi:src fmt",
|
|
68
|
-
"gi:src": "pnpm run z:gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --exclude entry-point.mts --exclude cmd",
|
|
69
|
-
"lint": "eslint .",
|
|
70
|
-
"lint:fix": "eslint . --fix",
|
|
71
|
-
"md": "markdownlint-cli2",
|
|
72
|
-
"prepare-release": "run-s sync-cli-versions fmt build doc",
|
|
73
|
-
"repo-settings:apply": "repo-settings apply",
|
|
74
|
-
"repo-settings:backup": "repo-settings backup",
|
|
75
|
-
"sync-cli-versions": "tsx scripts/cmd/sync-cli-versions.mts",
|
|
76
|
-
"test": "pnpm run z:vitest:node run",
|
|
77
|
-
"test:cov": "pnpm run z:vitest:node run --coverage",
|
|
78
|
-
"test:cov:ui": "vite preview --outDir ./coverage",
|
|
79
|
-
"test:ui": "pnpm run z:vitest:node --ui",
|
|
80
|
-
"testw": "pnpm run z:vitest:node watch",
|
|
81
|
-
"tsc": "node ./node_modules/typescript-native/bin/tsc --noEmit",
|
|
82
|
-
"tscw": "node ./node_modules/typescript-native/bin/tsc --noEmit --watch -p ./tsconfig.json",
|
|
83
|
-
"type-check": "node ./node_modules/typescript-native/bin/tsc --noEmit",
|
|
84
|
-
"z:assert-repo-is-clean": "tsx ./src/cmd/assert-repo-is-clean.mts",
|
|
85
|
-
"z:check-should-run-type-checks": "tsx ./src/cmd/check-should-run-type-checks.mts",
|
|
86
|
-
"z:format-diff-from": "tsx ./src/cmd/format-diff-from.mts",
|
|
87
|
-
"z:format-uncommitted": "tsx ./src/cmd/format-uncommitted.mts",
|
|
88
|
-
"z:gen-index-ts": "tsx ./src/cmd/gen-index-ts.mts",
|
|
89
|
-
"z:vitest": "vitest --config ./configs/vitest.config.mts",
|
|
90
|
-
"z:vitest:node": "pnpm run z:vitest --project='Node.js'"
|
|
91
|
-
},
|
|
92
44
|
"dependencies": {
|
|
93
45
|
"@nodelib/fs.walk": "^3.0.1",
|
|
94
46
|
"@sindresorhus/is": "^8.1.0",
|
|
@@ -96,56 +48,41 @@
|
|
|
96
48
|
"cmd-ts": "^0.15.0",
|
|
97
49
|
"fast-glob": "^3.3.3",
|
|
98
50
|
"micromatch": "^4.0.8",
|
|
99
|
-
"ts-data-forge": "^14.1
|
|
100
|
-
"ts-type-forge": "^9.1
|
|
101
|
-
"tsx": "^4.23.4"
|
|
51
|
+
"ts-data-forge": "^14.2.1",
|
|
52
|
+
"ts-type-forge": "^9.2.1"
|
|
102
53
|
},
|
|
103
54
|
"devDependencies": {
|
|
104
55
|
"@rollup/plugin-replace": "6.0.3",
|
|
105
56
|
"@rollup/plugin-strip": "3.0.4",
|
|
106
|
-
"@semantic-release/changelog": "7.0.0",
|
|
107
|
-
"@semantic-release/commit-analyzer": "13.0.1",
|
|
108
|
-
"@semantic-release/exec": "7.1.0",
|
|
109
|
-
"@semantic-release/git": "11.0.1",
|
|
110
|
-
"@semantic-release/github": "12.0.9",
|
|
111
|
-
"@semantic-release/npm": "13.1.5",
|
|
112
|
-
"@semantic-release/release-notes-generator": "14.1.1",
|
|
113
57
|
"@types/node": "26.2.0",
|
|
114
58
|
"@vitest/coverage-v8": "4.1.10",
|
|
115
59
|
"@vitest/ui": "4.1.10",
|
|
116
|
-
"conventional-changelog-conventionalcommits": "10.2.1",
|
|
117
60
|
"cspell": "10.0.1",
|
|
118
61
|
"dedent": "1.7.2",
|
|
119
62
|
"esbuild": "0.28.1",
|
|
120
63
|
"eslint": "10.8.0",
|
|
121
|
-
"eslint-config-typed": "5.8.4",
|
|
122
|
-
"eslint-plugin-ts-data-forge": "0.4.2",
|
|
123
|
-
"eslint-plugin-ts-fortress": "1.0.0",
|
|
124
|
-
"eslint-plugin-ts-type-forge": "0.6.1",
|
|
125
|
-
"github-settings-as-code": "2.1.0",
|
|
126
64
|
"jiti": "2.7.0",
|
|
127
|
-
"markdownlint": "0.41.1",
|
|
128
|
-
"markdownlint-cli2": "0.23.2",
|
|
129
65
|
"npm-run-all2": "9.0.3",
|
|
130
66
|
"prettier": "3.9.6",
|
|
131
67
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
132
68
|
"prettier-plugin-packagejson": "3.0.2",
|
|
133
69
|
"rollup": "4.62.4",
|
|
134
70
|
"rollup-plugin-esbuild": "6.2.1",
|
|
135
|
-
"
|
|
136
|
-
"ts-codemod-lib": "2.2.4",
|
|
137
|
-
"ts-repo-utils": "10.1.7",
|
|
71
|
+
"tsx": "4.23.4",
|
|
138
72
|
"typedoc": "0.28.20",
|
|
139
73
|
"typedoc-github-theme": "0.4.0",
|
|
140
74
|
"typescript": "6.0.3",
|
|
141
75
|
"typescript-native": "npm:typescript@7.0.2",
|
|
142
76
|
"vite": "8.2.0",
|
|
143
|
-
"vitest": "4.1.10"
|
|
77
|
+
"vitest": "4.1.10",
|
|
78
|
+
"eslint-config-typed": "5.8.5",
|
|
79
|
+
"eslint-plugin-ts-fortress": "1.0.1",
|
|
80
|
+
"eslint-plugin-ts-data-forge": "0.4.4",
|
|
81
|
+
"eslint-plugin-ts-type-forge": "0.6.3"
|
|
144
82
|
},
|
|
145
83
|
"peerDependencies": {
|
|
146
84
|
"prettier": ">=3.0.0"
|
|
147
85
|
},
|
|
148
|
-
"packageManager": "pnpm@11.20.0",
|
|
149
86
|
"engines": {
|
|
150
87
|
"node": ">=22.22.2",
|
|
151
88
|
"pnpm": ">=8.0.0"
|
|
@@ -156,5 +93,49 @@
|
|
|
156
93
|
"publishConfig": {
|
|
157
94
|
"access": "public",
|
|
158
95
|
"provenance": true
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/build.mts",
|
|
99
|
+
"build:min": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/build.mts --skip-check",
|
|
100
|
+
"check:ext": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-ext.mts",
|
|
101
|
+
"check-all": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-all.mts",
|
|
102
|
+
"codemod": "run-s codemod:uncommitted:as-const fmt codemod:uncommitted:readonly fmt",
|
|
103
|
+
"codemod:diff": "run-s codemod:diff:as-const fmt codemod:diff:readonly fmt",
|
|
104
|
+
"codemod:diff:as-const": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/append-as-const.mts --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
105
|
+
"codemod:diff:readonly": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/convert-to-readonly.mts --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
106
|
+
"codemod:full": "run-s codemod:full:as-const fmt codemod:full:readonly fmt",
|
|
107
|
+
"codemod:full:as-const": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/append-as-const.mts '{src,scripts,samples}/**/*.mts'",
|
|
108
|
+
"codemod:full:readonly": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/convert-to-readonly.mts '{src,scripts,samples}/**/*.mts'",
|
|
109
|
+
"codemod:uncommitted:as-const": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/append-as-const.mts --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
110
|
+
"codemod:uncommitted:readonly": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/convert-to-readonly.mts --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
111
|
+
"cspell": "cspell \"**\" --gitignore --gitignore-root ../../ --no-progress",
|
|
112
|
+
"doc": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/gen-docs.mts",
|
|
113
|
+
"doc:embed": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/embed-examples.mts",
|
|
114
|
+
"doc:preview": "vite preview --config ./configs/vite.doc.config.mts",
|
|
115
|
+
"doc:watch": "typedoc --options ./configs/typedoc.config.mjs --watch",
|
|
116
|
+
"fmt": "pnpm run z:format-uncommitted --cwd .",
|
|
117
|
+
"fmt:diff": "pnpm run z:format-diff-from origin/main --cwd .",
|
|
118
|
+
"fmt:full": "prettier --write .",
|
|
119
|
+
"gi": "run-s gi:src fmt",
|
|
120
|
+
"gi:src": "pnpm run z:gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --exclude entry-point.mts --exclude cmd",
|
|
121
|
+
"lint": "eslint .",
|
|
122
|
+
"lint:fix": "eslint . --fix",
|
|
123
|
+
"prepare-release": "run-s sync-cli-versions fmt build doc",
|
|
124
|
+
"sync-cli-versions": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json scripts/cmd/sync-cli-versions.mts",
|
|
125
|
+
"test": "pnpm run z:vitest:node run",
|
|
126
|
+
"test:cov": "pnpm run z:vitest:node run --coverage",
|
|
127
|
+
"test:cov:ui": "vite preview --outDir ./coverage",
|
|
128
|
+
"test:ui": "pnpm run z:vitest:node --ui",
|
|
129
|
+
"testw": "pnpm run z:vitest:node watch",
|
|
130
|
+
"tsc": "node ../../node_modules/typescript-native/bin/tsc --noEmit",
|
|
131
|
+
"tscw": "node ../../node_modules/typescript-native/bin/tsc --noEmit --watch -p ./tsconfig.json",
|
|
132
|
+
"type-check": "node ../../node_modules/typescript-native/bin/tsc --noEmit",
|
|
133
|
+
"z:assert-repo-is-clean": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./src/cmd/assert-repo-is-clean.mts",
|
|
134
|
+
"z:check-should-run-type-checks": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./src/cmd/check-should-run-type-checks.mts",
|
|
135
|
+
"z:format-diff-from": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./src/cmd/format-diff-from.mts",
|
|
136
|
+
"z:format-uncommitted": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./src/cmd/format-uncommitted.mts",
|
|
137
|
+
"z:gen-index-ts": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./src/cmd/gen-index-ts.mts",
|
|
138
|
+
"z:vitest": "vitest --config ./configs/vitest.config.mts",
|
|
139
|
+
"z:vitest:node": "pnpm run z:vitest --project='Node.js'"
|
|
159
140
|
}
|
|
160
|
-
}
|
|
141
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/cmd/gen-index-ts.mts
CHANGED
|
File without changes
|
|
@@ -15,7 +15,11 @@ import {
|
|
|
15
15
|
type ReadonlyRecord,
|
|
16
16
|
} from 'ts-type-forge';
|
|
17
17
|
import { glob } from '../glob.mjs';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
defaultDependencyFields,
|
|
20
|
+
type DependencyField,
|
|
21
|
+
type Package,
|
|
22
|
+
} from './types.mjs';
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* Retrieves all workspace packages from a monorepo based on the workspace
|
|
@@ -23,11 +27,15 @@ import { type Package } from './types.mjs';
|
|
|
23
27
|
*
|
|
24
28
|
* @param rootPackageJsonDir - The directory containing the root package.json
|
|
25
29
|
* file
|
|
30
|
+
* @param dependencyFields - Which `package.json` fields contribute to each
|
|
31
|
+
* package's `dependencies` map. Defaults to
|
|
32
|
+
* {@link defaultDependencyFields}.
|
|
26
33
|
* @returns A promise that resolves to an array of Package objects containing
|
|
27
34
|
* package metadata
|
|
28
35
|
*/
|
|
29
36
|
export const getWorkspacePackages = async (
|
|
30
37
|
rootPackageJsonDir: string,
|
|
38
|
+
dependencyFields: readonly DependencyField[] = defaultDependencyFields,
|
|
31
39
|
): Promise<readonly Package[]> => {
|
|
32
40
|
// Read root package.json
|
|
33
41
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -82,11 +90,11 @@ export const getWorkspacePackages = async (
|
|
|
82
90
|
name: getStrFromJsonValue(packageJson, 'name'),
|
|
83
91
|
path: path.dirname(packagePath),
|
|
84
92
|
packageJson,
|
|
85
|
-
dependencies:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
dependencies: Object.fromEntries(
|
|
94
|
+
dependencyFields.flatMap((field) =>
|
|
95
|
+
Object.entries(getKeyValueRecordFromJsonValue(packageJson, field)),
|
|
96
|
+
),
|
|
97
|
+
),
|
|
90
98
|
}));
|
|
91
99
|
|
|
92
100
|
return packageInfos;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isError } from '@sindresorhus/is';
|
|
2
2
|
import { executeStages } from './execute-parallel.mjs';
|
|
3
3
|
import { getWorkspacePackages } from './get-workspace-packages.mjs';
|
|
4
|
+
import { defaultDependencyFields, type DependencyField } from './types.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Executes a npm script command across all workspace packages in dependency
|
|
@@ -16,6 +17,10 @@ import { getWorkspacePackages } from './get-workspace-packages.mjs';
|
|
|
16
17
|
* simultaneously within each stage (default: 3)
|
|
17
18
|
* @param options.filterWorkspacePattern - Optional function to filter packages
|
|
18
19
|
* by name
|
|
20
|
+
* @param options.dependencyFields - Which `package.json` fields the ordering
|
|
21
|
+
* is derived from. Defaults to {@link defaultDependencyFields}; pass
|
|
22
|
+
* `['dependencies', 'peerDependencies']` to order by what has to be built
|
|
23
|
+
* first and ignore development-only edges.
|
|
19
24
|
* @returns A promise that resolves when all stages have completed execution
|
|
20
25
|
* successfully, or rejects immediately on first failure
|
|
21
26
|
*/
|
|
@@ -24,14 +29,19 @@ export const runCmdInStagesAcrossWorkspaces = async ({
|
|
|
24
29
|
cmd,
|
|
25
30
|
concurrency = 3,
|
|
26
31
|
filterWorkspacePattern,
|
|
32
|
+
dependencyFields = defaultDependencyFields,
|
|
27
33
|
}: Readonly<{
|
|
28
34
|
rootPackageJsonDir: string;
|
|
29
35
|
cmd: string;
|
|
30
36
|
concurrency?: number;
|
|
31
37
|
filterWorkspacePattern?: (packageName: string) => boolean;
|
|
38
|
+
dependencyFields?: readonly DependencyField[];
|
|
32
39
|
}>): Promise<void> => {
|
|
33
40
|
try {
|
|
34
|
-
const packages = await getWorkspacePackages(
|
|
41
|
+
const packages = await getWorkspacePackages(
|
|
42
|
+
rootPackageJsonDir,
|
|
43
|
+
dependencyFields,
|
|
44
|
+
);
|
|
35
45
|
|
|
36
46
|
const filteredPackages =
|
|
37
47
|
filterWorkspacePattern === undefined
|
|
@@ -7,3 +7,23 @@ export type Package = Readonly<{
|
|
|
7
7
|
packageJson: JsonValue;
|
|
8
8
|
dependencies: ReadonlyRecord<string, string>;
|
|
9
9
|
}>;
|
|
10
|
+
|
|
11
|
+
/** A `package.json` field that can contribute edges to the dependency graph. */
|
|
12
|
+
export type DependencyField =
|
|
13
|
+
'dependencies' | 'devDependencies' | 'peerDependencies';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fields merged into {@link Package.dependencies} when none are specified.
|
|
17
|
+
*
|
|
18
|
+
* Including `devDependencies` means a package that only *develops* against a
|
|
19
|
+
* sibling still has to wait for it. That is the safe default, but in a
|
|
20
|
+
* repository where the toolchain is itself a workspace package it makes the
|
|
21
|
+
* graph cyclic, since the toolchain depends on the packages it serves. Pass
|
|
22
|
+
* `['dependencies', 'peerDependencies']` when the ordering should reflect only
|
|
23
|
+
* what has to be built first.
|
|
24
|
+
*/
|
|
25
|
+
export const defaultDependencyFields = [
|
|
26
|
+
'dependencies',
|
|
27
|
+
'devDependencies',
|
|
28
|
+
'peerDependencies',
|
|
29
|
+
] as const satisfies readonly DependencyField[];
|