Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

chore/build-as-ESM #90

Closed
wants to merge 4 commits into from

Conversation

jenbutongit
Copy link

Hi!

xgov-form-builder is a project we're working on. Essentially it's a react app "designer", which spits out a JSON which allows the "runner" to play the config as a live service. The designer was not as actively worked on, but we're on it now 👷🏻‍♀️. We'd like to consume this package but we had some issues with importing and our build/test process.

Description

Currently, the build process is building in cjs (node-compatible) format. Since its react -- web, ESM is fine (import/export syntax). For any compilers that are ESM aware, it will use the module entry-point instead.

  • compile for ESM
    • compiling into module
    • script is in package.json
    • I'm ignoring any storybook stuff. We just want to consume the components!
  • added entrypoint for ESM in package.json ("module" key)
  • removing circular dependencies
    • by doing import/require '../..' you end up importing everything in the index. This way you end up with circular deps. I'm doing exact imports instead
  • publish script
    • I've changed the publish script to publish root, but added npm ignore to everything that's not dist or module
      • now that root is published, you can forgo doing cp of readme etc. I've left it in just in case you need them here though.
    • changed entry-point of "main" to dist/govuk/index.js
  • version bump to 4.0.4 :)

We have tested this by installing on our own fork. looks good to us!

…hed commit)

Squashed commits:
[2fb8089] use exact imports. build for ESM. ignores
@andymantell
Copy link
Collaborator

Thanks @jenbutongit, this sounds great. I will try and digest what you've done over the coming days - provisionally I'm happy with the ideas here but I need to make sure it plays well with the govuk-react-jsx-examples repository for instance (Basically vanilla create-react-app). And of course fix the tests etc. I wonder if this might wind up being a major version bump instead of a minor, but I need to get my head back into the right headspace and work out what you've done!

Are you ok running from your fork in the interim?

@jenbutongit
Copy link
Author

Hey Andy -- no probs. (I've just broken something so don't worry just yet..!). Hopefully this shouldn't change how people are currently using the library. If they need to use the CJS modules, they can do so by changing their compiler options. If you're already using react with webpack or rollup, you shouldn't have to worry.

@andymantell
Copy link
Collaborator

Regarding publishing root - the reason for not doing this was that I have a different package.json setup for the published package, whereby the main deps are listed as peerDependencies instead of dependencies. I think we probably need that back how it was.

What I'll do next week is to drop this onto govuk-react-jsx-examples and if it "just works" then I think we'll be good to go (plus pesky tests).

@andymantell andymantell self-assigned this Oct 2, 2020
@jenbutongit
Copy link
Author

sgtm. in any case, thanks for the library!!

@andymantell
Copy link
Collaborator

@jenbutongit I'm probably going to merge this to another branch for the meantime so I can sort out the tests and tweak package structure without affecting your fork. Can you send me a link to the appropriate repository+branch of your project so I can test the result against your code? Or if that's not possible, a minimal repository with the same build setup would be fine. Thanks.

@jenbutongit
Copy link
Author

sorry -- we're still working through a few things. I will let you know ASAP!

@andymantell
Copy link
Collaborator

@jenbutongit That's ok - I'm flat out on something else at the moment anyway so if it's not blocking you then we can work through this at an appropriate pace.

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

Successfully merging this pull request may close these issues.

2 participants