Skip to content

Commit

Permalink
[cli]: fix incorrect generated file name
Browse files Browse the repository at this point in the history
- do not create import type from core package if no data
- fix error when value is not object for mergeObj
- use filename without extensions when creating exports for package.json
  • Loading branch information
zgid123 committed Jun 12, 2024
1 parent dba8be8 commit 8fea241
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc.ts/cli",
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",
"directories": {
"lib": "lib"
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/tasks/createContent/createImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export function createImports({
messageDependentTypes,
serviceDependentTypes,
}: ICreateImportsParams) {
if (!hasService && !hasGrpcTimestamp && !hasService) {
return '';
}

const corePackage = '@grpc.ts/core';
const dependentTypes = mergeObj(messageDependentTypes, serviceDependentTypes);

Expand Down
16 changes: 12 additions & 4 deletions packages/cli/src/tasks/createContent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ export async function createContent(
};
});

const fileName = combine(
const fileNameWithoutExt = combine(
{
joinWith: '.',
},
filePath.slice(
filePath.lastIndexOf('/') + 1,
filePath.length - '.proto'.length,
),
'interface.ts',
'interface',
);

const fileName = combine(
{
joinWith: '.',
},
fileNameWithoutExt,
'ts',
);

cachedPackageOutputs[packageName] = fileName;
Expand All @@ -112,7 +120,7 @@ export async function createContent(

generatedFilenames.push({
packageName,
filename: fileName,
filename: fileNameWithoutExt,
});

writeFile(interfaceFilename, await format(fileContent), {
Expand Down Expand Up @@ -146,7 +154,7 @@ export async function createContent(
`./${filename}.${hasEngine ? 'js' : 'ts'}`;

result.typesVersions[`${packageName}`] = [
`./${filename}.${hasEngine ? '.d.ts' : '.ts'}`,
`./${filename}.${hasEngine ? 'd.ts' : 'ts'}`,
];

return result;
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/utils/objectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export function mergeObj(source: any, target: any): any {
if (sourceVal) {
if (Array.isArray(sourceVal) && Array.isArray(value)) {
source[key].push(...value);
} else {
} else if (typeof sourceVal === 'object') {
Object.assign(source[key], value);
} else {
source[key] = value;
}
} else {
source[key] = value;
Expand Down

0 comments on commit 8fea241

Please sign in to comment.