@sanlam-fintech-digital/mfe-platform-cli 0.3.0 → 0.4.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/dist/nuget/manager.js +44 -10
- package/package.json +1 -1
package/dist/nuget/manager.js
CHANGED
|
@@ -13,25 +13,59 @@ const os_1 = __importDefault(require("os"));
|
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
14
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
15
15
|
/**
|
|
16
|
-
* Get platform-specific NuGet config
|
|
16
|
+
* Get platform-specific NuGet config paths (primary and legacy fallback)
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
19
|
-
if (configPath)
|
|
20
|
-
return configPath;
|
|
18
|
+
function getNugetConfigPaths() {
|
|
21
19
|
const platform = process.platform;
|
|
22
20
|
if (platform === 'win32') {
|
|
23
21
|
const appData = process.env.APPDATA || path_1.default.join(os_1.default.homedir(), 'AppData', 'Roaming');
|
|
24
|
-
|
|
22
|
+
const primary = path_1.default.join(appData, 'NuGet', 'NuGet.Config');
|
|
23
|
+
return { primary, legacy: null };
|
|
25
24
|
}
|
|
26
25
|
else {
|
|
27
|
-
|
|
26
|
+
const primary = path_1.default.join(os_1.default.homedir(), '.nuget', 'NuGet', 'NuGet.Config');
|
|
27
|
+
const legacy = path_1.default.join(os_1.default.homedir(), '.config', 'NuGet', 'NuGet.Config');
|
|
28
|
+
return { primary, legacy };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the NuGet config path to use, checking both new and legacy locations.
|
|
33
|
+
* If a custom path is provided it is used as-is.
|
|
34
|
+
* Otherwise the new primary path (~/.nuget/NuGet/NuGet.Config) takes precedence,
|
|
35
|
+
* falling back to the legacy path (~/.config/NuGet/NuGet.Config) when it exists
|
|
36
|
+
* and the primary does not.
|
|
37
|
+
*/
|
|
38
|
+
async function resolveNugetConfigPath(configPath) {
|
|
39
|
+
if (configPath)
|
|
40
|
+
return configPath;
|
|
41
|
+
const { primary, legacy } = getNugetConfigPaths();
|
|
42
|
+
if (!legacy)
|
|
43
|
+
return primary;
|
|
44
|
+
// Prefer primary; fall back to legacy only when primary is absent (ENOENT)
|
|
45
|
+
try {
|
|
46
|
+
await promises_1.default.access(primary);
|
|
47
|
+
return primary;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
// Only fall back to legacy when the primary path truly does not exist.
|
|
51
|
+
// For any other error (e.g. EACCES, EIO) keep the primary path so the
|
|
52
|
+
// caller sees the real failure rather than silently switching paths.
|
|
53
|
+
if (err.code !== 'ENOENT')
|
|
54
|
+
return primary;
|
|
55
|
+
try {
|
|
56
|
+
await promises_1.default.access(legacy);
|
|
57
|
+
return legacy;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return primary;
|
|
61
|
+
}
|
|
28
62
|
}
|
|
29
63
|
}
|
|
30
64
|
/**
|
|
31
65
|
* Backup existing NuGet.config
|
|
32
66
|
*/
|
|
33
67
|
async function backupNugetConfig(configPath) {
|
|
34
|
-
const nugetPath =
|
|
68
|
+
const nugetPath = await resolveNugetConfigPath(configPath);
|
|
35
69
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
36
70
|
const backupPath = `${nugetPath}.backup.${timestamp}`;
|
|
37
71
|
try {
|
|
@@ -49,7 +83,7 @@ async function backupNugetConfig(configPath) {
|
|
|
49
83
|
* Read and parse NuGet.config
|
|
50
84
|
*/
|
|
51
85
|
async function readNugetConfig(configPath) {
|
|
52
|
-
const nugetPath =
|
|
86
|
+
const nugetPath = await resolveNugetConfigPath(configPath);
|
|
53
87
|
try {
|
|
54
88
|
const content = await promises_1.default.readFile(nugetPath, 'utf-8');
|
|
55
89
|
const parser = new fast_xml_parser_1.XMLParser({
|
|
@@ -117,7 +151,7 @@ async function addNuGetFeeds(feeds, tokenMap, configPath) {
|
|
|
117
151
|
* Write NuGet.config
|
|
118
152
|
*/
|
|
119
153
|
async function writeNugetConfig(config, configPath) {
|
|
120
|
-
const nugetPath =
|
|
154
|
+
const nugetPath = await resolveNugetConfigPath(configPath);
|
|
121
155
|
const dir = path_1.default.dirname(nugetPath);
|
|
122
156
|
// Ensure directory exists
|
|
123
157
|
await promises_1.default.mkdir(dir, { recursive: true });
|
|
@@ -138,6 +172,6 @@ async function writeNugetConfig(config, configPath) {
|
|
|
138
172
|
* Restore from backup
|
|
139
173
|
*/
|
|
140
174
|
async function restoreNugetFromBackup(backupPath, configPath) {
|
|
141
|
-
const nugetPath =
|
|
175
|
+
const nugetPath = await resolveNugetConfigPath(configPath);
|
|
142
176
|
await promises_1.default.copyFile(backupPath, nugetPath);
|
|
143
177
|
}
|