-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): ensure paths are resolved correctly in ng-packagr execu…
…tors (#13059)
- Loading branch information
1 parent
0432279
commit 6bc3720
Showing
5 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Adapted from a private function at ng-packagr | ||
* https://github.com/ng-packagr/ng-packagr/blob/main/src/lib/ts/tsconfig.ts#L12: | ||
* | ||
* Changes made: | ||
* - Added an extra function that updates the configFilePath in the returned parsed options | ||
* to be the original tsconfig file. | ||
*/ | ||
|
||
import type { | ||
CompilerOptions, | ||
ParsedConfiguration, | ||
} from '@angular/compiler-cli'; | ||
import { ngCompilerCli } from 'ng-packagr/lib/utils/ng-compiler-cli'; | ||
import { resolve } from 'path'; | ||
import * as ts from 'typescript'; | ||
|
||
async function readDefaultTsConfig( | ||
fileName: string | ||
): Promise<ParsedConfiguration> { | ||
// these options are mandatory | ||
const extraOptions: CompilerOptions = { | ||
target: ts.ScriptTarget.ES2020, | ||
experimentalDecorators: true, | ||
|
||
// sourcemaps | ||
sourceMap: false, | ||
inlineSources: true, | ||
inlineSourceMap: true, | ||
|
||
outDir: '', | ||
declaration: true, | ||
|
||
// ng compiler to options | ||
enableResourceInlining: true, | ||
|
||
// these are required to set the appropriate EmitFlags | ||
flatModuleId: 'AUTOGENERATED', | ||
flatModuleOutFile: 'AUTOGENERATED', | ||
}; | ||
|
||
const { readConfiguration } = await ngCompilerCli(); | ||
|
||
return readConfiguration(fileName, extraOptions); | ||
} | ||
|
||
/** | ||
* Proxy function that ensures the configFilePath option points to the original file path. | ||
*/ | ||
export async function parseRemappedTsConfigAndMergeDefaults( | ||
workspaceRoot: string, | ||
originalFilePath: string, | ||
remappedFilePath: string | ||
): Promise<ParsedConfiguration> { | ||
const parsedConfiguration = await readDefaultTsConfig(remappedFilePath); | ||
parsedConfiguration.options.configFilePath = resolve( | ||
workspaceRoot, | ||
originalFilePath | ||
); | ||
|
||
return parsedConfiguration; | ||
} |