Skip to content

Commit

Permalink
Merge branch 'main' into fix-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe authored Nov 7, 2023
2 parents 9507efe + 96ede9e commit 9e97f32
Show file tree
Hide file tree
Showing 197 changed files with 525 additions and 3,721 deletions.
6 changes: 6 additions & 0 deletions .changeset/dirty-ligers-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime': patch
---

fix: remake server ssr logger msg
fix: 重写 ssr server 日志信息
22 changes: 22 additions & 0 deletions .changeset/eighty-scissors-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@modern-js/plugin-router-v5': minor
'@modern-js/plugin-garfish': minor
'@modern-js/runtime': minor
'@modern-js/plugin-testing': minor
'@modern-js/module-tools': minor
'@modern-js/plugin-worker': minor
'@modern-js/plugin-tailwindcss': minor
'@modern-js/app-tools': minor
'@modern-js/main-doc': minor
'@modern-js/plugin-proxy': minor
'@modern-js/plugin-devtools': minor
'@modern-js/plugin-bff': minor
'@modern-js/plugin-ssg': minor
'@modern-js/plugin-swc': minor
'@modern-js/utils': minor
'@modern-js/core': minor
'@scripts/prebundle': minor
---

chore: remove ajv schema verification of configuration
chore: 移除 ajv 对项目配置的校验
7 changes: 7 additions & 0 deletions .changeset/late-cows-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/builder-rspack-provider': patch
---

chore(builder): update rspack to 0.3.10 and fix deprecate warning

chore(builder): 升级 rspack 到 0.3.10 并修复 deprecate warning
6 changes: 6 additions & 0 deletions .changeset/red-laws-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/module-tools': patch
---

chore(module-tools): remove unuse schema
chore(module-tools): 移除没有使用的 schema
6 changes: 6 additions & 0 deletions .changeset/tough-shoes-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/builder-doc': patch
---

doc(builder-doc): add version tip for sourceBuild api
doc(builder-doc): 为 sourceBuild API 添加版本提示信息
6 changes: 6 additions & 0 deletions .changeset/unlucky-adults-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': patch
---

fix(prod-server): inject reporter from req
fix(prod-server): 从 req 里拿到 reporter 去注入
6 changes: 3 additions & 3 deletions packages/builder/builder-rspack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"@modern-js/types": "workspace:*",
"@modern-js/utils": "workspace:*",
"@babel/preset-typescript": "^7.22.15",
"@rspack/core": "0.3.8",
"@rspack/dev-client": "0.3.8",
"@rspack/plugin-html": "0.3.8",
"@rspack/core": "0.3.10",
"@rspack/dev-client": "0.3.10",
"@rspack/plugin-html": "0.3.10",
"@swc/helpers": "0.5.1",
"rspack-manifest-plugin": "5.0.0-alpha0",
"caniuse-lite": "^1.0.30001520",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ export async function generateRspackConfig({
context: Context;
}) {
const chainUtils = await getChainUtils(target);
const { BannerPlugin, DefinePlugin } = await import('@rspack/core');
const { BannerPlugin, DefinePlugin, ProvidePlugin } = await import(
'@rspack/core'
);

const chain = await modifyBundlerChain(context, {
...chainUtils,
bundler: {
BannerPlugin,
DefinePlugin,
ProvidePlugin,
},
});

Expand Down
23 changes: 17 additions & 6 deletions packages/builder/builder-rspack-provider/src/plugins/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ export const builderPluginReact = (): BuilderPlugin => ({
// https://swc.rs/docs/configuration/compilation#jsctransformreactruntime
runtime: 'automatic',
});
});

setConfig(rspackConfig, 'builtins.provide', {
...(rspackConfig.builtins?.provide || {}),
$ReactRefreshRuntime$: [
require.resolve('@rspack/dev-client/react-refresh'),
],
});
api.modifyBundlerChain(async (chain, utils) => {
const config = api.getNormalizedConfig();

const usingHMR = isUsingHMR(config, utils);

const { bundler } = utils;

if (usingHMR) {
chain.plugin('ReactRefreshRuntime').use(bundler.ProvidePlugin, [
{
$ReactRefreshRuntime$: [
require.resolve('@rspack/dev-client/react-refresh'),
],
},
]);
}
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
"not op_mini all",
],
},
"provide": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"react": {
"development": true,
"refresh": true,
Expand Down Expand Up @@ -702,6 +697,14 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"name": "ProgressPlugin",
},
Plugin {
"_options": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"name": "ProvidePlugin",
},
],
"resolve": {
"alias": {
Expand Down Expand Up @@ -765,11 +768,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
"not op_mini all",
],
},
"provide": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"react": {
"development": false,
"refresh": false,
Expand Down Expand Up @@ -1541,11 +1539,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctyly when targ
"node >= 14",
],
},
"provide": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"react": {
"development": true,
"refresh": false,
Expand Down Expand Up @@ -2011,11 +2004,6 @@ exports[`tools.rspack > should match snapshot 1`] = `
"not op_mini all",
],
},
"provide": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"react": {
"development": true,
"refresh": true,
Expand Down Expand Up @@ -2683,6 +2671,14 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
"name": "ProgressPlugin",
},
Plugin {
"_options": {
"$ReactRefreshRuntime$": [
"<WORKSPACE>/node_modules/<PNPM_INNER>/@rspack/dev-client/src/reactRefresh.js",
],
},
"name": "ProvidePlugin",
},
],
"resolve": {
"alias": {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/builder-shared/src/apply/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ModifyChainUtils, SharedNormalizedConfig } from '../types';

export function isUsingHMR(
config: SharedNormalizedConfig,
{ isProd, target }: ModifyChainUtils,
{ isProd, target }: Pick<ModifyChainUtils, 'isProd' | 'target'>,
) {
return (
!isProd &&
Expand Down
1 change: 1 addition & 0 deletions packages/builder/builder-shared/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type ModifyBundlerChainUtils = ModifyChainUtils & {
bundler: {
BannerPlugin: WebpackPluginInstance;
DefinePlugin: WebpackPluginInstance;
ProvidePlugin: WebpackPluginInstance;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ export async function generateWebpackConfig({
context: Context;
}) {
const chainUtils = await getChainUtils(target);
const { BannerPlugin, DefinePlugin } = await import('webpack');
const { BannerPlugin, DefinePlugin, ProvidePlugin } = await import('webpack');

const bundlerChain = await modifyBundlerChain(context, {
...chainUtils,
bundler: {
BannerPlugin,
DefinePlugin,
ProvidePlugin,
},
});

Expand Down
32 changes: 5 additions & 27 deletions packages/builder/plugin-node-polyfill/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { setConfig } from '@modern-js/builder-shared';
import type { BuilderPlugin } from '@modern-js/builder';
import type { BuilderPluginAPI as WebpackBuilderPluginAPI } from '@modern-js/builder-webpack-provider';
import type { BuilderPluginAPI as RspackBuilderPluginAPI } from '@modern-js/builder-rspack-provider';
Expand Down Expand Up @@ -41,7 +40,7 @@ export function builderPluginNodePolyfill(): BuilderPlugin<
name: 'builder-plugin-node-polyfill',

async setup(api) {
api.modifyBundlerChain(async (chain, { isServer }) => {
api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, bundler }) => {
// it had not need `node polyfill`, if the target is 'node'(server runtime).
if (isServer) {
return;
Expand All @@ -54,32 +53,11 @@ export function builderPluginNodePolyfill(): BuilderPlugin<

// module polyfill
chain.resolve.fallback.merge(getResolveFallback(nodeLibs));
});

if (api.context.bundlerType === 'rspack') {
(api as RspackBuilderPluginAPI).modifyRspackConfig(
async (config, { isServer }) => {
if (isServer) {
return;
}
setConfig(config, 'builtins.provide', {
...(config.builtins?.provide ?? {}),
...(await getProvideLibs()),
});
},
);
} else {
(api as WebpackBuilderPluginAPI).modifyWebpackChain(
async (chain, { CHAIN_ID, isServer, webpack }) => {
if (isServer) {
return;
}
chain
.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE)
.use(webpack.ProvidePlugin, [await getProvideLibs()]);
},
);
}
chain
.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE)
.use(bundler.ProvidePlugin, [await getProvideLibs()]);
});
},
};
}
Expand Down
69 changes: 3 additions & 66 deletions packages/cli/core/src/config/createResolvedConfig.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { createDebugger, logger } from '@modern-js/utils';
import type { ErrorObject } from '@modern-js/utils/ajv';
import { patchSchema } from '../schema/patchSchema';
import type {
UserConfig,
NormalizedConfig,
LoadedConfig,
PluginValidateSchema,
} from '../types';
import { repeatKeyWarning } from '../utils/repeatKeyWarning';
import { createDebugger } from '@modern-js/utils';
import type { UserConfig, NormalizedConfig, LoadedConfig } from '../types';
import { mergeConfig } from '../utils/mergeConfig';
import { createDefaultConfig } from './createDefaultConfig';

Expand All @@ -17,64 +9,9 @@ export const createResolveConfig = async (
// eslint-disable-next-line @typescript-eslint/ban-types
loaded: LoadedConfig<{}>,
configs: UserConfig[],
schemas: PluginValidateSchema[],
onSchemaError?: (error: ErrorObject) => void | Promise<void>,
): Promise<NormalizedConfig> => {
const { default: Ajv } = await import('@modern-js/utils/ajv');
const { default: ajvKeywords } = await import(
'@modern-js/utils/ajv-keywords'
);
const { default: betterAjvErrors } = await import(
'@modern-js/utils/better-ajv-errors'
);

const { config: userConfig, jsConfig, pkgConfig } = loaded;

const ajv = new Ajv({ $data: true, strict: false });

ajvKeywords(ajv);

const validateSchema = patchSchema(schemas);
const validate = ajv.compile(validateSchema);

repeatKeyWarning(validateSchema, jsConfig, pkgConfig);

// validate user config.
const valid = validate(userConfig);

const formatValidateError = (config: UserConfig) =>
betterAjvErrors(
validateSchema,
config,
validate.errors?.map(e => ({
...e,
dataPath: e.instancePath,
})),
{
indent: 2,
},
);

if (!valid && validate.errors?.length) {
if (onSchemaError) {
await onSchemaError(validate?.errors[0]);
}
const errors = formatValidateError(userConfig);
logger.log(errors);
throw new Error(`Validate configuration error`);
}

// validate config from plugins.
for (const config of configs) {
if (!validate(config)) {
const errors = formatValidateError(config);
logger.error(errors);
throw new Error(`Validate configuration error.`);
}
}

const { config: userConfig } = loaded;
const resolved = mergeConfig([createDefaultConfig(), ...configs, userConfig]);

debug('resolved %o', resolved);

return resolved;
Expand Down
9 changes: 1 addition & 8 deletions packages/cli/core/src/createCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,7 @@ export const createCli = () => {

const extraConfigs = await hooksRunner.config();

const extraSchemas = await hooksRunner.validateSchema();

const normalizedConfig = await createResolveConfig(
loaded,
extraConfigs,
extraSchemas,
options?.onSchemaError,
);
const normalizedConfig = await createResolveConfig(loaded, extraConfigs);

const { resolved } = await hooksRunner.resolvedConfig({
resolved: normalizedConfig,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/core/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const baseHooks: BaseHooks<{}> = {
beforeConfig: createAsyncWorkflow(),
config: createParallelWorkflow(),
resolvedConfig: createAsyncWaterfall(),
validateSchema: createParallelWorkflow(),
prepare: createAsyncWorkflow(),
afterPrepare: createAsyncWorkflow(),
commands: createAsyncWorkflow(),
Expand Down
Loading

0 comments on commit 9e97f32

Please sign in to comment.