zephyr-agent 0.0.0-canary-20250703033536 → 0.0.0-canary-20250728152440
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 +99 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/build-context/detect-monorepo.d.ts +14 -0
- package/dist/lib/build-context/detect-monorepo.js +109 -0
- package/dist/lib/build-context/detect-monorepo.js.map +1 -0
- package/dist/lib/build-context/resolve-catalog-version.d.ts +24 -0
- package/dist/lib/build-context/resolve-catalog-version.js +365 -0
- package/dist/lib/build-context/resolve-catalog-version.js.map +1 -0
- package/dist/lib/build-context/ze-util-get-git-info.js +280 -18
- package/dist/lib/build-context/ze-util-get-git-info.js.map +1 -1
- package/dist/lib/build-context/ze-util-read-package-json.js +5 -0
- package/dist/lib/build-context/ze-util-read-package-json.js.map +1 -1
- package/dist/lib/errors/codes.d.ts +5 -0
- package/dist/lib/errors/codes.js +5 -0
- package/dist/lib/errors/codes.js.map +1 -1
- package/dist/lib/node-persist/upload-provider-options.d.ts +1 -4
- package/dist/lib/node-persist/upload-provider-options.js.map +1 -1
- package/dist/lib/transformers/ze-minimal-build-stats.d.ts +3 -0
- package/dist/lib/transformers/ze-minimal-build-stats.js +47 -0
- package/dist/lib/transformers/ze-minimal-build-stats.js.map +1 -0
- package/dist/package.json +1 -1
- package/dist/zephyr-engine/index.d.ts +1 -1
- package/dist/zephyr-engine/index.js +8 -0
- package/dist/zephyr-engine/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -95,6 +95,105 @@ interface ZephyrAgentConfig {
|
|
|
95
95
|
}
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
+
### Git Repository Requirements
|
|
99
|
+
|
|
100
|
+
**IMPORTANT**: Zephyr requires a properly initialized Git repository with a remote origin for production deployments.
|
|
101
|
+
|
|
102
|
+
#### Git Information Handling
|
|
103
|
+
|
|
104
|
+
When Zephyr cannot find a Git repository with remote origin, it will:
|
|
105
|
+
|
|
106
|
+
1. **Automatic Package.json-Based Naming**:
|
|
107
|
+
|
|
108
|
+
- Extract organization, project, and app names from your `package.json`
|
|
109
|
+
- Use authenticated user's username as the organization for personal Zephyr org
|
|
110
|
+
- Follow intelligent naming conventions based on package structure
|
|
111
|
+
- No user prompts or environment variables required
|
|
112
|
+
|
|
113
|
+
2. **Enhanced Naming Logic**:
|
|
114
|
+
- **Scoped packages** (`@scope/name`): project = scope, app = name
|
|
115
|
+
- **With root package.json**:
|
|
116
|
+
- If root is scoped (`@scope/name`): project = scope, app = current package name
|
|
117
|
+
- Otherwise: project = root package name, app = current package name
|
|
118
|
+
- **Fallback to directory name**: If no root package.json found, uses directory name as project
|
|
119
|
+
- **Single package**: project = app = package name
|
|
120
|
+
- **Organization**: Uses authenticated user's username (sanitized for URL safety)
|
|
121
|
+
|
|
122
|
+
#### Example Scenarios
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Recommended: Proper Git setup
|
|
126
|
+
git init
|
|
127
|
+
git remote add origin git@github.com:YOUR_ORG/YOUR_REPO.git
|
|
128
|
+
git add . && git commit -m "Initial commit"
|
|
129
|
+
npm run build # Works perfectly with full Git context
|
|
130
|
+
|
|
131
|
+
# Automatic fallback (works seamlessly)
|
|
132
|
+
# No git repository - uses package.json naming
|
|
133
|
+
npm run build # Automatically determines naming from package.json
|
|
134
|
+
|
|
135
|
+
# Examples of automatic naming:
|
|
136
|
+
# package.json: { "name": "@my-company/my-app" }
|
|
137
|
+
# → org: "jwt-username", project: "my-company", app: "my-app"
|
|
138
|
+
|
|
139
|
+
# package.json: { "name": "my-project" } (no root package.json)
|
|
140
|
+
# → org: "jwt-username", project: "my-project", app: "my-project"
|
|
141
|
+
|
|
142
|
+
# package.json: { "name": "my-app" } (root package.json: { "name": "my-workspace" })
|
|
143
|
+
# → org: "jwt-username", project: "my-workspace", app: "my-app"
|
|
144
|
+
|
|
145
|
+
# package.json: { "name": "my-app" } (root package.json: { "name": "@company/monorepo" })
|
|
146
|
+
# → org: "jwt-username", project: "company", app: "my-app"
|
|
147
|
+
|
|
148
|
+
# package.json: { "name": "my-app" } (no root package.json found)
|
|
149
|
+
# → org: "jwt-username", project: "current-directory-name", app: "my-app"
|
|
150
|
+
|
|
151
|
+
# Special characters in username get sanitized:
|
|
152
|
+
# Username: "Néstor López" → org: "n-stor-l-pez"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Why Git is Required
|
|
156
|
+
|
|
157
|
+
Zephyr uses Git information to:
|
|
158
|
+
|
|
159
|
+
- Determine organization and project structure
|
|
160
|
+
- Track deployment versions and commits
|
|
161
|
+
- Enable collaboration features
|
|
162
|
+
- Provide proper deployment metadata
|
|
163
|
+
|
|
164
|
+
Without Git, Zephyr cannot guarantee proper functionality, especially for:
|
|
165
|
+
|
|
166
|
+
- Production deployments
|
|
167
|
+
- Team collaboration
|
|
168
|
+
- Version tracking
|
|
169
|
+
- Rollback capabilities
|
|
170
|
+
|
|
171
|
+
#### Package.json-Based Naming (Non-Git Environments)
|
|
172
|
+
|
|
173
|
+
When Git is not available (e.g., AI coding tools, quick prototypes), Zephyr automatically extracts naming information from your `package.json` structure:
|
|
174
|
+
|
|
175
|
+
**Automatic Organization Detection:**
|
|
176
|
+
|
|
177
|
+
- Uses the authenticated user's name from your authentication token
|
|
178
|
+
- Requires valid authentication to determine organization
|
|
179
|
+
|
|
180
|
+
**Project and App Naming Logic:**
|
|
181
|
+
|
|
182
|
+
1. **Scoped Package** (`@company/app-name`):
|
|
183
|
+
|
|
184
|
+
- Project: `company` (scope without @)
|
|
185
|
+
- App: `app-name`
|
|
186
|
+
|
|
187
|
+
2. **Monorepo Structure** (root `package.json` exists):
|
|
188
|
+
|
|
189
|
+
- If root is scoped (`@company/monorepo`): Project = `company`, App = current package name
|
|
190
|
+
- Otherwise: Project = root package name, App = current package name
|
|
191
|
+
- If no root package.json found: Project = current directory name, App = current package name
|
|
192
|
+
|
|
193
|
+
3. **Single Package**:
|
|
194
|
+
- Project: Package name
|
|
195
|
+
- App: Package name
|
|
196
|
+
|
|
98
197
|
## Internal APIs
|
|
99
198
|
|
|
100
199
|
### Build Context API
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export { applyBaseHrefToAssets, normalizeBasePath, } from './lib/transformers/ze
|
|
|
8
8
|
export { zeBuildAssets } from './lib/transformers/ze-build-assets';
|
|
9
9
|
export { buildAssetsMap, type ZeBuildAssetsMap, } from './lib/transformers/ze-build-assets-map';
|
|
10
10
|
export { zeBuildDashData } from './lib/transformers/ze-build-dash-data';
|
|
11
|
+
export { create_minimal_build_stats } from './lib/transformers/ze-minimal-build-stats';
|
|
11
12
|
export { DEFAULT_AUTH_COMPLETION_TIMEOUT_MS, TOKEN_EXPIRY } from './lib/auth/auth-flags';
|
|
13
|
+
export { getCatalogPackages, resolveCatalogDependencies, resolveCatalogVersion, } from './lib/build-context/resolve-catalog-version';
|
|
12
14
|
export { is_zephyr_dependency_pair, readPackageJson, ZephyrEngine, type ZeDependencyPair, type ZephyrDependencies, type ZephyrEngineOptions, } from './zephyr-engine';
|
|
13
15
|
export type { Platform } from './zephyr-engine';
|
|
14
16
|
export type { ZeResolvedDependency } from './zephyr-engine/resolve_remote_dependency';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZephyrEngine = exports.readPackageJson = exports.is_zephyr_dependency_pair = exports.TOKEN_EXPIRY = exports.DEFAULT_AUTH_COMPLETION_TIMEOUT_MS = exports.zeBuildDashData = exports.buildAssetsMap = exports.zeBuildAssets = exports.normalizeBasePath = exports.applyBaseHrefToAssets = exports.logFn = exports.ze_log = exports.getAppDeployResult = exports.getAllDeployedApps = exports.getAllAppDeployResults = exports.ZephyrError = exports.ZeErrors = exports.savePartialAssetMap = exports.removePartialAssetMap = exports.getPartialAssetMap = exports.resolveIndexHtml = exports.onIndexHtmlResolved = void 0;
|
|
3
|
+
exports.ZephyrEngine = exports.readPackageJson = exports.is_zephyr_dependency_pair = exports.resolveCatalogVersion = exports.resolveCatalogDependencies = exports.getCatalogPackages = exports.TOKEN_EXPIRY = exports.DEFAULT_AUTH_COMPLETION_TIMEOUT_MS = exports.create_minimal_build_stats = exports.zeBuildDashData = exports.buildAssetsMap = exports.zeBuildAssets = exports.normalizeBasePath = exports.applyBaseHrefToAssets = exports.logFn = exports.ze_log = exports.getAppDeployResult = exports.getAllDeployedApps = exports.getAllAppDeployResults = exports.ZephyrError = exports.ZeErrors = exports.savePartialAssetMap = exports.removePartialAssetMap = exports.getPartialAssetMap = exports.resolveIndexHtml = exports.onIndexHtmlResolved = void 0;
|
|
4
4
|
// hack for angular
|
|
5
5
|
var resolve_index_html_1 = require("./lib/hacks/resolve-index-html");
|
|
6
6
|
Object.defineProperty(exports, "onIndexHtmlResolved", { enumerable: true, get: function () { return resolve_index_html_1.onIndexHtmlResolved; } });
|
|
@@ -34,10 +34,17 @@ var ze_build_assets_map_1 = require("./lib/transformers/ze-build-assets-map");
|
|
|
34
34
|
Object.defineProperty(exports, "buildAssetsMap", { enumerable: true, get: function () { return ze_build_assets_map_1.buildAssetsMap; } });
|
|
35
35
|
var ze_build_dash_data_1 = require("./lib/transformers/ze-build-dash-data");
|
|
36
36
|
Object.defineProperty(exports, "zeBuildDashData", { enumerable: true, get: function () { return ze_build_dash_data_1.zeBuildDashData; } });
|
|
37
|
+
var ze_minimal_build_stats_1 = require("./lib/transformers/ze-minimal-build-stats");
|
|
38
|
+
Object.defineProperty(exports, "create_minimal_build_stats", { enumerable: true, get: function () { return ze_minimal_build_stats_1.create_minimal_build_stats; } });
|
|
37
39
|
// Auth related exports
|
|
38
40
|
var auth_flags_1 = require("./lib/auth/auth-flags");
|
|
39
41
|
Object.defineProperty(exports, "DEFAULT_AUTH_COMPLETION_TIMEOUT_MS", { enumerable: true, get: function () { return auth_flags_1.DEFAULT_AUTH_COMPLETION_TIMEOUT_MS; } });
|
|
40
42
|
Object.defineProperty(exports, "TOKEN_EXPIRY", { enumerable: true, get: function () { return auth_flags_1.TOKEN_EXPIRY; } });
|
|
43
|
+
// Catalog related exports
|
|
44
|
+
var resolve_catalog_version_1 = require("./lib/build-context/resolve-catalog-version");
|
|
45
|
+
Object.defineProperty(exports, "getCatalogPackages", { enumerable: true, get: function () { return resolve_catalog_version_1.getCatalogPackages; } });
|
|
46
|
+
Object.defineProperty(exports, "resolveCatalogDependencies", { enumerable: true, get: function () { return resolve_catalog_version_1.resolveCatalogDependencies; } });
|
|
47
|
+
Object.defineProperty(exports, "resolveCatalogVersion", { enumerable: true, get: function () { return resolve_catalog_version_1.resolveCatalogVersion; } });
|
|
41
48
|
// Zephyr Edge is the main class which should be used
|
|
42
49
|
var zephyr_engine_1 = require("./zephyr-engine");
|
|
43
50
|
Object.defineProperty(exports, "is_zephyr_dependency_pair", { enumerable: true, get: function () { return zephyr_engine_1.is_zephyr_dependency_pair; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mBAAmB;AACnB,qEAAuF;AAA9E,yHAAA,mBAAmB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAC9C,sBAAsB;AACtB,4EAI+C;AAH7C,wHAAA,kBAAkB,OAAA;AAClB,2HAAA,qBAAqB,OAAA;AACrB,yHAAA,mBAAmB,OAAA;AAGrB,SAAS;AACT,uCAAqD;AAA5C,kGAAA,QAAQ,OAAA;AAAE,qGAAA,WAAW,OAAA;AAE9B,gBAAgB;AAChB,sFAKoD;AAJlD,iIAAA,sBAAsB,OAAA;AACtB,6HAAA,kBAAkB,OAAA;AAClB,6HAAA,kBAAkB,OAAA;AAIpB,SAAS;AACT,yCAAuC;AAA9B,iGAAA,MAAM,OAAA;AACf,2DAAmD;AAA1C,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AqB,OAAA;AAGvB,qDAAqD;AACrD,iDAOyB;AANvB,0HAAA,yBAAyB,OAAA;AACzB,gHAAA,eAAe,OAAA;AACf,6GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type MonorepoType = 'pnpm' | 'yarn' | 'npm' | 'lerna' | 'nx' | 'rush' | 'none';
|
|
2
|
+
export interface MonorepoInfo {
|
|
3
|
+
type: MonorepoType;
|
|
4
|
+
root: string;
|
|
5
|
+
configFile?: string;
|
|
6
|
+
workspaces?: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Detects if the current project is part of a monorepo and returns information about it.
|
|
10
|
+
* Traverses up the directory tree looking for monorepo configuration files.
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectMonorepo(startPath: string): Promise<MonorepoInfo>;
|
|
13
|
+
/** Gets the root package.json from a monorepo root directory */
|
|
14
|
+
export declare function getMonorepoRootPackageJson(monorepoRoot: string): Promise<Record<string, unknown> | null>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectMonorepo = detectMonorepo;
|
|
4
|
+
exports.getMonorepoRootPackageJson = getMonorepoRootPackageJson;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const debug_1 = require("../logging/debug");
|
|
9
|
+
const MONOREPO_CONFIG_FILES = [
|
|
10
|
+
{ file: 'pnpm-workspace.yaml', type: 'pnpm' },
|
|
11
|
+
{ file: 'pnpm-workspace.yml', type: 'pnpm' },
|
|
12
|
+
{ file: 'lerna.json', type: 'lerna' },
|
|
13
|
+
{ file: 'nx.json', type: 'nx' },
|
|
14
|
+
{ file: 'rush.json', type: 'rush' },
|
|
15
|
+
];
|
|
16
|
+
const MAX_TRAVERSAL_DEPTH = 10;
|
|
17
|
+
/**
|
|
18
|
+
* Detects if the current project is part of a monorepo and returns information about it.
|
|
19
|
+
* Traverses up the directory tree looking for monorepo configuration files.
|
|
20
|
+
*/
|
|
21
|
+
async function detectMonorepo(startPath) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
let currentDir = (0, node_path_1.resolve)(startPath);
|
|
24
|
+
let depth = 0;
|
|
25
|
+
while (depth < MAX_TRAVERSAL_DEPTH) {
|
|
26
|
+
// Check for specific monorepo config files
|
|
27
|
+
for (const config of MONOREPO_CONFIG_FILES) {
|
|
28
|
+
const configPath = (0, node_path_1.join)(currentDir, config.file);
|
|
29
|
+
if (fileExists(configPath)) {
|
|
30
|
+
debug_1.ze_log.misc(`Found ${config.type} monorepo config at ${configPath}`);
|
|
31
|
+
return {
|
|
32
|
+
type: config.type,
|
|
33
|
+
root: currentDir,
|
|
34
|
+
configFile: configPath,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Check for package.json with workspaces
|
|
39
|
+
const packageJsonPath = (0, node_path_1.join)(currentDir, 'package.json');
|
|
40
|
+
if (fileExists(packageJsonPath)) {
|
|
41
|
+
try {
|
|
42
|
+
const content = await (0, promises_1.readFile)(packageJsonPath, 'utf8');
|
|
43
|
+
const packageJson = JSON.parse(content);
|
|
44
|
+
// Check for npm/yarn workspaces
|
|
45
|
+
if (packageJson.workspaces) {
|
|
46
|
+
debug_1.ze_log.misc(`Found ${((_a = packageJson.packageManager) === null || _a === void 0 ? void 0 : _a.startsWith('yarn')) ? 'yarn' : 'npm'} workspaces at ${packageJsonPath}`);
|
|
47
|
+
return {
|
|
48
|
+
type: ((_b = packageJson.packageManager) === null || _b === void 0 ? void 0 : _b.startsWith('yarn')) ? 'yarn' : 'npm',
|
|
49
|
+
root: currentDir,
|
|
50
|
+
configFile: packageJsonPath,
|
|
51
|
+
workspaces: Array.isArray(packageJson.workspaces)
|
|
52
|
+
? packageJson.workspaces
|
|
53
|
+
: packageJson.workspaces.packages || [],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Check for .yarnrc.yml in the same directory (Yarn Berry)
|
|
57
|
+
const yarnrcPath = (0, node_path_1.join)(currentDir, '.yarnrc.yml');
|
|
58
|
+
if (fileExists(yarnrcPath)) {
|
|
59
|
+
debug_1.ze_log.misc(`Found Yarn Berry workspace at ${currentDir}`);
|
|
60
|
+
return {
|
|
61
|
+
type: 'yarn',
|
|
62
|
+
root: currentDir,
|
|
63
|
+
configFile: yarnrcPath,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
debug_1.ze_log.misc(`Error reading package.json at ${packageJsonPath}:`, error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Check if we've reached the root
|
|
72
|
+
const parentDir = (0, node_path_1.resolve)(currentDir, '..');
|
|
73
|
+
if (parentDir === currentDir) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
currentDir = parentDir;
|
|
77
|
+
depth++;
|
|
78
|
+
}
|
|
79
|
+
debug_1.ze_log.misc('No monorepo configuration found');
|
|
80
|
+
return {
|
|
81
|
+
type: 'none',
|
|
82
|
+
root: startPath,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Gets the root package.json from a monorepo root directory */
|
|
86
|
+
async function getMonorepoRootPackageJson(monorepoRoot) {
|
|
87
|
+
const packageJsonPath = (0, node_path_1.join)(monorepoRoot, 'package.json');
|
|
88
|
+
if (!fileExists(packageJsonPath)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const content = await (0, promises_1.readFile)(packageJsonPath, 'utf8');
|
|
93
|
+
return JSON.parse(content);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
debug_1.ze_log.misc(`Error reading root package.json at ${packageJsonPath}:`, error);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function fileExists(path) {
|
|
101
|
+
try {
|
|
102
|
+
(0, node_fs_1.accessSync)(path, node_fs_1.constants.F_OK);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (_a) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=detect-monorepo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-monorepo.js","sourceRoot":"","sources":["../../../src/lib/build-context/detect-monorepo.ts"],"names":[],"mappings":";;AAiCA,wCAsEC;AAGD,gEAeC;AAzHD,qCAAgD;AAChD,+CAA4C;AAC5C,yCAA0C;AAC1C,4CAA0C;AAgB1C,MAAM,qBAAqB,GAAkC;IAC3D,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC7C,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5C,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE;IAC/B,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE;CAC3B,CAAC;AAEX,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;GAGG;AACI,KAAK,UAAU,cAAc,CAAC,SAAiB;;IACpD,IAAI,UAAU,GAAG,IAAA,mBAAO,EAAC,SAAS,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,KAAK,GAAG,mBAAmB,EAAE,CAAC;QACnC,2CAA2C;QAC3C,KAAK,MAAM,MAAM,IAAI,qBAAqB,EAAE,CAAC;YAC3C,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YACjD,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC3B,cAAM,CAAC,IAAI,C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AAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,CAAC;QACH,IAAA,oBAAU,EAAC,IAAI,EAAE,mBAAS,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a catalog dependency version string (e.g., "catalog:react18") to its actual
|
|
3
|
+
* semver version range from pnpm-workspace.yaml
|
|
4
|
+
*
|
|
5
|
+
* @param versionString The version string to resolve
|
|
6
|
+
* @param packageName Optional package name to look up specific package in catalog
|
|
7
|
+
* @returns The resolved semver version or the original version if not a catalog reference
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveCatalogVersion(versionString: string, packageName?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Gets all packages with their versions for a specific catalog
|
|
12
|
+
*
|
|
13
|
+
* @param catalogName The name of the catalog
|
|
14
|
+
* @returns Object mapping package names to their versions, or null if catalog not found
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCatalogPackages(catalogName: string): Record<string, string> | null;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a dependency versions object, looking for catalog: references and replacing
|
|
19
|
+
* them with the actual semver version ranges
|
|
20
|
+
*
|
|
21
|
+
* @param dependencies Package dependencies object (e.g., from package.json)
|
|
22
|
+
* @returns New dependencies object with resolved versions
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveCatalogDependencies(dependencies: Record<string, string> | undefined): Record<string, string>;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveCatalogVersion = resolveCatalogVersion;
|
|
4
|
+
exports.getCatalogPackages = getCatalogPackages;
|
|
5
|
+
exports.resolveCatalogDependencies = resolveCatalogDependencies;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
8
|
+
const path = tslib_1.__importStar(require("path"));
|
|
9
|
+
const zephyr_edge_contract_1 = require("zephyr-edge-contract");
|
|
10
|
+
const logging_1 = require("../logging");
|
|
11
|
+
/** Cache for workspace config to avoid repeated file reads */
|
|
12
|
+
let workspaceConfigCache = null;
|
|
13
|
+
/** Cache for workspace packages to avoid repeated file scanning */
|
|
14
|
+
let workspacePackagesCache = null;
|
|
15
|
+
/**
|
|
16
|
+
* Reads the pnpm-workspace.yaml file to get catalog definitions
|
|
17
|
+
*
|
|
18
|
+
* @param workspacePath Optional path to the workspace file
|
|
19
|
+
* @returns The parsed pnpm workspace configuration
|
|
20
|
+
*/
|
|
21
|
+
function readWorkspaceConfig(workspacePath) {
|
|
22
|
+
if (workspaceConfigCache) {
|
|
23
|
+
return workspaceConfigCache;
|
|
24
|
+
}
|
|
25
|
+
// Try to find pnpm-workspace.yaml in current directory or parent directories
|
|
26
|
+
const searchPath = workspacePath || findWorkspaceFile();
|
|
27
|
+
if (!searchPath) {
|
|
28
|
+
logging_1.ze_log.app('Warning: Could not find pnpm-workspace.yaml file');
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// Using require would be simpler, but we'll use fs to read and YAML parse
|
|
33
|
+
// for more explicit error handling and to avoid needing yaml package
|
|
34
|
+
const yaml = fs.readFileSync(searchPath, 'utf8');
|
|
35
|
+
const config = parseYaml(yaml);
|
|
36
|
+
workspaceConfigCache = config;
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logging_1.ze_log.app('Error reading pnpm-workspace.yaml:', error);
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Simple YAML parser for pnpm-workspace.yaml This is a basic implementation that handles
|
|
46
|
+
* the format we expect in pnpm-workspace.yaml
|
|
47
|
+
*/
|
|
48
|
+
function parseYaml(yaml) {
|
|
49
|
+
const result = {};
|
|
50
|
+
let currentSection = null;
|
|
51
|
+
let currentSubsection = null;
|
|
52
|
+
const lines = yaml.split('\n');
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
const trimmedLine = line.trim();
|
|
55
|
+
// Skip comments and empty lines
|
|
56
|
+
if (trimmedLine.startsWith('#') || !trimmedLine) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// Check for main sections
|
|
60
|
+
if (trimmedLine.endsWith(':')) {
|
|
61
|
+
currentSection = trimmedLine.slice(0, -1);
|
|
62
|
+
if (!currentSection) {
|
|
63
|
+
currentSubsection = null;
|
|
64
|
+
}
|
|
65
|
+
if (currentSection === 'catalogs') {
|
|
66
|
+
result.catalogs = {};
|
|
67
|
+
}
|
|
68
|
+
if (currentSection === 'packages') {
|
|
69
|
+
result.packages = [];
|
|
70
|
+
}
|
|
71
|
+
// Get the catalog's name
|
|
72
|
+
if (trimmedLine.endsWith(':') && currentSection !== 'catalogs' && result.catalogs) {
|
|
73
|
+
currentSubsection = trimmedLine.trim().slice(0, -1);
|
|
74
|
+
result.catalogs[currentSubsection] = {};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Parse packages section
|
|
78
|
+
if (currentSection === 'packages' && trimmedLine.startsWith('-')) {
|
|
79
|
+
const pattern = trimmedLine.slice(1).trim();
|
|
80
|
+
// Remove quotes if present
|
|
81
|
+
const cleanPattern = pattern.replace(/^['"]|['"]$/g, '');
|
|
82
|
+
if (!result.packages) {
|
|
83
|
+
result.packages = [];
|
|
84
|
+
}
|
|
85
|
+
result.packages.push(cleanPattern);
|
|
86
|
+
}
|
|
87
|
+
// Get the key and value from the line (at here should be npm dependency name)
|
|
88
|
+
if (trimmedLine.includes(':') && currentSection !== 'catalogs' && result.catalogs) {
|
|
89
|
+
if (currentSubsection) {
|
|
90
|
+
const [key, value] = trimmedLine.split(':', 2).map((part) => part.trim());
|
|
91
|
+
// remove all the double quotes and single quotes and replace them with '\'', because this is affecting the replacement
|
|
92
|
+
const cleanedKey = key.replace(/['"]/g, '');
|
|
93
|
+
result.catalogs[currentSubsection][cleanedKey] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Finds the pnpm-workspace.yaml file by looking in the current directory and traversing
|
|
101
|
+
* up the directory tree
|
|
102
|
+
*/
|
|
103
|
+
function findWorkspaceFile() {
|
|
104
|
+
let currentDir = process.cwd();
|
|
105
|
+
const root = path.parse(currentDir).root;
|
|
106
|
+
while (currentDir !== root) {
|
|
107
|
+
const workspacePath = path.join(currentDir, 'pnpm-workspace.yaml');
|
|
108
|
+
if (fs.existsSync(workspacePath)) {
|
|
109
|
+
return workspacePath;
|
|
110
|
+
}
|
|
111
|
+
currentDir = path.dirname(currentDir);
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Gets the workspace root directory by finding the directory containing the
|
|
117
|
+
* pnpm-workspace.yaml file
|
|
118
|
+
*/
|
|
119
|
+
function getWorkspaceRoot() {
|
|
120
|
+
const workspaceFile = findWorkspaceFile();
|
|
121
|
+
if (!workspaceFile) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return path.dirname(workspaceFile);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Find package.json files in a directory according to glob-like patterns This is a custom
|
|
128
|
+
* implementation to replace glob.sync
|
|
129
|
+
*
|
|
130
|
+
* @param rootDir The root directory to start searching from
|
|
131
|
+
* @param includePattern The pattern to include (e.g., "libs/**")
|
|
132
|
+
* @param excludePatterns Array of patterns to exclude
|
|
133
|
+
* @returns Array of absolute paths to matching package.json files
|
|
134
|
+
*/
|
|
135
|
+
function findPackageJsonFiles(rootDir, includePattern, excludePatterns = []) {
|
|
136
|
+
const results = [];
|
|
137
|
+
// Convert glob-like pattern to regex pattern for matching
|
|
138
|
+
const patternParts = includePattern.split('/');
|
|
139
|
+
const baseDir = patternParts[0] === '**' ? '' : patternParts[0];
|
|
140
|
+
const hasDoubleGlob = includePattern.includes('**');
|
|
141
|
+
// Build the full base path
|
|
142
|
+
const basePath = path.join(rootDir, baseDir);
|
|
143
|
+
// Check if the base directory exists
|
|
144
|
+
if (!fs.existsSync(basePath) || !fs.statSync(basePath).isDirectory()) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
// Function to check if a path should be excluded
|
|
148
|
+
const isExcluded = (filePath) => {
|
|
149
|
+
const relativePath = path.relative(rootDir, filePath);
|
|
150
|
+
return excludePatterns.some((pattern) => {
|
|
151
|
+
// Remove the ! from negated patterns
|
|
152
|
+
const cleanPattern = pattern.startsWith('!') ? pattern.slice(1) : pattern;
|
|
153
|
+
// Simple string matching for exact paths or basic wildcards
|
|
154
|
+
if (cleanPattern.endsWith('/**')) {
|
|
155
|
+
const prefix = cleanPattern.slice(0, -3);
|
|
156
|
+
return relativePath.startsWith(prefix);
|
|
157
|
+
}
|
|
158
|
+
return (relativePath === cleanPattern ||
|
|
159
|
+
(cleanPattern.includes('*') &&
|
|
160
|
+
relativePath.startsWith(cleanPattern.split('*')[0])));
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
// Recursive function to find package.json files
|
|
164
|
+
const findRecursively = (dir, depth = 0) => {
|
|
165
|
+
if (isExcluded(dir)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
170
|
+
for (const entry of entries) {
|
|
171
|
+
const fullPath = path.join(dir, entry.name);
|
|
172
|
+
if (isExcluded(fullPath)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (entry.isDirectory() && (hasDoubleGlob || depth < patternParts.length)) {
|
|
176
|
+
// Recurse into directories if we have ** or haven't reached max depth
|
|
177
|
+
findRecursively(fullPath, depth + 1);
|
|
178
|
+
}
|
|
179
|
+
else if (entry.name === 'package.json') {
|
|
180
|
+
results.push(fullPath);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
logging_1.ze_log.app(`Error reading directory ${dir}:`, error);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// Start the recursive search
|
|
189
|
+
findRecursively(basePath);
|
|
190
|
+
return results;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Finds all package.json files in the workspace based on the patterns specified in the
|
|
194
|
+
* pnpm-workspace.yaml file
|
|
195
|
+
*/
|
|
196
|
+
function findWorkspacePackages() {
|
|
197
|
+
// Return cached result if available
|
|
198
|
+
if (workspacePackagesCache) {
|
|
199
|
+
return workspacePackagesCache;
|
|
200
|
+
}
|
|
201
|
+
const workspaceRoot = getWorkspaceRoot();
|
|
202
|
+
if (!workspaceRoot) {
|
|
203
|
+
logging_1.ze_log.app('Warning: Could not find workspace root directory');
|
|
204
|
+
return new Map();
|
|
205
|
+
}
|
|
206
|
+
const config = readWorkspaceConfig();
|
|
207
|
+
if (!config.packages || config.packages.length === 0) {
|
|
208
|
+
logging_1.ze_log.app('Warning: No workspace packages defined in pnpm-workspace.yaml');
|
|
209
|
+
return new Map();
|
|
210
|
+
}
|
|
211
|
+
const packageJsonMap = new Map();
|
|
212
|
+
const includePatterns = [];
|
|
213
|
+
const excludePatterns = [];
|
|
214
|
+
// Separate include and exclude patterns
|
|
215
|
+
for (const pattern of config.packages) {
|
|
216
|
+
if (pattern.startsWith('!')) {
|
|
217
|
+
excludePatterns.push(pattern.slice(1));
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
includePatterns.push(pattern);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Process include patterns
|
|
224
|
+
for (const includePattern of includePatterns) {
|
|
225
|
+
try {
|
|
226
|
+
// Use our own file finder instead of glob
|
|
227
|
+
const packageJsonPaths = findPackageJsonFiles(workspaceRoot, includePattern, excludePatterns);
|
|
228
|
+
// Read each package.json file
|
|
229
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
230
|
+
try {
|
|
231
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
|
|
232
|
+
const packageJson = (0, zephyr_edge_contract_1.safe_json_parse)(packageJsonContent);
|
|
233
|
+
if (packageJson && packageJson.name) {
|
|
234
|
+
packageJsonMap.set(packageJson.name, packageJson);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
logging_1.ze_log.app(`Error reading package.json at ${packageJsonPath}:`, error);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
logging_1.ze_log.app(`Error processing pattern ${includePattern}:`, error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Cache the result
|
|
247
|
+
workspacePackagesCache = packageJsonMap;
|
|
248
|
+
return packageJsonMap;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Resolves a workspace:* dependency by finding the package in the workspace
|
|
252
|
+
*
|
|
253
|
+
* @param packageName The name of the package to find in the workspace
|
|
254
|
+
* @returns The version of the package, or null if not found
|
|
255
|
+
*/
|
|
256
|
+
function resolveWorkspaceVersion(packageName) {
|
|
257
|
+
var _a;
|
|
258
|
+
const workspacePackages = findWorkspacePackages();
|
|
259
|
+
if (workspacePackages.has(packageName)) {
|
|
260
|
+
return ((_a = workspacePackages.get(packageName)) === null || _a === void 0 ? void 0 : _a.version) || null;
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Resolves a catalog dependency version string (e.g., "catalog:react18") to its actual
|
|
266
|
+
* semver version range from pnpm-workspace.yaml
|
|
267
|
+
*
|
|
268
|
+
* @param versionString The version string to resolve
|
|
269
|
+
* @param packageName Optional package name to look up specific package in catalog
|
|
270
|
+
* @returns The resolved semver version or the original version if not a catalog reference
|
|
271
|
+
*/
|
|
272
|
+
function resolveCatalogVersion(versionString, packageName) {
|
|
273
|
+
// If it's not a catalog reference, return as is
|
|
274
|
+
if (!versionString ||
|
|
275
|
+
typeof versionString !== 'string' ||
|
|
276
|
+
!versionString.startsWith('catalog:')) {
|
|
277
|
+
return versionString;
|
|
278
|
+
}
|
|
279
|
+
// Extract catalog name from format "catalog:catalogName"
|
|
280
|
+
const catalogName = versionString.substring(8); // Remove "catalog:" prefix
|
|
281
|
+
// Read workspace config to get catalog information
|
|
282
|
+
const config = readWorkspaceConfig();
|
|
283
|
+
// If no catalogs section or the specified catalog doesn't exist
|
|
284
|
+
if (!config.catalogs || !Object.keys(config.catalogs).includes(catalogName)) {
|
|
285
|
+
logging_1.ze_log.app(`Warning: Catalog "${catalogName}" not found in pnpm-workspace.yaml`);
|
|
286
|
+
return versionString; // Return the original version string as fallback
|
|
287
|
+
}
|
|
288
|
+
// If a package name is provided, look for that specific package in the catalog
|
|
289
|
+
if (packageName && config.catalogs[catalogName][packageName]) {
|
|
290
|
+
return config.catalogs[catalogName][packageName];
|
|
291
|
+
}
|
|
292
|
+
// Return an object representation of all versions in this catalog
|
|
293
|
+
// This is useful for module federation shared config
|
|
294
|
+
return JSON.stringify(config.catalogs[catalogName]);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Gets all packages with their versions for a specific catalog
|
|
298
|
+
*
|
|
299
|
+
* @param catalogName The name of the catalog
|
|
300
|
+
* @returns Object mapping package names to their versions, or null if catalog not found
|
|
301
|
+
*/
|
|
302
|
+
function getCatalogPackages(catalogName) {
|
|
303
|
+
// Read workspace config to get catalog information
|
|
304
|
+
const config = readWorkspaceConfig();
|
|
305
|
+
// If no catalogs section or the specified catalog doesn't exist
|
|
306
|
+
if (!config.catalogs || !Object.keys(config.catalogs).includes(catalogName)) {
|
|
307
|
+
logging_1.ze_log.app(`Warning: Catalog "${catalogName}" not found in pnpm-workspace.yaml`);
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
return config.catalogs[catalogName];
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Resolves a dependency versions object, looking for catalog: references and replacing
|
|
314
|
+
* them with the actual semver version ranges
|
|
315
|
+
*
|
|
316
|
+
* @param dependencies Package dependencies object (e.g., from package.json)
|
|
317
|
+
* @returns New dependencies object with resolved versions
|
|
318
|
+
*/
|
|
319
|
+
function resolveCatalogDependencies(dependencies) {
|
|
320
|
+
if (!dependencies)
|
|
321
|
+
return {};
|
|
322
|
+
const result = {};
|
|
323
|
+
for (const [name, version] of Object.entries(dependencies)) {
|
|
324
|
+
if (version && typeof version === 'string' && version.startsWith('catalog:')) {
|
|
325
|
+
const catalogName = version.substring(8);
|
|
326
|
+
const catalogPackages = getCatalogPackages(catalogName);
|
|
327
|
+
if (catalogPackages && catalogPackages[name]) {
|
|
328
|
+
// Use the specific package version from the catalog
|
|
329
|
+
result[name] = catalogPackages[name];
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
// If the exact package isn't in the catalog, keep the original for backward compatibility
|
|
333
|
+
result[name] = version;
|
|
334
|
+
logging_1.ze_log.app(`Warning: Package ${name} not found in catalog ${catalogName}, using original reference`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else if (version === 'workspace:*') {
|
|
338
|
+
// Handle workspace references by finding the package in the workspace
|
|
339
|
+
const resolvedVersion = resolveWorkspaceVersion(name);
|
|
340
|
+
if (resolvedVersion) {
|
|
341
|
+
result[name] = resolvedVersion;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
// If the package isn't found in the workspace, keep the original
|
|
345
|
+
result[name] = version;
|
|
346
|
+
logging_1.ze_log.app(`Warning: Package ${name} not found in workspace, using original reference`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else if (version && typeof version === 'string') {
|
|
350
|
+
// Handle normal semver
|
|
351
|
+
result[name] = version;
|
|
352
|
+
}
|
|
353
|
+
else if (version) {
|
|
354
|
+
// Handle other non-standard formats by stringifying
|
|
355
|
+
result[name] = String(version);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
// Fallback for edge cases
|
|
359
|
+
result[name] = '*';
|
|
360
|
+
logging_1.ze_log.app(`Warning: No valid version found for ${name}, it's using wildcard '*'`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=resolve-catalog-version.js.map
|