Skip to content

Commit

Permalink
remove getSources, not required, typescript does it
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Nov 12, 2024
1 parent 16f8da1 commit 4107526
Showing 1 changed file with 1 addition and 66 deletions.
67 changes: 1 addition & 66 deletions packages/build/src/schemaExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,7 @@ export const schemaExtractorPlugin = (

build.onEnd(async () => {
const baseDir = pluginOptions.baseDir || process.cwd();
const sourceFiles = getSourceFiles(
pluginOptions,
hyperwebBuildOptions,
baseDir
);

if (!sourceFiles.length) {
console.error(
'No entry files provided or matched for schema extraction.'
);
return;
}
const sourceFiles = hyperwebBuildOptions.entryPoints as string[];

const program = ts.createProgram(sourceFiles, {
target: ts.ScriptTarget.ESNext,
Expand Down Expand Up @@ -98,60 +87,6 @@ export const schemaExtractorPlugin = (
},
});

function getSourceFiles(
pluginOptions: SchemaExtractorOptions,
hyperwebBuildOptions: HyperwebBuildOptions,
baseDir: string
): string[] {
const includePatterns = pluginOptions.include || [/\.tsx?$/];
const excludePatterns = pluginOptions.exclude || [/node_modules/];

if (!hyperwebBuildOptions.entryPoints) {
throw new Error('No entryPoints provided in build options.');
}

let resolvedFiles: string[] = [];

if (Array.isArray(hyperwebBuildOptions.entryPoints)) {
resolvedFiles = hyperwebBuildOptions.entryPoints.map((entry) => {
if (typeof entry === 'string') {
return path.resolve(baseDir, entry);
} else {
throw new Error('Invalid entryPoints array item: expected string');
}
});
} else if (typeof hyperwebBuildOptions.entryPoints === 'object') {
resolvedFiles = Object.values(hyperwebBuildOptions.entryPoints).map(
(file) => path.resolve(baseDir, file)
);
} else {
throw new Error(
'Invalid entryPoints format: expected string[] or Record<string, string>'
);
}

return resolvedFiles.filter((fileName) => {
const relativeFileName = path.relative(baseDir, fileName);
const matchesInclude = includePatterns.some((pattern) =>
pattern.test(relativeFileName)
);
const matchesExclude = excludePatterns.some((pattern) =>
pattern.test(relativeFileName)
);
return matchesInclude && !matchesExclude;
});
}

function hasModifiers(node: ts.Node): node is ts.ClassElement | ts.MethodDeclaration {
return (
ts.isClassElement(node) ||
ts.isMethodDeclaration(node) ||
ts.isPropertyDeclaration(node) ||
ts.isGetAccessorDeclaration(node) ||
ts.isSetAccessorDeclaration(node)
);
}

// Helper function to check if a declaration has public visibility
function isPublicDeclaration(node: ts.Node): boolean {
// Check if the node has modifiers and is of a type that may include them
Expand Down

0 comments on commit 4107526

Please sign in to comment.