mb-run 0.0.1-dev-20260504-b6b8a3a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cache.js ADDED
@@ -0,0 +1,107 @@
1
+ import { readdir, readFile, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileExists } from './clean.js';
4
+ import { parsePackageJson } from './helpers.js';
5
+ import { logBackup, logRestore } from './logger.js';
6
+ export const packageJsonMap = new Map();
7
+ export const tsconfigMap = new Map();
8
+ const packageJsonPaths = new Map();
9
+ export async function resolveWorkspacePackageJsonPaths(rootDir) {
10
+ const rootPkg = await parsePackageJson(rootDir);
11
+ const workspacesConfig = rootPkg.workspaces;
12
+ let patterns = [];
13
+ if (Array.isArray(workspacesConfig)) {
14
+ patterns = workspacesConfig.filter((p) => typeof p === 'string');
15
+ }
16
+ else if (workspacesConfig && typeof workspacesConfig === 'object' && Array.isArray(workspacesConfig.packages)) {
17
+ patterns = workspacesConfig.packages.filter((p) => typeof p === 'string');
18
+ }
19
+ if (patterns.length === 0)
20
+ return [];
21
+ const hasGlobChars = (s) => /[*?\[]/.test(s);
22
+ const results = [];
23
+ for (const pattern of patterns) {
24
+ const trimmed = pattern.trim();
25
+ if (!trimmed)
26
+ continue;
27
+ if (!hasGlobChars(trimmed)) {
28
+ const candidate = path.join(rootDir, trimmed, 'package.json');
29
+ if (await fileExists(candidate))
30
+ results.push(candidate);
31
+ continue;
32
+ }
33
+ if (trimmed.endsWith('/*') && trimmed.indexOf('*') === trimmed.length - 1 && !/[?\[]/.test(trimmed)) {
34
+ const baseAbs = path.join(rootDir, trimmed.slice(0, -2));
35
+ let entries;
36
+ try {
37
+ entries = await readdir(baseAbs, { withFileTypes: true });
38
+ }
39
+ catch {
40
+ continue;
41
+ }
42
+ for (const entry of entries) {
43
+ if (!entry.isDirectory())
44
+ continue;
45
+ const candidate = path.join(baseAbs, entry.name, 'package.json');
46
+ if (await fileExists(candidate))
47
+ results.push(candidate);
48
+ }
49
+ continue;
50
+ }
51
+ }
52
+ return Array.from(new Set(results));
53
+ }
54
+ export async function backup(rootDir) {
55
+ logBackup(rootDir);
56
+ packageJsonMap.clear();
57
+ tsconfigMap.clear();
58
+ packageJsonPaths.clear();
59
+ const rootPkgPath = path.join(rootDir, 'package.json');
60
+ const rootPkg = await parsePackageJson(rootDir);
61
+ const rootName = String(rootPkg.name ?? '');
62
+ packageJsonMap.set(rootName, rootPkg);
63
+ packageJsonPaths.set(rootName, rootPkgPath);
64
+ const workspacePkgPaths = await resolveWorkspacePackageJsonPaths(rootDir);
65
+ const workspaceDirs = [];
66
+ for (const pkgPath of workspacePkgPaths) {
67
+ const pkg = JSON.parse(await readFile(pkgPath, 'utf8'));
68
+ const name = String(pkg.name ?? '');
69
+ packageJsonMap.set(name, pkg);
70
+ packageJsonPaths.set(name, pkgPath);
71
+ workspaceDirs.push(path.dirname(pkgPath));
72
+ }
73
+ const dirsToScan = [rootDir, ...workspaceDirs];
74
+ for (const dir of dirsToScan) {
75
+ let entries;
76
+ try {
77
+ entries = await readdir(dir, { withFileTypes: true });
78
+ }
79
+ catch {
80
+ continue;
81
+ }
82
+ for (const entry of entries) {
83
+ if (!entry.isFile())
84
+ continue;
85
+ const name = entry.name;
86
+ if (!name.startsWith('tsconfig') || !name.endsWith('.json'))
87
+ continue;
88
+ const absPath = path.join(dir, name);
89
+ const relKey = path.relative(rootDir, absPath).split(path.sep).join('/');
90
+ const parsed = JSON.parse(await readFile(absPath, 'utf8'));
91
+ tsconfigMap.set(relKey, parsed);
92
+ }
93
+ }
94
+ }
95
+ export async function restore(rootDir) {
96
+ logRestore(rootDir);
97
+ for (const [relKey, content] of tsconfigMap) {
98
+ const absPath = path.join(rootDir, ...relKey.split('/'));
99
+ await writeFile(absPath, JSON.stringify(content, null, 2));
100
+ }
101
+ for (const [name, content] of packageJsonMap) {
102
+ const absPath = packageJsonPaths.get(name);
103
+ if (absPath) {
104
+ await writeFile(absPath, JSON.stringify(content, null, 2));
105
+ }
106
+ }
107
+ }
package/dist/clean.js ADDED
@@ -0,0 +1,119 @@
1
+ import { access, readdir, rm } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { logDelete } from './logger.js';
4
+ export async function fileExists(filePath) {
5
+ try {
6
+ await access(filePath);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+ async function removePath(targetPath, opts) {
14
+ logDelete(targetPath);
15
+ if (opts.dryRun)
16
+ return;
17
+ await rm(targetPath, { recursive: true, force: true });
18
+ }
19
+ export async function emptyDir(dirPath, opts) {
20
+ if (!(await fileExists(dirPath)))
21
+ return;
22
+ const entries = await readdir(dirPath, { withFileTypes: true });
23
+ await Promise.all(entries.map(async (entry) => {
24
+ await removePath(path.join(dirPath, entry.name), opts);
25
+ }));
26
+ }
27
+ async function emptyDirIfExists(dirPath, opts) {
28
+ let entries;
29
+ try {
30
+ entries = await readdir(dirPath, { withFileTypes: true });
31
+ }
32
+ catch {
33
+ return;
34
+ }
35
+ await Promise.all(entries.map(async (entry) => {
36
+ await removePath(path.join(dirPath, entry.name), opts);
37
+ }));
38
+ }
39
+ async function removeTsBuildInfo(rootDir, opts) {
40
+ const stack = [rootDir];
41
+ while (stack.length > 0) {
42
+ const current = stack.pop();
43
+ if (!current)
44
+ break;
45
+ let entries;
46
+ try {
47
+ entries = await readdir(current, { withFileTypes: true });
48
+ }
49
+ catch {
50
+ continue;
51
+ }
52
+ for (const entry of entries) {
53
+ if (entry.isDirectory()) {
54
+ if (entry.name === 'node_modules')
55
+ continue;
56
+ stack.push(path.join(current, entry.name));
57
+ continue;
58
+ }
59
+ if (entry.isFile() && entry.name.endsWith('.tsbuildinfo')) {
60
+ await removePath(path.join(current, entry.name), opts);
61
+ }
62
+ }
63
+ }
64
+ }
65
+ async function cleanWorkspaceArtifacts(parentDir, ensureDirs, opts) {
66
+ let workspaces;
67
+ try {
68
+ workspaces = await readdir(parentDir, { withFileTypes: true });
69
+ }
70
+ catch {
71
+ return;
72
+ }
73
+ await Promise.all(workspaces
74
+ .filter((d) => d.isDirectory())
75
+ .map(async (d) => {
76
+ const wsRoot = path.join(parentDir, d.name);
77
+ await Promise.all([
78
+ removePath(path.join(wsRoot, 'build'), opts),
79
+ removePath(path.join(wsRoot, 'dist'), opts),
80
+ removePath(path.join(wsRoot, 'dist-jest'), opts),
81
+ removePath(path.join(wsRoot, 'coverage'), opts),
82
+ removePath(path.join(wsRoot, 'jest'), opts),
83
+ removePath(path.join(wsRoot, 'temp'), opts),
84
+ removePath(path.join(wsRoot, '.cache'), opts),
85
+ removePath(path.join(wsRoot, 'node_modules'), opts),
86
+ removePath(path.join(wsRoot, 'package-lock.json'), opts),
87
+ removePath(path.join(wsRoot, 'npm-shrinkwrap.json'), opts),
88
+ ]);
89
+ const empty = ensureDirs ? emptyDir : emptyDirIfExists;
90
+ await Promise.all([empty(path.join(wsRoot, '.cache'), opts), empty(path.join(wsRoot, 'node_modules'), opts)]);
91
+ }));
92
+ }
93
+ async function commonClean(emptyRootNodeModules, ensureWorkspaceDirs, opts) {
94
+ await removeTsBuildInfo(opts.rootDir, opts);
95
+ await Promise.all([
96
+ removePath(path.join(opts.rootDir, 'build'), opts),
97
+ removePath(path.join(opts.rootDir, 'dist'), opts),
98
+ removePath(path.join(opts.rootDir, 'dist-jest'), opts),
99
+ removePath(path.join(opts.rootDir, 'coverage'), opts),
100
+ removePath(path.join(opts.rootDir, 'jest'), opts),
101
+ removePath(path.join(opts.rootDir, 'temp'), opts),
102
+ removePath(path.join(opts.rootDir, 'npm-shrinkwrap.json'), opts),
103
+ ]);
104
+ await Promise.all([
105
+ cleanWorkspaceArtifacts(path.join(opts.rootDir, 'packages'), ensureWorkspaceDirs, opts),
106
+ cleanWorkspaceArtifacts(path.join(opts.rootDir, 'apps'), ensureWorkspaceDirs, opts),
107
+ ]);
108
+ const emptyRootCache = ensureWorkspaceDirs ? emptyDir : emptyDirIfExists;
109
+ await emptyRootCache(path.join(opts.rootDir, '.cache'), opts);
110
+ if (emptyRootNodeModules) {
111
+ await emptyDir(path.join(opts.rootDir, 'node_modules'), opts);
112
+ }
113
+ }
114
+ export async function resetClean(opts) {
115
+ await commonClean(true, false, opts);
116
+ }
117
+ export async function cleanOnly(opts) {
118
+ await commonClean(false, false, opts);
119
+ }
@@ -0,0 +1,80 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { build } from 'esbuild';
4
+ import { resolveWorkspacePackageJsonPaths } from './cache.js';
5
+ import { parsePackageJson } from './helpers.js';
6
+ import { logEsbuild } from './logger.js';
7
+ export async function runEsbuild(opts) {
8
+ if (opts.dryRun)
9
+ return;
10
+ const workspacePaths = await resolveWorkspacePackageJsonPaths(opts.rootDir);
11
+ const allPkgPaths = [path.join(opts.rootDir, 'package.json'), ...workspacePaths];
12
+ const localNames = new Set();
13
+ for (const wPkgPath of workspacePaths) {
14
+ const wRaw = await readFile(wPkgPath, 'utf8');
15
+ const wPkg = JSON.parse(wRaw);
16
+ if (wPkg.name)
17
+ localNames.add(wPkg.name);
18
+ }
19
+ const externalSet = new Set();
20
+ for (const pkgPath of allPkgPaths) {
21
+ const pRaw = await readFile(pkgPath, 'utf8');
22
+ const pPkg = JSON.parse(pRaw);
23
+ for (const dep of [...Object.keys(pPkg.dependencies ?? {}), ...Object.keys(pPkg.optionalDependencies ?? {}), ...Object.keys(pPkg.peerDependencies ?? {})]) {
24
+ externalSet.add(dep);
25
+ }
26
+ }
27
+ for (const localName of localNames) {
28
+ externalSet.delete(localName);
29
+ }
30
+ const rootPkg = (await parsePackageJson(opts.rootDir));
31
+ const toTsSrc = (relPath) => relPath
32
+ .replace(/^\.?\//, '')
33
+ .replace('dist/', 'src/')
34
+ .replace(/\.js$/, '.ts');
35
+ const toOutName = (relPath) => relPath
36
+ .replace(/^\.?\//, '')
37
+ .replace(/^dist\//, '')
38
+ .replace(/\.js$/, '');
39
+ const exportsMain = typeof rootPkg.exports === 'object' && rootPkg.exports !== null ? rootPkg.exports['.']?.['import'] : undefined;
40
+ const mainRel = rootPkg.main ??
41
+ exportsMain ??
42
+ (() => {
43
+ throw new Error('No main entry point found in package.json (main or exports["."]["import"] required)');
44
+ })();
45
+ const binEntries = Object.entries(rootPkg.bin ?? {});
46
+ const alias = {};
47
+ for (const wPkgPath of workspacePaths) {
48
+ const wRaw = await readFile(wPkgPath, 'utf8');
49
+ const wPkg = JSON.parse(wRaw);
50
+ if (!wPkg.name)
51
+ continue;
52
+ const wExportsMain = typeof wPkg.exports === 'object' && wPkg.exports !== null ? wPkg.exports['.']?.['import'] : undefined;
53
+ const wMainRel = wPkg.main ?? wExportsMain;
54
+ if (!wMainRel)
55
+ continue;
56
+ alias[wPkg.name] = path.join(path.dirname(wPkgPath), toTsSrc(wMainRel));
57
+ }
58
+ const entryPoints = [
59
+ { in: path.join(opts.rootDir, toTsSrc(mainRel)), out: toOutName(mainRel) },
60
+ ...binEntries.map(([, binRelPath]) => ({
61
+ in: path.join(opts.rootDir, toTsSrc(binRelPath)),
62
+ out: toOutName(binRelPath),
63
+ })),
64
+ ];
65
+ logEsbuild(entryPoints, opts.rootDir);
66
+ const esbuildOptions = {
67
+ entryPoints,
68
+ bundle: true,
69
+ format: 'esm',
70
+ platform: 'node',
71
+ target: ['esnext'],
72
+ alias,
73
+ external: [...externalSet],
74
+ treeShaking: true,
75
+ splitting: true,
76
+ outdir: path.join(opts.rootDir, 'dist'),
77
+ write: true,
78
+ };
79
+ await build(esbuildOptions);
80
+ }
package/dist/help.js ADDED
@@ -0,0 +1,44 @@
1
+ import pkg from '../package.json' with { type: 'json' };
2
+ import { brightBlack, brightCyan, brightWhite, brightYellow, cyan, green, log } from './ansi.js';
3
+ export function printUsage() {
4
+ const title = `${brightCyan('mb-run')} ${brightBlack('version')} ${brightWhite(pkg.version)}`;
5
+ const usageLine = `${brightYellow('Usage:')} ${green('mb-run')} [--install] [--reset [--production]] [--clean] [--deep-clean] [--build [--production]] [--watch] [--test] [--lint|--lint-fix] [--format|--format-check] [--sort] [--update] [--pack] [--publish] [--dry-run] [--version [dev|edge|git|local|next|alpha|beta]] [--info]`;
6
+ const msg = `\
7
+ ${title}
8
+
9
+ Runs the same operations as the package.json scripts in the current working directory, but executes the local
10
+ binaries in node_modules/.bin directly (does not call npm scripts).
11
+
12
+ ${usageLine}
13
+
14
+ ${brightYellow('Notes:')}
15
+ - ${cyan('Multiple flags')} are run in this order: ${brightBlack('install → update → deep-clean → reset → clean → build → test → format → lint → sort → watch')}
16
+ - ${green('--install')} runs npm install --no-fund --no-audit
17
+ - ${green('--reset')} empties .cache/ and node_modules/ (keeps directories for devcontainer named volumes), then runs npm install and build
18
+ - ${green('--deep-clean')} empties .cache/ and node_modules/ like --reset but skips the install and build steps
19
+ - ${green('--test')} sets NODE_OPTIONS="--experimental-vm-modules --no-warnings" like the existing scripts
20
+ - ${green('--lint-fix')} runs eslint with --fix
21
+ - ${green('--format-check')} runs prettier with --check
22
+ - ${green('--build')} prefers per-workspace tsconfig.build.json when present
23
+ - ${green('--build --production')} prefers tsconfig.build.production.json, else tsconfig.build.json, else tsconfig.json
24
+ - ${green('--reset --production')} performs a reset and rebuilds using the production tsconfig
25
+ - ${green('--sort')} sorts top-level keys in all package.json files (root and workspaces) using the canonical key order
26
+ - ${green('--update')} installs npm-check-updates (--no-save) then runs ncu -u across all workspaces
27
+ - ${green('--pack')} backs up package.json, cleans, builds for production, strips devDependencies and scripts, empties node_modules, runs npm install --omit=dev, npm shrinkwrap, npm pack, then restores package.json and reinstalls
28
+ - ${green('--publish')} backs up all package.json files (root and workspaces), strips devDependencies and scripts from each, runs npm publish --dry-run for root and every workspace, then restores all package.json files
29
+ - ${green('--dry-run')} logs intended actions without changing files or executing commands
30
+ - ${green('--version')} updates versions for the current package and all configured workspaces
31
+ - ${green('--verbose')} prints each external command before it is executed
32
+ - ${green('--info')} prints system information (platform, hostname, memory, network, Node.js/npm versions)
33
+ `;
34
+ log(msg);
35
+ }
36
+ export function printVersionUsage() {
37
+ const msg = [
38
+ `${brightYellow('Usage:')} ${green('mb-run')} ${green('--version')} [dev|edge|git|local|next|alpha|beta]`,
39
+ `${cyan('Updates')} package.json + package-lock.json (current package and workspaces) version to:`,
40
+ ` ${brightBlack('<baseVersion>-<dev|edge|git|local|next|alpha|beta>-<yyyymmdd>-<7charSha>')}`,
41
+ `Or with no tag, strips the suffix back to ${brightBlack('<baseVersion>')}.`,
42
+ ].join('\n');
43
+ log(msg);
44
+ }
@@ -0,0 +1,20 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ export async function parsePackageJson(rootDir) {
4
+ const packageJsonPath = path.join(rootDir, 'package.json');
5
+ try {
6
+ const raw = await readFile(packageJsonPath, 'utf8');
7
+ return JSON.parse(raw);
8
+ }
9
+ catch (error) {
10
+ throw new Error(`Failed to read or parse ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
11
+ }
12
+ }
13
+ export async function isPlugin(rootDir) {
14
+ const pkg = (await parsePackageJson(rootDir));
15
+ return pkg?.scripts?.start === 'matterbridge' || pkg?.scripts?.['dev:link'] === 'npm link --no-fund --no-audit matterbridge';
16
+ }
17
+ export async function isMonorepo(rootDir) {
18
+ const pkg = await parsePackageJson(rootDir);
19
+ return pkg?.workspaces !== undefined;
20
+ }
package/dist/info.js ADDED
@@ -0,0 +1,93 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import process from 'node:process';
5
+ import { log } from './ansi.js';
6
+ function formatBytes(bytes) {
7
+ if (bytes >= 1024 * 1024 * 1024)
8
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
9
+ if (bytes >= 1024 * 1024)
10
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
11
+ return `${(bytes / 1024).toFixed(1)} KB`;
12
+ }
13
+ function formatUptime(seconds) {
14
+ const days = Math.floor(seconds / 86400);
15
+ const hours = Math.floor((seconds % 86400) / 3600);
16
+ const minutes = Math.floor((seconds % 3600) / 60);
17
+ const parts = [];
18
+ if (days > 0)
19
+ parts.push(`${days} day${days !== 1 ? 's' : ''}`);
20
+ if (hours > 0)
21
+ parts.push(`${hours} hour${hours !== 1 ? 's' : ''}`);
22
+ if (minutes > 0)
23
+ parts.push(`${minutes} minute${minutes !== 1 ? 's' : ''}`);
24
+ return parts.length > 0 ? `up ${parts.join(', ')}` : 'up less than a minute';
25
+ }
26
+ function getPrimaryIpv4() {
27
+ for (const iface of Object.values(os.networkInterfaces())) {
28
+ for (const addr of iface ?? []) {
29
+ if (addr.family === 'IPv4' && !addr.internal)
30
+ return addr.address;
31
+ }
32
+ }
33
+ return 'unavailable';
34
+ }
35
+ function getIpv6Addresses() {
36
+ const addrs = [];
37
+ for (const iface of Object.values(os.networkInterfaces())) {
38
+ for (const addr of iface ?? []) {
39
+ if (addr.family === 'IPv6' && !addr.internal)
40
+ addrs.push(addr.address);
41
+ }
42
+ }
43
+ return addrs.length > 0 ? addrs.join(' ') : 'none';
44
+ }
45
+ function npmPackageJsonCandidates(nodeBinDir) {
46
+ return [
47
+ path.join(nodeBinDir, 'node_modules', 'npm', 'package.json'),
48
+ path.join(nodeBinDir, '..', 'lib', 'node_modules', 'npm', 'package.json'),
49
+ '/usr/lib/node_modules/npm/package.json',
50
+ ];
51
+ }
52
+ function getNpmVersion() {
53
+ const nodeBinDir = path.dirname(process.execPath);
54
+ for (const candidate of npmPackageJsonCandidates(nodeBinDir)) {
55
+ try {
56
+ const raw = readFileSync(candidate, 'utf8');
57
+ const parsed = JSON.parse(raw);
58
+ if (parsed !== null && typeof parsed === 'object' && 'version' in parsed && typeof parsed['version'] === 'string') {
59
+ return parsed['version'];
60
+ }
61
+ }
62
+ catch {
63
+ }
64
+ }
65
+ const agent = process.env['npm_config_user_agent'];
66
+ if (agent) {
67
+ const match = /^npm\/(\S+)/u.exec(agent);
68
+ if (match?.[1])
69
+ return match[1];
70
+ }
71
+ return 'unavailable';
72
+ }
73
+ export function systemInfo() {
74
+ const total = os.totalmem();
75
+ const used = total - os.freemem();
76
+ let username = 'unavailable';
77
+ try {
78
+ username = os.userInfo().username;
79
+ }
80
+ catch {
81
+ }
82
+ log(`\u{1F4BB} Platform: ${os.type()} ${os.arch()}`);
83
+ log(`\u{1F9E9} Kernel: ${os.release()} / ${os.version()}`);
84
+ log(`\u{1F464} User: ${username}`);
85
+ log(`\u{1F516} Hostname: ${os.hostname()}`);
86
+ log(`\u{23F3} Uptime: ${formatUptime(os.uptime())}`);
87
+ log(`\u{1F4C5} Date: ${new Date().toString()}`);
88
+ log(`\u{1F9E0} Memory: ${formatBytes(used)} used / ${formatBytes(total)} total`);
89
+ log(`\u{1F310} IPv4: ${getPrimaryIpv4()}`);
90
+ log(`\u{1F310} IPv6: ${getIpv6Addresses()}`);
91
+ log(`\u{1F7E2} Node.js: ${process.version.replace(/^v/u, '')}`);
92
+ log(`\u{1F7E3} Npm: ${getNpmVersion()}`);
93
+ }
package/dist/logger.js ADDED
@@ -0,0 +1,79 @@
1
+ import path from 'node:path';
2
+ import { brightRed, brightYellow, cyan, green, log, magenta, reverse } from './ansi.js';
3
+ export function formatCommandArg(arg) {
4
+ if (arg === '')
5
+ return '""';
6
+ return /[\s"]/u.test(arg) ? JSON.stringify(arg) : arg;
7
+ }
8
+ export class Logger {
9
+ dryRun;
10
+ verbose;
11
+ rootDir;
12
+ constructor(opts) {
13
+ this.dryRun = opts.dryRun;
14
+ this.verbose = opts.verbose;
15
+ this.rootDir = opts.rootDir;
16
+ }
17
+ shouldLogActions() {
18
+ return this.verbose || this.dryRun;
19
+ }
20
+ logPrefix() {
21
+ return this.dryRun ? `${green('[mb-run]')} ${reverse(magenta('[dry]'))}` : green('[mb-run]');
22
+ }
23
+ logCommand = (command, args, cwd = this.rootDir) => {
24
+ if (!this.shouldLogActions())
25
+ return;
26
+ const parts = [command, ...args].map(formatCommandArg).join(' ');
27
+ log(`${this.logPrefix()} ${cyan(cwd)}> ${green('run')} ${parts}`);
28
+ };
29
+ logDelete = (targetPath) => {
30
+ if (!this.shouldLogActions())
31
+ return;
32
+ const resolvedPath = path.resolve(targetPath);
33
+ log(`${this.logPrefix()} ${cyan(path.dirname(resolvedPath))}> ${brightRed('delete')} ${formatCommandArg(path.basename(resolvedPath))}`);
34
+ };
35
+ logWriteFile = (filePath) => {
36
+ if (!this.shouldLogActions())
37
+ return;
38
+ const resolvedPath = path.resolve(filePath);
39
+ log(`${this.logPrefix()} ${cyan(path.dirname(resolvedPath))}> ${brightYellow('write')} ${formatCommandArg(path.basename(resolvedPath))}`);
40
+ };
41
+ logEsbuild = (entryPoints, cwd = this.rootDir) => {
42
+ if (!this.shouldLogActions())
43
+ return;
44
+ const entries = entryPoints.map(({ in: inPath }) => formatCommandArg(inPath)).join(' ');
45
+ log(`${this.logPrefix()} ${cyan(cwd)}> ${magenta('esbuild')} ${entries}`);
46
+ };
47
+ logBackup = (dir) => {
48
+ if (!this.shouldLogActions())
49
+ return;
50
+ log(`${this.logPrefix()} ${cyan(dir)}> ${brightYellow('backup')}`);
51
+ };
52
+ logRestore = (dir) => {
53
+ if (!this.shouldLogActions())
54
+ return;
55
+ log(`${this.logPrefix()} ${cyan(dir)}> ${brightYellow('restore')}`);
56
+ };
57
+ }
58
+ let logger = new Logger({ dryRun: false, verbose: false, rootDir: '' });
59
+ export function initLogger(opts) {
60
+ logger = new Logger(opts);
61
+ }
62
+ export function logCommand(command, args, cwd) {
63
+ logger.logCommand(command, args, cwd);
64
+ }
65
+ export function logDelete(targetPath) {
66
+ logger.logDelete(targetPath);
67
+ }
68
+ export function logWriteFile(filePath) {
69
+ logger.logWriteFile(filePath);
70
+ }
71
+ export function logEsbuild(entryPoints, cwd) {
72
+ logger.logEsbuild(entryPoints, cwd);
73
+ }
74
+ export function logBackup(dir) {
75
+ logger.logBackup(dir);
76
+ }
77
+ export function logRestore(dir) {
78
+ logger.logRestore(dir);
79
+ }