Skip to content

Commit

Permalink
fix: use applyOptionsChain
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Oct 19, 2023
1 parent 2f6179f commit 6722e3e
Show file tree
Hide file tree
Showing 9 changed files with 2,287 additions and 107 deletions.
2 changes: 1 addition & 1 deletion packages/generator/generator-cases/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('test generator cases', () => {
});
test('test getMWANewCases', async () => {
const mwaNewCases = getMWANewCases();
expect(mwaNewCases.length).toBe(13);
expect(mwaNewCases.length).toBe(14);
});
test('test getModuleNewCases', async () => {
const moduleNewCases = getModuleNewCases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ describe('new action test', () => {
expect(ActionFunctionText[ActionFunction.Proxy]()).toBe('启用「全局代理」');
});
it('mwa', () => {
expect(MWAActionFunctions.length).toBe(10);
expect(MWAActionFunctions.length).toBe(11);
});
});
12 changes: 0 additions & 12 deletions packages/storybook/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@
"@types/webpack-hot-middleware": "^2.25.6",
"typescript": "^5.2.2"
},
"peerDependencies": {
"@modern-js/builder-rspack-provider": "workspace:^2.34.0",
"@modern-js/builder-webpack-provider": "workspace:^2.34.0"
},
"peerDependenciesMeta": {
"@modern-js/builder-rspack-provider": {
"optional": true
},
"@modern-js/builder-webpack-provider": {
"optional": true
}
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const resolvePlugins = (runtime: IConfig['modernConfigRuntime']) => {
plugins.push(state(runtime.state));
}
} else if (api === allowedRuntimeAPI.router) {
// TODO: React Router v6 is not supported yet
plugins.push(
router({
...{ serverBase: ['/'] },
Expand Down
24 changes: 14 additions & 10 deletions packages/storybook/builder/src/plugin-storybook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
import { isAbsolute, join, resolve } from 'path';
import { slash, watch, globby } from '@modern-js/utils';
import { slash, watch, globby, applyOptionsChain } from '@modern-js/utils';
import {
BuilderPlugin,
SharedBuilderConfig,
Expand Down Expand Up @@ -186,11 +186,13 @@ async function prepareStorybookModules(
const [mappingsAlias, write] = await virtualModule(tempDir, cwd, mappings);

builderConfig.source ??= {};
builderConfig.source.alias = {
...builderConfig.source.alias,
...storybookPaths,
...mappingsAlias,
};
builderConfig.source.alias = applyOptionsChain(
{
...storybookPaths,
...mappingsAlias,
},
builderConfig.source.alias,
);

if (isDev()) {
const watcher = await watchStories(storyPatterns, cwd, write);
Expand Down Expand Up @@ -424,10 +426,12 @@ async function applyReact(config: AllBuilderConfig, options: Options) {
const useReact17 = legacyRootApi ?? !isReact18;
if (!useReact17) {
config.source ??= {};
config.source.alias ??= {};
// @ts-expect-error
config.source.alias['@storybook/react-dom-shim'] =
'@storybook/react-dom-shim/dist/react-18';
config.source.alias = applyOptionsChain(
{
'@storybook/react-dom-shim': '@storybook/react-dom-shim/dist/react-18',
},
config.source.alias,
);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/storybook/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@modern-js/storybook-builder": "workspace:*",
"@storybook/react": "^7.4.6",
"@modern-js/utils": "workspace:*",
"storybook": "^7.4.6"
},
"devDependencies": {
Expand Down
11 changes: 7 additions & 4 deletions packages/storybook/framework/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import type { Options } from '@storybook/types';
import type { BuilderConfig } from '@modern-js/storybook-builder/types';
import { applyOptionsChain } from '@modern-js/utils';

export const frameworkOptions = async (_: never, options: Options) => {
const config = await options.presets.apply('framework');
Expand Down Expand Up @@ -35,10 +36,12 @@ export const modern = (
...config,
source: {
...config.source,
alias: {
...config.source?.alias,
'@storybook/react': absPath('@storybook/react'),
},
alias: applyOptionsChain(
{
'@storybook/react': absPath('@storybook/react'),
},
config.source?.alias,
),
},
};
};
Expand Down
8 changes: 0 additions & 8 deletions packages/storybook/framework/src/upgrade.ts

This file was deleted.

Loading

0 comments on commit 6722e3e

Please sign in to comment.