Skip to content
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

fix: new build import bugs and types noop #91

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-bags-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-integration-kit": patch
---

Fixes runtime error when importing the new DB type extension
5 changes: 5 additions & 0 deletions .changeset/short-rice-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-integration-kit": patch
---

Fixes ESM import resolution after new build step
3 changes: 2 additions & 1 deletion package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"default": "./dist/plugins/index.js"
},
"./types/db": {
"types": "./types/db.d.ts"
"types": "./types/db.d.ts",
"default": "./types/noop.js"
}
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion package/src/utilities/add-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dirname, relative } from "node:path";
import { fileURLToPath } from "node:url";
import type { AstroIntegrationLogger } from "astro";
import { parse, prettyPrint } from "recast";
import typescriptParser from "recast/parsers/typescript";
import typescriptParser from "recast/parsers/typescript.js";

const injectEnvDTS = ({
srcDir,
Expand Down
2 changes: 1 addition & 1 deletion package/src/utilities/inject-dev-route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InjectedRoute } from "astro";
import type { HookParameters } from "../core/types";
import type { HookParameters } from "../core/types.js";

type HookParameterProperties = Pick<
HookParameters<"astro:config:setup">,
Expand Down
2 changes: 2 additions & 0 deletions package/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "astro/tsconfigs/strictest",
"compilerOptions": {
"module": "Node16",
"moduleResolution": "Node16",
"jsx": "preserve"
},
"exclude": ["dist"]
Expand Down
18 changes: 18 additions & 0 deletions package/types/noop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Type-only import is not supported with the nice syntax for modules across packages.
* This requires libraries using the extended types provided by AIK with one of the syntaxes below:
* - `import type {} from 'astro-integration-kit/types/db';` with the empty `{}`
* - `/// <reference types="astro-integration-kit/types/db" />` with the triple-slash directive`
*
* None of those are as nice as simply `import 'astro-integration-kit/types/db';`.
*
* Using the plain import means it will attempt to import a JS file during module resolution,
* which would fail at runtime because the type extensions are only available as types.
*
* As a workaround for that, this file exists. The type extensions are declared in the package.json
* with this file as their runtime counterpart, so the import will succeed and not throw at runtime.
*
* This file is a no-op, it does nothing. It is just a placeholder to make the nice import work.
*
* @see https://discord.com/channels/830184174198718474/1197638002764152843/1220528418035208212
*/
Loading