-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·72 lines (69 loc) · 2.9 KB
/
build.js
File metadata and controls
executable file
·72 lines (69 loc) · 2.9 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
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { build } from 'esbuild'
import pkg from './package.json' with { type: 'json' }
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: ['es2022'],
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: join(import.meta.dirname, 'fillers/schemaSelectionHandlers.ts')
}))
// The yaml language service only imports re-exports of vscode-languageserver-types from
// vscode-languageserver.
onResolve({ filter: /^vscode-languageserver(\/node|-protocol)?$/ }, () => ({
path: join(import.meta.dirname, 'fillers/vscode-languageserver-protocol.ts')
}))
// Ajv would significantly increase bundle size.
onResolve({ filter: /^ajv-i18n$/ }, () => ({
path: join(import.meta.dirname, 'fillers/json-schema.json')
}))
// Ajv would significantly increase bundle size.
onResolve({ filter: /^ajv.+\.json$/ }, () => ({
path: join(import.meta.dirname, 'fillers/json-schema.json')
}))
// Ajv would significantly increase bundle size.
onResolve({ filter: /^(ajv|ajv-draft-04|ajv\/dist\/\d+)$/ }, () => ({
path: join(import.meta.dirname, 'fillers/ajv.ts')
}))
// The yaml language service uses path. We can stub it using path-browserify.
onResolve({ filter: /^path$/ }, () => ({
path: 'path-browserify',
external: true,
sideEffects: false
}))
// This tiny filler implementation serves all our needs.
onResolve({ filter: /vscode-nls/ }, () => ({
path: join(import.meta.dirname, 'fillers/vscode-nls.ts'),
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: /.*/, namespace: 'file' }, async ({ path, ...options }) => ({
...(await resolve(path, { ...options, namespace: 'side-effect-free' })),
sideEffects: false
}))
onLoad({ filter: /yamlSchemaService\.js$/ }, async ({ path }) => ({
contents: (await readFile(path, 'utf8')).replaceAll(
"require('ajv/dist/refs/json-schema-draft-07.json')",
'undefined'
)
}))
}
}
]
})