@modern-js/module-tools 1.4.0 → 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 +63 -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 +5 -6
- 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/modern/schema/output.js +0 -5
- package/dist/js/modern/tasks/build-source-code.js +2 -1
- package/dist/js/modern/tasks/build-watch-source-code.js +2 -1
- package/dist/js/modern/tasks/generator-dts/index.js +144 -0
- package/dist/js/modern/tasks/generator-dts/utils.js +82 -0
- package/dist/js/modern/utils/babel.js +10 -3
- 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 +5 -7
- 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/js/node/schema/output.js +0 -5
- package/dist/js/node/tasks/build-source-code.js +2 -1
- package/dist/js/node/tasks/build-watch-source-code.js +2 -1
- package/dist/js/node/tasks/generator-dts/index.js +158 -0
- package/dist/js/node/tasks/{generator-dts.js → generator-dts/utils.js} +11 -151
- package/dist/js/node/utils/babel.js +9 -2
- 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/dist/types/tasks/{generator-dts.d.ts → generator-dts/index.d.ts} +0 -0
- package/dist/types/tasks/generator-dts/utils.d.ts +23 -0
- package/jest.config.js +2 -0
- package/lib/types.d.ts +92 -0
- package/package.json +12 -13
- package/tests/dev-cli.test.ts +42 -8
- package/tests/dev-command.test.ts +36 -10
- package/tests/dev-feature.test.ts +45 -13
- package/tests/generator-dts-utils.test.ts +10 -0
- package/tests/generator-dts.test.ts +48 -0
- package/dist/js/modern/tasks/generator-dts.js +0 -226
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @modern-js/module-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 366cf4fd: convert module-tools to new plugin
|
|
8
|
+
- Updated dependencies [05ce88a0]
|
|
9
|
+
- Updated dependencies [a8df060e]
|
|
10
|
+
- Updated dependencies [c2046f37]
|
|
11
|
+
- Updated dependencies [366cf4fd]
|
|
12
|
+
- Updated dependencies [61e3f623]
|
|
13
|
+
- Updated dependencies [6a7acb81]
|
|
14
|
+
- Updated dependencies [681a1ff9]
|
|
15
|
+
- Updated dependencies [4e2026e4]
|
|
16
|
+
- @modern-js/core@1.6.0
|
|
17
|
+
- @modern-js/utils@1.3.6
|
|
18
|
+
- @modern-js/module-tools-hooks@1.2.3
|
|
19
|
+
- @modern-js/plugin-changeset@1.2.3
|
|
20
|
+
- @modern-js/plugin-fast-refresh@1.2.2
|
|
21
|
+
- @modern-js/plugin-analyze@1.3.4
|
|
22
|
+
|
|
23
|
+
## 1.4.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 4b5d4bf4: feat: add img resource's inline and url type declaration
|
|
28
|
+
- 969f172f: support tools.styledComponents for module-tools,support close tsc process with disbaleTsChecker
|
|
29
|
+
- 55e18278: chore: remove unused dependencies and devDependencies
|
|
30
|
+
- edc3bd3d: fix: @modern-js/core package not found
|
|
31
|
+
- Updated dependencies [969f172f]
|
|
32
|
+
- Updated dependencies [4c792f68]
|
|
33
|
+
- Updated dependencies [83059b93]
|
|
34
|
+
- Updated dependencies [4b5d4bf4]
|
|
35
|
+
- Updated dependencies [62f5b8c8]
|
|
36
|
+
- Updated dependencies [55e18278]
|
|
37
|
+
- Updated dependencies [4499a674]
|
|
38
|
+
- Updated dependencies [403f5169]
|
|
39
|
+
- Updated dependencies [a7f42f48]
|
|
40
|
+
- Updated dependencies [83059b93]
|
|
41
|
+
- @modern-js/core@1.4.4
|
|
42
|
+
- @modern-js/utils@1.3.3
|
|
43
|
+
- @modern-js/new-action@1.3.3
|
|
44
|
+
- @modern-js/babel-compiler@1.2.2
|
|
45
|
+
|
|
46
|
+
## 1.4.1
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- 02ff289d: Modify the type of error text and display log messages
|
|
51
|
+
- 54786e58: add ts check
|
|
52
|
+
- 6668a1bf: feat: upgrade @modern-js/codesmith-api-app version
|
|
53
|
+
- fab92861: fix: @modern-js/core phantom dep
|
|
54
|
+
- Updated dependencies [deeaa602]
|
|
55
|
+
- Updated dependencies [54786e58]
|
|
56
|
+
- Updated dependencies [6668a1bf]
|
|
57
|
+
- Updated dependencies [6668a1bf]
|
|
58
|
+
- Updated dependencies [fab92861]
|
|
59
|
+
- @modern-js/plugin-analyze@1.3.3
|
|
60
|
+
- @modern-js/utils@1.3.2
|
|
61
|
+
- @modern-js/core@1.4.3
|
|
62
|
+
- @modern-js/new-action@1.3.2
|
|
63
|
+
- @modern-js/plugin-changeset@1.2.2
|
|
64
|
+
- @modern-js/module-tools-hooks@1.2.2
|
|
65
|
+
|
|
3
66
|
## 1.4.0
|
|
4
67
|
|
|
5
68
|
### Minor Changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Import } from '@modern-js/utils';
|
|
2
2
|
const local = Import.lazy('../locale/index', require);
|
|
3
3
|
const commands = Import.lazy('../commands', require);
|
|
4
|
-
export const buildCli = program => {
|
|
4
|
+
export const buildCli = (program, api) => {
|
|
5
5
|
// TODO: 初始化环境变量
|
|
6
6
|
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 => {
|
|
7
|
-
await commands.build(subCommand);
|
|
7
|
+
await commands.build(api, subCommand);
|
|
8
8
|
});
|
|
9
9
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Import } from '@modern-js/utils';
|
|
2
2
|
const local = Import.lazy('../locale', require);
|
|
3
3
|
const commands = Import.lazy('../commands', require);
|
|
4
|
-
export const devCli = program => {
|
|
4
|
+
export const devCli = (program, api) => {
|
|
5
5
|
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) => {
|
|
6
|
-
await commands.dev(params, subCmd);
|
|
6
|
+
await commands.dev(api, params, subCmd);
|
|
7
7
|
});
|
|
8
8
|
};
|
|
@@ -3,9 +3,8 @@ import { fs, Import } from '@modern-js/utils';
|
|
|
3
3
|
const tsConfigutils = Import.lazy('../utils/tsconfig', require);
|
|
4
4
|
const valid = Import.lazy('../utils/valide', require);
|
|
5
5
|
const buildFeature = Import.lazy('../features/build', require);
|
|
6
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
7
6
|
const dotenv = Import.lazy('dotenv', require);
|
|
8
|
-
export const build = async ({
|
|
7
|
+
export const build = async (api, {
|
|
9
8
|
watch: _watch = false,
|
|
10
9
|
tsconfig: tsconfigName,
|
|
11
10
|
tsc,
|
|
@@ -14,18 +13,18 @@ export const build = async ({
|
|
|
14
13
|
}) => {
|
|
15
14
|
const {
|
|
16
15
|
appDirectory
|
|
17
|
-
} =
|
|
18
|
-
const modernConfig =
|
|
16
|
+
} = api.useAppContext();
|
|
17
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
19
18
|
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
20
19
|
dotenv.config();
|
|
21
20
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
22
|
-
const enableTscCompiler = isTsProject && tsc;
|
|
21
|
+
const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
|
|
23
22
|
valid.valideBeforeTask({
|
|
24
23
|
modernConfig,
|
|
25
24
|
tsconfigPath
|
|
26
25
|
}); // TODO: 一些配置只需要从modernConfig中获取
|
|
27
26
|
|
|
28
|
-
await buildFeature.build({
|
|
27
|
+
await buildFeature.build(api, {
|
|
29
28
|
appDirectory,
|
|
30
29
|
enableWatchMode: _watch,
|
|
31
30
|
isTsProject,
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import { Import } from '@modern-js/utils';
|
|
3
3
|
const devFeature = Import.lazy('../features/dev', require);
|
|
4
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
5
4
|
const dotenv = Import.lazy('dotenv', require);
|
|
6
5
|
const tsConfigutils = Import.lazy('../utils/tsconfig', require);
|
|
7
6
|
const valid = Import.lazy('../utils/valide', require);
|
|
8
7
|
|
|
9
8
|
const existSubCmd = subCmd => subCmd.length > 0;
|
|
10
9
|
|
|
11
|
-
export const dev = async (option, subCmd = '') => {
|
|
10
|
+
export const dev = async (api, option, subCmd = '') => {
|
|
12
11
|
const {
|
|
13
12
|
tsconfig: tsconfigName
|
|
14
13
|
} = option;
|
|
15
|
-
const appContext =
|
|
16
|
-
const modernConfig =
|
|
14
|
+
const appContext = api.useAppContext();
|
|
15
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
17
16
|
const {
|
|
18
17
|
appDirectory
|
|
19
18
|
} = appContext;
|
|
@@ -26,7 +25,7 @@ export const dev = async (option, subCmd = '') => {
|
|
|
26
25
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
27
26
|
|
|
28
27
|
if (existSubCmd(subCmd)) {
|
|
29
|
-
await devFeature.runSubCmd(subCmd, {
|
|
28
|
+
await devFeature.runSubCmd(api, subCmd, {
|
|
30
29
|
isTsProject,
|
|
31
30
|
appDirectory
|
|
32
31
|
});
|
|
@@ -35,12 +34,12 @@ export const dev = async (option, subCmd = '') => {
|
|
|
35
34
|
|
|
36
35
|
|
|
37
36
|
if (process.env.RUN_PLATFORM) {
|
|
38
|
-
await devFeature.showMenu({
|
|
37
|
+
await devFeature.showMenu(api, {
|
|
39
38
|
isTsProject,
|
|
40
39
|
appDirectory
|
|
41
40
|
});
|
|
42
41
|
} else {
|
|
43
|
-
await devFeature.devStorybook({
|
|
42
|
+
await devFeature.devStorybook(api, {
|
|
44
43
|
isTsProject,
|
|
45
44
|
appDirectory
|
|
46
45
|
});
|
|
@@ -5,18 +5,18 @@ 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 { Import, chalk } from '@modern-js/utils';
|
|
8
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
9
8
|
const execa = Import.lazy('execa', require);
|
|
10
9
|
const lg = Import.lazy('./logger', require);
|
|
11
10
|
const pMap = Import.lazy('p-map', require);
|
|
12
|
-
export const buildPlatform = async option => {
|
|
11
|
+
export const buildPlatform = async (api, option) => {
|
|
13
12
|
const {
|
|
14
13
|
isTsProject = false,
|
|
15
14
|
platform
|
|
16
15
|
} = option;
|
|
17
16
|
const lm = new lg.LoggerManager(); // 获取platforms的参数
|
|
18
17
|
|
|
19
|
-
const
|
|
18
|
+
const runners = api.useHookRunners();
|
|
19
|
+
const buildTasks = await runners.platformBuild({
|
|
20
20
|
isTsProject
|
|
21
21
|
});
|
|
22
22
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { Import } from '@modern-js/utils';
|
|
4
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
5
4
|
const execa = Import.lazy('execa', require);
|
|
6
5
|
const lg = Import.lazy('./logger', require);
|
|
7
6
|
const pMap = Import.lazy('p-map', require);
|
|
8
7
|
const utils = Import.lazy('./utils', require);
|
|
9
8
|
const constants = Import.lazy('./constants', require);
|
|
10
|
-
export const buildInWatchMode = async (config, _) => {
|
|
9
|
+
export const buildInWatchMode = async (api, config, _) => {
|
|
11
10
|
const {
|
|
12
11
|
appDirectory
|
|
13
|
-
} =
|
|
12
|
+
} = api.useAppContext();
|
|
14
13
|
const {
|
|
15
14
|
sourceDir,
|
|
16
15
|
enableTscCompiler
|
|
@@ -30,15 +29,15 @@ export const buildInWatchMode = async (config, _) => {
|
|
|
30
29
|
const copyLog = lm.createLoggerText({
|
|
31
30
|
title: 'Copy Log:'
|
|
32
31
|
});
|
|
33
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
34
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
32
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
33
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
35
34
|
logger: codeLog,
|
|
36
35
|
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
37
36
|
config,
|
|
38
37
|
willCompilerDirOrFile: sourceDir,
|
|
39
38
|
initMapper: initCodeMapper,
|
|
40
39
|
srcRootDir
|
|
41
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
40
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
42
41
|
logger: styleLog,
|
|
43
42
|
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
44
43
|
}, {
|
|
@@ -7,15 +7,14 @@ const utils = Import.lazy('./utils', require);
|
|
|
7
7
|
const execa = Import.lazy('execa', require);
|
|
8
8
|
const lg = Import.lazy('./logger', require);
|
|
9
9
|
const constants = Import.lazy('./constants', require);
|
|
10
|
-
const
|
|
11
|
-
export const buildSourceCode = async (config, _) => {
|
|
10
|
+
export const buildSourceCode = async (api, config, _) => {
|
|
12
11
|
const {
|
|
13
12
|
sourceDir,
|
|
14
13
|
enableTscCompiler
|
|
15
14
|
} = config;
|
|
16
15
|
const {
|
|
17
16
|
appDirectory
|
|
18
|
-
} =
|
|
17
|
+
} = api.useAppContext();
|
|
19
18
|
const concurrency = os.cpus().length;
|
|
20
19
|
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
21
20
|
const lm = new lg.LoggerManager();
|
|
@@ -31,15 +30,15 @@ export const buildSourceCode = async (config, _) => {
|
|
|
31
30
|
const copyLog = lm.createLoggerText({
|
|
32
31
|
title: 'Copy Log:'
|
|
33
32
|
});
|
|
34
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
35
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
33
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
34
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
36
35
|
logger: codeLog,
|
|
37
36
|
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
38
37
|
config,
|
|
39
38
|
willCompilerDirOrFile: sourceDir,
|
|
40
39
|
initMapper: initCodeMapper,
|
|
41
40
|
srcRootDir
|
|
42
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
41
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
43
42
|
logger: styleLog,
|
|
44
43
|
taskPath: require.resolve("../../tasks/build-style")
|
|
45
44
|
}, {
|
|
@@ -3,7 +3,7 @@ import { Import, fs } from '@modern-js/utils';
|
|
|
3
3
|
const buildFeature = Import.lazy('./build', require);
|
|
4
4
|
const buildWatchFeature = Import.lazy('./build-watch', require);
|
|
5
5
|
const bp = Import.lazy('./build-platform', require);
|
|
6
|
-
export const build = async (config, modernConfig) => {
|
|
6
|
+
export const build = async (api, config, modernConfig) => {
|
|
7
7
|
const {
|
|
8
8
|
appDirectory,
|
|
9
9
|
enableWatchMode,
|
|
@@ -19,7 +19,7 @@ export const build = async (config, modernConfig) => {
|
|
|
19
19
|
|
|
20
20
|
if (typeof platform === 'boolean' && platform) {
|
|
21
21
|
if (process.env.RUN_PLATFORM) {
|
|
22
|
-
await bp.buildPlatform({
|
|
22
|
+
await bp.buildPlatform(api, {
|
|
23
23
|
platform: 'all',
|
|
24
24
|
isTsProject
|
|
25
25
|
});
|
|
@@ -30,7 +30,7 @@ export const build = async (config, modernConfig) => {
|
|
|
30
30
|
|
|
31
31
|
if (typeof platform === 'string') {
|
|
32
32
|
if (process.env.RUN_PLATFORM) {
|
|
33
|
-
await bp.buildPlatform({
|
|
33
|
+
await bp.buildPlatform(api, {
|
|
34
34
|
platform,
|
|
35
35
|
isTsProject
|
|
36
36
|
});
|
|
@@ -44,8 +44,8 @@ export const build = async (config, modernConfig) => {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (enableWatchMode) {
|
|
47
|
-
await buildWatchFeature.buildInWatchMode(config, modernConfig);
|
|
47
|
+
await buildWatchFeature.buildInWatchMode(api, config, modernConfig);
|
|
48
48
|
} else {
|
|
49
|
-
await buildFeature.buildSourceCode(config, modernConfig);
|
|
49
|
+
await buildFeature.buildSourceCode(api, config, modernConfig);
|
|
50
50
|
}
|
|
51
51
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { Import, chalk } from '@modern-js/utils';
|
|
4
|
-
const constants = Import.lazy('./constants', require);
|
|
5
|
-
const core = Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
|
|
4
|
+
const constants = Import.lazy('./constants', require); // 硬解字符串返回相应格式的对象
|
|
6
5
|
|
|
7
6
|
const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
8
7
|
if (packageFieldValue === 'CJS+ES6') {
|
|
@@ -28,13 +27,13 @@ const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
export const getCodeInitMapper = _ => {
|
|
30
|
+
export const getCodeInitMapper = (api, _) => {
|
|
32
31
|
const {
|
|
33
32
|
output: {
|
|
34
33
|
packageFields,
|
|
35
34
|
packageMode
|
|
36
35
|
}
|
|
37
|
-
} =
|
|
36
|
+
} = api.useResolvedConfigContext();
|
|
38
37
|
let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
|
|
39
38
|
|
|
40
39
|
if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
|
|
@@ -63,7 +62,7 @@ export const getCodeInitMapper = _ => {
|
|
|
63
62
|
return initMapper;
|
|
64
63
|
}; // 获取执行构建源码的参数
|
|
65
64
|
|
|
66
|
-
export const getCodeMapper = ({
|
|
65
|
+
export const getCodeMapper = (api, {
|
|
67
66
|
logger,
|
|
68
67
|
taskPath,
|
|
69
68
|
config,
|
|
@@ -73,8 +72,8 @@ export const getCodeMapper = ({
|
|
|
73
72
|
}) => {
|
|
74
73
|
const {
|
|
75
74
|
appDirectory
|
|
76
|
-
} =
|
|
77
|
-
const modernConfig =
|
|
75
|
+
} = api.useAppContext();
|
|
76
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
78
77
|
const {
|
|
79
78
|
output: {
|
|
80
79
|
enableSourceMap,
|
|
@@ -99,11 +98,11 @@ export const getCodeMapper = ({
|
|
|
99
98
|
});
|
|
100
99
|
}; // 获取执行生成 d.ts 的参数
|
|
101
100
|
|
|
102
|
-
export const getDtsMapper = (config, logger) => {
|
|
101
|
+
export const getDtsMapper = (api, config, logger) => {
|
|
103
102
|
const {
|
|
104
103
|
appDirectory
|
|
105
|
-
} =
|
|
106
|
-
const modernConfig =
|
|
104
|
+
} = api.useAppContext();
|
|
105
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
107
106
|
const {
|
|
108
107
|
output: {
|
|
109
108
|
disableTsChecker,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Import } from '@modern-js/utils';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
4
3
|
const inquirer = Import.lazy('inquirer', require);
|
|
5
4
|
const color = Import.lazy('../../utils/color', require);
|
|
6
|
-
export const showMenu = async config => {
|
|
7
|
-
const
|
|
5
|
+
export const showMenu = async (api, config) => {
|
|
6
|
+
const runners = api.useHookRunners();
|
|
7
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
8
8
|
|
|
9
9
|
if (metas.length <= 0) {
|
|
10
10
|
console.info(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
|
|
@@ -27,8 +27,9 @@ export const showMenu = async config => {
|
|
|
27
27
|
await devMeta.runTask(config);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
export const devStorybook = async config => {
|
|
31
|
-
const
|
|
30
|
+
export const devStorybook = async (api, config) => {
|
|
31
|
+
const runners = api.useHookRunners();
|
|
32
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
32
33
|
const findStorybook = metas.find(meta => meta.value === 'storybook');
|
|
33
34
|
|
|
34
35
|
if (findStorybook) {
|
|
@@ -39,8 +40,9 @@ export const devStorybook = async config => {
|
|
|
39
40
|
process.exit(0);
|
|
40
41
|
}
|
|
41
42
|
};
|
|
42
|
-
export const runSubCmd = async (subCmd, config) => {
|
|
43
|
-
const
|
|
43
|
+
export const runSubCmd = async (api, subCmd, config) => {
|
|
44
|
+
const runners = api.useHookRunners();
|
|
45
|
+
const metas = await runners.moduleToolsMenu(undefined);
|
|
44
46
|
const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
|
|
45
47
|
|
|
46
48
|
if (devMeta) {
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import { Import } from '@modern-js/utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import ChangesetPlugin from '@modern-js/plugin-changeset';
|
|
3
|
+
import AnalyzePlugin from '@modern-js/plugin-analyze';
|
|
4
|
+
import { hooks } from '@modern-js/module-tools-hooks';
|
|
5
5
|
const cli = Import.lazy('./cli', require);
|
|
6
6
|
const local = Import.lazy('./locale', require);
|
|
7
7
|
const schema = Import.lazy('./schema', require);
|
|
8
8
|
const lang = Import.lazy('./utils/language', require);
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
locale
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
export { defineConfig } from '@modern-js/core';
|
|
10
|
+
export default (() => ({
|
|
11
|
+
name: '@modern-js/module-tools',
|
|
12
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
|
|
13
|
+
registerHook: hooks,
|
|
14
|
+
usePlugins: [ChangesetPlugin(), AnalyzePlugin()],
|
|
15
|
+
setup: api => {
|
|
16
|
+
const locale = lang.getLocaleLanguage();
|
|
17
|
+
local.i18n.changeLanguage({
|
|
18
|
+
locale
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
validateSchema() {
|
|
22
|
+
return schema.addSchema();
|
|
23
|
+
},
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
config() {
|
|
26
|
+
return {
|
|
27
|
+
output: {
|
|
28
|
+
enableSourceMap: false,
|
|
29
|
+
jsPath: 'js'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
},
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
commands({
|
|
35
|
+
program
|
|
36
|
+
}) {
|
|
37
|
+
cli.devCli(program, api);
|
|
38
|
+
cli.buildCli(program, api);
|
|
39
|
+
cli.newCli(program, locale); // 便于其他插件辨别
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
program.$$libraryName = 'module-tools';
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
@@ -66,7 +66,8 @@ const runBabelCompiler = async (config, modernConfig) => {
|
|
|
66
66
|
rootDir: config.srcRootDir,
|
|
67
67
|
distDir: config.distDir,
|
|
68
68
|
watchDir: config.srcRootDir,
|
|
69
|
-
extensions: getExts(isTs)
|
|
69
|
+
extensions: getExts(isTs),
|
|
70
|
+
ignore: ['*.d.ts']
|
|
70
71
|
}, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
71
72
|
sourceMaps: config.sourceMaps
|
|
72
73
|
}));
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { Import, fs } from '@modern-js/utils';
|
|
3
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
4
|
+
const execa = Import.lazy('execa', require);
|
|
5
|
+
const JSON5 = Import.lazy('json5', require);
|
|
6
|
+
const argv = Import.lazy('process.argv', require);
|
|
7
|
+
const utils = Import.lazy('./utils', require);
|
|
8
|
+
let removeTsconfigPath = '';
|
|
9
|
+
|
|
10
|
+
const getProjectTsconfig = tsconfigPath => {
|
|
11
|
+
if (!tsconfigPath || !fs.existsSync(tsconfigPath)) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return JSON5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const resolveLog = (childProgress, {
|
|
19
|
+
tsCheck: _tsCheck = false,
|
|
20
|
+
watch: _watch = false
|
|
21
|
+
} = {}) => {
|
|
22
|
+
var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* tsc 所有的log信息都是从stdout data 事件中获取
|
|
26
|
+
* 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理
|
|
27
|
+
* watch 模式下,则使用这里的信息
|
|
28
|
+
*/
|
|
29
|
+
(_childProgress$stdout = childProgress.stdout) === null || _childProgress$stdout === void 0 ? void 0 : _childProgress$stdout.on('data', data => {
|
|
30
|
+
if (!_tsCheck) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (_watch) {
|
|
35
|
+
console.info(data.toString());
|
|
36
|
+
}
|
|
37
|
+
}); // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
|
|
38
|
+
|
|
39
|
+
(_childProgress$stdout2 = childProgress.stdout) === null || _childProgress$stdout2 === void 0 ? void 0 : _childProgress$stdout2.on('error', error => {
|
|
40
|
+
console.error(error.message);
|
|
41
|
+
});
|
|
42
|
+
(_childProgress$stderr = childProgress.stderr) === null || _childProgress$stderr === void 0 ? void 0 : _childProgress$stderr.on('data', chunk => {
|
|
43
|
+
console.error(chunk.toString());
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const generatorDts = async (_, config) => {
|
|
48
|
+
const {
|
|
49
|
+
tsconfigPath,
|
|
50
|
+
distDir,
|
|
51
|
+
sourceDirName = 'src',
|
|
52
|
+
projectData: {
|
|
53
|
+
appDirectory
|
|
54
|
+
},
|
|
55
|
+
tsCheck = false,
|
|
56
|
+
watch = false
|
|
57
|
+
} = config;
|
|
58
|
+
const userTsconfig = getProjectTsconfig(tsconfigPath);
|
|
59
|
+
const willDeleteTsconfigPath = utils.generatorTsConfig(userTsconfig, {
|
|
60
|
+
appDirectory,
|
|
61
|
+
distDir,
|
|
62
|
+
sourceDir: sourceDirName
|
|
63
|
+
});
|
|
64
|
+
removeTsconfigPath = willDeleteTsconfigPath;
|
|
65
|
+
const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
|
|
66
|
+
const watchParams = watch ? ['-w'] : [];
|
|
67
|
+
const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
|
|
68
|
+
stdio: 'pipe',
|
|
69
|
+
cwd: appDirectory
|
|
70
|
+
});
|
|
71
|
+
resolveLog(childProgress, {
|
|
72
|
+
tsCheck,
|
|
73
|
+
watch
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await childProgress;
|
|
78
|
+
console.info('[Tsc Compiler]: Successfully');
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (!tsCheck) {
|
|
81
|
+
console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
|
|
82
|
+
} else {
|
|
83
|
+
const isRecord = input => typeof input === 'object'; // 通过使用 execa,可以将tsc 的 data 类型的报错信息变为异常错误信息
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (isRecord(e)) {
|
|
87
|
+
console.error(e.stdout);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fs.removeSync(willDeleteTsconfigPath);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const taskMain = async ({
|
|
96
|
+
modernConfig
|
|
97
|
+
}) => {
|
|
98
|
+
const processArgv = argv(process.argv.slice(2));
|
|
99
|
+
const config = processArgv({
|
|
100
|
+
appDirectory: process.cwd(),
|
|
101
|
+
srcDir: 'src',
|
|
102
|
+
distDir: 'dist/types',
|
|
103
|
+
tsconfigPath: './tsconfig.json',
|
|
104
|
+
sourceDirName: 'src'
|
|
105
|
+
});
|
|
106
|
+
const option = {
|
|
107
|
+
srcDir: config.srcDir,
|
|
108
|
+
distDir: config.distDir,
|
|
109
|
+
projectData: {
|
|
110
|
+
appDirectory: config.appDirectory
|
|
111
|
+
},
|
|
112
|
+
tsconfigPath: config.tsconfigPath,
|
|
113
|
+
watch: config.watch,
|
|
114
|
+
tsCheck: config.tsCheck,
|
|
115
|
+
sourceDirName: config.sourceDirName
|
|
116
|
+
};
|
|
117
|
+
await generatorDts(modernConfig, option); // // TODO: watch 模式下无法转换
|
|
118
|
+
|
|
119
|
+
utils.resolveAlias(modernConfig, option);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
(async () => {
|
|
123
|
+
let options;
|
|
124
|
+
|
|
125
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
126
|
+
({
|
|
127
|
+
options
|
|
128
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const {
|
|
132
|
+
resolved
|
|
133
|
+
} = await core.cli.init([], options);
|
|
134
|
+
await core.manager.run(async () => {
|
|
135
|
+
try {
|
|
136
|
+
await taskMain({
|
|
137
|
+
modernConfig: resolved
|
|
138
|
+
});
|
|
139
|
+
} catch (e) {
|
|
140
|
+
console.error(e.message);
|
|
141
|
+
fs.removeSync(removeTsconfigPath);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
})();
|