@modern-js/module-tools 2.0.0-beta.0 → 2.0.0-beta.1
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 +51 -0
- package/dist/js/modern/cli/build.js +2 -1
- package/dist/js/modern/cli/dev.js +2 -2
- package/dist/js/modern/cli/new.js +0 -3
- package/dist/js/modern/commands/build.js +0 -4
- package/dist/js/modern/commands/dev.js +2 -5
- package/dist/js/modern/features/build/build-platform.js +11 -14
- package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
- package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
- package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
- package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
- package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
- package/dist/js/modern/features/build/bundleless/index.js +0 -2
- package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
- package/dist/js/modern/features/build/bundleless/style.js +1 -30
- package/dist/js/modern/features/build/constants.js +0 -3
- package/dist/js/modern/features/build/error.js +4 -27
- package/dist/js/modern/features/build/index.js +6 -15
- package/dist/js/modern/features/build/legacy-constants.js +8 -4
- package/dist/js/modern/features/build/logger/logText.js +0 -12
- package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
- package/dist/js/modern/features/build/normalize.js +18 -43
- package/dist/js/modern/features/build/utils.js +5 -14
- package/dist/js/modern/features/dev/index.js +4 -9
- package/dist/js/modern/hooks/index.js +0 -3
- package/dist/js/modern/index.js +5 -9
- package/dist/js/modern/schema/build-config.js +2 -1
- package/dist/js/modern/schema/output.js +5 -10
- package/dist/js/modern/utils/babel.js +12 -14
- package/dist/js/modern/utils/copy.js +6 -15
- package/dist/js/modern/utils/init-env.js +0 -1
- package/dist/js/modern/utils/logger.js +1 -16
- package/dist/js/modern/utils/readline.js +2 -4
- package/dist/js/modern/utils/tsconfig.js +0 -1
- package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
- package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
- package/dist/js/modern/utils/valide.js +2 -6
- package/dist/js/node/cli/build.js +2 -6
- package/dist/js/node/cli/dev.js +2 -7
- package/dist/js/node/cli/index.js +0 -6
- package/dist/js/node/cli/new.js +0 -8
- package/dist/js/node/commands/build.js +0 -19
- package/dist/js/node/commands/dev.js +2 -15
- package/dist/js/node/commands/index.js +0 -2
- package/dist/js/node/features/build/build-platform.js +11 -20
- package/dist/js/node/features/build/bundle/index.js +0 -6
- package/dist/js/node/features/build/bundle/runRollup.js +3 -32
- package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
- package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
- package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
- package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
- package/dist/js/node/features/build/bundleless/index.js +0 -11
- package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
- package/dist/js/node/features/build/bundleless/style.js +1 -50
- package/dist/js/node/features/build/constants.js +0 -11
- package/dist/js/node/features/build/error.js +4 -40
- package/dist/js/node/features/build/index.js +6 -38
- package/dist/js/node/features/build/legacy-constants.js +8 -4
- package/dist/js/node/features/build/logger/index.js +0 -4
- package/dist/js/node/features/build/logger/logText.js +0 -18
- package/dist/js/node/features/build/logger/loggerManager.js +5 -26
- package/dist/js/node/features/build/normalize.js +18 -61
- package/dist/js/node/features/build/utils.js +5 -30
- package/dist/js/node/features/dev/index.js +4 -17
- package/dist/js/node/hooks/build.js +0 -5
- package/dist/js/node/hooks/dev.js +0 -5
- package/dist/js/node/hooks/index.js +0 -10
- package/dist/js/node/index.js +6 -26
- package/dist/js/node/locale/index.js +0 -5
- package/dist/js/node/schema/build-config.js +2 -1
- package/dist/js/node/schema/index.js +0 -5
- package/dist/js/node/schema/output.js +5 -12
- package/dist/js/node/utils/babel.js +12 -22
- package/dist/js/node/utils/color.js +0 -3
- package/dist/js/node/utils/copy.js +6 -23
- package/dist/js/node/utils/init-env.js +0 -3
- package/dist/js/node/utils/json.js +0 -2
- package/dist/js/node/utils/language.js +0 -3
- package/dist/js/node/utils/logger.js +1 -26
- package/dist/js/node/utils/readline.js +0 -8
- package/dist/js/node/utils/tsconfig.js +0 -7
- package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/node/utils/tspaths-transform/index.js +2 -34
- package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
- package/dist/js/node/utils/valide.js +2 -11
- package/dist/types/commands/build.d.ts +0 -1
- package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
- package/dist/types/features/build/utils.d.ts +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/schema/types.d.ts +1 -3
- package/dist/types/types.d.ts +0 -1
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @modern-js/module-tools
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- d61ca88: update speedy version
|
|
12
|
+
更新依赖里 speedy 的版本
|
|
13
|
+
- b8bbe036c7: feat: export Hooks type
|
|
14
|
+
feat: 导出 Hooks 类型
|
|
15
|
+
- ebbeed1: update speedy-core to fix sass resolve error
|
|
16
|
+
更新 speedy-core 版本以修复 sass resolve 错误
|
|
17
|
+
- d4a4566: chore: rename plugin-jarvis to plugin-lint
|
|
18
|
+
|
|
19
|
+
chore: 重命名 plugin-jarvis 为 plugin-lint
|
|
20
|
+
|
|
21
|
+
- 14b712d: fix: use consistent alias type and default value across packages
|
|
22
|
+
|
|
23
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [c9e800d39a]
|
|
26
|
+
- Updated dependencies [85edee888c]
|
|
27
|
+
- Updated dependencies [92f0ead]
|
|
28
|
+
- Updated dependencies [edd1cfb1af]
|
|
29
|
+
- Updated dependencies [cc971eabfc]
|
|
30
|
+
- Updated dependencies [5b9049f]
|
|
31
|
+
- Updated dependencies [d4a4566]
|
|
32
|
+
- Updated dependencies [92004d1]
|
|
33
|
+
- Updated dependencies [b8bbe036c7]
|
|
34
|
+
- Updated dependencies [d5a31df781]
|
|
35
|
+
- Updated dependencies [dda38c9]
|
|
36
|
+
- Updated dependencies [8b8e1bb571]
|
|
37
|
+
- Updated dependencies [3bbea92b2a]
|
|
38
|
+
- Updated dependencies [f179749]
|
|
39
|
+
- Updated dependencies [abf3421]
|
|
40
|
+
- Updated dependencies [543be9558e]
|
|
41
|
+
- Updated dependencies [14b712d]
|
|
42
|
+
- @modern-js/core@2.0.0-beta.1
|
|
43
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
44
|
+
- @modern-js/plugin-lint@2.0.0-beta.1
|
|
45
|
+
- @modern-js/plugin@2.0.0-beta.1
|
|
46
|
+
- @modern-js/babel-preset-module@2.0.0-beta.1
|
|
47
|
+
- @modern-js/plugin-changeset@2.0.0-beta.1
|
|
48
|
+
- @modern-js/plugin-i18n@2.0.0-beta.1
|
|
49
|
+
- @modern-js/new-action@2.0.0-beta.1
|
|
50
|
+
- @modern-js/babel-compiler@2.0.0-beta.1
|
|
51
|
+
- @modern-js/style-compiler@2.0.0-beta.1
|
|
52
|
+
- @modern-js/upgrade@2.0.0-beta.1
|
|
53
|
+
|
|
3
54
|
## 2.0.0-beta.0
|
|
4
55
|
|
|
5
56
|
### Major Changes
|
|
@@ -2,7 +2,8 @@ import { Import } from '@modern-js/utils';
|
|
|
2
2
|
const local = Import.lazy('../locale/index', require);
|
|
3
3
|
const command = Import.lazy('../commands/build', require);
|
|
4
4
|
export const buildCli = (program, api) => {
|
|
5
|
-
return 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))
|
|
5
|
+
return 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))
|
|
6
|
+
// @deprecated
|
|
6
7
|
// The `--no-tsc` option has been superceded by the `--no-dts` option.
|
|
7
8
|
.option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--dts', local.i18n.t(local.localeKeys.command.build.dts)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).option('-c --config <config>', local.i18n.t(local.localeKeys.command.build.config)).action(async subCommand => {
|
|
8
9
|
await command.build(api, subCommand);
|
|
@@ -3,8 +3,8 @@ const local = Import.lazy('../locale', require);
|
|
|
3
3
|
const commands = Import.lazy('../commands', require);
|
|
4
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(api, params, subCmd);
|
|
7
|
-
|
|
6
|
+
await commands.dev(api, params, subCmd);
|
|
7
|
+
// support plugin-proxy
|
|
8
8
|
const runner = api.useHookRunners();
|
|
9
9
|
await runner.afterDev();
|
|
10
10
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import { Import } from '@modern-js/utils';
|
|
8
5
|
const newAction = Import.lazy('@modern-js/new-action', require);
|
|
9
6
|
const local = Import.lazy('../locale', require);
|
|
@@ -8,7 +8,6 @@ const buildFeature = Import.lazy('../features/build', require);
|
|
|
8
8
|
* init work before build task.
|
|
9
9
|
* @param api
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
export const init = api => {
|
|
13
12
|
const {
|
|
14
13
|
appDirectory
|
|
@@ -18,14 +17,12 @@ export const init = api => {
|
|
|
18
17
|
if (code === 0) {
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
|
|
23
21
|
const files = globby(slash(tempTsconfigPathPattern), {
|
|
24
22
|
stats: true,
|
|
25
23
|
absolute: true
|
|
26
24
|
});
|
|
27
25
|
const currentTime = Date.now();
|
|
28
|
-
|
|
29
26
|
for (const file of files) {
|
|
30
27
|
// over 30s, will delete it
|
|
31
28
|
if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
|
|
@@ -36,7 +33,6 @@ export const init = api => {
|
|
|
36
33
|
};
|
|
37
34
|
export const build = async (api, buildCommandOption) => {
|
|
38
35
|
var _modernConfig$output$;
|
|
39
|
-
|
|
40
36
|
const {
|
|
41
37
|
watch = false,
|
|
42
38
|
tsconfig: tsconfigName,
|
|
@@ -3,9 +3,7 @@ import { dotenv, Import } from '@modern-js/utils';
|
|
|
3
3
|
const devFeature = Import.lazy('../features/dev', require);
|
|
4
4
|
const tsConfigutils = Import.lazy('../utils/tsconfig', require);
|
|
5
5
|
const valid = Import.lazy('../utils/valide', require);
|
|
6
|
-
|
|
7
6
|
const existSubCmd = subCmd => subCmd.length > 0;
|
|
8
|
-
|
|
9
7
|
export const dev = async (api, option, subCmd = '') => {
|
|
10
8
|
const {
|
|
11
9
|
tsconfig: tsconfigName
|
|
@@ -22,16 +20,15 @@ export const dev = async (api, option, subCmd = '') => {
|
|
|
22
20
|
tsconfigPath
|
|
23
21
|
});
|
|
24
22
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
25
|
-
|
|
26
23
|
if (existSubCmd(subCmd)) {
|
|
27
24
|
await devFeature.runSubCmd(api, subCmd, {
|
|
28
25
|
isTsProject,
|
|
29
26
|
appDirectory
|
|
30
27
|
});
|
|
31
28
|
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
29
|
+
}
|
|
34
30
|
|
|
31
|
+
// Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
|
|
35
32
|
if (process.env.RUN_PLATFORM) {
|
|
36
33
|
await devFeature.showMenu(api, {
|
|
37
34
|
isTsProject,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import { execa, Import, chalk } from '@modern-js/utils';
|
|
8
5
|
const lg = Import.lazy('./logger', require);
|
|
9
6
|
const pMap = Import.lazy('p-map', require);
|
|
@@ -12,18 +9,16 @@ export const buildPlatform = async (api, option) => {
|
|
|
12
9
|
isTsProject = false,
|
|
13
10
|
platform
|
|
14
11
|
} = option;
|
|
15
|
-
const lm = new lg.LoggerManager();
|
|
16
|
-
|
|
12
|
+
const lm = new lg.LoggerManager();
|
|
13
|
+
// 获取platforms的参数
|
|
17
14
|
const runners = api.useHookRunners();
|
|
18
15
|
const buildTasks = await runners.platformBuild({
|
|
19
16
|
isTsProject
|
|
20
17
|
});
|
|
21
|
-
|
|
22
18
|
if (buildTasks.length <= 0) {
|
|
23
19
|
console.info(chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
|
|
24
20
|
return;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
const loggerMap = {};
|
|
28
23
|
const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
|
|
29
24
|
const logger = lm.createLoggerText({
|
|
@@ -34,12 +29,10 @@ export const buildPlatform = async (api, option) => {
|
|
|
34
29
|
logger
|
|
35
30
|
}, params);
|
|
36
31
|
});
|
|
37
|
-
|
|
38
32
|
if (taskMapper.length <= 0) {
|
|
39
33
|
console.info(chalk.yellow(`'${platform}' is undefined task`));
|
|
40
34
|
return;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
lm.showCompiling();
|
|
44
37
|
await pMap(taskMapper, async ({
|
|
45
38
|
taskPath,
|
|
@@ -49,23 +42,27 @@ export const buildPlatform = async (api, option) => {
|
|
|
49
42
|
const childProcess = execa.node(taskPath, params, {
|
|
50
43
|
stdio: 'inherit',
|
|
51
44
|
all: true
|
|
52
|
-
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// lm.addStdout(logger, childProcess.stdout, {
|
|
53
48
|
// event: { data: true, error: true },
|
|
54
49
|
// });
|
|
55
|
-
// lm.addStderr(logger, childProcess.stderr);
|
|
56
50
|
|
|
51
|
+
// lm.addStderr(logger, childProcess.stderr);
|
|
57
52
|
try {
|
|
58
53
|
await childProcess;
|
|
59
54
|
} catch (_unused) {
|
|
60
55
|
// eslint-disable-next-line no-process-exit
|
|
61
56
|
process.exit(1);
|
|
62
|
-
}
|
|
57
|
+
}
|
|
58
|
+
// lm.disappearCompiling();
|
|
63
59
|
// console.info(lg.colors.title(title));
|
|
64
60
|
// console.info(a.all);
|
|
65
|
-
|
|
66
61
|
}, {
|
|
67
62
|
concurrency: 1
|
|
68
|
-
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// lm.disappearCompiling();
|
|
69
66
|
// for (const key of Object.keys(loggerMap)) {
|
|
70
67
|
// console.info(loggerMap[key].value);
|
|
71
68
|
// }
|
|
@@ -1,30 +1,26 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import path from 'path';
|
|
8
5
|
import ts from 'typescript';
|
|
9
6
|
import hashbangPlugin from 'rollup-plugin-hashbang';
|
|
10
7
|
import jsonPlugin from '@rollup/plugin-json';
|
|
11
8
|
import { InternalDTSError } from "../error";
|
|
12
|
-
import { SectionTitleStatus, watchSectionTitle } from "../utils";
|
|
9
|
+
import { SectionTitleStatus, watchSectionTitle } from "../utils";
|
|
10
|
+
|
|
11
|
+
// Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
|
|
13
12
|
|
|
14
13
|
const loadCompilerOptions = tsconfig => {
|
|
15
14
|
if (!tsconfig) {
|
|
16
15
|
return {};
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
const configFile = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
20
18
|
const {
|
|
21
19
|
options
|
|
22
20
|
} = ts.parseJsonConfigFileContent(configFile.config, ts.sys, './');
|
|
23
21
|
return options;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
23
|
const dtsPlugin = require('rollup-plugin-dts');
|
|
27
|
-
|
|
28
24
|
const getRollupConfig = async (api, options) => {
|
|
29
25
|
const {
|
|
30
26
|
appDirectory
|
|
@@ -46,29 +42,23 @@ const getRollupConfig = async (api, options) => {
|
|
|
46
42
|
};
|
|
47
43
|
const ignoreFiles = {
|
|
48
44
|
name: 'ignore-files',
|
|
49
|
-
|
|
50
45
|
load(id) {
|
|
51
46
|
if (!/\.(js|jsx|ts|tsx|json)$/.test(id)) {
|
|
52
47
|
return '';
|
|
53
48
|
}
|
|
54
|
-
|
|
55
49
|
return null;
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
};
|
|
59
52
|
return {
|
|
60
53
|
inputConfig: {
|
|
61
54
|
input: dtsOptions.entry,
|
|
62
55
|
external: bundleOptions.externals,
|
|
63
|
-
|
|
64
56
|
onwarn(warning, handler) {
|
|
65
57
|
if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
|
|
66
58
|
return;
|
|
67
59
|
}
|
|
68
|
-
|
|
69
60
|
handler(warning);
|
|
70
61
|
},
|
|
71
|
-
|
|
72
62
|
plugins: [hashbangPlugin(), jsonPlugin(), ignoreFiles, dtsPlugin.default({
|
|
73
63
|
// use external to prevent them which come from node_modules from be bundled.
|
|
74
64
|
respectExternal: true,
|
|
@@ -98,7 +88,6 @@ const getRollupConfig = async (api, options) => {
|
|
|
98
88
|
}
|
|
99
89
|
};
|
|
100
90
|
};
|
|
101
|
-
|
|
102
91
|
async function runRollup(options, context) {
|
|
103
92
|
try {
|
|
104
93
|
const {
|
|
@@ -114,7 +103,6 @@ async function runRollup(options, context) {
|
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
}
|
|
117
|
-
|
|
118
106
|
async function watchRollup(options) {
|
|
119
107
|
const {
|
|
120
108
|
watch
|
|
@@ -128,15 +116,14 @@ async function watchRollup(options) {
|
|
|
128
116
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
|
|
129
117
|
} else if (event.code === 'BUNDLE_END') {
|
|
130
118
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
131
|
-
} else if (event.code === 'ERROR') {
|
|
119
|
+
} else if (event.code === 'ERROR') {
|
|
120
|
+
// this is dts rollup plugin bug, error not complete message
|
|
132
121
|
}
|
|
133
122
|
});
|
|
134
123
|
}
|
|
135
|
-
|
|
136
124
|
export const startRollup = async (api, options) => {
|
|
137
125
|
if (options.enableDts) {
|
|
138
126
|
const config = await getRollupConfig(api, options);
|
|
139
|
-
|
|
140
127
|
if (options.watch) {
|
|
141
128
|
watchRollup(config);
|
|
142
129
|
} else {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import path from 'path';
|
|
8
5
|
import { SpeedyBundler } from '@speedy-js/speedy-core';
|
|
9
6
|
import { es5InputPlugin } from '@speedy-js/speedy-plugin-es5';
|
|
@@ -17,8 +14,8 @@ export const getAlias = api => {
|
|
|
17
14
|
} = api.useAppContext();
|
|
18
15
|
const {
|
|
19
16
|
source
|
|
20
|
-
} = api.useResolvedConfigContext();
|
|
21
|
-
|
|
17
|
+
} = api.useResolvedConfigContext();
|
|
18
|
+
// TODO: maybe check tsconfig `paths`
|
|
22
19
|
const defaultAlias = {
|
|
23
20
|
'@': srcDirectory
|
|
24
21
|
};
|
|
@@ -46,7 +43,6 @@ export const getDefine = api => {
|
|
|
46
43
|
}, {});
|
|
47
44
|
return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
|
|
48
45
|
};
|
|
49
|
-
|
|
50
46
|
const getStyleOptionFromModern = async api => {
|
|
51
47
|
const runner = api.useHookRunners();
|
|
52
48
|
const {
|
|
@@ -69,13 +65,10 @@ const getStyleOptionFromModern = async api => {
|
|
|
69
65
|
onLast: async _ => undefined
|
|
70
66
|
});
|
|
71
67
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
72
|
-
|
|
73
68
|
if (tailwindPlugin) {
|
|
74
69
|
var _postcssOption$plugin;
|
|
75
|
-
|
|
76
70
|
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
77
71
|
}
|
|
78
|
-
|
|
79
72
|
return {
|
|
80
73
|
less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
|
|
81
74
|
sass: sassOption,
|
|
@@ -84,7 +77,6 @@ const getStyleOptionFromModern = async api => {
|
|
|
84
77
|
})
|
|
85
78
|
};
|
|
86
79
|
};
|
|
87
|
-
|
|
88
80
|
export const runSpeedy = async (api, config) => {
|
|
89
81
|
const {
|
|
90
82
|
appDirectory
|
|
@@ -118,23 +110,19 @@ export const runSpeedy = async (api, config) => {
|
|
|
118
110
|
const style = await getStyleOptionFromModern(api);
|
|
119
111
|
const alias = getAlias(api);
|
|
120
112
|
const define = getDefine(api);
|
|
121
|
-
|
|
122
113
|
const watchPlugin = () => {
|
|
123
114
|
return {
|
|
124
115
|
name: 'watch-plugin',
|
|
125
|
-
|
|
126
116
|
apply(compiler) {
|
|
127
117
|
compiler.hooks.watchChange.tap('watch-plugin', async () => {
|
|
128
118
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
|
|
129
119
|
});
|
|
130
120
|
}
|
|
131
|
-
|
|
132
121
|
};
|
|
133
122
|
};
|
|
134
|
-
|
|
135
123
|
const plugins = target === 'es5' ? [es5InputPlugin()] : [];
|
|
136
|
-
plugins.push(watchPlugin());
|
|
137
|
-
|
|
124
|
+
plugins.push(watchPlugin());
|
|
125
|
+
// TODO: add speedy plugin about react
|
|
138
126
|
const internalSpeedyConfig = {
|
|
139
127
|
command: 'build',
|
|
140
128
|
mode: 'production',
|
|
@@ -165,12 +153,10 @@ export const runSpeedy = async (api, config) => {
|
|
|
165
153
|
};
|
|
166
154
|
const speedyConfig = applyOptionsChain(internalSpeedyConfig, userSpeedyConfig);
|
|
167
155
|
const compiler = await SpeedyBundler.create(speedyConfig);
|
|
168
|
-
|
|
169
156
|
try {
|
|
170
157
|
if (watch) {
|
|
171
158
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
|
|
172
159
|
}
|
|
173
|
-
|
|
174
160
|
await compiler.build();
|
|
175
161
|
} catch (e) {
|
|
176
162
|
/**
|
|
@@ -2,7 +2,6 @@ import * as path from 'path';
|
|
|
2
2
|
import { fs, watch, glob, WatchChangeType, Import } from '@modern-js/utils';
|
|
3
3
|
const copyUtils = Import.lazy('../../../utils/copy', require);
|
|
4
4
|
const SRC_DIRS = 'src';
|
|
5
|
-
|
|
6
5
|
const copyAssets = ({
|
|
7
6
|
targetDir,
|
|
8
7
|
outputDir
|
|
@@ -10,18 +9,15 @@ const copyAssets = ({
|
|
|
10
9
|
const assetsFiles = glob.sync(`${targetDir}/**/*.*`, {
|
|
11
10
|
ignore: ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']
|
|
12
11
|
});
|
|
13
|
-
|
|
14
12
|
if (assetsFiles.length > 0) {
|
|
15
13
|
fs.ensureDirSync(outputDir);
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
for (const resource of assetsFiles) {
|
|
19
16
|
const file = path.relative(targetDir, resource);
|
|
20
17
|
fs.ensureDirSync(path.dirname(path.resolve(outputDir, file)));
|
|
21
18
|
fs.copyFileSync(resource, path.resolve(outputDir, file));
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
|
|
25
21
|
const watchAssets = (api, {
|
|
26
22
|
targetDir,
|
|
27
23
|
outputDir
|
|
@@ -35,15 +31,12 @@ const watchAssets = (api, {
|
|
|
35
31
|
fs.removeSync(removeFile);
|
|
36
32
|
return;
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
const file = path.relative(targetDir, changedFilePath);
|
|
40
35
|
fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
|
|
41
36
|
}, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
|
|
42
37
|
};
|
|
43
|
-
|
|
44
38
|
export const copyStaticAssets = async (api, config) => {
|
|
45
39
|
var _bundlelessOptions$so;
|
|
46
|
-
|
|
47
40
|
const appContext = api.useAppContext();
|
|
48
41
|
const modernConfig = api.useResolvedConfigContext();
|
|
49
42
|
const {
|
|
@@ -73,7 +66,6 @@ export const copyStaticAssets = async (api, config) => {
|
|
|
73
66
|
modernConfig,
|
|
74
67
|
appContext
|
|
75
68
|
});
|
|
76
|
-
|
|
77
69
|
if (config.watch) {
|
|
78
70
|
watchAssets(api, {
|
|
79
71
|
targetDir: srcDir,
|
|
@@ -4,20 +4,16 @@ import { InternalDTSError } from "../../error";
|
|
|
4
4
|
import { SectionTitleStatus, watchSectionTitle } from "../../utils";
|
|
5
5
|
import { getTscBinPath } from "./utils";
|
|
6
6
|
const utils = Import.lazy('./utils', require);
|
|
7
|
-
|
|
8
7
|
const getProjectTsconfig = tsconfigPath => {
|
|
9
8
|
if (!tsconfigPath || !fs.existsSync(tsconfigPath)) {
|
|
10
9
|
return {};
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
const resolveLog = (childProgress, {
|
|
17
14
|
watch: _watch = false
|
|
18
15
|
} = {}) => {
|
|
19
16
|
var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
|
|
20
|
-
|
|
21
17
|
/**
|
|
22
18
|
* tsc 所有的log信息都是从stdout data 事件中获取
|
|
23
19
|
* 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理
|
|
@@ -28,8 +24,8 @@ const resolveLog = (childProgress, {
|
|
|
28
24
|
console.info(watchSectionTitle('[Bundleless:DTS]', SectionTitleStatus.Log));
|
|
29
25
|
console.info(data.toString());
|
|
30
26
|
}
|
|
31
|
-
});
|
|
32
|
-
|
|
27
|
+
});
|
|
28
|
+
// 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
|
|
33
29
|
(_childProgress$stdout2 = childProgress.stdout) === null || _childProgress$stdout2 === void 0 ? void 0 : _childProgress$stdout2.on('error', error => {
|
|
34
30
|
console.error(error.message);
|
|
35
31
|
});
|
|
@@ -37,7 +33,6 @@ const resolveLog = (childProgress, {
|
|
|
37
33
|
console.error(chunk.toString());
|
|
38
34
|
});
|
|
39
35
|
};
|
|
40
|
-
|
|
41
36
|
const generatorDts = async (_, config) => {
|
|
42
37
|
const {
|
|
43
38
|
tsconfigPath,
|
|
@@ -54,9 +49,9 @@ const generatorDts = async (_, config) => {
|
|
|
54
49
|
});
|
|
55
50
|
const tscBinFile = getTscBinPath(appDirectory);
|
|
56
51
|
const watchParams = watch ? ['-w'] : [];
|
|
57
|
-
const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath,
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, /* Required parameter, use it stdout have color */
|
|
53
|
+
'--pretty',
|
|
54
|
+
// https://github.com/microsoft/TypeScript/issues/21824
|
|
60
55
|
'--preserveWatchOutput', ...watchParams], {
|
|
61
56
|
stdio: 'pipe',
|
|
62
57
|
cwd: appDirectory
|
|
@@ -64,7 +59,6 @@ const generatorDts = async (_, config) => {
|
|
|
64
59
|
resolveLog(childProgress, {
|
|
65
60
|
watch
|
|
66
61
|
});
|
|
67
|
-
|
|
68
62
|
try {
|
|
69
63
|
await childProgress;
|
|
70
64
|
} catch (e) {
|
|
@@ -74,10 +68,8 @@ const generatorDts = async (_, config) => {
|
|
|
74
68
|
});
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
|
-
|
|
78
71
|
fs.removeSync(willDeleteTsconfigPath);
|
|
79
72
|
};
|
|
80
|
-
|
|
81
73
|
export const genDts = async (api, config) => {
|
|
82
74
|
const {
|
|
83
75
|
outputPath,
|
|
@@ -88,11 +80,9 @@ export const genDts = async (api, config) => {
|
|
|
88
80
|
},
|
|
89
81
|
enableDts
|
|
90
82
|
} = config;
|
|
91
|
-
|
|
92
83
|
if (!enableDts) {
|
|
93
84
|
return;
|
|
94
85
|
}
|
|
95
|
-
|
|
96
86
|
const {
|
|
97
87
|
appDirectory
|
|
98
88
|
} = api.useAppContext();
|
|
@@ -110,7 +100,7 @@ export const genDts = async (api, config) => {
|
|
|
110
100
|
watch,
|
|
111
101
|
sourceDir
|
|
112
102
|
};
|
|
113
|
-
await generatorDts(modernConfig, option);
|
|
114
|
-
|
|
103
|
+
await generatorDts(modernConfig, option);
|
|
104
|
+
// TODO: watch 模式下无法转换
|
|
115
105
|
utils.resolveAlias(modernConfig, option);
|
|
116
106
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import * as path from 'path';
|
|
8
5
|
import { Import, glob, fs, nanoid } from '@modern-js/utils';
|
|
9
6
|
import { merge as deepMerge } from '@modern-js/utils/lodash';
|
|
@@ -15,17 +12,16 @@ export const generatorTsConfig = (projectTsconfig, {
|
|
|
15
12
|
sourceDir: _sourceDir = 'src'
|
|
16
13
|
}) => {
|
|
17
14
|
var _projectTsconfig$comp, _projectTsconfig$comp2, _ref, _projectTsconfig$excl;
|
|
18
|
-
|
|
19
15
|
const tempPath = path.resolve(appDirectory, './node_modules');
|
|
20
|
-
const resolvePath = path.relative(tempPath, appDirectory);
|
|
16
|
+
const resolvePath = path.relative(tempPath, appDirectory);
|
|
17
|
+
// const rootDir = projectTsconfig.compilerOptions?.rootDir
|
|
21
18
|
// ? path.join(resolvePath, projectTsconfig.compilerOptions?.rootDir)
|
|
22
19
|
// : resolvePath;
|
|
23
20
|
// 目前限制 rootDir 的路径为 sourceDir
|
|
24
|
-
|
|
25
21
|
const rootDir = path.join(resolvePath, _sourceDir);
|
|
26
|
-
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;
|
|
22
|
+
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;
|
|
23
|
+
// if include = ['src'], final include should be ['../src']
|
|
27
24
|
// const include = projectTsconfig.include?.map(includePath =>
|
|
28
|
-
|
|
29
25
|
const include = (_ref = [_sourceDir]) === null || _ref === void 0 ? void 0 : _ref.map(includePath => path.join(resolvePath, includePath));
|
|
30
26
|
const exclude = (_projectTsconfig$excl = projectTsconfig.exclude) === null || _projectTsconfig$excl === void 0 ? void 0 : _projectTsconfig$excl.map(excludePath => path.join(resolvePath, excludePath));
|
|
31
27
|
const resetConfig = {
|
|
@@ -40,11 +36,9 @@ export const generatorTsConfig = (projectTsconfig, {
|
|
|
40
36
|
include,
|
|
41
37
|
exclude
|
|
42
38
|
};
|
|
43
|
-
|
|
44
39
|
if (projectTsconfig.extends) {
|
|
45
40
|
resetConfig.extends = projectTsconfig.extends.startsWith('.') ? path.join(resolvePath, projectTsconfig.extends) : projectTsconfig.extends;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
const recommendOption = {
|
|
49
43
|
// Ensure that Babel can safely transpile files in the TypeScript project
|
|
50
44
|
compilerOptions: {
|
|
@@ -53,7 +47,8 @@ export const generatorTsConfig = (projectTsconfig, {
|
|
|
53
47
|
};
|
|
54
48
|
const tempTsconfigPath = path.join(tempPath, `tsconfig.${Date.now()}.${nanoid()}.json`);
|
|
55
49
|
fs.ensureFileSync(tempTsconfigPath);
|
|
56
|
-
fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig,
|
|
50
|
+
fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig,
|
|
51
|
+
// 此处是必须要覆盖用户默认配置
|
|
57
52
|
resetConfig));
|
|
58
53
|
return tempTsconfigPath;
|
|
59
54
|
};
|
|
@@ -79,7 +74,6 @@ export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
|
|
|
79
74
|
baseUrl: path.join(config.appDirectory, output.path || 'dist'),
|
|
80
75
|
paths: mergedPaths
|
|
81
76
|
});
|
|
82
|
-
|
|
83
77
|
for (const r of result) {
|
|
84
78
|
fs.writeFileSync(r.path, r.content);
|
|
85
79
|
}
|
|
@@ -89,16 +83,12 @@ export const getTscBinPath = appDirectory => {
|
|
|
89
83
|
root
|
|
90
84
|
} = path.parse(appDirectory);
|
|
91
85
|
let currentDirectory = appDirectory;
|
|
92
|
-
|
|
93
86
|
while (currentDirectory !== root) {
|
|
94
87
|
const tscBinFile = path.join(currentDirectory, './node_modules/.bin/tsc');
|
|
95
|
-
|
|
96
88
|
if (fs.existsSync(tscBinFile)) {
|
|
97
89
|
return tscBinFile;
|
|
98
90
|
}
|
|
99
|
-
|
|
100
91
|
currentDirectory = path.dirname(currentDirectory);
|
|
101
92
|
}
|
|
102
|
-
|
|
103
93
|
throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
|
|
104
94
|
};
|
|
@@ -10,12 +10,10 @@ export const build = async (api, config, legacyOptions) => {
|
|
|
10
10
|
console.info(chalk.yellowBright('bundleless 构建暂时不支持 umd 格式'));
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
if (legacyOptions !== null && legacyOptions !== void 0 && legacyOptions.styleOnly) {
|
|
15
14
|
await buildStyle(api, config);
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
const tasks = config.dtsOnly ? [genDts] : [runBabelBuild, genDts, buildStyle, copyStaticAssets];
|
|
20
18
|
await pMap(tasks, async task => {
|
|
21
19
|
await task(api, config);
|