-
Notifications
You must be signed in to change notification settings - Fork 11.9k
feat(@angular/cli): add ability to build bundle for node #6913
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
Conversation
31c8e93
to
160ca2c
Compare
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.
1 question for now
@@ -4,5 +4,5 @@ import {DOCUMENT} from '@angular/platform-browser'; | |||
|
|||
@Injectable() | |||
export class MyInjectable { | |||
constructor(public viewContainer: ViewContainerRef, @Inject(DOCUMENT) public doc) {} |
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.
?
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.
VCR is not an ordinary injectable
It can only be injected from a component and it's value is the VCR of the specific instance of the component.
A service/ injectable is not able to inject a VCR
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.
This is to test the downgrading of a non-annotated Angular class. I think the test needs to happen, I don't care much with which class. Does this test makes your code fail? How so?
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.
This test is done in the normal webpack tests.
This test makes my tests fail because I am actually executing the application and it fails to bootstrap because the service is not able to find the VCR.
Is it fine to remove it from this set of tests because the functionality is covered in the other webpack tests?
df8d278
to
2602917
Compare
+ 'type: undefined, decorators.*Inject.*args: .*DOCUMENT.*')) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
new RegExp('AppComponent.ctorParameters = .*MyInjectable')) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
/AppModule \*\/\].*\.testProp = \'testing\'/)) | ||
.then(() => expectFileToMatch('dist/app.main.js', | ||
/renderModuleFactory \*\/\].*\/\* AppModuleNgFactory \*\/\]/)) | ||
/renderModuleFactory \*\/\].*\/\* AppModuleNgFactory \*\/\]/)) | ||
.then(() => exec(normalize('rm'), |
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.
Considering there's no path, normalize('rm')
is a noop.
@@ -83,6 +83,11 @@ | |||
"type": "string", | |||
"description": "Base url for the application being built." | |||
}, | |||
"platform": { | |||
"type": "string", |
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.
This should be an enum, not a generic stsring.
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.
This is done.
eb675f2
to
04d605e
Compare
packages/@angular/cli/tasks/eject.ts
Outdated
@@ -436,6 +436,9 @@ export default Task.extend({ | |||
if (project.root === path.resolve(outputPath)) { | |||
throw new SilentError ('Output path MUST not be project root directory!'); | |||
} | |||
if (appConfig.platform && appConfig.platform === 'server') { |
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.
appConfig.platform
is redundant here.
@@ -464,11 +533,14 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s | |||
if (!plugin.skipCodeGeneration) { | |||
return Promise.resolve() | |||
.then(() => _removeDecorators(refactor)) | |||
.then(() => _refactorBootstrap(plugin, refactor)); | |||
.then(() => _refactorBootstrap(plugin, refactor)) | |||
.then(() => _stuff(plugin, refactor)) |
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.
_stuff
? I'm sure you can do better ;)
d6e695d
to
ed7f5f0
Compare
}); | ||
|
||
const dirName = path.normalize(path.dirname(refactor.fileName)); | ||
let exportStatement = `export const moduleMap = ${JSON.stringify(map)};`; |
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.
Change this to not use JSON.stringify
and instead properly build up the export map without string replacement hacks.
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.
Also, let's rename the exported symbol to LAZY_MODULE_FACTORY_MAP
.
return { | ||
loadChildrenString: routeKey, | ||
path: plugin.lazyRoutes[lazyRouteKey], | ||
name: routeKey.split('#')[1] |
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.
Add validation that the loadChildren
format is correct.
e127c52
to
a2d4ddb
Compare
refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); | ||
return `"${routeKey}": __lazy_${index}__.${moduleName}`; | ||
}) | ||
.join(); |
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.
Wait, how are these separated. Shouldn't it be joined with a comma or something?
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.
Never mind, apparently comma is the default for join()
.
|
||
const modulePath = plugin.lazyRoutes[lazyRouteKey]; | ||
const relativePath = path.relative(dirName, modulePath).replace(/\\/g, '/'); | ||
refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); |
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.
It's weird for .map
to have side effects. Can we move this out to a separate .forEach
iteration through the keys?
refactor.prependBefore(node, `import * as __lazy_${index}__ from './${relativePath}'`); | ||
return `"${routeKey}": __lazy_${index}__.${moduleName}`; | ||
}) | ||
.join(); |
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.
Never mind, apparently comma is the default for join()
.
eafa684
to
b6ae689
Compare
b6ae689
to
f089a33
Compare
Just confirmed locally that the e2e tests are flakes and everything is green. Cheers. |
Was just playing with this and found an issue with a particular export pattern in barrels that is broken: intellix/universal-cli@8ed967d#diff-a44e09a3c12667be300e8cb75d793c5dR1 Worked inside @app/user/index.ts: export * from './user.module';
export * from './user.service'; Didn't work inside app/user/index.ts: export { UserModule } from './user.module';
export { UserService } from './user.service'; Build error:
|
@intellix Thank you for testing this feature and for the replication for the issue. I have prepared a fix for this issue but would you do the honors of logging it as an issue in this GitHub repo? Thank you |
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. |
This adds the ability to create a commonjs bundle which contains the application module/ngfactory which can be used in node environments
Here's an example of how a project using this feature would look https://github.com/FrozenPandaz/u-cli-app