Skip to content

Adding a base npm middleware and making it public #7046

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

Closed
wants to merge 3 commits into from
Closed

Adding a base npm middleware and making it public #7046

wants to merge 3 commits into from

Conversation

alexeyzimarev
Copy link

Summary of the changes (Less than 80 chars)

  • Added a more generic npm middleware and making it public
  • Changed the Angular CLI and React dev server middleware to use the new npm middleware
  • The change makes it possible to create a custom middleware for other SPA frameworks, for example, Vue.js

Addresses #5214 (partially)

@dnfclas
Copy link

dnfclas commented Jan 27, 2019

CLA assistant check
All CLA requirements met.

@alexeyzimarev
Copy link
Author

If we get a generic npm server middleware, adding a new Vue CLI middleware would be trivial, check https://gist.github.com/alexeyzimarev/deda49dc8faf26b0d0978610d91b5c41

It also simplifies the code for the existing Angular and React middleware classes.

@alexeyzimarev
Copy link
Author

I don't the build fails due to my changes

@Tratcher
Copy link
Member

/AzurePipelines run AspNetCore-ci

@azure-pipelines
Copy link

Success! 2 created and queued.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 28, 2019
@SteveSandersonMS
Copy link
Member

I'm fine with doing this sort of thing, but I do think the APIs this creates are very unusual.

        public static void Attach(ISpaBuilder spaBuilder,
            string npmScriptName,
            Func<int, string> npmParameters,
            Func<int, IDictionary<string, string>> envVars, 
            Regex outputMatch, Func<Match, int, Uri> listeningUri)

We don't usually have people pass things like Func<int, string>. It's not obvious for the caller what their callback is meant to do here, or what the int param is (I know it's the port, but I don't think it's obvious). It's also a bit sketchy to assume that all SPA server middleware is always going to make its "am I ready or not" decision based on a Regex match of some console process's output - that seems pretty specific to the way that Angular CLI and create-react-app work.

Perhaps rather than bundling all these assumptions together in one method, we should have a collection of separate methods you can pick the relevant ones out of, e.g. on some NpmHelpers class:

  • Process StartNpmScript(string scriptName, string arguments)
  • IAsyncEnumerable<string> ReadOutputLinesAsync(Process process)
  • Task PollForSuccessResponseAsync(Uri uri, TimeSpan timeout)

Then AngularCliMiddleware, ReactDevelopmentServerMiddleware, and external SPA dev server middlewares can be constructed more simply out of these primitives.

@ryanbrandenburg What's your preference on how the SPA middleware APIs should evolve?

@alexeyzimarev
Copy link
Author

alexeyzimarev commented Feb 1, 2019 via email

@mkArtakMSFT
Copy link
Member

@SteveSandersonMS does this look align with our long-term vision in this area? The issue this is partially resolving is our plan (#5182). If this looks fine, let's ask @alexeyzimarev to rebase this so we can get this merged for 5.0.

@SteveSandersonMS
Copy link
Member

@mkArtakMSFT As I commented above, I think we certainly could add a base NPM middleware. My concern is that the APIs proposed in this PR aren't what we would want, for the reasons described in my comment. I suggested some alternate API design thoughts in my comment.

@mkArtakMSFT
Copy link
Member

Thanks for your effort, @alexeyzimarev.
After some further discussion we've decided that we don't want to take this PR as it's not a complete solution for #5182. We will instead come up with a design for the feature and tackle it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants