2024-02-12 21:10:09 +01:00
|
|
|
import { globSync } from 'glob';
|
2024-02-12 21:20:31 +01:00
|
|
|
import { packageJsonExports } from './meta.js';
|
2024-02-12 21:10:09 +01:00
|
|
|
|
2024-02-12 21:18:26 +01:00
|
|
|
const validateExports = async () => {
|
|
|
|
|
const errors = [];
|
2024-02-12 21:10:09 +01:00
|
|
|
|
2024-02-12 21:18:26 +01:00
|
|
|
// Iterate over the exports in package.json
|
|
|
|
|
for (const [key, value] of Object.entries(packageJsonExports || {})) {
|
|
|
|
|
if (value) {
|
|
|
|
|
const jsFiles = await globSync(value);
|
|
|
|
|
|
|
|
|
|
// Log an error if the export from the package.json does not exist in the build output
|
|
|
|
|
if (jsFiles.length === 0) {
|
|
|
|
|
errors.push(`Could not find export: ${key} -> ${value} in the build output.`);
|
|
|
|
|
}
|
2024-02-12 21:10:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-02-12 21:18:26 +01:00
|
|
|
|
|
|
|
|
if (errors.length > 0) {
|
|
|
|
|
throw new Error(errors.join('\n'));
|
2024-02-12 21:23:47 +01:00
|
|
|
} else {
|
|
|
|
|
console.log('--- Exports validated successfully. ---');
|
2024-02-12 21:18:26 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
validateExports();
|