withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
43.84k stars 2.28k forks source link

Remove resolve package and refactor db & studio exports #11331

Closed bluwy closed 2 days ago

bluwy commented 4 days ago

Changes

We can use require.resolve() instead of the resolve package for resolving.

Also simplifies the resolving of @astrojs/db by hoisting it up so it can be resolved from packages/astro/dist/cli/install-package.js. While we could also install @astrojs/db as a devdep in packages/astro/package.json to fix it, it would however create a cyclic workspace dependency between astro, @astrojs/db, and @astrojs/studio.

In order to simplify the code, I had to tweak the exports condition of @astrojs/db and @astrojs/studio to allow importing ESM from CJS (by require.resolve). This would also unblock a future Node.js feature where you could import ESM from CJS as long as there's no top-level await. In practice, I also find that it's best practice to use the import condition only if you have a corresponding require condition.

Testing

Tested manually in an external project and in one of the fixtures.

Docs

n/a. refactor only. I added a changeset as it removes a dependency (and would like to document this for users)

changeset-bot[bot] commented 4 days ago

🦋 Changeset detected

Latest commit: f1922389bdf5fbd266a2edd080cd7877f254ae7b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR