Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const buildOptions = {
// undefined when bundled to CJS, causing runtime errors.
openpgp: "./node_modules/openpgp/dist/node/openpgp.min.cjs",
},
external: ["vscode"],
external: ["vscode", "@napi-rs/keyring"],
sourcemap: production ? "external" : true,
minify: production,
plugins: watch ? [logRebuildPlugin] : [],
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default defineConfig(

// Build config - ESM with Node globals
{
files: ["esbuild.mjs"],
files: ["esbuild.mjs", "scripts/*.mjs"],
languageOptions: {
globals: {
...globals.node,
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test:integration": "tsc -p test --outDir out --noCheck && node esbuild.mjs && vscode-test",
"test:webview": "vitest --project webview",
"typecheck": "concurrently -g \"tsc --noEmit\" \"tsc --noEmit -p test\"",
"vscode:prepublish": "pnpm build:production",
"vscode:prepublish": "pnpm build:production && node scripts/vendor-keyring.mjs",
"watch": "concurrently -n extension,webviews \"pnpm watch:extension\" \"pnpm watch:webviews\"",
"watch:extension": "node esbuild.mjs --watch",
"watch:webviews": "pnpm -r --filter \"./packages/*\" --parallel dev"
Expand Down Expand Up @@ -164,6 +164,11 @@
"type": "string"
}
},
"coder.useKeyring": {
"markdownDescription": "Store session tokens in the OS keyring (macOS Keychain, Windows Credential Manager) instead of plaintext files. Requires CLI >= 2.29.0. Has no effect on Linux.",
"type": "boolean",
"default": true
},
"coder.httpClientLogLevel": {
"markdownDescription": "Controls the verbosity of HTTP client logging. This affects what details are logged for each HTTP request and response.",
"type": "string",
Expand Down Expand Up @@ -471,6 +476,7 @@
"word-wrap": "1.2.5"
},
"dependencies": {
"@napi-rs/keyring": "^1.2.0",
"@peculiar/x509": "^1.14.3",
"@repo/shared": "workspace:*",
"axios": "1.13.5",
Expand Down
143 changes: 139 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ onlyBuiltDependencies:
- keytar
- unrs-resolver
- utf-8-validate

# Install @napi-rs/keyring native binaries for macOS and Windows so they're
# available when building the universal VSIX (even on Linux CI).
# Only macOS and Windows use the keyring; Linux falls back to file storage.
supportedArchitectures:
os:
- current
- darwin
- win32
cpu:
- current
- x64
- arm64
61 changes: 61 additions & 0 deletions scripts/vendor-keyring.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Vendor @napi-rs/keyring into dist/node_modules/ for VSIX packaging.
*
* pnpm uses symlinks that vsce can't follow. This script resolves them and
* copies the JS wrapper plus macOS/Windows .node binaries into dist/, where
* Node's require() resolution finds them from dist/extension.js.
*/
import {
cpSync,
existsSync,
mkdirSync,
readdirSync,
realpathSync,
rmSync,
} from "node:fs";
import { join, resolve } from "node:path";

const keyringPkg = resolve("node_modules/@napi-rs/keyring");
const outputDir = resolve("dist/node_modules/@napi-rs/keyring");

if (!existsSync(keyringPkg)) {
console.error("@napi-rs/keyring not found — run pnpm install first");
process.exit(1);
}

// Copy the JS wrapper package (resolving pnpm symlinks)
const resolvedPkg = realpathSync(keyringPkg);
rmSync(outputDir, { recursive: true, force: true });
mkdirSync(outputDir, { recursive: true });
cpSync(resolvedPkg, outputDir, { recursive: true });

// Native binary packages live as siblings of the resolved keyring package in
// pnpm's content-addressable store (they aren't hoisted to node_modules).
const siblingsDir = resolve(resolvedPkg, "..");
const nativePackages = [
"keyring-darwin-arm64",
"keyring-darwin-x64",
"keyring-win32-arm64-msvc",
"keyring-win32-x64-msvc",
];
Comment on lines +35 to +40
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make a universal VSIX, we have to package all of these (x64 and arm64 for macOS and Windows). Potentially we can split this into separate VSIXs (esp. when we have linux which has even more).

The universal VSIX went from 1.02MB to 1.80MB. Almost doubled but still acceptable IMO


for (const pkg of nativePackages) {
const pkgDir = join(siblingsDir, pkg);
if (!existsSync(pkgDir)) {
console.error(
`Missing native package: ${pkg}\n` +
"Ensure supportedArchitectures in pnpm-workspace.yaml includes all target platforms.",
);
process.exit(1);
}
const nodeFile = readdirSync(pkgDir).find((f) => f.endsWith(".node"));
if (!nodeFile) {
console.error(`No .node binary found in ${pkg}`);
process.exit(1);
}
cpSync(join(pkgDir, nodeFile), join(outputDir, nodeFile));
}

console.log(
`Vendored @napi-rs/keyring with ${nativePackages.length} platform binaries into dist/`,
);
6 changes: 3 additions & 3 deletions src/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { spawn } from "node:child_process";
import * as vscode from "vscode";

import { getGlobalFlags } from "../cliConfig";
import { type CliAuth, getGlobalFlags } from "../cliConfig";
import { type FeatureSet } from "../featureSet";
import { escapeCommandArg } from "../util";
import { type UnidirectionalStream } from "../websocket/eventStreamConnection";
Expand Down Expand Up @@ -50,7 +50,7 @@ export class LazyStream<T> {
*/
export async function startWorkspaceIfStoppedOrFailed(
restClient: Api,
globalConfigDir: string,
auth: CliAuth,
binPath: string,
workspace: Workspace,
writeEmitter: vscode.EventEmitter<string>,
Expand All @@ -65,7 +65,7 @@ export async function startWorkspaceIfStoppedOrFailed(

return new Promise((resolve, reject) => {
const startArgs = [
...getGlobalFlags(vscode.workspace.getConfiguration(), globalConfigDir),
...getGlobalFlags(vscode.workspace.getConfiguration(), auth),
"start",
"--yes",
createWorkspaceIdentifier(workspace),
Expand Down
Loading