Skip to content

Commit

Permalink
chore: merge conf
Browse files Browse the repository at this point in the history
  • Loading branch information
witsaint committed Dec 6, 2024
2 parents e63b61f + ee6b35f commit 5531075
Show file tree
Hide file tree
Showing 161 changed files with 1,926 additions and 1,172 deletions.
4 changes: 2 additions & 2 deletions e2e/cases/alias/alias-by-target/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
},
environments: {
web: {
source: {
resolve: {
alias: {
'@common': './src/common',
},
Expand All @@ -16,7 +16,7 @@ export default defineConfig({
},
},
node: {
source: {
resolve: {
alias: {
'@common': './src/common2',
},
Expand Down
10 changes: 7 additions & 3 deletions e2e/cases/alias/jsconfig-paths/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ rspackOnlyTest(
cwd: __dirname,
page,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@common': './src/common2',
},
},
source: {
tsconfigPath: './jsconfig.json',
},
},
Expand All @@ -31,18 +33,20 @@ rspackOnlyTest(
cwd: __dirname,
page,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@/common': './src/common2',
},
aliasStrategy: 'prefer-alias',
},
source: {
tsconfigPath: './jsconfig.json',
},
},
});

const foo = page.locator('#foo');
await expect(foo).toHaveText('source.alias worked');
await expect(foo).toHaveText('resolve.alias worked');

await rsbuild.close();
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/alias/jsconfig-paths/src/common2/test.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const content = 'source.alias worked';
export const content = 'resolve.alias worked';
20 changes: 20 additions & 0 deletions e2e/cases/alias/legacy-alias/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should allow to use the legacy `source.alias` config', async () => {
const rsbuild = await build({
cwd: __dirname,
});

const files = await rsbuild.unwrapOutputJSON();
const fileNames = Object.keys(files);
const webIndex = fileNames.find(
(file) => file.includes('static/js') && file.endsWith('index.js'),
);
const nodeIndex = fileNames.find(
(file) => file.includes('server/index') && file.endsWith('index.js'),
);

expect(files[webIndex!]).toContain('for web target');
expect(files[nodeIndex!]).toContain('for node target');
});
32 changes: 32 additions & 0 deletions e2e/cases/alias/legacy-alias/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
filenameHash: false,
},
environments: {
web: {
source: {
alias: {
'@common': './src/common',
},
},
output: {
target: 'web',
},
},
node: {
source: {
alias: {
'@common': './src/common2',
},
},
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
});
1 change: 1 addition & 0 deletions e2e/cases/alias/legacy-alias/src/common/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const content = 'for web target';
1 change: 1 addition & 0 deletions e2e/cases/alias/legacy-alias/src/common2/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const content = 'for node target';
3 changes: 3 additions & 0 deletions e2e/cases/alias/legacy-alias/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { content } from '@common/test';

console.log(content);
2 changes: 1 addition & 1 deletion e2e/cases/alias/tsconfig-paths-references/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rspackOnlyTest(
cwd: __dirname,
page,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@common': './src/common2',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const content = 'source.alias worked';
export const content = 'resolve.alias worked';
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
source: {
resolve: {
alias: {
'@common': './src/common2',
},
},
source: {
tsconfigPath: 'tsconfig.custom.json',
},
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const content = 'source.alias worked';
export const content = 'resolve.alias worked';
6 changes: 3 additions & 3 deletions e2e/cases/alias/tsconfig-paths/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('tsconfig paths should work and override the alias config', async ({
cwd: __dirname,
page,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@common': './src/common2',
},
Expand All @@ -29,7 +29,7 @@ test('tsconfig paths should not work when aliasStrategy is "prefer-alias"', asyn
cwd: __dirname,
page,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@/common': './src/common2',
},
Expand All @@ -39,7 +39,7 @@ test('tsconfig paths should not work when aliasStrategy is "prefer-alias"', asyn
});

const foo = page.locator('#foo');
await expect(foo).toHaveText('source.alias worked');
await expect(foo).toHaveText('resolve.alias worked');

await rsbuild.close();
});
2 changes: 1 addition & 1 deletion e2e/cases/alias/tsconfig-paths/src/common2/test.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const content = 'source.alias worked';
export const content = 'resolve.alias worked';
2 changes: 1 addition & 1 deletion e2e/cases/config/rspack-config-validate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ rspackOnlyTest(
} catch (e) {
expect(e).toBeTruthy();
expect(stripAnsi((e as Error).message)).toContain(
'rsbuild:react appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.',
'[rsbuild:plugin] "rsbuild:react" appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.',
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/css/import-common-css/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rspackOnlyTest('should compile common CSS import correctly', async () => {
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
source: {
resolve: {
alias: {
'@': './src',
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/css/resolve-alias/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pluginSass } from '@rsbuild/plugin-sass';

export default {
plugins: [pluginLess(), pluginSass()],
source: {
resolve: {
alias: {
'@common': path.resolve(__dirname, 'src/common'),
},
Expand Down
17 changes: 17 additions & 0 deletions e2e/cases/javascript-api/build/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@playwright/test';
import { createRsbuild } from '@rsbuild/core';

test('should allow to call `build` and get stats object', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
});

const { stats, close } = await rsbuild.build();

await close();

const result = stats?.toJson({ all: true })!;

expect(result.name).toBe('web');
expect(result.assets?.length).toBeGreaterThan(0);
});
1 change: 1 addition & 0 deletions e2e/cases/javascript-api/build/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello');
35 changes: 34 additions & 1 deletion e2e/cases/output/manifest/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { build } from '@e2e/helper';
import { build, dev } from '@e2e/helper';
import { expect, test } from '@playwright/test';

const fixtures = __dirname;
Expand Down Expand Up @@ -108,3 +108,36 @@ test('output.manifest when target is node', async () => {
},
});
});

test('output.manifest should always write to disk when dev', async ({
page,
}) => {
const rsbuild = await dev({
cwd: fixtures,
page,
rsbuildConfig: {
output: {
distPath: {
root: 'dist-dev',
},
manifest: true,
legalComments: 'none',
filenameHash: false,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

const files = await rsbuild.unwrapOutputJSON();

const manifestContent =
files[Object.keys(files).find((file) => file.endsWith('manifest.json'))!];

expect(manifestContent).toBeDefined();

await rsbuild.close();
});
36 changes: 36 additions & 0 deletions e2e/cases/resolve/dedupe/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { join } from 'node:path';
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { outputFileSync } from 'fs-extra';

function writeDuplicatedPackage(flag: string) {
const fooPath = join(__dirname, 'node_modules', 'foo');
outputFileSync(
join(fooPath, 'package.json'),
JSON.stringify({ name: 'foo', version: '1.0.0' }),
);
outputFileSync(
join(fooPath, 'index.js'),
'import React from "react";export default React;',
);
outputFileSync(
join(fooPath, 'node_modules', 'react', 'package.json'),
JSON.stringify({ name: 'react', version: '1.0.0' }),
);
outputFileSync(
join(fooPath, 'node_modules', 'react', 'index.js'),
`console.log("${flag}");`,
);
}

test('should dedupe specified packages as expected', async () => {
const flag = 'This is fake React';
writeDuplicatedPackage(flag);

const rsbuild = await build({
cwd: __dirname,
});

const { content } = await rsbuild.getIndexFile();
expect(content).not.toContain(flag);
});
12 changes: 12 additions & 0 deletions e2e/cases/resolve/dedupe/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
resolve: {
dedupe: ['react', 'react-dom'],
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
});
5 changes: 5 additions & 0 deletions e2e/cases/resolve/dedupe/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import foo from 'foo';
import React from 'react';
import ReactDOM from 'react-dom';

console.log(React, ReactDOM, foo);
4 changes: 2 additions & 2 deletions e2e/cases/server/ssr/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { pluginReact } from '@rsbuild/plugin-react';
export const serverRender =
(serverAPI: SetupMiddlewaresServer): RequestHandler =>
async (_req, res, _next) => {
const indexModule = await serverAPI.environments.ssr.loadBundle<{
const indexModule = await serverAPI.environments.node.loadBundle<{
render: () => string;
}>('index');

Expand Down Expand Up @@ -59,7 +59,7 @@ export default defineConfig({
},
},
},
ssr: {
node: {
output: {
target: 'node',
},
Expand Down
4 changes: 3 additions & 1 deletion e2e/cases/source/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ test.describe('source configure multi', () => {
entry: {
index: join(fixtures, 'basic/src/index.js'),
},
preEntry: ['./src/pre.js'],
},
resolve: {
alias: {
'@common': './src/common',
},
preEntry: ['./src/pre.js'],
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "@e2e/svelte",
"version": "1.0.0",
"dependencies": {
"svelte": "^5.2.7"
"svelte": "^5.4.0"
},
"devDependencies": {
"less": "^4.2.0",
"sass": "^1.81.0",
"less": "^4.2.1",
"sass": "^1.81.1",
"stylus": "0.64.0"
}
}
Loading

0 comments on commit 5531075

Please sign in to comment.