26 lines
843 B
JavaScript
26 lines
843 B
JavaScript
import { access, readdir } from 'node:fs/promises';
|
|
|
|
const expectedOutputs = [
|
|
'dist/apps/api/main.js',
|
|
'dist/apps/scheduler/main.js',
|
|
'dist/apps/worker/main.js',
|
|
];
|
|
|
|
await Promise.all(expectedOutputs.map((output) => access(output)));
|
|
|
|
const sourceDirectories = ['apps', 'libs', 'test'];
|
|
const leakedOutputs = [];
|
|
|
|
async function findLeakedOutputs(directory) {
|
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
const target = `${directory}/${entry.name}`;
|
|
if (entry.isDirectory()) await findLeakedOutputs(target);
|
|
if (entry.isFile() && /\.(?:js|js\.map|d\.ts)$/.test(entry.name)) leakedOutputs.push(target);
|
|
}
|
|
}
|
|
|
|
await Promise.all(sourceDirectories.map(findLeakedOutputs));
|
|
if (leakedOutputs.length > 0) {
|
|
throw new Error(`构建产物不得写入源码目录:${leakedOutputs.join('、')}`);
|
|
}
|