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

feat: Bump minimal version of Astro to 4.12 #115

Merged
merged 6 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 26 additions & 0 deletions .changeset/twelve-coins-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
"astro-integration-kit": minor
---

Bump the minimal version of Astro to 4.12
Fryuni marked this conversation as resolved.
Show resolved Hide resolved

- Removed the `AstroIntergation.ExtraHooks` workaround for extending hooks in favor of the native `Astro.IntegrationHooks` extendable interface.
Fryuni marked this conversation as resolved.
Show resolved Hide resolved

```diff
-namespace AstroIntergationKit {
Fryuni marked this conversation as resolved.
Show resolved Hide resolved
- interface ExtraHooks {
+namespace Astro {
+ interface IntegrationHooks {
'myLib:myHook': (params: { foo: string }) => Promise<void>;
}
}
```

- Removed the `HookParameters` type that combined the native types and the workaround above. The native `HookParameters` should be used now:
Fryuni marked this conversation as resolved.
Show resolved Hide resolved

```diff
- import type { HookParameters } from 'astro-integration-kit';
+ import type { HookParameters } from 'astro';
```

- Fixes the typing of `defineUtility` to not cause transitive dependency on non-portble Astro types when building libraries with type declarations.
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/starlight": "^0.22.4",
"@astrojs/starlight": "^0.25.1",
"@expressive-code/plugin-line-numbers": "^0.35.3",
"astro": "^4.8.6",
"astro": "^4.12.1",
"sharp": "^0.33.4"
},
"devDependencies": {
"@astrojs/check": "^0.7.0",
"@astrojs/check": "^0.8.2",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"packageManager": "pnpm@9.1.1",
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903",
"engines": {
"node": ">=18.19.0"
},
Expand Down
12 changes: 1 addition & 11 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
"types": "./dist/plugins/index.d.ts",
"default": "./dist/plugins/index.js"
},
"./types/db": {
"types": "./types/db.d.ts",
"default": "./types/noop.js"
},
"./dev": {
"types": "./dist/dev/index.d.ts",
"default": "./dist/dev/index.js"
Expand All @@ -48,13 +44,7 @@
},
"type": "module",
"peerDependencies": {
"@astrojs/db": "^0.9 || ^0.10 || ^0.11",
"astro": "^4.4.1"
},
"peerDependenciesMeta": {
"@astrojs/db": {
"optional": true
}
"astro": "^4.12.0"
},
"devDependencies": {
"@types/node": "^20.12.12",
Expand Down
7 changes: 4 additions & 3 deletions package/src/core/define-utility.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { HookParameters, Hooks } from "./types.js";
import type { HookParameters } from "astro";
import type { Hooks } from "./types.js";

/**
* Allows defining a type-safe function requiring all the params of a given hook.
Expand All @@ -21,7 +22,7 @@ export const defineUtility =
* The function itself
* @param {Function} fn;
*/
<TFn extends (params: HookParameters<THook>, ...args: Array<any>) => any>(
fn: TFn,
<TArgs extends Array<any>, T>(
fn: (params: HookParameters<THook>, ...args: TArgs) => T,
) =>
fn;
14 changes: 1 addition & 13 deletions package/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,7 @@ export type Plugin<
// To avoid having to call this manually for every generic
export type AnyPlugin = Plugin<string, Record<string, any>>;

declare global {
namespace AstroIntegrationKit {
// biome-ignore lint/suspicious/noEmptyInterface: Requires for interface merging
export interface ExtraHooks {}
}
}

export type Hooks = Prettify<
Required<NonNullable<import("astro").AstroIntegration["hooks"]>> &
AstroIntegrationKit.ExtraHooks
>;

export type HookParameters<T extends keyof Hooks> = Parameters<Hooks[T]>[0];
export type Hooks = Required<Astro.IntegrationHooks>;

type AnyFunction = (...args: Array<any>) => any;

Expand Down
10 changes: 2 additions & 8 deletions package/src/core/with-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { AstroIntegration } from "astro";
import type { AstroIntegration, HookParameters } from "astro";
import type { NonEmptyArray, Prettify } from "../internal/types.js";
import type {
AddedParam,
AnyPlugin,
ExtendedHooks,
HookParameters,
Hooks,
} from "./types.js";
import type { AddedParam, AnyPlugin, ExtendedHooks, Hooks } from "./types.js";

type WithPluginsParams<TPlugins extends NonEmptyArray<AnyPlugin>> = {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion package/tests/unit/watch-directory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import type { HookParameters } from "astro";
import { dirname, normalize } from "pathe";
import type { Plugin } from "vite";
import {
Expand All @@ -11,7 +12,6 @@ import {
vi,
} from "vitest";
import { createResolver } from "../../src/core/create-resolver.ts";
import type { HookParameters } from "../../src/core/types.ts";
import { watchDirectory } from "../../src/utilities/watch-directory.ts";

const tempFolderName = ".TMP_WATCHDIRECTORY";
Expand Down
10 changes: 0 additions & 10 deletions package/types/db.d.ts

This file was deleted.

18 changes: 0 additions & 18 deletions package/types/noop.js

This file was deleted.

4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
},
"dependencies": {
"@astrojs/tailwind": "^5.1.0",
"astro": "^4.8.6",
"astro": "^4.12.1",
"astro-integration-kit": "workspace:*",
"tailwindcss": "^3.4.3"
},
"devDependencies": {
"@astrojs/check": "^0.7.0",
"@astrojs/check": "^0.8.2",
"@types/node": "^20.12.12",
"typescript": "^5.4.5",
"vite-plugin-pwa": "^0.19.8"
Expand Down
Loading
Loading