Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't generate transitively imported files for mapped imports #854

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@ async function main() {
const typeMap = createTypeMap(request, options);
const utils = makeUtils(options);
const ctx: Context = { typeMap, options, utils };
let filesToGenerate;

if (options.emitImportedFiles) {
const fileSet = new Set();
const addFilesUnlessAliased = (filenames: string[]) => {
filenames
.filter((name) => !options.M[name])
.forEach((name) => {
fileSet.add(name);
const file = request.protoFile.find((file) => file.name === name);
if (file && file.dependency.length > 0) {
addFilesUnlessAliased(file.dependency);
}
});
};
addFilesUnlessAliased(request.fileToGenerate);
filesToGenerate = request.protoFile.filter((file) => fileSet.has(file.name));
} else {
filesToGenerate = protoFilesToGenerate(request).filter((file) => !options.M[file.name]);
}

const filesToGenerate = options.emitImportedFiles ? request.protoFile : protoFilesToGenerate(request);
const files = await Promise.all(
filesToGenerate
.filter((file) => !options.M[file.name])
marcushultman marked this conversation as resolved.
Show resolved Hide resolved
.map(async (file) => {
const [path, code] = generateFile(ctx, file);
const content = code.toString({ ...getTsPoetOpts(options), path });
return { name: path, content };
})
filesToGenerate.map(async (file) => {
const [path, code] = generateFile(ctx, file);
const content = code.toString({ ...getTsPoetOpts(options), path });
return { name: path, content };
})
);

if (options.outputTypeRegistry) {
Expand Down