@mxpicture/build-api 0.2.56 → 0.2.57
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/barrel/Barrel.d.ts +66 -0
- package/dist/barrel/Barrel.d.ts.map +1 -1
- package/dist/barrel/Barrel.js +66 -2
- package/dist/barrel/Barrel.js.map +1 -1
- package/dist/cleanup/Cleanup.d.ts +70 -0
- package/dist/cleanup/Cleanup.d.ts.map +1 -1
- package/dist/cleanup/Cleanup.js +70 -0
- package/dist/cleanup/Cleanup.js.map +1 -1
- package/dist/code/code.common.d.ts +37 -4
- package/dist/code/code.common.d.ts.map +1 -1
- package/dist/code/code.common.js +37 -4
- package/dist/code/code.common.js.map +1 -1
- package/dist/code/code.exports.d.ts +25 -0
- package/dist/code/code.exports.d.ts.map +1 -1
- package/dist/code/code.exports.js +25 -1
- package/dist/code/code.exports.js.map +1 -1
- package/dist/code/code.format.d.ts +23 -0
- package/dist/code/code.format.d.ts.map +1 -1
- package/dist/code/code.format.js +23 -0
- package/dist/code/code.format.js.map +1 -1
- package/dist/common/common.fs.d.ts +22 -0
- package/dist/common/common.fs.d.ts.map +1 -1
- package/dist/common/common.fs.js +22 -0
- package/dist/common/common.fs.js.map +1 -1
- package/dist/common/common.json.d.ts +27 -0
- package/dist/common/common.json.d.ts.map +1 -1
- package/dist/common/common.json.js +27 -0
- package/dist/common/common.json.js.map +1 -1
- package/dist/deps/FixWorkspaceDeps.d.ts +132 -0
- package/dist/deps/FixWorkspaceDeps.d.ts.map +1 -1
- package/dist/deps/FixWorkspaceDeps.js +120 -2
- package/dist/deps/FixWorkspaceDeps.js.map +1 -1
- package/dist/git/GitChanges.d.ts +60 -13
- package/dist/git/GitChanges.d.ts.map +1 -1
- package/dist/git/GitChanges.js +60 -13
- package/dist/git/GitChanges.js.map +1 -1
- package/dist/git/git.util.d.ts +58 -3
- package/dist/git/git.util.d.ts.map +1 -1
- package/dist/git/git.util.js +58 -3
- package/dist/git/git.util.js.map +1 -1
- package/dist/logger/Logger.d.ts +74 -0
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +49 -0
- package/dist/logger/Logger.js.map +1 -1
- package/dist/npmPublish/NpmPublisher.d.ts +36 -0
- package/dist/npmPublish/NpmPublisher.d.ts.map +1 -1
- package/dist/npmPublish/NpmPublisher.js +36 -0
- package/dist/npmPublish/NpmPublisher.js.map +1 -1
- package/dist/osInfo/osInfo.common.d.ts +45 -1
- package/dist/osInfo/osInfo.common.d.ts.map +1 -1
- package/dist/osInfo/osInfo.common.js +45 -1
- package/dist/osInfo/osInfo.common.js.map +1 -1
- package/dist/pkg/Pkg.d.ts +69 -0
- package/dist/pkg/Pkg.d.ts.map +1 -1
- package/dist/pkg/Pkg.js +69 -0
- package/dist/pkg/Pkg.js.map +1 -1
- package/dist/pkg/SyncPkgVersion.d.ts +35 -0
- package/dist/pkg/SyncPkgVersion.d.ts.map +1 -1
- package/dist/pkg/SyncPkgVersion.js +35 -0
- package/dist/pkg/SyncPkgVersion.js.map +1 -1
- package/dist/pkg/UpdatePackages.d.ts +36 -0
- package/dist/pkg/UpdatePackages.d.ts.map +1 -1
- package/dist/pkg/UpdatePackages.js +36 -0
- package/dist/pkg/UpdatePackages.js.map +1 -1
- package/dist/pkg/pkg.common.d.ts +73 -0
- package/dist/pkg/pkg.common.d.ts.map +1 -1
- package/dist/pkg/pkg.common.js +73 -0
- package/dist/pkg/pkg.common.js.map +1 -1
- package/dist/pkg/pkg.fs.d.ts +53 -0
- package/dist/pkg/pkg.fs.d.ts.map +1 -1
- package/dist/pkg/pkg.fs.js +53 -0
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/types/types.barrel.d.ts +28 -0
- package/dist/types/types.barrel.d.ts.map +1 -1
- package/dist/types/types.barrel.js.map +1 -1
- package/dist/types/types.changelog.d.ts +28 -0
- package/dist/types/types.changelog.d.ts.map +1 -1
- package/dist/types/types.changelog.js +9 -0
- package/dist/types/types.changelog.js.map +1 -1
- package/dist/types/types.cleanup.d.ts +19 -0
- package/dist/types/types.cleanup.d.ts.map +1 -1
- package/dist/types/types.cleanup.js.map +1 -1
- package/dist/types/types.code.d.ts +36 -0
- package/dist/types/types.code.d.ts.map +1 -1
- package/dist/types/types.code.js.map +1 -1
- package/dist/types/types.deps.d.ts +27 -0
- package/dist/types/types.deps.d.ts.map +1 -1
- package/dist/types/types.deps.js +10 -0
- package/dist/types/types.deps.js.map +1 -1
- package/dist/types/types.documents.d.ts +9 -0
- package/dist/types/types.documents.d.ts.map +1 -1
- package/dist/types/types.documents.js.map +1 -1
- package/dist/types/types.git.d.ts +25 -0
- package/dist/types/types.git.d.ts.map +1 -1
- package/dist/types/types.git.js.map +1 -1
- package/dist/types/types.npm.d.ts +7 -0
- package/dist/types/types.npm.d.ts.map +1 -1
- package/dist/types/types.npm.js.map +1 -1
- package/dist/types/types.os.d.ts +8 -0
- package/dist/types/types.os.d.ts.map +1 -1
- package/dist/types/types.os.js.map +1 -1
- package/dist/types/types.package.d.ts +48 -0
- package/dist/types/types.package.d.ts.map +1 -1
- package/dist/types/types.package.js.map +1 -1
- package/dist/types/types.run.d.ts +4 -0
- package/dist/types/types.run.d.ts.map +1 -1
- package/dist/types/types.run.js.map +1 -1
- package/dist/types/types.vscode.d.ts +46 -0
- package/dist/types/types.vscode.d.ts.map +1 -1
- package/dist/types/types.vscode.js.map +1 -1
- package/dist/types/types.workspace.d.ts +18 -0
- package/dist/types/types.workspace.d.ts.map +1 -1
- package/dist/types/types.workspace.js +6 -0
- package/dist/types/types.workspace.js.map +1 -1
- package/dist/vscode/vscode.config.d.ts +18 -0
- package/dist/vscode/vscode.config.d.ts.map +1 -1
- package/dist/vscode/vscode.config.js +18 -0
- package/dist/vscode/vscode.config.js.map +1 -1
- package/dist/vscode/vscode.profiles.d.ts +37 -0
- package/dist/vscode/vscode.profiles.d.ts.map +1 -1
- package/dist/vscode/vscode.profiles.js +37 -0
- package/dist/vscode/vscode.profiles.js.map +1 -1
- package/dist/vscode/vscode.settings.d.ts +26 -1
- package/dist/vscode/vscode.settings.d.ts.map +1 -1
- package/dist/vscode/vscode.settings.js +26 -1
- package/dist/vscode/vscode.settings.js.map +1 -1
- package/dist/vscode/vscode.storage.d.ts +21 -1
- package/dist/vscode/vscode.storage.d.ts.map +1 -1
- package/dist/vscode/vscode.storage.js +21 -1
- package/dist/vscode/vscode.storage.js.map +1 -1
- package/dist/vscode/vscode.workspace.d.ts +17 -0
- package/dist/vscode/vscode.workspace.d.ts.map +1 -1
- package/dist/vscode/vscode.workspace.js +17 -0
- package/dist/vscode/vscode.workspace.js.map +1 -1
- package/dist/workspace/Workspace.d.ts +85 -0
- package/dist/workspace/Workspace.d.ts.map +1 -1
- package/dist/workspace/Workspace.js +85 -0
- package/dist/workspace/Workspace.js.map +1 -1
- package/dist/workspace/workspace.common.d.ts +42 -1
- package/dist/workspace/workspace.common.d.ts.map +1 -1
- package/dist/workspace/workspace.common.js +42 -1
- package/dist/workspace/workspace.common.js.map +1 -1
- package/package.json +1 -1
package/dist/git/git.util.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { simpleGit } from "simple-git";
|
|
2
2
|
const __entries = [];
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Returns a verified {@link SimpleGit} instance for the given repository root.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Instances are cached by `rootDir` and `commitRef` pair. On the first call
|
|
8
|
+
* for a given pair the function verifies that `rootDir` is a git repository
|
|
9
|
+
* and, when supplied, that `commitRef` resolves to a valid object.
|
|
10
|
+
*
|
|
11
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
12
|
+
* @param commitRef - Optional git ref (SHA, tag, branch) to validate.
|
|
13
|
+
* @returns A {@link SimpleGit} instance bound to `rootDir`.
|
|
14
|
+
* @throws If `rootDir` is not a git repository or `commitRef` is invalid.
|
|
6
15
|
*/
|
|
7
16
|
export const verifiedGit = async (rootDir, commitRef) => {
|
|
8
17
|
let found = __entries.find((entry) => entry.rootDir === rootDir && entry.commitRef === commitRef);
|
|
@@ -25,14 +34,52 @@ const verifyGit = async (git, rootDir, commitRef) => {
|
|
|
25
34
|
}
|
|
26
35
|
return { git, rootDir, commitRef };
|
|
27
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the most recent tag in the repository.
|
|
39
|
+
*
|
|
40
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
41
|
+
* @returns The name of the latest tag, or `null` if no tags exist.
|
|
42
|
+
*/
|
|
28
43
|
export const lastTag = async (rootDir) => (await (await verifiedGit(rootDir)).tags()).latest ?? null;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves all tags in the repository.
|
|
46
|
+
*
|
|
47
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
48
|
+
* @returns An array of tag names.
|
|
49
|
+
*/
|
|
29
50
|
export const tags = async (rootDir) => (await (await verifiedGit(rootDir)).tags()).all;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the hash of the most recent commit on the current branch.
|
|
53
|
+
*
|
|
54
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
55
|
+
* @returns The SHA hash of the latest commit, or `null` if the log is empty.
|
|
56
|
+
*/
|
|
30
57
|
export const lastCommitHash = async (rootDir) => (await (await verifiedGit(rootDir)).log()).latest?.hash ?? null;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the full commit log as an array of {@link GitCommitHash} objects.
|
|
60
|
+
*
|
|
61
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
62
|
+
* @returns An array of commit hashes with dates and optional diff data.
|
|
63
|
+
*/
|
|
31
64
|
export const commitHashs = async (rootDir) => (await (await verifiedGit(rootDir)).log()).all.map((a) => ({
|
|
32
65
|
date: a.date,
|
|
33
66
|
hash: a.hash,
|
|
34
67
|
diff: a.diff,
|
|
35
68
|
}));
|
|
69
|
+
/**
|
|
70
|
+
* Resolves a git reference, falling back to a secondary ref if the primary is invalid.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Attempts to verify `ref` against the repository. If verification fails
|
|
74
|
+
* (e.g. the ref does not exist), `fallback` is verified and returned instead.
|
|
75
|
+
* An error is thrown only when *both* refs are invalid.
|
|
76
|
+
*
|
|
77
|
+
* @param ref - The preferred git reference to validate.
|
|
78
|
+
* @param fallback - A fallback git reference used when `ref` is invalid.
|
|
79
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
80
|
+
* @returns The verified git reference string (`ref` or `fallback`).
|
|
81
|
+
* @throws If neither `ref` nor `fallback` resolves to a valid git object.
|
|
82
|
+
*/
|
|
36
83
|
export const ensureCommitRef = async (ref, fallback, rootDir) => {
|
|
37
84
|
try {
|
|
38
85
|
await verifiedGit(rootDir, ref);
|
|
@@ -43,7 +90,15 @@ export const ensureCommitRef = async (ref, fallback, rootDir) => {
|
|
|
43
90
|
return fallback;
|
|
44
91
|
}
|
|
45
92
|
};
|
|
46
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Resets the internal cache of verified git entries.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* This is intended for test cleanup only and should never be called in
|
|
98
|
+
* production code.
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
47
102
|
export const __resetGitEntries = () => {
|
|
48
103
|
__entries.length = 0;
|
|
49
104
|
};
|
package/dist/git/git.util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.util.js","sourceRoot":"","sources":["../../src/git/git.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AASlD,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"git.util.js","sourceRoot":"","sources":["../../src/git/git.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AASlD,MAAM,SAAS,G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pC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import { SimpleGit, simpleGit } from \"simple-git\";\nimport { GitCommitHash } from \"../types/types.git.js\";\n\ninterface GitEntry {\n git: SimpleGit;\n rootDir: string;\n commitRef?: string;\n}\n\nconst __entries: GitEntry[] = [];\n\n/**\n * Returns a verified {@link SimpleGit} instance for the given repository root.\n *\n * @remarks\n * Instances are cached by `rootDir` and `commitRef` pair. On the first call\n * for a given pair the function verifies that `rootDir` is a git repository\n * and, when supplied, that `commitRef` resolves to a valid object.\n *\n * @param rootDir - Absolute path to the repository working directory.\n * @param commitRef - Optional git ref (SHA, tag, branch) to validate.\n * @returns A {@link SimpleGit} instance bound to `rootDir`.\n * @throws If `rootDir` is not a git repository or `commitRef` is invalid.\n */\nexport const verifiedGit = async (\n rootDir: string,\n commitRef?: string,\n): Promise<SimpleGit> => {\n let found = __entries.find(\n (entry) => entry.rootDir === rootDir && entry.commitRef === commitRef,\n );\n if (!found) {\n found = await verifyGit(simpleGit(rootDir), rootDir, commitRef);\n __entries.push(found);\n }\n\n return found.git;\n};\n\nconst verifyGit = async (\n git: SimpleGit,\n rootDir: string,\n commitRef?: string,\n): Promise<GitEntry> => {\n if (!(await git.checkIsRepo()))\n throw new Error(`Not a git repository: ${rootDir}`);\n\n if (!commitRef) return { git, rootDir, commitRef };\n\n try {\n await git.revparse([\"--verify\", commitRef]);\n } catch {\n throw new Error(`Invalid git commit reference: \"${commitRef}\"`);\n }\n\n return { git, rootDir, commitRef };\n};\n\n/**\n * Retrieves the most recent tag in the repository.\n *\n * @param rootDir - Absolute path to the repository working directory.\n * @returns The name of the latest tag, or `null` if no tags exist.\n */\nexport const lastTag = async (rootDir: string): Promise<string | null> =>\n (await (await verifiedGit(rootDir)).tags()).latest ?? null;\n\n/**\n * Retrieves all tags in the repository.\n *\n * @param rootDir - Absolute path to the repository working directory.\n * @returns An array of tag names.\n */\nexport const tags = async (rootDir: string): Promise<string[]> =>\n (await (await verifiedGit(rootDir)).tags()).all;\n\n/**\n * Retrieves the hash of the most recent commit on the current branch.\n *\n * @param rootDir - Absolute path to the repository working directory.\n * @returns The SHA hash of the latest commit, or `null` if the log is empty.\n */\nexport const lastCommitHash = async (rootDir: string): Promise<string | null> =>\n (await (await verifiedGit(rootDir)).log()).latest?.hash ?? null;\n\n/**\n * Retrieves the full commit log as an array of {@link GitCommitHash} objects.\n *\n * @param rootDir - Absolute path to the repository working directory.\n * @returns An array of commit hashes with dates and optional diff data.\n */\nexport const commitHashs = async (rootDir: string): Promise<GitCommitHash[]> =>\n (await (await verifiedGit(rootDir)).log()).all.map((a) => ({\n date: a.date,\n hash: a.hash,\n diff: a.diff,\n }));\n\n/**\n * Resolves a git reference, falling back to a secondary ref if the primary is invalid.\n *\n * @remarks\n * Attempts to verify `ref` against the repository. If verification fails\n * (e.g. the ref does not exist), `fallback` is verified and returned instead.\n * An error is thrown only when *both* refs are invalid.\n *\n * @param ref - The preferred git reference to validate.\n * @param fallback - A fallback git reference used when `ref` is invalid.\n * @param rootDir - Absolute path to the repository working directory.\n * @returns The verified git reference string (`ref` or `fallback`).\n * @throws If neither `ref` nor `fallback` resolves to a valid git object.\n */\nexport const ensureCommitRef = async (\n ref: string,\n fallback: string,\n rootDir: string,\n): Promise<string> => {\n try {\n await verifiedGit(rootDir, ref);\n return ref;\n } catch {\n await verifiedGit(rootDir, fallback);\n return fallback;\n }\n};\n\n/**\n * Resets the internal cache of verified git entries.\n *\n * @remarks\n * This is intended for test cleanup only and should never be called in\n * production code.\n *\n * @internal\n */\nexport const __resetGitEntries = () => {\n __entries.length = 0;\n};\n"]}
|
package/dist/logger/Logger.d.ts
CHANGED
|
@@ -1,14 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that accepts variadic arguments and logs them.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const handler: LoggerHandler = (...data) => console.log(...data);
|
|
7
|
+
* handler("hello", 42);
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
1
10
|
export type LoggerHandler = (...data: any[]) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Logger interface providing success, error, and info logging channels.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const myLogger: Logger = {
|
|
17
|
+
* success: console.log,
|
|
18
|
+
* error: console.error,
|
|
19
|
+
* info: console.log,
|
|
20
|
+
* };
|
|
21
|
+
* initLogger(myLogger);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export interface Logger {
|
|
25
|
+
/** Logs a success message. */
|
|
3
26
|
success: LoggerHandler;
|
|
27
|
+
/** Logs an error message. */
|
|
4
28
|
error: LoggerHandler;
|
|
29
|
+
/** Logs an informational message. */
|
|
5
30
|
info: LoggerHandler;
|
|
6
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Initializes the global logger instance.
|
|
34
|
+
*
|
|
35
|
+
* @param log - The {@link Logger} implementation to use globally.
|
|
36
|
+
* @returns The logger that was set.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* initLogger(consoleLogger);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
7
43
|
export declare const initLogger: (log: Logger) => Logger;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the current global logger, falling back to {@link silentLogger} if none has been initialized.
|
|
46
|
+
*
|
|
47
|
+
* @returns The active {@link Logger} instance.
|
|
48
|
+
*/
|
|
8
49
|
export declare const logger: () => Logger;
|
|
50
|
+
/**
|
|
51
|
+
* Logs a success message through the global logger.
|
|
52
|
+
*
|
|
53
|
+
* @param data - The values to log.
|
|
54
|
+
*/
|
|
9
55
|
export declare const logSuccess: LoggerHandler;
|
|
56
|
+
/**
|
|
57
|
+
* Logs an error message through the global logger.
|
|
58
|
+
*
|
|
59
|
+
* @param data - The values to log.
|
|
60
|
+
*/
|
|
10
61
|
export declare const logError: LoggerHandler;
|
|
62
|
+
/**
|
|
63
|
+
* Logs an informational message through the global logger.
|
|
64
|
+
*
|
|
65
|
+
* @param data - The values to log.
|
|
66
|
+
*/
|
|
11
67
|
export declare const logInfo: LoggerHandler;
|
|
68
|
+
/**
|
|
69
|
+
* A logger that silently discards all messages.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* initLogger(silentLogger);
|
|
74
|
+
* logInfo("this is discarded");
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
12
77
|
export declare const silentLogger: Logger;
|
|
78
|
+
/**
|
|
79
|
+
* A logger that writes to the console using {@link console.log} and {@link console.error}.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* initLogger(consoleLogger);
|
|
84
|
+
* logSuccess("build complete");
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
13
87
|
export declare const consoleLogger: Logger;
|
|
14
88
|
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/logger/Logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/logger/Logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,MAAM;IACrB,8BAA8B;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB,6BAA6B;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,qCAAqC;IACrC,IAAI,EAAE,aAAa,CAAC;CACrB;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,WAAqB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAO,MAAkC,CAAC;AAE7D;;;;GAIG;AAEH,eAAO,MAAM,UAAU,EAAE,aACE,CAAC;AAE5B;;;;GAIG;AAEH,eAAO,MAAM,QAAQ,EAAE,aACE,CAAC;AAE1B;;;;GAIG;AAEH,eAAO,MAAM,OAAO,EAAE,aACE,CAAC;AAEzB;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,MAI1B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,MAI3B,CAAC"}
|
package/dist/logger/Logger.js
CHANGED
|
@@ -1,17 +1,66 @@
|
|
|
1
1
|
let __logger = null;
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the global logger instance.
|
|
4
|
+
*
|
|
5
|
+
* @param log - The {@link Logger} implementation to use globally.
|
|
6
|
+
* @returns The logger that was set.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* initLogger(consoleLogger);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
2
13
|
export const initLogger = (log) => (__logger = log);
|
|
14
|
+
/**
|
|
15
|
+
* Returns the current global logger, falling back to {@link silentLogger} if none has been initialized.
|
|
16
|
+
*
|
|
17
|
+
* @returns The active {@link Logger} instance.
|
|
18
|
+
*/
|
|
3
19
|
export const logger = () => __logger ?? silentLogger;
|
|
20
|
+
/**
|
|
21
|
+
* Logs a success message through the global logger.
|
|
22
|
+
*
|
|
23
|
+
* @param data - The values to log.
|
|
24
|
+
*/
|
|
4
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
26
|
export const logSuccess = (...data) => logger().success(...data);
|
|
27
|
+
/**
|
|
28
|
+
* Logs an error message through the global logger.
|
|
29
|
+
*
|
|
30
|
+
* @param data - The values to log.
|
|
31
|
+
*/
|
|
6
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
33
|
export const logError = (...data) => logger().error(...data);
|
|
34
|
+
/**
|
|
35
|
+
* Logs an informational message through the global logger.
|
|
36
|
+
*
|
|
37
|
+
* @param data - The values to log.
|
|
38
|
+
*/
|
|
8
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
40
|
export const logInfo = (...data) => logger().info(...data);
|
|
41
|
+
/**
|
|
42
|
+
* A logger that silently discards all messages.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* initLogger(silentLogger);
|
|
47
|
+
* logInfo("this is discarded");
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
10
50
|
export const silentLogger = {
|
|
11
51
|
success: () => { },
|
|
12
52
|
error: () => { },
|
|
13
53
|
info: () => { },
|
|
14
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* A logger that writes to the console using {@link console.log} and {@link console.error}.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* initLogger(consoleLogger);
|
|
61
|
+
* logSuccess("build complete");
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
15
64
|
export const consoleLogger = {
|
|
16
65
|
success: console.log,
|
|
17
66
|
error: console.error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/logger/Logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/logger/Logger.ts"],"names":[],"mappings":"AAkCA,IAAI,QAAQ,GAAkB,IAAI,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAW,EAAE,CAAC,QAAQ,IAAI,YAAY,CAAC;AAE7D;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAkB,CAAC,GAAG,IAAW,EAAQ,EAAE,CAChE,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAE5B;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAkB,CAAC,GAAG,IAAW,EAAQ,EAAE,CAC9D,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;AAE1B;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,OAAO,GAAkB,CAAC,GAAG,IAAW,EAAQ,EAAE,CAC7D,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;CACf,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,OAAO,EAAE,OAAO,CAAC,GAAG;IACpB,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,GAAG;CAClB,CAAC","sourcesContent":["/**\n * A function that accepts variadic arguments and logs them.\n *\n * @example\n * ```ts\n * const handler: LoggerHandler = (...data) => console.log(...data);\n * handler(\"hello\", 42);\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type LoggerHandler = (...data: any[]) => void;\n\n/**\n * Logger interface providing success, error, and info logging channels.\n *\n * @example\n * ```ts\n * const myLogger: Logger = {\n * success: console.log,\n * error: console.error,\n * info: console.log,\n * };\n * initLogger(myLogger);\n * ```\n */\nexport interface Logger {\n /** Logs a success message. */\n success: LoggerHandler;\n /** Logs an error message. */\n error: LoggerHandler;\n /** Logs an informational message. */\n info: LoggerHandler;\n}\n\nlet __logger: Logger | null = null;\n\n/**\n * Initializes the global logger instance.\n *\n * @param log - The {@link Logger} implementation to use globally.\n * @returns The logger that was set.\n *\n * @example\n * ```ts\n * initLogger(consoleLogger);\n * ```\n */\nexport const initLogger = (log: Logger) => (__logger = log);\n\n/**\n * Returns the current global logger, falling back to {@link silentLogger} if none has been initialized.\n *\n * @returns The active {@link Logger} instance.\n */\nexport const logger = (): Logger => __logger ?? silentLogger;\n\n/**\n * Logs a success message through the global logger.\n *\n * @param data - The values to log.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const logSuccess: LoggerHandler = (...data: any[]): void =>\n logger().success(...data);\n\n/**\n * Logs an error message through the global logger.\n *\n * @param data - The values to log.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const logError: LoggerHandler = (...data: any[]): void =>\n logger().error(...data);\n\n/**\n * Logs an informational message through the global logger.\n *\n * @param data - The values to log.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const logInfo: LoggerHandler = (...data: any[]): void =>\n logger().info(...data);\n\n/**\n * A logger that silently discards all messages.\n *\n * @example\n * ```ts\n * initLogger(silentLogger);\n * logInfo(\"this is discarded\");\n * ```\n */\nexport const silentLogger: Logger = {\n success: () => {},\n error: () => {},\n info: () => {},\n};\n\n/**\n * A logger that writes to the console using {@link console.log} and {@link console.error}.\n *\n * @example\n * ```ts\n * initLogger(consoleLogger);\n * logSuccess(\"build complete\");\n * ```\n */\nexport const consoleLogger: Logger = {\n success: console.log,\n error: console.error,\n info: console.log,\n};\n"]}
|
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { NpmPublisherParams } from "../types/types.npm.js";
|
|
2
2
|
import { Pkg } from "../pkg/Pkg.js";
|
|
3
|
+
/**
|
|
4
|
+
* Publishes all non-private workspace packages to the npm registry.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Initialises the workspace from the given repository root, then delegates
|
|
8
|
+
* to {@link NpmPublisher.run} which publishes every public package in
|
|
9
|
+
* parallel. Already-published versions are automatically skipped.
|
|
10
|
+
*
|
|
11
|
+
* @param params - Publisher parameters containing the repository root path.
|
|
12
|
+
* @returns A promise that resolves when all packages have been processed.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* await runNpmPublisher({ repoRoot: "/path/to/repo" });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare const runNpmPublisher: (params: NpmPublisherParams) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Publishes workspace packages to the npm registry.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Reads every package from the current workspace, attempts to publish each
|
|
25
|
+
* non-private package in parallel via `npm publish --access public`, and
|
|
26
|
+
* exits the process with code 1 if any publication fails. Packages whose
|
|
27
|
+
* exact version is already on the registry are silently skipped.
|
|
28
|
+
*/
|
|
4
29
|
export declare class NpmPublisher {
|
|
30
|
+
/** Creates a new {@link NpmPublisher} instance. */
|
|
5
31
|
constructor();
|
|
32
|
+
/**
|
|
33
|
+
* Publishes all non-private workspace packages.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Each package is published concurrently using `Promise.allSettled`.
|
|
37
|
+
* If one or more packages fail, the errors are logged and the process
|
|
38
|
+
* exits with code 1.
|
|
39
|
+
*
|
|
40
|
+
* @returns A promise that resolves when all publish attempts have settled.
|
|
41
|
+
*/
|
|
6
42
|
run(): Promise<void>;
|
|
7
43
|
protected runPackage(pkg: Pkg): Promise<void>;
|
|
8
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NpmPublisher.d.ts","sourceRoot":"","sources":["../../src/npmPublish/NpmPublisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,eAAO,MAAM,eAAe,GAAU,QAAQ,kBAAkB,kBAG/D,CAAC;AAEF,qBAAa,YAAY;;
|
|
1
|
+
{"version":3,"file":"NpmPublisher.d.ts","sourceRoot":"","sources":["../../src/npmPublish/NpmPublisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAAU,QAAQ,kBAAkB,kBAG/D,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,YAAY;IACvB,mDAAmD;;IAGnD;;;;;;;;;OASG;IACU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;cAiBjB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAkCpD"}
|
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
import { logError, logInfo, logSuccess } from "../logger/Logger.js";
|
|
2
2
|
import { execAsync } from "../common/common.fs.js";
|
|
3
3
|
import { initWorkspace, workspace } from "../workspace/Workspace.js";
|
|
4
|
+
/**
|
|
5
|
+
* Publishes all non-private workspace packages to the npm registry.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Initialises the workspace from the given repository root, then delegates
|
|
9
|
+
* to {@link NpmPublisher.run} which publishes every public package in
|
|
10
|
+
* parallel. Already-published versions are automatically skipped.
|
|
11
|
+
*
|
|
12
|
+
* @param params - Publisher parameters containing the repository root path.
|
|
13
|
+
* @returns A promise that resolves when all packages have been processed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* await runNpmPublisher({ repoRoot: "/path/to/repo" });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
4
20
|
export const runNpmPublisher = async (params) => {
|
|
5
21
|
initWorkspace(params.repoRoot);
|
|
6
22
|
return new NpmPublisher().run();
|
|
7
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Publishes workspace packages to the npm registry.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Reads every package from the current workspace, attempts to publish each
|
|
29
|
+
* non-private package in parallel via `npm publish --access public`, and
|
|
30
|
+
* exits the process with code 1 if any publication fails. Packages whose
|
|
31
|
+
* exact version is already on the registry are silently skipped.
|
|
32
|
+
*/
|
|
8
33
|
export class NpmPublisher {
|
|
34
|
+
/** Creates a new {@link NpmPublisher} instance. */
|
|
9
35
|
constructor() { }
|
|
36
|
+
/**
|
|
37
|
+
* Publishes all non-private workspace packages.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Each package is published concurrently using `Promise.allSettled`.
|
|
41
|
+
* If one or more packages fail, the errors are logged and the process
|
|
42
|
+
* exits with code 1.
|
|
43
|
+
*
|
|
44
|
+
* @returns A promise that resolves when all publish attempts have settled.
|
|
45
|
+
*/
|
|
10
46
|
async run() {
|
|
11
47
|
const pkgs = (await workspace().read()).packages;
|
|
12
48
|
const results = await Promise.allSettled(pkgs.map((d) => this.runPackage(d)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NpmPublisher.js","sourceRoot":"","sources":["../../src/npmPublish/NpmPublisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,MAA0B,EAAE,EAAE;IAClE,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/B,OAAO,IAAI,YAAY,EAAE,CAAC,GAAG,EAAE,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,OAAO,YAAY;IACvB,gBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"NpmPublisher.js","sourceRoot":"","sources":["../../src/npmPublish/NpmPublisher.ts"],"names":[],"mappings":"AAAA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port { NpmPublisherParams } from \"../types/types.npm.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\n\n/**\n * Publishes all non-private workspace packages to the npm registry.\n *\n * @remarks\n * Initialises the workspace from the given repository root, then delegates\n * to {@link NpmPublisher.run} which publishes every public package in\n * parallel. Already-published versions are automatically skipped.\n *\n * @param params - Publisher parameters containing the repository root path.\n * @returns A promise that resolves when all packages have been processed.\n *\n * @example\n * ```ts\n * await runNpmPublisher({ repoRoot: \"/path/to/repo\" });\n * ```\n */\nexport const runNpmPublisher = async (params: NpmPublisherParams) => {\n initWorkspace(params.repoRoot);\n return new NpmPublisher().run();\n};\n\n/**\n * Publishes workspace packages to the npm registry.\n *\n * @remarks\n * Reads every package from the current workspace, attempts to publish each\n * non-private package in parallel via `npm publish --access public`, and\n * exits the process with code 1 if any publication fails. Packages whose\n * exact version is already on the registry are silently skipped.\n */\nexport class NpmPublisher {\n /** Creates a new {@link NpmPublisher} instance. */\n public constructor() {}\n\n /**\n * Publishes all non-private workspace packages.\n *\n * @remarks\n * Each package is published concurrently using `Promise.allSettled`.\n * If one or more packages fail, the errors are logged and the process\n * exits with code 1.\n *\n * @returns A promise that resolves when all publish attempts have settled.\n */\n public async run(): Promise<void> {\n const pkgs = (await workspace().read()).packages;\n\n const results = await Promise.allSettled(\n pkgs.map((d) => this.runPackage(d)),\n );\n\n const failures = results.filter((r) => r.status === \"rejected\");\n if (failures.length > 0) {\n logError(`\\n❌ ${failures.length} package(s) failed to publish:`);\n failures.forEach((failure) => {\n logError(failure.reason);\n });\n process.exit(1);\n }\n }\n\n protected async runPackage(pkg: Pkg): Promise<void> {\n if (pkg.content.private) return;\n const { name, version } = pkg.content;\n\n logInfo(\n `📦 Publishing ${name}@${version} ... (${new Date().toISOString()})`,\n );\n\n // Check if this exact version is already published\n try {\n const { stdout } = await execAsync(`npm view ${name}@${version} version`);\n const published = stdout.trim();\n\n if (published === version) {\n logInfo(`⏭️ ${name}@${version} already published, skipping.`);\n return;\n }\n } catch {\n // npm view exits non-zero if the package/version doesn't exist — means we should publish\n }\n\n try {\n await execAsync(\"npm publish --access public\", {\n cwd: pkg.dirPath,\n });\n logSuccess(\n `✅ ${name}@${version} published successfully (${new Date().toISOString()}).`,\n );\n } catch (err) {\n const errorMessage = `Failed to publish ${name}@${version} (${new Date().toISOString()})`;\n logError(`❌ ${errorMessage}`);\n throw new Error(errorMessage, { cause: err });\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,51 @@
|
|
|
1
1
|
import { OSInfo } from "../types/types.os.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current operating-system information, creating it on first call.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The result is lazily computed and cached for the lifetime of the process.
|
|
7
|
+
* On WSL environments (detected via the kernel release string) the info is
|
|
8
|
+
* sourced from the Windows host; otherwise the native Node.js APIs are used.
|
|
9
|
+
*
|
|
10
|
+
* @returns The cached {@link OSInfo} for the current environment.
|
|
11
|
+
* @throws {Error} If OS information cannot be determined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const info = osInfo();
|
|
16
|
+
* console.log(info.platform, info.homedir);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
2
19
|
export declare const osInfo: () => OSInfo;
|
|
20
|
+
/**
|
|
21
|
+
* Builds OS information using native Node.js APIs.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Resolves the platform-specific application configuration directory:
|
|
25
|
+
* - **Windows** (`win32`): `%APPDATA%`
|
|
26
|
+
* - **macOS** (`darwin`): `~/Library/Application Support`
|
|
27
|
+
* - **Linux / other**: `~/.config`
|
|
28
|
+
*
|
|
29
|
+
* @returns An {@link OSInfo} object for the current (non-WSL) environment.
|
|
30
|
+
*/
|
|
3
31
|
export declare const defaultInfo: () => OSInfo;
|
|
32
|
+
/**
|
|
33
|
+
* Builds OS information for a Windows Subsystem for Linux (WSL) environment.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Calls `whoami.exe` to determine the Windows username, then constructs
|
|
37
|
+
* paths that point into the Windows file system mounted under `/mnt/c`.
|
|
38
|
+
* The returned {@link OSInfo.isWSL} flag is always `true`.
|
|
39
|
+
*
|
|
40
|
+
* @returns An {@link OSInfo} object reflecting the Windows host environment.
|
|
41
|
+
* @throws {Error} If the Windows username cannot be determined from `whoami.exe`.
|
|
42
|
+
*/
|
|
4
43
|
export declare const wslInfo: () => OSInfo;
|
|
5
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Resets the cached OS information so the next call to {@link osInfo} recomputes it.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
* This function is intended for testing purposes only.
|
|
49
|
+
*/
|
|
6
50
|
export declare const __resetOsInfo: () => void;
|
|
7
51
|
//# sourceMappingURL=osInfo.common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osInfo.common.d.ts","sourceRoot":"","sources":["../../src/osInfo/osInfo.common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAM9C,eAAO,MAAM,MAAM,QAAO,MAOzB,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,MAmB9B,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,MAuB1B,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"osInfo.common.d.ts","sourceRoot":"","sources":["../../src/osInfo/osInfo.common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAM9C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,QAAO,MAOzB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,QAAO,MAmB9B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,QAAO,MAuB1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,YAEzB,CAAC"}
|
|
@@ -2,6 +2,23 @@ import { join, sep } from "node:path";
|
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import { execSync } from "node:child_process";
|
|
4
4
|
let __info = null;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current operating-system information, creating it on first call.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The result is lazily computed and cached for the lifetime of the process.
|
|
10
|
+
* On WSL environments (detected via the kernel release string) the info is
|
|
11
|
+
* sourced from the Windows host; otherwise the native Node.js APIs are used.
|
|
12
|
+
*
|
|
13
|
+
* @returns The cached {@link OSInfo} for the current environment.
|
|
14
|
+
* @throws {Error} If OS information cannot be determined.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const info = osInfo();
|
|
19
|
+
* console.log(info.platform, info.homedir);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
5
22
|
export const osInfo = () => {
|
|
6
23
|
if (!__info) {
|
|
7
24
|
const isWSL = os.release().toLowerCase().includes("microsoft");
|
|
@@ -11,6 +28,17 @@ export const osInfo = () => {
|
|
|
11
28
|
}
|
|
12
29
|
return __info;
|
|
13
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Builds OS information using native Node.js APIs.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Resolves the platform-specific application configuration directory:
|
|
36
|
+
* - **Windows** (`win32`): `%APPDATA%`
|
|
37
|
+
* - **macOS** (`darwin`): `~/Library/Application Support`
|
|
38
|
+
* - **Linux / other**: `~/.config`
|
|
39
|
+
*
|
|
40
|
+
* @returns An {@link OSInfo} object for the current (non-WSL) environment.
|
|
41
|
+
*/
|
|
14
42
|
export const defaultInfo = () => {
|
|
15
43
|
const platform = process.platform;
|
|
16
44
|
const homedir = os.homedir();
|
|
@@ -32,6 +60,17 @@ export const defaultInfo = () => {
|
|
|
32
60
|
configDir: join(...configDirParts),
|
|
33
61
|
};
|
|
34
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Builds OS information for a Windows Subsystem for Linux (WSL) environment.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Calls `whoami.exe` to determine the Windows username, then constructs
|
|
68
|
+
* paths that point into the Windows file system mounted under `/mnt/c`.
|
|
69
|
+
* The returned {@link OSInfo.isWSL} flag is always `true`.
|
|
70
|
+
*
|
|
71
|
+
* @returns An {@link OSInfo} object reflecting the Windows host environment.
|
|
72
|
+
* @throws {Error} If the Windows username cannot be determined from `whoami.exe`.
|
|
73
|
+
*/
|
|
35
74
|
export const wslInfo = () => {
|
|
36
75
|
const whoamiParts = execSync("whoami.exe").toString().split(sep);
|
|
37
76
|
if (whoamiParts.length === 0)
|
|
@@ -54,7 +93,12 @@ export const wslInfo = () => {
|
|
|
54
93
|
isWSL: true,
|
|
55
94
|
};
|
|
56
95
|
};
|
|
57
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Resets the cached OS information so the next call to {@link osInfo} recomputes it.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
* This function is intended for testing purposes only.
|
|
101
|
+
*/
|
|
58
102
|
export const __resetOsInfo = () => {
|
|
59
103
|
__info = null;
|
|
60
104
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osInfo.common.js","sourceRoot":"","sources":["../../src/osInfo/osInfo.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,IAAI,MAAM,GAAkB,IAAI,CAAC;AAEjC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAW,EAAE;IACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,EAAE,CAA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AC,CAAC;IACjE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAE1D,iEAAiE;IACjE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IAAI,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,kBAAkB;IAClB,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxD,MAAM,KAAK,GAAa,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAEtD,OAAO;QACL,QAAQ;QACR,OAAO;QACP,SAAS;QACT,QAAQ;QACR,KAAK,EAAE,IAAI;KACZ,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { join, sep } from \"node:path\";\nimport { OSInfo } from \"../types/types.os.js\";\nimport * as os from \"node:os\";\nimport { execSync } from \"node:child_process\";\n\nlet __info: OSInfo | null = null;\n\n/**\n * Returns the current operating-system information, creating it on first call.\n *\n * @remarks\n * The result is lazily computed and cached for the lifetime of the process.\n * On WSL environments (detected via the kernel release string) the info is\n * sourced from the Windows host; otherwise the native Node.js APIs are used.\n *\n * @returns The cached {@link OSInfo} for the current environment.\n * @throws {Error} If OS information cannot be determined.\n *\n * @example\n * ```ts\n * const info = osInfo();\n * console.log(info.platform, info.homedir);\n * ```\n */\nexport const osInfo = (): OSInfo => {\n if (!__info) {\n const isWSL = os.release().toLowerCase().includes(\"microsoft\");\n __info = isWSL ? wslInfo() : defaultInfo();\n if (!__info) throw new Error(\"Load OS info failed\");\n }\n return __info;\n};\n\n/**\n * Builds OS information using native Node.js APIs.\n *\n * @remarks\n * Resolves the platform-specific application configuration directory:\n * - **Windows** (`win32`): `%APPDATA%`\n * - **macOS** (`darwin`): `~/Library/Application Support`\n * - **Linux / other**: `~/.config`\n *\n * @returns An {@link OSInfo} object for the current (non-WSL) environment.\n */\nexport const defaultInfo = (): OSInfo => {\n const platform = process.platform;\n const homedir = os.homedir();\n const configDirParts: string[] = [];\n\n if (platform === \"win32\") {\n if (process.env.APPDATA) configDirParts.push(process.env.APPDATA);\n } else if (platform === \"darwin\") {\n configDirParts.push(homedir, \"Library\", \"Application Support\");\n } else {\n configDirParts.push(homedir, \".config\");\n }\n\n return {\n username: os.userInfo().username,\n homedir,\n platform,\n configDir: join(...configDirParts),\n };\n};\n\n/**\n * Builds OS information for a Windows Subsystem for Linux (WSL) environment.\n *\n * @remarks\n * Calls `whoami.exe` to determine the Windows username, then constructs\n * paths that point into the Windows file system mounted under `/mnt/c`.\n * The returned {@link OSInfo.isWSL} flag is always `true`.\n *\n * @returns An {@link OSInfo} object reflecting the Windows host environment.\n * @throws {Error} If the Windows username cannot be determined from `whoami.exe`.\n */\nexport const wslInfo = (): OSInfo => {\n const whoamiParts = execSync(\"whoami.exe\").toString().split(sep);\n if (whoamiParts.length === 0)\n throw new Error(\"Windows user could not be determined\");\n\n // const winUser = process.env[\"WINUSER\"] || process.env[\"USER\"];\n const platform = process.platform;\n let username = whoamiParts[whoamiParts.length - 1];\n // remove AD group\n const userParts = username.split(\"\\\\\");\n username = userParts[userParts.length - 1];\n username = username.replace(\"\\r\", \"\").replace(\"\\n\", \"\");\n const parts: string[] = [\"/mnt\", \"c\", \"Users\", username];\n const homedir = join(...parts);\n const configDir = join(homedir, \"AppData\", \"Roaming\");\n\n return {\n username,\n homedir,\n configDir,\n platform,\n isWSL: true,\n };\n};\n\n/**\n * Resets the cached OS information so the next call to {@link osInfo} recomputes it.\n *\n * @internal\n * This function is intended for testing purposes only.\n */\nexport const __resetOsInfo = () => {\n __info = null;\n};\n"]}
|