Skip to content

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

Merged
merged 2 commits into from
Jun 18, 2018
Merged

fix(@schematics/angular): add baseUrl in root tsconfig when migrating #11261

merged 2 commits into from
Jun 18, 2018

Conversation

alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Jun 15, 2018

Closes: #11258

The problem is that in Angular CLI 1.X.X the root tsconfig didn't have baseUrl, and when upgrading to v6 the baseUrl option is not added. baseUrl is now mandatory especially when creating a library.

//cc @StephenFluin

compilerOptions.module = compilerOptions.module || 'es2015';
compilerOptions.baseUrl = compilerOptions.baseUrl || './';

host.overwrite(tsConfigPath, JSON.stringify(tsCfgAst.value, null, 2));
Copy link
Collaborator Author

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');
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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 || './';
Copy link
Member

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.

@alan-agius4
Copy link
Collaborator Author

@clydin PR updated

@alan-agius4
Copy link
Collaborator Author

alan-agius4 commented Jun 17, 2018 via email


const validBaseUrl = ['./', '', '.'];
if (!validBaseUrl.includes(baseUrl as string)) {
console.log(terminal.yellow(
Copy link
Member

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.

Copy link
Collaborator Author

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.

@clydin clydin merged commit dad2de9 into angular:master Jun 18, 2018
@alan-agius4 alan-agius4 deleted the feature/migration-tsconfig branch June 18, 2018 13:38
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Building library gives error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option.
3 participants