astro icon indicating copy to clipboard operation
astro copied to clipboard

Make astro package play nice with node16 module resolution

Open Alxandr opened this issue 3 years ago • 2 comments

Projects using node16 module resolution in typescript uses the new exports and imports configuration from typescript to find definition files. This mirrors how nodejs resolves the files. If a package contains an exports map in the package.json, typescript will ignore the "types" field (not sure how it plays with typesVersions). This moves the typings hirearchy of definition files into the same hierarchy that astro produces output files in, so that typescript can discover them.

Changes

Projects using node16 module resolution in typescript uses the new exports and imports configuration from typescript to find definition files. This mirrors how nodejs resolves the files. If a package contains an exports map in the package.json, typescript will ignore the "types" field (not sure how it plays with typesVersions). This moves the typings hirearchy of definition files into the same hierarchy that astro produces output files in, so that typescript can discover them.

Testing

I've used pnpm link locally to do import type { AstroIntegration } from 'astro'; - it does not work if I just use the astro package from NPM.

Docs

This should only be visible in that people who use the new module resolution can now get typings - and also, the file hierarchy of the dist folder in the package is modified in that type-declarations now live next to their js counterparts.

Fixes: #4172

Alxandr avatar Aug 06 '22 08:08 Alxandr

🦋 Changeset detected

Latest commit: 0714a8e21087ed8e96f95ebd18bd9fc50e520513

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

This PR includes changesets to release 14 packages
Name Type
astro Minor
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/hydration-race Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

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

changeset-bot[bot] avatar Aug 06 '22 08:08 changeset-bot[bot]

This all makes sense to me! Thanks for the investigation and the thorough PR.

As Nate said in the issue I’d also want a +1 from out resident TS expert @Princesseuh before merging.

FredKSchott avatar Aug 06 '22 14:08 FredKSchott

I'm working around the issue of astro-files not caring about node16 by moving code to .tsm files and just importing them in astro-files - and for the most part that works (though it's definitely been less than optimal). I'm assuming the greater ecosystem will eventually migrate most of the things to work with node16, but it will definitely take time.

Alxandr avatar Aug 10 '22 11:08 Alxandr

This is marked as being a minor release, so it can go out the next time we do one of those.

matthewp avatar Aug 23 '22 12:08 matthewp