@eserstack/codebase 0.0.0-stage → 5.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/README.md +301 -2
- package/dist/changelog-gen.d.ts +105 -0
- package/dist/changelog-gen.js +498 -0
- package/dist/changelog-text.d.ts +39 -0
- package/dist/changelog-text.js +82 -0
- package/dist/cli-support.d.ts +140 -0
- package/dist/cli-support.js +244 -0
- package/dist/cli-system/app-opts.d.ts +15 -0
- package/dist/cli-system/app-opts.js +13 -0
- package/dist/cli-system/app.d.ts +29 -0
- package/dist/cli-system/app.js +12 -0
- package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
- package/dist/cli-system/handlers/completions-setup.js +139 -0
- package/dist/cli-system/handlers/completions.d.ts +3 -0
- package/dist/cli-system/handlers/completions.js +79 -0
- package/dist/cli-system/handlers/doctor.d.ts +8 -0
- package/dist/cli-system/handlers/doctor.js +146 -0
- package/dist/cli-system/handlers/info.d.ts +3 -0
- package/dist/cli-system/handlers/info.js +69 -0
- package/dist/cli-system/handlers/install.d.ts +8 -0
- package/dist/cli-system/handlers/install.js +137 -0
- package/dist/cli-system/handlers/mod.d.ts +12 -0
- package/dist/cli-system/handlers/mod.js +13 -0
- package/dist/cli-system/handlers/uninstall.d.ts +3 -0
- package/dist/cli-system/handlers/uninstall.js +60 -0
- package/dist/cli-system/handlers/update.d.ts +76 -0
- package/dist/cli-system/handlers/update.js +310 -0
- package/dist/cli-system/handlers/version-check.d.ts +16 -0
- package/dist/cli-system/handlers/version-check.js +176 -0
- package/dist/cli-system/handlers/version.d.ts +3 -0
- package/dist/cli-system/handlers/version.js +45 -0
- package/dist/cli-system/mod.d.ts +19 -0
- package/dist/cli-system/mod.js +52 -0
- package/dist/commitmsg.d.ts +28 -0
- package/dist/commitmsg.js +232 -0
- package/dist/directive-analysis.d.ts +75 -0
- package/dist/directive-analysis.js +223 -0
- package/dist/ffi-client.d.ts +11 -0
- package/dist/ffi-client.js +12 -0
- package/dist/file-tool.d.ts +96 -0
- package/dist/file-tool.js +274 -0
- package/dist/file-tools-shared.d.ts +81 -0
- package/dist/file-tools-shared.js +276 -0
- package/dist/gh-contributors.d.ts +89 -0
- package/dist/gh-contributors.js +205 -0
- package/dist/gh.d.ts +3 -0
- package/dist/gh.js +64 -0
- package/dist/git-listing.d.ts +27 -0
- package/dist/git-listing.js +69 -0
- package/dist/git.d.ts +172 -0
- package/dist/git.js +277 -0
- package/dist/install.d.ts +34 -0
- package/dist/install.js +421 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +14 -0
- package/dist/mod.d.ts +25 -0
- package/dist/mod.js +8 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.js +221 -0
- package/dist/native-functions.d.ts +1088 -0
- package/dist/native-functions.js +2 -0
- package/dist/npm-externals.d.ts +27 -0
- package/dist/npm-externals.js +34 -0
- package/dist/npm-workspace-specifiers.d.ts +6 -0
- package/dist/npm-workspace-specifiers.js +45 -0
- package/dist/package/loader.d.ts +34 -0
- package/dist/package/loader.js +203 -0
- package/dist/package/mod.d.ts +36 -0
- package/dist/package/mod.js +5 -0
- package/dist/package/types.d.ts +142 -0
- package/dist/package/types.js +32 -0
- package/dist/package/workspace.d.ts +33 -0
- package/dist/package/workspace.js +158 -0
- package/dist/package/writer.d.ts +52 -0
- package/dist/package/writer.js +278 -0
- package/dist/package.json +275 -0
- package/dist/release-notes.d.ts +90 -0
- package/dist/release-notes.js +236 -0
- package/dist/release-tag.d.ts +46 -0
- package/dist/release-tag.js +95 -0
- package/dist/release.d.ts +145 -0
- package/dist/release.js +584 -0
- package/dist/source-mask.d.ts +3 -0
- package/dist/source-mask.js +185 -0
- package/dist/validate-bom.d.ts +5 -0
- package/dist/validate-bom.js +43 -0
- package/dist/validate-case-conflict.d.ts +5 -0
- package/dist/validate-case-conflict.js +43 -0
- package/dist/validate-circular-deps.d.ts +11 -0
- package/dist/validate-circular-deps.js +53 -0
- package/dist/validate-code-conventions.d.ts +22 -0
- package/dist/validate-code-conventions.js +166 -0
- package/dist/validate-commit-msg.d.ts +50 -0
- package/dist/validate-commit-msg.js +182 -0
- package/dist/validate-docs.d.ts +20 -0
- package/dist/validate-docs.js +78 -0
- package/dist/validate-eof.d.ts +5 -0
- package/dist/validate-eof.js +61 -0
- package/dist/validate-error-coverage.d.ts +28 -0
- package/dist/validate-error-coverage.js +93 -0
- package/dist/validate-export-names.d.ts +17 -0
- package/dist/validate-export-names.js +56 -0
- package/dist/validate-filenames.d.ts +5 -0
- package/dist/validate-filenames.js +151 -0
- package/dist/validate-json.d.ts +5 -0
- package/dist/validate-json.js +71 -0
- package/dist/validate-large-files.d.ts +5 -0
- package/dist/validate-large-files.js +41 -0
- package/dist/validate-laroux-boundaries.d.ts +19 -0
- package/dist/validate-laroux-boundaries.js +59 -0
- package/dist/validate-licenses.d.ts +5 -0
- package/dist/validate-licenses.js +137 -0
- package/dist/validate-line-endings.d.ts +5 -0
- package/dist/validate-line-endings.js +47 -0
- package/dist/validate-merge-conflict.d.ts +5 -0
- package/dist/validate-merge-conflict.js +46 -0
- package/dist/validate-mod-exports.d.ts +16 -0
- package/dist/validate-mod-exports.js +56 -0
- package/dist/validate-naming-and-todos.d.ts +5 -0
- package/dist/validate-naming-and-todos.js +70 -0
- package/dist/validate-runtime-js-apis.d.ts +5 -0
- package/dist/validate-runtime-js-apis.js +78 -0
- package/dist/validate-secrets.d.ts +5 -0
- package/dist/validate-secrets.js +82 -0
- package/dist/validate-self-imports.d.ts +5 -0
- package/dist/validate-self-imports.js +78 -0
- package/dist/validate-server-loc.d.ts +32 -0
- package/dist/validate-server-loc.js +94 -0
- package/dist/validate-shebangs.d.ts +5 -0
- package/dist/validate-shebangs.js +33 -0
- package/dist/validate-stream.d.ts +25 -0
- package/dist/validate-stream.js +62 -0
- package/dist/validate-submodules.d.ts +5 -0
- package/dist/validate-submodules.js +43 -0
- package/dist/validate-symlinks.d.ts +5 -0
- package/dist/validate-symlinks.js +46 -0
- package/dist/validate-toml.d.ts +5 -0
- package/dist/validate-toml.js +40 -0
- package/dist/validate-trailing-whitespace.d.ts +5 -0
- package/dist/validate-trailing-whitespace.js +49 -0
- package/dist/validate-yaml.d.ts +5 -0
- package/dist/validate-yaml.js +40 -0
- package/dist/validation/config.d.ts +17 -0
- package/dist/validation/config.js +30 -0
- package/dist/validation/mod.d.ts +71 -0
- package/dist/validation/mod.js +479 -0
- package/dist/validation/registry.d.ts +57 -0
- package/dist/validation/registry.js +256 -0
- package/dist/validation/types.d.ts +101 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/validators/circular-deps.d.ts +7 -0
- package/dist/validation/validators/circular-deps.js +31 -0
- package/dist/validation/validators/docs.d.ts +7 -0
- package/dist/validation/validators/docs.js +38 -0
- package/dist/validation/validators/error-coverage.d.ts +2 -0
- package/dist/validation/validators/error-coverage.js +46 -0
- package/dist/validation/validators/export-names.d.ts +7 -0
- package/dist/validation/validators/export-names.js +31 -0
- package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
- package/dist/validation/validators/laroux-boundaries.js +29 -0
- package/dist/validation/validators/mod-exports.d.ts +7 -0
- package/dist/validation/validators/mod-exports.js +32 -0
- package/dist/validation/validators/mod.d.ts +11 -0
- package/dist/validation/validators/mod.js +12 -0
- package/dist/validation/validators/server-loc.d.ts +2 -0
- package/dist/validation/validators/server-loc.js +48 -0
- package/dist/versions.d.ts +166 -0
- package/dist/versions.js +349 -0
- package/dist/violation-baseline.d.ts +58 -0
- package/dist/violation-baseline.js +144 -0
- package/dist/walk-stream.d.ts +24 -0
- package/dist/walk-stream.js +55 -0
- package/dist/workspace-discovery.d.ts +60 -0
- package/dist/workspace-discovery.js +130 -0
- package/package.json +222 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one list of packages the npm bundles must not inline.
|
|
3
|
+
*
|
|
4
|
+
* `cli` and `noskills` each bundle a different entry point out of the same
|
|
5
|
+
* workspace with esbuild (laroux ships the library emit instead, TASK-237).
|
|
6
|
+
* The builders used to carry copies of this list, and the copies drifted:
|
|
7
|
+
* `noskills` broke the v4.3.0 release at the npm smoke test because only `cli`
|
|
8
|
+
* had the FFI entries. One module, imported by every builder, cannot drift.
|
|
9
|
+
*
|
|
10
|
+
* What stays external and why:
|
|
11
|
+
*
|
|
12
|
+
* - `tailwindcss`, `@tailwindcss/*`, `lightningcss` — native modules, resolved
|
|
13
|
+
* from the consumer's node_modules at runtime.
|
|
14
|
+
* - `@eserstack/ajan-*`, `@eserstack/ajan-wasm` — the per-platform shared
|
|
15
|
+
* libraries and the WASM fallback. They are optionalDependencies of the npm
|
|
16
|
+
* package and are located at runtime by the FFI loader via dlopen.
|
|
17
|
+
*
|
|
18
|
+
* What is deliberately NOT external: `@eserstack/ajan` itself. It is published
|
|
19
|
+
* to JSR only, so declaring it as an npm dependency leaves the package
|
|
20
|
+
* uninstallable (`npm install` 404s), and because the FFI loader is a static
|
|
21
|
+
* import in every ffi-client.ts the bundle is unloadable even from a link
|
|
22
|
+
* install. Bundling it keeps the package self-contained (v4.5.0 lesson).
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
/** esbuild `external` entries shared by every npm build in the workspace. */
|
|
27
|
+
export declare const NPM_EXTERNAL_PACKAGES: readonly string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* The one list of packages the npm bundles must not inline.
|
|
4
|
+
*
|
|
5
|
+
* `cli` and `noskills` each bundle a different entry point out of the same
|
|
6
|
+
* workspace with esbuild (laroux ships the library emit instead, TASK-237).
|
|
7
|
+
* The builders used to carry copies of this list, and the copies drifted:
|
|
8
|
+
* `noskills` broke the v4.3.0 release at the npm smoke test because only `cli`
|
|
9
|
+
* had the FFI entries. One module, imported by every builder, cannot drift.
|
|
10
|
+
*
|
|
11
|
+
* What stays external and why:
|
|
12
|
+
*
|
|
13
|
+
* - `tailwindcss`, `@tailwindcss/*`, `lightningcss` — native modules, resolved
|
|
14
|
+
* from the consumer's node_modules at runtime.
|
|
15
|
+
* - `@eserstack/ajan-*`, `@eserstack/ajan-wasm` — the per-platform shared
|
|
16
|
+
* libraries and the WASM fallback. They are optionalDependencies of the npm
|
|
17
|
+
* package and are located at runtime by the FFI loader via dlopen.
|
|
18
|
+
*
|
|
19
|
+
* What is deliberately NOT external: `@eserstack/ajan` itself. It is published
|
|
20
|
+
* to JSR only, so declaring it as an npm dependency leaves the package
|
|
21
|
+
* uninstallable (`npm install` 404s), and because the FFI loader is a static
|
|
22
|
+
* import in every ffi-client.ts the bundle is unloadable even from a link
|
|
23
|
+
* install. Bundling it keeps the package self-contained (v4.5.0 lesson).
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
/** esbuild `external` entries shared by every npm build in the workspace. */
|
|
28
|
+
export const NPM_EXTERNAL_PACKAGES = [
|
|
29
|
+
"tailwindcss",
|
|
30
|
+
"@tailwindcss/*",
|
|
31
|
+
"lightningcss",
|
|
32
|
+
"@eserstack/ajan-*",
|
|
33
|
+
"@eserstack/ajan-wasm",
|
|
34
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a copy of `dependencies` with every `workspace:` specifier replaced
|
|
3
|
+
* by the concrete specifier `pnpm publish` would emit for `version`; other
|
|
4
|
+
* entries are kept as they are.
|
|
5
|
+
*/
|
|
6
|
+
export declare const resolveWorkspaceSpecifiers: (dependencies: Readonly<Record<string, string>> | undefined, version: string) => Record<string, string> | undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `workspace:` specifiers for a manifest that is published from
|
|
4
|
+
* outside the workspace.
|
|
5
|
+
*
|
|
6
|
+
* `pnpm publish` rewrites `workspace:*` to the member's exact version — but
|
|
7
|
+
* only for a package it recognises as a workspace member. The npm bundles are
|
|
8
|
+
* built into `dist/` directories and published from there, so their generated
|
|
9
|
+
* manifests never get that rewrite and would ship the protocol verbatim, which
|
|
10
|
+
* npm consumers cannot install. This applies the same rule pnpm
|
|
11
|
+
* does: `workspace:*` becomes the exact version, `workspace:^` and
|
|
12
|
+
* `workspace:~` become caret and tilde ranges, and `workspace:<range>` keeps
|
|
13
|
+
* the range.
|
|
14
|
+
*
|
|
15
|
+
* Every workspace member shares the root VERSION, so one version serves all.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
const WORKSPACE_PROTOCOL = "workspace:";
|
|
20
|
+
/**
|
|
21
|
+
* Returns a copy of `dependencies` with every `workspace:` specifier replaced
|
|
22
|
+
* by the concrete specifier `pnpm publish` would emit for `version`; other
|
|
23
|
+
* entries are kept as they are.
|
|
24
|
+
*/
|
|
25
|
+
export const resolveWorkspaceSpecifiers = (dependencies, version) => {
|
|
26
|
+
if (dependencies === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return Object.fromEntries(Object.entries(dependencies).map(([name, spec]) => {
|
|
30
|
+
if (!spec.startsWith(WORKSPACE_PROTOCOL)) {
|
|
31
|
+
return [name, spec];
|
|
32
|
+
}
|
|
33
|
+
const range = spec.slice(WORKSPACE_PROTOCOL.length);
|
|
34
|
+
switch (range) {
|
|
35
|
+
case "*":
|
|
36
|
+
case "":
|
|
37
|
+
return [name, version];
|
|
38
|
+
case "^":
|
|
39
|
+
case "~":
|
|
40
|
+
return [name, `${range}${version}`];
|
|
41
|
+
default:
|
|
42
|
+
return [name, range];
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoadOptions, PackageConfig, PackageFieldName, RawConfigFile } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when loading package configuration fails.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PackageLoadError extends Error {
|
|
6
|
+
readonly filepath?: string;
|
|
7
|
+
constructor(message: string, filepath?: string, cause?: Error);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Loads and merges package configuration from multiple config files.
|
|
11
|
+
*
|
|
12
|
+
* @param options - Loading options
|
|
13
|
+
* @returns Merged package configuration with field origin tracking
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const config = await load({ baseDir: "./pkg/@eserstack/config" });
|
|
18
|
+
* console.log(config.name?.value); // "@eserstack/config"
|
|
19
|
+
* console.log(config.name?.origin.filepath); // "./pkg/@eserstack/config/package.json"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const load: (options?: LoadOptions) => Promise<PackageConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Loads package configuration, returning undefined if no config files found.
|
|
25
|
+
*/
|
|
26
|
+
export declare const tryLoad: (options?: LoadOptions) => Promise<PackageConfig | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets all files that contain a specific field.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getFilesWithField: (config: PackageConfig, fieldName: PackageFieldName) => RawConfigFile[];
|
|
31
|
+
/**
|
|
32
|
+
* Gets the base directory where config was loaded from.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getBaseDir: (config: PackageConfig) => string;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
import * as fileLoader from "@eserstack/config/file";
|
|
3
|
+
import * as get from "@eserstack/fp/get";
|
|
4
|
+
import * as deepMerge from "@eserstack/fp/deep-merge";
|
|
5
|
+
import { runtime } from "@eserstack/standards/cross-runtime";
|
|
6
|
+
import * as types from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when loading package configuration fails.
|
|
9
|
+
*/
|
|
10
|
+
export class PackageLoadError extends Error {
|
|
11
|
+
filepath;
|
|
12
|
+
constructor(message, filepath, cause) {
|
|
13
|
+
super(message, { cause });
|
|
14
|
+
this.name = "PackageLoadError";
|
|
15
|
+
this.filepath = filepath;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Attempts to load a single config file.
|
|
20
|
+
*/
|
|
21
|
+
const tryLoadConfigFile = async (filepath, fileType) => {
|
|
22
|
+
const exists = await runtime.fs.exists(filepath);
|
|
23
|
+
if (exists === false) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Verify it's a file, not a directory
|
|
27
|
+
const stat = await runtime.fs.stat(filepath);
|
|
28
|
+
if (stat.isFile === false) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
// Read raw text
|
|
32
|
+
const rawText = await runtime.fs.readTextFile(filepath);
|
|
33
|
+
// Use the file loader for parsing
|
|
34
|
+
const parseResult = await fileLoader.parse(filepath);
|
|
35
|
+
const content = parseResult.content;
|
|
36
|
+
if (content === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
filepath,
|
|
41
|
+
fileType,
|
|
42
|
+
content,
|
|
43
|
+
rawText,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Finds all config files in the specified directory.
|
|
48
|
+
*/
|
|
49
|
+
const findConfigFiles = async (baseDir, includeFiles) => {
|
|
50
|
+
// The candidate files are independent, so they load concurrently; the
|
|
51
|
+
// result keeps the priority order of includeFiles.
|
|
52
|
+
const loaded = await Promise.all(includeFiles.map((fileType) => tryLoadConfigFile(runtime.path.join(baseDir, fileType), fileType)));
|
|
53
|
+
return loaded.filter((file) => file !== undefined);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Gets a nested property value from an object using a dot-separated path.
|
|
57
|
+
* Uses @eserstack/fp's get() with array path for performance.
|
|
58
|
+
*/
|
|
59
|
+
const getPropertyByPath = (obj, path) => {
|
|
60
|
+
return get.get(obj, path.split("."));
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Extracts a field value from loaded config files with origin tracking.
|
|
64
|
+
*/
|
|
65
|
+
const extractField = (fieldName, loadedFiles, fieldMappings) => {
|
|
66
|
+
let primaryValue;
|
|
67
|
+
let primaryOrigin;
|
|
68
|
+
const alternateOrigins = [];
|
|
69
|
+
// Files are already in priority order
|
|
70
|
+
for (const file of loadedFiles) {
|
|
71
|
+
const propertyPath = fieldMappings[fieldName]?.[file.fileType];
|
|
72
|
+
if (propertyPath === undefined) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const value = getPropertyByPath(file.content, propertyPath);
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const origin = {
|
|
80
|
+
filepath: file.filepath,
|
|
81
|
+
fileType: file.fileType,
|
|
82
|
+
propertyPath,
|
|
83
|
+
};
|
|
84
|
+
if (primaryValue === undefined) {
|
|
85
|
+
primaryValue = value;
|
|
86
|
+
primaryOrigin = origin;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
alternateOrigins.push(origin);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (primaryValue === undefined || primaryOrigin === undefined) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
value: primaryValue,
|
|
97
|
+
origin: primaryOrigin,
|
|
98
|
+
alternateOrigins,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Merges custom field mappings with defaults using deepMerge.
|
|
103
|
+
*/
|
|
104
|
+
const mergeFieldMappings = (customMappings) => {
|
|
105
|
+
if (customMappings === undefined) {
|
|
106
|
+
return types.DEFAULT_FIELD_MAPPINGS;
|
|
107
|
+
}
|
|
108
|
+
return deepMerge.deepMerge(types.DEFAULT_FIELD_MAPPINGS, customMappings);
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Sorts include files by priority order.
|
|
112
|
+
*/
|
|
113
|
+
const sortByPriority = (files) => {
|
|
114
|
+
return [...files].sort((a, b) => types.CONFIG_FILE_PRIORITY.indexOf(a) -
|
|
115
|
+
types.CONFIG_FILE_PRIORITY.indexOf(b));
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Loads and merges package configuration from multiple config files.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Loading options
|
|
121
|
+
* @returns Merged package configuration with field origin tracking
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const config = await load({ baseDir: "./pkg/@eserstack/config" });
|
|
126
|
+
* console.log(config.name?.value); // "@eserstack/config"
|
|
127
|
+
* console.log(config.name?.origin.filepath); // "./pkg/@eserstack/config/package.json"
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export const load = async (options = {}) => {
|
|
131
|
+
const { baseDir = ".", includeFiles = types.CONFIG_FILE_PRIORITY, fieldMappings, searchParents = false, } = options;
|
|
132
|
+
const mergedMappings = mergeFieldMappings(fieldMappings);
|
|
133
|
+
const sortedFiles = sortByPriority(includeFiles);
|
|
134
|
+
// Find and load all config files
|
|
135
|
+
let searchDir = runtime.path.resolve(baseDir);
|
|
136
|
+
let loadedFiles = [];
|
|
137
|
+
while (true) {
|
|
138
|
+
// A parent directory is searched only when the one below it had no
|
|
139
|
+
// config, so the lookups are sequential.
|
|
140
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
141
|
+
loadedFiles = await findConfigFiles(searchDir, sortedFiles);
|
|
142
|
+
if (loadedFiles.length > 0 || !searchParents) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
const parent = runtime.path.dirname(searchDir);
|
|
146
|
+
if (parent === searchDir) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
searchDir = parent;
|
|
150
|
+
}
|
|
151
|
+
if (loadedFiles.length === 0) {
|
|
152
|
+
throw new PackageLoadError(`No config files found in ${baseDir}. Looked for: ${sortedFiles.join(", ")}`);
|
|
153
|
+
}
|
|
154
|
+
// Extract all fields with origin tracking
|
|
155
|
+
const config = {
|
|
156
|
+
name: extractField("name", loadedFiles, mergedMappings),
|
|
157
|
+
version: extractField("version", loadedFiles, mergedMappings),
|
|
158
|
+
description: extractField("description", loadedFiles, mergedMappings),
|
|
159
|
+
license: extractField("license", loadedFiles, mergedMappings),
|
|
160
|
+
private: extractField("private", loadedFiles, mergedMappings),
|
|
161
|
+
exports: extractField("exports", loadedFiles, mergedMappings),
|
|
162
|
+
workspaces: extractField("workspaces", loadedFiles, mergedMappings),
|
|
163
|
+
dependencies: extractField("dependencies", loadedFiles, mergedMappings),
|
|
164
|
+
devDependencies: extractField("devDependencies", loadedFiles, mergedMappings),
|
|
165
|
+
[types.baseDirProp]: searchDir,
|
|
166
|
+
_loadedFiles: loadedFiles,
|
|
167
|
+
};
|
|
168
|
+
return config;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Loads package configuration, returning undefined if no config files found.
|
|
172
|
+
*/
|
|
173
|
+
export const tryLoad = async (options = {}) => {
|
|
174
|
+
try {
|
|
175
|
+
return await load(options);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (error instanceof PackageLoadError) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Gets all files that contain a specific field.
|
|
186
|
+
*/
|
|
187
|
+
export const getFilesWithField = (config, fieldName) => {
|
|
188
|
+
const field = config[fieldName];
|
|
189
|
+
if (!field) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
const filepaths = new Set([
|
|
193
|
+
field.origin.filepath,
|
|
194
|
+
...field.alternateOrigins.map((o) => o.filepath),
|
|
195
|
+
]);
|
|
196
|
+
return config._loadedFiles.filter((f) => filepaths.has(f.filepath));
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Gets the base directory where config was loaded from.
|
|
200
|
+
*/
|
|
201
|
+
export const getBaseDir = (config) => {
|
|
202
|
+
return config[types.baseDirProp];
|
|
203
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified package configuration reading and writing.
|
|
3
|
+
*
|
|
4
|
+
* This module reads and writes package.json, the one package manifest the
|
|
5
|
+
* workspace keeps.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Track which file each field value originated from
|
|
9
|
+
* - Update fields in the config files that contain them
|
|
10
|
+
* - Synchronized version bumping
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import * as pkg from "@eserstack/codebase/package";
|
|
15
|
+
*
|
|
16
|
+
* // Load package config
|
|
17
|
+
* const config = await pkg.load({ baseDir: "./my-package" });
|
|
18
|
+
*
|
|
19
|
+
* // Read values with origin tracking
|
|
20
|
+
* console.log(config.name?.value); // "@scope/my-package"
|
|
21
|
+
* console.log(config.name?.origin.filepath); // "./my-package/package.json"
|
|
22
|
+
*
|
|
23
|
+
* // Update the version
|
|
24
|
+
* await pkg.updateVersion(config, "2.0.0");
|
|
25
|
+
*
|
|
26
|
+
* // Update specific field
|
|
27
|
+
* await pkg.updateField(config, "description", "New description");
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
export type { ConfigFileType, FieldMapping, FieldOrigin, LoadOptions, PackageConfig, PackageFieldName, RawConfigFile, TrackedField, UpdateOptions, UpdateResult, WorkspaceModule, } from "./types.ts";
|
|
33
|
+
export { baseDirProp, CONFIG_FILE_PRIORITY, ConfigFileTypes, DEFAULT_FIELD_MAPPINGS, } from "./types.ts";
|
|
34
|
+
export { getBaseDir, getFilesWithField, load, PackageLoadError, tryLoad, } from "./loader.ts";
|
|
35
|
+
export { getUpdateTargets, PackageUpdateError, syncField, updateField, updateFields, updateVersion, } from "./writer.ts";
|
|
36
|
+
export { getModule, getWorkspaceModules, loadPackageConfig, } from "./workspace.ts";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
export { baseDirProp, CONFIG_FILE_PRIORITY, ConfigFileTypes, DEFAULT_FIELD_MAPPINGS, } from "./types.js";
|
|
3
|
+
export { getBaseDir, getFilesWithField, load, PackageLoadError, tryLoad, } from "./loader.js";
|
|
4
|
+
export { getUpdateTargets, PackageUpdateError, syncField, updateField, updateFields, updateVersion, } from "./writer.js";
|
|
5
|
+
export { getModule, getWorkspaceModules, loadPackageConfig, } from "./workspace.js";
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported package config file types. package.json is the only one, since
|
|
3
|
+
* the libraries publish to npm alone.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ConfigFileTypes: {
|
|
6
|
+
readonly PackageJson: "package.json";
|
|
7
|
+
};
|
|
8
|
+
export type ConfigFileType = (typeof ConfigFileTypes)[keyof typeof ConfigFileTypes];
|
|
9
|
+
/**
|
|
10
|
+
* Priority order for config files (lower index = higher priority).
|
|
11
|
+
*/
|
|
12
|
+
export declare const CONFIG_FILE_PRIORITY: ReadonlyArray<ConfigFileType>;
|
|
13
|
+
/**
|
|
14
|
+
* Symbol used to track the base directory.
|
|
15
|
+
*/
|
|
16
|
+
export declare const baseDirProp: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Common field names that can be extracted from config files.
|
|
19
|
+
*/
|
|
20
|
+
export type PackageFieldName = "name" | "version" | "description" | "license" | "private" | "exports" | "workspaces" | "dependencies" | "devDependencies";
|
|
21
|
+
/**
|
|
22
|
+
* Field mapping - maps common field names to their property path
|
|
23
|
+
* in each config file type.
|
|
24
|
+
*/
|
|
25
|
+
export type FieldMapping = {
|
|
26
|
+
[K in PackageFieldName]: {
|
|
27
|
+
[T in ConfigFileType]?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Default field mappings between config file types.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_FIELD_MAPPINGS: FieldMapping;
|
|
34
|
+
/**
|
|
35
|
+
* Tracks which file a field value originated from.
|
|
36
|
+
*/
|
|
37
|
+
export type FieldOrigin = {
|
|
38
|
+
filepath: string;
|
|
39
|
+
fileType: ConfigFileType;
|
|
40
|
+
propertyPath: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A field value with its origin information.
|
|
44
|
+
*/
|
|
45
|
+
export type TrackedField<T> = {
|
|
46
|
+
value: T;
|
|
47
|
+
origin: FieldOrigin;
|
|
48
|
+
/**
|
|
49
|
+
* Additional files that also have this field defined.
|
|
50
|
+
* Values from these files were overridden by the primary origin.
|
|
51
|
+
*/
|
|
52
|
+
alternateOrigins: ReadonlyArray<FieldOrigin>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Raw config file content with metadata.
|
|
56
|
+
*/
|
|
57
|
+
export type RawConfigFile = {
|
|
58
|
+
filepath: string;
|
|
59
|
+
fileType: ConfigFileType;
|
|
60
|
+
content: Record<string, unknown>;
|
|
61
|
+
/** Original text content for preserving formatting */
|
|
62
|
+
rawText: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Unified package configuration with tracked field origins.
|
|
66
|
+
*/
|
|
67
|
+
export type PackageConfig = {
|
|
68
|
+
/** Package name (e.g., "@eserstack/codebase") */
|
|
69
|
+
name?: TrackedField<string>;
|
|
70
|
+
/** Package version (semver) */
|
|
71
|
+
version?: TrackedField<string>;
|
|
72
|
+
/** Package description */
|
|
73
|
+
description?: TrackedField<string>;
|
|
74
|
+
/** License identifier (e.g., "Apache-2.0") */
|
|
75
|
+
license?: TrackedField<string>;
|
|
76
|
+
/** Whether package is private */
|
|
77
|
+
private?: TrackedField<boolean>;
|
|
78
|
+
/** Export map */
|
|
79
|
+
exports?: TrackedField<Record<string, string> | string>;
|
|
80
|
+
/** Workspace members */
|
|
81
|
+
workspaces?: TrackedField<ReadonlyArray<string>>;
|
|
82
|
+
/** Dependencies */
|
|
83
|
+
dependencies?: TrackedField<Record<string, string>>;
|
|
84
|
+
/** Dev dependencies */
|
|
85
|
+
devDependencies?: TrackedField<Record<string, string>>;
|
|
86
|
+
/** Base directory where config was loaded from */
|
|
87
|
+
[baseDirProp]: string;
|
|
88
|
+
/** Reference to all loaded config files for write operations */
|
|
89
|
+
_loadedFiles: ReadonlyArray<RawConfigFile>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Options for loading package configuration.
|
|
93
|
+
*/
|
|
94
|
+
export type LoadOptions = {
|
|
95
|
+
/** Base directory to search for config files */
|
|
96
|
+
baseDir?: string;
|
|
97
|
+
/** Which config file types to load (default: all) */
|
|
98
|
+
includeFiles?: ReadonlyArray<ConfigFileType>;
|
|
99
|
+
/** Custom field mappings (merged with defaults) */
|
|
100
|
+
fieldMappings?: Partial<FieldMapping>;
|
|
101
|
+
/** Whether to search parent directories */
|
|
102
|
+
searchParents?: boolean;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Options for updating package configuration.
|
|
106
|
+
*/
|
|
107
|
+
export type UpdateOptions = {
|
|
108
|
+
/**
|
|
109
|
+
* Which files to update. Default: all files that have the field.
|
|
110
|
+
* - "all": Update all files containing the field
|
|
111
|
+
* - "origin": Only update the primary origin file
|
|
112
|
+
* - ConfigFileType[]: Update specific file types
|
|
113
|
+
*/
|
|
114
|
+
targetFiles?: "all" | "origin" | ReadonlyArray<ConfigFileType>;
|
|
115
|
+
/** Whether to create the field in files that don't have it */
|
|
116
|
+
createIfMissing?: boolean;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Result of an update operation.
|
|
120
|
+
*/
|
|
121
|
+
export type UpdateResult = {
|
|
122
|
+
/** Files that were successfully updated */
|
|
123
|
+
updated: ReadonlyArray<string>;
|
|
124
|
+
/** Files that failed to update with reasons */
|
|
125
|
+
failed: ReadonlyArray<{
|
|
126
|
+
filepath: string;
|
|
127
|
+
reason: string;
|
|
128
|
+
}>;
|
|
129
|
+
/** Files that were skipped (didn't have the field) */
|
|
130
|
+
skipped: ReadonlyArray<string>;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Represents a workspace member module with its package configuration.
|
|
134
|
+
*/
|
|
135
|
+
export type WorkspaceModule = {
|
|
136
|
+
/** Package name (e.g., "@eserstack/config") */
|
|
137
|
+
name: string;
|
|
138
|
+
/** Package version (semver) */
|
|
139
|
+
version: string;
|
|
140
|
+
/** The full package configuration */
|
|
141
|
+
config: PackageConfig;
|
|
142
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Supported package config file types. package.json is the only one, since
|
|
4
|
+
* the libraries publish to npm alone.
|
|
5
|
+
*/
|
|
6
|
+
export const ConfigFileTypes = {
|
|
7
|
+
PackageJson: "package.json",
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Priority order for config files (lower index = higher priority).
|
|
11
|
+
*/
|
|
12
|
+
export const CONFIG_FILE_PRIORITY = [
|
|
13
|
+
ConfigFileTypes.PackageJson,
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Symbol used to track the base directory.
|
|
17
|
+
*/
|
|
18
|
+
export const baseDirProp = Symbol.for("baseDir");
|
|
19
|
+
/**
|
|
20
|
+
* Default field mappings between config file types.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_FIELD_MAPPINGS = {
|
|
23
|
+
name: { "package.json": "name" },
|
|
24
|
+
version: { "package.json": "version" },
|
|
25
|
+
description: { "package.json": "description" },
|
|
26
|
+
license: { "package.json": "license" },
|
|
27
|
+
private: { "package.json": "private" },
|
|
28
|
+
exports: { "package.json": "exports" },
|
|
29
|
+
workspaces: { "package.json": "workspaces" },
|
|
30
|
+
dependencies: { "package.json": "dependencies" },
|
|
31
|
+
devDependencies: { "package.json": "devDependencies" },
|
|
32
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PackageConfig, WorkspaceModule } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when workspace configuration is invalid.
|
|
4
|
+
*/
|
|
5
|
+
export declare class WorkspaceError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Loads package configuration from a directory.
|
|
10
|
+
* Throws an error if no config file is found.
|
|
11
|
+
*
|
|
12
|
+
* @param path - Directory to load config from
|
|
13
|
+
* @returns PackageConfig with loaded configuration
|
|
14
|
+
* @throws {WorkspaceError} If no package config file is found
|
|
15
|
+
*/
|
|
16
|
+
export declare const loadPackageConfig: (path: string) => Promise<PackageConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets all workspace member modules from a root configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param root - Root directory containing workspace config
|
|
21
|
+
* @returns Tuple of [root config, workspace modules]
|
|
22
|
+
*/
|
|
23
|
+
export declare const getWorkspaceModules: (root: string) => Promise<[PackageConfig, WorkspaceModule[]]>;
|
|
24
|
+
/**
|
|
25
|
+
* Finds a module by name in a list of workspace modules.
|
|
26
|
+
* Matches either the full name or a partial name suffix.
|
|
27
|
+
*
|
|
28
|
+
* @param module - Module name to find (can be partial, e.g., "config" matches "@eserstack/config")
|
|
29
|
+
* @param modules - List of workspace modules to search
|
|
30
|
+
* @returns The matching module or undefined
|
|
31
|
+
*/
|
|
32
|
+
export declare const getModule: (module: string, modules: WorkspaceModule[]) => WorkspaceModule | undefined;
|
|
33
|
+
export { getBaseDir } from "./loader.ts";
|