forked from remcohaszing/monaco-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·74 lines (71 loc) · 3.01 KB
/
build.js
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
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { build } from 'esbuild'
const pkg = JSON.parse(await readFile(new URL('package.json', import.meta.url)))
await build({
entryPoints: ['src/index.ts', 'src/yaml.worker.ts'],
bundle: true,
external: Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies }),
logLevel: 'info',
outdir: '.',
sourcemap: true,
format: 'esm',
target: ['es2019'],
plugins: [
{
name: 'alias',
setup({ onLoad, onResolve, resolve }) {
// The file monaco-yaml/lib/esm/schemaSelectionHandlers.js imports code from the language
// server part that we don’t want.
onResolve({ filter: /\/schemaSelectionHandlers$/ }, () => ({
path: fileURLToPath(new URL('src/fillers/schemaSelectionHandlers.ts', import.meta.url))
}))
// The yaml language service only imports re-exports of vscode-languageserver-types from
// vscode-languageserver.
onResolve({ filter: /^vscode-languageserver(\/node|-protocol)?$/ }, () => ({
path: 'vscode-languageserver-types',
external: true,
sideEffects: false
}))
// Ajv would significantly increase bundle size.
onResolve({ filter: /^ajv$/ }, () => ({
path: fileURLToPath(new URL('src/fillers/ajv.ts', import.meta.url))
}))
// We only need cloneDeep from lodash. This can be replaced with structuredClone.
onResolve({ filter: /^lodash$/ }, () => ({
path: fileURLToPath(new URL('src/fillers/lodash.ts', import.meta.url))
}))
// The yaml language service uses path. We can stub it using path-browserify.
onResolve({ filter: /^path$/ }, () => ({
path: 'path-browserify',
external: true,
sideEffects: false
}))
// The main prettier entry point contains all of Prettier.
// The standalone bundle is smaller and works fine for us.
onResolve({ filter: /^prettier/ }, ({ path }) => ({
path: path === 'prettier' ? 'prettier/standalone.js' : `${path}.js`,
external: true,
sideEffects: false
}))
// This tiny filler implementation serves all our needs.
onResolve({ filter: /vscode-nls/ }, () => ({
path: fileURLToPath(new URL('src/fillers/vscode-nls.ts', import.meta.url)),
sideEffects: false
}))
// The language server dependencies tend to write both ESM and UMD output alongside each
// other, then use UMD for imports. We prefer ESM.
onResolve({ filter: /\/umd\// }, ({ path, ...options }) =>
resolve(path.replace(/\/umd\//, '/esm/'), options)
)
onResolve({ filter: /.*/ }, () => ({ sideEffects: false }))
onLoad({ filter: /yamlSchemaService\.js$/ }, async ({ path }) => ({
contents: (await readFile(path, 'utf8')).replaceAll(
"require('ajv/dist/refs/json-schema-draft-07.json')",
'undefined'
)
}))
}
}
]
})