@infosupport/huddle-cli 0.0.0-experiment-136.72.1 → 0.0.0-experiment-98.74.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/README.md +53 -1
- package/dist/config.js +145 -6
- package/dist/experiment.js +12 -7
- package/dist/firewall.js +184 -3
- package/dist/images.js +13 -9
- package/dist/index.js +119 -8
- package/dist/indexfolder.js +167 -0
- package/dist/init.js +49 -26
- package/dist/migrate.js +67 -58
- package/dist/start.js +49 -42
- package/package.json +1 -1
- package/dist/vscode.js +0 -144
package/dist/migrate.js
CHANGED
|
@@ -292,67 +292,76 @@ function rejectUnsupportedYaml(lines) {
|
|
|
292
292
|
throw unsupportedYaml('a YAML alias (`*`)');
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
+
function atIndent(c, indent) {
|
|
296
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent === indent;
|
|
297
|
+
}
|
|
298
|
+
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
299
|
+
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
300
|
+
function parseNode(c, indent, depth) {
|
|
301
|
+
if (depth > MAX_YAML_DEPTH) {
|
|
302
|
+
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
303
|
+
}
|
|
304
|
+
if (c.pos >= c.lines.length || c.lines[c.pos].indent < indent)
|
|
305
|
+
return null;
|
|
306
|
+
return isSeqItem(c.lines[c.pos].text) ? parseSequence(c, indent, depth) : parseMapping(c, indent, depth);
|
|
307
|
+
}
|
|
308
|
+
function parseMapping(c, indent, depth) {
|
|
309
|
+
const map = {};
|
|
310
|
+
while (atIndent(c, indent) && !isSeqItem(c.lines[c.pos].text)) {
|
|
311
|
+
const { text } = c.lines[c.pos];
|
|
312
|
+
const colon = findKeyColon(text);
|
|
313
|
+
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
314
|
+
if (colon < 0)
|
|
315
|
+
break;
|
|
316
|
+
const key = unquote(text.slice(0, colon).trim());
|
|
317
|
+
const rest = text.slice(colon + 1).trim();
|
|
318
|
+
c.pos++;
|
|
319
|
+
map[key] = parseMappingValue(c, rest, indent, depth);
|
|
320
|
+
}
|
|
321
|
+
return map;
|
|
322
|
+
}
|
|
323
|
+
/** The value belonging to `key:` — inline, the indented block below it, or none. */
|
|
324
|
+
function parseMappingValue(c, rest, indent, depth) {
|
|
325
|
+
if (rest !== '')
|
|
326
|
+
return parseScalar(rest);
|
|
327
|
+
if (c.pos < c.lines.length && c.lines[c.pos].indent > indent) {
|
|
328
|
+
return parseNode(c, c.lines[c.pos].indent, depth + 1);
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function parseSequence(c, indent, depth) {
|
|
333
|
+
const arr = [];
|
|
334
|
+
while (atIndent(c, indent) && isSeqItem(c.lines[c.pos].text)) {
|
|
335
|
+
arr.push(parseSequenceItem(c, indent, depth));
|
|
336
|
+
}
|
|
337
|
+
return arr;
|
|
338
|
+
}
|
|
339
|
+
function parseSequenceItem(c, indent, depth) {
|
|
340
|
+
const line = c.lines[c.pos];
|
|
341
|
+
const afterDash = line.text.replace(/^-\s*/, '');
|
|
342
|
+
// A bare `-`: the item is the indented block on the following lines.
|
|
343
|
+
if (afterDash === '') {
|
|
344
|
+
c.pos++;
|
|
345
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent > indent
|
|
346
|
+
? parseNode(c, c.lines[c.pos].indent, depth + 1)
|
|
347
|
+
: null;
|
|
348
|
+
}
|
|
349
|
+
// Inline map item: "- key: value". Re-interpret the remainder as a mapping
|
|
350
|
+
// that starts at a virtual indent past the dash. parseMapping consumes this
|
|
351
|
+
// same line, so the cursor deliberately does not advance here.
|
|
352
|
+
if (findKeyColon(afterDash) >= 0) {
|
|
353
|
+
const virtualIndent = indent + (line.text.length - afterDash.length);
|
|
354
|
+
c.lines[c.pos] = { indent: virtualIndent, text: afterDash };
|
|
355
|
+
return parseMapping(c, virtualIndent, depth + 1);
|
|
356
|
+
}
|
|
357
|
+
c.pos++;
|
|
358
|
+
return parseScalar(afterDash);
|
|
359
|
+
}
|
|
295
360
|
function parseYaml(input) {
|
|
296
361
|
const lines = tokenize(input);
|
|
297
362
|
rejectUnsupportedYaml(lines);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
301
|
-
function parseNode(indent, depth) {
|
|
302
|
-
if (depth > MAX_YAML_DEPTH) {
|
|
303
|
-
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
304
|
-
}
|
|
305
|
-
if (pos >= lines.length || lines[pos].indent < indent)
|
|
306
|
-
return null;
|
|
307
|
-
return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
|
|
308
|
-
}
|
|
309
|
-
function parseMapping(indent, depth) {
|
|
310
|
-
const map = {};
|
|
311
|
-
while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
|
|
312
|
-
const { text } = lines[pos];
|
|
313
|
-
const colon = findKeyColon(text);
|
|
314
|
-
if (colon < 0) {
|
|
315
|
-
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const key = unquote(text.slice(0, colon).trim());
|
|
319
|
-
const rest = text.slice(colon + 1).trim();
|
|
320
|
-
pos++;
|
|
321
|
-
if (rest !== '') {
|
|
322
|
-
map[key] = parseScalar(rest);
|
|
323
|
-
}
|
|
324
|
-
else if (pos < lines.length && lines[pos].indent > indent) {
|
|
325
|
-
map[key] = parseNode(lines[pos].indent, depth + 1);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
map[key] = null;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return map;
|
|
332
|
-
}
|
|
333
|
-
function parseSequence(indent, depth) {
|
|
334
|
-
const arr = [];
|
|
335
|
-
while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
|
|
336
|
-
const afterDash = lines[pos].text.replace(/^-\s*/, '');
|
|
337
|
-
if (afterDash === '') {
|
|
338
|
-
pos++;
|
|
339
|
-
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
|
|
340
|
-
}
|
|
341
|
-
else if (findKeyColon(afterDash) >= 0) {
|
|
342
|
-
// Inline map item: "- key: value". Re-interpret the remainder as a
|
|
343
|
-
// mapping that starts at a virtual indent past the dash.
|
|
344
|
-
const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
|
|
345
|
-
lines[pos] = { indent: virtualIndent, text: afterDash };
|
|
346
|
-
arr.push(parseMapping(virtualIndent, depth + 1));
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
arr.push(parseScalar(afterDash));
|
|
350
|
-
pos++;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return arr;
|
|
354
|
-
}
|
|
355
|
-
const root = parseNode(lines.length ? lines[0].indent : 0, 0);
|
|
363
|
+
const cursor = { lines, pos: 0 };
|
|
364
|
+
const root = parseNode(cursor, lines.length ? lines[0].indent : 0, 0);
|
|
356
365
|
return (root && typeof root === 'object' ? root : {});
|
|
357
366
|
}
|
|
358
367
|
function isSeqItem(text) {
|
package/dist/start.js
CHANGED
|
@@ -8,15 +8,49 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const api_1 = require("./api");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
-
const vscode_1 = require("./vscode");
|
|
12
11
|
async function runStart(opts) {
|
|
13
12
|
const ide = parseIde(opts.ide);
|
|
14
|
-
const
|
|
15
|
-
|
|
13
|
+
const hasMounts = !!opts.mounts && opts.mounts.length > 0;
|
|
14
|
+
if (hasMounts && opts.workspace) {
|
|
15
|
+
throw new Error('Cannot combine --workspace with --mount; use --mount for every folder instead.');
|
|
16
|
+
}
|
|
17
|
+
if (hasMounts && opts.empty) {
|
|
18
|
+
throw new Error('Cannot combine --empty with --mount.');
|
|
19
|
+
}
|
|
20
|
+
const resolvedMounts = hasMounts
|
|
21
|
+
? opts.mounts.map((m) => ({ hostPath: resolveWorkspace(m.hostPath), containerPath: validateContainerPath(m.containerPath) }))
|
|
22
|
+
: undefined;
|
|
23
|
+
if (resolvedMounts) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const m of resolvedMounts) {
|
|
26
|
+
if (seen.has(m.containerPath))
|
|
27
|
+
throw new Error(`Duplicate --mount container path: ${m.containerPath}`);
|
|
28
|
+
seen.add(m.containerPath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const workspaceRoot = opts.workspaceRoot?.trim() || undefined;
|
|
32
|
+
if (workspaceRoot && !hasMounts) {
|
|
33
|
+
throw new Error('--workspace-root requires at least one --mount.');
|
|
34
|
+
}
|
|
35
|
+
if (workspaceRoot && !workspaceRoot.startsWith('/')) {
|
|
36
|
+
throw new Error(`--workspace-root must be an absolute container path: "${workspaceRoot}".`);
|
|
37
|
+
}
|
|
38
|
+
const workspaceDir = opts.empty || hasMounts ? undefined : resolveWorkspace(opts.workspace);
|
|
39
|
+
const baseName = opts.empty
|
|
40
|
+
? 'empty'
|
|
41
|
+
: hasMounts
|
|
42
|
+
? (resolvedMounts[0].containerPath.split('/').filter(Boolean).pop() ?? 'workspace')
|
|
43
|
+
: path_1.default.basename(workspaceDir);
|
|
16
44
|
const containerName = opts.name ? validateContainerName(opts.name) : defaultContainerName(baseName);
|
|
17
45
|
console.log(`Starting ${(0, utils_1.bold)(containerName)} with ${(0, utils_1.bold)(ide)}...`);
|
|
18
46
|
if (workspaceDir)
|
|
19
47
|
console.log((0, utils_1.dim)(`Workspace: ${workspaceDir}`));
|
|
48
|
+
if (resolvedMounts) {
|
|
49
|
+
for (const m of resolvedMounts)
|
|
50
|
+
console.log((0, utils_1.dim)(`Mount ${m.hostPath} -> ${m.containerPath}`));
|
|
51
|
+
if (workspaceRoot)
|
|
52
|
+
console.log((0, utils_1.dim)(`Open IDE at: ${workspaceRoot}`));
|
|
53
|
+
}
|
|
20
54
|
let imageName = opts.image;
|
|
21
55
|
if (!imageName) {
|
|
22
56
|
const res = await (0, api_1.get)(`/api/docker/base-image?ide=${encodeURIComponent(ide)}`);
|
|
@@ -31,6 +65,11 @@ async function runStart(opts) {
|
|
|
31
65
|
if (opts.empty) {
|
|
32
66
|
body.empty = true;
|
|
33
67
|
}
|
|
68
|
+
else if (resolvedMounts) {
|
|
69
|
+
body.mounts = resolvedMounts;
|
|
70
|
+
if (workspaceRoot)
|
|
71
|
+
body.containerWorkspace = workspaceRoot;
|
|
72
|
+
}
|
|
34
73
|
else {
|
|
35
74
|
body.workspaceDir = workspaceDir;
|
|
36
75
|
}
|
|
@@ -38,51 +77,12 @@ async function runStart(opts) {
|
|
|
38
77
|
console.log((0, utils_1.green)(`[OK] Container started: ${result.containerName} (${result.id.slice(0, 12)})`));
|
|
39
78
|
console.log();
|
|
40
79
|
if (ide === 'vscode') {
|
|
41
|
-
const containerWorkspace = result.containerWorkspace ?? containerWorkspacePath(workspaceDir, containerName);
|
|
42
|
-
if (opts.vscodeConfig !== false) {
|
|
43
|
-
configureVscodeAttach(containerName, containerWorkspace, imageName);
|
|
44
|
-
}
|
|
45
80
|
console.log(`Open in VS Code: ${(0, utils_1.cyan)('Dev Containers: Attach to Running Container')} -> ${(0, utils_1.bold)(result.containerName)}`);
|
|
46
81
|
return;
|
|
47
82
|
}
|
|
48
83
|
console.log(`Open in JetBrains Gateway: ${(0, utils_1.cyan)('Remote Development > Dev Containers')} -> ${(0, utils_1.bold)(result.containerName)}`);
|
|
49
84
|
await tryPrintIdeLink(result.containerName);
|
|
50
85
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Teach VS Code which folder to open on attach. Best-effort: a failure here
|
|
53
|
-
* costs one manual File > Open Folder, never the container itself.
|
|
54
|
-
*/
|
|
55
|
-
function configureVscodeAttach(containerName, containerWorkspace, imageName) {
|
|
56
|
-
let result;
|
|
57
|
-
try {
|
|
58
|
-
result = (0, vscode_1.writeAttachedContainerConfig)(containerName, containerWorkspace);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
console.log((0, utils_1.yellow)(`! Could not configure VS Code: ${err instanceof Error ? err.message : String(err)}`));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
for (const file of result.written) {
|
|
65
|
-
console.log((0, utils_1.dim)(`VS Code will open ${containerWorkspace} on attach (${file})`));
|
|
66
|
-
}
|
|
67
|
-
for (const { file, reason } of result.skipped) {
|
|
68
|
-
console.log((0, utils_1.yellow)(`! Left ${file} untouched: ${reason}`));
|
|
69
|
-
}
|
|
70
|
-
if (!result.written.length && !result.skipped.length) {
|
|
71
|
-
console.log((0, utils_1.dim)('No VS Code config changes were made; if attach opens an empty window, use File > Open Folder on the container workspace.'));
|
|
72
|
-
}
|
|
73
|
-
// The name-level config above wins for THIS container, but a leftover
|
|
74
|
-
// image-level one still misdirects every other container on the same image.
|
|
75
|
-
for (const file of (0, vscode_1.findImageConfigs)(imageName)) {
|
|
76
|
-
console.log((0, utils_1.yellow)(`! Image-level config still present: ${file} (applies to every container from this image; consider deleting it)`));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/** Mirrors the gateway's containerWorkspacePath() for gateways that predate it. */
|
|
80
|
-
function containerWorkspacePath(workspaceDir, containerName) {
|
|
81
|
-
const leaf = workspaceDir
|
|
82
|
-
? workspaceDir.replace(/\\/g, '/').replace(/\/$/, '').split('/').pop() || containerName
|
|
83
|
-
: containerName.replace(/^devcontainer-/, '') || containerName;
|
|
84
|
-
return `/workspaces/${leaf}`;
|
|
85
|
-
}
|
|
86
86
|
async function tryPrintIdeLink(containerName) {
|
|
87
87
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
88
88
|
try {
|
|
@@ -119,6 +119,13 @@ function validateContainerName(name) {
|
|
|
119
119
|
}
|
|
120
120
|
return trimmed;
|
|
121
121
|
}
|
|
122
|
+
function validateContainerPath(path) {
|
|
123
|
+
const trimmed = (path ?? '').replace(/\\/g, '/').replace(/\/+$/, '').trim();
|
|
124
|
+
if (!trimmed.startsWith('/')) {
|
|
125
|
+
throw new Error(`Invalid --mount container path: "${path}". Use an absolute path, e.g. /workspace/backend.`);
|
|
126
|
+
}
|
|
127
|
+
return trimmed;
|
|
128
|
+
}
|
|
122
129
|
function parseIde(value) {
|
|
123
130
|
const normalized = value.toLowerCase().replace(/[ _-]+/g, '');
|
|
124
131
|
if (normalized === 'rider')
|
package/package.json
CHANGED
package/dist/vscode.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeAttachedContainerConfig = writeAttachedContainerConfig;
|
|
7
|
-
exports.findImageConfigs = findImageConfigs;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const os_1 = __importDefault(require("os"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const child_process_1 = require("child_process");
|
|
12
|
-
/**
|
|
13
|
-
* VS Code's "Attach to Running Container" decides which folder to open from an
|
|
14
|
-
* *attached container configuration file* on the host, and from nothing else:
|
|
15
|
-
* the Dev Containers extension reads `nameConfigs/<container>.json` first and
|
|
16
|
-
* falls back to `imageConfigs/<image>.json`; when neither holds a
|
|
17
|
-
* `workspaceFolder` it opens an empty window. Container labels play no part in
|
|
18
|
-
* that decision — `devcontainer.metadata` is only consumed by the build flow,
|
|
19
|
-
* and its merge drops every property outside the image-metadata spec (which
|
|
20
|
-
* does not include `workspaceFolder`).
|
|
21
|
-
*
|
|
22
|
-
* So huddle writes the per-container config itself. Per container, never per
|
|
23
|
-
* image: an image-level file would pin one workspace path for every container
|
|
24
|
-
* started from the same base image.
|
|
25
|
-
*/
|
|
26
|
-
const EXT_DIR = 'ms-vscode-remote.remote-containers';
|
|
27
|
-
/** VS Code's own escaping for config file names (see `nameConfigs` lookup). */
|
|
28
|
-
function encodeConfigName(containerName) {
|
|
29
|
-
return containerName.replace(/[:/%]/g, (c) => `%${c.charCodeAt(0).toString(16)}`);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* User-data directories of the installed VS Code flavours — the directory that
|
|
33
|
-
* holds `User/`, i.e. what `code --user-data-dir` points at. Insiders keeps its
|
|
34
|
-
* own tree, and a Flatpak install relocates the whole thing.
|
|
35
|
-
*/
|
|
36
|
-
function userDataDirCandidates() {
|
|
37
|
-
const override = process.env.HUDDLE_VSCODE_USER_DIR?.trim();
|
|
38
|
-
if (override)
|
|
39
|
-
return [override];
|
|
40
|
-
const home = os_1.default.homedir();
|
|
41
|
-
const dirs = [];
|
|
42
|
-
if (process.platform === 'win32') {
|
|
43
|
-
const appData = process.env.APPDATA ?? path_1.default.join(home, 'AppData', 'Roaming');
|
|
44
|
-
dirs.push(path_1.default.join(appData, 'Code'), path_1.default.join(appData, 'Code - Insiders'));
|
|
45
|
-
}
|
|
46
|
-
else if (process.platform === 'darwin') {
|
|
47
|
-
const support = path_1.default.join(home, 'Library', 'Application Support');
|
|
48
|
-
dirs.push(path_1.default.join(support, 'Code'), path_1.default.join(support, 'Code - Insiders'));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
dirs.push(path_1.default.join(home, '.config', 'Code'), path_1.default.join(home, '.config', 'Code - Insiders'));
|
|
52
|
-
dirs.push(path_1.default.join(home, '.var', 'app', 'com.visualstudio.code', 'config', 'Code'));
|
|
53
|
-
dirs.push(path_1.default.join(home, '.var', 'app', 'com.visualstudio.code.insiders', 'config', 'Code - Insiders'));
|
|
54
|
-
// On WSL the CLI runs in the distro while VS Code runs on Windows and reads
|
|
55
|
-
// its config from %APPDATA% there, so the Linux paths above would never be
|
|
56
|
-
// seen by the editor doing the attach.
|
|
57
|
-
for (const appData of windowsAppDataFromWsl()) {
|
|
58
|
-
dirs.push(path_1.default.join(appData, 'Code'), path_1.default.join(appData, 'Code - Insiders'));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return dirs;
|
|
62
|
-
}
|
|
63
|
-
/** Best-effort %APPDATA% as seen from inside WSL; empty when not on WSL. */
|
|
64
|
-
function windowsAppDataFromWsl() {
|
|
65
|
-
try {
|
|
66
|
-
if (!fs_1.default.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft'))
|
|
67
|
-
return [];
|
|
68
|
-
const appData = (0, child_process_1.execFileSync)('cmd.exe', ['/c', 'echo %APPDATA%'], {
|
|
69
|
-
encoding: 'utf8',
|
|
70
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
71
|
-
cwd: '/',
|
|
72
|
-
}).trim();
|
|
73
|
-
if (!appData || appData.includes('%APPDATA%'))
|
|
74
|
-
return [];
|
|
75
|
-
const unix = (0, child_process_1.execFileSync)('wslpath', ['-u', appData], {
|
|
76
|
-
encoding: 'utf8',
|
|
77
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
78
|
-
}).trim();
|
|
79
|
-
return unix ? [unix] : [];
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// No WSL interop (or cmd.exe/wslpath missing): nothing to configure there.
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Point every installed VS Code flavour at `workspaceFolder` when attaching to
|
|
88
|
-
* `containerName`. Only flavours that already have a `User/globalStorage` tree
|
|
89
|
-
* are touched — creating that tree for an editor that is not installed would
|
|
90
|
-
* leave dead config behind.
|
|
91
|
-
*/
|
|
92
|
-
function writeAttachedContainerConfig(containerName, workspaceFolder) {
|
|
93
|
-
const result = { written: [], skipped: [] };
|
|
94
|
-
for (const userDataDir of userDataDirCandidates()) {
|
|
95
|
-
const globalStorage = path_1.default.join(userDataDir, 'User', 'globalStorage');
|
|
96
|
-
if (!fs_1.default.existsSync(globalStorage))
|
|
97
|
-
continue;
|
|
98
|
-
const file = path_1.default.join(globalStorage, EXT_DIR, 'nameConfigs', `${encodeConfigName(containerName)}.json`);
|
|
99
|
-
let config = {};
|
|
100
|
-
if (fs_1.default.existsSync(file)) {
|
|
101
|
-
try {
|
|
102
|
-
const parsed = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
|
|
103
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
104
|
-
config = parsed;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
// Hand-edited file with comments or a syntax error: leave it alone
|
|
109
|
-
// rather than throw away settings the user put there.
|
|
110
|
-
result.skipped.push({ file, reason: 'existing config is not valid JSON' });
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (config.workspaceFolder === workspaceFolder)
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
config.workspaceFolder = workspaceFolder;
|
|
117
|
-
try {
|
|
118
|
-
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
|
|
119
|
-
// Tab indentation matches what the extension itself writes back into
|
|
120
|
-
// this file when you open another folder inside the container.
|
|
121
|
-
fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, '\t')}\n`);
|
|
122
|
-
result.written.push(file);
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
result.skipped.push({ file, reason: err instanceof Error ? err.message : String(err) });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* An image-level config outranks nothing (the name-level file wins) but it does
|
|
132
|
-
* apply to every other container from the same base image, where its workspace
|
|
133
|
-
* path does not exist. Report it so the operator can clean it up.
|
|
134
|
-
*/
|
|
135
|
-
function findImageConfigs(imageName) {
|
|
136
|
-
const encoded = encodeConfigName(imageName);
|
|
137
|
-
const found = [];
|
|
138
|
-
for (const userDataDir of userDataDirCandidates()) {
|
|
139
|
-
const file = path_1.default.join(userDataDir, 'User', 'globalStorage', EXT_DIR, 'imageConfigs', `${encoded}.json`);
|
|
140
|
-
if (fs_1.default.existsSync(file))
|
|
141
|
-
found.push(file);
|
|
142
|
-
}
|
|
143
|
-
return found;
|
|
144
|
-
}
|