@virmator/core 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +5 -0
- package/dist/api/copy-configs.d.ts +22 -0
- package/dist/api/copy-configs.js +74 -0
- package/dist/api/execute-command.d.ts +60 -0
- package/dist/api/execute-command.js +269 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +5 -0
- package/dist/api/install-deps.d.ts +25 -0
- package/dist/api/install-deps.js +79 -0
- package/dist/api/parse-args.d.ts +35 -0
- package/dist/api/parse-args.js +111 -0
- package/dist/api/typescript-config-file.d.ts +30 -0
- package/dist/api/typescript-config-file.js +66 -0
- package/dist/api/virmator-flags.d.ts +21 -0
- package/dist/api/virmator-flags.js +19 -0
- package/dist/augments/fs/search.d.ts +9 -0
- package/dist/augments/fs/search.js +31 -0
- package/dist/augments/index.d.ts +4 -0
- package/dist/augments/index.js +4 -0
- package/dist/augments/object/access.d.ts +3 -0
- package/dist/augments/object/access.js +13 -0
- package/dist/augments/stream/callback-writable.d.ts +10 -0
- package/dist/augments/stream/callback-writable.js +21 -0
- package/dist/augments/tsconfig/parse-tsconfig.d.ts +3 -0
- package/dist/augments/tsconfig/parse-tsconfig.js +24 -0
- package/dist/colors.d.ts +10 -0
- package/dist/colors.js +19 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/virmator-no-trace.error.d.ts +13 -0
- package/dist/errors/virmator-no-trace.error.js +15 -0
- package/dist/file-paths.mock.d.ts +3 -0
- package/dist/file-paths.mock.js +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/plugin/index.d.ts +6 -0
- package/dist/plugin/index.js +6 -0
- package/dist/plugin/plugin-configs.d.ts +31 -0
- package/dist/plugin/plugin-configs.js +1 -0
- package/dist/plugin/plugin-env.d.ts +16 -0
- package/dist/plugin/plugin-env.js +18 -0
- package/dist/plugin/plugin-executor.d.ts +104 -0
- package/dist/plugin/plugin-executor.js +1 -0
- package/dist/plugin/plugin-init.d.ts +45 -0
- package/dist/plugin/plugin-init.js +6 -0
- package/dist/plugin/plugin-logger.d.ts +10 -0
- package/dist/plugin/plugin-logger.js +89 -0
- package/dist/plugin/plugin.d.ts +7 -0
- package/dist/plugin/plugin.js +16 -0
- package/package.json +54 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { awaitedBlockingMap, getObjectTypedEntries, isTruthy } from '@augment-vir/common';
|
|
2
|
+
import { readPackageJson, runShellCommand } from '@augment-vir/node-js';
|
|
3
|
+
import * as semver from 'semver';
|
|
4
|
+
import { VirmatorNoTraceError } from '../errors/virmator-no-trace.error';
|
|
5
|
+
import { NpmDepType } from '../plugin/plugin-init';
|
|
6
|
+
/** Install's a virmator plugin's listed npm deps depending on which command is being run. */
|
|
7
|
+
export async function installPluginNpmDeps({ usedCommands, ...params }) {
|
|
8
|
+
const deps = flattenDeps(usedCommands);
|
|
9
|
+
await installNpmDeps({ ...params, deps });
|
|
10
|
+
}
|
|
11
|
+
/** Installs a set of virmator plugin npm deps. */
|
|
12
|
+
export async function installNpmDeps({ cwdPackagePath, cwdPackageJson, pluginPackagePath, pluginName, packageType, log, deps, }) {
|
|
13
|
+
const neededDeps = getObjectTypedEntries(deps);
|
|
14
|
+
if (!neededDeps.length) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const cwdPackageDeps = combineDeps(cwdPackageJson);
|
|
18
|
+
const pluginPackageJson = await readPackageJson(pluginPackagePath);
|
|
19
|
+
const currentPluginPackageDeps = combineDeps(pluginPackageJson);
|
|
20
|
+
const depsThatNeedInstalling = neededDeps.reduce((accum, [depName, depOptions,]) => {
|
|
21
|
+
if (!depOptions.packageType.includes(packageType)) {
|
|
22
|
+
return accum;
|
|
23
|
+
}
|
|
24
|
+
const baselineVersion = semver.coerce(currentPluginPackageDeps[depName] || '');
|
|
25
|
+
if (!baselineVersion) {
|
|
26
|
+
throw new VirmatorNoTraceError(`No baseline version found for npm dep '${depName}' in virmator plugin '${pluginName}'.`);
|
|
27
|
+
}
|
|
28
|
+
const currentVersion = semver.coerce(cwdPackageDeps[depName] || '');
|
|
29
|
+
if (currentVersion && baselineVersion.compare(currentVersion) !== 1) {
|
|
30
|
+
return accum;
|
|
31
|
+
}
|
|
32
|
+
const depNameWithVersion = `${depName}@${baselineVersion.raw}`;
|
|
33
|
+
accum[depOptions.type].push(depNameWithVersion);
|
|
34
|
+
return accum;
|
|
35
|
+
}, {
|
|
36
|
+
[NpmDepType.Dev]: [],
|
|
37
|
+
[NpmDepType.Regular]: [],
|
|
38
|
+
});
|
|
39
|
+
await awaitedBlockingMap(Object.entries(depsThatNeedInstalling), async ([depType, deps,]) => {
|
|
40
|
+
if (!deps.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const installDeps = deps.join(' ');
|
|
44
|
+
const installCommand = [
|
|
45
|
+
'npm',
|
|
46
|
+
'i',
|
|
47
|
+
depType === NpmDepType.Dev ? '-D' : '',
|
|
48
|
+
installDeps,
|
|
49
|
+
]
|
|
50
|
+
.filter(isTruthy)
|
|
51
|
+
.join(' ');
|
|
52
|
+
log.faint(`Installing ${installDeps}...`);
|
|
53
|
+
await runShellCommand(installCommand, {
|
|
54
|
+
cwd: cwdPackagePath,
|
|
55
|
+
hookUpToConsole: true,
|
|
56
|
+
rejectOnError: true,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function combineDeps(packageJson) {
|
|
61
|
+
return {
|
|
62
|
+
...packageJson.peerDependencies,
|
|
63
|
+
...packageJson.devDependencies,
|
|
64
|
+
...packageJson.dependencies,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function flattenDeps(usedCommands) {
|
|
68
|
+
return Object.values(usedCommands).reduce((accum, usedCommand) => {
|
|
69
|
+
if (!usedCommand) {
|
|
70
|
+
return accum;
|
|
71
|
+
}
|
|
72
|
+
Object.assign(accum, usedCommand.npmDeps);
|
|
73
|
+
if (Object.keys(usedCommand.subCommands).length) {
|
|
74
|
+
const subDeps = flattenDeps(usedCommand.subCommands);
|
|
75
|
+
Object.assign(accum, subDeps);
|
|
76
|
+
}
|
|
77
|
+
return accum;
|
|
78
|
+
}, {});
|
|
79
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { VirmatorPlugin } from '../plugin/plugin';
|
|
2
|
+
import { UsedVirmatorPluginCommands } from '../plugin/plugin-executor';
|
|
3
|
+
import { VirmatorPluginCliCommands } from '../plugin/plugin-init';
|
|
4
|
+
import { PluginLogger } from '../plugin/plugin-logger';
|
|
5
|
+
import { SetVirmatorFlags } from './virmator-flags';
|
|
6
|
+
/** All supported sets of args for virmator. */
|
|
7
|
+
export type ParsedArgs = {
|
|
8
|
+
virmatorFlags: SetVirmatorFlags;
|
|
9
|
+
commands: [string, ...string[]];
|
|
10
|
+
filteredCommandArgs: string[];
|
|
11
|
+
plugin: Readonly<VirmatorPlugin> | undefined;
|
|
12
|
+
usedCommands: UsedVirmatorPluginCommands;
|
|
13
|
+
};
|
|
14
|
+
/** Arbitrarily nested arbitrary virmator plugin commands. */
|
|
15
|
+
export type NestedSubCommands = Readonly<{
|
|
16
|
+
[SubCommand in string]: NestedSubCommands;
|
|
17
|
+
}>;
|
|
18
|
+
/** A mapping from command strings to plugins. */
|
|
19
|
+
export type PluginsMappedByCommand = Readonly<{
|
|
20
|
+
[Command in string]: Readonly<{
|
|
21
|
+
plugin: Readonly<VirmatorPlugin>;
|
|
22
|
+
subCommands: NestedSubCommands;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
25
|
+
/** Map a set of plugins from their top level commands to the plugins themselves. */
|
|
26
|
+
export declare function mapPluginsByCommand(plugins: ReadonlyArray<Readonly<VirmatorPlugin>>): PluginsMappedByCommand;
|
|
27
|
+
/** Determine the path of used commands from a plugin's nested cli command definition. */
|
|
28
|
+
export declare function calculateUsedCommands(pluginCliCommands: Readonly<VirmatorPluginCliCommands>, commands: ReadonlyArray<string>): UsedVirmatorPluginCommands;
|
|
29
|
+
/** Parses a raw cli command into supported virmator args. */
|
|
30
|
+
export declare function parseCliArgs({ cliCommand, entryPointFilePath, plugins, log, }: {
|
|
31
|
+
plugins: ReadonlyArray<Readonly<VirmatorPlugin>>;
|
|
32
|
+
cliCommand: string | ReadonlyArray<string>;
|
|
33
|
+
entryPointFilePath: string;
|
|
34
|
+
log: PluginLogger;
|
|
35
|
+
}): ParsedArgs;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { getObjectTypedEntries, hasKey, isLengthAtLeast, mapObjectValues, wrapInTry, } from '@augment-vir/common';
|
|
2
|
+
import { extractRelevantArgs } from 'cli-args-vir';
|
|
3
|
+
import { isRunTimeType } from 'run-time-assertions';
|
|
4
|
+
import { accessAtKeys } from '../augments/object/access';
|
|
5
|
+
import { virmatorFlags } from './virmator-flags';
|
|
6
|
+
function extractNestedCommands(cliCommands) {
|
|
7
|
+
return mapObjectValues(cliCommands, (commandName, command) => {
|
|
8
|
+
if (command.subCommands) {
|
|
9
|
+
return extractNestedCommands(command.subCommands);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Map a set of plugins from their top level commands to the plugins themselves. */
|
|
17
|
+
export function mapPluginsByCommand(plugins) {
|
|
18
|
+
const mappedPlugins = {};
|
|
19
|
+
plugins.forEach((plugin) => {
|
|
20
|
+
getObjectTypedEntries(plugin.cliCommands).forEach(([commandName, command,]) => {
|
|
21
|
+
if (!isRunTimeType(commandName, 'string')) {
|
|
22
|
+
throw new Error(`Command '${String(commandName)}' in plugin '${plugin.name}' must be string.`);
|
|
23
|
+
}
|
|
24
|
+
const existingPlugin = mappedPlugins[commandName]?.plugin;
|
|
25
|
+
if (existingPlugin) {
|
|
26
|
+
throw new Error(`Duplicate virmator command: '${commandName}' found in plugin '${plugin.name}' and plugin '${existingPlugin.name}'`);
|
|
27
|
+
}
|
|
28
|
+
mappedPlugins[commandName] = {
|
|
29
|
+
plugin,
|
|
30
|
+
subCommands: extractNestedCommands(command.subCommands || {}),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return mappedPlugins;
|
|
35
|
+
}
|
|
36
|
+
/** Determine the path of used commands from a plugin's nested cli command definition. */
|
|
37
|
+
export function calculateUsedCommands(pluginCliCommands, commands) {
|
|
38
|
+
if (!isLengthAtLeast(commands, 1)) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const pluginCommand = pluginCliCommands[commands[0]];
|
|
42
|
+
if (!pluginCommand) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
const subCommands = calculateUsedCommands(pluginCommand.subCommands || {}, commands.slice(1));
|
|
46
|
+
const usedCommands = {
|
|
47
|
+
[commands[0]]: {
|
|
48
|
+
...pluginCommand,
|
|
49
|
+
subCommands: Object.keys(subCommands).length ? subCommands : {},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return usedCommands;
|
|
53
|
+
}
|
|
54
|
+
/** Parses a raw cli command into supported virmator args. */
|
|
55
|
+
export function parseCliArgs({ cliCommand, entryPointFilePath, plugins, log, }) {
|
|
56
|
+
const rawArgs = isRunTimeType(cliCommand, 'array')
|
|
57
|
+
? cliCommand
|
|
58
|
+
: cliCommand.split(' ');
|
|
59
|
+
const relevantArgs = wrapInTry(() => extractRelevantArgs({
|
|
60
|
+
binName: 'virmator',
|
|
61
|
+
rawArgs,
|
|
62
|
+
fileName: entryPointFilePath,
|
|
63
|
+
errorIfNotFound: true,
|
|
64
|
+
}), {
|
|
65
|
+
fallbackValue: rawArgs,
|
|
66
|
+
});
|
|
67
|
+
const mappedPlugins = mapPluginsByCommand(plugins);
|
|
68
|
+
const parsedArgs = relevantArgs.reduce((parsedArgs, arg) => {
|
|
69
|
+
if (parsedArgs.filteredCommandArgs.length) {
|
|
70
|
+
parsedArgs.filteredCommandArgs.push(arg);
|
|
71
|
+
}
|
|
72
|
+
else if (isLengthAtLeast(parsedArgs.commands, 1)) {
|
|
73
|
+
const mainCommand = parsedArgs.commands[0];
|
|
74
|
+
const subCommands = mappedPlugins[mainCommand]?.subCommands || {};
|
|
75
|
+
const availableSubCommands = accessAtKeys(subCommands, parsedArgs.commands.slice(1));
|
|
76
|
+
if (availableSubCommands && arg in availableSubCommands) {
|
|
77
|
+
parsedArgs.commands.push(arg);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
parsedArgs.filteredCommandArgs.push(arg);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const commandPlugin = mappedPlugins[arg];
|
|
85
|
+
if (commandPlugin) {
|
|
86
|
+
parsedArgs.commands.push(arg);
|
|
87
|
+
parsedArgs.plugin = commandPlugin.plugin;
|
|
88
|
+
}
|
|
89
|
+
else if (hasKey(virmatorFlags, arg)) {
|
|
90
|
+
parsedArgs.virmatorFlags[arg] = true;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
log.warning(`Ignored unknown flag: '${arg}'`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return parsedArgs;
|
|
97
|
+
}, {
|
|
98
|
+
virmatorFlags: {},
|
|
99
|
+
commands: [],
|
|
100
|
+
filteredCommandArgs: [],
|
|
101
|
+
plugin: undefined,
|
|
102
|
+
usedCommands: {},
|
|
103
|
+
});
|
|
104
|
+
if (parsedArgs.virmatorFlags['--help']) {
|
|
105
|
+
parsedArgs.commands = ['help'];
|
|
106
|
+
parsedArgs.filteredCommandArgs = [];
|
|
107
|
+
parsedArgs.plugin = mappedPlugins['help']?.plugin;
|
|
108
|
+
}
|
|
109
|
+
parsedArgs.usedCommands = calculateUsedCommands(parsedArgs.plugin?.cliCommands || {}, parsedArgs.commands);
|
|
110
|
+
return parsedArgs;
|
|
111
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles and imports a TS file so it can be used within JS contexts. After the given callback is
|
|
4
|
+
* executed, the compiled JS output is deleted.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withImportedTsFile<T>({ inputPath, outputPath }: {
|
|
7
|
+
inputPath: string;
|
|
8
|
+
outputPath?: string | undefined;
|
|
9
|
+
}, moduleType: JsModuleType, callback: (config: any) => MaybePromise<T>): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Compiles a TS file and provides its path so it can be used within JS contexts. After the given
|
|
12
|
+
* callback is executed, the compiled JS output is deleted.
|
|
13
|
+
*/
|
|
14
|
+
export declare function withCompiledTsFile<T>({ inputPath, outputPath }: {
|
|
15
|
+
inputPath: string;
|
|
16
|
+
outputPath?: string | undefined;
|
|
17
|
+
}, moduleType: JsModuleType, callback: (configPath: string) => MaybePromise<T>): Promise<T>;
|
|
18
|
+
/** Output JS module types. */
|
|
19
|
+
export declare enum JsModuleType {
|
|
20
|
+
/** CommonJS. */
|
|
21
|
+
Cjs = "cjs",
|
|
22
|
+
/** EcmaScript Module. */
|
|
23
|
+
Esm = "esm"
|
|
24
|
+
}
|
|
25
|
+
/** Compiles a TS file to JS and returns its path. */
|
|
26
|
+
export declare function compileTs({ inputPath, outputPath, moduleType, }: {
|
|
27
|
+
inputPath: string;
|
|
28
|
+
moduleType: JsModuleType;
|
|
29
|
+
outputPath?: string | undefined;
|
|
30
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { wrapInTry } from '@augment-vir/common';
|
|
2
|
+
import { toPosixPath } from '@augment-vir/node-js';
|
|
3
|
+
import { rm } from 'node:fs/promises';
|
|
4
|
+
import { basename, join, relative } from 'node:path';
|
|
5
|
+
import { findClosestNodeModulesDir } from '../augments/index';
|
|
6
|
+
/**
|
|
7
|
+
* Compiles and imports a TS file so it can be used within JS contexts. After the given callback is
|
|
8
|
+
* executed, the compiled JS output is deleted.
|
|
9
|
+
*/
|
|
10
|
+
export async function withImportedTsFile({ inputPath, outputPath }, moduleType, callback) {
|
|
11
|
+
const compiledPath = await compileTs({
|
|
12
|
+
inputPath,
|
|
13
|
+
outputPath,
|
|
14
|
+
moduleType,
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const loadedConfig = await import(toPosixPath(relative(import.meta.dirname, compiledPath)));
|
|
18
|
+
return await callback(loadedConfig);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await wrapInTry(() => rm(compiledPath, { force: true }));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Compiles a TS file and provides its path so it can be used within JS contexts. After the given
|
|
26
|
+
* callback is executed, the compiled JS output is deleted.
|
|
27
|
+
*/
|
|
28
|
+
export async function withCompiledTsFile({ inputPath, outputPath }, moduleType, callback) {
|
|
29
|
+
const compiledPath = await compileTs({
|
|
30
|
+
inputPath,
|
|
31
|
+
outputPath,
|
|
32
|
+
moduleType,
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
return await callback(compiledPath);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await wrapInTry(() => rm(compiledPath, { force: true }));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function createOutfilePath(inputFilePath, moduleType) {
|
|
42
|
+
const nodeModulesDir = findClosestNodeModulesDir(import.meta.dirname);
|
|
43
|
+
return join(nodeModulesDir, '.virmator', basename(inputFilePath).replace(/\.ts$/, moduleType === JsModuleType.Cjs ? '.cjs' : '.mjs'));
|
|
44
|
+
}
|
|
45
|
+
/** Output JS module types. */
|
|
46
|
+
export var JsModuleType;
|
|
47
|
+
(function (JsModuleType) {
|
|
48
|
+
/** CommonJS. */
|
|
49
|
+
JsModuleType["Cjs"] = "cjs";
|
|
50
|
+
/** EcmaScript Module. */
|
|
51
|
+
JsModuleType["Esm"] = "esm";
|
|
52
|
+
})(JsModuleType || (JsModuleType = {}));
|
|
53
|
+
/** Compiles a TS file to JS and returns its path. */
|
|
54
|
+
export async function compileTs({ inputPath, outputPath, moduleType, }) {
|
|
55
|
+
const outfile = outputPath || createOutfilePath(inputPath, moduleType);
|
|
56
|
+
await (await import('esbuild')).build({
|
|
57
|
+
bundle: true,
|
|
58
|
+
entryPoints: [inputPath],
|
|
59
|
+
format: moduleType,
|
|
60
|
+
outfile,
|
|
61
|
+
platform: 'node',
|
|
62
|
+
target: ['node20'],
|
|
63
|
+
write: true,
|
|
64
|
+
});
|
|
65
|
+
return outfile;
|
|
66
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const rawVirmatorFlags: {
|
|
2
|
+
readonly '--no-configs': {
|
|
3
|
+
readonly doc: "Prevents command config files from being copied.";
|
|
4
|
+
};
|
|
5
|
+
readonly '--no-deps': {
|
|
6
|
+
readonly doc: "Prevents command npm deps from being installed.";
|
|
7
|
+
};
|
|
8
|
+
readonly '--help': {
|
|
9
|
+
readonly doc: "Print the help message.";
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Supported virmator flags. */
|
|
13
|
+
export declare const virmatorFlags: { [FlagName in keyof typeof rawVirmatorFlags]: {
|
|
14
|
+
doc: string;
|
|
15
|
+
name: FlagName;
|
|
16
|
+
}; };
|
|
17
|
+
/** Each supported virmator flag mapped to a boolean. */
|
|
18
|
+
export type SetVirmatorFlags = Partial<{
|
|
19
|
+
-readonly [FlagName in keyof typeof virmatorFlags]: true;
|
|
20
|
+
}>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { mapObjectValues } from '@augment-vir/common';
|
|
2
|
+
const rawVirmatorFlags = {
|
|
3
|
+
'--no-configs': {
|
|
4
|
+
doc: 'Prevents command config files from being copied.',
|
|
5
|
+
},
|
|
6
|
+
'--no-deps': {
|
|
7
|
+
doc: 'Prevents command npm deps from being installed.',
|
|
8
|
+
},
|
|
9
|
+
'--help': {
|
|
10
|
+
doc: 'Print the help message.',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
/** Supported virmator flags. */
|
|
14
|
+
export const virmatorFlags = mapObjectValues(rawVirmatorFlags, (flag, value) => {
|
|
15
|
+
return {
|
|
16
|
+
...value,
|
|
17
|
+
name: flag,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively calls the `check` callback on ancestor directories until there are no more ancestor
|
|
3
|
+
* directories to check.
|
|
4
|
+
*/
|
|
5
|
+
export declare function searchUpwardsForDir(startDirPath: string, check: (dirPath: string) => boolean): string;
|
|
6
|
+
/** Finds the closest ancestor directory with a `package.json` file. */
|
|
7
|
+
export declare function findClosestPackageDir(startDirPath: string): string;
|
|
8
|
+
/** Finds the closest ancestor `node_modules` directory. */
|
|
9
|
+
export declare function findClosestNodeModulesDir(startDirPath: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Recursively calls the `check` callback on ancestor directories until there are no more ancestor
|
|
5
|
+
* directories to check.
|
|
6
|
+
*/
|
|
7
|
+
export function searchUpwardsForDir(startDirPath, check) {
|
|
8
|
+
if (!existsSync(startDirPath) || !startDirPath) {
|
|
9
|
+
throw new Error(`Could not search in '${startDirPath}': it does not exist.`);
|
|
10
|
+
}
|
|
11
|
+
if (check(startDirPath)) {
|
|
12
|
+
return startDirPath;
|
|
13
|
+
}
|
|
14
|
+
const parent = dirname(startDirPath);
|
|
15
|
+
if (parent === startDirPath) {
|
|
16
|
+
throw new Error(`Cannot recurse any higher, already at '${parent}'`);
|
|
17
|
+
}
|
|
18
|
+
return searchUpwardsForDir(parent, check);
|
|
19
|
+
}
|
|
20
|
+
/** Finds the closest ancestor directory with a `package.json` file. */
|
|
21
|
+
export function findClosestPackageDir(startDirPath) {
|
|
22
|
+
return searchUpwardsForDir(startDirPath, (dir) => {
|
|
23
|
+
return existsSync(join(dir, 'package.json'));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Finds the closest ancestor `node_modules` directory. */
|
|
27
|
+
export function findClosestNodeModulesDir(startDirPath) {
|
|
28
|
+
return join(searchUpwardsForDir(startDirPath, (dir) => {
|
|
29
|
+
return existsSync(join(dir, 'node_modules'));
|
|
30
|
+
}), 'node_modules');
|
|
31
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnyObject } from '@augment-vir/common';
|
|
2
|
+
/** Gets the nested value within an object with the provided chain of keys. */
|
|
3
|
+
export declare function accessAtKeys<T extends AnyObject>(parent: Readonly<AnyObject> | undefined, keys: ReadonlyArray<PropertyKey>): T | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isLengthAtLeast } from '@augment-vir/common';
|
|
2
|
+
/** Gets the nested value within an object with the provided chain of keys. */
|
|
3
|
+
export function accessAtKeys(parent, keys) {
|
|
4
|
+
if (!parent) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
else if (!isLengthAtLeast(keys, 1)) {
|
|
8
|
+
return parent;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return accessAtKeys(parent[keys[0]], keys.slice(1));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
import { PluginLogger } from '../../plugin/plugin-logger';
|
|
3
|
+
/** A {@link Writable} implementation that writes to the provided plugin logger. */
|
|
4
|
+
export declare class CallbackWritable extends Writable {
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private chunks;
|
|
7
|
+
/** Special write implementation that writs to the given logger. */
|
|
8
|
+
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
9
|
+
constructor(logger: PluginLogger);
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
/** A {@link Writable} implementation that writes to the provided plugin logger. */
|
|
3
|
+
export class CallbackWritable extends Writable {
|
|
4
|
+
logger;
|
|
5
|
+
chunks = [];
|
|
6
|
+
/** Special write implementation that writs to the given logger. */
|
|
7
|
+
_write(chunk, encoding, callback) {
|
|
8
|
+
const chunkString = String(chunk);
|
|
9
|
+
this.chunks.push(chunkString);
|
|
10
|
+
if (chunkString.endsWith('\n')) {
|
|
11
|
+
const fullString = this.chunks.join('');
|
|
12
|
+
this.chunks = [];
|
|
13
|
+
this.logger.faint(fullString.trim());
|
|
14
|
+
}
|
|
15
|
+
callback();
|
|
16
|
+
}
|
|
17
|
+
constructor(logger) {
|
|
18
|
+
super();
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { log } from '@augment-vir/node-js';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { findConfigFile, parseJsonConfigFileContent, readConfigFile, sys, } from 'typescript';
|
|
5
|
+
/** Parsed the nearest ancestor TS Config file, if one can be found. */
|
|
6
|
+
export function parseTsConfig(cwd) {
|
|
7
|
+
try {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
9
|
+
const tsConfigPath = findConfigFile(cwd, sys.fileExists);
|
|
10
|
+
/** It'll be quite hard to setup a test where `tsConfigPath` is defined but does not exist. */
|
|
11
|
+
/* node:coverage ignore next 1 */
|
|
12
|
+
if (!tsConfigPath || !existsSync(tsConfigPath)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
16
|
+
const configFile = readConfigFile(tsConfigPath, sys.readFile);
|
|
17
|
+
return parseJsonConfigFileContent(configFile.config, sys, dirname(tsConfigPath));
|
|
18
|
+
/* node:coverage ignore next 4 */
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
log.error(error);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArrayElement } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* All terminal colors passed to concurrently and other concurrent operations used within virmator
|
|
4
|
+
* plugins.
|
|
5
|
+
*/
|
|
6
|
+
export declare const terminalColors: readonly ["red", "yellow", "greenBright", "cyan", "blueBright", "magentaBright", "grey"];
|
|
7
|
+
/** The supported terminal colors for virmator concurrent commands. */
|
|
8
|
+
export type TerminalColor = ArrayElement<typeof terminalColors>;
|
|
9
|
+
/** Gets a supported virmator terminal color, with support for overflowing indexes. */
|
|
10
|
+
export declare function getTerminalColor(index: number): TerminalColor;
|
package/dist/colors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All terminal colors passed to concurrently and other concurrent operations used within virmator
|
|
3
|
+
* plugins.
|
|
4
|
+
*/
|
|
5
|
+
export const terminalColors = [
|
|
6
|
+
// Text colors
|
|
7
|
+
'red',
|
|
8
|
+
'yellow',
|
|
9
|
+
'greenBright',
|
|
10
|
+
'cyan',
|
|
11
|
+
'blueBright',
|
|
12
|
+
'magentaBright',
|
|
13
|
+
'grey',
|
|
14
|
+
];
|
|
15
|
+
/** Gets a supported virmator terminal color, with support for overflowing indexes. */
|
|
16
|
+
export function getTerminalColor(index) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
18
|
+
return terminalColors[index % terminalColors.length];
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './virmator-no-trace.error';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './virmator-no-trace.error';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that aborts execution but should not get stack traced: only the error message should get
|
|
3
|
+
* logged.
|
|
4
|
+
*/
|
|
5
|
+
export declare class VirmatorNoTraceError extends Error {
|
|
6
|
+
readonly name = "VirmatorNoTraceError";
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Used for debugging. Set to `false` to see error traces. Should always be set back to `true` for
|
|
11
|
+
* publishing.
|
|
12
|
+
*/
|
|
13
|
+
export declare const hideNoTraceTraces: boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that aborts execution but should not get stack traced: only the error message should get
|
|
3
|
+
* logged.
|
|
4
|
+
*/
|
|
5
|
+
export class VirmatorNoTraceError extends Error {
|
|
6
|
+
name = 'VirmatorNoTraceError';
|
|
7
|
+
constructor(message = '') {
|
|
8
|
+
super(message);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Used for debugging. Set to `false` to see error traces. Should always be set back to `true` for
|
|
13
|
+
* publishing.
|
|
14
|
+
*/
|
|
15
|
+
export const hideNoTraceTraces = true;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { join, resolve } from 'node:path';
|
|
2
|
+
export const corePackageDir = resolve(import.meta.dirname, '..');
|
|
3
|
+
const monoRepoDir = resolve(corePackageDir, '..', '..');
|
|
4
|
+
export const monoRepoTestFilesDir = join(monoRepoDir, 'test-files', 'compile');
|
|
5
|
+
export const coreTestFilesDir = join(corePackageDir, 'test-files');
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PackageType, VirmatorEnv } from './plugin-env';
|
|
2
|
+
/** Definition for a plugin's config file. */
|
|
3
|
+
export type VirmatorPluginConfigFile = {
|
|
4
|
+
/**
|
|
5
|
+
* The path from which the config file resides within the virmator plugin itself. Relative to
|
|
6
|
+
* the plugin's package directory.
|
|
7
|
+
*/
|
|
8
|
+
copyFromPath: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to which the config file will be copied. Relative to the root directory of the host
|
|
11
|
+
* repo or npm workspace.
|
|
12
|
+
*/
|
|
13
|
+
copyToPath: string;
|
|
14
|
+
/** The environments in which this config should be used. */
|
|
15
|
+
env: VirmatorEnv[];
|
|
16
|
+
/** The package type for which this config should be used. */
|
|
17
|
+
packageType: PackageType[];
|
|
18
|
+
/**
|
|
19
|
+
* If set to `true`, this config will be copied over every time the command is run, if the
|
|
20
|
+
* config doesn't exist, unless `'--no-configs'` was set.
|
|
21
|
+
*/
|
|
22
|
+
required: boolean;
|
|
23
|
+
configFlags?: string[];
|
|
24
|
+
};
|
|
25
|
+
/** {@link VirmatorPluginConfigFile} but with resolved paths too. */
|
|
26
|
+
export type VirmatorPluginResolvedConfigFile = VirmatorPluginConfigFile & {
|
|
27
|
+
/** Absolute path to the config's copy to location. */
|
|
28
|
+
fullCopyToPath: string;
|
|
29
|
+
/** Absolute path to the config's copy from location. */
|
|
30
|
+
fullCopyFromPath: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|