Skip to content
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

build(bazel): use value of /// <amd-module name=“”> directive to convert fileNameToModuleName in ngc-wrapped #25650

Conversation

gregmagolan
Copy link
Contributor

@gregmagolan gregmagolan commented Aug 24, 2018

The work-around that was removed in #25604 is still needed for building angular from bazel downstream. I was mistaken in my analysis.

This PR puts the workaround back but adds fixes the module name resolution for cases like @angular/core.ngfactory which should actually be resolved to @angular/core/core.ngfactory.

This will fix angular/angular-cli#11835 which promted #25604 while not breaking angular building from source downstream.

UPDATE: New approach after talking to @alexeagle and @alxhub. Using the moduleName from the ts.SourceFile will ensure the .ngfactory && .ngsummary files get the correct module names when building angular from source downstream

@mary-poppins
Copy link

You can preview 22d4647 at https://pr25650-22d4647.ngbuilds.io/.

@gregmagolan gregmagolan force-pushed the amd-module-name-for-ngfactory-v2 branch from 22d4647 to 4b1e7a8 Compare August 24, 2018 03:06
@mary-poppins
Copy link

You can preview 4b1e7a8 at https://pr25650-4b1e7a8.ngbuilds.io/.

Copy link
Contributor

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the thorough commenting. gross, but as they say "Ivy fixes it"

@tretne
Copy link

tretne commented Aug 24, 2018

Tested this, but I still have issues with our scoped package's secondary entrypoints since they consists of three name segments, i.e. "@connect/block/spinner".

@ease
Copy link

ease commented Aug 24, 2018

@gregmagolan I've tested with "@angular/cli": "~6.1.5" but having the same problem on every file change, Issue angular/angular-cli#11835
Here's my package.json:

{
"name": "demo-portal",
"version": "1.1.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"download-webdriver-binaries": "node node_modules/protractor/bin/webdriver-manager update",
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.4",
"@angular/common": "^6.1.4",
"@angular/compiler": "^6.1.4",
"@angular/core": "^6.1.4",
"@angular/forms": "^6.1.4",
"@angular/http": "^6.1.4",
"@angular/platform-browser": "^6.1.4",
"@angular/platform-browser-dynamic": "^6.1.4",
"@angular/router": "^6.1.4",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"core-js": "^2.5.7",
"node-sass": "^4.9.3",
"rxjs": "^6.0.0",
"rxjs-compat": "6.2.2",
"zone.js": "^0.8.26",
"lodash.isequal": "^4.5.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "~6.1.5",
"@angular/compiler-cli": "^6.1.4",
"@angular/language-service": "^6.1.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~10.9.1",
"codelyzer": "~4.4.4",
"jasmine-core": "~3.2.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}

Edit: I'm using external library (demo-library) created with ng-packagr. I see the following error after first build (on every save):

ERROR in Demo-Portal\src\app\feature\contact-form.ngfactory.js
Module not found: Error: Can't resolve 'demo-library.ngfactory' in 'Demo-Portal\src\app\feature\contact-form'

@gregmagolan
Copy link
Contributor Author

@ease That should be fixed in 6.1.5 which hasn't been cut yet. #25604 landed just after the 6.1.4 cut.

@alexeagle
Copy link
Contributor

@ease if you really want to test things right after they land, you need to use snapshot builds of Angular and CLI, e.g. use @angular/core@github:angular/core-builds and @angular/cli@github:angular/cli-builds

@gregmagolan
Copy link
Contributor Author

Still not quite right. Doesn’t handle secondary entry point module names such as @angular/common/http as pointed out by @tretne. Need to find a more principled fix for this issue.

In the meantime, angular/angular-cli#11835 is fixed at the expense of building angular from source with bazel downstream.

@gregmagolan gregmagolan force-pushed the amd-module-name-for-ngfactory-v2 branch from 4b1e7a8 to eb69745 Compare August 24, 2018 22:07
@gregmagolan gregmagolan changed the title fix: add mappings for ngfactory & ngsummary files to their module names in aot summary resolver build(bazel): use value of /// <amd-module name=“”> directive to convert fileNameToModuleName in ngc-wrapped Aug 24, 2018
@gregmagolan
Copy link
Contributor Author

New approach after talking to @alexeagle and @alxhub. Using the moduleName from the ts.SourceFile will ensure the .ngfactory && .ngsummary files get the correct module names when building angular from source downstream

@gregmagolan
Copy link
Contributor Author

See comment bazelbuild/rules_typescript#223 (comment) for a good trace of the issue.

@mary-poppins
Copy link

You can preview eb69745 at https://pr25650-eb69745.ngbuilds.io/.

@@ -226,6 +226,15 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});

ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check whether the file is a .d.ts file before attempting this?

Otherwise, LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From slack:

@gregmagolan -> I thought of checking for .d.ts.. could a .ts have a /// <amd-module name="x" /> directive? and if it does do we care at that point?

@alexeagle -> it could, and I think the correct thing would be to honor that, since hopefully the user did it explicitly as a workaround for something

@gregmagolan gregmagolan added the action: merge The PR is ready for merge by the caretaker label Aug 24, 2018
if (sourceFile && sourceFile.moduleName) {
return sourceFile.moduleName;
}
} catch (err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove (err)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We don't need humans to figure that out. Would you like to find/write a lint check that catches unused identifiers in catch block? Maybe we just need to turn one on.

@matsko matsko closed this in 9bcd8c2 Aug 27, 2018
matsko pushed a commit that referenced this pull request Aug 27, 2018
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
@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 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ng serve --aot fail after file change
8 participants