-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Angular: Don't kill dev command by using observables #33185
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
Angular Architect builder Observable lifecycle long-running dev server
<web_search_result>
Short summary — how to implement a long-running dev-server builder with Architect (Observable lifecycle):
Sources:
[1] Angular CLI Builders (official docs) — watch mode, reportRunning, lifecycle.
[2] Community/docs mirrors explaining watch phases and reportRunning.
[3] @angular-devkit/architect / builder typings (BuilderRun/stop/output fields).
</web_search_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 1
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 1
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Angular Architect builder Observable subscription cleanup teardown function
<web_search_result>
Short answer
Example
Minimal pattern to ensure proper cleanup:
const myBuilder = createBuilder((options, context) => {
return new Observable(observer => {
const sub = someHotObservable.subscribe(value => {
// emit a BuilderOutput when appropriate
observer.next({ success: true });
}, err => observer.error(err));
});
});
Notes
Sources
[1] Angular CLI builders (official docs).
[2] createBuilder / CLI builder behavior (Architect teardown description).
</web_search_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: storybookjs/storybook
<shell_result>
Repository: storybookjs/storybook
Exit code: 0
stdout:
</shell_result>
Add Observable teardown function to gracefully stop the dev server when the builder is stopped.
The implementation starts a dev server via
buildDevStandalone()which resolves after the server is listening, then emits a successful BuilderOutput and keeps the Observable alive. However, when Architect callsrun.stop()or the Observable is unsubscribed, there is no teardown function to gracefully shut down the server process. This leaves the Node.js dev server running as an orphaned process.According to Angular Architect's documented patterns, provide a teardown function that stops the dev server:
Note:
buildDevStandalone()needs to be modified to return a handle (e.g., the server instance or process) that can be terminated in the teardown function.