Skip to content

Commit

Permalink
chore: fix plugin types
Browse files Browse the repository at this point in the history
they somehow got broken by updates
  • Loading branch information
wmertens authored and shairez committed Aug 1, 2024
1 parent f5fc443 commit 99296ea
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 100 deletions.
6 changes: 3 additions & 3 deletions packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@
}
],
"kind": "Function",
"content": "```typescript\nexport declare function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqwikViteOpts\n\n\n</td><td>\n\n[QwikVitePluginOptions](#qwikvitepluginoptions)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nany",
"content": "The types for Vite/Rollup don't allow us to be too specific about the return type. The correct return type is `[QwikVitePlugin, VitePlugin<never>]`<!-- -->, and if you search the plugin by name you'll get the `QwikVitePlugin`<!-- -->.\n\n\n```typescript\nexport declare function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqwikViteOpts\n\n\n</td><td>\n\n[QwikVitePluginOptions](#qwikvitepluginoptions)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nany",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts",
"mdFile": "qwik.qwikvite.md"
},
Expand All @@ -483,8 +483,8 @@
"id": "qwikviteplugin"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface QwikVitePlugin \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[api](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikVitePluginApi](#qwikvitepluginapi)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[name](#)\n\n\n</td><td>\n\n\n</td><td>\n\n'vite-plugin-qwik'\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"kind": "TypeAlias",
"content": "This is the type of the \"pre\" Qwik Vite plugin. `qwikVite` actually returns a tuple of two plugins, but after Vite flattens them, you can find the plugin by name.\n\n\n```typescript\nexport type QwikVitePlugin = P<QwikVitePluginApi> & {\n name: 'vite-plugin-qwik';\n};\n```\n**References:** [QwikVitePluginApi](#qwikvitepluginapi)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts",
"mdFile": "qwik.qwikviteplugin.md"
},
Expand Down
53 changes: 8 additions & 45 deletions packages/docs/src/routes/api/qwik-optimizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,8 @@ string \| null

## qwikVite

The types for Vite/Rollup don't allow us to be too specific about the return type. The correct return type is `[QwikVitePlugin, VitePlugin<never>]`, and if you search the plugin by name you'll get the `QwikVitePlugin`.

```typescript
export declare function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;
```
Expand Down Expand Up @@ -2215,54 +2217,15 @@ _(Optional)_

## QwikVitePlugin

This is the type of the "pre" Qwik Vite plugin. `qwikVite` actually returns a tuple of two plugins, but after Vite flattens them, you can find the plugin by name.

```typescript
export interface QwikVitePlugin
export type QwikVitePlugin = P<QwikVitePluginApi> & {
name: "vite-plugin-qwik";
};
```

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead>
<tbody><tr><td>

[api](#)

</td><td>

</td><td>

[QwikVitePluginApi](#qwikvitepluginapi)

</td><td>

</td></tr>
<tr><td>

[name](#)

</td><td>

</td><td>

'vite-plugin-qwik'

</td><td>

</td></tr>
</tbody></table>
**References:** [QwikVitePluginApi](#qwikvitepluginapi)

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts)

Expand Down
6 changes: 3 additions & 3 deletions packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"@mdx-js/mdx": "^3.0.1",
"@types/mdx": "^2.0.13",
"source-map": "^0.7.4",
"svgo": "^3.2.0",
"svgo": "3.3.2",
"undici": "*",
"vfile": "6.0.1",
"vite": "^5.2.10",
"vite-imagetools": "^6.2.9",
"vite": "5.3.4",
"vite-imagetools": "7.0.4",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/adapters/shared/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const STATIC_PATHS_ID = "@qwik-city-static-paths";
// Warning: (ae-forgotten-export) The symbol "ViteAdapterPluginOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function viteAdapter(opts: ViteAdapterPluginOptions): Plugin_2<any>;
export function viteAdapter(opts: ViteAdapterPluginOptions): Plugin_2<never>;

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/adapters/shared/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function viteAdapter(opts: ViteAdapterPluginOptions) {
let format = 'esm';
const outputEntries: string[] = [];

const plugin: Plugin = {
const plugin: Plugin<never> = {
name: `vite-plugin-qwik-city-${opts.name}`,
enforce: 'post',
apply: 'build',
Expand Down
10 changes: 5 additions & 5 deletions packages/qwik-city/src/buildtime/vite/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { BuiltinsWithOptionalParams } from 'svgo/plugins/plugins-types';
import type { CompileOptions } from '@mdx-js/mdx';
import type { Config } from 'svgo';
import { ConfigEnv } from 'vite';
import type { Plugin as Plugin_2 } from 'vite';
import type { PluginOption } from 'vite';
import { UserConfigExport } from 'vite';

Expand All @@ -20,12 +21,11 @@ export type MdxOptions = CompileOptions;
// @public (undocumented)
export function qwikCity(userOpts?: QwikCityVitePluginOptions): PluginOption[];

// Warning: (ae-forgotten-export) The symbol "P" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "QwikCityPluginApi" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export interface QwikCityPlugin {
// Warning: (ae-forgotten-export) The symbol "QwikCityPluginApi" needs to be exported by the entry point index.d.ts
//
// (undocumented)
api: QwikCityPluginApi;
export interface QwikCityPlugin extends P<QwikCityPluginApi> {
// (undocumented)
name: 'vite-plugin-qwik-city';
}
Expand Down
4 changes: 3 additions & 1 deletion packages/qwik-city/src/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
},
};

const plugin: Plugin = {
type P<T> = Plugin<T> & { api: T };

const plugin: P<QwikCityPluginApi> = {
name: 'vite-plugin-qwik-city',
enforce: 'pre',
api,
Expand Down
6 changes: 4 additions & 2 deletions packages/qwik-city/src/buildtime/vite/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { MdxTransform } from '../markdown/mdx';
import type { BuildContext, BuildEntry, BuildRoute, PluginOptions, MdxPlugins } from '../types';
import type { Config as SVGOConfig } from 'svgo';
import type { BuiltinsWithOptionalParams as SVGOBuiltinPluginsWithOptionalParams } from 'svgo/plugins/plugins-types';
import type { Plugin as VitePlugin } from 'vite';

/** @public */
export interface ImageOptimizationOptions {
Expand Down Expand Up @@ -39,10 +40,11 @@ export interface PluginContext {
mdxTransform: MdxTransform | null;
}

type P<T> = VitePlugin<T> & { api: T };

/** @public */
export interface QwikCityPlugin {
export interface QwikCityPlugin extends P<QwikCityPluginApi> {
name: 'vite-plugin-qwik-city';
api: QwikCityPluginApi;
}

/** @public */
Expand Down
10 changes: 5 additions & 5 deletions packages/qwik-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"license": "MIT",
"main": "./lib/index.qwik.mjs",
"peerDependencies": {
"@builder.io/qwik": "workspace:^",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"@builder.io/qwik": "1.7.3",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"qwik": "./lib/index.qwik.mjs",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"license": "MIT",
"main": "./lib/index.qwik.mjs",
"peerDependencies": {
"@builder.io/qwik": "workspace:^"
"@builder.io/qwik": "1.7.3"
},
"qwik": "./lib/index.qwik.mjs",
"repository": {
Expand Down
15 changes: 8 additions & 7 deletions packages/qwik/src/optimizer/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
```ts

import type { Plugin as Plugin_2 } from 'vite';

// @public (undocumented)
export interface ComponentEntryStrategy {
// (undocumented)
Expand Down Expand Up @@ -285,7 +287,7 @@ export interface QwikSymbol {
parent: string | null;
}

// @public (undocumented)
// @public
export function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;

// @public (undocumented)
Expand All @@ -296,13 +298,12 @@ export interface QwikViteDevResponse {
_qwikRenderResolve?: () => void;
}

// @public (undocumented)
export interface QwikVitePlugin {
// (undocumented)
api: QwikVitePluginApi;
// (undocumented)
// Warning: (ae-forgotten-export) The symbol "P" needs to be exported by the entry point index.d.ts
//
// @public
export type QwikVitePlugin = P<QwikVitePluginApi> & {
name: 'vite-plugin-qwik';
}
};

// @public (undocumented)
export interface QwikVitePluginApi {
Expand Down
10 changes: 8 additions & 2 deletions packages/qwik/src/optimizer/src/plugins/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
QwikManifest,
TransformModuleInput,
TransformModule,
Optimizer,
} from '../types';
import {
createPlugin,
Expand All @@ -18,6 +19,11 @@ import {
} from './plugin';
import { versions } from '../versions';

type QwikRollupPluginApi = {
getOptimizer: () => Optimizer;
getOptions: () => NormalizedQwikPluginOptions;
};

/** @public */
export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
const qwikPlugin = createPlugin(qwikRollupOpts.optimizerOptions);
Expand Down Expand Up @@ -323,5 +329,5 @@ export interface QwikRollupPluginOptions {
*/
lint?: boolean;
}

export interface QwikRollupPlugin extends Rollup.Plugin {}
type P<T> = Rollup.Plugin<T> & { api: T };
export interface QwikRollupPlugin extends P<QwikRollupPluginApi> {}
31 changes: 24 additions & 7 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,20 @@ const DEDUPE = [QWIK_CORE_ID, QWIK_JSX_RUNTIME_ID, QWIK_JSX_DEV_RUNTIME_ID];
const STYLING = ['.css', '.scss', '.sass', '.less', '.styl', '.stylus'];
const FONTS = ['.woff', '.woff2', '.ttf'];

/** @public */
/**
* Workaround to make the api be defined in the type.
*
* @internal
*/
type P<T> = VitePlugin<T> & { api: T; config: Extract<VitePlugin<T>['config'], Function> };

/**
* The types for Vite/Rollup don't allow us to be too specific about the return type. The correct
* return type is `[QwikVitePlugin, VitePlugin<never>]`, and if you search the plugin by name you'll
* get the `QwikVitePlugin`.
*
* @public
*/
export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
let isClientDevOnly = false;
let clientDevInput: undefined | string = undefined;
Expand Down Expand Up @@ -91,7 +104,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
// Vite hooks. The second plugin is a post plugin that is called after the build has finished.
// The post plugin is used to generate the Qwik manifest file that is used during SSR to
// generate QRLs for event handlers.
const vitePluginPre: VitePlugin = {
const vitePluginPre: P<QwikVitePluginApi> = {
name: 'vite-plugin-qwik',
enforce: 'pre',
api,
Expand Down Expand Up @@ -478,7 +491,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
},
};

const vitePluginPost: VitePlugin = {
const vitePluginPost: VitePlugin<never> = {
name: 'vite-plugin-qwik-post',
enforce: 'post',

Expand Down Expand Up @@ -1062,11 +1075,15 @@ export interface QwikVitePluginApi {
getAssetsDir: () => string | undefined;
}

/** @public */
export interface QwikVitePlugin {
/**
* This is the type of the "pre" Qwik Vite plugin. `qwikVite` actually returns a tuple of two
* plugins, but after Vite flattens them, you can find the plugin by name.
*
* @public
*/
export type QwikVitePlugin = P<QwikVitePluginApi> & {
name: 'vite-plugin-qwik';
api: QwikVitePluginApi;
}
};

/** @public */
export interface QwikViteDevResponse {
Expand Down
Loading

0 comments on commit 99296ea

Please sign in to comment.