Skip to content

Commit 2418e0b

Browse files
committed
Workaround unplugin bug
1 parent fade2a5 commit 2418e0b

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

packages/bundle/tsup.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ const commonConfig = applyConfig(config => ({
4444
SPEECH_CONDUCT_OCSP_CHECK: '',
4545
SPEECH_OCSP_CACHE_ROOT: ''
4646
},
47-
// Intentionally overriding existing esbuild plugins.
48-
esbuildPlugins: [resolveCognitiveServicesToES2015],
47+
esbuildPlugins: [...(config.esbuildPlugins ?? []), resolveCognitiveServicesToES2015],
4948
noExternal: [
5049
...(config.noExternal ?? []),
5150
'@babel/runtime',
@@ -76,7 +75,7 @@ export default defineConfig([
7675
'webchat-es5': './src/boot/bundle/full-es5.ts',
7776
'webchat-minimal': './src/boot/bundle/minimal.ts'
7877
},
79-
esbuildPlugins: [...commonConfig.esbuildPlugins, resolveReact],
78+
esbuildPlugins: [...(commonConfig.esbuildPlugins ?? []), resolveReact],
8079
format: 'iife',
8180
outExtension() {
8281
return { js: '.js' };

packages/directlinespeech/tsup.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ const config = applyConfig(config => ({
3131
SPEECH_CONDUCT_OCSP_CHECK: '',
3232
SPEECH_OCSP_CACHE_ROOT: ''
3333
},
34-
// Intentionally overriding existing esbuild plugins.
35-
esbuildPlugins: [resolveCognitiveServicesToES2015],
34+
esbuildPlugins: [...(config.esbuildPlugins ?? []), resolveCognitiveServicesToES2015],
3635
// We need to internalize event-target-shim because it appear as transient packages with a different version.
3736
noExternal: [...(config.noExternal ?? []), 'event-target-shim']
3837
}));

packages/fluent-theme/tsup.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default defineConfig([
5656
},
5757
entry: { 'botframework-webchat-fluent-theme': './src/index.ts' },
5858
esbuildPlugins: [
59-
...(config.esbuildPlugins || []),
59+
...(config.esbuildPlugins ?? []),
6060
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
6161
],
6262
format: ['cjs'],
@@ -70,7 +70,7 @@ export default defineConfig([
7070
},
7171
entry: { 'botframework-webchat-fluent-theme': './src/index.ts' },
7272
esbuildPlugins: [
73-
...(config.esbuildPlugins || []),
73+
...(config.esbuildPlugins ?? []),
7474
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
7575
],
7676
format: ['esm']
@@ -83,7 +83,7 @@ export default defineConfig([
8383
},
8484
entry: { 'botframework-webchat-fluent-theme.development': './src/bundle.ts' },
8585
esbuildPlugins: [
86-
// ...(config.esbuildPlugins || []),
86+
...(config.esbuildPlugins ?? []),
8787
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }),
8888
umdResolvePlugin
8989
],
@@ -100,7 +100,7 @@ export default defineConfig([
100100
},
101101
entry: { 'botframework-webchat-fluent-theme.production.min': './src/bundle.ts' },
102102
esbuildPlugins: [
103-
// ...(config.esbuildPlugins || []),
103+
...(config.esbuildPlugins ?? []),
104104
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }),
105105
umdResolvePlugin
106106
],

tsup.base.config.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type Plugin } from 'esbuild';
12
import { type Options } from 'tsup';
23
import lightningCssPlugin from 'unplugin-lightningcss/esbuild';
34

@@ -9,8 +10,8 @@ const env = process.env.NODE_ENV || 'development';
910
const { npm_package_version } = process.env;
1011
const istanbulPredicate: Predicate = args => defaultPredicate(args) && !/\.worker\.[cm]?[jt]s$/u.test(args.path);
1112

12-
type Plugin = NonNullable<Options['plugins']>[number];
13-
const disablePlugin = (pluginName: string): Plugin => ({
13+
type EsbuildPlugin = NonNullable<Options['plugins']>[number];
14+
const disablePlugin = (pluginName: string): EsbuildPlugin => ({
1415
name: `disable-plugin-${pluginName}`,
1516
esbuildOptions: options => {
1617
const plugin = options.plugins?.find(({ name }) => name === pluginName);
@@ -20,34 +21,47 @@ const disablePlugin = (pluginName: string): Plugin => ({
2021
}
2122
});
2223

23-
const cssPlugin = lightningCssPlugin({
24-
include: [/\.module\.css$/u],
25-
options: {
26-
cssModules: {
27-
pattern: 'w[hash]_[local]',
28-
pure: true,
29-
animation: false,
30-
grid: false,
31-
customIdents: false
32-
}
24+
// Due to a bug in unplugin, we cannot use the Lightning CSS unplugin directly.
25+
// https://github.com/unjs/unplugin/issues/546
26+
// To workaround the bug, we are converting it back to esbuild plugin so we can apply a custom `filter`.
27+
// Otherwise, unplugin will apply `filter: /.*/` and trigger the bug down the road.
28+
const cssPlugin: Plugin = {
29+
name: 'lightningcss',
30+
setup: build => {
31+
lightningCssPlugin({
32+
include: [/\.module\.css$/u],
33+
options: {
34+
cssModules: {
35+
pattern: 'w[hash]_[local]',
36+
pure: true,
37+
animation: false,
38+
grid: false,
39+
customIdents: false
40+
}
41+
}
42+
}).setup({
43+
...build,
44+
// eslint-disable-next-line require-unicode-regexp
45+
onLoad: (_filter, fn) => build.onLoad({ filter: /(\.module_built\.css|\?css_module)$/ }, fn)
46+
});
3347
}
34-
});
48+
};
3549

3650
function applyConfig(
3751
overrideOptions: (
3852
options: Omit<Options, 'entry' | 'onSuccess'> & {
3953
define: Record<string, string>;
40-
esbuildPlugins: Plugin[];
54+
esbuildPlugins: EsbuildPlugin[];
4155
target: Target[];
4256
}
4357
) => Options & {
4458
define: Record<string, string>;
45-
esbuildPlugins: Plugin[];
59+
esbuildPlugins: EsbuildPlugin[];
4660
target: Target[];
4761
}
4862
): Options & {
4963
define: Record<string, string>;
50-
esbuildPlugins: Plugin[];
64+
esbuildPlugins: EsbuildPlugin[];
5165
target: Target[];
5266
} {
5367
const nextOptions = overrideOptions({

0 commit comments

Comments
 (0)