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: create esbuild bundle for embedded devices #3480

Merged
merged 18 commits into from
Dec 12, 2023
Merged

feat: create esbuild bundle for embedded devices #3480

merged 18 commits into from
Dec 12, 2023

Conversation

robertsLando
Copy link
Member

@robertsLando robertsLando commented Dec 11, 2023

Ref #3473

@coveralls
Copy link

coveralls commented Dec 11, 2023

Pull Request Test Coverage Report for Build 7182031986

  • 2 of 142 (1.41%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 22.265%

Changes Missing Coverage Covered Lines Changed/Added Lines %
api/lib/ZwaveClient.ts 0 1 0.0%
api/lib/utils.ts 2 3 66.67%
esbuild.js 0 138 0.0%
Totals Coverage Status
Change from base Build 7165593458: -0.2%
Covered Lines: 3735
Relevant Lines: 17841

💛 - Coveralls

@robertsLando robertsLando changed the title chore: create esbuild bundle feat: create esbuild bundle for embedded devices Dec 12, 2023
@robertsLando robertsLando merged commit 68326d6 into master Dec 12, 2023
9 checks passed
@robertsLando robertsLando deleted the esbuild branch December 12, 2023 16:26
@dwmw2
Copy link

dwmw2 commented Dec 13, 2023

OK, I have a package building and working with these changes. Thanks!

nxhack/openwrt-node-packages@bcd6acf

Just a few nits...

To build against the release tarball, I needed the patches to be against server/api/{utils.js,ZWaveClient.js} instead of the corresponding .ts files. But that'll just fall out when there's a release.

I also needed to change the entryPoints in esbuild.js from api/bin/www.ts to server/bin/www.js though.

And when the package build does its npm install, I end up with the config in node_modules/zwave-js/node_modules/@zwave-js/config rather than node_modules/@zwave-js/config so for now I just made a symlink and then npm run bundle works.

@robertsLando
Copy link
Member Author

Humm insteresting... but what tarball are you donwloading? npm tarball?

@dwmw2
Copy link

dwmw2 commented Dec 13, 2023

Yes: https://registry.npmjs.org/zwave-js-ui/-/zwave-js-ui-9.5.1.tgz

Then I've applied your changes from commit 68326d6, changed to apply to server/bin/*.js as noted: nxhack/openwrt-node-packages@bcd6acf#diff-22a79582a1cde8962a6d14448ba53e73a6dd4cc77b75990f43304d12055a6e06

Then npm install with a bunch of arguments from @nxhack's packaging:

	npm install --prefer-offline --no-audit --global-style --install-strategy=shallow --no-save --omit=dev --no-package-lock --build-from-source --target_arch=$(NODEJS_CPU) --omit=optional --no-optional --prefer-dedupe

Then, as I described above:

	sed s^api/bin/www.ts^server/bin/www.js^ -i $(PKG_BUILD_DIR)/esbuild.js
	ln -sf ../zwave-js/node_modules/@zwave-js/config $(PKG_BUILD_DIR)/node_modules/@zwave-js/config

Finally, bundle it and create the symlink to the separately packaged serialport bindings:

	npm run bundle -- --minify
	rm -rf $(PKG_BUILD_DIR)/build/node_modules/@serialport
	ln -sf ../../@serialport $(PKG_BUILD_DIR)/build/node_modules/@serialport

Then the whole of the build/ directory gets packaged to be installed on the target system.

@robertsLando
Copy link
Member Author

robertsLando commented Dec 13, 2023

Would it help adding a flag like --js-entrypoint to handle that case on esbuild?

Done: f608a40

@dwmw2
Copy link

dwmw2 commented Dec 13, 2023

Or could we make it use server/bin/www.js unconditionally? Don't we always have to build api/bin/www.tsserver/bin/www.js anyway? The original TypeScript file isn't even in the bundle, surely?

@dwmw2
Copy link

dwmw2 commented Dec 13, 2023

https://janessagarrow.com/blog/typescript-and-esbuild/ seems to suggest that esbuild allows the .ts file to be specified because it might actually get built to multiple different .js files, for different environments. But that isn't a concern here as we're only building for node, right? So we can just unconditionally list server/bin/www.js as the entrypoint without needing an option?

@robertsLando
Copy link
Member Author

@dwmw2 reason is that compiling against ts with source maps set to true allows me to have a better stack errors as they will point to ts lines, otherwise it might be difficult to debug things

@dwmw2
Copy link

dwmw2 commented Dec 13, 2023

Don't you get that from the source maps anyway?

@robertsLando
Copy link
Member Author

Don't you get that from the source maps anyway?

Wrong, If I ship sourcemaps (with also the code inside api folder) I get full logs

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.

3 participants