@noldova/tools.pipelines 0.0.17 → 0.0.19

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 CHANGED
@@ -307,6 +307,27 @@ result.message; // "Looked for exact pins of @noldova/a, @noldova/b older than 0
307
307
  - It succeeds with one line for each repository, and fails, after trying every other repository, with the line of each that failed; an error in one repository, such as git failing, is that repository's line.
308
308
  - Given an output, it writes each repository's line there instead, as a success or a failure, as soon as that repository is done, so a run stopped partway still shows the repositories it finished; its result's message is then only the summary.
309
309
  - It removes its temporary folder whether it succeeds or fails, and makes it in the root its constructor is given, or in `os.tmpdir()`.
310
+ - It first checks out every repository and asks the host's `startRelockAsync` whether each relocks itself, giving the checkout's head commit and the release as a request: the source, the version, the commit, the released packages and the peers they pin; the host starts each such relock, so they run together. Then it finishes the repositories in order.
311
+ When the host answered `null`, it moves and relocks in the checkout as above.
312
+ Otherwise it reads with the host's `readRelockAsync` what the repository's relock step wrote: a repository's line, which becomes that repository's line, or the commit it ran at, the moved pins, the lock lines and the files that changed, which it writes into the checkout, each one a tracked `package.json` or `package-lock.json`, before it commits, pushes and proposes as above; a file that is neither, a relock of another commit than the checkout's, and a failure the host answers fail that repository.
313
+
314
+ ### The relock step
315
+
316
+ `relock <repository> <request> <result file> [<lock file>=<npm script>...]` runs in a dependent's own checkout, at the commit the dependents step names, after the dependent prepared it as its own build does, such as installing and building its packages.
317
+ It moves the pins and relocks as the dependents step does in its checkout, with the dependent's own npm configuration and credentials, and writes the result to the file, without committing or pushing anything.
318
+
319
+ ```ts
320
+ import { Npm, ProcessRunner, RelockStep } from "@noldova/tools.pipelines";
321
+
322
+ const processRunner = new ProcessRunner();
323
+ const step = new RelockStep(processRunner, new Npm(processRunner, process.cwd()), process.cwd());
324
+ const result = await step.runAsync(["noldova-com/example", request, "relock.json", "app/package-lock.json=lock:app"]);
325
+ result.message; // "noldova-com/example: moved 2 pins and wrote the 4 files that changed into the result."
326
+ ```
327
+
328
+ - `<repository>` is the dependent's full name, which starts each line; `<request>` is the release as the dependents step sends it.
329
+ - Each `<lock file>=<npm script>` relocks that tracked lock file with `npm run <npm script>` at the checkout's root instead, after its moved entries are removed as above and every other lock file is relocked, for a lock the repository makes its own way, such as one that takes the repository's own packages from its build; such a lock skips the stand-in archives. A script name is letters, digits and `:`, `.`, `_` and `-`; a lock file named twice, or a value without both parts, fails the step before it changes anything, and so does a wrong number of values.
330
+ - The result file holds JSON: the repository's line and whether it succeeded, when the repository is left as it is or fails, or the checkout's head commit, the moved pins, the lock lines and the text of each tracked `package.json` and `package-lock.json` that changed. A lock script for a lock file the repository doesn't track, a failed lock or script run, and an error, such as npm failing, are a failed line in the file, and a failed script's line carries its standard error, or the last 10 lines of its standard output when standard error is empty; the step itself still succeeds, so the release's dependents step reports them.
310
331
 
311
332
  ### The pins step
312
333
 
package/api/index.d.ts CHANGED
@@ -874,6 +874,37 @@ export declare interface IUpdateHost {
874
874
  */
875
875
  readReleaseNotesAsync(version: string, commit: string): Promise<string | StepResult>;
876
876
 
877
+ /**
878
+ * Starts a repository's own relock, when the host can: the relock runs the
879
+ * {@link RelockStep} in a checkout of the commit, prepared as the
880
+ * repository's own build does, while the step goes on to the next
881
+ * repository.
882
+ *
883
+ * @param repository The repository's full name.
884
+ * @param commit The commit the relock checks out.
885
+ * @param request The release, which the relock step reads.
886
+ * @returns A promise of what names the started relock, for
887
+ * {@link readRelockAsync}, `null` when the repository doesn't relock itself
888
+ * and the step relocks it in its own checkout, or a failed
889
+ * {@link StepResult} that says why the host could not start it.
890
+ */
891
+ startRelockAsync(repository: string, commit: string, request: string): Promise<string | null | StepResult>;
892
+
893
+ /**
894
+ * Waits for a relock {@link startRelockAsync} started and reads what its
895
+ * relock step wrote. The host's waits for all the relocks of one step
896
+ * share one time limit, since every relock starts before the first is
897
+ * read.
898
+ *
899
+ * @param repository The repository's full name.
900
+ * @param run What {@link startRelockAsync} answered.
901
+ * @returns A promise of the relock step's result file, which
902
+ * {@link RelockedFiles.parse} reads, or a failed {@link StepResult} that
903
+ * says why the host could not read it, such as a relock that failed or
904
+ * didn't finish within the time limit.
905
+ */
906
+ readRelockAsync(repository: string, run: string): Promise<string | StepResult>;
907
+
877
908
  /**
878
909
  * Checks out a repository's default branch into a new directory, as a git
879
910
  * clone the step can commit in.
@@ -1674,6 +1705,27 @@ export declare class Npm {
1674
1705
  */
1675
1706
  public lockAsync(directory: string, hiddenVariables?: readonly string[]): Promise<ProcessResult>;
1676
1707
 
1708
+ /**
1709
+ * Runs a script of the directory's `package.json` with `npm run <script>`,
1710
+ * as the lock refresh runs npm: through `cmd.exe` on Windows, and stopped
1711
+ * after 5 minutes elsewhere.
1712
+ *
1713
+ * @param directory The directory whose `package.json` names the script.
1714
+ * @param script The script's name, such as `lock:app`.
1715
+ * @param hiddenVariables The environment variables npm doesn't get;
1716
+ * omitted, it gets them all.
1717
+ * @returns A promise of npm's exit code and of what it wrote; a script
1718
+ * that fails still resolves. It rejects with {@link ProcessException} if
1719
+ * the program cannot start.
1720
+ * @example
1721
+ * ```ts
1722
+ * import { Npm, ProcessRunner } from "@noldova/tools.pipelines";
1723
+ *
1724
+ * (await new Npm(new ProcessRunner(), process.cwd()).runScriptAsync(process.cwd(), "lock:app")).isSuccessful; // true when the script succeeds
1725
+ * ```
1726
+ */
1727
+ public runScriptAsync(directory: string, script: string, hiddenVariables?: readonly string[]): Promise<ProcessResult>;
1728
+
1677
1729
  /**
1678
1730
  * Views a field of a package or a version as JSON with `npm view <specifier>
1679
1731
  * <field> --json --prefer-online`, run in a directory, so the registries its
@@ -2655,7 +2707,15 @@ export declare class ReproducibleStep implements IStep {
2655
2707
  * exists, it replaces it only when the branch is at a commit of its own, made
2656
2708
  * by the same committer with its title, and otherwise fails that repository,
2657
2709
  * so nobody's commits are lost. A repository that pins none of them is left
2658
- * as it is.
2710
+ * as it is. It first checks out every repository and asks
2711
+ * {@link IUpdateHost.startRelockAsync} whether each relocks itself, starting
2712
+ * every such relock, and then finishes the repositories in order; for one
2713
+ * that relocks itself, it reads with {@link IUpdateHost.readRelockAsync} the
2714
+ * line the repository's {@link RelockStep} wrote, or the files it changed,
2715
+ * which it writes into its checkout, each a tracked `package.json` or
2716
+ * `package-lock.json`, and commits, pushes and proposes them as above; any
2717
+ * other file, and a relock of a commit other than the one it checked out,
2718
+ * fails that repository.
2659
2719
  */
2660
2720
  export declare class DependentsStep implements IStep {
2661
2721
  /**
@@ -2724,6 +2784,138 @@ export declare class DependentsStep implements IStep {
2724
2784
  public runAsync(values: readonly string[]): Promise<StepResult>;
2725
2785
  }
2726
2786
 
2787
+ /**
2788
+ * What a repository's own relock wrote: the commit it ran at, the moved pins, a line for each
2789
+ * relocked lock file, and the text of each tracked `package.json` and
2790
+ * `package-lock.json` that changed.
2791
+ */
2792
+ export declare class RelockedFiles {
2793
+ /**
2794
+ * The full id of the commit the relock ran at.
2795
+ */
2796
+ public readonly commit: string;
2797
+
2798
+ /**
2799
+ * The moved pins, each as the proposal's description lists it.
2800
+ */
2801
+ public readonly moves: readonly string[];
2802
+
2803
+ /**
2804
+ * A line for each relocked lock file, saying how it was relocked.
2805
+ */
2806
+ public readonly lockLines: readonly string[];
2807
+
2808
+ /**
2809
+ * The text of each file that changed, by its path in the repository.
2810
+ */
2811
+ public readonly files: Readonly<Record<string, string>>;
2812
+
2813
+ /**
2814
+ * Creates the result.
2815
+ *
2816
+ * @param commit The commit the relock ran at.
2817
+ * @param moves The moved pins.
2818
+ * @param lockLines The lock files' lines.
2819
+ * @param files The changed files' text, by path.
2820
+ */
2821
+ public constructor(commit: string, moves: readonly string[], lockLines: readonly string[], files: Readonly<Record<string, string>>);
2822
+
2823
+ /**
2824
+ * Writes a result, or a repository's line, as the JSON the relock step's
2825
+ * result file holds.
2826
+ *
2827
+ * @param relocked The result, or the line as a {@link StepResult}.
2828
+ * @returns The JSON.
2829
+ * @example
2830
+ * ```ts
2831
+ * import { RelockedFiles, StepResult } from "@noldova/tools.pipelines";
2832
+ *
2833
+ * RelockedFiles.format(StepResult.succeeded("noldova-com/example: pins none of them below 0.0.4."));
2834
+ * // {"isSuccessful":true,"message":"noldova-com/example: pins none of them below 0.0.4."}
2835
+ * ```
2836
+ */
2837
+ public static format(relocked: StepResult | RelockedFiles): string;
2838
+
2839
+ /**
2840
+ * Reads what {@link format} wrote.
2841
+ *
2842
+ * @param text The JSON.
2843
+ * @returns The result, or the repository's line as a {@link StepResult}
2844
+ * that succeeded or failed as it did. It throws when the text isn't such
2845
+ * JSON.
2846
+ */
2847
+ public static parse(text: string): StepResult | RelockedFiles;
2848
+ }
2849
+
2850
+ /**
2851
+ * The step a repository runs to relock itself for a release:
2852
+ * `relock <repository> <request> <result file> [<lock file>=<npm script>...]`.
2853
+ * Run in the repository's own checkout, prepared as its own build does, it
2854
+ * moves the pins and relocks as the {@link DependentsStep} does in its
2855
+ * checkout, with the repository's own npm configuration and credentials,
2856
+ * and writes the result file, which {@link RelockedFiles.parse} reads,
2857
+ * without committing or pushing. Each `<lock file>=<npm script>` relocks
2858
+ * that tracked lock file with {@link Npm.runScriptAsync} at the checkout's
2859
+ * root instead, after its moved entries are removed and every other lock
2860
+ * file is relocked, and without stand-in archives, for a lock the
2861
+ * repository makes its own way. A script that fails is reported with its
2862
+ * standard error, or the last 10 lines of its standard output when
2863
+ * standard error is empty.
2864
+ */
2865
+ export declare class RelockStep implements IStep {
2866
+ /**
2867
+ * The step's name, `"relock"`.
2868
+ */
2869
+ public readonly name: string;
2870
+
2871
+ /**
2872
+ * The values the step takes,
2873
+ * `"<repository> <request> <result file> [<lock file>=<npm script>...]"`.
2874
+ */
2875
+ public readonly usage: string;
2876
+
2877
+ /**
2878
+ * Creates the step.
2879
+ *
2880
+ * @param processRunner What runs git in the checkout.
2881
+ * @param npm What views packages, refreshes the lock files and runs the
2882
+ * lock scripts.
2883
+ * @param workingDirectory The checkout, which the result file's path is
2884
+ * relative to.
2885
+ * @example
2886
+ * ```ts
2887
+ * import { Npm, ProcessRunner, RelockStep } from "@noldova/tools.pipelines";
2888
+ *
2889
+ * const processRunner = new ProcessRunner();
2890
+ * const step = new RelockStep(processRunner, new Npm(processRunner, process.cwd()), process.cwd());
2891
+ * step.name; // "relock"
2892
+ * ```
2893
+ */
2894
+ public constructor(processRunner: ProcessRunner, npm: Npm, workingDirectory: string);
2895
+
2896
+ /**
2897
+ * Relocks the checkout and writes the result file.
2898
+ *
2899
+ * @param values The repository's full name, the release as the
2900
+ * {@link DependentsStep} sends it, the result file's path, and any lock
2901
+ * scripts.
2902
+ * @returns A promise of the result, which says how many pins moved and
2903
+ * files changed, or holds the repository's line. It fails, writing
2904
+ * nothing, for fewer than three values and for a lock script that isn't
2905
+ * `<lock file>=<npm script>`, with a script name of letters, digits and
2906
+ * `:`, `.`, `_` and `-`, or names a lock file twice; a lock script for an
2907
+ * untracked lock file, a failed relock and an error, such as npm failing,
2908
+ * are a failed line in the file, and the step succeeds. It throws when
2909
+ * the request isn't the release's JSON.
2910
+ * @example
2911
+ * ```ts
2912
+ * (await step.runAsync(["noldova-com/example", request, "relock.json", "app/package-lock.json=lock:app"])).message;
2913
+ * // noldova-com/example: moved 2 pins and wrote the 4 files that changed into the result.
2914
+ * ```
2915
+ */
2916
+ public runAsync(values: readonly string[]): Promise<StepResult>;
2917
+ }
2918
+
2727
2919
  /**
2728
2920
  * The step that moves the repositories that pin a shared repository's
2729
2921
  * workflows: `pins <version> <commit>`. Run from a clone of the shared
package/api/index.js CHANGED
@@ -14,6 +14,7 @@ export { BuildConfig } from "../models/build-config.js";
14
14
  export { BuildPackage } from "../models/build-package.js";
15
15
  export { PackageArchive } from "../models/package-archive.js";
16
16
  export { ProcessResult } from "../models/process-result.js";
17
+ export { RelockedFiles } from "../models/relocked-files.js";
17
18
  export { StepResult } from "../models/step-result.js";
18
19
  export { TrackedFile } from "../models/tracked-file.js";
19
20
  export { Version } from "../models/version.js";
@@ -30,6 +31,7 @@ export { PinsStep } from "../services/pins-step.js";
30
31
  export { ProcessRunner } from "../services/process-runner.js";
31
32
  export { PruneStep } from "../services/prune-step.js";
32
33
  export { PublishStep } from "../services/publish-step.js";
34
+ export { RelockStep } from "../services/relock-step.js";
33
35
  export { ReproducibleStep } from "../services/reproducible-step.js";
34
36
  export { SourceStep } from "../services/source-step.js";
35
37
  export { TagStep } from "../services/tag-step.js";
package/api/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAMtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,aAAa,E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,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
@@ -5,6 +5,8 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import { JsonReader } from "@noldova/context.json";
9
+ import { Resources } from "../resources.js";
8
10
  export class DependentsUpdate {
9
11
  source;
10
12
  version;
@@ -20,5 +22,23 @@ export class DependentsUpdate {
20
22
  this.peerPins = peerPins;
21
23
  this.notes = notes;
22
24
  }
25
+ static parseRequest(text) {
26
+ const reader = JsonReader.parse(text);
27
+ const peerPins = reader.readObjectArray(Resources.relockPeerPinsField).map(t => ({
28
+ packageName: t.readString(Resources.relockPackageNameField),
29
+ version: t.readString(Resources.relockVersionField),
30
+ reason: t.readNullableString(Resources.relockReasonField)
31
+ }));
32
+ return new DependentsUpdate(reader.readString(Resources.relockSourceField), reader.readString(Resources.relockVersionField), reader.readString(Resources.relockCommitField), reader.readStringArray(Resources.relockPackageNamesField), peerPins, "");
33
+ }
34
+ formatRequest() {
35
+ return JSON.stringify({
36
+ [Resources.relockSourceField]: this.source,
37
+ [Resources.relockVersionField]: this.version,
38
+ [Resources.relockCommitField]: this.commit,
39
+ [Resources.relockPackageNamesField]: this.packageNames,
40
+ [Resources.relockPeerPinsField]: this.peerPins.map(t => ({ [Resources.relockPackageNameField]: t.packageName, [Resources.relockVersionField]: t.version, [Resources.relockReasonField]: t.reason }))
41
+ });
42
+ }
23
43
  }
24
44
  //# sourceMappingURL=dependents-update.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dependents-update.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines/src/models/dependents-update.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,MAAM,OAAO,gBAAgB;IACX,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,YAAY,CAAoB;IAChC,QAAQ,CAAuB;IAC/B,KAAK,CAAS;IAE9B,YAAmB,MAAc,EAAE,OAAe,EAAE,MAAc,EAAE,YAA+B,EAAE,QAA8B,EAAE,KAAa;QAChJ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
1
+ {"version":3,"file":"dependents-update.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines/src/models/dependents-update.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,gBAAgB;IACX,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,YAAY,CAAoB;IAChC,QAAQ,CAAuB;IAC/B,KAAK,CAAS;IAE9B,YAAmB,MAAc,EAAE,OAAe,EAAE,MAAc,EAAE,YAA+B,EAAE,QAA8B,EAAE,KAAa;QAChJ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,YAAY,CA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S,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;SACrM,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { JsonReader } from "@noldova/context.json";
9
+ import { Resources } from "../resources.js";
10
+ import { StepResult } from "./step-result.js";
11
+ export class RelockedFiles {
12
+ commit;
13
+ moves;
14
+ lockLines;
15
+ files;
16
+ constructor(commit, moves, lockLines, files) {
17
+ this.commit = commit;
18
+ this.moves = moves;
19
+ this.lockLines = lockLines;
20
+ this.files = files;
21
+ }
22
+ static format(relocked) {
23
+ return JSON.stringify(relocked instanceof StepResult
24
+ ? { [Resources.relockSucceededField]: relocked.isSuccessful, [Resources.relockMessageField]: relocked.message }
25
+ : { [Resources.relockCommitField]: relocked.commit, [Resources.relockMovesField]: relocked.moves, [Resources.relockLockLinesField]: relocked.lockLines, [Resources.relockFilesField]: relocked.files });
26
+ }
27
+ static parse(text) {
28
+ const reader = JsonReader.parse(text);
29
+ if (reader.hasField(Resources.relockMessageField)) {
30
+ const message = reader.readString(Resources.relockMessageField);
31
+ return reader.readBoolean(Resources.relockSucceededField) ? StepResult.succeeded(message) : StepResult.failed(message);
32
+ }
33
+ const files = reader.readObject(Resources.relockFilesField);
34
+ return new RelockedFiles(reader.readString(Resources.relockCommitField), reader.readStringArray(Resources.relockMovesField), reader.readStringArray(Resources.relockLockLinesField), Object.fromEntries(Object.keys(files.toJson()).map(t => [t, files.readString(t)])));
35
+ }
36
+ }
37
+ //# sourceMappingURL=relocked-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relocked-files.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines/src/models/relocked-files.ts"],"names":[],"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AC,EAAE,CAAC;YAClD,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;YAEhE,OAAO,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzH,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAE5D,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,oBAAoB,CAAC,EACjL,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/tools.pipelines",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "type": "module",
5
5
  "main": "api/index.js",
6
6
  "types": "api/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "registry": "https://registry.npmjs.org/"
20
20
  },
21
21
  "dependencies": {
22
- "@noldova/context.exceptions": "0.0.5",
23
- "@noldova/context.json": "0.0.5"
22
+ "@noldova/context.exceptions": "0.0.6",
23
+ "@noldova/context.json": "0.0.6"
24
24
  },
25
- "gitHead": "d7accf5c52529a89729fe3f5faaa3727da153457"
25
+ "gitHead": "571d5f4e0c949a3eb2b68c1983cb104d5903342a"
26
26
  }
package/resources.js CHANGED
@@ -28,6 +28,23 @@ export class Resources {
28
28
  static dependentsFolderPrefix = "pipelines-dependents-";
29
29
  static dependentsStepName = "dependents";
30
30
  static dependentsStepUsage = "<version> <commit>";
31
+ static lockScriptPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]*$/;
32
+ static lockScriptSeparator = "=";
33
+ static npmScriptValues = ["run"];
34
+ static relockCommitField = "commit";
35
+ static relockFilesField = "files";
36
+ static relockLockLinesField = "lockLines";
37
+ static relockMessageField = "message";
38
+ static relockMovesField = "moves";
39
+ static relockPackageNameField = "packageName";
40
+ static relockPackageNamesField = "packageNames";
41
+ static relockPeerPinsField = "peerPins";
42
+ static relockReasonField = "reason";
43
+ static relockSourceField = "source";
44
+ static relockStepName = "relock";
45
+ static relockStepUsage = "<repository> <request> <result file> [<lock file>=<npm script>...]";
46
+ static relockSucceededField = "isSuccessful";
47
+ static relockVersionField = "version";
31
48
  static dependabotFilePaths = [".github/dependabot.yml", ".github/dependabot.yaml"];
32
49
  static failureExitCode = 1;
33
50
  static exactVersionPattern = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
@@ -82,6 +99,7 @@ export class Resources {
82
99
  static millisecondsPerSecond = 1000;
83
100
  static manifestFileName = "package.json";
84
101
  static messagePartSeparator = "; ";
102
+ static failedScriptOutputLines = 10;
85
103
  static minorPartName = "minor";
86
104
  static mixedLineEndings = "mixed";
87
105
  static nameField = "name";
@@ -566,6 +584,36 @@ export class Resources {
566
584
  static formatOwnLocked(lockFilePath, packageNames) {
567
585
  return `\`${lockFilePath}\`: the repository's own ${packageNames.map(t => `\`${t}\``).join(", ")} locked from their tracked manifests, without asking the registry; their entries left out, and the root entry keeps the folder's pins`;
568
586
  }
587
+ static formatLocked(lockFilePath) {
588
+ return `\`${lockFilePath}\`: the moved packages, the entries nested under them and the entries that depend on them resolved again with \`npm ${Resources.npmLockValues.join(Resources.valueSeparator)}\`; every other entry kept unless a resolved package needs it to change`;
589
+ }
590
+ static formatScriptLocked(lockFilePath, script) {
591
+ return `\`${lockFilePath}\`: the moved packages, the entries nested under them and the entries that depend on them resolved again with the repository's own \`npm ${Resources.npmScriptValues.join(Resources.valueSeparator)} ${script}\`, after the dependent prepared its checkout as its own build does`;
592
+ }
593
+ static formatLockScriptsUntracked(lockFilePaths) {
594
+ return `The lock scripts name lock files the repository doesn't track: ${lockFilePaths.join(", ")}.`;
595
+ }
596
+ static keepLastOutputLines(output) {
597
+ return output.split(Resources.lineBreakPattern).filter(t => t.trim().length > 0).slice(-Resources.failedScriptOutputLines).join("\n");
598
+ }
599
+ static formatLockScriptFailed(lockFilePath, script, exitCode, errorOutput) {
600
+ return Resources.formatFailureLine(`Relocking ${lockFilePath}, npm ${Resources.npmScriptValues.join(Resources.valueSeparator)} ${script}, exited with code ${exitCode}`, errorOutput);
601
+ }
602
+ static formatLockScriptInvalid(value) {
603
+ return `${value} isn't a lock script: give each tracked lock file once, as <lock file>=<npm script>, such as app/package-lock.json=lock:app, with a script name of letters, digits and : . _ -.`;
604
+ }
605
+ static formatRelockWritten(repository, moveCount, fileCount) {
606
+ return `${repository}: moved ${moveCount} pins and wrote the ${fileCount} files that changed into the result.`;
607
+ }
608
+ static formatRelockedElsewhere(relocked, head) {
609
+ return `The repository's relock ran at ${relocked}, not at ${head}, the commit the step checked out and sent, so none of its files are taken.`;
610
+ }
611
+ static formatRelockedUntracked(filePaths) {
612
+ return `The repository's relock changed files that aren't its tracked package.json or package-lock.json files, so none are taken: ${filePaths.join(", ")}.`;
613
+ }
614
+ static formatWindowsNpmScriptValues(script) {
615
+ return ["/d", "/s", "/c", `npm.cmd ${Resources.npmScriptValues.join(Resources.valueSeparator)} ${script}`];
616
+ }
569
617
  static formatTarHeaderFields(entryName, size) {
570
618
  return [
571
619
  [0, entryName],
@@ -604,15 +652,14 @@ export class Resources {
604
652
  static formatUpdateBranch(source) {
605
653
  return `pipelines/update-${source}`;
606
654
  }
607
- static formatUpdateBody(source, version, commit, moves, lockFilePaths, ownLines, notes) {
655
+ static formatUpdateBody(source, version, commit, moves, lockLines, notes) {
608
656
  return [
609
657
  "## Summary",
610
658
  "",
611
659
  `${source} released ${version} from commit ${commit}; this moves every exact pin of its packages that was older.`,
612
660
  "",
613
661
  ...moves.map(t => `- ${t}`),
614
- ...lockFilePaths.map(t => `- \`${t}\`: the moved packages, the entries nested under them and the entries that depend on them resolved again with \`npm ${Resources.npmLockValues.join(Resources.valueSeparator)}\`; every other entry kept unless a resolved package needs it to change`),
615
- ...ownLines.map(t => `- ${t}`),
662
+ ...lockLines.map(t => `- ${t}`),
616
663
  "",
617
664
  notes.length === 0 ? `The pull request that merged ${commit} has no "Release notes" section.` : notes
618
665
  ].join(Resources.lineSeparator);