Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
const childProcess = require('child_process');
|
|
const path = require('path');
|
|
const { promisify } = require('util');
|
|
const { chunk } = require('es-toolkit/array');
|
|
const glob = require('fast-glob');
|
|
|
|
const exec = promisify(childProcess.exec);
|
|
const packageRoot = path.resolve(__dirname, '../');
|
|
|
|
async function test(tsconfigPath) {
|
|
try {
|
|
await exec(['pnpm', 'tsc', '--project', tsconfigPath].join(' '), { cwd: packageRoot });
|
|
} catch (error) {
|
|
if (error.stdout !== undefined) {
|
|
// `exec` error
|
|
throw new Error(`exit code ${error.code}: ${error.stdout}`);
|
|
}
|
|
// Unknown error
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tests various module augmentation scenarios.
|
|
* We can't run them with a single `tsc` run since these apply globally.
|
|
* Running them all would mean they're not isolated.
|
|
* Each test case represents a section in our docs.
|
|
*/
|
|
async function main() {
|
|
const tsconfigPaths = await glob('test/typescript/moduleAugmentation/*.tsconfig.json', {
|
|
absolute: true,
|
|
cwd: packageRoot,
|
|
});
|
|
// Need to process in chunks or we might run out-of-memory
|
|
// approximate pnpm lerna --concurrency 7
|
|
const tsconfigPathsChunks = chunk(tsconfigPaths, 7);
|
|
|
|
for await (const tsconfigPathsChunk of tsconfigPathsChunks) {
|
|
await Promise.all(
|
|
tsconfigPathsChunk.map(async (tsconfigPath) => {
|
|
await test(tsconfigPath).then(
|
|
() => {
|
|
// eslint-disable-next-line no-console -- test runner feedback
|
|
console.log(`PASS ${path.relative(process.cwd(), tsconfigPath)}`);
|
|
},
|
|
(error) => {
|
|
// don't bail but log the error
|
|
console.error(`FAIL ${path.relative(process.cwd(), tsconfigPath)}\n ${error}`);
|
|
// and mark the test as failed
|
|
process.exitCode = 1;
|
|
},
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|