Skip to content

Commit

Permalink
Merge branch 'main' into dirname_shims_1115
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 20, 2024
2 parents c8595f3 + 660af78 commit a71523d
Show file tree
Hide file tree
Showing 104 changed files with 1,626 additions and 1,060 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:

- name: Install Dependencies
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./e2e && npx playwright install
run: pnpm install && cd ./e2e && npx playwright install chromium

- name: E2E Test
if: steps.changes.outputs.changed == 'true'
Expand Down
43 changes: 43 additions & 0 deletions e2e/cases/assets/script-as-assets/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest(
'should allow to use `new URL` to reference script as assets',
async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
page,
});

const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

const test1 = filenames.find((filename) =>
filename.includes('dist/static/assets/test1.js'),
);
const test2 = filenames.find((filename) =>
filename.includes('dist/static/assets/test2.ts'),
);
const test3 = filenames.find((filename) =>
filename.includes('dist/static/assets/test3.mjs'),
);

expect(test1).toBeDefined();
expect(test2).toBeDefined();
expect(test3).toBeDefined();

expect(files[test1!]).toEqual('export const test="test1";');
expect(files[test2!]).toContain(`export const test2: string = 'test2';`);
expect(files[test3!]).toEqual('export const test="test3";');

expect(await page.evaluate('window.test1')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test1.js`,
);
expect(await page.evaluate('window.test2')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test2.ts`,
);
expect(await page.evaluate('window.test3')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test3.mjs`,
);
},
);
7 changes: 7 additions & 0 deletions e2e/cases/assets/script-as-assets/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
output: {
filenameHash: false,
},
});
7 changes: 7 additions & 0 deletions e2e/cases/assets/script-as-assets/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const test1 = new URL('./test1.js', import.meta.url).href;
const test2 = new URL('./test2.ts', import.meta.url).href;
const test3 = new URL('./test3.mjs', import.meta.url).href;

window.test1 = test1;
window.test2 = test2;
window.test3 = test3;
1 change: 1 addition & 0 deletions e2e/cases/assets/script-as-assets/src/test1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test = 'test1';
1 change: 1 addition & 0 deletions e2e/cases/assets/script-as-assets/src/test2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test2: string = 'test2';
1 change: 1 addition & 0 deletions e2e/cases/assets/script-as-assets/src/test3.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test = 'test3';
49 changes: 49 additions & 0 deletions e2e/cases/assets/styles-as-assets/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest(
'should allow to use `new URL` to reference styles as assets',
async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
page,
});

const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

const test1 = filenames.find((filename) =>
filename.includes('dist/static/assets/test1.css'),
);
const test2 = filenames.find((filename) =>
filename.includes('dist/static/assets/test2.less'),
);
const test3 = filenames.find((filename) =>
filename.includes('dist/static/assets/test3.scss'),
);
const test4 = filenames.find((filename) =>
filename.includes('dist/static/assets/test4.styl'),
);

expect(test1).toBeDefined();
expect(test2).toBeDefined();
expect(test3).toBeDefined();
expect(test4).toBeDefined();
expect(files[test1!]).toContain('body{color:red}');
expect(files[test2!]).toContain('& .foo');
expect(files[test3!]).toContain('& .foo');
expect(files[test4!]).toContain('& .foo');
expect(await page.evaluate('window.test1')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test1.css`,
);
expect(await page.evaluate('window.test2')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test2.less`,
);
expect(await page.evaluate('window.test3')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test3.scss`,
);
expect(await page.evaluate('window.test4')).toBe(
`http://localhost:${rsbuild.port}/static/assets/test4.styl`,
);
},
);
11 changes: 11 additions & 0 deletions e2e/cases/assets/styles-as-assets/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from '@rsbuild/core';
import { pluginLess } from '@rsbuild/plugin-less';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginStylus } from '@rsbuild/plugin-stylus';

export default defineConfig({
plugins: [pluginLess(), pluginSass(), pluginStylus()],
output: {
filenameHash: false,
},
});
4 changes: 4 additions & 0 deletions e2e/cases/assets/styles-as-assets/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.test1 = new URL('./test1.css', import.meta.url).href;
window.test2 = new URL('./test2.less', import.meta.url).href;
window.test3 = new URL('./test3.scss', import.meta.url).href;
window.test4 = new URL('./test4.styl', import.meta.url).href;
3 changes: 3 additions & 0 deletions e2e/cases/assets/styles-as-assets/src/test1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: red;
}
5 changes: 5 additions & 0 deletions e2e/cases/assets/styles-as-assets/src/test2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
& .foo {
color: blue;
}
}
5 changes: 5 additions & 0 deletions e2e/cases/assets/styles-as-assets/src/test3.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
& .foo {
color: green;
}
}
5 changes: 5 additions & 0 deletions e2e/cases/assets/styles-as-assets/src/test4.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
& .foo {
color: yellow;
}
}
17 changes: 17 additions & 0 deletions e2e/cases/config/stats-module-trace/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { build, proxyConsole } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should log error module trace', async () => {
const { restore, logs } = proxyConsole();

await expect(
build({
cwd: __dirname,
rsbuildConfig: {},
}),
).rejects.toThrowError('build failed');

expect(logs.some((log) => log.includes('@ ./src/index.tsx'))).toBeTruthy();

restore();
});
1 change: 1 addition & 0 deletions e2e/cases/config/stats-module-trace/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './test';
1 change: 1 addition & 0 deletions e2e/cases/config/stats-module-trace/src/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './test1';
2 changes: 1 addition & 1 deletion e2e/cases/config/stats-options/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('should log warning by default', async () => {
logs.some((log) =>
log.includes('Using / for division outside of calc() is deprecated'),
),
);
).toBeTruthy();

restore();
});
Expand Down
47 changes: 47 additions & 0 deletions e2e/cases/server/print-urls/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,50 @@ test('should print server urls when HTML is disabled but printUrls is a custom f
await rsbuild.close();
restore();
});

test('should get posix route correctly', async ({ page }) => {
const { logs, restore } = proxyConsole('log');

const rsbuild = await dev({
cwd,
rsbuildConfig: {
server: {
printUrls: ({ urls, routes }) => {
expect(routes[0].pathname).toBe('/dist/');
expect(routes[1].pathname).toBe('/.dist/web1/index1');
return urls;
},
},
environments: {
web: {},
web1: {
source: {
entry: {
index1: './src/index.js',
},
},
output: {
distPath: {
root: '.dist/web1',
},
},
},
},
},
});

await page.goto(`http://localhost:${rsbuild.port}`);

const webLog = logs.find((log) =>
log.includes(`http://localhost:${rsbuild.port}/dist/`),
);
const web1Log = logs.find((log) =>
log.includes(`http://localhost:${rsbuild.port}/.dist/web1/index1`),
);

expect(webLog).toBeTruthy();
expect(web1Log).toBeTruthy();

await rsbuild.close();
restore();
});
4 changes: 2 additions & 2 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.1.13"
"svelte": "^5.2.4"
},
"devDependencies": {
"less": "^4.2.0",
"sass": "^1.80.6",
"sass": "^1.81.0",
"stylus": "0.64.0"
}
}
2 changes: 1 addition & 1 deletion e2e/cases/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "@e2e/vue3",
"version": "1.0.0",
"dependencies": {
"vue": "^3.5.12"
"vue": "^3.5.13"
}
}
8 changes: 4 additions & 4 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react-dom": "^18.3.1",
"react-router-dom": "^6.28.0",
"solid-js": "^1.9.3",
"vue": "^3.5.12",
"vue": "^3.5.13",
"vue-router": "^4.4.5"
},
"devDependencies": {
Expand All @@ -38,18 +38,18 @@
"@rsbuild/plugin-vue": "workspace:*",
"@rsbuild/plugin-vue-jsx": "^1.0.1",
"@rsbuild/webpack": "workspace:*",
"@module-federation/rspack": "0.7.1",
"@module-federation/rspack": "0.7.6",
"@scripts/test-helper": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.13",
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"create-rsbuild": "workspace:*",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"playwright": "1.44.1",
"tailwindcss": "^3.4.14",
"tailwindcss": "^3.4.15",
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion examples/module-federation-v2/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@module-federation/rspack": "0.7.1",
"@module-federation/rspack": "0.7.6",
"@rsbuild/core": "workspace:*",
"@rsbuild/plugin-react": "workspace:*"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/module-federation-v2/remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@module-federation/rspack": "0.7.1",
"@module-federation/rspack": "0.7.6",
"@rsbuild/core": "workspace:*",
"@rsbuild/plugin-react": "workspace:*"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion examples/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"preview": "rsbuild preview"
},
"dependencies": {
"svelte": "^5.1.13"
"svelte": "^5.2.4"
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"preview": "rsbuild preview"
},
"dependencies": {
"vue": "^3.5.12"
"vue": "^3.5.13"
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"cross-env": "^7.0.3",
"cspell-ban-words": "^0.0.4",
"nano-staged": "^0.8.0",
"nx": "^20.1.0",
"nx": "^20.1.2",
"prettier": "^3.3.3",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.6.3",
"vitest": "^2.1.4"
"vitest": "^2.1.5"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/plugin-webpack-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsbuild/plugin-webpack-swc",
"version": "1.0.7",
"version": "1.0.8",
"description": "SWC plugin for Rsbuild webpack provider",
"repository": {
"type": "git",
Expand All @@ -27,7 +27,6 @@
},
"dependencies": {
"@modern-js/swc-plugins": "0.6.11",
"@rslib/core": "0.0.18",
"@swc/helpers": "^0.5.15",
"core-js": "~3.39.0",
"deepmerge": "^4.3.1",
Expand All @@ -38,6 +37,7 @@
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@rsbuild/webpack": "workspace:*",
"@rslib/core": "0.0.18",
"@types/lodash": "^4.17.13",
"@types/semver": "^7.5.8",
"typescript": "^5.6.3",
Expand Down
Loading

0 comments on commit a71523d

Please sign in to comment.