@domainlang/language 0.1.81
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 +32 -0
- package/out/ast-augmentation.d.ts +6 -0
- package/out/ast-augmentation.js +2 -0
- package/out/ast-augmentation.js.map +1 -0
- package/out/domain-lang-module.d.ts +55 -0
- package/out/domain-lang-module.js +59 -0
- package/out/domain-lang-module.js.map +1 -0
- package/out/generated/ast.d.ts +770 -0
- package/out/generated/ast.js +565 -0
- package/out/generated/ast.js.map +1 -0
- package/out/generated/grammar.d.ts +6 -0
- package/out/generated/grammar.js +2502 -0
- package/out/generated/grammar.js.map +1 -0
- package/out/generated/module.d.ts +13 -0
- package/out/generated/module.js +21 -0
- package/out/generated/module.js.map +1 -0
- package/out/index.d.ts +13 -0
- package/out/index.js +17 -0
- package/out/index.js.map +1 -0
- package/out/lsp/domain-lang-completion.d.ts +37 -0
- package/out/lsp/domain-lang-completion.js +452 -0
- package/out/lsp/domain-lang-completion.js.map +1 -0
- package/out/lsp/domain-lang-formatter.d.ts +15 -0
- package/out/lsp/domain-lang-formatter.js +43 -0
- package/out/lsp/domain-lang-formatter.js.map +1 -0
- package/out/lsp/domain-lang-naming.d.ts +34 -0
- package/out/lsp/domain-lang-naming.js +49 -0
- package/out/lsp/domain-lang-naming.js.map +1 -0
- package/out/lsp/domain-lang-scope.d.ts +59 -0
- package/out/lsp/domain-lang-scope.js +102 -0
- package/out/lsp/domain-lang-scope.js.map +1 -0
- package/out/lsp/hover/ddd-pattern-explanations.d.ts +50 -0
- package/out/lsp/hover/ddd-pattern-explanations.js +196 -0
- package/out/lsp/hover/ddd-pattern-explanations.js.map +1 -0
- package/out/lsp/hover/domain-lang-hover.d.ts +19 -0
- package/out/lsp/hover/domain-lang-hover.js +306 -0
- package/out/lsp/hover/domain-lang-hover.js.map +1 -0
- package/out/lsp/hover/domain-lang-keywords.d.ts +13 -0
- package/out/lsp/hover/domain-lang-keywords.js +47 -0
- package/out/lsp/hover/domain-lang-keywords.js.map +1 -0
- package/out/main-browser.d.ts +1 -0
- package/out/main-browser.js +11 -0
- package/out/main-browser.js.map +1 -0
- package/out/main.d.ts +1 -0
- package/out/main.js +74 -0
- package/out/main.js.map +1 -0
- package/out/sdk/ast-augmentation.d.ts +136 -0
- package/out/sdk/ast-augmentation.js +62 -0
- package/out/sdk/ast-augmentation.js.map +1 -0
- package/out/sdk/index.d.ts +94 -0
- package/out/sdk/index.js +97 -0
- package/out/sdk/index.js.map +1 -0
- package/out/sdk/indexes.d.ts +16 -0
- package/out/sdk/indexes.js +97 -0
- package/out/sdk/indexes.js.map +1 -0
- package/out/sdk/loader-node.d.ts +47 -0
- package/out/sdk/loader-node.js +104 -0
- package/out/sdk/loader-node.js.map +1 -0
- package/out/sdk/loader.d.ts +49 -0
- package/out/sdk/loader.js +85 -0
- package/out/sdk/loader.js.map +1 -0
- package/out/sdk/patterns.d.ts +93 -0
- package/out/sdk/patterns.js +123 -0
- package/out/sdk/patterns.js.map +1 -0
- package/out/sdk/query.d.ts +90 -0
- package/out/sdk/query.js +679 -0
- package/out/sdk/query.js.map +1 -0
- package/out/sdk/resolution.d.ts +52 -0
- package/out/sdk/resolution.js +68 -0
- package/out/sdk/resolution.js.map +1 -0
- package/out/sdk/types.d.ts +301 -0
- package/out/sdk/types.js +8 -0
- package/out/sdk/types.js.map +1 -0
- package/out/services/dependency-analyzer.d.ts +94 -0
- package/out/services/dependency-analyzer.js +279 -0
- package/out/services/dependency-analyzer.js.map +1 -0
- package/out/services/dependency-resolver.d.ts +123 -0
- package/out/services/dependency-resolver.js +252 -0
- package/out/services/dependency-resolver.js.map +1 -0
- package/out/services/git-url-resolver.browser.d.ts +18 -0
- package/out/services/git-url-resolver.browser.js +15 -0
- package/out/services/git-url-resolver.browser.js.map +1 -0
- package/out/services/git-url-resolver.d.ts +192 -0
- package/out/services/git-url-resolver.js +382 -0
- package/out/services/git-url-resolver.js.map +1 -0
- package/out/services/governance-validator.d.ts +80 -0
- package/out/services/governance-validator.js +159 -0
- package/out/services/governance-validator.js.map +1 -0
- package/out/services/import-resolver.d.ts +18 -0
- package/out/services/import-resolver.js +22 -0
- package/out/services/import-resolver.js.map +1 -0
- package/out/services/performance-optimizer.d.ts +60 -0
- package/out/services/performance-optimizer.js +140 -0
- package/out/services/performance-optimizer.js.map +1 -0
- package/out/services/relationship-inference.d.ts +11 -0
- package/out/services/relationship-inference.js +98 -0
- package/out/services/relationship-inference.js.map +1 -0
- package/out/services/workspace-manager.d.ts +76 -0
- package/out/services/workspace-manager.js +323 -0
- package/out/services/workspace-manager.js.map +1 -0
- package/out/syntaxes/domain-lang.monarch.d.ts +76 -0
- package/out/syntaxes/domain-lang.monarch.js +29 -0
- package/out/syntaxes/domain-lang.monarch.js.map +1 -0
- package/out/utils/import-utils.d.ts +57 -0
- package/out/utils/import-utils.js +228 -0
- package/out/utils/import-utils.js.map +1 -0
- package/out/validation/bounded-context.d.ts +11 -0
- package/out/validation/bounded-context.js +79 -0
- package/out/validation/bounded-context.js.map +1 -0
- package/out/validation/classification.d.ts +3 -0
- package/out/validation/classification.js +3 -0
- package/out/validation/classification.js.map +1 -0
- package/out/validation/constants.d.ts +77 -0
- package/out/validation/constants.js +96 -0
- package/out/validation/constants.js.map +1 -0
- package/out/validation/domain-lang-validator.d.ts +2 -0
- package/out/validation/domain-lang-validator.js +27 -0
- package/out/validation/domain-lang-validator.js.map +1 -0
- package/out/validation/domain.d.ts +11 -0
- package/out/validation/domain.js +18 -0
- package/out/validation/domain.js.map +1 -0
- package/out/validation/import.d.ts +44 -0
- package/out/validation/import.js +135 -0
- package/out/validation/import.js.map +1 -0
- package/out/validation/maps.d.ts +21 -0
- package/out/validation/maps.js +56 -0
- package/out/validation/maps.js.map +1 -0
- package/out/validation/metadata.d.ts +7 -0
- package/out/validation/metadata.js +12 -0
- package/out/validation/metadata.js.map +1 -0
- package/out/validation/model.d.ts +12 -0
- package/out/validation/model.js +29 -0
- package/out/validation/model.js.map +1 -0
- package/out/validation/relationships.d.ts +12 -0
- package/out/validation/relationships.js +94 -0
- package/out/validation/relationships.js.map +1 -0
- package/out/validation/shared.d.ts +6 -0
- package/out/validation/shared.js +12 -0
- package/out/validation/shared.js.map +1 -0
- package/package.json +97 -0
- package/src/ast-augmentation.ts +5 -0
- package/src/domain-lang-module.ts +100 -0
- package/src/domain-lang.langium +356 -0
- package/src/generated/ast.ts +999 -0
- package/src/generated/grammar.ts +2504 -0
- package/src/generated/module.ts +25 -0
- package/src/index.ts +17 -0
- package/src/lsp/domain-lang-completion.ts +514 -0
- package/src/lsp/domain-lang-formatter.ts +51 -0
- package/src/lsp/domain-lang-naming.ts +56 -0
- package/src/lsp/domain-lang-scope.ts +137 -0
- package/src/lsp/hover/ddd-pattern-explanations.ts +237 -0
- package/src/lsp/hover/domain-lang-hover.ts +340 -0
- package/src/lsp/hover/domain-lang-keywords.ts +50 -0
- package/src/main-browser.ts +15 -0
- package/src/main.ts +85 -0
- package/src/sdk/README.md +297 -0
- package/src/sdk/ast-augmentation.ts +157 -0
- package/src/sdk/index.ts +128 -0
- package/src/sdk/indexes.ts +155 -0
- package/src/sdk/loader-node.ts +126 -0
- package/src/sdk/loader.ts +99 -0
- package/src/sdk/patterns.ts +147 -0
- package/src/sdk/query.ts +802 -0
- package/src/sdk/resolution.ts +78 -0
- package/src/sdk/types.ts +346 -0
- package/src/services/dependency-analyzer.ts +381 -0
- package/src/services/dependency-resolver.ts +334 -0
- package/src/services/git-url-resolver.browser.ts +31 -0
- package/src/services/git-url-resolver.ts +524 -0
- package/src/services/governance-validator.ts +219 -0
- package/src/services/import-resolver.ts +30 -0
- package/src/services/performance-optimizer.ts +170 -0
- package/src/services/relationship-inference.ts +121 -0
- package/src/services/workspace-manager.ts +416 -0
- package/src/syntaxes/domain-lang.monarch.ts +29 -0
- package/src/utils/import-utils.ts +274 -0
- package/src/validation/bounded-context.ts +99 -0
- package/src/validation/classification.ts +5 -0
- package/src/validation/constants.ts +124 -0
- package/src/validation/domain-lang-validator.ts +33 -0
- package/src/validation/domain.ts +24 -0
- package/src/validation/import.ts +171 -0
- package/src/validation/maps.ts +72 -0
- package/src/validation/metadata.ts +14 -0
- package/src/validation/model.ts +37 -0
- package/src/validation/relationships.ts +154 -0
- package/src/validation/shared.ts +14 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Browser stub for GitUrlResolver
|
|
2
|
+
|
|
3
|
+
export interface GitImportInfo {
|
|
4
|
+
original: string;
|
|
5
|
+
platform: 'github' | 'gitlab' | 'bitbucket' | 'generic';
|
|
6
|
+
owner: string;
|
|
7
|
+
repo: string;
|
|
8
|
+
version: string;
|
|
9
|
+
repoUrl: string;
|
|
10
|
+
entryPoint: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class GitUrlResolver {
|
|
14
|
+
constructor() {
|
|
15
|
+
throw new Error('GitUrlResolver is not available in the browser.');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export const GitUrlParser = {
|
|
21
|
+
parse() {
|
|
22
|
+
throw new Error('GitUrlParser is not available in the browser.');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function loadLockFile(): void {
|
|
27
|
+
throw new Error('loadLockFile is not available in the browser.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type LockFile = unknown;
|
|
31
|
+
export type LockedDependency = unknown;
|
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Repository Resolver Service
|
|
3
|
+
*
|
|
4
|
+
* Resolves git-based package imports to local cached repositories.
|
|
5
|
+
* Supports simplified GitHub syntax (owner/repo@version) and full URLs.
|
|
6
|
+
*
|
|
7
|
+
* Design: Repository-level imports (not individual files)
|
|
8
|
+
* - Imports load entire package
|
|
9
|
+
* - Package entry point defined in model.yaml
|
|
10
|
+
* - Version pinning at repository level
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { URI } from 'langium';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import fs from 'node:fs/promises';
|
|
16
|
+
import os from 'node:os';
|
|
17
|
+
import { exec } from 'node:child_process';
|
|
18
|
+
import { promisify } from 'node:util';
|
|
19
|
+
import YAML from 'yaml';
|
|
20
|
+
|
|
21
|
+
const execAsync = promisify(exec);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parsed git import with repository-level information.
|
|
25
|
+
*/
|
|
26
|
+
export interface GitImportInfo {
|
|
27
|
+
/** Original import string */
|
|
28
|
+
original: string;
|
|
29
|
+
/** Git platform (github, gitlab, bitbucket, or generic) */
|
|
30
|
+
platform: 'github' | 'gitlab' | 'bitbucket' | 'generic';
|
|
31
|
+
/** Repository owner/organization */
|
|
32
|
+
owner: string;
|
|
33
|
+
/** Repository name */
|
|
34
|
+
repo: string;
|
|
35
|
+
/** Version (tag, branch, or commit hash) */
|
|
36
|
+
version: string;
|
|
37
|
+
/** Full git repository URL */
|
|
38
|
+
repoUrl: string;
|
|
39
|
+
/** Package main entry point (from dlang.toml or default index.dlang) */
|
|
40
|
+
entryPoint: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Package metadata from model.yaml
|
|
45
|
+
*/
|
|
46
|
+
export interface PackageMetadata {
|
|
47
|
+
name?: string;
|
|
48
|
+
version?: string;
|
|
49
|
+
main?: string; // Entry point file (legacy field name for compatibility)
|
|
50
|
+
entry?: string; // Entry point file (preferred field name)
|
|
51
|
+
exports?: Record<string, string>;
|
|
52
|
+
dependencies?: Record<string, string>; // name → version constraint
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Lock file format (dlang.lock)
|
|
57
|
+
*
|
|
58
|
+
* Pins exact versions and commit hashes for all dependencies
|
|
59
|
+
* in the dependency tree. Ensures reproducible builds.
|
|
60
|
+
*/
|
|
61
|
+
export interface LockFile {
|
|
62
|
+
version: string; // Lock file format version (currently "1")
|
|
63
|
+
dependencies: Record<string, LockedDependency>; // package name → locked info
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A single locked dependency with pinned version and commit.
|
|
68
|
+
*/
|
|
69
|
+
export interface LockedDependency {
|
|
70
|
+
version: string; // Resolved semantic version
|
|
71
|
+
resolved: string; // Full git URL
|
|
72
|
+
commit: string; // Exact commit hash (content-addressable)
|
|
73
|
+
integrity?: string; // Optional SHA-256 hash for verification
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parses import URLs into structured git import information.
|
|
78
|
+
*
|
|
79
|
+
* Supported formats:
|
|
80
|
+
* - owner/repo@version (GitHub assumed)
|
|
81
|
+
* - owner/repo (GitHub, defaults to main)
|
|
82
|
+
* - https://github.com/owner/repo@version
|
|
83
|
+
* - https://gitlab.com/owner/repo@version
|
|
84
|
+
* - https://git.example.com/owner/repo@version
|
|
85
|
+
*/
|
|
86
|
+
export class GitUrlParser {
|
|
87
|
+
/**
|
|
88
|
+
* Determines if an import string is a git repository import.
|
|
89
|
+
*/
|
|
90
|
+
static isGitUrl(importStr: string): boolean {
|
|
91
|
+
// GitHub shorthand: owner/repo or owner/repo@version
|
|
92
|
+
if (/^[a-zA-Z0-9-]+\/[a-zA-Z0-9-_.]+(@[^/]+)?$/.test(importStr)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Full URLs
|
|
97
|
+
return (
|
|
98
|
+
importStr.startsWith('https://github.com/') ||
|
|
99
|
+
importStr.startsWith('https://gitlab.com/') ||
|
|
100
|
+
importStr.startsWith('https://bitbucket.org/') ||
|
|
101
|
+
importStr.startsWith('https://git.') ||
|
|
102
|
+
importStr.startsWith('git://')
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Parses a git import URL into structured components.
|
|
108
|
+
*
|
|
109
|
+
* @param importStr - The import URL string
|
|
110
|
+
* @returns Parsed git import information
|
|
111
|
+
* @throws Error if URL format is invalid
|
|
112
|
+
*/
|
|
113
|
+
static parse(importStr: string): GitImportInfo {
|
|
114
|
+
// Handle GitHub shorthand (owner/repo or owner/repo@version)
|
|
115
|
+
if (this.isGitHubShorthand(importStr)) {
|
|
116
|
+
return this.parseGitHubShorthand(importStr);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Handle full URLs
|
|
120
|
+
if (importStr.startsWith('https://') || importStr.startsWith('git://')) {
|
|
121
|
+
return this.parseFullUrl(importStr);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new Error(`Invalid git import URL: ${importStr}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Checks if string is GitHub shorthand format.
|
|
129
|
+
*/
|
|
130
|
+
private static isGitHubShorthand(importStr: string): boolean {
|
|
131
|
+
return /^[a-zA-Z0-9-]+\/[a-zA-Z0-9-_.]+(@[^/]+)?$/.test(importStr);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Parses GitHub shorthand (owner/repo or owner/repo@version).
|
|
136
|
+
*/
|
|
137
|
+
private static parseGitHubShorthand(importStr: string): GitImportInfo {
|
|
138
|
+
const match = importStr.match(/^([a-zA-Z0-9-]+)\/([a-zA-Z0-9-_.]+)(?:@([^/]+))?$/);
|
|
139
|
+
if (!match) {
|
|
140
|
+
throw new Error(`Invalid GitHub shorthand format: ${importStr}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const [, owner, repo, version] = match;
|
|
144
|
+
const resolvedVersion = version || 'main';
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
original: importStr,
|
|
148
|
+
platform: 'github',
|
|
149
|
+
owner,
|
|
150
|
+
repo,
|
|
151
|
+
version: resolvedVersion,
|
|
152
|
+
repoUrl: `https://github.com/${owner}/${repo}`,
|
|
153
|
+
entryPoint: 'index.dlang', // Default, will be resolved from dlang.toml
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parses full git URLs (https://...).
|
|
159
|
+
*
|
|
160
|
+
* Supported:
|
|
161
|
+
* - https://github.com/owner/repo@version
|
|
162
|
+
* - https://gitlab.com/owner/repo@version
|
|
163
|
+
* - https://git.example.com/owner/repo@version
|
|
164
|
+
*/
|
|
165
|
+
private static parseFullUrl(importStr: string): GitImportInfo {
|
|
166
|
+
// GitHub
|
|
167
|
+
const ghMatch = importStr.match(
|
|
168
|
+
/^https:\/\/github\.com\/([^/]+)\/([^/@]+)(?:@([^/]+))?$/
|
|
169
|
+
);
|
|
170
|
+
if (ghMatch) {
|
|
171
|
+
const [, owner, repo, version] = ghMatch;
|
|
172
|
+
return {
|
|
173
|
+
original: importStr,
|
|
174
|
+
platform: 'github',
|
|
175
|
+
owner,
|
|
176
|
+
repo,
|
|
177
|
+
version: version || 'main',
|
|
178
|
+
repoUrl: `https://github.com/${owner}/${repo}`,
|
|
179
|
+
entryPoint: 'index.dlang',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// GitLab
|
|
184
|
+
const glMatch = importStr.match(
|
|
185
|
+
/^https:\/\/gitlab\.com\/([^/]+)\/([^/@]+)(?:@([^/]+))?$/
|
|
186
|
+
);
|
|
187
|
+
if (glMatch) {
|
|
188
|
+
const [, owner, repo, version] = glMatch;
|
|
189
|
+
return {
|
|
190
|
+
original: importStr,
|
|
191
|
+
platform: 'gitlab',
|
|
192
|
+
owner,
|
|
193
|
+
repo,
|
|
194
|
+
version: version || 'main',
|
|
195
|
+
repoUrl: `https://gitlab.com/${owner}/${repo}`,
|
|
196
|
+
entryPoint: 'index.dlang',
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Bitbucket
|
|
201
|
+
const bbMatch = importStr.match(
|
|
202
|
+
/^https:\/\/bitbucket\.org\/([^/]+)\/([^/@]+)(?:@([^/]+))?$/
|
|
203
|
+
);
|
|
204
|
+
if (bbMatch) {
|
|
205
|
+
const [, owner, repo, version] = bbMatch;
|
|
206
|
+
return {
|
|
207
|
+
original: importStr,
|
|
208
|
+
platform: 'bitbucket',
|
|
209
|
+
owner,
|
|
210
|
+
repo,
|
|
211
|
+
version: version || 'main',
|
|
212
|
+
repoUrl: `https://bitbucket.org/${owner}/${repo}`,
|
|
213
|
+
entryPoint: 'index.dlang',
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Generic git URL
|
|
218
|
+
const genericMatch = importStr.match(
|
|
219
|
+
/^(?:https|git):\/\/([^/]+)\/([^/]+)\/([^/@]+)(?:@([^/]+))?$/
|
|
220
|
+
);
|
|
221
|
+
if (genericMatch) {
|
|
222
|
+
const [, host, owner, repo, version] = genericMatch;
|
|
223
|
+
return {
|
|
224
|
+
original: importStr,
|
|
225
|
+
platform: 'generic',
|
|
226
|
+
owner,
|
|
227
|
+
repo,
|
|
228
|
+
version: version || 'main',
|
|
229
|
+
repoUrl: `https://${host}/${owner}/${repo}`,
|
|
230
|
+
entryPoint: 'index.dlang',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
throw new Error(`Unsupported git URL format: ${importStr}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Resolves git repository imports to local entry point files.
|
|
240
|
+
*
|
|
241
|
+
* Implements a content-addressable cache:
|
|
242
|
+
* - Cache location: ~/.dlang/cache/
|
|
243
|
+
* - Cache key: platform/owner/repo/commit-hash
|
|
244
|
+
* - Downloads entire repository on first use
|
|
245
|
+
* - Reads dlang.toml to find entry point
|
|
246
|
+
* - Returns URI to entry point file
|
|
247
|
+
*/
|
|
248
|
+
export class GitUrlResolver {
|
|
249
|
+
private cacheDir: string;
|
|
250
|
+
private lockFile?: LockFile;
|
|
251
|
+
|
|
252
|
+
constructor(cacheDir?: string) {
|
|
253
|
+
this.cacheDir = cacheDir || path.join(os.homedir(), '.dlang', 'cache');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Sets the lock file for dependency resolution.
|
|
258
|
+
*
|
|
259
|
+
* When a lock file is set, all package imports will use
|
|
260
|
+
* the locked commit hashes instead of resolving versions.
|
|
261
|
+
* This ensures reproducible builds and handles transitive dependencies.
|
|
262
|
+
*
|
|
263
|
+
* @param lockFile - The parsed lock file from the workspace root
|
|
264
|
+
*/
|
|
265
|
+
setLockFile(lockFile: LockFile | undefined): void {
|
|
266
|
+
this.lockFile = lockFile;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Resolves a git import URL to the package's entry point file.
|
|
271
|
+
*
|
|
272
|
+
* Process:
|
|
273
|
+
* 1. Parse git URL
|
|
274
|
+
* 2. Check lock file for pinned version (transitive dependency support)
|
|
275
|
+
* 3. Resolve version to commit hash (if not locked)
|
|
276
|
+
* 4. Check cache
|
|
277
|
+
* 5. Download repository if not cached
|
|
278
|
+
* 6. Read dlang.toml to find entry point
|
|
279
|
+
* 7. Return URI to entry point file
|
|
280
|
+
*
|
|
281
|
+
* @param importUrl - The git import URL
|
|
282
|
+
* @returns URI to the package's entry point file
|
|
283
|
+
*/
|
|
284
|
+
async resolve(importUrl: string): Promise<URI> {
|
|
285
|
+
const gitInfo = GitUrlParser.parse(importUrl);
|
|
286
|
+
|
|
287
|
+
// Check lock file for pinned version (handles transitive dependencies)
|
|
288
|
+
let commitHash: string;
|
|
289
|
+
const packageKey = `${gitInfo.owner}/${gitInfo.repo}`;
|
|
290
|
+
|
|
291
|
+
if (this.lockFile?.dependencies[packageKey]) {
|
|
292
|
+
// Use locked commit hash (reproducible build)
|
|
293
|
+
commitHash = this.lockFile.dependencies[packageKey].commit;
|
|
294
|
+
} else {
|
|
295
|
+
// Resolve version dynamically (development mode or missing lock)
|
|
296
|
+
commitHash = await this.resolveCommit(gitInfo);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Check cache
|
|
300
|
+
const cachedPath = this.getCachePath(gitInfo, commitHash);
|
|
301
|
+
|
|
302
|
+
if (!(await this.existsInCache(cachedPath))) {
|
|
303
|
+
// Download repository
|
|
304
|
+
await this.downloadRepo(gitInfo, commitHash, cachedPath);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Read package metadata to get entry point
|
|
308
|
+
const entryPoint = await this.getEntryPoint(cachedPath);
|
|
309
|
+
const entryFile = path.join(cachedPath, entryPoint);
|
|
310
|
+
|
|
311
|
+
// Verify entry point exists
|
|
312
|
+
if (!(await this.existsInCache(entryFile))) {
|
|
313
|
+
throw new Error(
|
|
314
|
+
`Entry point not found: ${entryPoint} in ${gitInfo.repoUrl}@${gitInfo.version}`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return URI.file(entryFile);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Reads model.yaml to get the package entry point.
|
|
323
|
+
* Falls back to index.dlang if no model.yaml found.
|
|
324
|
+
*/
|
|
325
|
+
private async getEntryPoint(repoPath: string): Promise<string> {
|
|
326
|
+
const yamlPath = path.join(repoPath, 'model.yaml');
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
const yamlContent = await fs.readFile(yamlPath, 'utf-8');
|
|
330
|
+
const metadata = this.parseYaml(yamlContent);
|
|
331
|
+
// Prefer 'entry' field, fallback to 'main' for backward compatibility
|
|
332
|
+
return metadata.entry || metadata.main || 'index.dlang';
|
|
333
|
+
} catch {
|
|
334
|
+
// No model.yaml or parse error, use default
|
|
335
|
+
return 'index.dlang';
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Parses model.yaml content to extract entry point.
|
|
341
|
+
*
|
|
342
|
+
* Expected structure:
|
|
343
|
+
* model:
|
|
344
|
+
* entry: index.dlang
|
|
345
|
+
*/
|
|
346
|
+
private parseYaml(content: string): PackageMetadata {
|
|
347
|
+
const parsed = YAML.parse(content) as {
|
|
348
|
+
model?: {
|
|
349
|
+
name?: string;
|
|
350
|
+
version?: string;
|
|
351
|
+
entry?: string;
|
|
352
|
+
main?: string;
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
entry: parsed.model?.entry,
|
|
358
|
+
main: parsed.model?.main,
|
|
359
|
+
name: parsed.model?.name,
|
|
360
|
+
version: parsed.model?.version,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Resolves a version (tag/branch) to a commit hash using git ls-remote.
|
|
366
|
+
*/
|
|
367
|
+
private async resolveCommit(gitInfo: GitImportInfo): Promise<string> {
|
|
368
|
+
try {
|
|
369
|
+
// Try to resolve as tag or branch
|
|
370
|
+
const { stdout } = await execAsync(
|
|
371
|
+
`git ls-remote ${gitInfo.repoUrl} ${gitInfo.version}`
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
if (stdout.trim()) {
|
|
375
|
+
const commitHash = stdout.split('\t')[0];
|
|
376
|
+
return commitHash;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// If not found, assume it's already a commit hash
|
|
380
|
+
if (/^[0-9a-f]{7,40}$/i.test(gitInfo.version)) {
|
|
381
|
+
return gitInfo.version;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
throw new Error(`Could not resolve version: ${gitInfo.version}`);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
throw new Error(
|
|
387
|
+
`Failed to resolve git version ${gitInfo.version} for ${gitInfo.repoUrl}: ${error}`
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Gets the local cache path for a git repository.
|
|
394
|
+
*
|
|
395
|
+
* Format: ~/.dlang/cache/{platform}/{owner}/{repo}/{commit-hash}/
|
|
396
|
+
*/
|
|
397
|
+
private getCachePath(gitInfo: GitImportInfo, commitHash: string): string {
|
|
398
|
+
return path.join(
|
|
399
|
+
this.cacheDir,
|
|
400
|
+
gitInfo.platform,
|
|
401
|
+
gitInfo.owner,
|
|
402
|
+
gitInfo.repo,
|
|
403
|
+
commitHash
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Checks if a file or directory exists in the cache.
|
|
409
|
+
*/
|
|
410
|
+
private async existsInCache(filePath: string): Promise<boolean> {
|
|
411
|
+
try {
|
|
412
|
+
await fs.access(filePath);
|
|
413
|
+
return true;
|
|
414
|
+
} catch {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Downloads a git repository to the cache.
|
|
421
|
+
*
|
|
422
|
+
* Uses shallow clone for efficiency (only downloads the specific commit).
|
|
423
|
+
*/
|
|
424
|
+
private async downloadRepo(
|
|
425
|
+
gitInfo: GitImportInfo,
|
|
426
|
+
commitHash: string,
|
|
427
|
+
cachePath: string
|
|
428
|
+
): Promise<void> {
|
|
429
|
+
const targetDir = path.resolve(cachePath);
|
|
430
|
+
const parentDir = path.dirname(targetDir);
|
|
431
|
+
await fs.mkdir(parentDir, { recursive: true });
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
await execAsync(
|
|
435
|
+
`git clone ${gitInfo.repoUrl}.git "${targetDir}" --no-checkout`
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
await execAsync(
|
|
439
|
+
`git -C "${targetDir}" fetch --depth 1 origin ${commitHash}`
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
await execAsync(
|
|
443
|
+
`git -C "${targetDir}" checkout --force --detach ${commitHash}`
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
await fs.rm(path.join(targetDir, '.git'), { recursive: true, force: true });
|
|
447
|
+
} catch (error) {
|
|
448
|
+
await fs.rm(targetDir, { recursive: true, force: true });
|
|
449
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
450
|
+
throw new Error(
|
|
451
|
+
`Failed to download git repository ${gitInfo.repoUrl}@${gitInfo.version}: ${message}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Clears the entire cache.
|
|
458
|
+
*/
|
|
459
|
+
async clearCache(): Promise<void> {
|
|
460
|
+
await fs.rm(this.cacheDir, { recursive: true, force: true });
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Gets cache statistics (size, number of cached repos, etc.).
|
|
465
|
+
*/
|
|
466
|
+
async getCacheStats(): Promise<{
|
|
467
|
+
totalSize: number;
|
|
468
|
+
repoCount: number;
|
|
469
|
+
cacheDir: string;
|
|
470
|
+
}> {
|
|
471
|
+
let totalSize = 0;
|
|
472
|
+
let repoCount = 0;
|
|
473
|
+
|
|
474
|
+
try {
|
|
475
|
+
const platforms = await fs.readdir(this.cacheDir);
|
|
476
|
+
for (const platform of platforms) {
|
|
477
|
+
const platformPath = path.join(this.cacheDir, platform);
|
|
478
|
+
const owners = await fs.readdir(platformPath);
|
|
479
|
+
for (const owner of owners) {
|
|
480
|
+
const ownerPath = path.join(platformPath, owner);
|
|
481
|
+
const repos = await fs.readdir(ownerPath);
|
|
482
|
+
for (const repo of repos) {
|
|
483
|
+
const repoPath = path.join(ownerPath, repo);
|
|
484
|
+
const commits = await fs.readdir(repoPath);
|
|
485
|
+
repoCount += commits.length;
|
|
486
|
+
|
|
487
|
+
for (const commit of commits) {
|
|
488
|
+
const commitPath = path.join(repoPath, commit);
|
|
489
|
+
totalSize += await this.getDirectorySize(commitPath);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
} catch {
|
|
495
|
+
// Cache directory doesn't exist yet
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return {
|
|
499
|
+
totalSize,
|
|
500
|
+
repoCount,
|
|
501
|
+
cacheDir: this.cacheDir,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Gets the total size of a directory in bytes.
|
|
507
|
+
*/
|
|
508
|
+
private async getDirectorySize(dirPath: string): Promise<number> {
|
|
509
|
+
let size = 0;
|
|
510
|
+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
511
|
+
|
|
512
|
+
for (const entry of entries) {
|
|
513
|
+
const entryPath = path.join(dirPath, entry.name);
|
|
514
|
+
if (entry.isDirectory()) {
|
|
515
|
+
size += await this.getDirectorySize(entryPath);
|
|
516
|
+
} else {
|
|
517
|
+
const stats = await fs.stat(entryPath);
|
|
518
|
+
size += stats.size;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return size;
|
|
523
|
+
}
|
|
524
|
+
}
|