coc-vscode-loader 1.2.2 → 1.2.3

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "converter",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "private": true,
5
5
  "description": "vscode → coc.nvim converter prototype",
6
6
  "type": "module",
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ var require_package = __commonJS({
39
39
  "package.json"(exports2, module2) {
40
40
  module2.exports = {
41
41
  name: "coc-vscode-loader",
42
- version: "1.2.2",
42
+ version: "1.2.3",
43
43
  description: "Run VS Code extensions seamlessly in coc.nvim",
44
44
  main: "lib/index.js",
45
45
  keywords: [
@@ -521,7 +521,7 @@ async function downloadSource(info, name, onProgress) {
521
521
  }
522
522
  async function convertSource(inputDir, name, info, onProgress) {
523
523
  const build = buildDir(name);
524
- if (fs3.existsSync(build)) fs3.rmSync(build, { recursive: true });
524
+ await rimraf(build);
525
525
  const cli = converterCliPath();
526
526
  const converterDir = path3.resolve(path3.dirname(path3.dirname(cli)));
527
527
  if (!fs3.existsSync(path3.join(converterDir, "node_modules", "commander"))) {
@@ -614,34 +614,53 @@ async function buildPackage(name, inputDir, info, onProgress) {
614
614
  onProgress(3, 5, "Installing server dependencies...", `npm install in ${serverDir}`);
615
615
  await run("npm", ["install", "--legacy-peer-deps"], serverDir, npmLog);
616
616
  const destServer = path3.join(build, "server");
617
- if (fs3.existsSync(destServer)) fs3.rmSync(destServer, { recursive: true });
618
- fs3.cpSync(serverDir, destServer, { recursive: true });
617
+ await rimraf(destServer);
618
+ await cpdir(serverDir, destServer);
619
619
  }
620
620
  onProgress(4, 5, "Building...", "node esbuild.mjs");
621
621
  const buildLog = (chunk) => onProgress(4, 5, chunk.trim(), "");
622
622
  await run("node", ["esbuild.mjs"], build, buildLog);
623
+ const archMap = {
624
+ arm64: "aarch64",
625
+ x64: "x86_64"
626
+ };
627
+ const platformMap = {
628
+ darwin: "apple-darwin",
629
+ linux: "unknown-linux-gnu",
630
+ win32: "pc-windows-msvc"
631
+ };
632
+ const arch2 = os3.arch() === "arm64" ? "arm64" : "x64";
633
+ const platform = process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux";
634
+ const rawArch = archMap[arch2] || arch2;
635
+ const rustTarget = `${rawArch}-${platformMap[platform] || platform}`;
636
+ const indexPath = path3.join(build, "lib", "index.js");
637
+ if (fs3.existsSync(indexPath)) {
638
+ let code = fs3.readFileSync(indexPath, "utf-8");
639
+ for (const [key, val] of [["platform", platform], ["arch", arch2], ["raw-arch", rawArch], ["rust-target", rustTarget]]) {
640
+ code = code.replace(new RegExp(`\\{\\{${key}}}`, "g"), val);
641
+ }
642
+ if (code !== fs3.readFileSync(indexPath, "utf-8")) {
643
+ fs3.writeFileSync(indexPath, code);
644
+ }
645
+ }
623
646
  if (info.serverBinary) {
624
647
  const sb = info.serverBinary;
625
648
  onProgress(4, 5, "Downloading language server...", `fetching ${sb.repo}`);
626
649
  try {
627
- const tagRes = await fetch(`https://api.github.com/repos/${sb.repo}/releases/latest`);
628
- if (!tagRes.ok) throw new Error(`GitHub API: HTTP ${tagRes.status}`);
629
- const tagData = await tagRes.json();
650
+ let tagData;
651
+ try {
652
+ const tagRes = await fetch(`https://api.github.com/repos/${sb.repo}/releases/latest`);
653
+ if (!tagRes.ok) throw new Error(`HTTP ${tagRes.status}`);
654
+ tagData = await tagRes.json();
655
+ } catch {
656
+ const { execFile: execFile2 } = require("child_process");
657
+ const out = await new Promise((resolve2, reject) => {
658
+ execFile2("curl", ["-sL", `https://api.github.com/repos/${sb.repo}/releases/latest`], { encoding: "utf-8", maxBuffer: 1024 * 1024 }, (err, stdout) => err ? reject(err) : resolve2(stdout));
659
+ });
660
+ tagData = JSON.parse(out);
661
+ }
630
662
  const tag = tagData.tag_name;
631
663
  const version = tag.replace(/^v/, "");
632
- const archMap = {
633
- arm64: "aarch64",
634
- x64: "x86_64"
635
- };
636
- const platformMap = {
637
- darwin: "apple-darwin",
638
- linux: "unknown-linux-gnu",
639
- win32: "pc-windows-msvc"
640
- };
641
- const arch2 = os3.arch() === "arm64" ? "arm64" : "x64";
642
- const platform = process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux";
643
- const rawArch = archMap[arch2] || arch2;
644
- const rustTarget = `${rawArch}-${platformMap[platform] || platform}`;
645
664
  const filename = sb.asset.replace(/\{\{version}}/g, version).replace(/\{\{platform}}/g, platform).replace(/\{\{arch}}/g, arch2).replace(/\{\{raw-arch}}/g, rawArch).replace(/\{\{rust-target}}/g, rustTarget);
646
665
  const url = `https://github.com/${sb.repo}/releases/download/${tag}/${filename}`;
647
666
  onProgress(4, 5, "Downloading...", `curl ${filename}`);
@@ -667,19 +686,18 @@ async function buildPackage(name, inputDir, info, onProgress) {
667
686
  });
668
687
  } catch {
669
688
  }
689
+ if (version) {
690
+ const verPath = path3.join(build, "lib", "index.js");
691
+ if (fs3.existsSync(verPath)) {
692
+ let vc = fs3.readFileSync(verPath, "utf-8");
693
+ if (vc.includes("{{version}}")) {
694
+ fs3.writeFileSync(verPath, vc.replace(/\{\{version}}/g, version));
695
+ }
696
+ }
697
+ }
670
698
  if (sb.binaryPath || filename.match(/\.(zip|gz)$/)) {
671
699
  const archivePath = path3.join(build, filename);
672
- if (fs3.existsSync(archivePath)) fs3.rmSync(archivePath);
673
- }
674
- const indexPath = path3.join(build, "lib", "index.js");
675
- if (fs3.existsSync(indexPath)) {
676
- let code = fs3.readFileSync(indexPath, "utf-8");
677
- code = code.replace(/\{\{version}}/g, version);
678
- code = code.replace(/\{\{platform}}/g, platform);
679
- code = code.replace(/\{\{arch}}/g, arch2);
680
- code = code.replace(/\{\{raw-arch}}/g, rawArch);
681
- code = code.replace(/\{\{rust-target}}/g, rustTarget);
682
- fs3.writeFileSync(indexPath, code);
700
+ if (fs3.existsSync(archivePath)) await rimraf(archivePath);
683
701
  }
684
702
  } catch (e) {
685
703
  onProgress(4, 5, `Warning: serverBinary setup failed (${e.message})`, "install server binary manually");
@@ -693,9 +711,9 @@ async function installToCoc(name, onProgress) {
693
711
  const src = buildDir(name);
694
712
  const dest = pluginDir(name);
695
713
  onProgress(5, 5, "Installing to coc...", `copy to ${dest} + register in extensions/package.json`);
696
- if (fs3.existsSync(dest)) fs3.rmSync(dest, { recursive: true });
714
+ await rimraf(dest);
697
715
  fs3.mkdirSync(path3.dirname(dest), { recursive: true });
698
- fs3.cpSync(src, dest, { recursive: true });
716
+ await cpdir(src, dest);
699
717
  const pkgPath = extensionsPkgPath();
700
718
  const pkg = fs3.existsSync(pkgPath) ? JSON.parse(fs3.readFileSync(pkgPath, "utf-8")) : { dependencies: {} };
701
719
  pkg.dependencies = pkg.dependencies || {};
@@ -761,13 +779,23 @@ async function installPackage(state, name) {
761
779
  state.setPackageStatus(name, "failed", { error: e.message });
762
780
  }
763
781
  }
782
+ function rimraf(dir) {
783
+ return new Promise((resolve2, reject) => {
784
+ if (!fs3.existsSync(dir)) return resolve2();
785
+ (0, import_child_process2.spawn)("rm", ["-rf", dir], { stdio: "ignore" }).on("close", (code) => code === 0 ? resolve2() : reject(new Error(`rm -rf exited ${code}`)));
786
+ });
787
+ }
788
+ function cpdir(src, dest) {
789
+ return new Promise((resolve2, reject) => {
790
+ const parent = path3.dirname(dest);
791
+ if (!fs3.existsSync(parent)) fs3.mkdirSync(parent, { recursive: true });
792
+ (0, import_child_process2.spawn)("cp", ["-r", src, dest], { stdio: "ignore" }).on("close", (code) => code === 0 ? resolve2() : reject(new Error(`cp -r exited ${code}`)));
793
+ });
794
+ }
764
795
  async function uninstallPackage(state, name) {
765
796
  state.setPackageStatus(name, "uninstalling", { progress: "[1/3] Removing from coc..." });
766
797
  try {
767
- const dest = pluginDir(name);
768
- if (fs3.existsSync(dest)) {
769
- fs3.rmSync(dest, { recursive: true });
770
- }
798
+ await rimraf(pluginDir(name));
771
799
  state.setPackageStatus(name, "uninstalling", { progress: "[2/3] Removing from package.json..." });
772
800
  const pkgPath = extensionsPkgPath();
773
801
  const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
@@ -779,10 +807,7 @@ async function uninstallPackage(state, name) {
779
807
  fs3.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
780
808
  }
781
809
  state.setPackageStatus(name, "uninstalling", { progress: "[3/3] Removing cache..." });
782
- const cache = cacheDir(name);
783
- if (fs3.existsSync(cache)) {
784
- fs3.rmSync(cache, { recursive: true });
785
- }
810
+ await rimraf(cacheDir(name));
786
811
  state.setPackageStatus(name, "not-installed");
787
812
  state.setDirty();
788
813
  import_coc.window.showInformationMessage(`coc-${name} uninstalled`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coc-vscode-loader",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Run VS Code extensions seamlessly in coc.nvim",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [