@modern-js/module-tools 1.5.7 → 1.6.0-alpha.0
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 +34 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +40 -27
- package/dist/js/modern/features/build/bundle/index.js +6 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/modern/features/build/bundleless/index.js +13 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +84 -19
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +293 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +29 -137
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +104 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +50 -29
- package/dist/js/node/features/build/bundle/index.js +17 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/node/features/build/bundleless/index.js +26 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +92 -19
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +322 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +31 -145
- package/dist/js/node/index.js +5 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +113 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/cli/new.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +4 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
- package/dist/types/features/build/normalize.d.ts +18 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +9 -31
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +179 -0
- package/dist/types/schema/index.d.ts +166 -18
- package/dist/types/schema/output.d.ts +170 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +45 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/dist/types/utils/logger.d.ts +2 -0
- package/package.json +28 -15
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -207
- package/dist/js/modern/tasks/build-style.js +0 -168
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
- package/dist/js/modern/tasks/build-watch-style.js +0 -215
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -233
- package/dist/js/node/tasks/build-style.js +0 -183
- package/dist/js/node/tasks/build-watch-source-code.js +0 -173
- package/dist/js/node/tasks/build-watch-style.js +0 -232
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { OutputConfig, SourceConfig } from '@modern-js/core/config';
|
|
2
1
|
import type { ImportStyleType } from '@modern-js/babel-preset-module';
|
|
3
|
-
import type {
|
|
2
|
+
import type { CLIConfig as SpeedyConfig } from '@speedy-js/speedy-core';
|
|
4
3
|
import type { LoggerText } from './features/build/logger/logText';
|
|
5
4
|
import type { Platform } from './features/build/build-platform';
|
|
5
|
+
import type { BuildPreset, BuildConfig, PackageModeType, PackageFields } from './schema/types';
|
|
6
6
|
export type { Platform } from './features/build/build-platform';
|
|
7
7
|
export type { ITsconfig } from './utils/tsconfig';
|
|
8
8
|
export interface ITaskMapper {
|
|
@@ -10,23 +10,16 @@ export interface ITaskMapper {
|
|
|
10
10
|
taskPath: string;
|
|
11
11
|
params?: string[];
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
export declare type JsSyntaxType = 'CJS+ES6' | 'ESM+ES5' | 'ESM+ES6';
|
|
15
|
-
export interface IPackageFields {
|
|
16
|
-
main?: JsSyntaxType;
|
|
17
|
-
modern?: JsSyntaxType;
|
|
18
|
-
module?: JsSyntaxType;
|
|
19
|
-
}
|
|
20
|
-
export interface IBuildConfig {
|
|
21
|
-
appDirectory: string;
|
|
13
|
+
export interface IBuildFeatOption {
|
|
22
14
|
platform: boolean | Exclude<Platform, 'all'>;
|
|
23
|
-
|
|
15
|
+
enableDtsGen: boolean;
|
|
24
16
|
enableWatchMode?: boolean;
|
|
25
17
|
isTsProject: boolean;
|
|
26
|
-
|
|
27
|
-
tsconfigName?: string;
|
|
18
|
+
tsconfigName: string;
|
|
28
19
|
clear?: boolean;
|
|
29
20
|
styleOnly?: boolean;
|
|
21
|
+
outputPath: string;
|
|
22
|
+
legacyTsc: boolean;
|
|
30
23
|
}
|
|
31
24
|
export interface IPackageModeValue {
|
|
32
25
|
type: 'module' | 'commonjs';
|
|
@@ -34,18 +27,26 @@ export interface IPackageModeValue {
|
|
|
34
27
|
outDir: 'node' | 'treeshaking' | 'modern';
|
|
35
28
|
copyDirs?: ('node' | 'treeshaking' | 'modern')[];
|
|
36
29
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
disableTsChecker: boolean;
|
|
40
|
-
enableSourceMap: boolean;
|
|
41
|
-
packageMode: PackageModeType;
|
|
42
|
-
packageFields: IPackageFields;
|
|
43
|
-
importStyle: ImportStyleType;
|
|
44
|
-
}
|
|
45
|
-
export interface ModuleToolsSource extends SourceConfig {
|
|
46
|
-
jsxTransformRuntime: 'automatic' | 'classic';
|
|
30
|
+
interface ToolsConfig {
|
|
31
|
+
speedy?: SpeedyConfig | ((config: SpeedyConfig) => SpeedyConfig);
|
|
47
32
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
declare module '@modern-js/core' {
|
|
34
|
+
interface OutputConfig {
|
|
35
|
+
/** @deprecated Use the `buildConfig.bundlelessOptions.static.path` instead . */
|
|
36
|
+
assetsPath?: string;
|
|
37
|
+
/** @deprecated Use the `buildConfig.sourceMap` instead */
|
|
38
|
+
|
|
39
|
+
disableSourceMap?: boolean;
|
|
40
|
+
buildPreset?: BuildPreset;
|
|
41
|
+
buildConfig?: BuildConfig;
|
|
42
|
+
importStyle?: ImportStyleType;
|
|
43
|
+
packageMode?: PackageModeType;
|
|
44
|
+
packageFields?: PackageFields;
|
|
45
|
+
}
|
|
46
|
+
interface NormalizedToolsConfig {
|
|
47
|
+
speedy: ToolsConfig['speedy'] | Array<NonNullable<ToolsConfig['speedy']>>;
|
|
48
|
+
}
|
|
49
|
+
interface SourceConfig {
|
|
50
|
+
jsxTransformRuntime?: 'automatic' | 'classic';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
2
|
-
import { IPackageModeValue } from '../types';
|
|
2
|
+
import type { IPackageModeValue } from '../types';
|
|
3
|
+
import type { BundlelessOptions, SourceMap } from '../schema/types';
|
|
3
4
|
export declare const getFinalAlias: any;
|
|
4
|
-
export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, option: Pick<IPackageModeValue, 'syntax' | 'type'> & {
|
|
5
|
+
export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, sourceMap: SourceMap, bundlelessOptions: Required<BundlelessOptions>, option: Pick<IPackageModeValue, 'syntax' | 'type'> & {
|
|
5
6
|
sourceAbsDir: string;
|
|
6
7
|
tsconfigPath: string;
|
|
7
8
|
}) => import("@modern-js/core").TransformOptions;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.6.0-alpha.0",
|
|
15
15
|
"bin": {
|
|
16
16
|
"modern": "./bin/modern.js"
|
|
17
17
|
},
|
|
@@ -54,25 +54,34 @@
|
|
|
54
54
|
"@babel/runtime": "^7.18.0",
|
|
55
55
|
"@babel/traverse": "^7.18.0",
|
|
56
56
|
"@babel/types": "^7.18.0",
|
|
57
|
-
"@modern-js/babel-compiler": "^1.2.
|
|
58
|
-
"@modern-js/babel-preset-module": "^1.
|
|
59
|
-
"@modern-js/core": "^1.12.0",
|
|
60
|
-
"@modern-js/css-config": "^1.2.
|
|
57
|
+
"@modern-js/babel-compiler": "^1.2.7-alpha.0",
|
|
58
|
+
"@modern-js/babel-preset-module": "^1.4.0-alpha.0",
|
|
59
|
+
"@modern-js/core": "^1.12.2-alpha.0",
|
|
60
|
+
"@modern-js/css-config": "^1.2.8-alpha.0",
|
|
61
61
|
"@modern-js/i18n-cli-language-detector": "^1.2.4",
|
|
62
|
-
"@modern-js/new-action": "^1.3.
|
|
63
|
-
"@modern-js/plugin": "^1.
|
|
64
|
-
"@modern-js/plugin-analyze": "^1.4.
|
|
65
|
-
"@modern-js/plugin-changeset": "^1.
|
|
66
|
-
"@modern-js/plugin-i18n": "^1.2.
|
|
67
|
-
"@modern-js/
|
|
68
|
-
"@modern-js/
|
|
62
|
+
"@modern-js/new-action": "^1.3.11-alpha.0",
|
|
63
|
+
"@modern-js/plugin": "^1.4.0-alpha.0",
|
|
64
|
+
"@modern-js/plugin-analyze": "^1.4.7-alpha.0",
|
|
65
|
+
"@modern-js/plugin-changeset": "^1.3.1-alpha.0",
|
|
66
|
+
"@modern-js/plugin-i18n": "^1.2.8-alpha.0",
|
|
67
|
+
"@modern-js/plugin-jarvis": "^1.2.14-alpha.0",
|
|
68
|
+
"@modern-js/style-compiler": "^1.2.11-alpha.0",
|
|
69
|
+
"@modern-js/utils": "^1.7.9-alpha.0",
|
|
70
|
+
"@rollup/plugin-json": "~4.1.0",
|
|
71
|
+
"@speedy-js/speedy-core": "0.13.1",
|
|
72
|
+
"@speedy-js/speedy-plugin-es5": "0.13.1",
|
|
69
73
|
"normalize-path": "^3.0.0",
|
|
70
74
|
"p-map": "^4",
|
|
71
|
-
"process.argv": "^0.6.0"
|
|
75
|
+
"process.argv": "^0.6.0",
|
|
76
|
+
"rollup": "^2.70.2",
|
|
77
|
+
"rollup-plugin-dts": "^4.2.1",
|
|
78
|
+
"rollup-plugin-hashbang": "^3.0.0",
|
|
79
|
+
"signal-exit": "^3.0.7"
|
|
72
80
|
},
|
|
73
81
|
"devDependencies": {
|
|
74
82
|
"@scripts/build": "0.0.0",
|
|
75
83
|
"@scripts/jest-config": "0.0.0",
|
|
84
|
+
"@speedy-js/speedy-types": "0.13.1",
|
|
76
85
|
"@types/babel__core": "^7.1.15",
|
|
77
86
|
"@types/babel__generator": "^7.6.3",
|
|
78
87
|
"@types/babel__traverse": "^7.14.2",
|
|
@@ -82,8 +91,11 @@
|
|
|
82
91
|
"@types/normalize-path": "^3.0.0",
|
|
83
92
|
"@types/react": "^17",
|
|
84
93
|
"@types/react-dom": "^17",
|
|
94
|
+
"@types/signal-exit": "^3.0.1",
|
|
85
95
|
"jest": "^27",
|
|
86
|
-
"typescript": "^4"
|
|
96
|
+
"typescript": "^4",
|
|
97
|
+
"ajv": "^8",
|
|
98
|
+
"ajv-keywords": "^5"
|
|
87
99
|
},
|
|
88
100
|
"sideEffects": false,
|
|
89
101
|
"modernConfig": {
|
|
@@ -121,7 +133,8 @@
|
|
|
121
133
|
"scripts": {
|
|
122
134
|
"new": "modern new",
|
|
123
135
|
"build": "wireit",
|
|
124
|
-
"test": "wireit"
|
|
136
|
+
"test": "wireit",
|
|
137
|
+
"dev": "modern build --watch"
|
|
125
138
|
},
|
|
126
139
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
127
140
|
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import { execa, Import } from '@modern-js/utils';
|
|
4
|
-
const lg = Import.lazy('./logger', require);
|
|
5
|
-
const pMap = Import.lazy('p-map', require);
|
|
6
|
-
const utils = Import.lazy('./utils', require);
|
|
7
|
-
const constants = Import.lazy('./constants', require);
|
|
8
|
-
export const buildInWatchMode = async (api, config, _) => {
|
|
9
|
-
const {
|
|
10
|
-
appDirectory
|
|
11
|
-
} = api.useAppContext();
|
|
12
|
-
const {
|
|
13
|
-
sourceDir,
|
|
14
|
-
enableTscCompiler
|
|
15
|
-
} = config;
|
|
16
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
17
|
-
const concurrency = os.cpus().length;
|
|
18
|
-
const lm = new lg.LoggerManager();
|
|
19
|
-
const codeLog = lm.createLoggerText({
|
|
20
|
-
title: constants.runBabelCompilerTitle
|
|
21
|
-
});
|
|
22
|
-
const dtsLog = lm.createLoggerText({
|
|
23
|
-
title: constants.runTscWatchTitle
|
|
24
|
-
});
|
|
25
|
-
const styleLog = lm.createLoggerText({
|
|
26
|
-
title: constants.runStyleCompilerTitle
|
|
27
|
-
});
|
|
28
|
-
const copyLog = lm.createLoggerText({
|
|
29
|
-
title: 'Copy Log:'
|
|
30
|
-
});
|
|
31
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
32
|
-
const taskMapper = [...utils.getCodeMapper(api, {
|
|
33
|
-
logger: codeLog,
|
|
34
|
-
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
35
|
-
config,
|
|
36
|
-
willCompilerDirOrFile: sourceDir,
|
|
37
|
-
initMapper: initCodeMapper,
|
|
38
|
-
srcRootDir
|
|
39
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
40
|
-
logger: styleLog,
|
|
41
|
-
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
42
|
-
}, {
|
|
43
|
-
logger: copyLog,
|
|
44
|
-
taskPath: require.resolve("../../tasks/copy-assets"),
|
|
45
|
-
params: ['--watch']
|
|
46
|
-
}];
|
|
47
|
-
lm.on('data', () => {
|
|
48
|
-
console.info(constants.clearFlag);
|
|
49
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
50
|
-
console.info(codeLog.value);
|
|
51
|
-
console.info(styleLog.value);
|
|
52
|
-
});
|
|
53
|
-
await pMap(taskMapper, async ({
|
|
54
|
-
logger,
|
|
55
|
-
taskPath,
|
|
56
|
-
params
|
|
57
|
-
}) => {
|
|
58
|
-
const childProcess = execa.node(taskPath, params, {
|
|
59
|
-
stdio: 'pipe'
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (logger === codeLog) {
|
|
63
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
64
|
-
event: {
|
|
65
|
-
error: true,
|
|
66
|
-
data: true
|
|
67
|
-
} // colors: { data: s => s },
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (logger === dtsLog) {
|
|
74
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
75
|
-
event: {
|
|
76
|
-
data: true,
|
|
77
|
-
error: true
|
|
78
|
-
},
|
|
79
|
-
colors: {
|
|
80
|
-
// tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
|
|
81
|
-
data: s => s
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (logger === styleLog || logger === copyLog) {
|
|
87
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
88
|
-
event: {
|
|
89
|
-
error: true,
|
|
90
|
-
data: true
|
|
91
|
-
} // colors: { data: s => s },
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await childProcess;
|
|
98
|
-
}, {
|
|
99
|
-
concurrency
|
|
100
|
-
});
|
|
101
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import { execa, Import } from '@modern-js/utils';
|
|
4
|
-
const pMap = Import.lazy('p-map', require);
|
|
5
|
-
const utils = Import.lazy('./utils', require);
|
|
6
|
-
const lg = Import.lazy('./logger', require);
|
|
7
|
-
const constants = Import.lazy('./constants', require);
|
|
8
|
-
export const buildSourceCode = async (api, config, _) => {
|
|
9
|
-
const {
|
|
10
|
-
sourceDir,
|
|
11
|
-
enableTscCompiler,
|
|
12
|
-
styleOnly
|
|
13
|
-
} = config;
|
|
14
|
-
const {
|
|
15
|
-
appDirectory
|
|
16
|
-
} = api.useAppContext();
|
|
17
|
-
const concurrency = os.cpus().length;
|
|
18
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
19
|
-
const lm = new lg.LoggerManager();
|
|
20
|
-
const codeLog = lm.createLoggerText({
|
|
21
|
-
title: constants.runBabelCompilerTitle
|
|
22
|
-
});
|
|
23
|
-
const dtsLog = lm.createLoggerText({
|
|
24
|
-
title: constants.runTscTitle
|
|
25
|
-
});
|
|
26
|
-
const styleLog = lm.createLoggerText({
|
|
27
|
-
title: constants.runStyleCompilerTitle
|
|
28
|
-
});
|
|
29
|
-
const copyLog = lm.createLoggerText({
|
|
30
|
-
title: 'Copy Log:'
|
|
31
|
-
});
|
|
32
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
33
|
-
let taskMapper = [];
|
|
34
|
-
|
|
35
|
-
if (styleOnly) {
|
|
36
|
-
taskMapper = [{
|
|
37
|
-
logger: styleLog,
|
|
38
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
39
|
-
}, {
|
|
40
|
-
logger: copyLog,
|
|
41
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
42
|
-
}];
|
|
43
|
-
} else {
|
|
44
|
-
taskMapper = [...utils.getCodeMapper(api, {
|
|
45
|
-
logger: codeLog,
|
|
46
|
-
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
47
|
-
config,
|
|
48
|
-
willCompilerDirOrFile: sourceDir,
|
|
49
|
-
initMapper: initCodeMapper,
|
|
50
|
-
srcRootDir
|
|
51
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
52
|
-
logger: styleLog,
|
|
53
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
54
|
-
}, {
|
|
55
|
-
logger: copyLog,
|
|
56
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
57
|
-
}];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
lm.showCompiling();
|
|
61
|
-
await pMap(taskMapper, async ({
|
|
62
|
-
logger,
|
|
63
|
-
taskPath,
|
|
64
|
-
params
|
|
65
|
-
}) => {
|
|
66
|
-
const childProcess = execa.node(taskPath, params, {
|
|
67
|
-
stdio: 'pipe'
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (logger === codeLog || logger === copyLog) {
|
|
71
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
72
|
-
event: {
|
|
73
|
-
data: true,
|
|
74
|
-
error: true
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (logger === dtsLog) {
|
|
81
|
-
lm.addStdout(dtsLog, childProcess.stdout, {
|
|
82
|
-
event: {
|
|
83
|
-
data: true,
|
|
84
|
-
error: true
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
lm.addStderr(dtsLog, childProcess.stderr);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (logger === styleLog) {
|
|
91
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
92
|
-
event: {
|
|
93
|
-
data: true,
|
|
94
|
-
error: true
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
await childProcess;
|
|
101
|
-
}, {
|
|
102
|
-
concurrency
|
|
103
|
-
});
|
|
104
|
-
lm.disappearCompiling();
|
|
105
|
-
|
|
106
|
-
if (!styleOnly) {
|
|
107
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
108
|
-
console.info(codeLog.value);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (styleLog.hasMessages()) {
|
|
112
|
-
console.info(styleLog.value);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (copyLog.hasMessages()) {
|
|
116
|
-
console.info(copyLog.value);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (dtsLog.hasErrorMessage || codeLog.hasErrorMessage || styleLog.hasErrorMessage || copyLog.hasErrorMessage) {
|
|
120
|
-
// eslint-disable-next-line no-process-exit
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
@@ -1,207 +0,0 @@
|
|
|
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 { Import, glob, fs } from '@modern-js/utils';
|
|
8
|
-
import { initEnv } from "../utils/init-env";
|
|
9
|
-
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
10
|
-
const argv = Import.lazy('process.argv', require);
|
|
11
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
12
|
-
const bc = Import.lazy('../utils/babel', require);
|
|
13
|
-
const ts = Import.lazy('../utils/tsconfig', require);
|
|
14
|
-
export let Compiler;
|
|
15
|
-
|
|
16
|
-
(function (Compiler) {
|
|
17
|
-
Compiler[Compiler["babel"] = 0] = "babel";
|
|
18
|
-
Compiler[Compiler["esbuild"] = 1] = "esbuild";
|
|
19
|
-
Compiler[Compiler["swc"] = 2] = "swc";
|
|
20
|
-
})(Compiler || (Compiler = {}));
|
|
21
|
-
|
|
22
|
-
const runBabelCompiler = async (willCompilerFiles, config, babelConfig = {}) => {
|
|
23
|
-
const {
|
|
24
|
-
srcRootDir,
|
|
25
|
-
distDir
|
|
26
|
-
} = config; // TODO: 判断lynx模式下,修改distFileExtMap: {'js': 'js', 'jsx': 'jsx', 'ts': 'js', 'tsx': 'jsx'}
|
|
27
|
-
|
|
28
|
-
return babelCompiler.compiler({
|
|
29
|
-
quiet: true,
|
|
30
|
-
enableVirtualDist: true,
|
|
31
|
-
rootDir: srcRootDir,
|
|
32
|
-
filenames: willCompilerFiles,
|
|
33
|
-
distDir,
|
|
34
|
-
ignore: ['*.d.ts']
|
|
35
|
-
}, babelConfig);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getWillCompilerCode = (srcDirOrFile, option) => {
|
|
39
|
-
const {
|
|
40
|
-
tsconfig,
|
|
41
|
-
isTsProject
|
|
42
|
-
} = option; // 如果是一个文件路径,则直接返回
|
|
43
|
-
|
|
44
|
-
if (fs.existsSync(srcDirOrFile) && fs.lstatSync(srcDirOrFile).isFile()) {
|
|
45
|
-
return [srcDirOrFile];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const getExts = isTs => {
|
|
49
|
-
// TODO: 是否受控tsconfig.json 里的jsx配置
|
|
50
|
-
let exts = [];
|
|
51
|
-
|
|
52
|
-
if (isTs) {
|
|
53
|
-
var _tsconfig$compilerOpt;
|
|
54
|
-
|
|
55
|
-
exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
|
|
56
|
-
} else {
|
|
57
|
-
exts = ['.js', '.jsx'];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return exts;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const exts = getExts(isTsProject);
|
|
64
|
-
const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
|
|
65
|
-
const files = glob.sync(globPattern, {
|
|
66
|
-
ignore: [`${srcDirOrFile}/**/*.d.ts`],
|
|
67
|
-
absolute: true
|
|
68
|
-
});
|
|
69
|
-
return files;
|
|
70
|
-
};
|
|
71
|
-
export const buildSourceCode = async config => {
|
|
72
|
-
const {
|
|
73
|
-
compiler,
|
|
74
|
-
willCompilerDirOrFile,
|
|
75
|
-
tsconfigPath,
|
|
76
|
-
sourceMaps,
|
|
77
|
-
babelConfig
|
|
78
|
-
} = config;
|
|
79
|
-
const tsconfig = ts.readTsConfig(tsconfigPath);
|
|
80
|
-
const willCompilerFiles = getWillCompilerCode(willCompilerDirOrFile, {
|
|
81
|
-
tsconfig,
|
|
82
|
-
isTsProject: Boolean(tsconfig)
|
|
83
|
-
});
|
|
84
|
-
let distSet = null;
|
|
85
|
-
|
|
86
|
-
if (compiler === Compiler.babel) {
|
|
87
|
-
distSet = await runBabelCompiler(willCompilerFiles, config, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
88
|
-
sourceMaps
|
|
89
|
-
}));
|
|
90
|
-
} else {
|
|
91
|
-
distSet = {
|
|
92
|
-
code: 1,
|
|
93
|
-
message: 'no compiler'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return distSet;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const generatorRealFiles = virtualDists => {
|
|
101
|
-
for (const virtualDist of virtualDists) {
|
|
102
|
-
const {
|
|
103
|
-
distPath,
|
|
104
|
-
code,
|
|
105
|
-
sourcemap,
|
|
106
|
-
sourceMapPath
|
|
107
|
-
} = virtualDist;
|
|
108
|
-
fs.ensureFileSync(distPath);
|
|
109
|
-
fs.writeFileSync(distPath, code);
|
|
110
|
-
|
|
111
|
-
if (sourcemap.length > 0) {
|
|
112
|
-
fs.ensureFileSync(sourceMapPath);
|
|
113
|
-
fs.writeFileSync(sourceMapPath, sourcemap);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const defaultConfig = {
|
|
119
|
-
srcRootDir: `${process.cwd()}/src`,
|
|
120
|
-
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
121
|
-
distDir: './dist/js/temp',
|
|
122
|
-
compiler: 'babel',
|
|
123
|
-
appDirectory: '',
|
|
124
|
-
sourceMaps: false,
|
|
125
|
-
tsconfigPath: '',
|
|
126
|
-
syntax: 'es5',
|
|
127
|
-
type: 'module',
|
|
128
|
-
watch: false
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const taskMain = async ({
|
|
132
|
-
modernConfig
|
|
133
|
-
}) => {
|
|
134
|
-
// Execution of the script's parameter handling and related required configuration acquisition
|
|
135
|
-
const processArgv = argv(process.argv.slice(2));
|
|
136
|
-
const config = processArgv(defaultConfig);
|
|
137
|
-
process.env.BUILD_FORMAT = initEnv(config);
|
|
138
|
-
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
139
|
-
|
|
140
|
-
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
141
|
-
sourceAbsDir: config.srcRootDir,
|
|
142
|
-
tsconfigPath: config.tsconfigPath,
|
|
143
|
-
syntax: config.syntax,
|
|
144
|
-
type: config.type
|
|
145
|
-
});
|
|
146
|
-
const {
|
|
147
|
-
code,
|
|
148
|
-
message,
|
|
149
|
-
messageDetails,
|
|
150
|
-
virtualDists = []
|
|
151
|
-
} = await buildSourceCode({
|
|
152
|
-
distDir: config.distDir,
|
|
153
|
-
srcRootDir: config.srcRootDir,
|
|
154
|
-
willCompilerDirOrFile: config.willCompilerDirOrFile,
|
|
155
|
-
sourceMaps: config.sourceMaps,
|
|
156
|
-
compiler,
|
|
157
|
-
projectData: {
|
|
158
|
-
appDirectory: config.appDirectory
|
|
159
|
-
},
|
|
160
|
-
tsconfigPath: config.tsconfigPath,
|
|
161
|
-
babelConfig
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (code === 0) {
|
|
165
|
-
generatorRealFiles(virtualDists); // 执行成功log使用 console.info
|
|
166
|
-
|
|
167
|
-
console.info('[Babel Compiler]: Successfully');
|
|
168
|
-
} else if (messageDetails && messageDetails.length > 0) {
|
|
169
|
-
console.error(message);
|
|
170
|
-
|
|
171
|
-
for (const detail of messageDetails || []) {
|
|
172
|
-
console.error(detail.content);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (code === 0 && config.copyDirs) {
|
|
177
|
-
const copyList = config.copyDirs.split(',');
|
|
178
|
-
|
|
179
|
-
for (const copyDir of copyList) {
|
|
180
|
-
fs.ensureDirSync(copyDir);
|
|
181
|
-
fs.copySync(config.distDir, copyDir);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
(async () => {
|
|
187
|
-
let options;
|
|
188
|
-
|
|
189
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
190
|
-
({
|
|
191
|
-
options
|
|
192
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const {
|
|
196
|
-
resolved
|
|
197
|
-
} = await core.cli.init([], options);
|
|
198
|
-
await core.manager.run(async () => {
|
|
199
|
-
try {
|
|
200
|
-
await taskMain({
|
|
201
|
-
modernConfig: resolved
|
|
202
|
-
});
|
|
203
|
-
} catch (e) {
|
|
204
|
-
console.error(e);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
})();
|