@infosupport/huddle-cli 0.0.0-experiment-56.68.1 → 0.0.0-experiment-136.72.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 +1 -0
- package/dist/index.js +4 -1
- package/dist/start.js +40 -0
- package/dist/vscode.js +144 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const self_update_1 = require("./self-update");
|
|
|
16
16
|
const utils_1 = require("./utils");
|
|
17
17
|
const experiment_1 = require("./experiment");
|
|
18
18
|
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output']);
|
|
19
|
-
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force']);
|
|
19
|
+
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'no-vscode-config']);
|
|
20
20
|
const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'experiment', 'migrate', 'help', 'version']);
|
|
21
21
|
function parseArgs(argv) {
|
|
22
22
|
const positional = [];
|
|
@@ -119,6 +119,8 @@ Start options:
|
|
|
119
119
|
--name <name> Container name (default: devcontainer-<foldername>)
|
|
120
120
|
--image <image> Use a specific image
|
|
121
121
|
--empty Empty container without a workspace
|
|
122
|
+
--no-vscode-config Do not write the per-container attach config
|
|
123
|
+
that makes VS Code open the workspace folder
|
|
122
124
|
|
|
123
125
|
Migrate options:
|
|
124
126
|
--ca-path <path> Where the Huddle CA lands in the container
|
|
@@ -182,6 +184,7 @@ async function main() {
|
|
|
182
184
|
name: flagString(flags, 'name'),
|
|
183
185
|
image: flagString(flags, 'image'),
|
|
184
186
|
empty: flagBool(flags, 'empty'),
|
|
187
|
+
vscodeConfig: !flagBool(flags, 'no-vscode-config'),
|
|
185
188
|
});
|
|
186
189
|
return;
|
|
187
190
|
}
|
package/dist/start.js
CHANGED
|
@@ -8,6 +8,7 @@ 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");
|
|
11
12
|
async function runStart(opts) {
|
|
12
13
|
const ide = parseIde(opts.ide);
|
|
13
14
|
const workspaceDir = opts.empty ? undefined : resolveWorkspace(opts.workspace);
|
|
@@ -37,12 +38,51 @@ async function runStart(opts) {
|
|
|
37
38
|
console.log((0, utils_1.green)(`[OK] Container started: ${result.containerName} (${result.id.slice(0, 12)})`));
|
|
38
39
|
console.log();
|
|
39
40
|
if (ide === 'vscode') {
|
|
41
|
+
const containerWorkspace = result.containerWorkspace ?? containerWorkspacePath(workspaceDir, containerName);
|
|
42
|
+
if (opts.vscodeConfig !== false) {
|
|
43
|
+
configureVscodeAttach(containerName, containerWorkspace, imageName);
|
|
44
|
+
}
|
|
40
45
|
console.log(`Open in VS Code: ${(0, utils_1.cyan)('Dev Containers: Attach to Running Container')} -> ${(0, utils_1.bold)(result.containerName)}`);
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
48
|
console.log(`Open in JetBrains Gateway: ${(0, utils_1.cyan)('Remote Development > Dev Containers')} -> ${(0, utils_1.bold)(result.containerName)}`);
|
|
44
49
|
await tryPrintIdeLink(result.containerName);
|
|
45
50
|
}
|
|
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
|
+
}
|
|
46
86
|
async function tryPrintIdeLink(containerName) {
|
|
47
87
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
48
88
|
try {
|
package/dist/vscode.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED