Skip to content

Commit 3eba4f4

Browse files
committed
Go back to using file: instead of * for shared in package.json
Update shared/README.md with info on the difference.
1 parent 175d793 commit 3eba4f4

6 files changed

Lines changed: 20 additions & 6 deletions

File tree

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"react-router-dom": "^5.3.3",
1515
"react-use-websocket": "^2.9.1",
1616
"sass": "^1.57.1",
17-
"shared": "*",
17+
"shared": "file:../shared",
1818
"use-sound": "^4.0.1",
1919
"uswds": "^2.13.3"
2020
},

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"sequelize-auto": "^0.5.4",
2626
"sequelize-cli": "^6.4.1",
2727
"sequelize-fixtures": "^1.2.0",
28-
"shared": "*",
28+
"shared": "file:../shared",
2929
"supertest": "^4.0.2",
3030
"supertest-session": "^4.1.0",
3131
"utf-8-validate": "^5.0.9",

shared/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ These files are shared by both the `client` and `server` packages. The `shared`
55
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.
66

77
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.
8+
9+
10+
## Using `*` instead of `file:../shared` doesn't work
11+
12+
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.
13+
14+
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".`
15+
16+
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).
17+
18+
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.)

shared/constants/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exports.DeliveryStatus = require('./DeliveryStatus');
1+
module.exports.DeliveryStatus = require('./DeliveryStatus');

shared/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports = {
2-
...require('./constants'),
3-
...require('./metadata')
1+
module.exports = {
2+
constants: require('./constants'),
3+
metadata: require('./metadata')
44
};

yarn.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,6 +5452,9 @@ setprototypeof@1.2.0:
54525452
resolved "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz"
54535453
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==
54545454

5455+
"shared@file:shared":
5456+
version "0.1.0"
5457+
54555458
shebang-command@^2.0.0:
54565459
version "2.0.0"
54575460
resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz"

0 commit comments

Comments
 (0)