Skip to content

Commit

Permalink
Go back to using file: instead of * for shared in package.json
Browse files Browse the repository at this point in the history
Update shared/README.md with info on the difference.
  • Loading branch information
fwextensions committed Mar 24, 2023
1 parent 175d793 commit 3eba4f4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react-router-dom": "^5.3.3",
"react-use-websocket": "^2.9.1",
"sass": "^1.57.1",
"shared": "*",
"shared": "file:../shared",
"use-sound": "^4.0.1",
"uswds": "^2.13.3"
},
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"sequelize-auto": "^0.5.4",
"sequelize-cli": "^6.4.1",
"sequelize-fixtures": "^1.2.0",
"shared": "*",
"shared": "file:../shared",
"supertest": "^4.0.2",
"supertest-session": "^4.1.0",
"utf-8-validate": "^5.0.9",
Expand Down
11 changes: 11 additions & 0 deletions shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ These files are shared by both the `client` and `server` packages. The `shared`
If you want to make a change in the shared code and then test it the client or server, run `yarn upgrade shared` from the root `/app` directory in the docker instance. This should cause yarn to copy the latest files from the `shared` package to the root `/node_modules/shared/` directory that's used by the client and server.

If you're making lots of changes to `shared` and want to quickly test them, using [`yarn link`](https://classic.yarnpkg.com/lang/en/docs/cli/link/) may be easier.


## Using `*` instead of `file:../shared` doesn't work

In theory, you should be able to add the `shared` package to others in the monorepo by adding `"shared": "*"` to their `package.json` files. This would link the package, so that any changes to `shared` would immediately be available in the other packages.

But using `*` instead of `file:../shared` causes a Rollup error during the build: `RollupError: "DeliveryStatus" is not exported by "../shared/constants/index.js", imported by "src/Models/Ringdown.js".`

This seems to be related to the fact that the `shared` package is in CJS format and has to get optimized during the dev serving process, thanks to the `optimizeDeps.include` array in the Vite config. But that during doesn't work during build, and various attempts at changing the `build.commonjsOptions` flags haven't worked. It also seems to be related to [this Vite bug](https://github.com/vitejs/vite/issues/2679).

So it seems simplest to use the `file:` format for specifying the version of `shared` for now, until it can get rewritten as an ES module. (Also note that you have to re-run yarn after making changes to the package.json file; otherwise things may look like they're working, even though they won't during CI/CD.)
2 changes: 1 addition & 1 deletion shared/constants/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.DeliveryStatus = require('./DeliveryStatus');
module.exports.DeliveryStatus = require('./DeliveryStatus');
6 changes: 3 additions & 3 deletions shared/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports = {
...require('./constants'),
...require('./metadata')
module.exports = {
constants: require('./constants'),
metadata: require('./metadata')
};
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5452,6 +5452,9 @@ [email protected]:
resolved "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==

"shared@file:shared":
version "0.1.0"

shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz"
Expand Down

0 comments on commit 3eba4f4

Please sign in to comment.