Repository navigation
Expand file tree
/
Copy pathrslib.config.mts
More file actions
160 lines (151 loc) · 4.98 KB
/
Copy pathrslib.config.mts
File metadata and controls
160 lines (151 loc) · 4.98 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
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
import { existsSync } from 'node:fs';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig, type LibConfig, rspack } from '@rslib/core';
import WebpackLicensePlugin from 'webpack-license-plugin';
const require = createRequire(import.meta.url);
const rootDir = path.dirname(fileURLToPath(import.meta.url));
// The VSIX is platform-targeted for exactly one reason: Rstest's AST test-case
// collection loads the `yuku-core` napi binding (via `yuku-parser`). Everything
// else in this extension is platform neutral (the Rslint Go binary and its napi
// parser are resolved from the project at runtime and never ship in the VSIX).
// On musl Linux (Alpine), set `VSCE_TARGET=alpine-<arch>` explicitly.
const vsceTarget =
process.env.VSCE_TARGET ?? `${process.platform}-${process.arch}`;
// Yuku's loader resolves `binding-${platform}-${arch}${libc}`; the Linux VSIX
// targets differ only by libc: `linux-*` is glibc, `alpine-*` is musl.
const LINUX_LIBC: Record<string, string> = { linux: 'gnu', alpine: 'musl' };
const [targetOs, targetArch] = vsceTarget.split('-');
const libc = LINUX_LIBC[targetOs];
const yukuBindingSuffix = libc ? `linux-${targetArch}-${libc}` : vsceTarget;
const yukuCoreRequire = createRequire(
createRequire(require.resolve('yuku-parser')).resolve('yuku-core'),
);
// Yuku computes this package name at runtime, so Rspack cannot discover it.
const yukuBindingPackage = `@yuku-core/binding-${yukuBindingSuffix}`;
const yukuBindingPath = yukuCoreRequire.resolve(yukuBindingPackage);
/**
* Packages that are always resolved from the user's project at runtime, never
* bundled: the extension ships types only.
*/
const RUNTIME_RESOLVED_PACKAGES = /^(@rslint\/core|@rstest\/core|jiti)(\/|$)/;
const externals: NonNullable<NonNullable<LibConfig['output']>['externals']> = [
{ vscode: 'commonjs vscode' },
({ request }, callback) => {
if (request && RUNTIME_RESOLVED_PACKAGES.test(request)) {
return callback(undefined, `commonjs ${request}`);
}
return callback();
},
];
// The Rstest worker entry is owned by the Rstest stack and may not exist yet
// while the stacks are still being copied in.
const workerEntry = './src/stacks/test/worker/index.ts';
const hasWorkerEntry = existsSync(path.join(rootDir, workerEntry));
const lintWorkerEntry = './src/stacks/lint/worker/main.ts';
const libs: LibConfig[] = [
{
id: 'extension',
syntax: 'es2023',
format: 'cjs',
source: {
entry: {
extension: './src/extension.ts',
},
},
tools: {
rspack: {
output: {
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
plugins: [
new rspack.CopyRspackPlugin({
patterns: [
{
from: yukuBindingPath,
to: `${yukuBindingPackage}/${path.basename(yukuBindingPath)}`,
},
{
// The VSIX must carry a LICENSE (`.vscodeignore` keeps it), and
// the workspace root LICENSE is the single source of truth. The
// copy lands next to package.json — not in dist/ — because vsce
// packages from the package directory; it is gitignored.
from: path.join(rootDir, '..', '..', 'LICENSE'),
to: path.join(rootDir, 'LICENSE'),
toType: 'file',
},
],
}),
],
},
},
},
];
if (hasWorkerEntry) {
libs.push({
id: 'worker',
syntax: 'es2023',
format: 'cjs',
source: {
entry: {
worker: workerEntry,
},
},
tools: {
rspack: {
output: {
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
},
},
});
}
libs.push({
id: 'lint-worker',
syntax: 'es2023',
format: 'cjs',
source: {
entry: {
'lint-worker': lintWorkerEntry,
},
},
tools: {
rspack: {
output: {
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
},
},
});
/**
* Output shared by every bundle. `rslib build --env-mode dev` (`build:local`
* / `watch:local`) keeps readable output with source maps so breakpoints in
* `src/` bind in the dev host; the release build (`build`, used by CI and the
* Release workflow) minifies and emits no source maps.
*/
export default defineConfig(({ envMode }) => {
const devBuild = envMode === 'dev';
const output: LibConfig['output'] = {
target: 'node',
externals,
sourceMap: devBuild,
minify: !devBuild,
};
return {
lib: libs.map((lib) => ({ ...lib, output })),
tools: {
rspack: (_, { appendPlugins, environment }) => {
appendPlugins(
new WebpackLicensePlugin({
outputFilename: `${environment.name}.licenses.json`,
includePackages: () =>
environment.name === 'extension'
? [path.dirname(yukuBindingPath)]
: [],
}),
);
},
},
};
});