-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mts
More file actions
97 lines (90 loc) · 2.34 KB
/
rollup.config.mts
File metadata and controls
97 lines (90 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file rollup
* @module config/rollup
*/
import listWorkspaces from '#utils/list-workspaces'
import pathe from '@flex-development/pathe'
import resolve from '@rollup/plugin-node-resolve'
import type { Dirent } from 'node:fs'
import type {
NormalizedOutputOptions,
OutputBundle,
PluginContext,
RollupOptions
} from 'rollup'
import { dts } from 'rollup-plugin-dts'
/**
* The rollup configuration.
*
* @see {@linkcode RollupOptions}
*
* @type {RollupOptions[]}
*/
export default listWorkspaces().map((
workspace: Dirent,
index: number,
workspaces: readonly Dirent[]
): RollupOptions => {
/**
* The path to the package directory.
*
* @const {string} dir
*/
const directory: string = pathe.join(workspace.parentPath, workspace.name)
/**
* The target file.
*
* @const {string} file
*/
const file: string = pathe.join(directory, 'dist/index.d.mts')
return {
external: workspaces.filter(w => !directory.endsWith(w.name)).map(w => {
return '@flex-development/' + w.name
}),
input: file,
output: [{ file, format: 'esm' }],
plugins: [
resolve({ extensions: ['.d.mts', '.mts'] }),
dts({ includeExternal: [] }),
{
/**
* Re-add lost `type` modifiers.
*
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/354
*
* @this {PluginContext}
*
* @param {NormalizedOutputOptions} options
* The normalized output options
* @param {OutputBundle} bundle
* The output bundle object
* @return {undefined}
*/
generateBundle(
this: PluginContext,
options: NormalizedOutputOptions,
bundle: OutputBundle
): undefined {
for (const output of Object.values(bundle)) {
if (output.type === 'chunk') {
output.code = output.code
.replaceAll('import *', 'import type *')
.replaceAll('import {', 'import type {')
if (workspace.name === 'grease-util-types') {
output.code = output.code.replaceAll(
'export {',
'export type {'
)
}
}
}
return void this
},
/**
* The plugin name.
*/
name: 'build:dts'
}
]
}
})