coc-vscode-loader 1.2.2 → 1.2.4

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.4",
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.4",
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"))) {
@@ -543,13 +543,24 @@ async function convertSource(inputDir, name, info, onProgress) {
543
543
  } else {
544
544
  const globalPresetsCache = path3.join(os3.homedir(), ".config", "coc", "converter-cache", "presets.json");
545
545
  if (!fs3.existsSync(globalPresetsCache)) {
546
+ const presetsUrl = "https://raw.githubusercontent.com/coc-plugin/coc-vscode-registry/main/presets.json";
546
547
  try {
547
- const res = await fetch("https://raw.githubusercontent.com/coc-plugin/coc-vscode-registry/main/presets.json");
548
+ const res = await fetch(presetsUrl);
548
549
  if (res.ok) {
549
550
  fs3.mkdirSync(path3.dirname(globalPresetsCache), { recursive: true });
550
551
  fs3.writeFileSync(globalPresetsCache, await res.text());
551
552
  }
552
553
  } catch {
554
+ try {
555
+ const out = await new Promise((resolve2, reject) => {
556
+ (0, import_child_process2.execFile)("curl", ["-sL", presetsUrl], { encoding: "utf-8", maxBuffer: 1024 * 1024 }, (err, stdout) => err ? reject(err) : resolve2(stdout));
557
+ });
558
+ if (out) {
559
+ fs3.mkdirSync(path3.dirname(globalPresetsCache), { recursive: true });
560
+ fs3.writeFileSync(globalPresetsCache, out);
561
+ }
562
+ } catch {
563
+ }
553
564
  }
554
565
  }
555
566
  if (fs3.existsSync(globalPresetsCache)) {
@@ -614,34 +625,52 @@ async function buildPackage(name, inputDir, info, onProgress) {
614
625
  onProgress(3, 5, "Installing server dependencies...", `npm install in ${serverDir}`);
615
626
  await run("npm", ["install", "--legacy-peer-deps"], serverDir, npmLog);
616
627
  const destServer = path3.join(build, "server");
617
- if (fs3.existsSync(destServer)) fs3.rmSync(destServer, { recursive: true });
618
- fs3.cpSync(serverDir, destServer, { recursive: true });
628
+ await rimraf(destServer);
629
+ await cpdir(serverDir, destServer);
619
630
  }
620
631
  onProgress(4, 5, "Building...", "node esbuild.mjs");
621
632
  const buildLog = (chunk) => onProgress(4, 5, chunk.trim(), "");
622
633
  await run("node", ["esbuild.mjs"], build, buildLog);
634
+ const archMap = {
635
+ arm64: "aarch64",
636
+ x64: "x86_64"
637
+ };
638
+ const platformMap = {
639
+ darwin: "apple-darwin",
640
+ linux: "unknown-linux-gnu",
641
+ win32: "pc-windows-msvc"
642
+ };
643
+ const arch2 = os3.arch() === "arm64" ? "arm64" : "x64";
644
+ const platform = process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux";
645
+ const rawArch = archMap[arch2] || arch2;
646
+ const rustTarget = `${rawArch}-${platformMap[platform] || platform}`;
647
+ const indexPath = path3.join(build, "lib", "index.js");
648
+ if (fs3.existsSync(indexPath)) {
649
+ let code = fs3.readFileSync(indexPath, "utf-8");
650
+ for (const [key, val] of [["platform", platform], ["arch", arch2], ["raw-arch", rawArch], ["rust-target", rustTarget]]) {
651
+ code = code.replace(new RegExp(`\\{\\{${key}}}`, "g"), val);
652
+ }
653
+ if (code !== fs3.readFileSync(indexPath, "utf-8")) {
654
+ fs3.writeFileSync(indexPath, code);
655
+ }
656
+ }
623
657
  if (info.serverBinary) {
624
658
  const sb = info.serverBinary;
625
659
  onProgress(4, 5, "Downloading language server...", `fetching ${sb.repo}`);
626
660
  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();
661
+ let tagData;
662
+ try {
663
+ const tagRes = await fetch(`https://api.github.com/repos/${sb.repo}/releases/latest`);
664
+ if (!tagRes.ok) throw new Error(`HTTP ${tagRes.status}`);
665
+ tagData = await tagRes.json();
666
+ } catch {
667
+ const out = await new Promise((resolve2, reject) => {
668
+ (0, import_child_process2.execFile)("curl", ["-sL", `https://api.github.com/repos/${sb.repo}/releases/latest`], { encoding: "utf-8", maxBuffer: 1024 * 1024 }, (err, stdout) => err ? reject(err) : resolve2(stdout));
669
+ });
670
+ tagData = JSON.parse(out);
671
+ }
630
672
  const tag = tagData.tag_name;
631
673
  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
674
  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
675
  const url = `https://github.com/${sb.repo}/releases/download/${tag}/${filename}`;
647
676
  onProgress(4, 5, "Downloading...", `curl ${filename}`);
@@ -667,19 +696,18 @@ async function buildPackage(name, inputDir, info, onProgress) {
667
696
  });
668
697
  } catch {
669
698
  }
699
+ if (version) {
700
+ const verPath = path3.join(build, "lib", "index.js");
701
+ if (fs3.existsSync(verPath)) {
702
+ let vc = fs3.readFileSync(verPath, "utf-8");
703
+ if (vc.includes("{{version}}")) {
704
+ fs3.writeFileSync(verPath, vc.replace(/\{\{version}}/g, version));
705
+ }
706
+ }
707
+ }
670
708
  if (sb.binaryPath || filename.match(/\.(zip|gz)$/)) {
671
709
  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);
710
+ if (fs3.existsSync(archivePath)) await rimraf(archivePath);
683
711
  }
684
712
  } catch (e) {
685
713
  onProgress(4, 5, `Warning: serverBinary setup failed (${e.message})`, "install server binary manually");
@@ -693,9 +721,9 @@ async function installToCoc(name, onProgress) {
693
721
  const src = buildDir(name);
694
722
  const dest = pluginDir(name);
695
723
  onProgress(5, 5, "Installing to coc...", `copy to ${dest} + register in extensions/package.json`);
696
- if (fs3.existsSync(dest)) fs3.rmSync(dest, { recursive: true });
724
+ await rimraf(dest);
697
725
  fs3.mkdirSync(path3.dirname(dest), { recursive: true });
698
- fs3.cpSync(src, dest, { recursive: true });
726
+ await cpdir(src, dest);
699
727
  const pkgPath = extensionsPkgPath();
700
728
  const pkg = fs3.existsSync(pkgPath) ? JSON.parse(fs3.readFileSync(pkgPath, "utf-8")) : { dependencies: {} };
701
729
  pkg.dependencies = pkg.dependencies || {};
@@ -761,13 +789,23 @@ async function installPackage(state, name) {
761
789
  state.setPackageStatus(name, "failed", { error: e.message });
762
790
  }
763
791
  }
792
+ function rimraf(dir) {
793
+ return new Promise((resolve2, reject) => {
794
+ if (!fs3.existsSync(dir)) return resolve2();
795
+ (0, import_child_process2.spawn)("rm", ["-rf", dir], { stdio: "ignore" }).on("close", (code) => code === 0 ? resolve2() : reject(new Error(`rm -rf exited ${code}`)));
796
+ });
797
+ }
798
+ function cpdir(src, dest) {
799
+ return new Promise((resolve2, reject) => {
800
+ const parent = path3.dirname(dest);
801
+ if (!fs3.existsSync(parent)) fs3.mkdirSync(parent, { recursive: true });
802
+ (0, import_child_process2.spawn)("cp", ["-r", src, dest], { stdio: "ignore" }).on("close", (code) => code === 0 ? resolve2() : reject(new Error(`cp -r exited ${code}`)));
803
+ });
804
+ }
764
805
  async function uninstallPackage(state, name) {
765
806
  state.setPackageStatus(name, "uninstalling", { progress: "[1/3] Removing from coc..." });
766
807
  try {
767
- const dest = pluginDir(name);
768
- if (fs3.existsSync(dest)) {
769
- fs3.rmSync(dest, { recursive: true });
770
- }
808
+ await rimraf(pluginDir(name));
771
809
  state.setPackageStatus(name, "uninstalling", { progress: "[2/3] Removing from package.json..." });
772
810
  const pkgPath = extensionsPkgPath();
773
811
  const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
@@ -779,10 +817,7 @@ async function uninstallPackage(state, name) {
779
817
  fs3.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
780
818
  }
781
819
  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
- }
820
+ await rimraf(cacheDir(name));
786
821
  state.setPackageStatus(name, "not-installed");
787
822
  state.setDirty();
788
823
  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.4",
4
4
  "description": "Run VS Code extensions seamlessly in coc.nvim",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [