@henryqw/pi-open-in 0.1.5 → 0.2.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.
Files changed (2) hide show
  1. package/extensions/open.ts +12 -0
  2. package/package.json +4 -1
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { mkdir, writeFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
+ import { pathToFileURL } from "node:url";
4
5
  import {
5
6
  getAgentDir,
6
7
  type ExtensionAPI,
@@ -22,6 +23,17 @@ function configuredCommand(): string {
22
23
  return DEFAULT_COMMAND;
23
24
  }
24
25
 
26
+ export function configuredOpenUri(path: string): string | undefined {
27
+ if (configuredCommand() !== "code") return undefined;
28
+ if (path.startsWith("\\\\")) {
29
+ const [host, ...parts] = path.slice(2).split("\\");
30
+ const uri = new URL(`file://${host}`);
31
+ uri.pathname = `/${parts.join("/")}`;
32
+ return `vscode://file//${uri.host}${uri.pathname}`;
33
+ }
34
+ return `vscode://file${pathToFileURL(path).pathname}`;
35
+ }
36
+
25
37
  async function saveCommand(command: string): Promise<void> {
26
38
  const path = configPath();
27
39
  await mkdir(dirname(path), { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-open-in",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "Open the current Pi working directory with a configurable command.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -19,6 +19,9 @@
19
19
  "README.md",
20
20
  "LICENSE"
21
21
  ],
22
+ "exports": {
23
+ "./open-uri": "./extensions/open.ts"
24
+ },
22
25
  "scripts": {
23
26
  "test": "node --test test/*.test.ts",
24
27
  "typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/open.ts test/*.test.ts",