inai-react-components 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const program = new Command();
|
|
|
17
17
|
program
|
|
18
18
|
.name("inai-ui")
|
|
19
19
|
.description("CLI for InAI UI component library")
|
|
20
|
-
.version("1.6.
|
|
20
|
+
.version("1.6.1");
|
|
21
21
|
program
|
|
22
22
|
.command("init [repo-url]")
|
|
23
23
|
.description("Initialize InAI UI in your project. Optionally pass a Git repo URL to fetch components remotely.")
|
|
@@ -5,6 +5,11 @@ export declare function getRegistryCacheDir(name: string): string;
|
|
|
5
5
|
* Clone (or fast-forward) a git registry into the legacy single-cache
|
|
6
6
|
* directory. Preserved for backward compatibility with the v0.5.0
|
|
7
7
|
* code path that called this directly.
|
|
8
|
+
*
|
|
9
|
+
* If a prior cache is present but refuses to fast-forward (dirty tree,
|
|
10
|
+
* diverged history, interrupted previous run), the cache is reset to
|
|
11
|
+
* match origin; if that also fails, the directory is nuked and a fresh
|
|
12
|
+
* clone is done. Users should never have to touch `~/.inai-ui/registry`.
|
|
8
13
|
*/
|
|
9
14
|
export declare function cloneRegistry(repoUrl: string): string;
|
|
10
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/registry-resolver.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAS7E,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;
|
|
1
|
+
{"version":3,"file":"registry-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/registry-resolver.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAS7E,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AA8CD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAcrD;AAmBD;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,MAAM,CAAC,CA+FjB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAS7D"}
|
|
@@ -15,22 +15,71 @@ export function getCacheDir() {
|
|
|
15
15
|
export function getRegistryCacheDir(name) {
|
|
16
16
|
return path.join(REGISTRIES_CACHE_DIR, name);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Attempt to refresh an existing git cache to the latest upstream state.
|
|
20
|
+
* Tries `git pull --ff-only` first, and if the working tree is dirty or
|
|
21
|
+
* has diverged from upstream (either of which aborts the fast-forward),
|
|
22
|
+
* falls back to a hard reset + clean so the cache matches origin exactly.
|
|
23
|
+
*
|
|
24
|
+
* The cache is an implementation detail of the CLI — users should never
|
|
25
|
+
* have to edit files inside it, so any local changes are unconditionally
|
|
26
|
+
* discarded in favor of whatever origin currently ships.
|
|
27
|
+
*
|
|
28
|
+
* Returns `true` on success, `false` if both pull and reset failed (in
|
|
29
|
+
* which case the caller should nuke the directory and re-clone).
|
|
30
|
+
*/
|
|
31
|
+
function refreshGitCache(cacheDir) {
|
|
32
|
+
try {
|
|
33
|
+
execSync("git pull --ff-only", { cwd: cacheDir, stdio: "pipe" });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Dirty tree, diverged history, or both. Salvage the clone by
|
|
38
|
+
// fetching fresh refs and resetting hard onto origin's default
|
|
39
|
+
// branch. `git clean -fd` drops any untracked files the user (or a
|
|
40
|
+
// previous botched run) left behind.
|
|
41
|
+
try {
|
|
42
|
+
execSync("git fetch --all --prune", { cwd: cacheDir, stdio: "pipe" });
|
|
43
|
+
// Derive the remote HEAD dynamically so we respect whatever branch
|
|
44
|
+
// origin tracks (main, master, develop, ...).
|
|
45
|
+
const remoteHead = execSync("git symbolic-ref refs/remotes/origin/HEAD", { cwd: cacheDir, stdio: ["pipe", "pipe", "pipe"] })
|
|
46
|
+
.toString()
|
|
47
|
+
.trim();
|
|
48
|
+
execSync(`git reset --hard ${remoteHead}`, {
|
|
49
|
+
cwd: cacheDir,
|
|
50
|
+
stdio: "pipe",
|
|
51
|
+
});
|
|
52
|
+
execSync("git clean -fd", { cwd: cacheDir, stdio: "pipe" });
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
18
60
|
/**
|
|
19
61
|
* Clone (or fast-forward) a git registry into the legacy single-cache
|
|
20
62
|
* directory. Preserved for backward compatibility with the v0.5.0
|
|
21
63
|
* code path that called this directly.
|
|
64
|
+
*
|
|
65
|
+
* If a prior cache is present but refuses to fast-forward (dirty tree,
|
|
66
|
+
* diverged history, interrupted previous run), the cache is reset to
|
|
67
|
+
* match origin; if that also fails, the directory is nuked and a fresh
|
|
68
|
+
* clone is done. Users should never have to touch `~/.inai-ui/registry`.
|
|
22
69
|
*/
|
|
23
70
|
export function cloneRegistry(repoUrl) {
|
|
24
71
|
if (fs.existsSync(path.join(LEGACY_CACHE_DIR, ".git"))) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
else {
|
|
28
|
-
fs.mkdirSync(CACHE_BASE, { recursive: true });
|
|
29
|
-
if (fs.existsSync(LEGACY_CACHE_DIR)) {
|
|
30
|
-
fs.rmSync(LEGACY_CACHE_DIR, { recursive: true });
|
|
72
|
+
if (refreshGitCache(LEGACY_CACHE_DIR)) {
|
|
73
|
+
return LEGACY_CACHE_DIR;
|
|
31
74
|
}
|
|
32
|
-
|
|
75
|
+
// Salvage failed — nuke and re-clone below.
|
|
76
|
+
fs.rmSync(LEGACY_CACHE_DIR, { recursive: true, force: true });
|
|
77
|
+
}
|
|
78
|
+
fs.mkdirSync(CACHE_BASE, { recursive: true });
|
|
79
|
+
if (fs.existsSync(LEGACY_CACHE_DIR)) {
|
|
80
|
+
fs.rmSync(LEGACY_CACHE_DIR, { recursive: true });
|
|
33
81
|
}
|
|
82
|
+
execSync(`git clone "${repoUrl}" "${LEGACY_CACHE_DIR}"`, { stdio: "pipe" });
|
|
34
83
|
return LEGACY_CACHE_DIR;
|
|
35
84
|
}
|
|
36
85
|
/**
|
|
@@ -89,18 +138,13 @@ export async function resolveRegistry(registry, projectDir, options = {}) {
|
|
|
89
138
|
const cloneUrl = token ? embedTokenInGitUrl(registry.url, token) : registry.url;
|
|
90
139
|
const branch = registry.branch ?? "main";
|
|
91
140
|
if (fs.existsSync(path.join(cacheDir, ".git"))) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
catch {
|
|
96
|
-
// If pull fails (network hiccup, diverged), fall back to cached copy.
|
|
141
|
+
if (!refreshGitCache(cacheDir)) {
|
|
142
|
+
// Salvage failed — nuke and re-clone below.
|
|
143
|
+
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
97
144
|
}
|
|
98
145
|
}
|
|
99
|
-
|
|
146
|
+
if (!fs.existsSync(path.join(cacheDir, ".git"))) {
|
|
100
147
|
fs.mkdirSync(REGISTRIES_CACHE_DIR, { recursive: true });
|
|
101
|
-
if (fs.existsSync(cacheDir)) {
|
|
102
|
-
fs.rmSync(cacheDir, { recursive: true });
|
|
103
|
-
}
|
|
104
148
|
execSync(`git clone --branch "${branch}" "${cloneUrl}" "${cacheDir}"`, { stdio: "pipe" });
|
|
105
149
|
}
|
|
106
150
|
return cacheDir;
|
package/package.json
CHANGED