depflow 3.0.0-dev.1 → 3.0.0-dev.11
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 +108 -43
- 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/CLI.d.ts +157 -0
- package/dist/cli/CLI.js +214 -0
- package/dist/cli/CLI.js.map +1 -0
- package/dist/cli/DepFLowCLI.d.ts +93 -0
- package/dist/cli/DepFLowCLI.js +413 -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 +68 -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 +50 -0
- package/dist/dependency/DepUtils.js +71 -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/dist/resolve/AliasCompiler.d.ts +45 -0
- package/dist/resolve/AliasCompiler.js +84 -0
- package/dist/resolve/AliasCompiler.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/PathResolver.d.ts +26 -9
- 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/dist/schema/Config/Builder.d.ts +496 -0
- package/dist/schema/Config/Builder.js +78 -0
- package/dist/schema/Config/Builder.js.map +1 -0
- package/dist/schema/Config/Config.d.ts +673 -0
- package/dist/schema/Config/Config.js +62 -0
- package/dist/schema/Config/Config.js.map +1 -0
- package/dist/schema/Config/Dependency.d.ts +878 -0
- package/dist/schema/Config/Dependency.js +80 -0
- package/dist/schema/Config/Dependency.js.map +1 -0
- package/dist/schema/Config/Extractor.d.ts +157 -0
- package/dist/schema/Config/Extractor.js +43 -0
- package/dist/schema/Config/Extractor.js.map +1 -0
- package/dist/schema/Config/Resolver.d.ts +87 -0
- package/dist/schema/Config/Resolver.js +43 -0
- package/dist/schema/Config/Resolver.js.map +1 -0
- package/dist/schema/Config/Transform.d.ts +90 -0
- 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/dist/schema/TSConfig.d.ts +70 -0
- package/dist/schema/TSConfig.js +39 -0
- package/dist/schema/TSConfig.js.map +1 -0
- package/dist/schema/schema.d.ts +38 -0
- package/dist/schema/schema.js +40 -0
- 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 +16 -14
- package/.gitignore +0 -7
- package/build/cli/DepFLowCLI.d.ts +0 -15
- package/build/cli/DepFLowCLI.js +0 -223
- package/build/cli/DepFLowCLI.js.map +0 -1
- package/build/cli/bin.js +0 -41
- 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 -37
- package/build/config/ImportMap.js +0 -82
- package/build/config/ImportMap.js.map +0 -1
- package/build/config/Tsconfig.d.ts +0 -57
- package/build/config/Tsconfig.js +0 -100
- package/build/config/Tsconfig.js.map +0 -1
- package/build/config/schemas.d.ts +0 -1194
- package/build/config/schemas.js +0 -66
- package/build/config/schemas.js.map +0 -1
- package/build/support/Async.d.ts +0 -22
- package/build/support/Async.js +0 -62
- package/build/support/Async.js.map +0 -1
- package/build/support/Builder/Builder.d.ts +0 -36
- package/build/support/Builder/Builder.js +0 -89
- 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/Dependency/Resolver.d.ts +0 -7
- package/build/support/Dependency/Resolver.js +0 -4
- package/build/support/Dependency/Resolver.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.d.ts +0 -25
- package/build/support/PathResolver/AliasCompiler.js +0 -39
- package/build/support/PathResolver/AliasCompiler.js.map +0 -1
- package/build/support/PathResolver/PathResolver.js +0 -104
- 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 @@
|
|
|
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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ull 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,CAAC;AAEzC,MAAM,OAAO,GAAG;IACZ;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,IAAY,EAAE,OAAwB;QAC1E,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QAC7D,MAAM,YAAY,GAAuB;YACrC,EAAE,UAAU,EAAE,KAAK,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AM,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,CAA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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,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;SACtC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACtC,CAAC;IAED,yFAAyF;IACzF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,C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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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import schema from '../schema/schema.js';
|
|
2
|
+
export declare class AliasCompiler {
|
|
3
|
+
private projectRoot;
|
|
4
|
+
/** Matches the optional wildcard suffix of an alias or target (`/*` or `/`). */
|
|
5
|
+
private static readonly WILDCARD_SUFFIX_REGEX;
|
|
6
|
+
constructor(projectRoot: string);
|
|
7
|
+
/**
|
|
8
|
+
* Compiles alias configurations from the provided config object into a structured format for path resolution.
|
|
9
|
+
* It processes both regular and wildcard aliases, resolving local paths to absolute paths based on the project root.
|
|
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.
|
|
11
|
+
* @param config - The configuration object containing dependencies with resolver entries to compile into aliases.
|
|
12
|
+
* @returns An array of compiled alias objects ready for use in path resolution.
|
|
13
|
+
*/
|
|
14
|
+
compile(config: schema.Config): AliasCompiler.CompiledAlias[];
|
|
15
|
+
/**
|
|
16
|
+
* Resolves an array of resolver entries into compiled alias objects, handling both string and object target formats.
|
|
17
|
+
* It determines if each alias is a wildcard and resolves local paths to absolute paths based on the project root.
|
|
18
|
+
* The method also extracts type and CDN targets if provided in the resolver entry.
|
|
19
|
+
* @param resolver - An array of resolver entries to process into compiled aliases.
|
|
20
|
+
* @returns An array of compiled alias objects derived from the resolver entries.
|
|
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;
|
|
35
|
+
}
|
|
36
|
+
export declare namespace AliasCompiler {
|
|
37
|
+
type Resolver = schema.Resolver;
|
|
38
|
+
type Target = Exclude<schema.Target, string>;
|
|
39
|
+
interface CompiledAlias {
|
|
40
|
+
alias: string;
|
|
41
|
+
targets: Target;
|
|
42
|
+
isWildcard: boolean;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default AliasCompiler;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
3
|
+
* @description Compiles resolver entries from the configuration into absolute compiled aliases.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
export class AliasCompiler {
|
|
8
|
+
projectRoot;
|
|
9
|
+
/** Matches the optional wildcard suffix of an alias or target (`/*` or `/`). */
|
|
10
|
+
static WILDCARD_SUFFIX_REGEX = /\/\*?$/;
|
|
11
|
+
constructor(projectRoot) {
|
|
12
|
+
this.projectRoot = projectRoot;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compiles alias configurations from the provided config object into a structured format for path resolution.
|
|
16
|
+
* It processes both regular and wildcard aliases, resolving local paths to absolute paths based on the project root.
|
|
17
|
+
* The resulting compiled aliases include information about the alias name, whether it's a wildcard, and its target paths for local and CDN usage.
|
|
18
|
+
* @param config - The configuration object containing dependencies with resolver entries to compile into aliases.
|
|
19
|
+
* @returns An array of compiled alias objects ready for use in path resolution.
|
|
20
|
+
*/
|
|
21
|
+
compile(config) {
|
|
22
|
+
const result = [];
|
|
23
|
+
const allDeps = [
|
|
24
|
+
...(config.dependencies || []),
|
|
25
|
+
...(config.npmDependencies || [])
|
|
26
|
+
];
|
|
27
|
+
const baseResolvers = config.resolver || {};
|
|
28
|
+
for (const dep of allDeps) {
|
|
29
|
+
if (typeof dep !== 'object' || !dep.resolver)
|
|
30
|
+
continue;
|
|
31
|
+
result.push(...this.resolve(dep.resolver));
|
|
32
|
+
}
|
|
33
|
+
result.push(...this.resolve(baseResolvers));
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an array of resolver entries into compiled alias objects, handling both string and object target formats.
|
|
38
|
+
* It determines if each alias is a wildcard and resolves local paths to absolute paths based on the project root.
|
|
39
|
+
* The method also extracts type and CDN targets if provided in the resolver entry.
|
|
40
|
+
* @param resolver - An array of resolver entries to process into compiled aliases.
|
|
41
|
+
* @returns An array of compiled alias objects derived from the resolver entries.
|
|
42
|
+
*/
|
|
43
|
+
resolve(resolver) {
|
|
44
|
+
const result = [];
|
|
45
|
+
for (const [crudeAlias, target] of Object.entries(resolver)) {
|
|
46
|
+
const isWildcard = AliasCompiler.isWildcard(crudeAlias);
|
|
47
|
+
const alias = AliasCompiler.removeWildcardSuffix(crudeAlias);
|
|
48
|
+
const rawLocal = typeof target === 'string' ? target : target.local;
|
|
49
|
+
const localTarget = path.isAbsolute(rawLocal)
|
|
50
|
+
? AliasCompiler.removeWildcardSuffix(rawLocal)
|
|
51
|
+
: path.resolve(this.projectRoot, AliasCompiler.removeWildcardSuffix(rawLocal));
|
|
52
|
+
let cdnTarget;
|
|
53
|
+
let typeTarget;
|
|
54
|
+
if (typeof target === 'object') {
|
|
55
|
+
if (target.type) {
|
|
56
|
+
typeTarget = AliasCompiler.removeWildcardSuffix(target.type);
|
|
57
|
+
}
|
|
58
|
+
if (target.cdn) {
|
|
59
|
+
cdnTarget = AliasCompiler.removeWildcardSuffix(target.cdn);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
result.push({ alias, isWildcard, targets: { local: localTarget, type: typeTarget, cdn: cdnTarget } });
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether an alias string carries the wildcard suffix (`/*` or `/`) that turns it into a mapping.
|
|
68
|
+
* @param alias - The alias string to check.
|
|
69
|
+
* @returns True if the alias ends with a wildcard suffix, false otherwise.
|
|
70
|
+
*/
|
|
71
|
+
static isWildcard(alias) {
|
|
72
|
+
return this.WILDCARD_SUFFIX_REGEX.test(alias);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Strips the wildcard suffix from an alias or target string, leaving its base form.
|
|
76
|
+
* @param pathStr - The string to normalize (e.g., `components/*` or `utils/`).
|
|
77
|
+
* @returns The string without its wildcard suffix (e.g., `components` or `utils`).
|
|
78
|
+
*/
|
|
79
|
+
static removeWildcardSuffix(pathStr) {
|
|
80
|
+
return pathStr.replace(this.WILDCARD_SUFFIX_REGEX, '');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export default AliasCompiler;
|
|
84
|
+
//# sourceMappingURL=Alias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AAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;CACJ;AAUD,eAAe,aAAa,CAAC"}
|
|
@@ -1,40 +1,57 @@
|
|
|
1
1
|
import { Logger } from "@netfeez/vterm";
|
|
2
|
-
import Schemas from '../../config/schemas.js';
|
|
3
2
|
import PathRewriter from './PathRewriter.js';
|
|
4
3
|
import AliasCompiler from './AliasCompiler.js';
|
|
4
|
+
import schema from '../schema/schema.js';
|
|
5
5
|
export declare class PathResolver {
|
|
6
|
-
readonly config: Schemas.Config['infer'];
|
|
7
6
|
readonly options: PathResolver.Options;
|
|
8
|
-
|
|
7
|
+
/** The extensions of the built files the resolver owns, in any mode. */
|
|
9
8
|
static readonly EXTENSIONS: string[];
|
|
10
9
|
protected readonly logger: Logger;
|
|
11
10
|
protected readonly rewriter: PathRewriter;
|
|
12
|
-
protected readonly
|
|
11
|
+
protected readonly outDir: string;
|
|
13
12
|
readonly aliases: AliasCompiler.CompiledAlias[];
|
|
14
|
-
constructor(
|
|
13
|
+
constructor(data: schema.Config, projectRoot: string, options?: PathResolver.Options);
|
|
14
|
+
/**
|
|
15
|
+
* The pattern that matches the built files the resolver owns, derived from the extensions it does.
|
|
16
|
+
* @returns The glob pattern of the files to rewrite.
|
|
17
|
+
**/
|
|
18
|
+
private static get filter();
|
|
15
19
|
/**
|
|
16
20
|
* Resolves and rewrites paths in built files based on the provided mode (local or CDN).
|
|
17
21
|
* It processes all files in the output directory, rewriting import paths according to the configured aliases.
|
|
18
|
-
* @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use.
|
|
22
|
+
* @param mode - The resolution mode ('local' or 'cdn') to determine which target paths to use.
|
|
23
|
+
* @throws { Error } When any of the files could not be rewritten, reporting all of them.
|
|
24
|
+
*
|
|
25
|
+
* @remarks A file that cannot be rewritten is not a file that was left alone: a build that reports
|
|
26
|
+
* success while some of its files still point at the source tree is a build that cannot be
|
|
27
|
+
* deployed, so the failure travels up to whoever asked for the resolution.
|
|
19
28
|
*/
|
|
20
29
|
rewritePaths(mode: PathResolver.Mode): Promise<void>;
|
|
21
30
|
/**
|
|
22
31
|
* Processes a single file, rewriting import paths based on the configured aliases and the specified mode (local or CDN).
|
|
23
32
|
* It reads the file content, applies the path rewriting logic, and writes the updated content back to the file system if any changes were made.
|
|
24
|
-
* @param file The path of the file to process.
|
|
25
|
-
* @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting.
|
|
33
|
+
* @param file - The path of the file to process.
|
|
34
|
+
* @param mode - The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting.
|
|
26
35
|
* @returns A boolean indicating whether the file was modified (true if rewritten, false if no changes were made).
|
|
36
|
+
* @throws { Error } When the file cannot be read, rewritten or written.
|
|
27
37
|
*/
|
|
28
38
|
protected processFile(file: string, mode: PathResolver.Mode): Promise<boolean>;
|
|
29
39
|
/**
|
|
30
40
|
* Watches the output directory for changes and automatically rewrites paths in modified files based on the configured aliases and specified mode (local or CDN).
|
|
31
41
|
* It sets up a file system watcher that listens for changes in the output directory, and when a relevant file is modified, it triggers the path rewriting process for that file.
|
|
32
42
|
* The method includes debouncing to prevent excessive processing during rapid file changes, ensuring efficient handling of updates while maintaining responsiveness.
|
|
33
|
-
* @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting when changes are detected.
|
|
43
|
+
* @param mode - The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting when changes are detected.
|
|
34
44
|
* @returns A promise that resolves when the watcher is set up and running, allowing the application to continue monitoring for changes indefinitely until manually stopped.
|
|
35
45
|
* @throws Will throw an error if there is an issue setting up the file system watcher or processing files, which can be caught by the caller to handle it appropriately.
|
|
36
46
|
*/
|
|
37
47
|
watch(mode: PathResolver.Mode): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Debounces a function so it only executes after the specified delay has passed since the last invocation.
|
|
50
|
+
* @param fn - The function to debounce.
|
|
51
|
+
* @param delay - The number of milliseconds to wait before executing the function.
|
|
52
|
+
* @returns A debounced version of the function that delays its execution.
|
|
53
|
+
*/
|
|
54
|
+
private static debounce;
|
|
38
55
|
}
|
|
39
56
|
export declare namespace PathResolver {
|
|
40
57
|
type Mode = 'local' | 'cdn';
|