depflow 3.0.0-dev.10 → 3.0.0-dev.12
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 +513 -117
- package/dist/builder/Builder.d.ts +279 -0
- package/dist/builder/Builder.js +391 -0
- package/dist/builder/Builder.js.map +1 -0
- package/dist/cli/Actions.d.ts +187 -0
- package/dist/cli/Actions.js +793 -0
- package/dist/cli/Actions.js.map +1 -0
- package/dist/cli/CLI.d.ts +170 -0
- package/dist/cli/CLI.js +231 -0
- package/dist/cli/CLI.js.map +1 -0
- package/dist/cli/DepflowCLI.d.ts +62 -0
- package/dist/cli/DepflowCLI.js +229 -0
- package/dist/cli/DepflowCLI.js.map +1 -0
- package/dist/cli/Flags.d.ts +106 -0
- package/dist/cli/Flags.js +125 -0
- package/dist/cli/Flags.js.map +1 -0
- package/dist/cli/bin.js +63 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/config/Config.d.ts +690 -0
- package/dist/config/Config.js +45 -0
- package/dist/config/Config.js.map +1 -0
- package/dist/config/ImportMap.d.ts +60 -0
- package/dist/config/ImportMap.js +66 -0
- package/dist/config/ImportMap.js.map +1 -0
- package/dist/config/JsonSchema.d.ts +12 -0
- package/dist/config/JsonSchema.js +26 -0
- package/dist/config/JsonSchema.js.map +1 -0
- package/dist/config/Settings.d.ts +201 -0
- package/dist/config/Settings.js +191 -0
- package/dist/config/Settings.js.map +1 -0
- package/dist/config/TSConfig.d.ts +73 -0
- package/dist/config/TSConfig.js +73 -0
- package/dist/config/TSConfig.js.map +1 -0
- package/dist/config/codecs/JsonCodec.d.ts +30 -0
- package/dist/config/codecs/JsonCodec.js +31 -0
- package/dist/config/codecs/JsonCodec.js.map +1 -0
- package/dist/config/codecs/YamlCodec.d.ts +62 -0
- package/dist/config/codecs/YamlCodec.js +89 -0
- package/dist/config/codecs/YamlCodec.js.map +1 -0
- package/dist/dependency/DepUtils.d.ts +78 -0
- package/dist/dependency/DepUtils.js +122 -0
- package/dist/dependency/DepUtils.js.map +1 -0
- package/dist/dependency/Dependency.d.ts +81 -0
- package/dist/dependency/Dependency.js +71 -0
- package/dist/dependency/Dependency.js.map +1 -0
- package/dist/dependency/Git.d.ts +75 -0
- package/dist/dependency/Git.js +97 -0
- package/dist/dependency/Git.js.map +1 -0
- package/dist/dependency/GitDependency.d.ts +30 -0
- package/dist/dependency/GitDependency.js +79 -0
- package/dist/dependency/GitDependency.js.map +1 -0
- package/dist/dependency/NpmDependency.d.ts +27 -0
- package/dist/dependency/NpmDependency.js +91 -0
- package/dist/dependency/NpmDependency.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.d.ts +18 -5
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.js +31 -9
- package/dist/resolve/AliasCompiler.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/PathResolver.d.ts +25 -8
- package/dist/resolve/PathResolver.js +133 -0
- package/dist/resolve/PathResolver.js.map +1 -0
- package/dist/resolve/PathRewriter.d.ts +24 -0
- package/{build/support/PathResolver → dist/resolve}/PathRewriter.js +21 -11
- package/dist/resolve/PathRewriter.js.map +1 -0
- package/{build → dist}/schema/Config/Builder.d.ts +114 -49
- package/dist/schema/Config/Builder.js +78 -0
- package/dist/schema/Config/Builder.js.map +1 -0
- package/{build → dist}/schema/Config/Config.d.ts +169 -78
- package/dist/schema/Config/Config.js +62 -0
- package/dist/schema/Config/Config.js.map +1 -0
- package/{build → dist}/schema/Config/Dependency.d.ts +219 -89
- package/dist/schema/Config/Dependency.js +80 -0
- package/dist/schema/Config/Dependency.js.map +1 -0
- package/{build → dist}/schema/Config/Extractor.d.ts +41 -17
- package/dist/schema/Config/Extractor.js +43 -0
- package/dist/schema/Config/Extractor.js.map +1 -0
- package/{build → dist}/schema/Config/Resolver.d.ts +25 -8
- package/dist/schema/Config/Resolver.js +43 -0
- package/dist/schema/Config/Resolver.js.map +1 -0
- package/{build → dist}/schema/Config/Transform.d.ts +22 -5
- package/dist/schema/Config/Transform.js +51 -0
- package/dist/schema/Config/Transform.js.map +1 -0
- package/dist/schema/Defaults.d.ts +20 -0
- package/dist/schema/Defaults.js +24 -0
- package/dist/schema/Defaults.js.map +1 -0
- package/dist/schema/ImportMap.d.ts +30 -0
- package/dist/schema/ImportMap.js +28 -0
- package/dist/schema/ImportMap.js.map +1 -0
- package/{build → dist}/schema/TSConfig.d.ts +23 -9
- package/dist/schema/TSConfig.js +39 -0
- package/dist/schema/TSConfig.js.map +1 -0
- package/{build → dist}/schema/schema.d.ts +11 -2
- package/{build → dist}/schema/schema.js +11 -2
- package/dist/schema/schema.js.map +1 -0
- package/dist/task/Command.d.ts +287 -0
- package/dist/task/Command.js +404 -0
- package/dist/task/Command.js.map +1 -0
- package/dist/task/Group.d.ts +15 -0
- package/dist/task/Group.js +29 -0
- package/dist/task/Group.js.map +1 -0
- package/dist/task/OutputPolicy.d.ts +262 -0
- package/dist/task/OutputPolicy.js +364 -0
- package/dist/task/OutputPolicy.js.map +1 -0
- package/dist/task/Task.d.ts +210 -0
- package/dist/task/Task.js +312 -0
- package/dist/task/Task.js.map +1 -0
- package/package.json +14 -10
- package/.gitignore +0 -7
- package/build/cli/DepFLowCLI.d.ts +0 -16
- package/build/cli/DepFLowCLI.js +0 -254
- package/build/cli/DepFLowCLI.js.map +0 -1
- package/build/cli/bin.js +0 -38
- package/build/cli/bin.js.map +0 -1
- package/build/config/Config.d.ts +0 -28
- package/build/config/Config.js +0 -46
- package/build/config/Config.js.map +0 -1
- package/build/config/ImportMap.d.ts +0 -51
- package/build/config/ImportMap.js +0 -97
- package/build/config/ImportMap.js.map +0 -1
- package/build/config/TSConfig.d.ts +0 -54
- package/build/config/TSConfig.js +0 -104
- package/build/config/TSConfig.js.map +0 -1
- package/build/schema/Config/Builder.js +0 -48
- package/build/schema/Config/Builder.js.map +0 -1
- package/build/schema/Config/Config.js +0 -20
- package/build/schema/Config/Config.js.map +0 -1
- package/build/schema/Config/Dependency.js +0 -25
- package/build/schema/Config/Dependency.js.map +0 -1
- package/build/schema/Config/Extractor.js +0 -25
- package/build/schema/Config/Extractor.js.map +0 -1
- package/build/schema/Config/Resolver.js +0 -25
- package/build/schema/Config/Resolver.js.map +0 -1
- package/build/schema/Config/Transform.js +0 -27
- package/build/schema/Config/Transform.js.map +0 -1
- package/build/schema/ImportMap.d.ts +0 -22
- package/build/schema/ImportMap.js +0 -12
- package/build/schema/ImportMap.js.map +0 -1
- package/build/schema/TSConfig.js +0 -19
- package/build/schema/TSConfig.js.map +0 -1
- package/build/schema/schema.js.map +0 -1
- package/build/support/Builder/Builder.d.ts +0 -46
- package/build/support/Builder/Builder.js +0 -116
- package/build/support/Builder/Builder.js.map +0 -1
- package/build/support/Dependency/Dependency.d.ts +0 -38
- package/build/support/Dependency/Dependency.js +0 -14
- package/build/support/Dependency/Dependency.js.map +0 -1
- package/build/support/Dependency/GitDependency.d.ts +0 -20
- package/build/support/Dependency/GitDependency.js +0 -67
- package/build/support/Dependency/GitDependency.js.map +0 -1
- package/build/support/Dependency/NpmDependency.d.ts +0 -18
- package/build/support/Dependency/NpmDependency.js +0 -65
- package/build/support/Dependency/NpmDependency.js.map +0 -1
- package/build/support/Git.d.ts +0 -53
- package/build/support/Git.js +0 -86
- package/build/support/Git.js.map +0 -1
- package/build/support/PathResolver/AliasCompiler.js.map +0 -1
- package/build/support/PathResolver/PathResolver.js +0 -105
- package/build/support/PathResolver/PathResolver.js.map +0 -1
- package/build/support/PathResolver/PathRewriter.d.ts +0 -18
- package/build/support/PathResolver/PathRewriter.js.map +0 -1
- package/build/support/PathResolver/Utils.d.ts +0 -36
- package/build/support/PathResolver/Utils.js +0 -45
- package/build/support/PathResolver/Utils.js.map +0 -1
- package/build/support/Task/Command.d.ts +0 -49
- package/build/support/Task/Command.js +0 -100
- package/build/support/Task/Command.js.map +0 -1
- package/build/support/Task/Task.d.ts +0 -84
- package/build/support/Task/Task.js +0 -145
- package/build/support/Task/Task.js.map +0 -1
- package/build/support/Utils.d.ts +0 -40
- package/build/support/Utils.js +0 -138
- package/build/support/Utils.js.map +0 -1
- package/build/support/Validator.d.ts +0 -22
- package/build/support/Validator.js +0 -28
- package/build/support/Validator.js.map +0 -1
- /package/{build → dist}/cli/bin.d.ts +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type Logger from "@netfeez/vterm";
|
|
2
|
+
import schema from "../schema/schema.js";
|
|
3
|
+
import type AliasCompiler from "../resolve/AliasCompiler.js";
|
|
4
|
+
import type OutputPolicy from "../task/OutputPolicy.js";
|
|
5
|
+
export declare abstract class Dependency {
|
|
6
|
+
readonly flowFolder: string;
|
|
7
|
+
readonly projectRoot: string;
|
|
8
|
+
/**
|
|
9
|
+
* The deadline every acquisition of a source runs under, in milliseconds. Acquisition is bounded so a
|
|
10
|
+
* repository that never answers is reported instead of waiting forever.
|
|
11
|
+
*
|
|
12
|
+
* @remarks It is not the deadline of a build step, which is the one the schema declares: a clone or an
|
|
13
|
+
* install of a large source legitimately takes longer than a build step, and cutting it at the build
|
|
14
|
+
* deadline would report a failure for work that is still on its way.
|
|
15
|
+
*/
|
|
16
|
+
static readonly ACQUISITION_TIME_MS: number;
|
|
17
|
+
protected readonly logger: Logger | null;
|
|
18
|
+
protected readonly policy: OutputPolicy | null;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly builder: schema.Builder;
|
|
21
|
+
readonly resolver: AliasCompiler.Resolver;
|
|
22
|
+
/**
|
|
23
|
+
* Creates the dependency over the two roots it works between.
|
|
24
|
+
* @param flowFolder - The flow directory (`.depflow`) every checkout of the project lives in.
|
|
25
|
+
* @param projectRoot - The root of the project the artifacts of the dependency are meant to land in.
|
|
26
|
+
* @param info - The identity, the build pipeline and the resolver entries of the dependency.
|
|
27
|
+
* @param logger - Where the acquisition and the build of the dependency report to.
|
|
28
|
+
* @param policy - How the output of the commands the dependency runs is presented. Without it the
|
|
29
|
+
* dependency falls back to its logger, which streams the live output and says nothing else about it.
|
|
30
|
+
*
|
|
31
|
+
* @remarks The two roots are not the same and are not interchangeable: the flow folder owns the working
|
|
32
|
+
* copy of a dependency, the project root owns what the project consumes. A pipeline reads from the first
|
|
33
|
+
* and deposits into the second, which is why both travel together instead of one being derived from the
|
|
34
|
+
* other.
|
|
35
|
+
*
|
|
36
|
+
* @remarks The logger and the policy are not two ways of saying the same thing. The logger carries what
|
|
37
|
+
* the dependency decides to say about itself, and it says it whatever the user asked to be shown; the
|
|
38
|
+
* policy carries what the commands printed, and how much of it is shown depends on that. A dependency
|
|
39
|
+
* built through the CLI gets both, and a dependency built from a test gets neither.
|
|
40
|
+
*/
|
|
41
|
+
constructor(flowFolder: string, projectRoot: string, info: Dependency.Info, logger?: Logger | null, policy?: OutputPolicy | null);
|
|
42
|
+
/**
|
|
43
|
+
* Resolves a folder of the dependency, relative to the flow folder, and guarantees it stays inside it.
|
|
44
|
+
* @param segments - The path of the folder inside the flow folder.
|
|
45
|
+
* @returns The normalized path of the folder.
|
|
46
|
+
* @throws { Error } When the segments escape the flow folder.
|
|
47
|
+
*
|
|
48
|
+
* @remarks A name is an identity, never a path: the schema rejects the ones that are not a single
|
|
49
|
+
* segment, and this is where the ones that reach a dependency any other way are stopped, before
|
|
50
|
+
* anything is cloned into them or removed from them.
|
|
51
|
+
*/
|
|
52
|
+
protected resolve(...segments: string[]): string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the dependency is installed, which is the folder of its files being in place.
|
|
55
|
+
* @returns A promise resolving to `true` when the files of the dependency are there.
|
|
56
|
+
*/
|
|
57
|
+
abstract isInstalled(): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Install the dependency.
|
|
60
|
+
* This method should handle the installation process, such as downloading files, setting up configurations, etc.
|
|
61
|
+
*/
|
|
62
|
+
abstract install(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Uninstall the dependency.
|
|
65
|
+
* This method should handle the uninstallation process, such as removing files, cleaning up configurations, etc.
|
|
66
|
+
*/
|
|
67
|
+
abstract uninstall(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Build the dependency.
|
|
70
|
+
* This method should handle the build process, such as compiling code, bundling files, etc.
|
|
71
|
+
*/
|
|
72
|
+
abstract build(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
export declare namespace Dependency {
|
|
75
|
+
interface Info {
|
|
76
|
+
name: string;
|
|
77
|
+
builder?: schema.Builder;
|
|
78
|
+
resolver?: AliasCompiler.Resolver;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export default Dependency;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
3
|
+
* @description Base contract for installable dependencies with their build pipeline and resolver.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Path } from "@netfeez/common-node";
|
|
7
|
+
export class Dependency {
|
|
8
|
+
flowFolder;
|
|
9
|
+
projectRoot;
|
|
10
|
+
/**
|
|
11
|
+
* The deadline every acquisition of a source runs under, in milliseconds. Acquisition is bounded so a
|
|
12
|
+
* repository that never answers is reported instead of waiting forever.
|
|
13
|
+
*
|
|
14
|
+
* @remarks It is not the deadline of a build step, which is the one the schema declares: a clone or an
|
|
15
|
+
* install of a large source legitimately takes longer than a build step, and cutting it at the build
|
|
16
|
+
* deadline would report a failure for work that is still on its way.
|
|
17
|
+
*/
|
|
18
|
+
static ACQUISITION_TIME_MS = 300000;
|
|
19
|
+
logger;
|
|
20
|
+
policy;
|
|
21
|
+
name;
|
|
22
|
+
builder;
|
|
23
|
+
resolver;
|
|
24
|
+
/**
|
|
25
|
+
* Creates the dependency over the two roots it works between.
|
|
26
|
+
* @param flowFolder - The flow directory (`.depflow`) every checkout of the project lives in.
|
|
27
|
+
* @param projectRoot - The root of the project the artifacts of the dependency are meant to land in.
|
|
28
|
+
* @param info - The identity, the build pipeline and the resolver entries of the dependency.
|
|
29
|
+
* @param logger - Where the acquisition and the build of the dependency report to.
|
|
30
|
+
* @param policy - How the output of the commands the dependency runs is presented. Without it the
|
|
31
|
+
* dependency falls back to its logger, which streams the live output and says nothing else about it.
|
|
32
|
+
*
|
|
33
|
+
* @remarks The two roots are not the same and are not interchangeable: the flow folder owns the working
|
|
34
|
+
* copy of a dependency, the project root owns what the project consumes. A pipeline reads from the first
|
|
35
|
+
* and deposits into the second, which is why both travel together instead of one being derived from the
|
|
36
|
+
* other.
|
|
37
|
+
*
|
|
38
|
+
* @remarks The logger and the policy are not two ways of saying the same thing. The logger carries what
|
|
39
|
+
* the dependency decides to say about itself, and it says it whatever the user asked to be shown; the
|
|
40
|
+
* policy carries what the commands printed, and how much of it is shown depends on that. A dependency
|
|
41
|
+
* built through the CLI gets both, and a dependency built from a test gets neither.
|
|
42
|
+
*/
|
|
43
|
+
constructor(flowFolder, projectRoot, info, logger, policy) {
|
|
44
|
+
this.flowFolder = flowFolder;
|
|
45
|
+
this.projectRoot = projectRoot;
|
|
46
|
+
this.name = info.name;
|
|
47
|
+
this.builder = info.builder || [];
|
|
48
|
+
this.resolver = info.resolver || {};
|
|
49
|
+
this.logger = logger || null;
|
|
50
|
+
this.policy = policy || null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolves a folder of the dependency, relative to the flow folder, and guarantees it stays inside it.
|
|
54
|
+
* @param segments - The path of the folder inside the flow folder.
|
|
55
|
+
* @returns The normalized path of the folder.
|
|
56
|
+
* @throws { Error } When the segments escape the flow folder.
|
|
57
|
+
*
|
|
58
|
+
* @remarks A name is an identity, never a path: the schema rejects the ones that are not a single
|
|
59
|
+
* segment, and this is where the ones that reach a dependency any other way are stopped, before
|
|
60
|
+
* anything is cloned into them or removed from them.
|
|
61
|
+
*/
|
|
62
|
+
resolve(...segments) {
|
|
63
|
+
const root = Path.normalize(this.flowFolder);
|
|
64
|
+
const folder = Path.normalize(Path.join(root, ...segments));
|
|
65
|
+
if (!Path.isInside(root, folder))
|
|
66
|
+
throw new Error(`Dependency "${this.name}" resolves outside of the flow folder: ${folder}`);
|
|
67
|
+
return folder;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export default Dependency;
|
|
71
|
+
//# sourceMappingURL=Dependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dependency.js","sourceRoot":"","sources":["../../src/dependency/Dependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAO5C,MAAM,OAAgB,UAAU;IAsCR,UAAU;IACV,WAAW;IAtC/B;;;;;;;OAOG;IACI,MAAM,CAAU,mBAAmB,GAAW,MAAM,CAAC;IAEzC,MAAM,CAAgB;IACtB,MAAM,CAAsB;IAE/B,IAAI,CAAS;IACb,OAAO,CAAiB;IACxB,QAAQ,CAAyB;IAEjD;;;;;;;;;;;;;;;;;;OAkBG;IACH,YACoB,UAAkB,EAClB,WAAmB,EACnC,IAAqB,EACrB,MAAsB,EACtB,MAA4B;0BAJZ,UAAU;2BACV,WAAW;QAK3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;IACjC,CAAC;IACD;;;;;;;;;OASG;IACO,OAAO,CAAC,GAAG,QAAkB;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,CAAC,IAAI,0CAA0C,MAAM,EAAE,CAAC,CAAC;QAC9H,OAAO,MAAM,CAAC;IAClB,CAAC;CAqBJ;AAQD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
3
|
+
* @description Runs git clone and pull operations as programs of their own, with real-time logging.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type Logger from "@netfeez/vterm";
|
|
7
|
+
import Task from "../task/Task.js";
|
|
8
|
+
import OutputPolicy from "../task/OutputPolicy.js";
|
|
9
|
+
export declare class Git {
|
|
10
|
+
/**
|
|
11
|
+
* Clones a Git repository from the specified URL to the target path, optionally checking out a
|
|
12
|
+
* specific tag after cloning.
|
|
13
|
+
* The repository, the path and the tag are passed as arguments of `git`, never as a script, so
|
|
14
|
+
* nothing in them can be reinterpreted as another command.
|
|
15
|
+
* @param repo - The URL of the Git repository to clone.
|
|
16
|
+
* @param path - The file system path where the repository should be cloned to.
|
|
17
|
+
* @param options - An object containing optional parameters for the clone operation, including:
|
|
18
|
+
* - tag: An optional Git tag to check out after cloning the repository.
|
|
19
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
20
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
21
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
22
|
+
*/
|
|
23
|
+
static clone(repo: string, path: string, options: Git.RepoOptions): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Brings an existing checkout of a repository to the revision that was asked for.
|
|
26
|
+
*
|
|
27
|
+
* The objects are fetched first, always, and then the revision is checked out: a tag is a
|
|
28
|
+
* revision, not a branch, so a checkout that already sits on one has a detached HEAD, where
|
|
29
|
+
* `git pull` has nothing to pull into and fails. Checking out the requested revision lands on the
|
|
30
|
+
* very same commit a fresh clone of that revision would.
|
|
31
|
+
* @param path - The file system path to the local Git repository to bring up to date.
|
|
32
|
+
* @param options - An object containing optional parameters for the pull operation, including:
|
|
33
|
+
* - tag: An optional Git tag to check out, or the branch to fast forward when it is absent.
|
|
34
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
35
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
36
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
37
|
+
*/
|
|
38
|
+
static pull(path: string, options: Git.RepoOptions): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Runs the instructions of a Git operation as a Task, reporting them through the policy of the run.
|
|
41
|
+
* The verdict of the task is the verdict of the operation: it is awaited, never read from an event.
|
|
42
|
+
*
|
|
43
|
+
* @remarks Without a policy the task is only streamed into the logger it was given, and nothing else
|
|
44
|
+
* is said about it: what a task reports about a command is the result of that command, and that
|
|
45
|
+
* result is presented by whoever owns the policy, never by the task itself.
|
|
46
|
+
*
|
|
47
|
+
* @param instructions - The git instructions to run.
|
|
48
|
+
* @param options - An object containing optional parameters for the operation, including:
|
|
49
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
50
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
51
|
+
* - cwd: The working directory of the task, defaulting to the process's current working directory.
|
|
52
|
+
* @returns A promise resolving once every instruction ran.
|
|
53
|
+
* @throws { Task.Failure } When any of the instructions fails.
|
|
54
|
+
*
|
|
55
|
+
* @remarks The operation is not named anywhere here. The name belonged to the diagnostic of a command,
|
|
56
|
+
* and that diagnostic is composed by the policy out of the command itself, so naming the operation
|
|
57
|
+
* here said the same thing twice, in two translations that never agreed.
|
|
58
|
+
*/
|
|
59
|
+
protected static runTask(instructions: Task.Instruction[], options: Git.ShellOptions): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export declare namespace Git {
|
|
62
|
+
interface ShellOptions {
|
|
63
|
+
cwd?: string;
|
|
64
|
+
logger?: Logger;
|
|
65
|
+
/**
|
|
66
|
+
* The policy the output of the commands of the operation is reported through. A Git operation has
|
|
67
|
+
* no step of a pipeline to be identified against, so the commands of it are reported as `C<M>`.
|
|
68
|
+
*/
|
|
69
|
+
policy?: OutputPolicy | null;
|
|
70
|
+
}
|
|
71
|
+
interface RepoOptions extends ShellOptions {
|
|
72
|
+
tag?: string;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export default Git;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Task from "../task/Task.js";
|
|
2
|
+
import Dependency from './Dependency.js';
|
|
3
|
+
export class Git {
|
|
4
|
+
/**
|
|
5
|
+
* Clones a Git repository from the specified URL to the target path, optionally checking out a
|
|
6
|
+
* specific tag after cloning.
|
|
7
|
+
* The repository, the path and the tag are passed as arguments of `git`, never as a script, so
|
|
8
|
+
* nothing in them can be reinterpreted as another command.
|
|
9
|
+
* @param repo - The URL of the Git repository to clone.
|
|
10
|
+
* @param path - The file system path where the repository should be cloned to.
|
|
11
|
+
* @param options - An object containing optional parameters for the clone operation, including:
|
|
12
|
+
* - tag: An optional Git tag to check out after cloning the repository.
|
|
13
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
14
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
15
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
16
|
+
*/
|
|
17
|
+
static async clone(repo, path, options) {
|
|
18
|
+
const { tag, logger, policy, cwd = process.cwd() } = options;
|
|
19
|
+
const instructions = [
|
|
20
|
+
{ executable: 'git', args: ['clone', repo, path], cwd }
|
|
21
|
+
];
|
|
22
|
+
if (tag)
|
|
23
|
+
instructions.push({ executable: 'git', args: ['checkout', tag], cwd: path });
|
|
24
|
+
await this.runTask(instructions, { cwd, logger, policy });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Brings an existing checkout of a repository to the revision that was asked for.
|
|
28
|
+
*
|
|
29
|
+
* The objects are fetched first, always, and then the revision is checked out: a tag is a
|
|
30
|
+
* revision, not a branch, so a checkout that already sits on one has a detached HEAD, where
|
|
31
|
+
* `git pull` has nothing to pull into and fails. Checking out the requested revision lands on the
|
|
32
|
+
* very same commit a fresh clone of that revision would.
|
|
33
|
+
* @param path - The file system path to the local Git repository to bring up to date.
|
|
34
|
+
* @param options - An object containing optional parameters for the pull operation, including:
|
|
35
|
+
* - tag: An optional Git tag to check out, or the branch to fast forward when it is absent.
|
|
36
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
37
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
38
|
+
* - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
|
|
39
|
+
*/
|
|
40
|
+
static async pull(path, options) {
|
|
41
|
+
const { tag, logger, policy } = options;
|
|
42
|
+
const instructions = [
|
|
43
|
+
{ executable: 'git', args: ['fetch', '--tags', '--force'], cwd: path }
|
|
44
|
+
];
|
|
45
|
+
instructions.push(tag
|
|
46
|
+
? { executable: 'git', args: ['checkout', tag], cwd: path }
|
|
47
|
+
: { executable: 'git', args: ['pull', '--ff-only'], cwd: path });
|
|
48
|
+
await this.runTask(instructions, { logger, policy });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the instructions of a Git operation as a Task, reporting them through the policy of the run.
|
|
52
|
+
* The verdict of the task is the verdict of the operation: it is awaited, never read from an event.
|
|
53
|
+
*
|
|
54
|
+
* @remarks Without a policy the task is only streamed into the logger it was given, and nothing else
|
|
55
|
+
* is said about it: what a task reports about a command is the result of that command, and that
|
|
56
|
+
* result is presented by whoever owns the policy, never by the task itself.
|
|
57
|
+
*
|
|
58
|
+
* @param instructions - The git instructions to run.
|
|
59
|
+
* @param options - An object containing optional parameters for the operation, including:
|
|
60
|
+
* - logger: An optional Logger instance for real-time logging of command output and errors.
|
|
61
|
+
* - policy: The policy the output of the commands is reported through, when the run asked for one.
|
|
62
|
+
* - cwd: The working directory of the task, defaulting to the process's current working directory.
|
|
63
|
+
* @returns A promise resolving once every instruction ran.
|
|
64
|
+
* @throws { Task.Failure } When any of the instructions fails.
|
|
65
|
+
*
|
|
66
|
+
* @remarks The operation is not named anywhere here. The name belonged to the diagnostic of a command,
|
|
67
|
+
* and that diagnostic is composed by the policy out of the command itself, so naming the operation
|
|
68
|
+
* here said the same thing twice, in two translations that never agreed.
|
|
69
|
+
*/
|
|
70
|
+
static async runTask(instructions, options) {
|
|
71
|
+
const { cwd = process.cwd(), logger, policy } = options;
|
|
72
|
+
const task = new Task(cwd, instructions, { maxTimeMs: Dependency.ACQUISITION_TIME_MS });
|
|
73
|
+
if (policy) {
|
|
74
|
+
const identity = { step: null };
|
|
75
|
+
task.on('line', (line, ordinal) => policy.live(identity, line, ordinal, 'stdout'));
|
|
76
|
+
task.on('err', (line, ordinal) => policy.live(identity, line, ordinal, 'stderr'));
|
|
77
|
+
task.once('finish', (data) => policy.settleTask(identity, data));
|
|
78
|
+
try {
|
|
79
|
+
await task.run();
|
|
80
|
+
}
|
|
81
|
+
catch (failure) {
|
|
82
|
+
if (failure instanceof Task.Failure)
|
|
83
|
+
policy.stepFailed(identity, failure);
|
|
84
|
+
throw failure;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (logger) {
|
|
89
|
+
task.on('line', (line) => logger.info(line));
|
|
90
|
+
task.on('err', (line) => logger.error(line));
|
|
91
|
+
}
|
|
92
|
+
await task.run();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export default Git;
|
|
97
|
+
//# sourceMappingURL=Git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Git.js","sourceRoot":"","sources":["../../src/dependency/Git.ts"],"names":[],"mappings":"AAOA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AAGnC,OAAO,UAAU,MAAM,iBAAiB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,CAAC,CAAC;gBAC1E,MAAM,OAAO,CAAC;YAClB,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,MAAM,EAAE,CAAC;gBACT,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC7C,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACjD,CAAC;YACD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;IACL,CAAC;CACJ;AAeD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Logger from "@netfeez/vterm";
|
|
2
|
+
import DepUtils from "./DepUtils.js";
|
|
3
|
+
import Dependency from './Dependency.js';
|
|
4
|
+
import type OutputPolicy from '../task/OutputPolicy.js';
|
|
5
|
+
import schema from '../schema/schema.js';
|
|
6
|
+
export declare class GitDependency extends Dependency implements GitDependency.Data {
|
|
7
|
+
readonly repo: GitDependency.repo;
|
|
8
|
+
readonly tag: string;
|
|
9
|
+
constructor(flowFolder: string, projectRoot: string, dependency: GitDependency.Data, logger?: Logger | null, policy?: OutputPolicy | null);
|
|
10
|
+
/** The folder of the checkout, the identity of the dependency inside the flow folder. **/
|
|
11
|
+
get folder(): string;
|
|
12
|
+
/** Whether the checkout of the dependency is in place. **/
|
|
13
|
+
isInstalled(): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Installs the dependency, bringing the repository in and building it.
|
|
16
|
+
*
|
|
17
|
+
* @remarks The group of the acquisition is opened only when the run decorates its output, and it is
|
|
18
|
+
* closed in a `finally` so an acquisition that throws leaves the output as closed as one that
|
|
19
|
+
* succeeded: a box left open is a box every line after it is drawn inside.
|
|
20
|
+
*/
|
|
21
|
+
install(): Promise<void>;
|
|
22
|
+
/** Removes the local clone from the flow folder, if present. **/
|
|
23
|
+
uninstall(): Promise<void>;
|
|
24
|
+
build(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare namespace GitDependency {
|
|
27
|
+
type repo = DepUtils.Repo;
|
|
28
|
+
type Data = schema.Dependency.GitDependency;
|
|
29
|
+
}
|
|
30
|
+
export default GitDependency;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
3
|
+
* @description Dependency utility.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { File } from '@netfeez/common-node';
|
|
7
|
+
import DepUtils from "./DepUtils.js";
|
|
8
|
+
import Git from "./Git.js";
|
|
9
|
+
import Group from "../task/Group.js";
|
|
10
|
+
import Dependency from './Dependency.js';
|
|
11
|
+
import Builder from '../builder/Builder.js';
|
|
12
|
+
export class GitDependency extends Dependency {
|
|
13
|
+
repo;
|
|
14
|
+
tag;
|
|
15
|
+
constructor(flowFolder, projectRoot, dependency, logger = null, policy = null) {
|
|
16
|
+
super(flowFolder, projectRoot, {
|
|
17
|
+
name: dependency.name,
|
|
18
|
+
builder: dependency.builder,
|
|
19
|
+
resolver: dependency.resolver || {}
|
|
20
|
+
}, logger, policy);
|
|
21
|
+
DepUtils.repo(dependency.repo);
|
|
22
|
+
this.repo = dependency.repo;
|
|
23
|
+
this.tag = dependency.tag;
|
|
24
|
+
}
|
|
25
|
+
/** The folder of the checkout, the identity of the dependency inside the flow folder. **/
|
|
26
|
+
get folder() { return this.resolve(this.name); }
|
|
27
|
+
/** Whether the checkout of the dependency is in place. **/
|
|
28
|
+
async isInstalled() { return File.exists(this.folder); }
|
|
29
|
+
/**
|
|
30
|
+
* Installs the dependency, bringing the repository in and building it.
|
|
31
|
+
*
|
|
32
|
+
* @remarks The group of the acquisition is opened only when the run decorates its output, and it is
|
|
33
|
+
* closed in a `finally` so an acquisition that throws leaves the output as closed as one that
|
|
34
|
+
* succeeded: a box left open is a box every line after it is drawn inside.
|
|
35
|
+
*/
|
|
36
|
+
async install() {
|
|
37
|
+
const boxed = this.policy === null || this.policy.decoration === 'on';
|
|
38
|
+
if (boxed)
|
|
39
|
+
this.logger?.group(Group.create('#00B4FF'));
|
|
40
|
+
try {
|
|
41
|
+
if (await this.isInstalled()) {
|
|
42
|
+
this.logger?.log(`&C3Repository already exists, pulling latest changes...`);
|
|
43
|
+
await Git.pull(this.folder, { tag: this.tag, logger: this.logger ?? undefined, policy: this.policy });
|
|
44
|
+
this.logger?.log(`&C2Pull completed successfully.`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.logger?.log(`&C5Cloning repository from &C6${this.repo}&C5...`);
|
|
48
|
+
await Git.clone(this.repo, this.folder, { tag: this.tag, logger: this.logger ?? undefined, policy: this.policy });
|
|
49
|
+
this.logger?.log(`&C2Clone completed successfully.`);
|
|
50
|
+
}
|
|
51
|
+
await this.build();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (boxed)
|
|
55
|
+
this.logger?.end();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Removes the local clone from the flow folder, if present. **/
|
|
59
|
+
async uninstall() {
|
|
60
|
+
if (!await this.isInstalled())
|
|
61
|
+
return void this.logger?.log(`&C4No installation found for &C6${this.name}&C4, skipping.`);
|
|
62
|
+
this.logger?.log(`&C1Removing &C6${this.name}&C1 from &C4${this.folder}&C1...`);
|
|
63
|
+
await File.remove(this.folder);
|
|
64
|
+
}
|
|
65
|
+
async build() {
|
|
66
|
+
if (this.builder.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
const builder = new Builder({
|
|
69
|
+
pipeline: this.builder,
|
|
70
|
+
cwd: this.folder,
|
|
71
|
+
projectRoot: this.projectRoot,
|
|
72
|
+
logger: this.logger,
|
|
73
|
+
policy: this.policy
|
|
74
|
+
});
|
|
75
|
+
await builder.run();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export default GitDependency;
|
|
79
|
+
//# sourceMappingURL=GitDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitDependency.js","sourceRoot":"","sources":["../../src/dependency/GitDependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAI5C,MAAM,OAAO,aAAc,SAAQ,UAAU;IACzB,IAAI,CAAqB;IACzB,GAAG,CAAS;IAE5B,YACI,UAAkB,EAClB,WAAmB,EACnB,UAA8B,EAC9B,MAAM,GAAkB,IAAI,EAC5B,MAAM,GAAwB,IAAI;QAClC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE;YAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;SACtC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACnB,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAC9B,CAAC;IACD,0FAA0F;IAC1F,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/D,2DAA2D;IACpD,KAAK,CAAC,WAAW,KAAuB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjF;;;;;;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1D,KAAK,CAAC,SAAS;QAClB,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE;YAAE,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,mCAAmC,IAAI,CAAC,IAAI,gBAAgB,CAAC,CAAC;QAC1H,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,kBAAkB,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,MAAM,QAAQ,CAAC,CAAC;QAChF,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IACM,KAAK,CAAC,KAAK;QACd,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;YACxB,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,GAAG,EAAE,IAAI,CAAC,MAAM;YAChB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;CACJ;AAOD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Logger from "@netfeez/vterm";
|
|
2
|
+
import type OutputPolicy from "../task/OutputPolicy.js";
|
|
3
|
+
import { Dependency } from "./Dependency.js";
|
|
4
|
+
import schema from "../schema/schema.js";
|
|
5
|
+
export declare class NpmDependency extends Dependency implements NpmDependency.Data {
|
|
6
|
+
version: string;
|
|
7
|
+
constructor(flowFolder: string, projectRoot: string, dependency: NpmDependency.Data, logger?: Logger | null, policy?: OutputPolicy | null);
|
|
8
|
+
/** The folder of the package, the identity of the dependency inside the flow folder. **/
|
|
9
|
+
get folder(): string;
|
|
10
|
+
/** Whether the package is installed in the flow folder. **/
|
|
11
|
+
isInstalled(): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Installs the package and builds it with the pipeline of the dependency.
|
|
14
|
+
*
|
|
15
|
+
* @remarks The group of the acquisition is opened only when the run decorates its output, and it is
|
|
16
|
+
* closed in a `finally` so an installation that throws leaves the output as closed as one that
|
|
17
|
+
* succeeded: a box left open is a box every line after it is drawn inside.
|
|
18
|
+
*/
|
|
19
|
+
install(): Promise<void>;
|
|
20
|
+
/** Removes the installed npm package folder, if present. **/
|
|
21
|
+
uninstall(): Promise<void>;
|
|
22
|
+
build(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace NpmDependency {
|
|
25
|
+
type Data = schema.Dependency.NpmDependency;
|
|
26
|
+
}
|
|
27
|
+
export default NpmDependency;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
3
|
+
* @description NPM dependency: installs a package and builds it with the configured pipeline.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { File } from "@netfeez/common-node";
|
|
7
|
+
import Builder from "../builder/Builder.js";
|
|
8
|
+
import Task from "../task/Task.js";
|
|
9
|
+
import Group from "../task/Group.js";
|
|
10
|
+
import { Dependency } from "./Dependency.js";
|
|
11
|
+
export class NpmDependency extends Dependency {
|
|
12
|
+
version;
|
|
13
|
+
constructor(flowFolder, projectRoot, dependency, logger = null, policy = null) {
|
|
14
|
+
super(flowFolder, projectRoot, {
|
|
15
|
+
name: dependency.name,
|
|
16
|
+
builder: dependency.builder,
|
|
17
|
+
resolver: dependency.resolver || {}
|
|
18
|
+
}, logger, policy);
|
|
19
|
+
this.version = dependency.version;
|
|
20
|
+
}
|
|
21
|
+
/** The folder of the package, the identity of the dependency inside the flow folder. **/
|
|
22
|
+
get folder() { return this.resolve('node_modules', this.name); }
|
|
23
|
+
/** Whether the package is installed in the flow folder. **/
|
|
24
|
+
async isInstalled() { return File.exists(this.folder); }
|
|
25
|
+
/**
|
|
26
|
+
* Installs the package and builds it with the pipeline of the dependency.
|
|
27
|
+
*
|
|
28
|
+
* @remarks The group of the acquisition is opened only when the run decorates its output, and it is
|
|
29
|
+
* closed in a `finally` so an installation that throws leaves the output as closed as one that
|
|
30
|
+
* succeeded: a box left open is a box every line after it is drawn inside.
|
|
31
|
+
*/
|
|
32
|
+
async install() {
|
|
33
|
+
const boxed = this.policy === null || this.policy.decoration === 'on';
|
|
34
|
+
if (boxed)
|
|
35
|
+
this.logger?.group(Group.create('#00B4FF'));
|
|
36
|
+
try {
|
|
37
|
+
this.logger?.log(`&C5Using npm to install &C6${this.name}&C5...`);
|
|
38
|
+
const identity = { step: null };
|
|
39
|
+
const task = new Task(this.flowFolder, [
|
|
40
|
+
{ executable: 'npm', args: ['install', `${this.name}@${this.version}`, '--prefix', './', '--no-save'], cwd: this.flowFolder }
|
|
41
|
+
], { maxTimeMs: Dependency.ACQUISITION_TIME_MS });
|
|
42
|
+
if (this.policy) {
|
|
43
|
+
task.on('line', (line, ordinal) => this.policy?.live(identity, line, ordinal, 'stdout'));
|
|
44
|
+
task.on('err', (line, ordinal) => this.policy?.live(identity, line, ordinal, 'stderr'));
|
|
45
|
+
task.once('finish', (data) => this.policy?.settleTask(identity, data));
|
|
46
|
+
try {
|
|
47
|
+
await task.run();
|
|
48
|
+
}
|
|
49
|
+
catch (failure) {
|
|
50
|
+
if (failure instanceof Task.Failure)
|
|
51
|
+
this.policy.stepFailed(identity, failure);
|
|
52
|
+
throw failure;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (this.logger) {
|
|
57
|
+
task.on('line', (line) => this.logger?.log(`&C3${line}`));
|
|
58
|
+
task.on('err', (line) => this.logger?.error(`&C1${line}`));
|
|
59
|
+
}
|
|
60
|
+
await task.run();
|
|
61
|
+
}
|
|
62
|
+
this.logger?.log(`&C2Installation of ${this.name} completed successfully.`);
|
|
63
|
+
await this.build();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (boxed)
|
|
67
|
+
this.logger?.end();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Removes the installed npm package folder, if present. **/
|
|
71
|
+
async uninstall() {
|
|
72
|
+
if (!await this.isInstalled())
|
|
73
|
+
return void this.logger?.log(`&C4No installation found for &C6${this.name}&C4, skipping.`);
|
|
74
|
+
this.logger?.log(`&C1Removing &C6${this.name}&C1 from &C4${this.folder}&C1...`);
|
|
75
|
+
await File.remove(this.folder);
|
|
76
|
+
}
|
|
77
|
+
async build() {
|
|
78
|
+
if (this.builder.length === 0)
|
|
79
|
+
return;
|
|
80
|
+
const builder = new Builder({
|
|
81
|
+
pipeline: this.builder,
|
|
82
|
+
cwd: this.folder,
|
|
83
|
+
projectRoot: this.projectRoot,
|
|
84
|
+
logger: this.logger,
|
|
85
|
+
policy: this.policy
|
|
86
|
+
});
|
|
87
|
+
await builder.run();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export default NpmDependency;
|
|
91
|
+
//# sourceMappingURL=NpmDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NpmDependency.js","sourceRoot":"","sources":["../../src/dependency/NpmDependency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,MAAM,OAAO,aAAc,SAAQ,UAAU;IAClC,OAAO,CAAS;IAEvB,YACI,UAAkB,EAClB,WAAmB,EACnB,UAA8B,EAC9B,MAAM,GAAkB,IAAI,EAC5B,MAAM,GAAwB,IAAI;QAElC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE;YAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB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MAAM,EAAE,GAAG,CAAC,sBAAsB,IAAI,CAAC,IAAI,0BAA0B,CAAC,CAAC;YAE5E,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;gBAAS,CAAC;YACP,IAAI,KAAK;gBAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAClC,CAAC;IACL,CAAC;IACD,6DAA6D;IACtD,KAAK,CAAC,SAAS;QAClB,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE;YAAE,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,mCAAmC,IAAI,CAAC,IAAI,gBAAgB,CAAC,CAAC;QAC1H,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,kBAAkB,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,MAAM,QAAQ,CAAC,CAAC;QAChF,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IACM,KAAK,CAAC,KAAK;QACd,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;YACxB,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,GAAG,EAAE,IAAI,CAAC,MAAM;YAChB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;CACJ;AAID,eAAe,aAAa,CAAC"}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import schema from '../../schema/schema.js';
|
|
1
|
+
import schema from '../schema/schema.js';
|
|
3
2
|
export declare class AliasCompiler {
|
|
4
3
|
private projectRoot;
|
|
4
|
+
/** Matches the optional wildcard suffix of an alias or target (`/*` or `/`). */
|
|
5
|
+
private static readonly WILDCARD_SUFFIX_REGEX;
|
|
5
6
|
constructor(projectRoot: string);
|
|
6
7
|
/**
|
|
7
8
|
* Compiles alias configurations from the provided config object into a structured format for path resolution.
|
|
8
9
|
* It processes both regular and wildcard aliases, resolving local paths to absolute paths based on the project root.
|
|
9
10
|
* The resulting compiled aliases include information about the alias name, whether it's a wildcard, and its target paths for local and CDN usage.
|
|
10
|
-
* @param config The configuration object containing dependencies with resolver entries to compile into aliases.
|
|
11
|
+
* @param config - The configuration object containing dependencies with resolver entries to compile into aliases.
|
|
11
12
|
* @returns An array of compiled alias objects ready for use in path resolution.
|
|
12
13
|
*/
|
|
13
|
-
compile(config:
|
|
14
|
+
compile(config: schema.Config): AliasCompiler.CompiledAlias[];
|
|
14
15
|
/**
|
|
15
16
|
* Resolves an array of resolver entries into compiled alias objects, handling both string and object target formats.
|
|
16
17
|
* It determines if each alias is a wildcard and resolves local paths to absolute paths based on the project root.
|
|
17
18
|
* The method also extracts type and CDN targets if provided in the resolver entry.
|
|
18
|
-
* @param resolver An array of resolver entries to process into compiled aliases.
|
|
19
|
+
* @param resolver - An array of resolver entries to process into compiled aliases.
|
|
19
20
|
* @returns An array of compiled alias objects derived from the resolver entries.
|
|
20
21
|
*/
|
|
21
22
|
protected resolve(resolver: AliasCompiler.Resolver): AliasCompiler.CompiledAlias[];
|
|
23
|
+
/**
|
|
24
|
+
* Checks whether an alias string carries the wildcard suffix (`/*` or `/`) that turns it into a mapping.
|
|
25
|
+
* @param alias - The alias string to check.
|
|
26
|
+
* @returns True if the alias ends with a wildcard suffix, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
private static isWildcard;
|
|
29
|
+
/**
|
|
30
|
+
* Strips the wildcard suffix from an alias or target string, leaving its base form.
|
|
31
|
+
* @param pathStr - The string to normalize (e.g., `components/*` or `utils/`).
|
|
32
|
+
* @returns The string without its wildcard suffix (e.g., `components` or `utils`).
|
|
33
|
+
*/
|
|
34
|
+
private static removeWildcardSuffix;
|
|
22
35
|
}
|
|
23
36
|
export declare namespace AliasCompiler {
|
|
24
37
|
type Resolver = schema.Resolver;
|