Files
react-test/scripts/testBuiltTypes.mjs
how2ice 005cf56baf
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
init project
2025-12-12 14:26:25 +09:00

39 lines
1.2 KiB
JavaScript

import { globby } from 'globby';
import fs from 'node:fs/promises';
import path from 'path';
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
async function main() {
const workspaceRoot = await findWorkspaceDir(process.cwd());
const declarationFiles = await globby('**/build/**/*.d.ts', {
absolute: true,
cwd: workspaceRoot,
ignore: ['node_modules'],
followSymbolicLinks: false,
});
await Promise.all(
declarationFiles.map(async (declarationFilePath) => {
const declarationFile = await fs.readFile(declarationFilePath, { encoding: 'utf8' });
// find occurrences of e.g. `import("../../mui-*/src/...")`
const typeImportsRelativeToWorkspace = declarationFile.match(/import\(("|')(\.\.\/)+mui/g);
if (typeImportsRelativeToWorkspace !== null) {
console.error(
// readable path for CI while making it clickable locally
`${path.relative(process.cwd(), declarationFilePath)} possibly imports types ${
typeImportsRelativeToWorkspace.length
} times that are unreachable once published.`,
);
process.exitCode = 1;
}
}),
);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});