Skip to content

Commit c206e8a

Browse files
committed
fix: use the correct plugins TypeScript types
1 parent 8c3178e commit c206e8a

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

src/main.ts

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
import { includesAny, getPluginFunction } from "./utils"
22

33
import type resolve from "@rollup/plugin-node-resolve"
4+
type RollupResolveOptions = Parameters<typeof resolve>[0]
45
import type commonjs from "@rollup/plugin-commonjs"
6+
type RollupCommonjsOptions = Parameters<typeof commonjs>[0]
57
import type { terser } from "rollup-plugin-terser"
8+
type RollupTerserOptions = Parameters<typeof terser>[0]
69
import type sourcemaps from "rollup-plugin-sourcemaps"
10+
type RollupSourcemapsOptions = Parameters<typeof sourcemaps>[0]
711
import type replace from "@rollup/plugin-replace"
12+
type RollupReplaceOptions = Parameters<typeof replace>[0]
813
// @ts-ignore
914
import type autoExternal from "rollup-plugin-auto-external"
15+
type RollupAutoexternalOptions = Parameters<typeof autoExternal>[0] & Record<string, any>
1016
import type typescript from "@rollup/plugin-typescript"
17+
type RollupTypeScriptOptions = Parameters<typeof typescript>[0]
1118
// @ts-ignore
1219
import type coffeescript from "rollup-plugin-coffee-script"
20+
type RollupCoffeeOptions = Parameters<typeof coffeescript>[0] & Record<string, any>
1321
import type json from "@rollup/plugin-json"
22+
type RollupJsonOptions = Parameters<typeof json>[0]
1423
// @ts-ignore
1524
import type cssOnly from "rollup-plugin-css-only"
25+
type RollupCssonlyOptions = Parameters<typeof cssOnly>[0] & Record<string, any>
1626
import type babel from "@rollup/plugin-babel"
27+
type RollupBabelOptions = Parameters<typeof babel>[0]
1728
import type { wasm } from "@rollup/plugin-wasm"
29+
type RollupWasmOptions = Parameters<typeof wasm>[0]
1830
// @ts-ignore
1931
import type { asc } from "rollup-plugin-assemblyscript"
32+
type RollupAscOptions = Parameters<typeof asc>[0] & Record<string, any>
2033
import type visualizer from "rollup-plugin-visualizer"
34+
type RollupVisualizerOptions = Parameters<typeof visualizer>[0]
2135

2236
export type Plugin =
2337
| "js"
@@ -35,20 +49,20 @@ export type Plugin =
3549
| "resolve"
3650
| "autoExternal"
3751
| "visualizer"
38-
| ["ts", typeof typescript, boolean?]
39-
| ["babel", typeof babel, boolean?]
40-
| ["coffee", typeof coffeescript, boolean?]
41-
| ["json", typeof json, boolean?]
42-
| ["css", typeof cssOnly, boolean?]
43-
| ["wasm", typeof wasm, boolean?]
44-
| ["as", typeof asc, boolean?]
45-
| ["terser", typeof terser, boolean?]
46-
| ["replace", typeof replace, boolean?]
47-
| ["sourcemaps", typeof sourcemaps, boolean?]
48-
| ["commonjs", typeof commonjs, boolean?]
49-
| ["resolve", typeof resolve, boolean?]
50-
| ["autoExternal", typeof autoExternal, boolean?]
51-
| ["visualizer", typeof visualizer, boolean?]
52+
| ["ts", RollupTypeScriptOptions, boolean?]
53+
| ["babel", RollupBabelOptions, boolean?]
54+
| ["coffee", RollupCoffeeOptions, boolean?]
55+
| ["json", RollupJsonOptions, boolean?]
56+
| ["css", RollupCssonlyOptions, boolean?]
57+
| ["wasm", RollupWasmOptions, boolean?]
58+
| ["as", RollupAscOptions, boolean?]
59+
| ["terser", RollupTerserOptions, boolean?]
60+
| ["replace", RollupReplaceOptions, boolean?]
61+
| ["sourcemaps", RollupSourcemapsOptions, boolean?]
62+
| ["commonjs", RollupCommonjsOptions, boolean?]
63+
| ["resolve", RollupResolveOptions, boolean?]
64+
| ["autoExternal", RollupAutoexternalOptions, boolean?]
65+
| ["visualizer", RollupVisualizerOptions, boolean?]
5266

5367
export function createPlugins(
5468
inputPluginsNames: Array<Plugin> = ["ts", "js", "json", "coffee"],
@@ -62,7 +76,7 @@ export function createPlugins(
6276
pushPlugin(["ts", ".ts", "typescript", "TypeScript"], ["@rollup/plugin-typescript"], {
6377
noEmitOnError: false,
6478
module: "ESNext", // do not modify the imports
65-
})
79+
} as RollupTypeScriptOptions)
6680

6781
// coffeescript
6882
pushPlugin(
@@ -71,7 +85,7 @@ export function createPlugins(
7185
)
7286

7387
// json
74-
pushPlugin(["json", ".json", "JSON"], ["@rollup/plugin-json"], { compact: true })
88+
pushPlugin(["json", ".json", "JSON"], ["@rollup/plugin-json"], { compact: true } as RollupJsonOptions)
7589

7690
// css only
7791
const cssIndex = includesAny(inputPluginsNames, ["css", ".css"])
@@ -84,7 +98,7 @@ export function createPlugins(
8498
`)
8599
if (typeof inputPluginsNames[cssIndex] === "string") {
86100
// plugin name only
87-
plugins.push(cssOnly({ output: "dist/bundle.css" }))
101+
plugins.push(cssOnly({ output: "dist/bundle.css" } as RollupCssonlyOptions))
88102
} else {
89103
// plugin with options
90104
plugins.push(cssOnly(inputPluginsNames[cssIndex][1]))
@@ -100,7 +114,7 @@ export function createPlugins(
100114
pushPlugin(["babel"], ["@rollup/plugin-babel", "babel"], {
101115
extensions: [".js", ".jsx", ".mjs", ".coffee"],
102116
babelHelpers: "bundled",
103-
})
117+
} as RollupBabelOptions)
104118

105119
// wasm
106120
pushPlugin(["wasm", "WebAssembly"], ["@rollup/plugin-wasm", "wasm"])
@@ -109,7 +123,10 @@ export function createPlugins(
109123
pushPlugin(["as", "asc", "assemblyscript", "AssemblyScript"], ["rollup-plugin-assemblyscript", "asc"])
110124

111125
// visualizer
112-
pushPlugin(["visualizer", "plot"], ["rollup-plugin-visualizer"], { sourcemap: true, open: true })
126+
pushPlugin(["visualizer", "plot"], ["rollup-plugin-visualizer"], {
127+
sourcemap: true,
128+
open: true,
129+
} as RollupVisualizerOptions)
113130

114131
// extra plugins
115132
if (extraPlugins !== undefined && typeof extraPlugins === "object" /*array*/) {
@@ -123,7 +140,7 @@ export function createPlugins(
123140
// Default plugins
124141

125142
// loading files with existing source maps
126-
pushPlugin(["sourcemaps"], ["rollup-plugin-sourcemaps"], {}, true)
143+
pushPlugin(["sourcemaps"], ["rollup-plugin-sourcemaps"], {} as RollupSourcemapsOptions, true)
127144

128145
pushPlugin(
129146
["autoExternal"],
@@ -132,7 +149,7 @@ export function createPlugins(
132149
builtins: true,
133150
dependencies: false,
134151
peerDependencies: false,
135-
},
152+
} as RollupAutoexternalOptions,
136153
true
137154
)
138155

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
type PluginOptions = Record<string, string> | undefined | unknown
12
// function to check if the first array has any of the second array
23
// first array can have `[string, object]` as their input
3-
export function includesAny(arr1: Array<string | [string, Object, boolean?]>, arr2: Array<string>): null | number {
4+
export function includesAny(
5+
arr1: Array<string | [string, PluginOptions, boolean?]>,
6+
arr2: Array<string>
7+
): null | number {
48
for (let index = 0; index < arr1.length; index++) {
59
const elm = arr1[index]
610
let name: string

0 commit comments

Comments
 (0)