Skip to content

Commit

Permalink
fix(angular): emit dts when using entrypoint name as filename in ng-p…
Browse files Browse the repository at this point in the history
…ackagr executors (nrwl#11032)
  • Loading branch information
leosvelperez authored Jul 6, 2022
1 parent d579f94 commit bc5c414
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export function cacheCompilerHost(
entryPoint.dependsOn(node);
};

const { flatModuleFile, entryFile } = entryPoint.data.entryPoint;
const { flatModuleFile, destinationPath, entryFile } =
entryPoint.data.entryPoint;
const flatModuleFileDtsFilename = `${flatModuleFile}.d.ts`;
const flatModuleFileDtsPath = ensureUnixPath(
path.join(destinationPath, flatModuleFileDtsFilename)
);
const hasIndexEntryFile =
path.basename(entryFile.toLowerCase()) === 'index.ts';

Expand Down Expand Up @@ -85,13 +89,19 @@ export function cacheCompilerHost(
sourceFiles?: ReadonlyArray<ts.SourceFile>
) => {
if (fileName.endsWith('.d.ts')) {
if (
hasIndexEntryFile &&
path.basename(fileName) === flatModuleFileDtsFilename
) {
// In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.
// Because it will cause a conflict.
return;
if (fileName === flatModuleFileDtsPath) {
if (hasIndexEntryFile) {
// In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.
// Because it will cause a conflict.
return;
} else {
// Rename file to index.d.ts so that TypeScript can resolve types without
// them needing to be referenced in the package.json manifest.
fileName = fileName.replace(
flatModuleFileDtsFilename,
'index.d.ts'
);
}
}

// Rename file to index.d.ts so that TypeScript can resolve types without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export function cacheCompilerHost(
entryPoint.dependsOn(node);
};

const { flatModuleFile, entryFile } = entryPoint.data.entryPoint;
const { flatModuleFile, destinationPath, entryFile } =
entryPoint.data.entryPoint;
const flatModuleFileDtsFilename = `${flatModuleFile}.d.ts`;
const flatModuleFileDtsPath = ensureUnixPath(
path.join(destinationPath, flatModuleFileDtsFilename)
);
const hasIndexEntryFile =
path.basename(entryFile.toLowerCase()) === 'index.ts';

Expand Down Expand Up @@ -85,13 +89,19 @@ export function cacheCompilerHost(
sourceFiles?: ReadonlyArray<ts.SourceFile>
) => {
if (fileName.endsWith('.d.ts')) {
if (
hasIndexEntryFile &&
path.basename(fileName) === flatModuleFileDtsFilename
) {
// In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.
// Because it will cause a conflict.
return;
if (fileName === flatModuleFileDtsPath) {
if (hasIndexEntryFile) {
// In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.
// Because it will cause a conflict.
return;
} else {
// Rename file to index.d.ts so that TypeScript can resolve types without
// them needing to be referenced in the package.json manifest.
fileName = fileName.replace(
flatModuleFileDtsFilename,
'index.d.ts'
);
}
}

// Rename file to index.d.ts so that TypeScript can resolve types without
Expand Down

0 comments on commit bc5c414

Please sign in to comment.