@modern-js/module-tools 1.4.2 → 1.4.5
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 +66 -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 +4 -5
- package/dist/js/modern/features/build/build-watch.js +6 -8
- package/dist/js/modern/features/build/build.js +7 -11
- 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 +10 -9
- package/dist/js/modern/hooks/build.js +20 -0
- package/dist/js/modern/hooks/dev.js +11 -0
- package/dist/js/modern/hooks/index.js +14 -0
- package/dist/js/modern/index.js +37 -37
- package/dist/js/modern/tasks/build-source-code.js +1 -2
- package/dist/js/modern/tasks/build-style.js +2 -3
- package/dist/js/modern/tasks/build-watch-style.js +3 -6
- package/dist/js/modern/tasks/copy-assets.js +1 -2
- package/dist/js/modern/tasks/generator-dts/index.js +8 -11
- package/dist/js/modern/tasks/generator-dts/utils.js +11 -3
- package/dist/js/modern/utils/babel.js +2 -19
- package/dist/js/modern/utils/copy.js +1 -2
- package/dist/js/modern/utils/logger.js +1 -2
- 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 +5 -7
- package/dist/js/node/features/build/build-watch.js +6 -10
- package/dist/js/node/features/build/build.js +6 -13
- 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 +11 -14
- package/dist/js/node/hooks/build.js +37 -0
- package/dist/js/node/hooks/dev.js +25 -0
- package/dist/js/node/hooks/index.js +39 -0
- package/dist/js/node/index.js +50 -42
- package/dist/js/node/tasks/build-source-code.js +3 -3
- package/dist/js/node/tasks/build-style.js +2 -4
- package/dist/js/node/tasks/build-watch-style.js +3 -7
- package/dist/js/node/tasks/copy-assets.js +1 -3
- package/dist/js/node/tasks/generator-dts/index.js +8 -16
- package/dist/js/node/tasks/generator-dts/utils.js +18 -8
- package/dist/js/node/utils/babel.js +1 -18
- package/dist/js/node/utils/copy.js +1 -2
- package/dist/js/node/utils/logger.js +5 -7
- package/dist/types/cli/build.d.ts +3 -2
- package/dist/types/cli/dev.d.ts +3 -2
- package/dist/types/cli/new.d.ts +1 -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/hooks/build.d.ts +46 -0
- package/dist/types/hooks/dev.d.ts +18 -0
- package/dist/types/hooks/index.d.ts +26 -0
- package/dist/types/index.d.ts +3 -19
- package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
- package/dist/types/utils/babel.d.ts +2 -3
- package/jest.config.js +0 -3
- package/package.json +19 -22
- package/tests/dev-cli.test.ts +43 -9
- package/tests/dev-command.test.ts +36 -10
- package/tests/dev-feature.test.ts +45 -13
- package/tests/generate-dts.test.ts +9 -0
- package/tests/generator-dts.test.ts +0 -11
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Import, execa, fs, isObject } from '@modern-js/utils';
|
|
2
|
+
import { getTscBinPath } from "./utils";
|
|
3
3
|
const core = Import.lazy('@modern-js/core', require);
|
|
4
|
-
const execa = Import.lazy('execa', require);
|
|
5
4
|
const JSON5 = Import.lazy('json5', require);
|
|
6
5
|
const argv = Import.lazy('process.argv', require);
|
|
7
6
|
const utils = Import.lazy('./utils', require);
|
|
@@ -62,7 +61,7 @@ const generatorDts = async (_, config) => {
|
|
|
62
61
|
sourceDir: sourceDirName
|
|
63
62
|
});
|
|
64
63
|
removeTsconfigPath = willDeleteTsconfigPath;
|
|
65
|
-
const tscBinFile =
|
|
64
|
+
const tscBinFile = getTscBinPath(appDirectory);
|
|
66
65
|
const watchParams = watch ? ['-w'] : [];
|
|
67
66
|
const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
|
|
68
67
|
stdio: 'pipe',
|
|
@@ -75,17 +74,15 @@ const generatorDts = async (_, config) => {
|
|
|
75
74
|
|
|
76
75
|
try {
|
|
77
76
|
await childProgress;
|
|
78
|
-
console.info('[
|
|
77
|
+
console.info('[TSC Compiler]: Successfully');
|
|
79
78
|
} catch (e) {
|
|
80
79
|
if (!tsCheck) {
|
|
81
80
|
console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
|
|
81
|
+
} // 通过使用 execa,可以将 tsc 的 data 类型的报错信息变为异常错误信息
|
|
82
|
+
else if (isObject(e) && e.stdout) {
|
|
83
|
+
console.error(e.stdout);
|
|
82
84
|
} else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (isRecord(e)) {
|
|
87
|
-
console.error(e.stdout);
|
|
88
|
-
}
|
|
85
|
+
console.error(e);
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
|
|
@@ -5,12 +5,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
7
|
import * as path from 'path';
|
|
8
|
-
import { Import, fs } from '@modern-js/utils';
|
|
9
|
-
|
|
8
|
+
import { Import, glob, fs } from '@modern-js/utils';
|
|
9
|
+
import { merge as deepMerge } from '@modern-js/utils/lodash';
|
|
10
10
|
const babel = Import.lazy('../../utils/babel', require);
|
|
11
11
|
const tsPathsTransform = Import.lazy('../../utils/tspaths-transform', require);
|
|
12
12
|
const constants = Import.lazy('../constants', require);
|
|
13
|
-
const deepMerge = Import.lazy('lodash.merge', require);
|
|
14
13
|
export const generatorTsConfig = (projectTsconfig, {
|
|
15
14
|
appDirectory,
|
|
16
15
|
distDir,
|
|
@@ -79,4 +78,13 @@ export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
|
|
|
79
78
|
for (const r of result) {
|
|
80
79
|
fs.writeFileSync(r.path, r.content);
|
|
81
80
|
}
|
|
81
|
+
};
|
|
82
|
+
export const getTscBinPath = appDirectory => {
|
|
83
|
+
const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
|
|
84
|
+
|
|
85
|
+
if (!fs.existsSync(tscBinFile)) {
|
|
86
|
+
throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return tscBinFile;
|
|
82
90
|
};
|
|
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import { getBabelConfig
|
|
7
|
+
import { getBabelConfig } from '@modern-js/babel-preset-module';
|
|
8
8
|
import { applyOptionsChain, getAlias, isUseSSRBundle } from '@modern-js/utils';
|
|
9
9
|
export const getFinalAlias = (modernConfig, option) => {
|
|
10
10
|
const aliasConfig = getAlias(modernConfig.source.alias, option); // 排除内部别名,因为不需要处理
|
|
@@ -72,23 +72,6 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
|
|
|
72
72
|
}); // Preventing warning when files are too large
|
|
73
73
|
|
|
74
74
|
internalBabelConfig.compact = false;
|
|
75
|
-
const babelChain = getModuleBabelChain({
|
|
76
|
-
appDirectory,
|
|
77
|
-
enableReactPreset: true,
|
|
78
|
-
enableTypescriptPreset: true,
|
|
79
|
-
alias: aliasConfig,
|
|
80
|
-
envVars,
|
|
81
|
-
globalVars,
|
|
82
|
-
lodashOptions,
|
|
83
|
-
jsxTransformRuntime,
|
|
84
|
-
importStyle
|
|
85
|
-
}, {
|
|
86
|
-
type: option.type,
|
|
87
|
-
syntax: option.syntax
|
|
88
|
-
});
|
|
89
75
|
const userBabelConfig = modernConfig.tools.babel;
|
|
90
|
-
return applyOptionsChain(internalBabelConfig,
|
|
91
|
-
userBabelConfig, {
|
|
92
|
-
chain: babelChain
|
|
93
|
-
});
|
|
76
|
+
return applyOptionsChain(internalBabelConfig, userBabelConfig);
|
|
94
77
|
};
|
|
@@ -8,8 +8,7 @@ import * as path from 'path';
|
|
|
8
8
|
import { fs, Import } from '@modern-js/utils';
|
|
9
9
|
const globby = Import.lazy('globby', require);
|
|
10
10
|
const fastGlob = Import.lazy('fast-glob', require);
|
|
11
|
-
const normalizePath = Import.lazy('normalize-path', require);
|
|
12
|
-
|
|
11
|
+
const normalizePath = Import.lazy('normalize-path', require);
|
|
13
12
|
export const copyTask = async option => {
|
|
14
13
|
const {
|
|
15
14
|
modernConfig,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import {
|
|
3
|
-
const chalk = Import.lazy('chalk', require);
|
|
2
|
+
import { chalk } from '@modern-js/utils';
|
|
4
3
|
export const clearFlag = '\x1Bc';
|
|
5
4
|
export const logTemplate = (title, messageStack, maxLength, {
|
|
6
5
|
noBottomBorder: _noBottomBorder = false,
|
|
@@ -11,10 +11,10 @@ const local = _utils.Import.lazy('../locale/index', require);
|
|
|
11
11
|
|
|
12
12
|
const commands = _utils.Import.lazy('../commands', require);
|
|
13
13
|
|
|
14
|
-
const buildCli = program => {
|
|
14
|
+
const buildCli = (program, api) => {
|
|
15
15
|
// TODO: 初始化环境变量
|
|
16
16
|
program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('-p, --platform [platform]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).action(async subCommand => {
|
|
17
|
-
await commands.build(subCommand);
|
|
17
|
+
await commands.build(api, subCommand);
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
|
package/dist/js/node/cli/dev.js
CHANGED
|
@@ -11,9 +11,9 @@ const local = _utils.Import.lazy('../locale', require);
|
|
|
11
11
|
|
|
12
12
|
const commands = _utils.Import.lazy('../commands', require);
|
|
13
13
|
|
|
14
|
-
const devCli = program => {
|
|
14
|
+
const devCli = (program, api) => {
|
|
15
15
|
program.command('dev [subCmd]').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async (subCmd, params) => {
|
|
16
|
-
await commands.dev(params, subCmd);
|
|
16
|
+
await commands.dev(api, params, subCmd);
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -19,11 +19,9 @@ const valid = _utils.Import.lazy('../utils/valide', require);
|
|
|
19
19
|
|
|
20
20
|
const buildFeature = _utils.Import.lazy('../features/build', require);
|
|
21
21
|
|
|
22
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
23
|
-
|
|
24
22
|
const dotenv = _utils.Import.lazy('dotenv', require);
|
|
25
23
|
|
|
26
|
-
const build = async ({
|
|
24
|
+
const build = async (api, {
|
|
27
25
|
watch: _watch = false,
|
|
28
26
|
tsconfig: tsconfigName,
|
|
29
27
|
tsc,
|
|
@@ -32,8 +30,8 @@ const build = async ({
|
|
|
32
30
|
}) => {
|
|
33
31
|
const {
|
|
34
32
|
appDirectory
|
|
35
|
-
} =
|
|
36
|
-
const modernConfig =
|
|
33
|
+
} = api.useAppContext();
|
|
34
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
37
35
|
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
38
36
|
dotenv.config();
|
|
39
37
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
@@ -43,7 +41,7 @@ const build = async ({
|
|
|
43
41
|
tsconfigPath
|
|
44
42
|
}); // TODO: 一些配置只需要从modernConfig中获取
|
|
45
43
|
|
|
46
|
-
await buildFeature.build({
|
|
44
|
+
await buildFeature.build(api, {
|
|
47
45
|
appDirectory,
|
|
48
46
|
enableWatchMode: _watch,
|
|
49
47
|
isTsProject,
|
|
@@ -15,8 +15,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
15
15
|
|
|
16
16
|
const devFeature = _utils.Import.lazy('../features/dev', require);
|
|
17
17
|
|
|
18
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
19
|
-
|
|
20
18
|
const dotenv = _utils.Import.lazy('dotenv', require);
|
|
21
19
|
|
|
22
20
|
const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
|
|
@@ -25,12 +23,12 @@ const valid = _utils.Import.lazy('../utils/valide', require);
|
|
|
25
23
|
|
|
26
24
|
const existSubCmd = subCmd => subCmd.length > 0;
|
|
27
25
|
|
|
28
|
-
const dev = async (option, subCmd = '') => {
|
|
26
|
+
const dev = async (api, option, subCmd = '') => {
|
|
29
27
|
const {
|
|
30
28
|
tsconfig: tsconfigName
|
|
31
29
|
} = option;
|
|
32
|
-
const appContext =
|
|
33
|
-
const modernConfig =
|
|
30
|
+
const appContext = api.useAppContext();
|
|
31
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
34
32
|
const {
|
|
35
33
|
appDirectory
|
|
36
34
|
} = appContext;
|
|
@@ -43,7 +41,7 @@ const dev = async (option, subCmd = '') => {
|
|
|
43
41
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
44
42
|
|
|
45
43
|
if (existSubCmd(subCmd)) {
|
|
46
|
-
await devFeature.runSubCmd(subCmd, {
|
|
44
|
+
await devFeature.runSubCmd(api, subCmd, {
|
|
47
45
|
isTsProject,
|
|
48
46
|
appDirectory
|
|
49
47
|
});
|
|
@@ -52,12 +50,12 @@ const dev = async (option, subCmd = '') => {
|
|
|
52
50
|
|
|
53
51
|
|
|
54
52
|
if (process.env.RUN_PLATFORM) {
|
|
55
|
-
await devFeature.showMenu({
|
|
53
|
+
await devFeature.showMenu(api, {
|
|
56
54
|
isTsProject,
|
|
57
55
|
appDirectory
|
|
58
56
|
});
|
|
59
57
|
} else {
|
|
60
|
-
await devFeature.devStorybook({
|
|
58
|
+
await devFeature.devStorybook(api, {
|
|
61
59
|
isTsProject,
|
|
62
60
|
appDirectory
|
|
63
61
|
});
|
|
@@ -13,22 +13,19 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
13
13
|
|
|
14
14
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
15
|
|
|
16
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
17
|
-
|
|
18
|
-
const execa = _utils.Import.lazy('execa', require);
|
|
19
|
-
|
|
20
16
|
const lg = _utils.Import.lazy('./logger', require);
|
|
21
17
|
|
|
22
18
|
const pMap = _utils.Import.lazy('p-map', require);
|
|
23
19
|
|
|
24
|
-
const buildPlatform = async option => {
|
|
20
|
+
const buildPlatform = async (api, option) => {
|
|
25
21
|
const {
|
|
26
22
|
isTsProject = false,
|
|
27
23
|
platform
|
|
28
24
|
} = option;
|
|
29
25
|
const lm = new lg.LoggerManager(); // 获取platforms的参数
|
|
30
26
|
|
|
31
|
-
const
|
|
27
|
+
const runners = api.useHookRunners();
|
|
28
|
+
const buildTasks = await runners.platformBuild({
|
|
32
29
|
isTsProject
|
|
33
30
|
});
|
|
34
31
|
|
|
@@ -59,7 +56,7 @@ const buildPlatform = async option => {
|
|
|
59
56
|
params,
|
|
60
57
|
logger: _
|
|
61
58
|
}) => {
|
|
62
|
-
const childProcess = execa.node(taskPath, params, {
|
|
59
|
+
const childProcess = _utils.execa.node(taskPath, params, {
|
|
63
60
|
stdio: 'inherit',
|
|
64
61
|
all: true
|
|
65
62
|
}); // lm.addStdout(logger, childProcess.stdout, {
|
|
@@ -67,6 +64,7 @@ const buildPlatform = async option => {
|
|
|
67
64
|
// });
|
|
68
65
|
// lm.addStderr(logger, childProcess.stderr);
|
|
69
66
|
|
|
67
|
+
|
|
70
68
|
try {
|
|
71
69
|
await childProcess;
|
|
72
70
|
} catch (_unused) {
|
|
@@ -15,10 +15,6 @@ 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 core = _utils.Import.lazy('@modern-js/core', require);
|
|
19
|
-
|
|
20
|
-
const execa = _utils.Import.lazy('execa', require);
|
|
21
|
-
|
|
22
18
|
const lg = _utils.Import.lazy('./logger', require);
|
|
23
19
|
|
|
24
20
|
const pMap = _utils.Import.lazy('p-map', require);
|
|
@@ -27,10 +23,10 @@ const utils = _utils.Import.lazy('./utils', require);
|
|
|
27
23
|
|
|
28
24
|
const constants = _utils.Import.lazy('./constants', require);
|
|
29
25
|
|
|
30
|
-
const buildInWatchMode = async (config, _) => {
|
|
26
|
+
const buildInWatchMode = async (api, config, _) => {
|
|
31
27
|
const {
|
|
32
28
|
appDirectory
|
|
33
|
-
} =
|
|
29
|
+
} = api.useAppContext();
|
|
34
30
|
const {
|
|
35
31
|
sourceDir,
|
|
36
32
|
enableTscCompiler
|
|
@@ -50,15 +46,15 @@ const buildInWatchMode = async (config, _) => {
|
|
|
50
46
|
const copyLog = lm.createLoggerText({
|
|
51
47
|
title: 'Copy Log:'
|
|
52
48
|
});
|
|
53
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
54
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
49
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
50
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
55
51
|
logger: codeLog,
|
|
56
52
|
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
57
53
|
config,
|
|
58
54
|
willCompilerDirOrFile: sourceDir,
|
|
59
55
|
initMapper: initCodeMapper,
|
|
60
56
|
srcRootDir
|
|
61
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
57
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
62
58
|
logger: styleLog,
|
|
63
59
|
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
64
60
|
}, {
|
|
@@ -77,7 +73,7 @@ const buildInWatchMode = async (config, _) => {
|
|
|
77
73
|
taskPath,
|
|
78
74
|
params
|
|
79
75
|
}) => {
|
|
80
|
-
const childProcess = execa.node(taskPath, params, {
|
|
76
|
+
const childProcess = _utils.execa.node(taskPath, params, {
|
|
81
77
|
stdio: 'pipe'
|
|
82
78
|
});
|
|
83
79
|
|
|
@@ -15,27 +15,22 @@ 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
|
-
/* eslint-disable max-statements */
|
|
19
18
|
const pMap = _utils.Import.lazy('p-map', require);
|
|
20
19
|
|
|
21
20
|
const utils = _utils.Import.lazy('./utils', require);
|
|
22
21
|
|
|
23
|
-
const execa = _utils.Import.lazy('execa', require);
|
|
24
|
-
|
|
25
22
|
const lg = _utils.Import.lazy('./logger', require);
|
|
26
23
|
|
|
27
24
|
const constants = _utils.Import.lazy('./constants', require);
|
|
28
25
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const buildSourceCode = async (config, _) => {
|
|
26
|
+
const buildSourceCode = async (api, config, _) => {
|
|
32
27
|
const {
|
|
33
28
|
sourceDir,
|
|
34
29
|
enableTscCompiler
|
|
35
30
|
} = config;
|
|
36
31
|
const {
|
|
37
32
|
appDirectory
|
|
38
|
-
} =
|
|
33
|
+
} = api.useAppContext();
|
|
39
34
|
const concurrency = os.cpus().length;
|
|
40
35
|
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
41
36
|
const lm = new lg.LoggerManager();
|
|
@@ -51,15 +46,15 @@ const buildSourceCode = async (config, _) => {
|
|
|
51
46
|
const copyLog = lm.createLoggerText({
|
|
52
47
|
title: 'Copy Log:'
|
|
53
48
|
});
|
|
54
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
55
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
49
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
50
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
56
51
|
logger: codeLog,
|
|
57
52
|
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
58
53
|
config,
|
|
59
54
|
willCompilerDirOrFile: sourceDir,
|
|
60
55
|
initMapper: initCodeMapper,
|
|
61
56
|
srcRootDir
|
|
62
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
57
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
63
58
|
logger: styleLog,
|
|
64
59
|
taskPath: require.resolve("../../tasks/build-style")
|
|
65
60
|
}, {
|
|
@@ -72,7 +67,7 @@ const buildSourceCode = async (config, _) => {
|
|
|
72
67
|
taskPath,
|
|
73
68
|
params
|
|
74
69
|
}) => {
|
|
75
|
-
const childProcess = execa.node(taskPath, params, {
|
|
70
|
+
const childProcess = _utils.execa.node(taskPath, params, {
|
|
76
71
|
stdio: 'pipe'
|
|
77
72
|
});
|
|
78
73
|
|
|
@@ -127,7 +122,5 @@ const buildSourceCode = async (config, _) => {
|
|
|
127
122
|
process.exit(1);
|
|
128
123
|
}
|
|
129
124
|
};
|
|
130
|
-
/* eslint-enable max-statements */
|
|
131
|
-
|
|
132
125
|
|
|
133
126
|
exports.buildSourceCode = buildSourceCode;
|
|
@@ -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,
|
|
@@ -7,21 +7,16 @@ exports.showMenu = exports.runSubCmd = exports.devStorybook = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
15
|
-
|
|
16
10
|
const inquirer = _utils.Import.lazy('inquirer', require);
|
|
17
11
|
|
|
18
12
|
const color = _utils.Import.lazy('../../utils/color', require);
|
|
19
13
|
|
|
20
|
-
const showMenu = async config => {
|
|
21
|
-
const
|
|
14
|
+
const showMenu = async (api, config) => {
|
|
15
|
+
const runners = api.useHookRunners();
|
|
16
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
22
17
|
|
|
23
18
|
if (metas.length <= 0) {
|
|
24
|
-
console.info(
|
|
19
|
+
console.info(_utils.chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
|
|
25
20
|
|
|
26
21
|
process.exit(0);
|
|
27
22
|
}
|
|
@@ -44,14 +39,15 @@ const showMenu = async config => {
|
|
|
44
39
|
|
|
45
40
|
exports.showMenu = showMenu;
|
|
46
41
|
|
|
47
|
-
const devStorybook = async config => {
|
|
48
|
-
const
|
|
42
|
+
const devStorybook = async (api, config) => {
|
|
43
|
+
const runners = api.useHookRunners();
|
|
44
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
49
45
|
const findStorybook = metas.find(meta => meta.value === 'storybook');
|
|
50
46
|
|
|
51
47
|
if (findStorybook) {
|
|
52
48
|
await findStorybook.runTask(config);
|
|
53
49
|
} else {
|
|
54
|
-
console.info(
|
|
50
|
+
console.info(_utils.chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
|
|
55
51
|
|
|
56
52
|
process.exit(0);
|
|
57
53
|
}
|
|
@@ -59,8 +55,9 @@ const devStorybook = async config => {
|
|
|
59
55
|
|
|
60
56
|
exports.devStorybook = devStorybook;
|
|
61
57
|
|
|
62
|
-
const runSubCmd = async (subCmd, config) => {
|
|
63
|
-
const
|
|
58
|
+
const runSubCmd = async (api, subCmd, config) => {
|
|
59
|
+
const runners = api.useHookRunners();
|
|
60
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
64
61
|
const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
|
|
65
62
|
|
|
66
63
|
if (devMeta) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.platformBuild = exports.moduleTailwindConfig = exports.moduleSassConfig = exports.moduleLessConfig = exports.lifecycle = exports.buildHooks = void 0;
|
|
7
|
+
|
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
|
9
|
+
|
|
10
|
+
var _core = require("@modern-js/core");
|
|
11
|
+
|
|
12
|
+
const platformBuild = (0, _plugin.createParallelWorkflow)();
|
|
13
|
+
exports.platformBuild = platformBuild;
|
|
14
|
+
const moduleLessConfig = (0, _plugin.createAsyncPipeline)();
|
|
15
|
+
exports.moduleLessConfig = moduleLessConfig;
|
|
16
|
+
const moduleSassConfig = (0, _plugin.createAsyncPipeline)();
|
|
17
|
+
exports.moduleSassConfig = moduleSassConfig;
|
|
18
|
+
const moduleTailwindConfig = (0, _plugin.createAsyncPipeline)();
|
|
19
|
+
exports.moduleTailwindConfig = moduleTailwindConfig;
|
|
20
|
+
const buildHooks = {
|
|
21
|
+
platformBuild,
|
|
22
|
+
moduleLessConfig,
|
|
23
|
+
moduleSassConfig,
|
|
24
|
+
moduleTailwindConfig
|
|
25
|
+
};
|
|
26
|
+
exports.buildHooks = buildHooks;
|
|
27
|
+
|
|
28
|
+
const lifecycle = () => {
|
|
29
|
+
(0, _core.registerHook)({
|
|
30
|
+
moduleLessConfig,
|
|
31
|
+
moduleSassConfig,
|
|
32
|
+
moduleTailwindConfig,
|
|
33
|
+
platformBuild
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.lifecycle = lifecycle;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moduleToolsMenu = exports.lifecycle = exports.devHooks = void 0;
|
|
7
|
+
|
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
|
9
|
+
|
|
10
|
+
var _core = require("@modern-js/core");
|
|
11
|
+
|
|
12
|
+
const moduleToolsMenu = (0, _plugin.createParallelWorkflow)();
|
|
13
|
+
exports.moduleToolsMenu = moduleToolsMenu;
|
|
14
|
+
const devHooks = {
|
|
15
|
+
moduleToolsMenu
|
|
16
|
+
};
|
|
17
|
+
exports.devHooks = devHooks;
|
|
18
|
+
|
|
19
|
+
const lifecycle = () => {
|
|
20
|
+
(0, _core.registerHook)({
|
|
21
|
+
moduleToolsMenu
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.lifecycle = lifecycle;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "buildLifeCycle", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _build.lifecycle;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "devLifeCycle", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dev.lifecycle;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.lifecycle = exports.hooks = void 0;
|
|
19
|
+
|
|
20
|
+
var _build = require("./build");
|
|
21
|
+
|
|
22
|
+
var _dev = require("./dev");
|
|
23
|
+
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
+
|
|
28
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
+
|
|
30
|
+
const lifecycle = () => {
|
|
31
|
+
(0, _dev.lifecycle)();
|
|
32
|
+
(0, _build.lifecycle)();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.lifecycle = lifecycle;
|
|
36
|
+
|
|
37
|
+
const hooks = _objectSpread(_objectSpread({}, _build.buildHooks), _dev.devHooks);
|
|
38
|
+
|
|
39
|
+
exports.hooks = hooks;
|