Skip to content

Build packages as both CJS and ESM#1519

Merged
Mrtenz merged 21 commits intomainfrom
mrtenz/bundle-esm
Jun 22, 2023
Merged

Build packages as both CJS and ESM#1519
Mrtenz merged 21 commits intomainfrom
mrtenz/bundle-esm

Conversation

@Mrtenz
Copy link
Copy Markdown
Member

@Mrtenz Mrtenz commented Jun 17, 2023

  • We now use SWC to transpile TypeScript to JavaScript (both ESM and CJS).
  • TypeScript (tsc) is still used to generate types (and thus perform type checking).
  • The build job in CI was split into two jobs, to perform the two above tasks separately.
  • Each package.json now defines an exports field, so that consumers of the libraries can choose the right version for their specific environment.

@socket-security
Copy link
Copy Markdown

socket-security bot commented Jun 17, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: @mole-inc/bin-wrapper@8.0.1, @swc/cli@0.1.62, arch@2.2.0, strip-outer@2.0.0, strip-eof@1.0.0, @tokenizer/token@0.3.0, executable@4.1.1, bin-check@4.1.0, semver-truncate@2.0.0, sort-keys@1.1.2, find-versions@5.1.0, bin-version-check@5.0.0, filename-reserved-regex@3.0.0, bin-version@6.0.0, semver-regex@4.0.5, ext-list@2.2.2, os-filter-obj@2.0.0, sort-keys-length@1.0.1, trim-repeated@2.0.0, ext-name@5.0.0

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

@socket-security
Copy link
Copy Markdown

socket-security bot commented Jun 17, 2023

New and updated dependency changes detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives1 Size Publisher
@swc/cli 🆕 0.1.62 filesystem, shell, environment +504 22 MB kdy1

Footnotes

  1. https://docs.socket.dev

@Mrtenz Mrtenz force-pushed the mrtenz/bundle-esm branch from ec5ed61 to f3f0281 Compare June 20, 2023 09:42
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 20, 2023

Codecov Report

Merging #1519 (cf32418) into main (2273f01) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1519   +/-   ##
=======================================
  Coverage   95.10%   95.10%           
=======================================
  Files         218      218           
  Lines        4960     4965    +5     
  Branches      763      763           
=======================================
+ Hits         4717     4722    +5     
  Misses        243      243           
Impacted Files Coverage Δ
packages/snaps-cli/src/cmds/build/index.ts 100.00% <100.00%> (ø)
packages/snaps-cli/src/cmds/eval/index.ts 100.00% <100.00%> (ø)
packages/snaps-cli/src/cmds/manifest/index.ts 100.00% <100.00%> (ø)
packages/snaps-cli/src/cmds/serve/index.ts 100.00% <100.00%> (ø)
packages/snaps-cli/src/cmds/watch/index.ts 100.00% <100.00%> (ø)

@Mrtenz Mrtenz force-pushed the mrtenz/bundle-esm branch 2 times, most recently from 38529ae to 76332f3 Compare June 21, 2023 09:50
@Mrtenz Mrtenz marked this pull request as ready for review June 21, 2023 10:20
@Mrtenz Mrtenz requested a review from a team as a code owner June 21, 2023 10:20
@Mrtenz
Copy link
Copy Markdown
Member Author

Mrtenz commented Jun 21, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask/create-snap": "0.34.1-flask.1",
  "@metamask/rpc-methods": "0.34.1-preview.a96df8a",
  "@metamask/snaps-browserify-plugin": "0.34.1-preview.a96df8a",
  "@metamask/snaps-cli": "0.34.1-preview.a96df8a",
  "@metamask/snaps-controllers": "0.34.1-preview.a96df8a",
  "@metamask/snaps-execution-environments": "0.34.1-preview.a96df8a",
  "@metamask/snaps-jest": "0.34.1-preview.a96df8a",
  "@metamask/snaps-rollup-plugin": "0.34.1-preview.a96df8a",
  "@metamask/snaps-simulator": "0.34.1-flask.1",
  "@metamask/snaps-types": "0.34.1-preview.a96df8a",
  "@metamask/snaps-ui": "0.34.1-preview.a96df8a",
  "@metamask/snaps-utils": "0.34.1-preview.a96df8a",
  "@metamask/snaps-webpack-plugin": "0.34.1-preview.a96df8a",
  "@metamask/bip32-example-snap": "0.34.1-flask.1",
  "@metamask/bip44-example-snap": "0.34.1-flask.1",
  "@metamask/browserify-plugin-example-snap": "0.34.1-flask.1",
  "@metamask/cronjob-example-snap": "0.34.1-flask.1",
  "@metamask/dialog-example-snap": "0.34.1-flask.1",
  "@metamask/error-example-snap": "0.34.1-flask.1",
  "@metamask/ethereum-provider-example-snap": "0.34.1-flask.1",
  "@metamask/ethers-js-example-snap": "0.34.1-flask.1",
  "@metamask/get-entropy-example-snap": "0.34.1-flask.1",
  "@metamask/json-rpc-example-snap": "0.34.1-flask.1",
  "@metamask/manage-state-example-snap": "0.34.1-flask.1",
  "@metamask/network-example-snap": "0.34.1-flask.1",
  "@metamask/notification-example-snap": "0.34.1-flask.1",
  "@metamask/rollup-plugin-example-snap": "0.34.1-flask.1",
  "@metamask/insights-example-snap": "0.34.1-flask.1",
  "@metamask/wasm-example-snap": "0.34.1-flask.1",
  "@metamask/webpack-plugin-example-snap": "0.34.1-flask.1",
  "@metamask/consumer-signer-example-snap": "0.34.1-flask.1",
  "@metamask/core-signer-example-snap": "0.34.1-flask.1"
}

@Mrtenz Mrtenz force-pushed the mrtenz/bundle-esm branch from 2170fa6 to 3b98cc8 Compare June 21, 2023 11:44
@Mrtenz
Copy link
Copy Markdown
Member Author

Mrtenz commented Jun 21, 2023

@metamaskbot publish-preview

@Mrtenz Mrtenz force-pushed the mrtenz/bundle-esm branch from cd9622e to 6dfbae9 Compare June 21, 2023 17:30
@Mrtenz
Copy link
Copy Markdown
Member Author

Mrtenz commented Jun 21, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask/create-snap": "0.34.1-preview.6dfbae9",
  "@metamask/rpc-methods": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-browserify-plugin": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-cli": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-controllers": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-execution-environments": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-jest": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-rollup-plugin": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-simulator": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-types": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-ui": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-utils": "0.34.1-preview.6dfbae9",
  "@metamask/snaps-webpack-plugin": "0.34.1-preview.6dfbae9",
  "@metamask/bip32-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/bip44-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/browserify-plugin-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/cronjob-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/dialog-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/error-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/ethereum-provider-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/ethers-js-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/get-entropy-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/json-rpc-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/manage-state-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/network-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/notification-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/rollup-plugin-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/insights-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/wasm-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/webpack-plugin-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/consumer-signer-example-snap": "0.34.1-preview.6dfbae9",
  "@metamask/core-signer-example-snap": "0.34.1-preview.6dfbae9"
}

@Mrtenz
Copy link
Copy Markdown
Member Author

Mrtenz commented Jun 21, 2023

I have verified that this works in the MetaMask extension.

@Mrtenz Mrtenz force-pushed the mrtenz/bundle-esm branch from bbc29cd to a118517 Compare June 22, 2023 08:51
@Mrtenz
Copy link
Copy Markdown
Member Author

Mrtenz commented Jun 22, 2023

@SocketSecurity ignore-all

@Mrtenz Mrtenz merged commit 29981d1 into main Jun 22, 2023
@Mrtenz Mrtenz deleted the mrtenz/bundle-esm branch June 22, 2023 10:27
GuillaumeRx pushed a commit that referenced this pull request Jun 22, 2023
* Build packages as both CJS and ESM

* Fix lint issues

* Ignore more files in SWC build

* Fix build issues

* Build everything with SWC

* Exclude eval-worker.js from build

* Fix snaps-utils entry fields

* Update snap shasums

* Use latest version of @swc/core

* Fix end-to-end tests

* Output types to `dist/types`

* Build source and types in separate CI job

* Fix `files` property in `package.json`s

* Fix `snap-controllers` exports field

* Remove unused script from snaps-simulator

* Remove outDir from examples

* Add `./` to `create-snap` fields

* Update yarn.lock

* Update more fields for consistency

* Update Yarn constraints

* Update snap shasum
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.

2 participants