-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(@schematics/angular): add baseUrl
in root tsconfig when migrating
#11261
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(@schematics/angular): add baseUrl
in root tsconfig when migrating
#11261
Conversation
compilerOptions.module = compilerOptions.module || 'es2015'; | ||
compilerOptions.baseUrl = compilerOptions.baseUrl || './'; | ||
|
||
host.overwrite(tsConfigPath, JSON.stringify(tsCfgAst.value, null, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tired to use the JSON AST for this, but updating multiple properties within the same JSON Object is kinda tricky with appendPropertyInAstObject
as it kept appending ,
after the last existing property. I also tried to use the .remove
and insertLeft
, but it kinda get too much complicated for this trivial thing.
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
if (tsCfgAst.kind != 'object') { | ||
throw new SchematicsException('Invalid tsconfig. Was expecting an object'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message should indicate the root tsconfig is the problematic one. Also, I'm not sure that this would be fatal. Maybe log an error/warning and return? Same for the check below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fatal since other schematics such as generate library always extend the root ts config.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Just the verbiage adjustment then.
|
||
const compilerOptions = compilerOptionsAstNode.value; | ||
compilerOptions.module = compilerOptions.module || 'es2015'; | ||
compilerOptions.baseUrl = compilerOptions.baseUrl || './'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is already set and not a variation of the current directory (e.g., "", ".", or "./") then a warning should probably be shown indicating that generated library path mapping will not work.
@clydin PR updated |
With AppVeyor, I am getting this error quite a lot even in my other PRs
Error: ENOTEMPTY: directory not empty, rmdir
'C:\projects\angular-cli\tests\@angular_devkit\build_angular\test-project-host-hello-world-app-ao7kthpblkg\src'
177
<https://ci.appveyor.com/project/AngularCLI/angular-cli/build/1.0.11959#L177>
at Object.fs.rmdirSync (fs.js:821:3)
…On Sun, 17 Jun 2018 at 17:08, clydin ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/schematics/angular/migrations/update-6/index.ts
<#11261 (comment)>:
> @@ -724,6 +724,43 @@ function updateTsLintConfig(): Rule {
};
}
+function updateRootTsConfig(): Rule {
+ return (host: Tree, context: SchematicContext) => {
+ const tsConfigPath = '/tsconfig.json';
+ const buffer = host.read(tsConfigPath);
+ if (!buffer) {
+ return;
+ }
+
+ const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose);
+ if (tsCfgAst.kind != 'object') {
+ throw new SchematicsException('Invalid tsconfig. Was expecting an object');
True. Just the verbiage adjustment then.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11261 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQv-WrfziN4KKaoEModlzAaE2jYgBMSEks5t9nEHgaJpZM4UpguH>
.
|
|
||
const validBaseUrl = ['./', '', '.']; | ||
if (!validBaseUrl.includes(baseUrl as string)) { | ||
console.log(terminal.yellow( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use context.logger.warn(...)
instead. Otherwise looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies about that. PR updated.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes: #11258
The problem is that in Angular CLI 1.X.X the root
tsconfig
didn't havebaseUrl
, and when upgrading to v6 thebaseUrl
option is not added.baseUrl
is now mandatory especially when creating a library.//cc @StephenFluin