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

feat(hmr): add in hmr capabilities #1400

Merged
merged 33 commits into from
May 5, 2022
Merged

feat(hmr): add in hmr capabilities #1400

merged 33 commits into from
May 5, 2022

Conversation

brandonseydel
Copy link
Member

Pull Request

πŸ“– Description

🎫 Issues

πŸ‘©β€πŸ’» Reviewer Notes

πŸ“‘ Test Plan

⏭ Next Steps

Copy link
Member

@bigopon bigopon left a comment

Choose a reason for hiding this comment

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

Looks great! Can we have some demo gif pls πŸ˜„

@3cp
Copy link
Member

3cp commented Apr 25, 2022

I am against to add HMR inside conventions.

  1. HMR sounds like has nothing to do with conventions.

  2. If user manually writes customElement decorator, it will bypass conventions logic. But we still want to support HMR in that use case. I believe the implementation here didn't cover the use case.

User can also write Aurelia 2 app without using our conventions in the toolchain at all. Aka, totally manual and verbose code.

For the above two arguments, I suggest to invest the possibility to add HMR support in other place (or a standalone npm package like we did for Aurelia v1).

@bigopon bigopon force-pushed the master branch 18 times, most recently from 23d93cc to 8a0fb9c Compare April 25, 2022 12:09
@brandonseydel
Copy link
Member Author

brandonseydel commented Apr 25, 2022

I am against to add HMR inside conventions.

  1. HMR sounds like has nothing to do with conventions.
  2. If user manually writes customElement decorator, it will bypass conventions logic. But we still want to support HMR in that use case. I believe the implementation here didn't cover the use case.

User can also write Aurelia 2 app without using our conventions in the toolchain at all. Aka, totally manual and verbose code.

For the above two arguments, I suggest to invest the possibility to add HMR support in other place (or a standalone npm package like we did for Aurelia v1).

I think plugin-conventions is just a naming problem and this code indeed belongs here. We shouldn't be making double processing a thing from our one plugin. There is an issue with a standalone package as it would be one file with not really any code (more an interpolated string). This is overkill. I would suggest just renaming conventions and letting it include more than just conventions in the plugin.

@aurelia/cli
@aurelia/processor

@Sayan751
Copy link
Contributor

Sayan751 commented Apr 25, 2022

I think not everyone would like to use the convention, though. I think it would be better to create multiple plugins (if not multiple packages) that focuses on a single aspect, and then an umbrella plugin to aggregate the config or whatever for the ease of use (although it can be postponed if super complicated or if the individual plugins can be easily used). IMO, it is important to ensure that HMR works individually without relying on convention.

@brandonseydel
Copy link
Member Author

I think not everyone would like to use the convention, though. I think it would be better to create multiple plugin (if not multiple packages) that focuses on a single aspect, and then an umbrella plugin to aggregate the config or whatever for the ease of use (although it might be postponed if super complicated or if the individual plugins can be easily used). IMO, it is important to ensure that HMR works individually without relying on convention.

It doesn't rely on convention. HMR operates by itself entirely in the plugin-convention package. That is why I am thinking it is named improperly as it takes care of more than just one thing. We can seperate out into many packages, but there should be one entry into code manipulation I feel.

@3cp
Copy link
Member

3cp commented Apr 27, 2022

I recall, quite some time ago, we talked about moving all package-cjs into individual repos.

Those packages are not core packages. Putting them into monorepo actually hurts development more than helping, especially the cjs/esm mode build switching for local setup.

We should revisit the idea before production release.

@bigopon
Copy link
Member

bigopon commented Apr 27, 2022

cjs/esm mode build switching for local setup

With rollup, we no longer need to switch to build. Though we are still switching the main and module fields to run the tests of these packages. If we are to split it out, I'd imagine it'd be more difficult.

When running test with mocha, we still need to do this because some reasons I'm not sure 100% yet. Running mocha --loader esm or mocha --register ts-node/esm didn't seem to work. I'll need to investigate that.

@3cp
Copy link
Member

3cp commented Apr 27, 2022

If you don't use "type": "module" in package.json, you can still ship both cjs and esm with explicit .cjs and .mjs files. And mocha should work better. At least my ava setup is happier with default commonjs type in package.json.

"main": "dist/index.cjs",
  "module": "dist/index.mjs",
  "types": "dist/index.d.ts",
  "exports": {
// works with require(...)
    "require": "dist/index.cjs",
// works with import.
    "import": "dist/index.mjs"
  },

Ref: https://github.com/gorbjs/shared/blob/main/package.json

@bigopon
Copy link
Member

bigopon commented Apr 27, 2022

@3cp thanks, I'll be applying that.

@brandonseydel
Copy link
Member Author

brandonseydel commented Apr 27, 2022

I guess our next task is to find a name that is appropriate for the package. Any suggestion on that? Some immediate candidates:

  • component-processor
  • resource-processor
    maybe add pre prefix to processor. Any suggestions?

@bigopon some more

@aurelia/processor
@aurelia/pre-processor

@bigopon
Copy link
Member

bigopon commented Apr 28, 2022

I've created a discussion for our rename here #1404
I think we can go ahead first, with a rename later.

@codecov
Copy link

codecov bot commented Apr 28, 2022

Codecov Report

Merging #1400 (0561f22) into master (585d94c) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1400   +/-   ##
=======================================
  Coverage   87.07%   87.07%           
=======================================
  Files         212      212           
  Lines       17505    17505           
  Branches     4106     4106           
=======================================
  Hits        15243    15243           
  Misses       2262     2262           

πŸ“£ Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@bigopon bigopon added this to the v2.0-beta milestone Apr 28, 2022
@3cp
Copy link
Member

3cp commented Apr 28, 2022

@brandonseydel BTW, I could not get my head around how to support vite prod build.

Vite uses different path for dev and prod build. The prod build tries to parse our html as html, but we already transpiled html into js code. The whole rollup chain does not have concept of asset type, nor allowing changing extname in id (the file name).

When you are on Vite, see if you can come up with any workaround, thx.

For reference: the vite au2 plugin which works (kind of) in dev mode:
https://github.com/3cp/au2-vite/blob/main/vite.config.ts

@brandonseydel
Copy link
Member Author

@brandonseydel BTW, I could not get my head around how to support vite prod build.

Vite uses different path for dev and prod build. The prod build tries to parse our html as html, but we already transpiled html into js code. The whole rollup chain does not have concept of asset type, nor allowing changing extname in id (the file name).

When you are on Vite, see if you can come up with any workaround, thx.

For reference: the vite au2 plugin which works (kind of) in dev mode: https://github.com/3cp/au2-vite/blob/main/vite.config.ts

Yea been fighting with vite some on the mangler side of things. It doesn't seem to want to listen when using esbuild.....

@bigopon bigopon merged commit 6d932a7 into master May 5, 2022
@bigopon bigopon deleted the feat/hmr branch May 5, 2022 23:08
@@ -27,7 +27,12 @@ export function preprocess(
unit.filePair = path.basename(filePair);
}
}
return preprocessHtmlTemplate(unit, allOptions);

const hasViewModel = Boolean(allOptions.jsExtensions.map(e =>
Copy link
Member

Choose a reason for hiding this comment

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

@brandonseydel I might be confused, but I don't think this ever worked. We don't unit test hmr setup, so might missed this bug.

Boolean([false, false]) yields true

cc @bigopon

Copy link
Member

Choose a reason for hiding this comment

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

@brandonseydel @bigopon my bad, I miss understood the code :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants