summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Aleksander Heintz <alxandr@alxandr.me> 2022-08-25 20:57:11 +0200
committerGravatar GitHub <noreply@github.com> 2022-08-25 14:57:11 -0400
commitfcc36ac908429733b1d9e51caddbc7590f9eeea5 (patch)
tree5ca0d15cdce8a4dc02ba1e8276f40ef154230eea
parent243525b1565385753ae1464c5def0d7de799f906 (diff)
downloadastro-fcc36ac908429733b1d9e51caddbc7590f9eeea5.tar.gz
astro-fcc36ac908429733b1d9e51caddbc7590f9eeea5.tar.zst
astro-fcc36ac908429733b1d9e51caddbc7590f9eeea5.zip
Make astro package play nice with node16 module resolution (#4182)
* Make astro package play nice with node16 module resolution 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. Fixes: #4172 * Add changeset * Reorder export keys * Update paths inside .d.ts files Co-authored-by: Princesseuh <princssdev@gmail.com>
-rw-r--r--.changeset/perfect-melons-wonder.md5
-rw-r--r--packages/astro/astro-jsx.d.ts10
-rw-r--r--packages/astro/env.d.ts6
-rw-r--r--packages/astro/package.json11
-rw-r--r--packages/astro/tsconfig.json2
5 files changed, 21 insertions, 13 deletions
diff --git a/.changeset/perfect-melons-wonder.md b/.changeset/perfect-melons-wonder.md
new file mode 100644
index 000000000..0c45ce87d
--- /dev/null
+++ b/.changeset/perfect-melons-wonder.md
@@ -0,0 +1,5 @@
+---
+'astro': minor
+---
+
+Make type definitions available through package.json exports
diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts
index bdf6b6aa2..27a37bd42 100644
--- a/packages/astro/astro-jsx.d.ts
+++ b/packages/astro/astro-jsx.d.ts
@@ -23,12 +23,12 @@ declare namespace astroHTML.JSX {
children?: Children;
}
- type AstroBuiltinProps = import('./dist/types/@types/astro').AstroBuiltinProps;
- type AstroBuiltinAttributes = import('./dist/types/@types/astro').AstroBuiltinAttributes;
- type AstroDefineVarsAttribute = import('./dist/types/@types/astro').AstroDefineVarsAttribute;
- type AstroScriptAttributes = import('./dist/types/@types/astro').AstroScriptAttributes &
+ type AstroBuiltinProps = import('./dist/@types/astro').AstroBuiltinProps;
+ type AstroBuiltinAttributes = import('./dist/@types/astro').AstroBuiltinAttributes;
+ type AstroDefineVarsAttribute = import('./dist/@types/astro').AstroDefineVarsAttribute;
+ type AstroScriptAttributes = import('./dist/@types/astro').AstroScriptAttributes &
AstroDefineVarsAttribute;
- type AstroStyleAttributes = import('./dist/types/@types/astro').AstroStyleAttributes &
+ type AstroStyleAttributes = import('./dist/@types/astro').AstroStyleAttributes &
AstroDefineVarsAttribute;
// This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework
diff --git a/packages/astro/env.d.ts b/packages/astro/env.d.ts
index 4b6ce7750..a579d78ce 100644
--- a/packages/astro/env.d.ts
+++ b/packages/astro/env.d.ts
@@ -1,6 +1,6 @@
/// <reference path="./client.d.ts" />
-type Astro = import('./dist/types/@types/astro').AstroGlobal;
+type Astro = import('./dist/@types/astro').AstroGlobal;
// We duplicate the description here because editors won't show the JSDoc comment from the imported type (but will for its properties, ex: Astro.request will show the AstroGlobal.request description)
/**
@@ -13,7 +13,7 @@ declare const Astro: Readonly<Astro>;
declare const Fragment: any;
declare module '*.md' {
- type MD = import('./dist/types/@types/astro').MarkdownInstance<Record<string, any>>;
+ type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
export const frontmatter: MD['frontmatter'];
export const file: MD['file'];
@@ -30,7 +30,7 @@ declare module '*.md' {
}
declare module '*.mdx' {
- type MDX = import('astro').MDXInstance<Record<string, any>>;
+ type MDX = import('./dist/@types/astro').MDXInstance<Record<string, any>>;
export const frontmatter: MDX['frontmatter'];
export const file: MDX['file'];
diff --git a/packages/astro/package.json b/packages/astro/package.json
index 711b8edf0..d674ef69e 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -12,19 +12,22 @@
},
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build",
- "types": "./dist/types/@types/astro.d.ts",
+ "types": "./dist/@types/astro.d.ts",
"typesVersions": {
"*": {
"app": [
- "./dist/types/core/app/index"
+ "./dist/core/app/index"
],
"app/*": [
- "./dist/types/core/app/*"
+ "./dist/core/app/*"
]
}
},
"exports": {
- ".": "./astro.js",
+ ".": {
+ "types": "./dist/@types/astro.d.ts",
+ "default": "./astro.js"
+ },
"./env": "./env.d.ts",
"./client": "./client.d.ts",
"./client-base": "./client-base.d.ts",
diff --git a/packages/astro/tsconfig.json b/packages/astro/tsconfig.json
index 58e865c0c..a51690d2a 100644
--- a/packages/astro/tsconfig.json
+++ b/packages/astro/tsconfig.json
@@ -3,7 +3,7 @@
"include": ["src", "index.d.ts"],
"compilerOptions": {
"allowJs": true,
- "declarationDir": "./dist/types",
+ "declarationDir": "./dist",
"module": "ES2020",
"outDir": "./dist",
"target": "ES2020",