Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions e2e/cases/source/source-include/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from 'node:path';
import { build, proxyConsole } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginCheckSyntax } from '@rsbuild/plugin-check-syntax';
import { normalizeToPosixPath } from '@scripts/test-helper';

test('should not compile file which outside of project by default', async () => {
test('should compile modules outside of project by default', async () => {
const { logs, restore } = proxyConsole();
await expect(
build({
Expand All @@ -16,30 +14,8 @@ test('should not compile file which outside of project by default', async () =>
},
},
}),
).rejects.toThrowError('[@rsbuild/plugin-check-syntax]');
).resolves.toBeDefined();

expect(logs.find((log) => log.includes('Syntax check passed'))).toBeTruthy();
restore();

expect(logs.find((log) => log.includes('ERROR 1'))).toBeTruthy();
expect(
logs.find(
(log) =>
log.includes('source:') &&
normalizeToPosixPath(log).includes('/dist/static/js/index'),
),
).toBeTruthy();
});

test('should compile specified file when source.include', async () => {
await expect(
build({
cwd: __dirname,
plugins: [pluginCheckSyntax()],
rsbuildConfig: {
source: {
include: [path.resolve(__dirname, '../test.js')],
},
},
}),
).resolves.toBeDefined();
});
1 change: 1 addition & 0 deletions e2e/cases/source/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is used by the test case: source-include
export const printLog = () => {
const arr = [1, 2, 3, 4, [5, 6, [7, 8]]];
console.log(arr, arr.flat());
Expand Down
28 changes: 4 additions & 24 deletions packages/compat/webpack/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"include": [
{
"and": [
"<ROOT>/packages/compat/webpack/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down Expand Up @@ -557,12 +552,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
},
"include": [
{
"and": [
"<ROOT>/packages/compat/webpack/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1006,12 +996,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"include": [
{
"and": [
"<ROOT>/packages/compat/webpack/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1385,12 +1370,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"include": [
{
"and": [
"<ROOT>/packages/compat/webpack/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/plugins/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
NormalizedEnvironmentConfig,
NormalizedSourceConfig,
Polyfill,
RsbuildContext,
RsbuildPlugin,
RsbuildTarget,
RspackChain,
Expand All @@ -35,19 +34,15 @@ function applyScriptCondition({
rule,
isDev,
config,
context,
rsbuildTarget,
}: {
rule: RspackChain.Rule;
isDev: boolean;
config: NormalizedEnvironmentConfig;
context: RsbuildContext;
rsbuildTarget: RsbuildTarget;
}): void {
// compile all modules in the app directory, exclude node_modules
rule.include.add({
and: [context.rootPath, { not: NODE_MODULES_REGEX }],
});
rule.include.add({ not: NODE_MODULES_REGEX });

// always compile TS and JSX files.
// otherwise, it may cause compilation errors and incorrect output
Expand Down Expand Up @@ -125,7 +120,6 @@ export const pluginSwc = (): RsbuildPlugin => ({
rule,
isDev,
config,
context: api.context,
rsbuildTarget: target,
});

Expand Down
7 changes: 1 addition & 6 deletions packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ exports[`should use Rspack as the default bundler > apply Rspack correctly 1`] =
},
"include": [
{
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down
28 changes: 4 additions & 24 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"include": [
{
"and": [
"<ROOT>/packages/core/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down Expand Up @@ -595,12 +590,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
"include": [
{
"and": [
"<ROOT>/packages/core/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1075,12 +1065,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"include": [
{
"and": [
"<ROOT>/packages/core/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1504,12 +1489,7 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
"include": [
{
"and": [
"<ROOT>/packages/core/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down
14 changes: 2 additions & 12 deletions packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,7 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
},
"include": [
{
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down Expand Up @@ -1806,12 +1801,7 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
},
"include": [
{
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
Loading
Loading