@dsh-workbench/adapter-profile 1.1.4 → 1.1.5
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.
|
@@ -15,6 +15,7 @@ export interface RegistryEntry {
|
|
|
15
15
|
export interface RegistryNotebook {
|
|
16
16
|
sources(): readonly RegistryEntry[];
|
|
17
17
|
remember(entries: readonly RegistryEntry[]): readonly string[];
|
|
18
|
+
swapScope?(scope: string, registry: string): () => void;
|
|
18
19
|
}
|
|
19
20
|
export declare const REGISTRY_MARKER = "# dsh-workbench \u5199\u7684\uFF1A\u8FD9\u4E00\u884C\u7684\u5305\u53EA\u5728\u8FD9\u4E2A\u6E90\u4E0A\uFF08dsh \u5378\u8F7D\u6CA1\u6709\u6E90\u53C2\u6570\uFF0Cpnpm \u5F97\u95EE\u5F97\u5230\uFF09";
|
|
20
21
|
export declare function scopeOf(pkg: string): string | null;
|
|
@@ -26,5 +27,6 @@ export interface RegistryConfigMerge {
|
|
|
26
27
|
readonly added: readonly string[];
|
|
27
28
|
}
|
|
28
29
|
export declare function mergeRegistryConfig(text: string, entries: readonly RegistryEntry[]): RegistryConfigMerge;
|
|
30
|
+
export declare function replaceScopeRegistry(text: string, scope: string, registry: string): string;
|
|
29
31
|
export declare function registryFailure(change: BundleChange): boolean;
|
|
30
32
|
export declare function createRegistryNotebook(dir: string | null): RegistryNotebook;
|
|
@@ -81,6 +81,34 @@ export function mergeRegistryConfig(text, entries) {
|
|
|
81
81
|
const marker = base.includes(REGISTRY_MARKER) ? '' : `${REGISTRY_MARKER}\n`;
|
|
82
82
|
return { text: `${base}${marker}${appended.join('\n')}\n`, added };
|
|
83
83
|
}
|
|
84
|
+
export function replaceScopeRegistry(text, scope, registry) {
|
|
85
|
+
const key = `${scope}:registry`;
|
|
86
|
+
const value = normalizeRegistry(registry);
|
|
87
|
+
let found = false;
|
|
88
|
+
const lines = text.split('\n').map((line) => {
|
|
89
|
+
if (!line.trim().startsWith(`${key}=`))
|
|
90
|
+
return line;
|
|
91
|
+
found = true;
|
|
92
|
+
return `${key}=${value}`;
|
|
93
|
+
});
|
|
94
|
+
if (found)
|
|
95
|
+
return lines.join('\n');
|
|
96
|
+
const base = text === '' ? '' : text.endsWith('\n') ? text : `${text}\n`;
|
|
97
|
+
return `${base}${key}=${value}\n`;
|
|
98
|
+
}
|
|
99
|
+
function readNpmrc(file) {
|
|
100
|
+
try {
|
|
101
|
+
return fs.readFileSync(file, 'utf8');
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function writeNpmrc(file, text) {
|
|
108
|
+
const temp = `${file}.dsh-workbench.tmp`;
|
|
109
|
+
fs.writeFileSync(temp, text, { mode: 0o600 });
|
|
110
|
+
fs.renameSync(temp, file);
|
|
111
|
+
}
|
|
84
112
|
export function registryFailure(change) {
|
|
85
113
|
if (change.application !== 'failed')
|
|
86
114
|
return false;
|
|
@@ -105,20 +133,40 @@ export function createRegistryNotebook(dir) {
|
|
|
105
133
|
if (dir === null || entries.length === 0)
|
|
106
134
|
return [];
|
|
107
135
|
const file = path.join(dir, '.npmrc');
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
before = fs.readFileSync(file, 'utf8');
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
before = '';
|
|
114
|
-
}
|
|
115
|
-
const merged = mergeRegistryConfig(before, entries);
|
|
136
|
+
const merged = mergeRegistryConfig(readNpmrc(file), entries);
|
|
116
137
|
if (merged.added.length === 0)
|
|
117
138
|
return [];
|
|
118
|
-
|
|
119
|
-
fs.writeFileSync(temp, merged.text, { mode: 0o600 });
|
|
120
|
-
fs.renameSync(temp, file);
|
|
139
|
+
writeNpmrc(file, merged.text);
|
|
121
140
|
return merged.added;
|
|
122
141
|
},
|
|
142
|
+
swapScope(scope, registry) {
|
|
143
|
+
if (dir === null || scope.trim() === '' || registry.trim() === '')
|
|
144
|
+
return () => { };
|
|
145
|
+
const file = path.join(dir, '.npmrc');
|
|
146
|
+
const key = `${scope.trim()}:registry`;
|
|
147
|
+
const value = normalizeRegistry(registry);
|
|
148
|
+
const before = readNpmrc(file);
|
|
149
|
+
const previous = before.split('\n').find((line) => line.trim().startsWith(`${key}=`));
|
|
150
|
+
const after = replaceScopeRegistry(before, scope.trim(), registry);
|
|
151
|
+
if (after === before)
|
|
152
|
+
return () => { };
|
|
153
|
+
writeNpmrc(file, after);
|
|
154
|
+
return () => {
|
|
155
|
+
const now = readNpmrc(file);
|
|
156
|
+
if (now === after) {
|
|
157
|
+
if (before === '')
|
|
158
|
+
fs.rmSync(file, { force: true });
|
|
159
|
+
else
|
|
160
|
+
writeNpmrc(file, before);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (!now.includes(`${key}=${value}`))
|
|
164
|
+
return;
|
|
165
|
+
const restored = previous === undefined
|
|
166
|
+
? now.split('\n').filter((line) => !line.trim().startsWith(`${key}=`)).join('\n')
|
|
167
|
+
: now.replace(`${key}=${value}`, previous);
|
|
168
|
+
writeNpmrc(file, restored);
|
|
169
|
+
};
|
|
170
|
+
},
|
|
123
171
|
};
|
|
124
172
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-workbench/adapter-profile",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Workbench profile adapter package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"execa": "^10.2.0",
|
|
33
33
|
"proper-lockfile": "^4.1.2",
|
|
34
34
|
"write-file-atomic": "^8.0.0",
|
|
35
|
-
"@dsh-workbench/adapter-runtime": "1.1.
|
|
36
|
-
"@dsh-workbench/shared": "1.1.
|
|
35
|
+
"@dsh-workbench/adapter-runtime": "1.1.5",
|
|
36
|
+
"@dsh-workbench/shared": "1.1.5"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -p tsconfig.json",
|