Files
qipai/scripts/check-script-path-portability.mjs
T
2026-08-10 19:20:47 +08:00

56 lines
1.5 KiB
JavaScript

import assert from 'node:assert/strict';
import {
cpSync,
mkdtempSync,
mkdirSync,
rmSync
} from 'node:fs';
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('..', import.meta.url));
const temporaryRoot = mkdtempSync(join(tmpdir(), '棋牌 路径回归 '));
const checks = [
'check-miniapp-m08-a.mjs',
'check-miniapp-m08-c.mjs',
'check-admin-m08-b.mjs',
'check-admin-m08-d.mjs'
];
const copySource = (name) => {
const source = join(root, name);
const target = join(temporaryRoot, name);
cpSync(source, target, {
recursive: true,
filter: (entry) => {
const part = basename(entry);
return part !== 'node_modules' && part !== 'dist';
}
});
};
try {
copySource('admin');
copySource('backend');
copySource('database');
copySource('miniapp');
mkdirSync(join(temporaryRoot, 'scripts'));
for (const check of checks) {
cpSync(join(root, 'scripts', check), join(temporaryRoot, 'scripts', check));
const result = spawnSync(process.execPath, [join(temporaryRoot, 'scripts', check)], {
cwd: temporaryRoot,
encoding: 'utf8'
});
assert.equal(
result.status,
0,
`${check} failed in ${temporaryRoot}\n${result.stdout}${result.stderr}`
);
}
console.log(`PASS: four static checks support a Unicode/space repository path (${temporaryRoot}).`);
} finally {
rmSync(temporaryRoot, { recursive: true, force: true });
}