@modern-js/module-tools 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/js/modern/cli/build.js +2 -2
- package/dist/js/modern/cli/dev.js +2 -2
- package/dist/js/modern/commands/build.js +4 -5
- package/dist/js/modern/commands/dev.js +6 -7
- package/dist/js/modern/features/build/build-platform.js +3 -3
- package/dist/js/modern/features/build/build-watch.js +5 -6
- package/dist/js/modern/features/build/build.js +5 -6
- package/dist/js/modern/features/build/index.js +5 -5
- package/dist/js/modern/features/build/utils.js +9 -10
- package/dist/js/modern/features/dev/index.js +9 -7
- package/dist/js/modern/index.js +37 -37
- package/dist/js/node/cli/build.js +2 -2
- package/dist/js/node/cli/dev.js +2 -2
- package/dist/js/node/commands/build.js +4 -6
- package/dist/js/node/commands/dev.js +6 -8
- package/dist/js/node/features/build/build-platform.js +3 -4
- package/dist/js/node/features/build/build-watch.js +5 -7
- package/dist/js/node/features/build/build.js +5 -7
- package/dist/js/node/features/build/index.js +5 -5
- package/dist/js/node/features/build/utils.js +9 -11
- package/dist/js/node/features/dev/index.js +9 -8
- package/dist/js/node/index.js +50 -42
- package/dist/types/cli/build.d.ts +2 -1
- package/dist/types/cli/dev.d.ts +2 -1
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/features/build/build-platform.d.ts +2 -1
- package/dist/types/features/build/build-watch.d.ts +2 -2
- package/dist/types/features/build/build.d.ts +2 -2
- package/dist/types/features/build/index.d.ts +2 -2
- package/dist/types/features/build/utils.d.ts +4 -3
- package/dist/types/features/dev/index.d.ts +4 -3
- package/dist/types/index.d.ts +3 -19
- package/package.json +8 -8
- package/tests/dev-cli.test.ts +42 -8
- package/tests/dev-command.test.ts +36 -10
- package/tests/dev-feature.test.ts +45 -13
|
@@ -26,16 +26,14 @@ const lg = _utils.Import.lazy('./logger', require);
|
|
|
26
26
|
|
|
27
27
|
const constants = _utils.Import.lazy('./constants', require);
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const buildSourceCode = async (config, _) => {
|
|
29
|
+
const buildSourceCode = async (api, config, _) => {
|
|
32
30
|
const {
|
|
33
31
|
sourceDir,
|
|
34
32
|
enableTscCompiler
|
|
35
33
|
} = config;
|
|
36
34
|
const {
|
|
37
35
|
appDirectory
|
|
38
|
-
} =
|
|
36
|
+
} = api.useAppContext();
|
|
39
37
|
const concurrency = os.cpus().length;
|
|
40
38
|
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
41
39
|
const lm = new lg.LoggerManager();
|
|
@@ -51,15 +49,15 @@ const buildSourceCode = async (config, _) => {
|
|
|
51
49
|
const copyLog = lm.createLoggerText({
|
|
52
50
|
title: 'Copy Log:'
|
|
53
51
|
});
|
|
54
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
55
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
52
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
53
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
56
54
|
logger: codeLog,
|
|
57
55
|
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
58
56
|
config,
|
|
59
57
|
willCompilerDirOrFile: sourceDir,
|
|
60
58
|
initMapper: initCodeMapper,
|
|
61
59
|
srcRootDir
|
|
62
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
60
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
63
61
|
logger: styleLog,
|
|
64
62
|
taskPath: require.resolve("../../tasks/build-style")
|
|
65
63
|
}, {
|
|
@@ -17,7 +17,7 @@ const buildWatchFeature = _utils.Import.lazy('./build-watch', require);
|
|
|
17
17
|
|
|
18
18
|
const bp = _utils.Import.lazy('./build-platform', require);
|
|
19
19
|
|
|
20
|
-
const build = async (config, modernConfig) => {
|
|
20
|
+
const build = async (api, config, modernConfig) => {
|
|
21
21
|
const {
|
|
22
22
|
appDirectory,
|
|
23
23
|
enableWatchMode,
|
|
@@ -33,7 +33,7 @@ const build = async (config, modernConfig) => {
|
|
|
33
33
|
|
|
34
34
|
if (typeof platform === 'boolean' && platform) {
|
|
35
35
|
if (process.env.RUN_PLATFORM) {
|
|
36
|
-
await bp.buildPlatform({
|
|
36
|
+
await bp.buildPlatform(api, {
|
|
37
37
|
platform: 'all',
|
|
38
38
|
isTsProject
|
|
39
39
|
});
|
|
@@ -44,7 +44,7 @@ const build = async (config, modernConfig) => {
|
|
|
44
44
|
|
|
45
45
|
if (typeof platform === 'string') {
|
|
46
46
|
if (process.env.RUN_PLATFORM) {
|
|
47
|
-
await bp.buildPlatform({
|
|
47
|
+
await bp.buildPlatform(api, {
|
|
48
48
|
platform,
|
|
49
49
|
isTsProject
|
|
50
50
|
});
|
|
@@ -58,9 +58,9 @@ const build = async (config, modernConfig) => {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (enableWatchMode) {
|
|
61
|
-
await buildWatchFeature.buildInWatchMode(config, modernConfig);
|
|
61
|
+
await buildWatchFeature.buildInWatchMode(api, config, modernConfig);
|
|
62
62
|
} else {
|
|
63
|
-
await buildFeature.buildSourceCode(config, modernConfig);
|
|
63
|
+
await buildFeature.buildSourceCode(api, config, modernConfig);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
@@ -15,9 +15,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
17
|
|
|
18
|
-
const constants = _utils.Import.lazy('./constants', require);
|
|
19
|
-
|
|
20
|
-
const core = _utils.Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
|
|
18
|
+
const constants = _utils.Import.lazy('./constants', require); // 硬解字符串返回相应格式的对象
|
|
21
19
|
|
|
22
20
|
|
|
23
21
|
const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
@@ -44,13 +42,13 @@ const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
44
|
|
|
47
|
-
const getCodeInitMapper = _ => {
|
|
45
|
+
const getCodeInitMapper = (api, _) => {
|
|
48
46
|
const {
|
|
49
47
|
output: {
|
|
50
48
|
packageFields,
|
|
51
49
|
packageMode
|
|
52
50
|
}
|
|
53
|
-
} =
|
|
51
|
+
} = api.useResolvedConfigContext();
|
|
54
52
|
let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
|
|
55
53
|
|
|
56
54
|
if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
|
|
@@ -82,7 +80,7 @@ const getCodeInitMapper = _ => {
|
|
|
82
80
|
|
|
83
81
|
exports.getCodeInitMapper = getCodeInitMapper;
|
|
84
82
|
|
|
85
|
-
const getCodeMapper = ({
|
|
83
|
+
const getCodeMapper = (api, {
|
|
86
84
|
logger,
|
|
87
85
|
taskPath,
|
|
88
86
|
config,
|
|
@@ -92,8 +90,8 @@ const getCodeMapper = ({
|
|
|
92
90
|
}) => {
|
|
93
91
|
const {
|
|
94
92
|
appDirectory
|
|
95
|
-
} =
|
|
96
|
-
const modernConfig =
|
|
93
|
+
} = api.useAppContext();
|
|
94
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
97
95
|
const {
|
|
98
96
|
output: {
|
|
99
97
|
enableSourceMap,
|
|
@@ -121,11 +119,11 @@ const getCodeMapper = ({
|
|
|
121
119
|
|
|
122
120
|
exports.getCodeMapper = getCodeMapper;
|
|
123
121
|
|
|
124
|
-
const getDtsMapper = (config, logger) => {
|
|
122
|
+
const getDtsMapper = (api, config, logger) => {
|
|
125
123
|
const {
|
|
126
124
|
appDirectory
|
|
127
|
-
} =
|
|
128
|
-
const modernConfig =
|
|
125
|
+
} = api.useAppContext();
|
|
126
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
129
127
|
const {
|
|
130
128
|
output: {
|
|
131
129
|
disableTsChecker,
|
|
@@ -11,14 +11,13 @@ var _chalk = _interopRequireDefault(require("chalk"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
15
|
-
|
|
16
14
|
const inquirer = _utils.Import.lazy('inquirer', require);
|
|
17
15
|
|
|
18
16
|
const color = _utils.Import.lazy('../../utils/color', require);
|
|
19
17
|
|
|
20
|
-
const showMenu = async config => {
|
|
21
|
-
const
|
|
18
|
+
const showMenu = async (api, config) => {
|
|
19
|
+
const runners = api.useHookRunners();
|
|
20
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
22
21
|
|
|
23
22
|
if (metas.length <= 0) {
|
|
24
23
|
console.info(_chalk.default.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
|
|
@@ -44,8 +43,9 @@ const showMenu = async config => {
|
|
|
44
43
|
|
|
45
44
|
exports.showMenu = showMenu;
|
|
46
45
|
|
|
47
|
-
const devStorybook = async config => {
|
|
48
|
-
const
|
|
46
|
+
const devStorybook = async (api, config) => {
|
|
47
|
+
const runners = api.useHookRunners();
|
|
48
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
49
49
|
const findStorybook = metas.find(meta => meta.value === 'storybook');
|
|
50
50
|
|
|
51
51
|
if (findStorybook) {
|
|
@@ -59,8 +59,9 @@ const devStorybook = async config => {
|
|
|
59
59
|
|
|
60
60
|
exports.devStorybook = devStorybook;
|
|
61
61
|
|
|
62
|
-
const runSubCmd = async (subCmd, config) => {
|
|
63
|
-
const
|
|
62
|
+
const runSubCmd = async (api, subCmd, config) => {
|
|
63
|
+
const runners = api.useHookRunners();
|
|
64
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
64
65
|
const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
|
|
65
66
|
|
|
66
67
|
if (devMeta) {
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,14 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
Object.defineProperty(exports, "defineConfig", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _core.defineConfig;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
|
|
8
14
|
var _utils = require("@modern-js/utils");
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changeset"));
|
|
17
|
+
|
|
18
|
+
var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
|
|
19
|
+
|
|
20
|
+
var _moduleToolsHooks = require("@modern-js/module-tools-hooks");
|
|
11
21
|
|
|
22
|
+
var _core = require("@modern-js/core");
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
25
|
|
|
15
26
|
const cli = _utils.Import.lazy('./cli', require);
|
|
16
27
|
|
|
@@ -20,45 +31,42 @@ const schema = _utils.Import.lazy('./schema', require);
|
|
|
20
31
|
|
|
21
32
|
const lang = _utils.Import.lazy('./utils/language', require);
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
}, {
|
|
61
|
-
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset']
|
|
34
|
+
var _default = () => ({
|
|
35
|
+
name: '@modern-js/module-tools',
|
|
36
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
|
|
37
|
+
registerHook: _moduleToolsHooks.hooks,
|
|
38
|
+
usePlugins: [(0, _pluginChangeset.default)(), (0, _pluginAnalyze.default)()],
|
|
39
|
+
setup: api => {
|
|
40
|
+
const locale = lang.getLocaleLanguage();
|
|
41
|
+
local.i18n.changeLanguage({
|
|
42
|
+
locale
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
validateSchema() {
|
|
46
|
+
return schema.addSchema();
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
config() {
|
|
50
|
+
return {
|
|
51
|
+
output: {
|
|
52
|
+
enableSourceMap: false,
|
|
53
|
+
jsPath: 'js'
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
commands({
|
|
59
|
+
program
|
|
60
|
+
}) {
|
|
61
|
+
cli.devCli(program, api);
|
|
62
|
+
cli.buildCli(program, api);
|
|
63
|
+
cli.newCli(program, locale); // 便于其他插件辨别
|
|
64
|
+
|
|
65
|
+
program.$$libraryName = 'module-tools';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
}
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
exports.default = _default;
|
package/dist/types/cli/dev.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
1
2
|
import type { Platform } from '../types';
|
|
2
3
|
export interface IBuildOption {
|
|
3
4
|
watch: boolean;
|
|
@@ -7,7 +8,7 @@ export interface IBuildOption {
|
|
|
7
8
|
tsc: boolean;
|
|
8
9
|
clear: boolean;
|
|
9
10
|
}
|
|
10
|
-
export declare const build: ({
|
|
11
|
+
export declare const build: (api: PluginAPI, {
|
|
11
12
|
watch,
|
|
12
13
|
tsconfig: tsconfigName,
|
|
13
14
|
tsc,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
1
2
|
export interface IDevOption {
|
|
2
3
|
tsconfig: string;
|
|
3
4
|
}
|
|
4
|
-
export declare const dev: (option: IDevOption, subCmd?: string) => Promise<void>;
|
|
5
|
+
export declare const dev: (api: PluginAPI, option: IDevOption, subCmd?: string) => Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
1
2
|
export declare type Platform = 'all' | 'docs' | 'storybook';
|
|
2
3
|
export interface IBuildPlatformOption {
|
|
3
4
|
platform: Platform;
|
|
4
5
|
isTsProject?: boolean;
|
|
5
6
|
}
|
|
6
|
-
export declare const buildPlatform: (option: IBuildPlatformOption) => Promise<void>;
|
|
7
|
+
export declare const buildPlatform: (api: PluginAPI, option: IBuildPlatformOption) => Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
1
|
+
import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
2
2
|
import type { IBuildConfig } from '../../types';
|
|
3
|
-
export declare const buildInWatchMode: (config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
|
|
3
|
+
export declare const buildInWatchMode: (api: PluginAPI, config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
1
|
+
import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
2
2
|
import type { IBuildConfig } from '../../types';
|
|
3
|
-
export declare const buildSourceCode: (config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
|
|
3
|
+
export declare const buildSourceCode: (api: PluginAPI, config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
1
|
+
import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
2
2
|
import type { IBuildConfig } from '../../types';
|
|
3
|
-
export declare const build: (config: IBuildConfig, modernConfig: NormalizedConfig) => Promise<void>;
|
|
3
|
+
export declare const build: (api: PluginAPI, config: IBuildConfig, modernConfig: NormalizedConfig) => Promise<void>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
1
2
|
import type { IBuildConfig, IPackageModeValue, ITaskMapper } from '../../types';
|
|
2
3
|
import type { LoggerText } from './logger';
|
|
3
|
-
export declare const getCodeInitMapper: (_: IBuildConfig) => IPackageModeValue[];
|
|
4
|
-
export declare const getCodeMapper: ({
|
|
4
|
+
export declare const getCodeInitMapper: (api: PluginAPI, _: IBuildConfig) => IPackageModeValue[];
|
|
5
|
+
export declare const getCodeMapper: (api: PluginAPI, {
|
|
5
6
|
logger,
|
|
6
7
|
taskPath,
|
|
7
8
|
config,
|
|
@@ -18,7 +19,7 @@ export declare const getCodeMapper: ({
|
|
|
18
19
|
taskPath: string;
|
|
19
20
|
params: string[];
|
|
20
21
|
}[];
|
|
21
|
-
export declare const getDtsMapper: (config: IBuildConfig, logger: LoggerText) => {
|
|
22
|
+
export declare const getDtsMapper: (api: PluginAPI, config: IBuildConfig, logger: LoggerText) => {
|
|
22
23
|
logger: LoggerText;
|
|
23
24
|
taskPath: string;
|
|
24
25
|
params: string[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
1
2
|
export interface IDevConfig {
|
|
2
3
|
appDirectory: string;
|
|
3
4
|
isTsProject: boolean;
|
|
4
5
|
}
|
|
5
6
|
export declare type DevTaskType = 'storybook' | 'docsite' | 'unknow';
|
|
6
|
-
export declare const showMenu: (config: IDevConfig) => Promise<void>;
|
|
7
|
-
export declare const devStorybook: (config: IDevConfig) => Promise<void>;
|
|
8
|
-
export declare const runSubCmd: (subCmd: string, config: IDevConfig) => Promise<void>;
|
|
7
|
+
export declare const showMenu: (api: PluginAPI, config: IDevConfig) => Promise<void>;
|
|
8
|
+
export declare const devStorybook: (api: PluginAPI, config: IDevConfig) => Promise<void>;
|
|
9
|
+
export declare const runSubCmd: (api: PluginAPI, subCmd: string, config: IDevConfig) => Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { CliPlugin } from '@modern-js/core';
|
|
2
|
+
export { defineConfig } from '@modern-js/core';
|
|
2
3
|
|
|
3
|
-
declare const _default:
|
|
4
|
-
config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
5
|
-
resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
|
|
6
|
-
resolved: import("@modern-js/core").NormalizedConfig;
|
|
7
|
-
}>;
|
|
8
|
-
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
9
|
-
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
10
|
-
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
11
|
-
program: import("commander").Command;
|
|
12
|
-
}, void>;
|
|
13
|
-
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
14
|
-
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
15
|
-
filename: string;
|
|
16
|
-
eventType: "add" | "unlink" | "change";
|
|
17
|
-
}, void>;
|
|
18
|
-
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
19
|
-
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
20
|
-
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
4
|
+
declare const _default: () => CliPlugin;
|
|
21
5
|
|
|
22
6
|
export default _default;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.3",
|
|
15
15
|
"bin": {
|
|
16
16
|
"modern": "./bin/modern.js"
|
|
17
17
|
},
|
|
@@ -46,24 +46,24 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@modern-js/core": "^1.
|
|
49
|
+
"@modern-js/core": "^1.6.0",
|
|
50
50
|
"@babel/generator": "^7.15.0",
|
|
51
51
|
"@babel/parser": "^7.15.2",
|
|
52
52
|
"@babel/runtime": "^7",
|
|
53
53
|
"@babel/traverse": "^7.15.0",
|
|
54
|
-
"@babel/types": "^7.
|
|
54
|
+
"@babel/types": "^7.17.0",
|
|
55
55
|
"@modern-js/babel-compiler": "^1.2.2",
|
|
56
56
|
"@modern-js/babel-preset-module": "^1.3.1",
|
|
57
57
|
"@modern-js/css-config": "^1.2.2",
|
|
58
58
|
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
59
|
-
"@modern-js/module-tools-hooks": "^1.2.
|
|
59
|
+
"@modern-js/module-tools-hooks": "^1.2.3",
|
|
60
60
|
"@modern-js/new-action": "^1.3.3",
|
|
61
|
-
"@modern-js/plugin-analyze": "^1.3.
|
|
62
|
-
"@modern-js/plugin-changeset": "^1.2.
|
|
63
|
-
"@modern-js/plugin-fast-refresh": "^1.2.
|
|
61
|
+
"@modern-js/plugin-analyze": "^1.3.4",
|
|
62
|
+
"@modern-js/plugin-changeset": "^1.2.3",
|
|
63
|
+
"@modern-js/plugin-fast-refresh": "^1.2.2",
|
|
64
64
|
"@modern-js/plugin-i18n": "^1.2.1",
|
|
65
65
|
"@modern-js/style-compiler": "^1.2.2",
|
|
66
|
-
"@modern-js/utils": "^1.3.
|
|
66
|
+
"@modern-js/utils": "^1.3.6",
|
|
67
67
|
"chalk": "^4.1.2",
|
|
68
68
|
"dotenv": "^10.0.0",
|
|
69
69
|
"execa": "^5.1.1",
|
package/tests/dev-cli.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { manager } from '@modern-js/core';
|
|
1
2
|
import { program } from 'commander';
|
|
2
3
|
import { devCli } from '../src/cli/dev';
|
|
3
4
|
|
|
@@ -11,15 +12,48 @@ describe('dev cli subCmd', () => {
|
|
|
11
12
|
dev: mockCommandDev,
|
|
12
13
|
}));
|
|
13
14
|
});
|
|
14
|
-
it('should be storybook with "dev storybook"', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
it('should be storybook with "dev storybook"', async () => {
|
|
16
|
+
const mockAPI = {
|
|
17
|
+
useAppContext: jest.fn((): any => ({
|
|
18
|
+
existSrc: false,
|
|
19
|
+
distDirectory: '',
|
|
20
|
+
})),
|
|
21
|
+
useResolvedConfigContext: jest.fn(),
|
|
22
|
+
useHookRunners: (): any => ({}),
|
|
23
|
+
};
|
|
24
|
+
const cloned = manager.clone(mockAPI);
|
|
25
|
+
cloned.usePlugin({
|
|
26
|
+
setup(api) {
|
|
27
|
+
devCli(program, api);
|
|
28
|
+
program.parse(['', '', 'dev', 'storybook']);
|
|
29
|
+
expect(mockCommandDev.mock.calls[0][2]).toBe('storybook');
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
await cloned.init();
|
|
18
33
|
});
|
|
19
34
|
|
|
20
|
-
it('should be undefined with "dev"', () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
it('should be undefined with "dev"', async () => {
|
|
36
|
+
const mockBeforeBuild = jest.fn();
|
|
37
|
+
const mockAfterBuild = jest.fn();
|
|
38
|
+
const mockAPI = {
|
|
39
|
+
useAppContext: jest.fn((): any => ({
|
|
40
|
+
existSrc: false,
|
|
41
|
+
distDirectory: '',
|
|
42
|
+
})),
|
|
43
|
+
useResolvedConfigContext: jest.fn(),
|
|
44
|
+
useHookRunners: (): any => ({
|
|
45
|
+
afterBuild: mockAfterBuild,
|
|
46
|
+
beforeBuild: mockBeforeBuild,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
const cloned = manager.clone(mockAPI);
|
|
50
|
+
cloned.usePlugin({
|
|
51
|
+
setup(api) {
|
|
52
|
+
devCli(program, api);
|
|
53
|
+
program.parse(['', '', 'dev']);
|
|
54
|
+
expect(mockCommandDev.mock.calls[0][2]).toBe(undefined);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
await cloned.init();
|
|
24
58
|
});
|
|
25
59
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { manager } from '@modern-js/core';
|
|
1
2
|
import { dev } from '../src/commands/dev';
|
|
2
3
|
|
|
3
4
|
const mockRunSubCmd = jest.fn();
|
|
@@ -6,11 +7,6 @@ jest.mock('../src/features/dev', () => ({
|
|
|
6
7
|
runSubCmd: mockRunSubCmd,
|
|
7
8
|
devStorybook: jest.fn(),
|
|
8
9
|
}));
|
|
9
|
-
jest.mock('@modern-js/core', () => ({
|
|
10
|
-
__esModule: true,
|
|
11
|
-
useAppContext: jest.fn(() => ({ appDirectory: '' })),
|
|
12
|
-
useResolvedConfigContext: jest.fn(),
|
|
13
|
-
}));
|
|
14
10
|
|
|
15
11
|
jest.mock('dotenv', () => ({
|
|
16
12
|
__esModule: true,
|
|
@@ -32,13 +28,43 @@ describe('dev command with subCmd', () => {
|
|
|
32
28
|
jest.clearAllMocks();
|
|
33
29
|
});
|
|
34
30
|
it('should call runSubCmd with storybook param', async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const mockAPI = {
|
|
32
|
+
useAppContext: jest.fn((): any => ({
|
|
33
|
+
existSrc: false,
|
|
34
|
+
distDirectory: '',
|
|
35
|
+
appDirectory: '',
|
|
36
|
+
})),
|
|
37
|
+
useResolvedConfigContext: jest.fn(),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const cloned = manager.clone(mockAPI);
|
|
41
|
+
cloned.usePlugin({
|
|
42
|
+
async setup(api) {
|
|
43
|
+
await dev(api, { tsconfig: 'tsconfig.json' }, 'storybook');
|
|
44
|
+
expect(mockRunSubCmd.mock.calls.length).toBe(1);
|
|
45
|
+
expect(mockRunSubCmd.mock.calls[0][1]).toBe('storybook');
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
await cloned.init();
|
|
38
49
|
});
|
|
39
50
|
|
|
40
51
|
it('should not call runSubCmd with nothing param', async () => {
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
const mockAPI = {
|
|
53
|
+
useAppContext: jest.fn((): any => ({
|
|
54
|
+
existSrc: false,
|
|
55
|
+
distDirectory: '',
|
|
56
|
+
appDirectory: '',
|
|
57
|
+
})),
|
|
58
|
+
useResolvedConfigContext: jest.fn(),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const cloned = manager.clone(mockAPI);
|
|
62
|
+
cloned.usePlugin({
|
|
63
|
+
async setup(api) {
|
|
64
|
+
await dev(api, { tsconfig: 'tsconfig.json' });
|
|
65
|
+
expect(mockRunSubCmd.mock.calls.length).toBe(0);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
await cloned.init();
|
|
43
69
|
});
|
|
44
70
|
});
|