@nzyme/cli 0.15.1 → 0.16.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/dist/NzymePackageConfig.d.ts +2 -0
- package/dist/affected/AffectedConfig.d.ts +61 -0
- package/dist/affected/AffectedConfig.js +73 -0
- package/dist/affected/AffectedConfig.js.map +1 -0
- package/dist/affected/AffectedConfig.test.js +48 -0
- package/dist/affected/AffectedConfig.test.js.map +1 -0
- package/dist/affected/affected.test.js +154 -0
- package/dist/affected/affected.test.js.map +1 -0
- package/dist/affected/collectChangedFiles.d.ts +25 -0
- package/dist/affected/collectChangedFiles.js +83 -0
- package/dist/affected/collectChangedFiles.js.map +1 -0
- package/dist/affected/rewriteChangedPath.d.ts +7 -0
- package/dist/affected/rewriteChangedPath.js +15 -0
- package/dist/affected/rewriteChangedPath.js.map +1 -0
- package/dist/affected/selectAffectedFiles.d.ts +52 -0
- package/dist/affected/selectAffectedFiles.js +135 -0
- package/dist/affected/selectAffectedFiles.js.map +1 -0
- package/dist/affected/selectAffectedFiles.test.d.ts +1 -0
- package/dist/affected/selectAffectedFiles.test.js +207 -0
- package/dist/affected/selectAffectedFiles.test.js.map +1 -0
- package/dist/cli.js +23 -15
- package/dist/cli.js.map +1 -1
- package/dist/codeIndex/NzymeIndexConfig.js +5 -33
- package/dist/codeIndex/NzymeIndexConfig.js.map +1 -1
- package/dist/codeIndex/collectIndexSourceFiles.d.ts +3 -3
- package/dist/codeIndex/collectIndexSourceFiles.js +7 -37
- package/dist/codeIndex/collectIndexSourceFiles.js.map +1 -1
- package/dist/codeIndex/collectSymbols.test.js +7 -3
- package/dist/codeIndex/collectSymbols.test.js.map +1 -1
- package/dist/codeIndex/importPathOf.js +2 -2
- package/dist/codeIndex/importPathOf.js.map +1 -1
- package/dist/commands/DepcheckCommand.d.ts +1 -1
- package/dist/commands/DepcheckCommand.js +2 -2
- package/dist/commands/DepcheckCommand.js.map +1 -1
- package/dist/commands/GitAffectedCommand.d.ts +25 -0
- package/dist/commands/GitAffectedCommand.js +229 -0
- package/dist/commands/GitAffectedCommand.js.map +1 -0
- package/dist/commands/GitAffectedCommand.test.d.ts +1 -0
- package/dist/commands/GitAffectedCommand.test.js +159 -0
- package/dist/commands/GitAffectedCommand.test.js.map +1 -0
- package/dist/commands/GitBaseCommand.d.ts +17 -0
- package/dist/commands/GitBaseCommand.js +48 -0
- package/dist/commands/GitBaseCommand.js.map +1 -0
- package/dist/commands/GitBaseCommand.test.d.ts +1 -0
- package/dist/commands/GitBaseCommand.test.js +76 -0
- package/dist/commands/GitBaseCommand.test.js.map +1 -0
- package/dist/commands/IndexCommand.d.ts +1 -1
- package/dist/commands/IndexCommand.js +1 -1
- package/dist/commands/IndexCommand.js.map +1 -1
- package/dist/commands/LocaliseCommand.d.ts +1 -1
- package/dist/commands/LocaliseCommand.js +2 -2
- package/dist/commands/LocaliseCommand.js.map +1 -1
- package/dist/commands/MonorepoCommand.d.ts +1 -1
- package/dist/commands/MonorepoCommand.js +4 -6
- package/dist/commands/MonorepoCommand.js.map +1 -1
- package/dist/commands/QuietRunCommand.d.ts +1 -1
- package/dist/commands/QuietRunCommand.js +12 -21
- package/dist/commands/QuietRunCommand.js.map +1 -1
- package/dist/commands/SubmoduleBumpCommand.d.ts +1 -1
- package/dist/commands/SubmoduleBumpCommand.js +2 -2
- package/dist/commands/SubmoduleBumpCommand.js.map +1 -1
- package/dist/plugins/loadPlugins.d.ts +8 -0
- package/dist/plugins/loadPlugins.js +60 -0
- package/dist/plugins/loadPlugins.js.map +1 -0
- package/dist/plugins/loadPlugins.test.d.ts +1 -0
- package/dist/plugins/loadPlugins.test.js +129 -0
- package/dist/plugins/loadPlugins.test.js.map +1 -0
- package/dist/submodule/GitRepository.d.ts +4 -0
- package/dist/submodule/GitRepository.js +15 -6
- package/dist/submodule/GitRepository.js.map +1 -1
- package/dist/utils/createConfigParsers.d.ts +15 -0
- package/dist/utils/createConfigParsers.js +42 -0
- package/dist/utils/createConfigParsers.js.map +1 -0
- package/dist/utils/readNzymeConfig.d.ts +9 -0
- package/dist/utils/readNzymeConfig.js +16 -0
- package/dist/utils/readNzymeConfig.js.map +1 -0
- package/dist/utils/readProperty.d.ts +7 -0
- package/dist/utils/readProperty.js +13 -0
- package/dist/utils/readProperty.js.map +1 -0
- package/package.json +23 -38
- package/dist/Command.d.ts +0 -59
- package/dist/Command.js +0 -87
- package/dist/Command.js.map +0 -1
- package/dist/Command.test.js +0 -77
- package/dist/Command.test.js.map +0 -1
- package/dist/commands/FormatMarkdownCommand.d.ts +0 -22
- package/dist/commands/FormatMarkdownCommand.js +0 -256
- package/dist/commands/FormatMarkdownCommand.js.map +0 -1
- package/dist/commands/FormatMarkdownCommand.test.js +0 -82
- package/dist/commands/FormatMarkdownCommand.test.js.map +0 -1
- package/dist/execute.d.ts +0 -25
- package/dist/execute.js +0 -22
- package/dist/execute.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/initialize.d.ts +0 -4
- package/dist/initialize.js +0 -10
- package/dist/initialize.js.map +0 -1
- /package/dist/{Command.test.d.ts → affected/AffectedConfig.test.d.ts} +0 -0
- /package/dist/{commands/FormatMarkdownCommand.test.d.ts → affected/affected.test.d.ts} +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ImportAlias } from '@nzyme/project-utils/importGraph/resolveImportTarget.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration of `nzyme git affected` (`baseBranches` also of `nzyme git base`), read from the
|
|
4
|
+
* `nzyme.affected` field of the repo's root `package.json`. Everything is optional;
|
|
5
|
+
* {@link readAffectedConfig} fills in the defaults.
|
|
6
|
+
*
|
|
7
|
+
* `fullRunTriggers` and `ignore` are globs (`Bun.Glob`) always matched against the root-relative
|
|
8
|
+
* path — unlike the command's selection patterns, a glob without `/` is NOT matched against the
|
|
9
|
+
* basename. So `package.json` is the root manifest only (a package's own `package.json` is handled
|
|
10
|
+
* separately: it stands for a change of every source file of that package), and a glob meant for
|
|
11
|
+
* every directory says so: `**\/tsconfig*.json`. A source file a trigger file imports, transitively,
|
|
12
|
+
* triggers too — list the roots (the test preload, a `.storybook/preview.ts`), not what they import.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```json
|
|
16
|
+
* {
|
|
17
|
+
* "nzyme": {
|
|
18
|
+
* "affected": {
|
|
19
|
+
* "baseBranches": ["main", "release"],
|
|
20
|
+
* "aliases": [{ "prefix": "@/", "packages": ["@acme/app"] }],
|
|
21
|
+
* "rewrites": [{ "from": ".loc.yaml", "to": ".loc.ts" }],
|
|
22
|
+
* "fullRunTriggers": ["package.json", "bun.lock", "**\/tsconfig*.json"],
|
|
23
|
+
* "ignore": ["**\/*.md", "docs/**"]
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface AffectedConfig {
|
|
30
|
+
/** Branches auto base detection tries, as `origin/<name>`; the nearest merge-base wins. Default `["main"]`. */
|
|
31
|
+
baseBranches: string[];
|
|
32
|
+
/** Path aliases resolved by the import graph, e.g. Nuxt's `@/`. */
|
|
33
|
+
aliases: ImportAlias[];
|
|
34
|
+
/** Changed files that also stand for a change of another path. */
|
|
35
|
+
rewrites: AffectedRewrite[];
|
|
36
|
+
/** Root-relative globs: a changed file matching one selects every file matching the patterns. */
|
|
37
|
+
fullRunTriggers: string[];
|
|
38
|
+
/** Root-relative globs: a changed file matching one selects nothing (unless it is also a trigger). */
|
|
39
|
+
ignore: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Suffix → suffix: a changed file whose path ends in `from` is also treated as a change of the same
|
|
43
|
+
* path with `to` in place of that suffix — whether or not that path exists. `{ from: '.handler.ts',
|
|
44
|
+
* to: '.ts' }` makes `x/Foo.handler.ts` also change `x/Foo.ts`.
|
|
45
|
+
*/
|
|
46
|
+
export interface AffectedRewrite {
|
|
47
|
+
from: string;
|
|
48
|
+
to: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reads {@link AffectedConfig} from the `nzyme.affected` field of `<root>/package.json`. A missing
|
|
52
|
+
* field is the default config; a malformed one throws, naming the offending path.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readAffectedConfig(root: string): Promise<AffectedConfig>;
|
|
55
|
+
/**
|
|
56
|
+
* Validates a raw `nzyme.affected` value into an {@link AffectedConfig}, applying the defaults.
|
|
57
|
+
* Hand-rolled rather than schema-based, like the code index config: the shape is small and this
|
|
58
|
+
* keeps the CLI free of a validation dependency.
|
|
59
|
+
* @__NO_SIDE_EFFECTS__
|
|
60
|
+
*/
|
|
61
|
+
export declare function parseAffectedConfig(value: unknown): AffectedConfig;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isPlainObject } from '@nzyme/utils/isPlainObject.js';
|
|
2
|
+
import { createConfigParsers } from '../utils/createConfigParsers.js';
|
|
3
|
+
import { readNzymeConfig } from '../utils/readNzymeConfig.js';
|
|
4
|
+
const { parseArray, parseStringArray, parseString, configError } = createConfigParsers('affected');
|
|
5
|
+
/**
|
|
6
|
+
* Reads {@link AffectedConfig} from the `nzyme.affected` field of `<root>/package.json`. A missing
|
|
7
|
+
* field is the default config; a malformed one throws, naming the offending path.
|
|
8
|
+
*/
|
|
9
|
+
export async function readAffectedConfig(root) {
|
|
10
|
+
const nzyme = await readNzymeConfig(root);
|
|
11
|
+
return parseAffectedConfig(isPlainObject(nzyme) ? nzyme.affected : undefined);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Validates a raw `nzyme.affected` value into an {@link AffectedConfig}, applying the defaults.
|
|
15
|
+
* Hand-rolled rather than schema-based, like the code index config: the shape is small and this
|
|
16
|
+
* keeps the CLI free of a validation dependency.
|
|
17
|
+
* @__NO_SIDE_EFFECTS__
|
|
18
|
+
*/
|
|
19
|
+
export function parseAffectedConfig(value) {
|
|
20
|
+
const config = {
|
|
21
|
+
baseBranches: ['main'],
|
|
22
|
+
aliases: [],
|
|
23
|
+
rewrites: [],
|
|
24
|
+
fullRunTriggers: [],
|
|
25
|
+
ignore: [],
|
|
26
|
+
};
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
if (!isPlainObject(value)) {
|
|
31
|
+
throw configError('nzyme.affected', 'an object');
|
|
32
|
+
}
|
|
33
|
+
if (value.baseBranches !== undefined) {
|
|
34
|
+
config.baseBranches = parseStringArray(value.baseBranches, 'nzyme.affected.baseBranches');
|
|
35
|
+
if (config.baseBranches.length === 0) {
|
|
36
|
+
throw configError('nzyme.affected.baseBranches', 'a non-empty array of strings');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (value.aliases !== undefined) {
|
|
40
|
+
config.aliases = parseArray(value.aliases, 'nzyme.affected.aliases', parseAlias);
|
|
41
|
+
}
|
|
42
|
+
if (value.rewrites !== undefined) {
|
|
43
|
+
config.rewrites = parseArray(value.rewrites, 'nzyme.affected.rewrites', parseRewrite);
|
|
44
|
+
}
|
|
45
|
+
if (value.fullRunTriggers !== undefined) {
|
|
46
|
+
config.fullRunTriggers = parseStringArray(value.fullRunTriggers, 'nzyme.affected.fullRunTriggers');
|
|
47
|
+
}
|
|
48
|
+
if (value.ignore !== undefined) {
|
|
49
|
+
config.ignore = parseStringArray(value.ignore, 'nzyme.affected.ignore');
|
|
50
|
+
}
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
/** Validates one `aliases` entry. */
|
|
54
|
+
function parseAlias(value, path) {
|
|
55
|
+
if (!isPlainObject(value)) {
|
|
56
|
+
throw configError(path, 'an object');
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
prefix: parseString(value.prefix, `${path}.prefix`),
|
|
60
|
+
packages: parseStringArray(value.packages, `${path}.packages`),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Validates one `rewrites` entry. */
|
|
64
|
+
function parseRewrite(value, path) {
|
|
65
|
+
if (!isPlainObject(value)) {
|
|
66
|
+
throw configError(path, 'an object');
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
from: parseString(value.from, `${path}.from`),
|
|
70
|
+
to: parseString(value.to, `${path}.to`),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=AffectedConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AffectedConfig.js","sourceRoot":"","sources":["../../src/affected/AffectedConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAoDnG;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAY;IACjD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,mBAAmB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAClF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAC9C,MAAM,MAAM,GAAmB;QAC3B,YAAY,EAAE,CAAC,MAAM,CAAC;QACtB,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,eAAe,EAAE,EAAE;QACnB,MAAM,EAAE,EAAE;KACb,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAA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AO;QACH,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC;QACnD,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,IAAI,WAAW,CAAC;KACjE,CAAC;AACN,CAAC;AAED,sCAAsC;AACtC,SAAS,YAAY,CAAC,KAAc,EAAE,IAAY;IAC9C,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,OAAO;QACH,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,OAAO,CAAC;QAC7C,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,IAAI,KAAK,CAAC;KAC1C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test';
|
|
2
|
+
import { parseAffectedConfig } from './AffectedConfig.js';
|
|
3
|
+
test('a missing config is the defaults', () => {
|
|
4
|
+
const expected = {
|
|
5
|
+
baseBranches: ['main'],
|
|
6
|
+
aliases: [],
|
|
7
|
+
rewrites: [],
|
|
8
|
+
fullRunTriggers: [],
|
|
9
|
+
ignore: [],
|
|
10
|
+
};
|
|
11
|
+
expect(parseAffectedConfig(undefined)).toEqual(expected);
|
|
12
|
+
});
|
|
13
|
+
test('parses a full config, keeping the defaults for absent fields', () => {
|
|
14
|
+
const full = {
|
|
15
|
+
baseBranches: ['main', 'release'],
|
|
16
|
+
aliases: [{ prefix: '@/', packages: ['@acme/app'] }],
|
|
17
|
+
rewrites: [{ from: '.loc.yaml', to: '.loc.ts' }],
|
|
18
|
+
fullRunTriggers: ['bun.lock'],
|
|
19
|
+
ignore: ['**/*.md'],
|
|
20
|
+
};
|
|
21
|
+
expect(parseAffectedConfig(full)).toEqual(full);
|
|
22
|
+
const expected = {
|
|
23
|
+
baseBranches: ['main'],
|
|
24
|
+
aliases: [],
|
|
25
|
+
rewrites: [],
|
|
26
|
+
fullRunTriggers: [],
|
|
27
|
+
ignore: ['docs/**'],
|
|
28
|
+
};
|
|
29
|
+
expect(parseAffectedConfig({ ignore: ['docs/**'] })).toEqual(expected);
|
|
30
|
+
});
|
|
31
|
+
test('a malformed config throws, naming the offending path', () => {
|
|
32
|
+
const cases = [
|
|
33
|
+
['main', '`nzyme.affected` must be an object'],
|
|
34
|
+
[{ baseBranches: 'main' }, '`nzyme.affected.baseBranches` must be an array of strings'],
|
|
35
|
+
[{ baseBranches: [] }, '`nzyme.affected.baseBranches` must be a non-empty array'],
|
|
36
|
+
[
|
|
37
|
+
{ aliases: [{ prefix: '@/', packages: [1] }] },
|
|
38
|
+
'`nzyme.affected.aliases[0].packages[0]` must be a non-empty string',
|
|
39
|
+
],
|
|
40
|
+
[{ rewrites: [{ from: '.a' }] }, '`nzyme.affected.rewrites[0].to` must be a non-empty string'],
|
|
41
|
+
[{ rewrites: {} }, '`nzyme.affected.rewrites` must be an array'],
|
|
42
|
+
[{ ignore: ['ok', ''] }, '`nzyme.affected.ignore[1]` must be a non-empty string'],
|
|
43
|
+
];
|
|
44
|
+
for (const [value, message] of cases) {
|
|
45
|
+
expect(() => parseAffectedConfig(value)).toThrow(message);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=AffectedConfig.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AffectedConfig.test.js","sourceRoot":"","sources":["../../src/affected/AffectedConfig.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAC1C,MAAM,QAAQ,GAAmB;QAC7B,YAAY,EAAE,CAAC,MAAM,CAAC;Q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AAE,EAAE,yDAAyD,CAAC;QACjF;YACI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;YAC9C,oEAAoE;SACvE;QACD,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,4DAA4D,CAAC;QAC9F,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,4CAA4C,CAAC;QAChE,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,uDAAuD,CAAC;KACpF,CAAC;IAEF,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { afterEach, expect, setDefaultTimeout, test } from 'bun:test';
|
|
6
|
+
import { collectChangedFiles } from './collectChangedFiles.js';
|
|
7
|
+
// Every test builds real git repositories.
|
|
8
|
+
setDefaultTimeout(60_000);
|
|
9
|
+
const GIT_CONFIG = [
|
|
10
|
+
'-c',
|
|
11
|
+
'user.name=nzyme test',
|
|
12
|
+
'-c',
|
|
13
|
+
'user.email=test@nzyme.invalid',
|
|
14
|
+
'-c',
|
|
15
|
+
'commit.gpgsign=false',
|
|
16
|
+
'-c',
|
|
17
|
+
'init.defaultBranch=main',
|
|
18
|
+
'-c',
|
|
19
|
+
'protocol.file.allow=always',
|
|
20
|
+
];
|
|
21
|
+
const HERMETIC_GIT_ENV = { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
|
|
22
|
+
const tmpDirs = [];
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
await Promise.all(tmpDirs.splice(0).map(dir => fs.rm(dir, { recursive: true, force: true })));
|
|
25
|
+
});
|
|
26
|
+
function git(cwd, ...args) {
|
|
27
|
+
return execFileSync('git', [...GIT_CONFIG, ...args], { cwd, env: HERMETIC_GIT_ENV, encoding: 'utf8' }).trim();
|
|
28
|
+
}
|
|
29
|
+
async function write(repo, file, content = file) {
|
|
30
|
+
await fs.mkdir(path.dirname(path.join(repo, file)), { recursive: true });
|
|
31
|
+
await fs.writeFile(path.join(repo, file), content);
|
|
32
|
+
}
|
|
33
|
+
const DEFAULT_FILES = { 'README.md': 'readme' };
|
|
34
|
+
async function createRepo(files) {
|
|
35
|
+
const dir = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'nzyme-affected-')));
|
|
36
|
+
tmpDirs.push(dir);
|
|
37
|
+
git(dir, 'init', '-q');
|
|
38
|
+
for (const [file, content] of Object.entries(files ?? DEFAULT_FILES)) {
|
|
39
|
+
await write(dir, file, content);
|
|
40
|
+
}
|
|
41
|
+
git(dir, 'add', '-A');
|
|
42
|
+
git(dir, 'commit', '-q', '-m', 'initial');
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
function commitFile(repo, file, message = file) {
|
|
46
|
+
git(repo, 'add', '-A');
|
|
47
|
+
git(repo, 'commit', '-q', '-m', message);
|
|
48
|
+
return git(repo, 'rev-parse', 'HEAD');
|
|
49
|
+
}
|
|
50
|
+
test('collects modified, added, staged, deleted, renamed and untracked files against the merge-base', async () => {
|
|
51
|
+
const repo = await createRepo({
|
|
52
|
+
'a.ts': 'a',
|
|
53
|
+
'modified.ts': 'm',
|
|
54
|
+
'deleted.ts': 'd',
|
|
55
|
+
'renamed-old.ts': 'a rather long body so that git detects the rename '.repeat(5),
|
|
56
|
+
'unstaged.ts': 'u',
|
|
57
|
+
'dir/ignored-by-gitignore.log': 'x',
|
|
58
|
+
'.gitignore': '*.log\n',
|
|
59
|
+
});
|
|
60
|
+
const base = git(repo, 'rev-parse', 'HEAD');
|
|
61
|
+
await write(repo, 'modified.ts', 'changed');
|
|
62
|
+
await write(repo, 'committed-new.ts');
|
|
63
|
+
commitFile(repo, 'x');
|
|
64
|
+
await fs.rm(path.join(repo, 'deleted.ts'));
|
|
65
|
+
git(repo, 'mv', 'renamed-old.ts', 'renamed-new.ts');
|
|
66
|
+
await write(repo, 'staged.ts');
|
|
67
|
+
git(repo, 'add', 'staged.ts');
|
|
68
|
+
await write(repo, 'unstaged.ts', 'edited');
|
|
69
|
+
await write(repo, 'sub dir/untracked.ts');
|
|
70
|
+
await write(repo, 'ignored.log');
|
|
71
|
+
expect(await collectChangedFiles({ root: repo, mergeBase: base })).toEqual([
|
|
72
|
+
{ path: 'committed-new.ts', deleted: false },
|
|
73
|
+
{ path: 'deleted.ts', deleted: true },
|
|
74
|
+
{ path: 'modified.ts', deleted: false },
|
|
75
|
+
{ path: 'renamed-new.ts', deleted: false },
|
|
76
|
+
{ path: 'renamed-old.ts', deleted: true },
|
|
77
|
+
{ path: 'staged.ts', deleted: false },
|
|
78
|
+
{ path: 'sub dir/untracked.ts', deleted: false },
|
|
79
|
+
{ path: 'unstaged.ts', deleted: false },
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
test('a commit that is part of the base is not listed', async () => {
|
|
83
|
+
const repo = await createRepo();
|
|
84
|
+
await write(repo, 'before.ts');
|
|
85
|
+
const base = commitFile(repo, 'before');
|
|
86
|
+
expect(await collectChangedFiles({ root: repo, mergeBase: base })).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
async function createRepoWithSubmodule() {
|
|
89
|
+
const upstream = await createRepo({ 'lib.ts': 'lib', 'old.ts': 'old' });
|
|
90
|
+
const repo = await createRepo({ 'app.ts': 'app' });
|
|
91
|
+
git(repo, 'submodule', 'add', '-q', upstream, 'libs/sub');
|
|
92
|
+
commitFile(repo, 'add submodule');
|
|
93
|
+
return { repo, upstream };
|
|
94
|
+
}
|
|
95
|
+
test('submodule changes are diffed against the gitlink of the base, with the path prefixed', async () => {
|
|
96
|
+
const { repo } = await createRepoWithSubmodule();
|
|
97
|
+
const base = git(repo, 'rev-parse', 'HEAD');
|
|
98
|
+
const sub = path.join(repo, 'libs/sub');
|
|
99
|
+
await write(sub, 'lib.ts', 'changed');
|
|
100
|
+
await write(sub, 'added.ts');
|
|
101
|
+
await fs.rm(path.join(sub, 'old.ts'));
|
|
102
|
+
git(sub, 'add', '-A');
|
|
103
|
+
git(sub, 'commit', '-q', '-m', 'sub change');
|
|
104
|
+
await write(sub, 'untracked.ts');
|
|
105
|
+
git(repo, 'add', 'libs/sub');
|
|
106
|
+
await write(repo, 'app.ts', 'changed');
|
|
107
|
+
expect(await collectChangedFiles({ root: repo, mergeBase: base })).toEqual([
|
|
108
|
+
{ path: 'app.ts', deleted: false },
|
|
109
|
+
{ path: 'libs/sub/added.ts', deleted: false },
|
|
110
|
+
{ path: 'libs/sub/lib.ts', deleted: false },
|
|
111
|
+
{ path: 'libs/sub/old.ts', deleted: true },
|
|
112
|
+
{ path: 'libs/sub/untracked.ts', deleted: false },
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
test('a submodule change already recorded in the base is not listed', async () => {
|
|
116
|
+
const { repo } = await createRepoWithSubmodule();
|
|
117
|
+
const sub = path.join(repo, 'libs/sub');
|
|
118
|
+
await write(sub, 'lib.ts', 'changed');
|
|
119
|
+
git(sub, 'add', '-A');
|
|
120
|
+
git(sub, 'commit', '-q', '-m', 'sub change');
|
|
121
|
+
const base = commitFile(repo, 'bump submodule');
|
|
122
|
+
expect(await collectChangedFiles({ root: repo, mergeBase: base })).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
test('a submodule that did not exist in the base counts as entirely new', async () => {
|
|
125
|
+
const repo = await createRepo({ 'app.ts': 'app' });
|
|
126
|
+
const base = git(repo, 'rev-parse', 'HEAD');
|
|
127
|
+
const upstream = await createRepo({ 'lib.ts': 'lib' });
|
|
128
|
+
git(repo, 'submodule', 'add', '-q', upstream, 'libs/sub');
|
|
129
|
+
commitFile(repo, 'add submodule');
|
|
130
|
+
const files = await collectChangedFiles({ root: repo, mergeBase: base });
|
|
131
|
+
expect(files.map(file => file.path)).toEqual(['.gitmodules', 'libs/sub/lib.ts']);
|
|
132
|
+
});
|
|
133
|
+
test('an uninitialised submodule is skipped, unless its commit changed since the base', async () => {
|
|
134
|
+
const { repo, upstream } = await createRepoWithSubmodule();
|
|
135
|
+
const base = git(repo, 'rev-parse', 'HEAD');
|
|
136
|
+
const clone = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'nzyme-affected-clone-')));
|
|
137
|
+
tmpDirs.push(clone);
|
|
138
|
+
git(clone, 'clone', '-q', repo, 'work');
|
|
139
|
+
const work = path.join(clone, 'work');
|
|
140
|
+
// Not initialised (empty dir), gitlink unchanged: nothing to report, and no leak from the parent repo.
|
|
141
|
+
await write(work, 'app.ts', 'changed');
|
|
142
|
+
expect(await collectChangedFiles({ root: work, mergeBase: base })).toEqual([{ path: 'app.ts', deleted: false }]);
|
|
143
|
+
// Gitlink moved while the checkout is missing: the change is invisible, so refuse.
|
|
144
|
+
await write(upstream, 'lib.ts', 'newer');
|
|
145
|
+
const newer = commitFile(upstream, 'newer');
|
|
146
|
+
git(work, 'update-index', '--cacheinfo', `160000,${newer},libs/sub`);
|
|
147
|
+
git(work, 'commit', '-q', '-m', 'bump');
|
|
148
|
+
await expect(collectChangedFiles({ root: work, mergeBase: base })).rejects.toThrow(/not checked out/);
|
|
149
|
+
});
|
|
150
|
+
test('an unknown merge-base throws instead of returning an empty list', async () => {
|
|
151
|
+
const repo = await createRepo();
|
|
152
|
+
await expect(collectChangedFiles({ root: repo, mergeBase: 'deadbeef' })).rejects.toThrow();
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=affected.test.js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AAM,mBAAmB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAEjH,mFAAmF;IACnF,MAAM,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,KAAK,WAAW,CAAC,CAAC;IACrE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,MAAM,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC1G,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;IAC/E,MAAM,IAAI,GAAG,MAAM,UAAU,EAAE,CAAC;IAChC,MAAM,MAAM,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAC/F,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A file that differs from the base. Deleted files (and the old path of a rename) are included. */
|
|
2
|
+
export interface ChangedFile {
|
|
3
|
+
/** Root-relative, `/`-separated. */
|
|
4
|
+
path: string;
|
|
5
|
+
/** True when the file no longer exists in the working tree. */
|
|
6
|
+
deleted: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface CollectChangedFilesOptions {
|
|
9
|
+
/** Top of the git working tree. */
|
|
10
|
+
root: string;
|
|
11
|
+
/** Commit to diff the working tree against (see `resolveAffectedBase`). */
|
|
12
|
+
mergeBase: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Files that differ between `mergeBase` and the working tree: commits since the base, staged,
|
|
16
|
+
* unstaged and untracked (not ignored) changes. Submodules are diffed against the gitlink the base
|
|
17
|
+
* commit recorded, with their paths prefixed by the submodule path; the gitlink itself is not listed.
|
|
18
|
+
*
|
|
19
|
+
* A submodule absent from the base counts as entirely new (all its tracked files). An uninitialised
|
|
20
|
+
* submodule has no local changes and is skipped, unless its gitlink moved between base and `HEAD` —
|
|
21
|
+
* then the change cannot be seen and this throws.
|
|
22
|
+
*
|
|
23
|
+
* Returns sorted, unique paths; a path that exists in the working tree is never reported deleted.
|
|
24
|
+
*/
|
|
25
|
+
export declare function collectChangedFiles(options: CollectChangedFilesOptions): Promise<ChangedFile[]>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { GitRepository } from '../submodule/GitRepository.js';
|
|
3
|
+
/**
|
|
4
|
+
* Files that differ between `mergeBase` and the working tree: commits since the base, staged,
|
|
5
|
+
* unstaged and untracked (not ignored) changes. Submodules are diffed against the gitlink the base
|
|
6
|
+
* commit recorded, with their paths prefixed by the submodule path; the gitlink itself is not listed.
|
|
7
|
+
*
|
|
8
|
+
* A submodule absent from the base counts as entirely new (all its tracked files). An uninitialised
|
|
9
|
+
* submodule has no local changes and is skipped, unless its gitlink moved between base and `HEAD` —
|
|
10
|
+
* then the change cannot be seen and this throws.
|
|
11
|
+
*
|
|
12
|
+
* Returns sorted, unique paths; a path that exists in the working tree is never reported deleted.
|
|
13
|
+
*/
|
|
14
|
+
export async function collectChangedFiles(options) {
|
|
15
|
+
const git = new GitRepository(options.root);
|
|
16
|
+
const submodules = await listSubmodulePaths(options.root);
|
|
17
|
+
const files = new Map();
|
|
18
|
+
function add(filePath, deleted) {
|
|
19
|
+
files.set(filePath, (files.get(filePath) ?? true) && deleted);
|
|
20
|
+
}
|
|
21
|
+
// The gitlink of a submodule shows up as a changed path in its parent; its own files stand for it.
|
|
22
|
+
for (const file of await diffRepository(git, options.mergeBase)) {
|
|
23
|
+
if (!submodules.includes(file.path)) {
|
|
24
|
+
add(file.path, file.deleted);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const submodule of submodules) {
|
|
28
|
+
const baseSha = await git.findGitlink(options.mergeBase, submodule);
|
|
29
|
+
const sub = new GitRepository(path.join(options.root, submodule));
|
|
30
|
+
if (!(await sub.isCheckedOut())) {
|
|
31
|
+
if (baseSha !== (await git.findGitlink('HEAD', submodule))) {
|
|
32
|
+
throw new Error(`Submodule "${submodule}" is not checked out but its commit changed since the base. ` +
|
|
33
|
+
'Run `git submodule update --init` first.');
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const changed = baseSha === null
|
|
38
|
+
? splitNul(await sub.git(['ls-files', '-z'])).map(filePath => ({ path: filePath, deleted: false }))
|
|
39
|
+
: await diffRepository(sub, baseSha);
|
|
40
|
+
for (const file of changed) {
|
|
41
|
+
add(`${submodule}/${file.path}`, file.deleted);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...files.entries()]
|
|
45
|
+
.map(([filePath, deleted]) => ({ path: filePath, deleted }))
|
|
46
|
+
.toSorted((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
47
|
+
}
|
|
48
|
+
/** Working tree vs `base` (renames contribute their old path as deleted) plus untracked, unignored files. */
|
|
49
|
+
async function diffRepository(git, base) {
|
|
50
|
+
const result = [];
|
|
51
|
+
const diff = splitNul(await git.git(['diff', '--name-status', '-M', '-z', base]));
|
|
52
|
+
for (let i = 0; i < diff.length;) {
|
|
53
|
+
const status = diff[i++] ?? '';
|
|
54
|
+
const first = diff[i++] ?? '';
|
|
55
|
+
if (status.startsWith('R')) {
|
|
56
|
+
result.push({ path: first, deleted: true }, { path: diff[i++] ?? '', deleted: false });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
result.push({ path: first, deleted: status.startsWith('D') });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const file of splitNul(await git.git(['ls-files', '-z', '--others', '--exclude-standard']))) {
|
|
63
|
+
result.push({ path: file, deleted: false });
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/** Submodule paths declared in the working tree's `.gitmodules`. */
|
|
68
|
+
async function listSubmodulePaths(root) {
|
|
69
|
+
const git = new GitRepository(root);
|
|
70
|
+
const result = await git.tryGit(['config', '-f', '.gitmodules', '-z', '--get-regexp', '^submodule\\..*\\.path$']);
|
|
71
|
+
if (!result.ok) {
|
|
72
|
+
// Exit 1 means "no match" (no .gitmodules or no submodules); anything else is a real failure.
|
|
73
|
+
if (result.exitCode === 1) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Cannot read .gitmodules in ${root}: ${result.stderr}`);
|
|
77
|
+
}
|
|
78
|
+
return splitNul(result.stdout).map(entry => entry.slice(entry.indexOf('\n') + 1));
|
|
79
|
+
}
|
|
80
|
+
function splitNul(output) {
|
|
81
|
+
return output.split('\0').filter(entry => entry !== '');
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=collectChangedFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectChangedFiles.js","sourceRoot":"","sources":["../../src/affected/collectChangedFiles.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAiB9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAmC;IACzE,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,MA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AAC;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc;IAC5B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AffectedRewrite } from './AffectedConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* The paths a changed file also stands for under the `rewrites` rules — one per rule whose `from`
|
|
4
|
+
* ends the path, whether or not that path exists; `[]` when no rule matches.
|
|
5
|
+
* @__NO_SIDE_EFFECTS__
|
|
6
|
+
*/
|
|
7
|
+
export declare function rewriteChangedPath(file: string, rewrites: AffectedRewrite[]): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paths a changed file also stands for under the `rewrites` rules — one per rule whose `from`
|
|
3
|
+
* ends the path, whether or not that path exists; `[]` when no rule matches.
|
|
4
|
+
* @__NO_SIDE_EFFECTS__
|
|
5
|
+
*/
|
|
6
|
+
export function rewriteChangedPath(file, rewrites) {
|
|
7
|
+
const rewritten = [];
|
|
8
|
+
for (const rewrite of rewrites) {
|
|
9
|
+
if (file.endsWith(rewrite.from)) {
|
|
10
|
+
rewritten.push(file.slice(0, -rewrite.from.length) + rewrite.to);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return rewritten;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rewriteChangedPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewriteChangedPath.js","sourceRoot":"","sources":["../../src/affected/rewriteChangedPath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,QAA2B;IACxE,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ImportGraph } from '@nzyme/project-utils/importGraph/buildImportGraph.js';
|
|
2
|
+
import type { AffectedConfig } from './AffectedConfig.js';
|
|
3
|
+
import type { ChangedFile } from './collectChangedFiles.js';
|
|
4
|
+
/** Options of {@link selectAffectedFiles}. */
|
|
5
|
+
export interface SelectAffectedFilesOptions {
|
|
6
|
+
graph: ImportGraph;
|
|
7
|
+
changedFiles: ChangedFile[];
|
|
8
|
+
config: Pick<AffectedConfig, 'rewrites' | 'fullRunTriggers' | 'ignore'>;
|
|
9
|
+
/**
|
|
10
|
+
* Selection globs (`Bun.Glob`). One without `/` matches the basename (`*.test.ts`); one with
|
|
11
|
+
* `/` matches the root-relative path (`packages/{ui,app}/**\/*.stories.tsx`).
|
|
12
|
+
*/
|
|
13
|
+
patterns: string[];
|
|
14
|
+
/** Root-relative, `/`-separated directories of the workspace packages; `''` is never one. */
|
|
15
|
+
packageDirs: string[];
|
|
16
|
+
}
|
|
17
|
+
/** What {@link selectAffectedFiles} selected, and why. */
|
|
18
|
+
export interface AffectedSelection {
|
|
19
|
+
/** Root-relative paths matching the patterns, sorted and unique; only files that exist. */
|
|
20
|
+
files: string[];
|
|
21
|
+
/** Set when a changed file matches a full-run trigger (the first in path order) or a trigger file imports it. */
|
|
22
|
+
fullRun?: AffectedFullRunReason;
|
|
23
|
+
}
|
|
24
|
+
/** The changed file that triggered a full run, and the trigger it matched. */
|
|
25
|
+
export interface AffectedFullRunReason {
|
|
26
|
+
file: string;
|
|
27
|
+
trigger: string;
|
|
28
|
+
/** The file matching `trigger` that imports `file`, transitively; unset when `file` matches it itself. */
|
|
29
|
+
via?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Picks the files matching `patterns` that a change can affect: the changed files themselves plus
|
|
33
|
+
* every file that imports one of them, transitively.
|
|
34
|
+
*
|
|
35
|
+
* Per changed file, in order:
|
|
36
|
+
* 1. matches a `fullRunTriggers` glob → every graph file matching the patterns (triggers win over `ignore`);
|
|
37
|
+
* 2. matches an `ignore` glob, or is a `.d.ts` → nothing (Bun erases types when it runs a test, so a
|
|
38
|
+
* declaration file changes no test outcome; the typecheck covers it);
|
|
39
|
+
* 3. a package's `package.json` → seeds every source file of that package (a dependency change acts on
|
|
40
|
+
* the whole package and its importers);
|
|
41
|
+
* 4. otherwise a seed; a `rewrites` rule also seeds the rewritten path.
|
|
42
|
+
*
|
|
43
|
+
* A seed of step 4 that a trigger file imports, transitively (a module the test preload or a
|
|
44
|
+
* `.storybook/preview.ts` runs), is a trigger too: it changes what every test runs in.
|
|
45
|
+
*
|
|
46
|
+
* A seed that is not a source file and that nothing imports (a fixture read through `fs`, a codegen
|
|
47
|
+
* input) seeds every file of its owning package — the deepest package directory containing it, or the
|
|
48
|
+
* files outside every package — and so their importers in other packages. A changed file that
|
|
49
|
+
* matched a rewrite rule is exempt: the rule says where its dependents are (`x.loc.yaml` → `x.loc.ts`). Deleted files seed like any other; they are never selected.
|
|
50
|
+
* @__NO_SIDE_EFFECTS__
|
|
51
|
+
*/
|
|
52
|
+
export declare function selectAffectedFiles(options: SelectAffectedFilesOptions): AffectedSelection;
|