Skip to content

Commit c21076e

Browse files
committed
chore(build): añadir utilidades de diagnostico spawn y parche postinstall para entornos Windows restringidos
1 parent 9302560 commit c21076e

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/doctor-node-spawn.cjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { spawnSync } = require('node:child_process');
2+
3+
function testSpawn(cmd, args) {
4+
try {
5+
const result = spawnSync(cmd, args, { encoding: 'utf8' });
6+
if (result.error) {
7+
return { ok: false, error: result.error };
8+
}
9+
if (result.status !== 0) {
10+
return { ok: false, stderr: result.stderr, status: result.status };
11+
}
12+
return { ok: true, stdout: result.stdout.trim() };
13+
} catch (error) {
14+
return { ok: false, error };
15+
}
16+
}
17+
18+
const tests = [
19+
['cmd.exe', ['/c', 'echo', 'spawn-ok']],
20+
['node', ['-v']],
21+
];
22+
23+
let allOk = true;
24+
for (const [cmd, args] of tests) {
25+
const out = testSpawn(cmd, args);
26+
if (!out.ok) {
27+
allOk = false;
28+
console.error(`[doctor-node-spawn] FAIL ${cmd} ${args.join(' ')}`);
29+
if (out.error) console.error(out.error);
30+
if (out.stderr) console.error(out.stderr);
31+
} else {
32+
console.log(`[doctor-node-spawn] OK ${cmd} -> ${out.stdout}`);
33+
}
34+
}
35+
36+
if (!allOk) {
37+
console.error('\n[doctor-node-spawn] El entorno bloquea child_process.spawn desde Node.');
38+
console.error('[doctor-node-spawn] Solucion: permitir Node en politicas de seguridad (App Control / CI / EDR) o usar un runner Linux/CI sin esa restriccion.');
39+
process.exit(1);
40+
}
41+
42+
console.log('\n[doctor-node-spawn] Entorno listo para Vite/Tauri build.');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const fs = require('node:fs');
2+
const path = require('node:path');
3+
4+
const target = path.join(
5+
process.cwd(),
6+
'node_modules',
7+
'vite',
8+
'dist',
9+
'node',
10+
'chunks',
11+
'config.js'
12+
);
13+
14+
if (!fs.existsSync(target)) {
15+
console.log('[patch-vite-windows-eperm] Skip: vite config chunk not found');
16+
process.exit(0);
17+
}
18+
19+
const source = fs.readFileSync(target, 'utf8');
20+
const marker = 'Some locked-down Windows environments block child_process spawn.';
21+
if (source.includes(marker)) {
22+
console.log('[patch-vite-windows-eperm] Already patched');
23+
process.exit(0);
24+
}
25+
26+
const before = `\texec("net use", (error$1, stdout) => {
27+
\t\tif (error$1) return;
28+
\t\tconst lines = stdout.split("\\n");
29+
\t\tfor (const line of lines) {
30+
\t\t\tconst m = parseNetUseRE.exec(line);
31+
\t\t\tif (m) windowsNetworkMap.set(m[2], m[1]);
32+
\t\t}
33+
\t\tif (windowsNetworkMap.size === 0) safeRealpathSync = fs.realpathSync.native;
34+
\t\telse safeRealpathSync = windowsMappedRealpathSync;
35+
\t});`;
36+
37+
const after = `\ttry {
38+
\t\texec("net use", (error$1, stdout) => {
39+
\t\t\tif (error$1) return;
40+
\t\t\tconst lines = stdout.split("\\n");
41+
\t\t\tfor (const line of lines) {
42+
\t\t\t\tconst m = parseNetUseRE.exec(line);
43+
\t\t\t\tif (m) windowsNetworkMap.set(m[2], m[1]);
44+
\t\t\t}
45+
\t\t\tif (windowsNetworkMap.size === 0) safeRealpathSync = fs.realpathSync.native;
46+
\t\t\telse safeRealpathSync = windowsMappedRealpathSync;
47+
\t\t});
48+
\t} catch {
49+
\t\t// Some locked-down Windows environments block child_process spawn.
50+
\t\t// Fallback to native realpath to avoid crashing during config load.
51+
\t\tsafeRealpathSync = fs.realpathSync.native;
52+
\t}`;
53+
54+
if (!source.includes(before)) {
55+
console.log('[patch-vite-windows-eperm] Pattern not found, nothing changed');
56+
process.exit(0);
57+
}
58+
59+
fs.writeFileSync(target, source.replace(before, after), 'utf8');
60+
console.log('[patch-vite-windows-eperm] Patch applied');

0 commit comments

Comments
 (0)