Skip to content

refactor: Migrate monorepo to ESM, make various tweaks #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

rekmarks
Copy link
Member

@rekmarks rekmarks commented Aug 7, 2024

Extracted from #11
Requires #13
Unblocks #16

In the course of implementing #11, I made various changes to the monorepo that I deemed either necessary or simply beneficial. Here these changes are extracted from #11, which has been separated into this PR and #16. Contains the following changes:

  • Upgrade ts-bridge and migrate all packages to ESM
    • In the course of implementing feat: Introduce streams package #11, I ran into a TypeScript project references-related error, because ts-bridge originally did not support this feature. However, ts-bridge recently added support for project references, and updating fixed the problem.
    • This, however, necessitated migrating all monorepo packages to be ESM-first ("type": "module"), and setting TypeScript's moduleResolution algorithm to Node16. So, now the entire monorepo is ESM-first, but any libraries we publish will still be importable in CommonJS, due to ts-bridge.
    • As part of this change, .js files were renamed to .cjs, and .mjs files to .js. The same goes for their .ts equivalents.
      • A notable exception includes the published files in @ocap/shims, which retain their .mjs extensions as a redundancy measure.
  • Fix intra-repo path resolution in tests
    • In the /snaps and /core monorepos, Jest's moduleNameMapper option is manually configured to match the paths property in tsconfig.json to ensure that tests use source code as opposed to build outputs.
    • In vite, we accomplish the same by dropping in the plugin vite-tsconfig-paths, with no additional configuration whatsoever.
  • Add internal test-utils package
    • Rather than keeping a folder of test utilities at the monorepo root, I decided to just create an internal package for this purpose.
  • Set the version of all intra-monorepo dependencies to workspace:^
    • This takes a queue from the Snaps monorepo. In this way, we will never accidentally pull a workspace package from npm.
    • Note that this required stealing some of the Snaps monorepo's constraints for our constraints.pro. However, don't spend too much time on that file, because it will be replaced soon: monorepo: Migrate constraints from Prolog to JavaScript #17
  • Externalize endoify.mjs in extension HTML files
    • Introduces our own tiny vite plugin, endoifyHtmlFilesPlugin, that inserts the endoify.mjs in the correct place just before HTML files are built. vite's aggressive optimization and module resolution logic otherwise prevents us from doing this.
  • Add clean script to all packages
    • After experiencing some issues with cached builds, I decided to make sure every package has a clean script.

Copy link

socket-security bot commented Aug 7, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@ts-bridge/[email protected] None 0 249 kB mrten
npm/@ts-bridge/[email protected] filesystem, unsafe 0 127 kB mrten
npm/[email protected] None 0 14.2 kB terkelg
npm/[email protected] None 0 68.1 kB dominik_g
npm/[email protected] filesystem 0 95.5 kB aleclarson

🚮 Removed packages: npm/@ts-bridge/[email protected], npm/[email protected]

View full report↗︎

This comment was marked as resolved.

@rekmarks rekmarks force-pushed the rekm/monorepo-chores branch from 8947197 to 46600ea Compare August 7, 2024 10:00
@rekmarks
Copy link
Member Author

rekmarks commented Aug 7, 2024

@SocketSecurity ignore npm/[email protected] npm/[email protected]

Due to well-known and widely used dev dependency cheerio.

Base automatically changed from rekm/vitest to main August 7, 2024 15:56
- test: Add internal test-utils package
- chore: Synchronize workspace package dependencies
  - Accomplished by copying over sections of the Snaps monorepo constraints,
    which allow the `workspace:^` dependency version. In this way, we will
    never accidentally pull a workspace package from npm.
- build(extension): Externalize endoify.mjs in HTML files
- refactor: Upgrade ts-bridge and migrate all packages to ESM
- chore: Add "clean" script to all packages
- fix: Fix intra-repo path resolution in tests
  - By means of the plugin `vite-tsconfig-paths`
@rekmarks rekmarks force-pushed the rekm/monorepo-chores branch from 46600ea to c2a46ae Compare August 7, 2024 15:59
@rekmarks rekmarks marked this pull request as ready for review August 7, 2024 16:28
@rekmarks rekmarks requested a review from a team as a code owner August 7, 2024 16:28
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #17, this file will be removed in the near future.

Copy link
Contributor

@SMotaal SMotaal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — I've reviewed the commits and the final changes. I did not spot concerns that would need to be addressed at this point.

Renamed Files

-.eslintrc.js
+.eslintrc.cjs
-.prettierrc.js
+.prettierrc.cjs
 .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
-packages/extension/.eslintrc.js
+packages/extension/.eslintrc.cjs
 packages/extension/src/background.ts
-packages/extension/src/dev-console.mjs
+packages/extension/src/dev-console.js
 packages/extension/src/iframe-manager.test.ts
 packages/extension/src/iframe-manager.ts
 packages/extension/src/iframe.ts
 packages/extension/src/offscreen.ts
 packages/extension/src/shared.test.ts
 packages/extension/src/shared.ts
-packages/extension/vite.config.mts
+packages/extension/vite.config.ts
-packages/extension/vitest.config.mts
+packages/extension/vitest.config.ts
-packages/shims/.eslintrc.js
+packages/shims/.eslintrc.cjs
-packages/shims/scripts/bundle.mjs
+packages/shims/scripts/bundle.js
 packages/shims/src/apply-lockdown.mjs
 packages/shims/src/endoify.mjs
 packages/shims/src/eventual-send.mjs
-packages/shims/vitest.config.mts
+packages/shims/vitest.config.ts
-vitest.config.packages.mjs
+vitest.config.packages.js
+packages/test-utils/src/env/mock-endo.ts
+packages/test-utils/src/index.ts
+packages/test-utils/src/mocks.ts
+packages/test-utils/src/utils.ts

@rekmarks rekmarks merged commit 3af4ff3 into main Aug 9, 2024
20 checks passed
@rekmarks rekmarks deleted the rekm/monorepo-chores branch August 9, 2024 16:01
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