Skip to content

Commit 04fc1a1

Browse files
authored
Use Vite plugin type and return minimal version (#2672)
Ths change uses the Vite plugin type to annotate the Rollup plugin internally. This means that we get full type checking support for the implementation. However, the return type is annotated as our very minimal plugin type. This way it’s compatible with Rollup, Vite, and Rolldown, but we don’t need a dependency on Rollup. `@rollup/pluginutils` has an optional peer dependency on `rollup`, but it’s not actually used. So it can be removed now. Closes #2671
1 parent cc0da8e commit 04fc1a1

3 files changed

Lines changed: 6 additions & 37 deletions

File tree

package-lock.json

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rollup/lib/index.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @import {FormatAwareProcessors} from '@mdx-js/mdx/internal-create-format-aware-processors'
33
* @import {CompileOptions} from '@mdx-js/mdx'
44
* @import {FilterPattern} from '@rollup/pluginutils'
5-
* @import {SourceDescription} from 'rollup'
5+
* @import * as vite from 'vite'
66
*/
77

88
/**
@@ -23,33 +23,6 @@
2323
* Plugin that is compatible with both Rollup and Vite.
2424
* @property {string} name
2525
* The name of the plugin
26-
* @property {ViteConfig} config
27-
* Function used by Vite to set additional configuration options.
28-
* @property {Transform} transform
29-
* Function to transform the source content.
30-
*
31-
* @callback Transform
32-
* Callback called by Rollup and Vite to transform.
33-
* @param {string} value
34-
* File contents.
35-
* @param {string} id
36-
* Module ID.
37-
* @returns {Promise<SourceDescription | undefined>}
38-
* Result.
39-
*
40-
* @callback ViteConfig
41-
* Callback called by Vite to set additional configuration options.
42-
* @param {unknown} config
43-
* Configuration object (unused).
44-
* @param {ViteEnv} env
45-
* Environment variables.
46-
* @returns {undefined}
47-
* Nothing.
48-
*
49-
* @typedef ViteEnv
50-
* Environment variables used by Vite.
51-
* @property {string} mode
52-
* Mode.
5326
*/
5427

5528
import {createFormatAwareProcessors} from '@mdx-js/mdx/internal-create-format-aware-processors'
@@ -71,7 +44,8 @@ export function rollup(options) {
7144
let formatAwareProcessors
7245
const filter = createFilter(include, exclude)
7346

74-
return {
47+
/** @type {vite.Plugin<unknown>} */
48+
const plugin = {
7549
name: '@mdx-js/rollup',
7650
config(config, env) {
7751
formatAwareProcessors = createFormatAwareProcessors({
@@ -102,4 +76,6 @@ export function rollup(options) {
10276
}
10377
}
10478
}
79+
80+
return plugin
10581
}

packages/rollup/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@
6363
"source-map": "^0.7.0",
6464
"vfile": "^6.0.0"
6565
},
66-
"peerDependencies": {
67-
"rollup": ">=2"
68-
},
69-
"devDependencies": {},
7066
"scripts": {
7167
"test": "npm run test-coverage",
7268
"test-api": "node --conditions development test/index.js",

0 commit comments

Comments
 (0)