Skip to content

Commit

Permalink
feat: big upgrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Sep 9, 2024
1 parent 58cbbe2 commit 629a206
Show file tree
Hide file tree
Showing 23 changed files with 7,184 additions and 6,763 deletions.
4 changes: 2 additions & 2 deletions examples/with-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"@types/react-dom": "^18.0.2",
"express": "^4.19.2",
"tslib": "^2.5.0",
"tsx": "^3.12.1"
"tsx": "^4.19.0"
}
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"stylelint": "^15.10.1",
"tsx": "^3.12.1",
"tsx": "^4.19.0",
"typescript": "^4.7.4",
"vitest": "^0.15.2"
},
Expand All @@ -71,7 +71,6 @@
"packageManager": "[email protected]",
"pnpm": {
"patchedDependencies": {
"@rspack/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/bundles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"mime-types": "2.1.35"
},
"devDependencies": {
"@rspack/plugin-react-refresh": "0.5.7",
"@rspack/dev-server": "0.5.7",
"@rspack/core": "0.5.7",
"@rspack/plugin-react-refresh": "1.0.0",
"@rspack/dev-server": "1.0.3",
"@rspack/core": "1.0.3",
"@types/less": "^3.0.3",
"@types/lodash": "^4.14.181",
"@types/webpack-bundle-analyzer": "^4.4.1",
Expand Down Expand Up @@ -82,9 +82,9 @@
"terser-webpack-plugin": "5.3.5",
"typescript": "^4.6.4",
"trusted-cert": "1.1.3",
"webpack": "5.88.2",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-dev-server": "4.15.0",
"webpack-dev-server": "5.1.0",
"unplugin": "1.6.0",
"bonjour-service": "^1.0.13",
"colorette": "^2.0.10",
Expand Down
17 changes: 8 additions & 9 deletions packages/bundles/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { fileURLToPath } from 'url';
import fs from 'fs-extra';
import ncc from '@vercel/ncc';
import chalk from 'chalk';
import * as dts from 'dts-bundle';
import glob from 'glob';
import findUp from 'find-up';
import tasks, { taskExternals } from './tasks';
Expand Down Expand Up @@ -121,14 +120,14 @@ export async function packDependency(options: Options): Promise<void> {
if (pkgJson.types) {
dtsName = 'index.d.ts';
console.log(chalk.green(`bundle dts file for ${pkgName || file}`));
dts.bundle({
name: pkgJson.name,
outputAsModuleFolder: true,
out: path.join(targetPath, dtsName),
main: path.join(packageRoot, pkgJson.types),
headerPath: '',
headerText: '',
});
// dts.bundle({
// name: pkgJson.name,
// outputAsModuleFolder: true,
// out: path.join(targetPath, dtsName),
// main: path.join(packageRoot, pkgJson.types),
// headerPath: '',
// headerText: '',
// });
} else {
try {
const typesRoot = path.dirname(require.resolve(`@types/${pkgName}/package.json`, {
Expand Down
25 changes: 13 additions & 12 deletions packages/bundles/scripts/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const tasks = [
const targetPath = path.join(__dirname, '../compiled/mini-css-extract-plugin');
const entryPath = path.join(targetPath, 'dist/index.js');
fs.copySync(path.join(pkgPath, 'dist'), path.join(targetPath, 'dist'));
fs.copyFileSync(path.join(targetPath, 'index.d.ts'), path.join(targetPath, 'dist/index.d.ts'));
fs.copySync(path.join(pkgPath, 'types'), path.join(targetPath, 'types'));
fs.writeFileSync(entryPath, fs.readFileSync(entryPath, 'utf-8').replace('schema-utils', '@ice/bundles/compiled/schema-utils/index.js'));
},
},
Expand Down Expand Up @@ -295,22 +295,23 @@ const tasks = [
const sourcePath = path.join(pkgPath, filePath);
const targetPath = path.join(__dirname, `../compiled/@rspack/plugin-react-refresh/${filePath}`);
if (path.extname(filePath) === '.js') {
const fileContent = fs.readFileSync(sourcePath, 'utf8');
fs.writeFileSync(targetPath,
replaceDeps(fileContent, webpackDevServerDeps.concat([
...commonDeps,
'@rspack/core',
])),
);
// const fileContent = fs.readFileSync(sourcePath, 'utf8');
// fs.writeFileSync(targetPath,
// replaceDeps(fileContent, webpackDevServerDeps.concat([
// ...commonDeps,
// // '@rspack/core',
// ])),
// );
fs.copyFileSync(sourcePath, targetPath);
} else {
fs.copyFileSync(sourcePath, targetPath);
}
});
// Overwrite RefreshUtils.js which is customized for ice.js.
fs.copyFileSync(
path.join(__dirname, '../override/RefreshUtils.js'),
path.join(__dirname, '../compiled/@rspack/plugin-react-refresh/client/refreshUtils.js'),
);
// fs.copyFileSync(
// path.join(__dirname, '../override/RefreshUtils.js'),
// path.join(__dirname, '../compiled/@rspack/plugin-react-refresh/client/refreshUtils.js'),
// );
},
},
];
Expand Down
6 changes: 3 additions & 3 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
"sass": "^1.50.0",
"unplugin": "^1.6.0",
"webpack": "^5.88.0",
"webpack-dev-server": "4.15.0",
"@rspack/core": "0.5.7",
"@rspack/dev-server": "0.5.7"
"webpack-dev-server": "5.1.0",
"@rspack/core": "1.0.3",
"@rspack/dev-server": "1.0.3"
},
"peerDependencies": {
"react": ">=18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/bundler/config/getUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getUrls = ({
devServerConfig,
}: Options) => {
const urlPathname = getRouterBasename(taskConfig, appConfig) || '/';
const protocol = devServerConfig.https ? 'https' : 'http';
const protocol = typeof devServerConfig?.server === 'object' && devServerConfig?.server.type === 'https' ? 'https' : 'http';
const enabledHashRouter = appConfig.router?.type === 'hash';
const urls = prepareURLs(
protocol,
Expand Down
4 changes: 1 addition & 3 deletions packages/ice/src/bundler/rspack/formatStats.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import chalk from 'chalk';
import type { Stats, MultiStats } from '@rspack/core';
import type { StatsCompilation } from 'webpack';
import formatWebpackMessages from '../../utils/formatWebpackMessages.js';

function formatStats(stats: Stats | MultiStats, showWarnings = true) {
const statsData = stats.toJson({
preset: 'errors-warnings',
}) as StatsCompilation;

});
const { errors, warnings } = formatWebpackMessages(statsData);

if (errors.length) {
Expand Down
3 changes: 1 addition & 2 deletions packages/ice/src/bundler/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function bundler(
let compiler: MultiCompiler;
let dataLoaderCompiler: Compiler;
let devServer: RspackDevServer;
const { rspack } = await import('@ice/bundles/esm/rspack.js');
const { rspack } = await import('@rspack/core');
// Override the type of rspack, because of rspack is imported from pre-compiled bundle.
const rspackConfigs = await getConfig(context, options, rspack as unknown as typeof Rspack);
try {
Expand Down Expand Up @@ -65,7 +65,6 @@ async function bundler(
rspackConfigs,
};
if (command === 'start') {
// @ts-expect-error dev-server has been pre-packed, so it will have different type.
devServer = await start(buildOptions, dataLoaderCompiler);
} else if (command === 'build') {
await build(buildOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/bundler/rspack/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const start = async ({
...hooksAPI,
});

const { RspackDevServer } = await import('@ice/bundles/esm/dev-server.js');
const { RspackDevServer } = await import('@rspack/dev-server');
const devServer = new RspackDevServer(devServerConfig, compiler);

compiler.hooks.done.tap('done', async stats => {
Expand Down
1 change: 0 additions & 1 deletion packages/ice/src/bundler/webpack/getWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const getWebpackConfig: GetWebpackConfig = async (context, options) => {
let webpackConfig = getDefaultWebpackConfig({
config,
rootDir,
// @ts-expect-error fix type error of compiled webpack
webpack,
runtimeTmpDir: RUNTIME_TMP_DIR,
userConfigHash,
Expand Down
1 change: 0 additions & 1 deletion packages/ice/src/bundler/webpack/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function startDevServer(
// Sort by length, shortest path first.
a.split('/').filter(Boolean).length - b.split('/').filter(Boolean).length);
const webTaskConfig = taskConfigs.find(({ name }) => name === WEB);
// @ts-expect-error webpack-dev-server types in Configuration is missing.
const originalDevServer: DevServerConfiguration = webpackConfigs[0].devServer;
const customMiddlewares = originalDevServer?.setupMiddlewares;
const defaultDevServerConfig = await getDefaultServerConfig(originalDevServer, commandArgs);
Expand Down
1 change: 0 additions & 1 deletion packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ const cliOption = [
if (host && host !== 'localhost') {
hosts.push(host);
}
// @ts-expect-error certificateFor types
const certInfo = await certificateFor(hosts, { silent: true });
const key = await fse.readFile(certInfo.keyFilePath, 'utf8');
const cert = await fse.readFile(certInfo.certFilePath, 'utf8');
Expand Down
6 changes: 4 additions & 2 deletions packages/ice/src/middlewares/dataLoaderMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export default function createDataLoaderMiddleware(compiler: Compiler): Middlewa
if (method !== 'GET') {
return next();
}
const publicPath = compiler.options.output?.publicPath
? `${compiler.options.output.publicPath.replace(/\/$/, '')}/`
const orginalPublicPath = compiler.options.output?.publicPath;
const publicPath = orginalPublicPath && typeof orginalPublicPath === 'string'
? `${orginalPublicPath.replace(/\/$/, '')}/`
: '/';
const filePath = parse(url || '').pathname;
const filename = filePath?.startsWith(publicPath) ? filePath.slice(publicPath.length) : filePath.slice(1);
// Mark sure the compiler is ready.
await compileTask;
// @ts-expect-error
const buffer = compiler.getAsset(filename);

if (!buffer) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ice/src/utils/formatWebpackMessages.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// This file is based on https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/formatWebpackMessages.js
// It's been rewrite to ts and ICE specific logic
import type { StatsCompilation } from 'webpack';
import type { StatsCompilation as RspackStatsCompilation } from '@rspack/core';

const friendlySyntaxErrorLabel = 'Syntax error:';

type IsLikelyASyntaxError = (message: string) => boolean;
type Message = string | { message: string } | { message: string }[];
type FormatMessage = (message: Message) => string;
type FormatWebpackMessages = (
json: StatsCompilation,
json: StatsCompilation | RspackStatsCompilation,
) => { errors: string[]; warnings: string[] };

const isLikelyASyntaxError: IsLikelyASyntaxError = message => {
Expand Down
1 change: 0 additions & 1 deletion packages/ice/src/webpack/ServerCompilerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default class ServerCompilerPlugin {
compiler.hooks.watchRun.tap(pluginName, () => {
this.isCompiling = true;
});
// @ts-expect-error webpack hooks type not match.
compiler.hooks.emit.tapPromise(pluginName, async (compilation: Compilation) => {
this.isCompiling = false;
await this.compileTask(compilation);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/accept-language-parser": "^1.5.3",
"@types/react": "^18.0.33",
"cross-env": "^7.0.3",
"webpack-dev-server": "4.15.0"
"webpack-dev-server": "5.1.0"
},
"peerDependencies": {
"@ice/app": "^3.4.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"build-scripts": "^2.1.2-0",
"esbuild": "^0.17.16",
"webpack": "^5.88.0",
"webpack-dev-server": "4.15.0"
"webpack-dev-server": "5.1.0"
},
"repository": {
"type": "http",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@ice/shared-config": "1.2.8"
},
"devDependencies": {
"@rspack/core": "0.5.7"
"@rspack/core": "1.0.3"
},
"scripts": {
"watch": "tsc -w --sourceMap",
Expand Down
Loading

0 comments on commit 629a206

Please sign in to comment.