@kmugalkhod/lightcode 0.1.2 → 0.1.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.
- package/cli.js +1 -1
- package/lightcode.cjs +41 -26
- package/package.json +1 -1
package/cli.js
CHANGED
package/lightcode.cjs
CHANGED
|
@@ -35,35 +35,50 @@ try {
|
|
|
35
35
|
// Bun uses its own TLS stack and does not read the Windows certificate store,
|
|
36
36
|
// so corporate SSL proxies (which install their CA into Windows) are invisible
|
|
37
37
|
// to Bun unless we forward the certs explicitly.
|
|
38
|
+
// Strategy: use PowerShell only to export raw DER .cer files; do all PEM
|
|
39
|
+
// formatting in Node.js where string/encoding handling is reliable.
|
|
38
40
|
if (process.platform === "win32" && !process.env.NODE_EXTRA_CA_CERTS) {
|
|
39
41
|
try {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
42
|
+
const tmpDir = os.tmpdir();
|
|
43
|
+
const cerDir = path.join(tmpDir, "lightcode-certs");
|
|
44
|
+
const pemFile = path.join(tmpDir, "lightcode-win-ca.pem");
|
|
45
|
+
const ps1File = path.join(tmpDir, "lightcode-cert-export.ps1");
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(cerDir)) fs.mkdirSync(cerDir, { recursive: true });
|
|
48
|
+
|
|
49
|
+
// Forward slashes work in PowerShell and avoid backslash escaping issues
|
|
50
|
+
const cerDirFwd = cerDir.replace(/\\/g, "/");
|
|
51
|
+
const psLines = [
|
|
52
|
+
"$i = 0",
|
|
53
|
+
'foreach ($s in @("Root", "CA")) {',
|
|
54
|
+
' try {',
|
|
55
|
+
' foreach ($c in (Get-ChildItem "Cert:\\LocalMachine\\$s" -EA Stop)) {',
|
|
56
|
+
' Export-Certificate -Cert $c -FilePath "' + cerDirFwd + '/$i.cer" -Type CERT | Out-Null',
|
|
57
|
+
' $i++',
|
|
58
|
+
' }',
|
|
59
|
+
' } catch {}',
|
|
60
|
+
'}',
|
|
61
|
+
];
|
|
62
|
+
fs.writeFileSync(ps1File, psLines.join("\n"), "utf8");
|
|
63
|
+
spawnSync("powershell", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", ps1File], { stdio: "pipe" });
|
|
64
|
+
try { fs.unlinkSync(ps1File); } catch {}
|
|
65
|
+
|
|
66
|
+
// Convert DER .cer files to PEM entirely in Node.js
|
|
67
|
+
const cerFiles = fs.existsSync(cerDir) ? fs.readdirSync(cerDir).filter(function(f) { return f.endsWith(".cer"); }) : [];
|
|
68
|
+
const pems = cerFiles.map(function(f) {
|
|
69
|
+
const der = fs.readFileSync(path.join(cerDir, f));
|
|
70
|
+
const b64 = der.toString("base64").match(/.{1,64}/g).join("\n");
|
|
71
|
+
return "-----BEGIN CERTIFICATE-----\n" + b64 + "\n-----END CERTIFICATE-----";
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (pems.length > 0) {
|
|
75
|
+
fs.writeFileSync(pemFile, pems.join("\n") + "\n", "ascii");
|
|
76
|
+
process.env.NODE_EXTRA_CA_CERTS = pemFile;
|
|
66
77
|
}
|
|
78
|
+
|
|
79
|
+
// Cleanup individual cert files
|
|
80
|
+
cerFiles.forEach(function(f) { try { fs.unlinkSync(path.join(cerDir, f)); } catch {} });
|
|
81
|
+
try { fs.rmdirSync(cerDir); } catch {}
|
|
67
82
|
} catch {
|
|
68
83
|
// cert export failed — Bun uses its own bundled roots
|
|
69
84
|
}
|