Files
pdfme/playground/scripts/verify-package-exports.mjs
hand-dot c759a120d7 feat: update test script to run workspace tests and refactor schema imports
- Changed the test script in package.json to run workspace tests using a new script.
- Updated imports in generator and helper files to point to specific schema paths.
- Added new builtins and tables exports in schemas package.json and created corresponding files.
- Enhanced error handling in multiVariableText propPanel for JSON parsing.
- Refactored UI components to use React 18 and updated dependencies accordingly.
- Improved snapshot tests to ensure cleaner output by removing empty text nodes.
- Updated documentation to reflect changes in package usage and requirements.
2026-03-21 16:10:48 +09:00

78 lines
2.4 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const playgroundRoot = path.resolve(__dirname, '..');
const trackedSpecifiers = [
'@pdfme/common',
'@pdfme/converter',
'@pdfme/generator',
'@pdfme/manipulator',
'@pdfme/schemas',
'@pdfme/schemas/builtins',
'@pdfme/schemas/tables',
'@pdfme/schemas/utils',
'@pdfme/ui',
];
const trackedDirs = ['src', 'scripts', 'e2e', 'node-playground'];
const trackedExtensions = new Set(['.ts', '.tsx', '.js', '.mjs', '.json']);
const forbiddenSegments = ['/src/', '/cjs/src/', '/esm/src/', '/dist/cjs/src/', '/dist/esm/src/'];
const forbiddenImportPatterns = [
/['"]@pdfme\/[^'"]+\/dist\//,
/['"]@pdfme\/[^'"]+\/cjs\//,
/['"]@pdfme\/[^'"]+\/esm\//,
/['"]@pdfme\/[^'"]+\/src\//,
];
function collectFiles(dirPath) {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
return entries.flatMap((entry) => {
const fullPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
return collectFiles(fullPath);
}
if (!trackedExtensions.has(path.extname(entry.name))) {
return [];
}
return [fullPath];
});
}
const filesToCheck = trackedDirs.flatMap((dir) => collectFiles(path.join(playgroundRoot, dir)));
const importViolations = filesToCheck.flatMap((filePath) => {
const content = fs.readFileSync(filePath, 'utf8');
return forbiddenImportPatterns.flatMap((pattern) => {
if (!pattern.test(content)) {
return [];
}
return [path.relative(playgroundRoot, filePath)];
});
});
if (importViolations.length > 0) {
console.error('Found legacy @pdfme deep imports in playground files:');
for (const filePath of [...new Set(importViolations)]) {
console.error(`- ${filePath}`);
}
process.exit(1);
}
for (const specifier of trackedSpecifiers) {
const resolved = await import.meta.resolve(specifier);
const resolvedPath = new URL(resolved).pathname;
if (!resolvedPath.includes('/dist/')) {
console.error(`${specifier} did not resolve to a dist export: ${resolved}`);
process.exit(1);
}
if (forbiddenSegments.some((segment) => resolvedPath.includes(segment))) {
console.error(`${specifier} resolved to a legacy internal path: ${resolved}`);
process.exit(1);
}
}
console.log('Verified playground @pdfme imports and package exports.');