@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
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { Import, fs } from '@modern-js/utils';
|
|
9
|
+
const glob = Import.lazy('glob', require);
|
|
10
|
+
const babel = Import.lazy('../../utils/babel', require);
|
|
11
|
+
const tsPathsTransform = Import.lazy('../../utils/tspaths-transform', require);
|
|
12
|
+
const constants = Import.lazy('../constants', require);
|
|
13
|
+
const deepMerge = Import.lazy('lodash.merge', require);
|
|
14
|
+
export const generatorTsConfig = (projectTsconfig, {
|
|
15
|
+
appDirectory,
|
|
16
|
+
distDir,
|
|
17
|
+
sourceDir: _sourceDir = 'src'
|
|
18
|
+
}) => {
|
|
19
|
+
var _projectTsconfig$comp, _projectTsconfig$comp2, _projectTsconfig$incl, _projectTsconfig$excl;
|
|
20
|
+
|
|
21
|
+
const tempPath = path.resolve(appDirectory, './node_modules');
|
|
22
|
+
const resolvePath = path.relative(tempPath, appDirectory); // const rootDir = projectTsconfig.compilerOptions?.rootDir
|
|
23
|
+
// ? path.join(resolvePath, projectTsconfig.compilerOptions?.rootDir)
|
|
24
|
+
// : resolvePath;
|
|
25
|
+
// 目前限制 rootDir 的路径为 sourceDir
|
|
26
|
+
|
|
27
|
+
const rootDir = path.join(resolvePath, _sourceDir);
|
|
28
|
+
const baseUrl = (_projectTsconfig$comp = projectTsconfig.compilerOptions) !== null && _projectTsconfig$comp !== void 0 && _projectTsconfig$comp.baseUrl ? path.join(appDirectory, (_projectTsconfig$comp2 = projectTsconfig.compilerOptions) === null || _projectTsconfig$comp2 === void 0 ? void 0 : _projectTsconfig$comp2.baseUrl) : appDirectory; // if include = ['src'], final include should be ['../src']
|
|
29
|
+
|
|
30
|
+
const include = (_projectTsconfig$incl = projectTsconfig.include) === null || _projectTsconfig$incl === void 0 ? void 0 : _projectTsconfig$incl.map(includePath => path.join(resolvePath, includePath));
|
|
31
|
+
const exclude = (_projectTsconfig$excl = projectTsconfig.exclude) === null || _projectTsconfig$excl === void 0 ? void 0 : _projectTsconfig$excl.map(excludePath => path.join(resolvePath, excludePath));
|
|
32
|
+
const resetConfig = {
|
|
33
|
+
compilerOptions: {
|
|
34
|
+
rootDir,
|
|
35
|
+
baseUrl,
|
|
36
|
+
// Ensure that .d.ts files are created by tsc, but not .js files
|
|
37
|
+
declaration: true,
|
|
38
|
+
emitDeclarationOnly: true,
|
|
39
|
+
outDir: distDir
|
|
40
|
+
},
|
|
41
|
+
include,
|
|
42
|
+
exclude
|
|
43
|
+
};
|
|
44
|
+
const recommendOption = {
|
|
45
|
+
// Ensure that Babel can safely transpile files in the TypeScript project
|
|
46
|
+
compilerOptions: {
|
|
47
|
+
isolatedModules: true
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const tempTsconfigPath = path.join(tempPath, constants.tempTsconfigName);
|
|
51
|
+
fs.ensureFileSync(tempTsconfigPath);
|
|
52
|
+
fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
|
|
53
|
+
resetConfig));
|
|
54
|
+
return tempTsconfigPath;
|
|
55
|
+
};
|
|
56
|
+
export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
|
|
57
|
+
const {
|
|
58
|
+
output
|
|
59
|
+
} = modernConfig;
|
|
60
|
+
const defaultPaths = {
|
|
61
|
+
'@': ['./src']
|
|
62
|
+
};
|
|
63
|
+
const dtsDistPath = `${config.distDir}/**/*.d.ts`;
|
|
64
|
+
const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : glob.sync(dtsDistPath, {
|
|
65
|
+
absolute: true
|
|
66
|
+
});
|
|
67
|
+
const alias = babel.getFinalAlias(modernConfig, {
|
|
68
|
+
appDirectory: config.projectData.appDirectory,
|
|
69
|
+
tsconfigPath: config.tsconfigPath || path.join(config.projectData.appDirectory, './tsconfig.json'),
|
|
70
|
+
sourceAbsDir: config.distDir
|
|
71
|
+
});
|
|
72
|
+
const mergedPaths = alias.isTsPath ? alias.paths || {} : _objectSpread(_objectSpread({}, defaultPaths), alias.paths || {});
|
|
73
|
+
const result = tsPathsTransform.transformDtsAlias({
|
|
74
|
+
filenames: dtsFilenames,
|
|
75
|
+
baseUrl: path.join(config.projectData.appDirectory, output.path || 'dist'),
|
|
76
|
+
paths: mergedPaths
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
for (const r of result) {
|
|
80
|
+
fs.writeFileSync(r.path, r.content);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -5,7 +5,7 @@ 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 { getBabelConfig, getModuleBabelChain } from '@modern-js/babel-preset-module';
|
|
8
|
-
import { applyOptionsChain, getAlias } from '@modern-js/utils';
|
|
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); // 排除内部别名,因为不需要处理
|
|
11
11
|
|
|
@@ -36,7 +36,8 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
|
|
|
36
36
|
importStyle
|
|
37
37
|
},
|
|
38
38
|
tools: {
|
|
39
|
-
lodash: userLodashOption
|
|
39
|
+
lodash: userLodashOption,
|
|
40
|
+
styledComponents
|
|
40
41
|
}
|
|
41
42
|
} = modernConfig; // alias config
|
|
42
43
|
|
|
@@ -58,7 +59,13 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
|
|
|
58
59
|
globalVars,
|
|
59
60
|
lodashOptions,
|
|
60
61
|
jsxTransformRuntime,
|
|
61
|
-
importStyle
|
|
62
|
+
importStyle,
|
|
63
|
+
styledComponentsOptions: applyOptionsChain({
|
|
64
|
+
pure: true,
|
|
65
|
+
displayName: true,
|
|
66
|
+
ssr: isUseSSRBundle(modernConfig),
|
|
67
|
+
transpileTemplateLiterals: true
|
|
68
|
+
}, styledComponents)
|
|
62
69
|
}, {
|
|
63
70
|
type: option.type,
|
|
64
71
|
syntax: option.syntax
|
|
@@ -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,18 +30,18 @@ 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);
|
|
40
|
-
const enableTscCompiler = isTsProject && tsc;
|
|
38
|
+
const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
|
|
41
39
|
valid.valideBeforeTask({
|
|
42
40
|
modernConfig,
|
|
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,21 @@ 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
16
|
const execa = _utils.Import.lazy('execa', require);
|
|
19
17
|
|
|
20
18
|
const lg = _utils.Import.lazy('./logger', require);
|
|
21
19
|
|
|
22
20
|
const pMap = _utils.Import.lazy('p-map', require);
|
|
23
21
|
|
|
24
|
-
const buildPlatform = async option => {
|
|
22
|
+
const buildPlatform = async (api, option) => {
|
|
25
23
|
const {
|
|
26
24
|
isTsProject = false,
|
|
27
25
|
platform
|
|
28
26
|
} = option;
|
|
29
27
|
const lm = new lg.LoggerManager(); // 获取platforms的参数
|
|
30
28
|
|
|
31
|
-
const
|
|
29
|
+
const runners = api.useHookRunners();
|
|
30
|
+
const buildTasks = await runners.platformBuild({
|
|
32
31
|
isTsProject
|
|
33
32
|
});
|
|
34
33
|
|
|
@@ -15,8 +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
18
|
const execa = _utils.Import.lazy('execa', require);
|
|
21
19
|
|
|
22
20
|
const lg = _utils.Import.lazy('./logger', require);
|
|
@@ -27,10 +25,10 @@ const utils = _utils.Import.lazy('./utils', require);
|
|
|
27
25
|
|
|
28
26
|
const constants = _utils.Import.lazy('./constants', require);
|
|
29
27
|
|
|
30
|
-
const buildInWatchMode = async (config, _) => {
|
|
28
|
+
const buildInWatchMode = async (api, config, _) => {
|
|
31
29
|
const {
|
|
32
30
|
appDirectory
|
|
33
|
-
} =
|
|
31
|
+
} = api.useAppContext();
|
|
34
32
|
const {
|
|
35
33
|
sourceDir,
|
|
36
34
|
enableTscCompiler
|
|
@@ -50,15 +48,15 @@ const buildInWatchMode = async (config, _) => {
|
|
|
50
48
|
const copyLog = lm.createLoggerText({
|
|
51
49
|
title: 'Copy Log:'
|
|
52
50
|
});
|
|
53
|
-
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
54
|
-
const taskMapper = [...utils.getCodeMapper({
|
|
51
|
+
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
52
|
+
const taskMapper = [...utils.getCodeMapper(api, {
|
|
55
53
|
logger: codeLog,
|
|
56
54
|
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
57
55
|
config,
|
|
58
56
|
willCompilerDirOrFile: sourceDir,
|
|
59
57
|
initMapper: initCodeMapper,
|
|
60
58
|
srcRootDir
|
|
61
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
59
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
62
60
|
logger: styleLog,
|
|
63
61
|
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
64
62
|
}, {
|
|
@@ -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;
|
|
@@ -78,7 +78,8 @@ const runBabelCompiler = async (config, modernConfig) => {
|
|
|
78
78
|
rootDir: config.srcRootDir,
|
|
79
79
|
distDir: config.distDir,
|
|
80
80
|
watchDir: config.srcRootDir,
|
|
81
|
-
extensions: getExts(isTs)
|
|
81
|
+
extensions: getExts(isTs),
|
|
82
|
+
ignore: ['*.d.ts']
|
|
82
83
|
}, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
83
84
|
sourceMaps: config.sourceMaps
|
|
84
85
|
}));
|