-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.ts
196 lines (189 loc) · 5.82 KB
/
rollup.config.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { visualizer } from 'rollup-plugin-visualizer'
import commonjs from '@rollup/plugin-commonjs'
import alias from '@rollup/plugin-alias'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import * as rollup from 'rollup'
import vsixPlugin, { IExtensionManifest } from '@codingame/monaco-vscode-rollup-vsix-plugin'
import glob from 'fast-glob'
import { addExtension, dataToEsm } from '@rollup/pluginutils'
import { importMetaAssets } from '@web/rollup-plugin-import-meta-assets'
import path from 'path'
import fs from 'fs'
import pkg from './package.json' assert { type: 'json' }
const externals = Object.keys(pkg.dependencies)
const extensions = ['.js', '.ts']
export default rollup.defineConfig({
cache: false,
input: {
main: 'src/index.ts',
'features/views': 'src/features/views.ts',
'features/viewPanels': 'src/features/viewPanels.ts',
'features/search': 'src/features/search.ts',
'features/debug': 'src/features/debug.ts',
'features/testing': 'src/features/testing.ts',
'features/terminal': 'src/features/terminal.ts',
'features/extensionHostWorker': 'src/features/extensionHostWorker.ts',
'features/notifications': 'src/features/notifications.ts',
'features/extensionGallery': 'src/features/extensionGallery.ts',
'features/workbench': 'src/features/workbench.ts',
'features/profile': 'src/features/profile.ts',
'features/typescriptStandalone': 'src/features/typescriptStandalone.ts',
'features/workingCopyBackup': 'src/features/workingCopyBackup.ts'
},
output: [{
dir: 'dist',
format: 'esm',
paths: {
'monaco-editor-core': 'monaco-editor'
},
preserveModules: true,
preserveModulesRoot: 'src',
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
chunkFileNames: '[name].js'
}],
plugins: [
importMetaAssets({
include: ['**/*.ts', '**/*.js'],
exclude: ['**/worker.ts', '**/features/*.ts']
}),
{
name: 'external-resolver',
resolveId (id) {
// monaco-editor can safely be imported with monaco-vscode-api
if (id === 'monaco-editor/esm/vs/editor/editor.api') {
return {
id: 'monaco-editor',
external: 'absolute'
}
}
// Add missing .js extension to respect ESM strict mode
if (id.startsWith('monaco-editor/esm')) {
return {
id: addExtension(id, '.js'),
external: 'absolute'
}
}
if (/\.wasm$/.test(id) || externals.some(external => id === external || id.startsWith(`${external}/`))) {
return {
id,
external: true
}
}
return undefined
}
},
{
name: 'd-ts-glob-import',
async resolveId (source, importer) {
if (source.startsWith('types:')) {
return `types:${path.resolve(path.dirname(importer!), source.slice(6))}`
}
return undefined
},
async load (importee) {
if (importee.startsWith('types:')) {
const cwd = importee.slice(6)
const files = await glob('**/*.d.ts', {
cwd
})
const data = Object.fromEntries(await Promise.all(files.map(async f => {
const data = await fs.promises.readFile(path.resolve(cwd, f))
return [
f,
data.toString('utf-8')
]
})))
return dataToEsm(data)
}
return undefined
}
},
{
name: 'glob-vsix-import',
async resolveId (source, importer) {
if (source.endsWith('*.vsix')) {
return `vsixGlob:${path.resolve(path.dirname(importer!), source)}`
}
return undefined
},
async load (importee) {
if (importee.startsWith('vsixGlob:')) {
const files = await glob(importee.slice(9))
return `
${files.map((file, index) => `import { whenReady as whenReady${index} } from '${file}'`).join('\n')}
export async function whenReady () {
await Promise.all([
${files.map((_, index) => ` whenReady${index}()`).join(',\n')}
])
}
`
}
return undefined
}
},
vsixPlugin({
transformManifest (manifest) {
const {
commands,
debuggers,
keybindings,
menus,
views,
walkthroughs,
breakpoints,
taskDefinitions,
viewsWelcome,
terminal,
viewsContainers,
typescriptServerPlugins,
...remainingContribute
} = ((manifest.contributes ?? {}) as (IExtensionManifest['contributes'] & {
typescriptServerPlugins: unknown // typescript extension specific field
}))
const {
activationEvents,
devDependencies,
dependencies,
scripts,
browser,
main,
l10n,
extensionDependencies, // for pure-d that requires hbenl.vscode-test-explorer
...remainingManifest
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = manifest as any
return {
...remainingManifest,
contributes: remainingContribute
}
}
}),
nodeResolve({
extensions
}),
commonjs({
esmExternals: (id) => id.match(/^monaco-editor(\/.*)?/) != null // required for monaco-emacs with use import monaco-editor esm code from commonjs code
}),
typescript({
noEmitOnError: true
}),
visualizer(),
alias({
entries: [{
find: /^monaco-editor-core\//,
replacement: 'monaco-editor/'
}]
}),
{
name: 'dynamic-import-polyfill',
renderDynamicImport (): { left: string, right: string } {
return {
left: 'import(',
right: ').then(module => module)'
}
}
}
]
})