diff --git a/client/package.json b/client/package.json index ff631095..f409b0db 100644 --- a/client/package.json +++ b/client/package.json @@ -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" }, diff --git a/server/package.json b/server/package.json index a42ad8cf..64666cad 100644 --- a/server/package.json +++ b/server/package.json @@ -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", diff --git a/shared/README.md b/shared/README.md index 4d3910bb..b3d59014 100644 --- a/shared/README.md +++ b/shared/README.md @@ -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.) diff --git a/shared/constants/index.js b/shared/constants/index.js index f22046bb..0777adb3 100644 --- a/shared/constants/index.js +++ b/shared/constants/index.js @@ -1 +1 @@ -exports.DeliveryStatus = require('./DeliveryStatus'); +module.exports.DeliveryStatus = require('./DeliveryStatus'); diff --git a/shared/index.js b/shared/index.js index 14d3d9e9..3f59d233 100644 --- a/shared/index.js +++ b/shared/index.js @@ -1,4 +1,4 @@ -exports = { - ...require('./constants'), - ...require('./metadata') +module.exports = { + constants: require('./constants'), + metadata: require('./metadata') }; diff --git a/yarn.lock b/yarn.lock index 2b43e5fb..f9b9e6e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5452,6 +5452,9 @@ setprototypeof@1.2.0: 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"