From 48ab2684ca5c4c1c60923e6b6fbd5739528d3a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Melv=C3=A6r?= Date: Wed, 11 Oct 2023 23:07:25 -0700 Subject: [PATCH] fix: exports and config (#83) * fix: clean up types and add module declarations * fix: update lockfile * fix: add prerelease support * chore(release): 2.0.1-beta.1 [skip ci] * fix: include declaration files in build * chore(release): 2.0.1-beta.2 [skip ci] * fix: more typing * chore(release): 2.0.1-beta.3 [skip ci] * remove tsconfig * chore: tidy up * fix: include module declaration in dist * chore(release): 2.0.1-beta.4 [skip ci] * fix: use referenece path to include module * chore(release): 2.0.1-beta.5 [skip ci] * fix: export types * chore(release): 2.0.1-beta.6 [skip ci] * fix: use named export * fix: clean up type files * chore: import order * chore: move to src * chore: adjust to new src folder * fix: simplify example * chore(release): 2.0.1-beta.7 [skip ci] * fix: use mjs for esm * fix: use named export * chore(release): 2.0.1-beta.8 [skip ci] * fix: rename plugin * fix: trying different config * chore(release): 2.0.1-beta.9 [skip ci] * manually copy the dts * fix: add client as peerdep * chore(release): 2.0.1-beta.10 [skip ci] * fix: remove dts from files * chore(release): 2.0.1-beta.11 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.12 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.13 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.14 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.15 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.16 [skip ci] * fix: config fix * chore(release): 2.0.1-beta.17 [skip ci] * fix: try including dts in chain * chore(release): 2.0.1-beta.18 [skip ci] * chore: add jsx to tsconfig * fix: add @types * chore(release): 2.0.1-beta.19 [skip ci] * Revert "chore: add jsx to tsconfig" This reverts commit 4e8e8e82e35fd73456518ffa7db80f9f053d9f7d. * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.20 [skip ci] * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.21 [skip ci] * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.22 [skip ci] * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.23 [skip ci] * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.24 [skip ci] * fix: try env.d.ts strategy * chore(release): 2.0.1-beta.25 [skip ci] * fix: finalize env.d.ts strategy * fix: fix exports * chore(release): 2.0.1-beta.26 [skip ci] * chore(release): 2.0.1-beta.26 [skip ci] * chore: update config * update config * chore: update lock file * fix: use named export --------- Co-authored-by: semantic-release-bot --- apps/example-ssr/astro.config.mjs | 2 +- apps/example/astro.config.mjs | 2 +- package-lock.json | 16 ++++++++++++---- packages/sanity-astro/CHANGELOG.md | 3 +-- packages/sanity-astro/package.json | 13 ++++++------- packages/sanity-astro/src/env.d.ts | 1 + packages/sanity-astro/src/index.ts | 8 ++++---- .../sanity-astro/src/studio/studio-component.tsx | 2 +- packages/sanity-astro/src/studio/studio-route.ts | 2 ++ packages/sanity-astro/tsconfig.json | 12 +++++++----- packages/sanity-astro/vite.config.ts | 2 +- 11 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 packages/sanity-astro/src/env.d.ts create mode 100644 packages/sanity-astro/src/studio/studio-route.ts diff --git a/apps/example-ssr/astro.config.mjs b/apps/example-ssr/astro.config.mjs index 07a5d6c3..11ae6a36 100644 --- a/apps/example-ssr/astro.config.mjs +++ b/apps/example-ssr/astro.config.mjs @@ -1,4 +1,4 @@ -import sanityIntegration from '@sanity/astro' +import { sanityIntegration } from '@sanity/astro' import { defineConfig } from 'astro/config' import vercel from '@astrojs/vercel/serverless'; import react from '@astrojs/react'; diff --git a/apps/example/astro.config.mjs b/apps/example/astro.config.mjs index ddb3e3a6..50cca0e8 100644 --- a/apps/example/astro.config.mjs +++ b/apps/example/astro.config.mjs @@ -1,4 +1,4 @@ -import sanityIntegration from "@sanity/astro"; +import { sanityIntegration } from "@sanity/astro"; import { defineConfig } from "astro/config"; import react from '@astrojs/react'; import vercel from '@astrojs/vercel/serverless'; diff --git a/package-lock.json b/package-lock.json index b0c8abcf..d07c903d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3959,9 +3959,9 @@ "license": "ISC" }, "node_modules/ci-info": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", - "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", + "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", "funding": [ { "type": "github", @@ -10596,6 +10596,14 @@ "node": ">=8" } }, + "node_modules/pkg-dir/node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/pluralize-esm": { "version": "9.0.5", "license": "MIT", @@ -14891,7 +14899,7 @@ }, "packages/sanity-astro": { "name": "@sanity/astro", - "version": "2.1.1", + "version": "2.0.1-beta.26", "license": "MIT", "dependencies": { "@sanity/client": "^6.4.12", diff --git a/packages/sanity-astro/CHANGELOG.md b/packages/sanity-astro/CHANGELOG.md index c6897de1..14652d82 100644 --- a/packages/sanity-astro/CHANGELOG.md +++ b/packages/sanity-astro/CHANGELOG.md @@ -7,10 +7,9 @@ All notable changes to this project will be documented in this file. See ## [2.1.1](https://github.com/sanity-io/sanity-astro/compare/v2.1.0...v2.1.1) (2023-10-04) - ### Bug Fixes -* **ci:** replace semantic-release with release-please ([fe20b74](https://github.com/sanity-io/sanity-astro/commit/fe20b7410b7f5837fad041b78b09a35229e95f51)) +- **ci:** replace semantic-release with release-please ([fe20b74](https://github.com/sanity-io/sanity-astro/commit/fe20b7410b7f5837fad041b78b09a35229e95f51)) ## [2.1.0](https://github.com/sanity-io/sanity-astro/compare/v2.0.0...v2.1.0) (2023-10-03) diff --git a/packages/sanity-astro/package.json b/packages/sanity-astro/package.json index dc31d9d3..4b5b5bc3 100644 --- a/packages/sanity-astro/package.json +++ b/packages/sanity-astro/package.json @@ -10,22 +10,21 @@ }, "files": [ "dist", + "src/studio", "module.d.ts" ], - "type": "module", - "main": "./dist/sanity-astro.mjs", + "module": "./dist/sanity-astro.js", "exports": { ".": { "types": "./dist/types/index.d.ts", - "module": "./dist/sanity-astro.mjs", + "module": "./dist/sanity-astro.js", "default": "./dist/sanity-astro.mjs" }, "./module": "./module.d.ts", "./studio/studio-route.astro": "./dist/studio/studio-route.astro", - "./studio/studio-component": { - "types": "./dist/types/studio/studio-component.d.ts", - "module": "./dist/studio/studio-component.tsx", - "default": "./dist/studio/studio-component.tsx" + "./studio/studio-component.tsx": { + "types": "./src/studio/studio-component.tsx", + "default": "./src/studio/studio-component.tsx" } }, "types": "./dist/types/index.d.ts", diff --git a/packages/sanity-astro/src/env.d.ts b/packages/sanity-astro/src/env.d.ts new file mode 100644 index 00000000..54ad1be9 --- /dev/null +++ b/packages/sanity-astro/src/env.d.ts @@ -0,0 +1 @@ +/// diff --git a/packages/sanity-astro/src/index.ts b/packages/sanity-astro/src/index.ts index a874d985..344e6162 100644 --- a/packages/sanity-astro/src/index.ts +++ b/packages/sanity-astro/src/index.ts @@ -3,7 +3,7 @@ import { vitePluginSanityClient } from "./vite-plugin-sanity-client"; import { vitePluginSanityStudio } from "./vite-plugin-sanity-studio"; import type { ClientConfig } from "@sanity/client"; -export type IntegrationOptions = ClientConfig & { +type IntegrationOptions = ClientConfig & { studioBasePath?: string; }; @@ -11,8 +11,8 @@ const defaultOptions: IntegrationOptions = { apiVersion: "v2023-08-24", }; -export default function sanityIntegration( - options: IntegrationOptions, +export function sanityIntegration( + options: IntegrationOptions ): AstroIntegration { const resolvedOptions = { ...defaultOptions, @@ -49,7 +49,7 @@ export default function sanityIntegration( ` import { sanityClient } from "sanity:client"; globalThis.sanityClient = sanityClient; - `, + ` ); }, }, diff --git a/packages/sanity-astro/src/studio/studio-component.tsx b/packages/sanity-astro/src/studio/studio-component.tsx index 1e812d14..b72097d3 100644 --- a/packages/sanity-astro/src/studio/studio-component.tsx +++ b/packages/sanity-astro/src/studio/studio-component.tsx @@ -8,7 +8,7 @@ import { Studio } from "sanity"; if (!config) { throw new Error( - "[@sanity/astro]: Can't load Sanity Studio. Check that you've configured it in `sanity.config.js|ts`.", + "[@sanity/astro]: Can't load Sanity Studio. Check that you've configured it in `sanity.config.js|ts`." ); } diff --git a/packages/sanity-astro/src/studio/studio-route.ts b/packages/sanity-astro/src/studio/studio-route.ts new file mode 100644 index 00000000..69730bce --- /dev/null +++ b/packages/sanity-astro/src/studio/studio-route.ts @@ -0,0 +1,2 @@ +import StudioRoute from "./studio-route.astro"; +export default StudioRoute; diff --git a/packages/sanity-astro/tsconfig.json b/packages/sanity-astro/tsconfig.json index ef3549fa..db11b820 100644 --- a/packages/sanity-astro/tsconfig.json +++ b/packages/sanity-astro/tsconfig.json @@ -1,15 +1,17 @@ { + "extends": "astro/tsconfigs/base", "$schema": "https://json.schemastore.org/tsconfig", - "include": ["src/**/*"], - "exclude": ["node_modules/*", "./vite*.ts", "dist", "studio"], + "include": ["./*.astro", "./**/*.ts"], + "exclude": ["node_modules/*", "./vite*.ts", "dist"], "compilerOptions": { - "skipLibCheck": true, - // Enable top-level await, and other modern ESM features. "target": "ESNext", "module": "ESNext", "moduleResolution": "node", "esModuleInterop": true, "baseUrl": "src", + "outDir": "./dist", + "declaration": true, + "declarationDir": "./dist", "jsx": "preserve" } -} \ No newline at end of file +} diff --git a/packages/sanity-astro/vite.config.ts b/packages/sanity-astro/vite.config.ts index f51a99ae..613a5158 100644 --- a/packages/sanity-astro/vite.config.ts +++ b/packages/sanity-astro/vite.config.ts @@ -10,7 +10,7 @@ export default defineConfig(() => { build: { lib: { entry: [path.resolve(__dirname, "src/index.ts")], - name: "sanityAstro", + name, fileName: (format) => (format === "es" ? `${name}.mjs` : `${name}.js`), }, },