Vanilla Rsbuild
-Start building amazing things with Rsbuild.
-diff --git a/e2e/cases/preact/prefresh-context/index.test.ts b/e2e/cases/preact/prefresh-context/index.test.ts index fbda720e8f..15ec83a5e6 100644 --- a/e2e/cases/preact/prefresh-context/index.test.ts +++ b/e2e/cases/preact/prefresh-context/index.test.ts @@ -44,8 +44,8 @@ export default B; ); await page.waitForFunction(() => { - const aText = document.querySelector('#A')!.textContent; - const bText = document.querySelector('#B')!.textContent; + const aText = document.querySelector('#A')?.textContent; + const bText = document.querySelector('#B')?.textContent; return ( // the state (count) of A should be kept diff --git a/e2e/cases/preact/prefresh-disabled/index.test.ts b/e2e/cases/preact/prefresh-disabled/index.test.ts index 24d8b72aa9..8e84a15ada 100644 --- a/e2e/cases/preact/prefresh-disabled/index.test.ts +++ b/e2e/cases/preact/prefresh-disabled/index.test.ts @@ -43,8 +43,8 @@ export default B; ); await page.waitForFunction(() => { - const aText = document.querySelector('#A')!.textContent; - const bText = document.querySelector('#B')!.textContent; + const aText = document.querySelector('#A')?.textContent; + const bText = document.querySelector('#B')?.textContent; return ( // the state (count) of A should not be kept diff --git a/e2e/cases/preact/prefresh/index.test.ts b/e2e/cases/preact/prefresh/index.test.ts index d1a7f9472a..065df0ab94 100644 --- a/e2e/cases/preact/prefresh/index.test.ts +++ b/e2e/cases/preact/prefresh/index.test.ts @@ -43,8 +43,8 @@ export default B; ); await page.waitForFunction(() => { - const aText = document.querySelector('#A')!.textContent; - const bText = document.querySelector('#B')!.textContent; + const aText = document.querySelector('#A')?.textContent; + const bText = document.querySelector('#B')?.textContent; return ( // the state (count) of A should be kept diff --git a/e2e/cases/solid/hmr/index.test.ts b/e2e/cases/solid/hmr/index.test.ts index 4ecec20b59..1433fb51e5 100644 --- a/e2e/cases/solid/hmr/index.test.ts +++ b/e2e/cases/solid/hmr/index.test.ts @@ -43,8 +43,8 @@ export default B; ); await page.waitForFunction(() => { - const aText = document.querySelector('#A')!.textContent; - const bText = document.querySelector('#B')!.textContent; + const aText = document.querySelector('#A')?.textContent; + const bText = document.querySelector('#B')?.textContent; return ( // the state (count) of A should be kept diff --git a/e2e/scripts/shared.ts b/e2e/scripts/shared.ts index d5fbe8216c..4c7cbb859c 100644 --- a/e2e/scripts/shared.ts +++ b/e2e/scripts/shared.ts @@ -261,11 +261,11 @@ export async function build({ ([file]) => file.includes('index') && file.endsWith('.js'), ) || []; - assert(name); + assert(name && content); return { - content: content!, - size: content!.length / 1024, + content: content, + size: content.length / 1024, }; }; diff --git a/packages/compat/plugin-webpack-swc/tests/plugin.test.ts b/packages/compat/plugin-webpack-swc/tests/plugin.test.ts index 04e3478d4f..3508e62063 100644 --- a/packages/compat/plugin-webpack-swc/tests/plugin.test.ts +++ b/packages/compat/plugin-webpack-swc/tests/plugin.test.ts @@ -380,7 +380,8 @@ describe('plugin-webpack-swc', () => { const config = ( await applyPluginConfig( (config) => { - config.env!.coreJs = '2'; + config.env ||= {}; + config.env.coreJs = '2'; return config; }, UTILS, @@ -420,8 +421,7 @@ describe('plugin-webpack-swc', () => { }, }); const config = await rsbuild.unwrapConfig(); - - expect(config.module!.rules).toMatchSnapshot(); + expect(config.module.rules).toMatchSnapshot(); }); it('should allow to disable transformLodash', async () => { diff --git a/packages/compat/webpack/tests/initConfigs.test.ts b/packages/compat/webpack/tests/initConfigs.test.ts index 34b19c4708..1216750dbc 100644 --- a/packages/compat/webpack/tests/initConfigs.test.ts +++ b/packages/compat/webpack/tests/initConfigs.test.ts @@ -16,7 +16,8 @@ describe('modifyRsbuildConfig', () => { }); api.modifyWebpackChain(() => { - config.server!.port = 8899; + config.server ||= {}; + config.server.port = 8899; }); }, }, diff --git a/packages/core/src/client/overlay.ts b/packages/core/src/client/overlay.ts index b6ad835a9c..0e09a32a9b 100644 --- a/packages/core/src/client/overlay.ts +++ b/packages/core/src/client/overlay.ts @@ -19,10 +19,10 @@ class ErrorOverlay extends HTMLElement { const root = this.attachShadow({ mode: 'open' }); root.innerHTML = html; - root.querySelector('.close')!.addEventListener('click', this.close); + root.querySelector('.close')?.addEventListener('click', this.close); // close overlay when click outside this.addEventListener('click', this.close); - root.querySelector('.container')!.addEventListener('click', (e) => { + root.querySelector('.container')?.addEventListener('click', (e) => { if (e.target) { const { file } = (e.target as HTMLLinkElement).dataset; if (file) { diff --git a/packages/core/src/pluginManager.ts b/packages/core/src/pluginManager.ts index 90125101d8..9ef8ef24e0 100644 --- a/packages/core/src/pluginManager.ts +++ b/packages/core/src/pluginManager.ts @@ -256,7 +256,7 @@ export async function initPlugins({ continue; } const { instance, environment } = plugin; - await instance.setup(getPluginAPI!(environment)); + await instance.setup(getPluginAPI(environment)); } logger.debug('init plugins done'); diff --git a/packages/core/src/plugins/fileSize.ts b/packages/core/src/plugins/fileSize.ts index 1ed275d247..1c807445ff 100644 --- a/packages/core/src/plugins/fileSize.ts +++ b/packages/core/src/plugins/fileSize.ts @@ -143,7 +143,7 @@ async function printFileSizes( }); const exclude = options.exclude ?? excludeAsset; - const filteredAssets = origin.assets!.filter((asset) => { + const filteredAssets = (origin.assets || []).filter((asset) => { const assetInfo: PrintFileSizeAsset = { name: asset.name, size: asset.size, diff --git a/packages/core/src/plugins/manifest.ts b/packages/core/src/plugins/manifest.ts index 33d8da54e6..483cbdc05a 100644 --- a/packages/core/src/plugins/manifest.ts +++ b/packages/core/src/plugins/manifest.ts @@ -62,8 +62,10 @@ const generateManifest = assets.add(relatedLICENSE); } - for (const auxiliaryFile of file.chunk!.auxiliaryFiles) { - assets.add(auxiliaryFile); + if (file.chunk) { + for (const auxiliaryFile of file.chunk.auxiliaryFiles) { + assets.add(auxiliaryFile); + } } } diff --git a/packages/core/tests/mergeConfig.test.ts b/packages/core/tests/mergeConfig.test.ts index 13b625e4bd..332f1a47d2 100644 --- a/packages/core/tests/mergeConfig.test.ts +++ b/packages/core/tests/mergeConfig.test.ts @@ -329,7 +329,7 @@ describe('mergeRsbuildConfig', () => { }, }); - expect(mergedConfig.tools!.rspack.plugins[0] instanceof A).toBeTruthy(); + expect(mergedConfig.tools?.rspack.plugins[0] instanceof A).toBeTruthy(); }); test('should merge overrideBrowserslist in environments as expected', async () => { diff --git a/packages/create-rsbuild/template-vanilla-ts/src/index.ts b/packages/create-rsbuild/template-vanilla-ts/src/index.ts index 4f3e14e2a2..0c50c63f73 100644 --- a/packages/create-rsbuild/template-vanilla-ts/src/index.ts +++ b/packages/create-rsbuild/template-vanilla-ts/src/index.ts @@ -1,8 +1,11 @@ import './index.css'; -document.querySelector('#root')!.innerHTML = ` -
Start building amazing things with Rsbuild.
-Start building amazing things with Rsbuild.
+