@modern-js/module-tools 1.1.2-rc.0 → 1.1.4
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 +35 -14
- package/dist/js/modern/features/build/build-watch.js +8 -1
- package/dist/js/modern/tasks/build-source-code.js +14 -19
- package/dist/js/modern/tasks/build-style.js +9 -1
- package/dist/js/modern/tasks/build-watch-source-code.js +11 -1
- package/dist/js/modern/tasks/build-watch-style.js +15 -2
- package/dist/js/modern/tasks/copy-assets.js +9 -1
- package/dist/js/modern/tasks/generator-dts.js +9 -1
- package/dist/js/modern/utils/init-env.js +14 -0
- package/dist/js/node/features/build/build-watch.js +8 -1
- package/dist/js/node/tasks/build-source-code.js +16 -22
- package/dist/js/node/tasks/build-style.js +9 -1
- package/dist/js/node/tasks/build-watch-source-code.js +12 -1
- package/dist/js/node/tasks/build-watch-style.js +16 -2
- package/dist/js/node/tasks/copy-assets.js +9 -1
- package/dist/js/node/tasks/generator-dts.js +9 -1
- package/dist/js/node/utils/init-env.js +23 -0
- package/dist/types/tasks/build-source-code.d.ts +0 -17
- package/dist/types/utils/init-env.d.ts +21 -0
- package/package.json +14 -14
- package/src/features/build/build-watch.ts +7 -1
- package/src/tasks/build-source-code.ts +10 -17
- package/src/tasks/build-style.ts +13 -2
- package/src/tasks/build-watch-source-code.ts +8 -2
- package/src/tasks/build-watch-style.ts +27 -9
- package/src/tasks/copy-assets.ts +13 -2
- package/src/tasks/generator-dts.ts +6 -2
- package/src/utils/init-env.ts +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
# @modern-js/module-tools
|
|
2
2
|
|
|
3
|
-
## 1.1.
|
|
3
|
+
## 1.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 10676d31: fix build watch error
|
|
8
|
+
|
|
9
|
+
## 1.1.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ca7dcb32: support BUILD_FORMAT env and fix watch feature not work
|
|
14
|
+
- Updated dependencies [90eeb72c]
|
|
15
|
+
- Updated dependencies [e04914ce]
|
|
16
|
+
- Updated dependencies [e12b3d0b]
|
|
17
|
+
- Updated dependencies [ca7dcb32]
|
|
18
|
+
- Updated dependencies [e12b3d0b]
|
|
19
|
+
- Updated dependencies [5a4c557e]
|
|
20
|
+
- Updated dependencies [e04914ce]
|
|
21
|
+
- Updated dependencies [0c81020f]
|
|
22
|
+
- Updated dependencies [ca7dcb32]
|
|
23
|
+
- Updated dependencies [ecb344dc]
|
|
24
|
+
- @modern-js/core@1.2.0
|
|
25
|
+
- @modern-js/new-action@1.2.0
|
|
26
|
+
- @modern-js/babel-preset-module@1.1.2
|
|
27
|
+
- @modern-js/plugin-analyze@1.1.2
|
|
28
|
+
- @modern-js/babel-compiler@1.1.3
|
|
29
|
+
- @modern-js/utils@1.1.5
|
|
30
|
+
|
|
31
|
+
## 1.1.2
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
6
34
|
|
|
@@ -8,23 +36,16 @@
|
|
|
8
36
|
- Updated dependencies [d927bc83]
|
|
9
37
|
- Updated dependencies [d73ff455]
|
|
10
38
|
- Updated dependencies [9c1ab865]
|
|
39
|
+
- Updated dependencies [c5e3d4ad]
|
|
11
40
|
- Updated dependencies [d73ff455]
|
|
12
41
|
- Updated dependencies [d73ff455]
|
|
13
42
|
- Updated dependencies [d73ff455]
|
|
14
43
|
- Updated dependencies [d73ff455]
|
|
15
|
-
- @modern-js/utils@1.1.4
|
|
16
|
-
- @modern-js/core@1.1.4
|
|
17
|
-
- @modern-js/
|
|
18
|
-
- @modern-js/
|
|
19
|
-
- @modern-js/module-tools-hooks@1.1.2
|
|
20
|
-
- @modern-js/babel-preset-module@1.1.2-rc.0
|
|
21
|
-
- @modern-js/plugin-analyze@1.1.2-rc.0
|
|
22
|
-
- @modern-js/plugin-changeset@1.1.2-rc.0
|
|
23
|
-
- @modern-js/plugin-fast-refresh@1.1.2-rc.0
|
|
24
|
-
- @modern-js/babel-compiler@1.1.3-rc.0
|
|
25
|
-
- @modern-js/i18n-cli-language-detector@1.1.1
|
|
26
|
-
- @modern-js/plugin-i18n@1.1.1
|
|
27
|
-
- @modern-js/new-action@1.1.6-rc.0
|
|
44
|
+
- @modern-js/utils@1.1.4
|
|
45
|
+
- @modern-js/core@1.1.4
|
|
46
|
+
- @modern-js/style-compiler@1.1.3
|
|
47
|
+
- @modern-js/css-config@1.1.2
|
|
48
|
+
- @modern-js/module-tools-hooks@1.1.2
|
|
28
49
|
|
|
29
50
|
## 1.1.1
|
|
30
51
|
|
|
@@ -27,6 +27,9 @@ export const buildInWatchMode = async (config, _) => {
|
|
|
27
27
|
const styleLog = lm.createLoggerText({
|
|
28
28
|
title: constants.runStyleCompilerTitle
|
|
29
29
|
});
|
|
30
|
+
const copyLog = lm.createLoggerText({
|
|
31
|
+
title: 'Copy Log:'
|
|
32
|
+
});
|
|
30
33
|
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
31
34
|
const taskMapper = [...utils.getCodeMapper({
|
|
32
35
|
logger: codeLog,
|
|
@@ -38,6 +41,10 @@ export const buildInWatchMode = async (config, _) => {
|
|
|
38
41
|
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
39
42
|
logger: styleLog,
|
|
40
43
|
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
44
|
+
}, {
|
|
45
|
+
logger: copyLog,
|
|
46
|
+
taskPath: require.resolve("../../tasks/copy-assets"),
|
|
47
|
+
params: ['--watch']
|
|
41
48
|
}];
|
|
42
49
|
lm.on('data', () => {
|
|
43
50
|
console.info(constants.clearFlag);
|
|
@@ -78,7 +85,7 @@ export const buildInWatchMode = async (config, _) => {
|
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
if (logger === styleLog) {
|
|
88
|
+
if (logger === styleLog || logger === copyLog) {
|
|
82
89
|
lm.addStdout(logger, childProcess.stdout, {
|
|
83
90
|
event: {
|
|
84
91
|
error: true,
|
|
@@ -5,6 +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 { Import, fs } from '@modern-js/utils';
|
|
8
|
+
import { initEnv } from "../utils/init-env";
|
|
8
9
|
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
9
10
|
const glob = Import.lazy('glob', require);
|
|
10
11
|
const argv = Import.lazy('process.argv', require);
|
|
@@ -113,20 +114,6 @@ const generatorRealFiles = virtualDists => {
|
|
|
113
114
|
}
|
|
114
115
|
};
|
|
115
116
|
|
|
116
|
-
export const initEnv = ({
|
|
117
|
-
syntax,
|
|
118
|
-
type
|
|
119
|
-
}) => {
|
|
120
|
-
if (syntax === 'es6+' && type === 'commonjs') {
|
|
121
|
-
return 'nodejs';
|
|
122
|
-
} else if (syntax === 'es6+' && type === 'module') {
|
|
123
|
-
return 'modern';
|
|
124
|
-
} else if (syntax === 'es5' && type === 'module') {
|
|
125
|
-
return 'legacy-browser';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return '';
|
|
129
|
-
};
|
|
130
117
|
const defaultConfig = {
|
|
131
118
|
srcRootDir: `${process.cwd()}/src`,
|
|
132
119
|
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
@@ -143,11 +130,11 @@ const defaultConfig = {
|
|
|
143
130
|
const taskMain = async ({
|
|
144
131
|
modernConfig
|
|
145
132
|
}) => {
|
|
146
|
-
//
|
|
133
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
147
134
|
const processArgv = argv(process.argv.slice(2));
|
|
148
|
-
const config = processArgv(defaultConfig);
|
|
149
|
-
|
|
150
|
-
const compiler = Compiler.babel; //
|
|
135
|
+
const config = processArgv(defaultConfig);
|
|
136
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
137
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
151
138
|
|
|
152
139
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
153
140
|
sourceAbsDir: config.srcRootDir,
|
|
@@ -196,9 +183,17 @@ const taskMain = async ({
|
|
|
196
183
|
};
|
|
197
184
|
|
|
198
185
|
(async () => {
|
|
186
|
+
let options;
|
|
187
|
+
|
|
188
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
189
|
+
({
|
|
190
|
+
options
|
|
191
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
192
|
+
}
|
|
193
|
+
|
|
199
194
|
const {
|
|
200
195
|
resolved
|
|
201
|
-
} = await core.cli.init();
|
|
196
|
+
} = await core.cli.init([], options);
|
|
202
197
|
await core.manager.run(async () => {
|
|
203
198
|
try {
|
|
204
199
|
await taskMain({
|
|
@@ -143,11 +143,19 @@ const taskMain = async ({
|
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
(async () => {
|
|
146
|
+
let options;
|
|
147
|
+
|
|
148
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
149
|
+
({
|
|
150
|
+
options
|
|
151
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
152
|
+
}
|
|
153
|
+
|
|
146
154
|
hooks.buildLifeCycle();
|
|
147
155
|
const {
|
|
148
156
|
resolved: modernConfig,
|
|
149
157
|
appContext
|
|
150
|
-
} = await core.cli.init();
|
|
158
|
+
} = await core.cli.init([], options);
|
|
151
159
|
await core.manager.run(async () => {
|
|
152
160
|
try {
|
|
153
161
|
await taskMain({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Import, fs } from '@modern-js/utils';
|
|
2
|
+
import { initEnv } from "../utils/init-env";
|
|
2
3
|
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
3
4
|
const logger = Import.lazy('../features/build/logger', require);
|
|
4
5
|
const ts = Import.lazy('../utils/tsconfig', require);
|
|
@@ -123,13 +124,22 @@ const taskMain = async ({
|
|
|
123
124
|
syntax: 'es5',
|
|
124
125
|
type: 'module'
|
|
125
126
|
});
|
|
127
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
126
128
|
await buildSourceCode(config, modernConfig);
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
(async () => {
|
|
132
|
+
let options;
|
|
133
|
+
|
|
134
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
135
|
+
({
|
|
136
|
+
options
|
|
137
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
138
|
+
}
|
|
139
|
+
|
|
130
140
|
const {
|
|
131
141
|
resolved
|
|
132
|
-
} = await core.cli.init();
|
|
142
|
+
} = await core.cli.init([], options);
|
|
133
143
|
await core.manager.run(async () => {
|
|
134
144
|
try {
|
|
135
145
|
await taskMain({
|
|
@@ -53,6 +53,7 @@ const copyOriginStyleFiles = ({
|
|
|
53
53
|
|
|
54
54
|
for (const styleFile of styleFiles) {
|
|
55
55
|
const file = path.relative(targetDir, styleFile);
|
|
56
|
+
fs.ensureFileSync(path.join(outputDir, file));
|
|
56
57
|
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -77,9 +78,13 @@ const taskMain = async ({
|
|
|
77
78
|
appDirectory
|
|
78
79
|
} = appContext;
|
|
79
80
|
const lessOption = await core.mountHook().moduleLessConfig({
|
|
81
|
+
modernConfig
|
|
82
|
+
}, {
|
|
80
83
|
onLast: async _ => null
|
|
81
84
|
});
|
|
82
85
|
const sassOption = await core.mountHook().moduleSassConfig({
|
|
86
|
+
modernConfig
|
|
87
|
+
}, {
|
|
83
88
|
onLast: async _ => null
|
|
84
89
|
});
|
|
85
90
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
@@ -186,11 +191,19 @@ const taskMain = async ({
|
|
|
186
191
|
};
|
|
187
192
|
|
|
188
193
|
(async () => {
|
|
194
|
+
let options;
|
|
195
|
+
|
|
196
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
197
|
+
({
|
|
198
|
+
options
|
|
199
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
200
|
+
}
|
|
201
|
+
|
|
189
202
|
hooks.buildLifeCycle();
|
|
190
203
|
const {
|
|
191
204
|
resolved: modernConfig,
|
|
192
205
|
appContext
|
|
193
|
-
} = await core.cli.init();
|
|
206
|
+
} = await core.cli.init([], options);
|
|
194
207
|
await core.manager.run(async () => {
|
|
195
208
|
try {
|
|
196
209
|
await taskMain({
|
|
@@ -198,7 +211,7 @@ const taskMain = async ({
|
|
|
198
211
|
appContext
|
|
199
212
|
});
|
|
200
213
|
} catch (e) {
|
|
201
|
-
console.error(e
|
|
214
|
+
console.error(e);
|
|
202
215
|
}
|
|
203
216
|
});
|
|
204
217
|
})();
|
|
@@ -89,10 +89,18 @@ const taskMain = ({
|
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
(async () => {
|
|
92
|
+
let options;
|
|
93
|
+
|
|
94
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
95
|
+
({
|
|
96
|
+
options
|
|
97
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
98
|
+
}
|
|
99
|
+
|
|
92
100
|
const {
|
|
93
101
|
resolved: modernConfig,
|
|
94
102
|
appContext
|
|
95
|
-
} = await core.cli.init();
|
|
103
|
+
} = await core.cli.init([], options);
|
|
96
104
|
core.manager.run(() => {
|
|
97
105
|
try {
|
|
98
106
|
taskMain({
|
|
@@ -202,9 +202,17 @@ const taskMain = async ({
|
|
|
202
202
|
};
|
|
203
203
|
|
|
204
204
|
(async () => {
|
|
205
|
+
let options;
|
|
206
|
+
|
|
207
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
208
|
+
({
|
|
209
|
+
options
|
|
210
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
211
|
+
}
|
|
212
|
+
|
|
205
213
|
const {
|
|
206
214
|
resolved
|
|
207
|
-
} = await core.cli.init();
|
|
215
|
+
} = await core.cli.init([], options);
|
|
208
216
|
await core.manager.run(async () => {
|
|
209
217
|
try {
|
|
210
218
|
await taskMain({
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const initEnv = ({
|
|
2
|
+
syntax,
|
|
3
|
+
type
|
|
4
|
+
}) => {
|
|
5
|
+
if (syntax === 'es6+' && type === 'commonjs') {
|
|
6
|
+
return 'CJS_ES6';
|
|
7
|
+
} else if (syntax === 'es6+' && type === 'module') {
|
|
8
|
+
return 'ESM_ES6';
|
|
9
|
+
} else if (syntax === 'es5' && type === 'module') {
|
|
10
|
+
return 'ESM_ES5';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return '';
|
|
14
|
+
};
|
|
@@ -47,6 +47,9 @@ const buildInWatchMode = async (config, _) => {
|
|
|
47
47
|
const styleLog = lm.createLoggerText({
|
|
48
48
|
title: constants.runStyleCompilerTitle
|
|
49
49
|
});
|
|
50
|
+
const copyLog = lm.createLoggerText({
|
|
51
|
+
title: 'Copy Log:'
|
|
52
|
+
});
|
|
50
53
|
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
51
54
|
const taskMapper = [...utils.getCodeMapper({
|
|
52
55
|
logger: codeLog,
|
|
@@ -58,6 +61,10 @@ const buildInWatchMode = async (config, _) => {
|
|
|
58
61
|
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
59
62
|
logger: styleLog,
|
|
60
63
|
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
64
|
+
}, {
|
|
65
|
+
logger: copyLog,
|
|
66
|
+
taskPath: require.resolve("../../tasks/copy-assets"),
|
|
67
|
+
params: ['--watch']
|
|
61
68
|
}];
|
|
62
69
|
lm.on('data', () => {
|
|
63
70
|
console.info(constants.clearFlag);
|
|
@@ -98,7 +105,7 @@ const buildInWatchMode = async (config, _) => {
|
|
|
98
105
|
});
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
if (logger === styleLog) {
|
|
108
|
+
if (logger === styleLog || logger === copyLog) {
|
|
102
109
|
lm.addStdout(logger, childProcess.stdout, {
|
|
103
110
|
event: {
|
|
104
111
|
error: true,
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getWillCompilerCode = exports.buildSourceCode = exports.Compiler = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
+
var _initEnv = require("../utils/init-env");
|
|
11
|
+
|
|
10
12
|
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; }
|
|
11
13
|
|
|
12
14
|
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; }
|
|
@@ -136,22 +138,6 @@ const generatorRealFiles = virtualDists => {
|
|
|
136
138
|
}
|
|
137
139
|
};
|
|
138
140
|
|
|
139
|
-
const initEnv = ({
|
|
140
|
-
syntax,
|
|
141
|
-
type
|
|
142
|
-
}) => {
|
|
143
|
-
if (syntax === 'es6+' && type === 'commonjs') {
|
|
144
|
-
return 'nodejs';
|
|
145
|
-
} else if (syntax === 'es6+' && type === 'module') {
|
|
146
|
-
return 'modern';
|
|
147
|
-
} else if (syntax === 'es5' && type === 'module') {
|
|
148
|
-
return 'legacy-browser';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return '';
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
exports.initEnv = initEnv;
|
|
155
141
|
const defaultConfig = {
|
|
156
142
|
srcRootDir: `${process.cwd()}/src`,
|
|
157
143
|
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
@@ -168,11 +154,11 @@ const defaultConfig = {
|
|
|
168
154
|
const taskMain = async ({
|
|
169
155
|
modernConfig
|
|
170
156
|
}) => {
|
|
171
|
-
//
|
|
157
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
172
158
|
const processArgv = argv(process.argv.slice(2));
|
|
173
|
-
const config = processArgv(defaultConfig);
|
|
174
|
-
|
|
175
|
-
const compiler = Compiler.babel; //
|
|
159
|
+
const config = processArgv(defaultConfig);
|
|
160
|
+
process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
|
|
161
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
176
162
|
|
|
177
163
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
178
164
|
sourceAbsDir: config.srcRootDir,
|
|
@@ -222,9 +208,17 @@ const taskMain = async ({
|
|
|
222
208
|
};
|
|
223
209
|
|
|
224
210
|
(async () => {
|
|
211
|
+
let options;
|
|
212
|
+
|
|
213
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
214
|
+
({
|
|
215
|
+
options
|
|
216
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
217
|
+
}
|
|
218
|
+
|
|
225
219
|
const {
|
|
226
220
|
resolved
|
|
227
|
-
} = await core.cli.init();
|
|
221
|
+
} = await core.cli.init([], options);
|
|
228
222
|
await core.manager.run(async () => {
|
|
229
223
|
try {
|
|
230
224
|
await taskMain({
|
|
@@ -159,11 +159,19 @@ const taskMain = async ({
|
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
(async () => {
|
|
162
|
+
let options;
|
|
163
|
+
|
|
164
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
165
|
+
({
|
|
166
|
+
options
|
|
167
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
168
|
+
}
|
|
169
|
+
|
|
162
170
|
hooks.buildLifeCycle();
|
|
163
171
|
const {
|
|
164
172
|
resolved: modernConfig,
|
|
165
173
|
appContext
|
|
166
|
-
} = await core.cli.init();
|
|
174
|
+
} = await core.cli.init([], options);
|
|
167
175
|
await core.manager.run(async () => {
|
|
168
176
|
try {
|
|
169
177
|
await taskMain({
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _utils = require("@modern-js/utils");
|
|
4
4
|
|
|
5
|
+
var _initEnv = require("../utils/init-env");
|
|
6
|
+
|
|
5
7
|
const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
|
|
6
8
|
|
|
7
9
|
const logger = _utils.Import.lazy('../features/build/logger', require);
|
|
@@ -134,13 +136,22 @@ const taskMain = async ({
|
|
|
134
136
|
syntax: 'es5',
|
|
135
137
|
type: 'module'
|
|
136
138
|
});
|
|
139
|
+
process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
|
|
137
140
|
await buildSourceCode(config, modernConfig);
|
|
138
141
|
};
|
|
139
142
|
|
|
140
143
|
(async () => {
|
|
144
|
+
let options;
|
|
145
|
+
|
|
146
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
147
|
+
({
|
|
148
|
+
options
|
|
149
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
150
|
+
}
|
|
151
|
+
|
|
141
152
|
const {
|
|
142
153
|
resolved
|
|
143
|
-
} = await core.cli.init();
|
|
154
|
+
} = await core.cli.init([], options);
|
|
144
155
|
await core.manager.run(async () => {
|
|
145
156
|
try {
|
|
146
157
|
await taskMain({
|
|
@@ -69,6 +69,8 @@ const copyOriginStyleFiles = ({
|
|
|
69
69
|
for (const styleFile of styleFiles) {
|
|
70
70
|
const file = path.relative(targetDir, styleFile);
|
|
71
71
|
|
|
72
|
+
_utils.fs.ensureFileSync(path.join(outputDir, file));
|
|
73
|
+
|
|
72
74
|
_utils.fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
73
75
|
}
|
|
74
76
|
};
|
|
@@ -93,9 +95,13 @@ const taskMain = async ({
|
|
|
93
95
|
appDirectory
|
|
94
96
|
} = appContext;
|
|
95
97
|
const lessOption = await core.mountHook().moduleLessConfig({
|
|
98
|
+
modernConfig
|
|
99
|
+
}, {
|
|
96
100
|
onLast: async _ => null
|
|
97
101
|
});
|
|
98
102
|
const sassOption = await core.mountHook().moduleSassConfig({
|
|
103
|
+
modernConfig
|
|
104
|
+
}, {
|
|
99
105
|
onLast: async _ => null
|
|
100
106
|
});
|
|
101
107
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
@@ -203,11 +209,19 @@ const taskMain = async ({
|
|
|
203
209
|
};
|
|
204
210
|
|
|
205
211
|
(async () => {
|
|
212
|
+
let options;
|
|
213
|
+
|
|
214
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
215
|
+
({
|
|
216
|
+
options
|
|
217
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
218
|
+
}
|
|
219
|
+
|
|
206
220
|
hooks.buildLifeCycle();
|
|
207
221
|
const {
|
|
208
222
|
resolved: modernConfig,
|
|
209
223
|
appContext
|
|
210
|
-
} = await core.cli.init();
|
|
224
|
+
} = await core.cli.init([], options);
|
|
211
225
|
await core.manager.run(async () => {
|
|
212
226
|
try {
|
|
213
227
|
await taskMain({
|
|
@@ -215,7 +229,7 @@ const taskMain = async ({
|
|
|
215
229
|
appContext
|
|
216
230
|
});
|
|
217
231
|
} catch (e) {
|
|
218
|
-
console.error(e
|
|
232
|
+
console.error(e);
|
|
219
233
|
}
|
|
220
234
|
});
|
|
221
235
|
})();
|
|
@@ -106,10 +106,18 @@ const taskMain = ({
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
(async () => {
|
|
109
|
+
let options;
|
|
110
|
+
|
|
111
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
112
|
+
({
|
|
113
|
+
options
|
|
114
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
const {
|
|
110
118
|
resolved: modernConfig,
|
|
111
119
|
appContext
|
|
112
|
-
} = await core.cli.init();
|
|
120
|
+
} = await core.cli.init([], options);
|
|
113
121
|
core.manager.run(() => {
|
|
114
122
|
try {
|
|
115
123
|
taskMain({
|
|
@@ -223,9 +223,17 @@ const taskMain = async ({
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
(async () => {
|
|
226
|
+
let options;
|
|
227
|
+
|
|
228
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
229
|
+
({
|
|
230
|
+
options
|
|
231
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
const {
|
|
227
235
|
resolved
|
|
228
|
-
} = await core.cli.init();
|
|
236
|
+
} = await core.cli.init([], options);
|
|
229
237
|
await core.manager.run(async () => {
|
|
230
238
|
try {
|
|
231
239
|
await taskMain({
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.initEnv = void 0;
|
|
7
|
+
|
|
8
|
+
const initEnv = ({
|
|
9
|
+
syntax,
|
|
10
|
+
type
|
|
11
|
+
}) => {
|
|
12
|
+
if (syntax === 'es6+' && type === 'commonjs') {
|
|
13
|
+
return 'CJS_ES6';
|
|
14
|
+
} else if (syntax === 'es6+' && type === 'module') {
|
|
15
|
+
return 'ESM_ES6';
|
|
16
|
+
} else if (syntax === 'es5' && type === 'module') {
|
|
17
|
+
return 'ESM_ES5';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return '';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.initEnv = initEnv;
|
|
@@ -22,21 +22,4 @@ export declare const getWillCompilerCode: (srcDirOrFile: string, option: {
|
|
|
22
22
|
isTsProject: boolean;
|
|
23
23
|
}) => string[];
|
|
24
24
|
export declare const buildSourceCode: (config: IBuildSourceCodeConfig) => Promise<import("@modern-js/babel-compiler").ICompilerResult>;
|
|
25
|
-
export declare const initEnv: ({
|
|
26
|
-
syntax,
|
|
27
|
-
type
|
|
28
|
-
}: ITaskConfig) => "" | "modern" | "nodejs" | "legacy-browser";
|
|
29
|
-
interface ITaskConfig {
|
|
30
|
-
srcRootDir: string;
|
|
31
|
-
willCompilerDirOrFile: string;
|
|
32
|
-
distDir: string;
|
|
33
|
-
appDirectory: string;
|
|
34
|
-
sourceMaps: boolean;
|
|
35
|
-
syntax: 'es5' | 'es6+';
|
|
36
|
-
type: 'module' | 'commonjs';
|
|
37
|
-
tsconfigPath: string;
|
|
38
|
-
copyDirs?: string;
|
|
39
|
-
compiler?: 'babel' | 'esbuild' | 'swc';
|
|
40
|
-
watch: boolean;
|
|
41
|
-
}
|
|
42
25
|
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface ITaskConfig {
|
|
2
|
+
srcRootDir: string;
|
|
3
|
+
willCompilerDirOrFile: string;
|
|
4
|
+
distDir: string;
|
|
5
|
+
appDirectory: string;
|
|
6
|
+
sourceMaps: boolean;
|
|
7
|
+
syntax: 'es5' | 'es6+';
|
|
8
|
+
type: 'module' | 'commonjs';
|
|
9
|
+
tsconfigPath: string;
|
|
10
|
+
copyDirs?: string;
|
|
11
|
+
compiler?: 'babel' | 'esbuild' | 'swc';
|
|
12
|
+
watch: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const initEnv: ({
|
|
15
|
+
syntax,
|
|
16
|
+
type
|
|
17
|
+
}: {
|
|
18
|
+
syntax: ITaskConfig['syntax'];
|
|
19
|
+
type: ITaskConfig['type'];
|
|
20
|
+
}) => "" | "CJS_ES6" | "ESM_ES6" | "ESM_ES5";
|
|
21
|
+
export {};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.4",
|
|
15
15
|
"bin": {
|
|
16
16
|
"modern": "./bin/modern.js"
|
|
17
17
|
},
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
45
|
"@babel/traverse": "^7.15.0",
|
|
46
46
|
"@babel/types": "^7.15.0",
|
|
47
|
-
"@modern-js/babel-compiler": "^1.1.3
|
|
48
|
-
"@modern-js/babel-preset-module": "^1.1.2
|
|
49
|
-
"@modern-js/core": "^1.
|
|
50
|
-
"@modern-js/css-config": "^1.1.2
|
|
47
|
+
"@modern-js/babel-compiler": "^1.1.3",
|
|
48
|
+
"@modern-js/babel-preset-module": "^1.1.2",
|
|
49
|
+
"@modern-js/core": "^1.2.0",
|
|
50
|
+
"@modern-js/css-config": "^1.1.2",
|
|
51
51
|
"@modern-js/i18n-cli-language-detector": "^1.1.1",
|
|
52
|
-
"@modern-js/module-tools-hooks": "^1.1.2
|
|
53
|
-
"@modern-js/new-action": "^1.
|
|
54
|
-
"@modern-js/plugin-analyze": "^1.1.2
|
|
55
|
-
"@modern-js/plugin-changeset": "^1.1.
|
|
56
|
-
"@modern-js/plugin-fast-refresh": "^1.1.
|
|
52
|
+
"@modern-js/module-tools-hooks": "^1.1.2",
|
|
53
|
+
"@modern-js/new-action": "^1.2.0",
|
|
54
|
+
"@modern-js/plugin-analyze": "^1.1.2",
|
|
55
|
+
"@modern-js/plugin-changeset": "^1.1.1",
|
|
56
|
+
"@modern-js/plugin-fast-refresh": "^1.1.1",
|
|
57
57
|
"@modern-js/plugin-i18n": "^1.1.1",
|
|
58
|
-
"@modern-js/style-compiler": "^1.1.3
|
|
59
|
-
"@modern-js/utils": "^1.1.
|
|
58
|
+
"@modern-js/style-compiler": "^1.1.3",
|
|
59
|
+
"@modern-js/utils": "^1.1.5",
|
|
60
60
|
"chalk": "^4.1.2",
|
|
61
61
|
"chokidar": "^3.5.2",
|
|
62
62
|
"dotenv": "^10.0.0",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"@types/signale": "^1.4.2",
|
|
89
89
|
"commander": "^8.1.0",
|
|
90
90
|
"typescript": "^4",
|
|
91
|
-
"@modern-js/plugin-testing": "^1.
|
|
92
|
-
"@modern-js/module-tools": "^1.1.
|
|
91
|
+
"@modern-js/plugin-testing": "^1.2.0",
|
|
92
|
+
"@modern-js/module-tools": "^1.1.3"
|
|
93
93
|
},
|
|
94
94
|
"sideEffects": false,
|
|
95
95
|
"modernConfig": {
|
|
@@ -34,6 +34,7 @@ export const buildInWatchMode = async (
|
|
|
34
34
|
const styleLog = lm.createLoggerText({
|
|
35
35
|
title: constants.runStyleCompilerTitle,
|
|
36
36
|
});
|
|
37
|
+
const copyLog = lm.createLoggerText({ title: 'Copy Log:' });
|
|
37
38
|
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
38
39
|
const taskMapper: ITaskMapper[] = [
|
|
39
40
|
...utils.getCodeMapper({
|
|
@@ -49,6 +50,11 @@ export const buildInWatchMode = async (
|
|
|
49
50
|
logger: styleLog,
|
|
50
51
|
taskPath: require.resolve('../../tasks/build-watch-style'),
|
|
51
52
|
},
|
|
53
|
+
{
|
|
54
|
+
logger: copyLog,
|
|
55
|
+
taskPath: require.resolve('../../tasks/copy-assets'),
|
|
56
|
+
params: ['--watch'],
|
|
57
|
+
},
|
|
52
58
|
];
|
|
53
59
|
lm.on('data', () => {
|
|
54
60
|
console.info(constants.clearFlag);
|
|
@@ -78,7 +84,7 @@ export const buildInWatchMode = async (
|
|
|
78
84
|
});
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
if (logger === styleLog) {
|
|
87
|
+
if (logger === styleLog || logger === copyLog) {
|
|
82
88
|
lm.addStdout(logger, childProcess.stdout, {
|
|
83
89
|
event: { error: true, data: true },
|
|
84
90
|
// colors: { data: s => s },
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Import, fs } from '@modern-js/utils';
|
|
2
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
|
|
3
3
|
import type { BabelOptions, IVirtualDist } from '@modern-js/babel-compiler';
|
|
4
4
|
import type { ITsconfig } from '../types';
|
|
5
|
+
import { initEnv } from '../utils/init-env';
|
|
5
6
|
|
|
6
7
|
const babelCompiler: typeof import('@modern-js/babel-compiler') = Import.lazy(
|
|
7
8
|
'@modern-js/babel-compiler',
|
|
@@ -138,18 +139,6 @@ const generatorRealFiles = (virtualDists: IVirtualDist[]) => {
|
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
141
|
|
|
141
|
-
export const initEnv = ({ syntax, type }: ITaskConfig) => {
|
|
142
|
-
if (syntax === 'es6+' && type === 'commonjs') {
|
|
143
|
-
return 'nodejs';
|
|
144
|
-
} else if (syntax === 'es6+' && type === 'module') {
|
|
145
|
-
return 'modern';
|
|
146
|
-
} else if (syntax === 'es5' && type === 'module') {
|
|
147
|
-
return 'legacy-browser';
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return '';
|
|
151
|
-
};
|
|
152
|
-
|
|
153
142
|
interface ITaskConfig {
|
|
154
143
|
srcRootDir: string; // 源码的根目录
|
|
155
144
|
willCompilerDirOrFile: string; // 用于编译的源码文件或者源码目录
|
|
@@ -180,11 +169,11 @@ const taskMain = async ({
|
|
|
180
169
|
}: {
|
|
181
170
|
modernConfig: NormalizedConfig;
|
|
182
171
|
}) => {
|
|
183
|
-
//
|
|
172
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
184
173
|
const processArgv = argv(process.argv.slice(2));
|
|
185
174
|
const config = processArgv<ITaskConfig>(defaultConfig);
|
|
186
|
-
|
|
187
|
-
const compiler = Compiler.babel; //
|
|
175
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
176
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
188
177
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
189
178
|
sourceAbsDir: config.srcRootDir,
|
|
190
179
|
tsconfigPath: config.tsconfigPath,
|
|
@@ -229,7 +218,11 @@ const taskMain = async ({
|
|
|
229
218
|
};
|
|
230
219
|
|
|
231
220
|
(async () => {
|
|
232
|
-
|
|
221
|
+
let options: CoreOptions | undefined;
|
|
222
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
223
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
224
|
+
}
|
|
225
|
+
const { resolved } = await core.cli.init([], options);
|
|
233
226
|
await core.manager.run(async () => {
|
|
234
227
|
try {
|
|
235
228
|
await taskMain({ modernConfig: resolved });
|
package/src/tasks/build-style.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import { fs, Import } from '@modern-js/utils';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
NormalizedConfig,
|
|
5
|
+
IAppContext,
|
|
6
|
+
CoreOptions,
|
|
7
|
+
} from '@modern-js/core';
|
|
4
8
|
import type { ICompilerResult, PostcssOption } from '@modern-js/style-compiler';
|
|
5
9
|
import type { ModuleToolsOutput } from '../types';
|
|
6
10
|
|
|
@@ -171,8 +175,15 @@ const taskMain = async ({
|
|
|
171
175
|
};
|
|
172
176
|
|
|
173
177
|
(async () => {
|
|
178
|
+
let options: CoreOptions | undefined;
|
|
179
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
180
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
181
|
+
}
|
|
174
182
|
hooks.buildLifeCycle();
|
|
175
|
-
const { resolved: modernConfig, appContext } = await core.cli.init(
|
|
183
|
+
const { resolved: modernConfig, appContext } = await core.cli.init(
|
|
184
|
+
[],
|
|
185
|
+
options,
|
|
186
|
+
);
|
|
176
187
|
await core.manager.run(async () => {
|
|
177
188
|
try {
|
|
178
189
|
await taskMain({ modernConfig, appContext });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Import, fs } from '@modern-js/utils';
|
|
2
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
|
|
3
3
|
import type { ICompilerResult, IVirtualDist } from '@modern-js/babel-compiler';
|
|
4
4
|
import type { ITsconfig } from '../types';
|
|
5
|
+
import { initEnv } from '../utils/init-env';
|
|
5
6
|
|
|
6
7
|
const babelCompiler: typeof import('@modern-js/babel-compiler') = Import.lazy(
|
|
7
8
|
'@modern-js/babel-compiler',
|
|
@@ -164,12 +165,17 @@ const taskMain = async ({
|
|
|
164
165
|
syntax: 'es5',
|
|
165
166
|
type: 'module',
|
|
166
167
|
});
|
|
168
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
167
169
|
|
|
168
170
|
await buildSourceCode(config, modernConfig);
|
|
169
171
|
};
|
|
170
172
|
|
|
171
173
|
(async () => {
|
|
172
|
-
|
|
174
|
+
let options: CoreOptions | undefined;
|
|
175
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
176
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
177
|
+
}
|
|
178
|
+
const { resolved } = await core.cli.init([], options);
|
|
173
179
|
await core.manager.run(async () => {
|
|
174
180
|
try {
|
|
175
181
|
await taskMain({ modernConfig: resolved });
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* eslint-disable max-statements */
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
NormalizedConfig,
|
|
5
|
+
IAppContext,
|
|
6
|
+
CoreOptions,
|
|
7
|
+
} from '@modern-js/core';
|
|
4
8
|
import type { ICompilerResult, PostcssOption } from '@modern-js/style-compiler';
|
|
5
9
|
import { fs, watch, WatchChangeType, Import } from '@modern-js/utils';
|
|
6
10
|
import type { ModuleToolsOutput } from '../types';
|
|
@@ -79,6 +83,7 @@ const copyOriginStyleFiles = ({
|
|
|
79
83
|
}
|
|
80
84
|
for (const styleFile of styleFiles) {
|
|
81
85
|
const file = path.relative(targetDir, styleFile);
|
|
86
|
+
fs.ensureFileSync(path.join(outputDir, file));
|
|
82
87
|
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
83
88
|
}
|
|
84
89
|
};
|
|
@@ -107,12 +112,18 @@ const taskMain = async ({
|
|
|
107
112
|
} = modernConfig.output as ModuleToolsOutput;
|
|
108
113
|
const { appDirectory } = appContext;
|
|
109
114
|
|
|
110
|
-
const lessOption = await (core.mountHook() as any).moduleLessConfig(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const lessOption = await (core.mountHook() as any).moduleLessConfig(
|
|
116
|
+
{ modernConfig },
|
|
117
|
+
{
|
|
118
|
+
onLast: async (_: any) => null as any,
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
const sassOption = await (core.mountHook() as any).moduleSassConfig(
|
|
122
|
+
{ modernConfig },
|
|
123
|
+
{
|
|
124
|
+
onLast: async (_: any) => null as any,
|
|
125
|
+
},
|
|
126
|
+
);
|
|
116
127
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
117
128
|
const existStylesDir = checkStylesDirExist({ appDirectory });
|
|
118
129
|
const compilerMessage = {
|
|
@@ -240,13 +251,20 @@ const taskMain = async ({
|
|
|
240
251
|
};
|
|
241
252
|
|
|
242
253
|
(async () => {
|
|
254
|
+
let options: CoreOptions | undefined;
|
|
255
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
256
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
257
|
+
}
|
|
243
258
|
hooks.buildLifeCycle();
|
|
244
|
-
const { resolved: modernConfig, appContext } = await core.cli.init(
|
|
259
|
+
const { resolved: modernConfig, appContext } = await core.cli.init(
|
|
260
|
+
[],
|
|
261
|
+
options,
|
|
262
|
+
);
|
|
245
263
|
await core.manager.run(async () => {
|
|
246
264
|
try {
|
|
247
265
|
await taskMain({ modernConfig, appContext });
|
|
248
266
|
} catch (e: any) {
|
|
249
|
-
console.error(e
|
|
267
|
+
console.error(e);
|
|
250
268
|
}
|
|
251
269
|
});
|
|
252
270
|
})();
|
package/src/tasks/copy-assets.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import { fs, watch, WatchChangeType, Import } from '@modern-js/utils';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
NormalizedConfig,
|
|
5
|
+
IAppContext,
|
|
6
|
+
CoreOptions,
|
|
7
|
+
} from '@modern-js/core';
|
|
4
8
|
import type { ModuleToolsOutput } from '../types';
|
|
5
9
|
|
|
6
10
|
const argv: typeof import('process.argv').default = Import.lazy(
|
|
@@ -101,7 +105,14 @@ const taskMain = ({
|
|
|
101
105
|
};
|
|
102
106
|
|
|
103
107
|
(async () => {
|
|
104
|
-
|
|
108
|
+
let options: CoreOptions | undefined;
|
|
109
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
110
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
111
|
+
}
|
|
112
|
+
const { resolved: modernConfig, appContext } = await core.cli.init(
|
|
113
|
+
[],
|
|
114
|
+
options,
|
|
115
|
+
);
|
|
105
116
|
core.manager.run(() => {
|
|
106
117
|
try {
|
|
107
118
|
taskMain({ modernConfig, appContext });
|
|
@@ -2,7 +2,7 @@ import type { ChildProcess } from 'child_process';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import { Import, fs } from '@modern-js/utils';
|
|
5
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
|
+
import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
|
|
6
6
|
import type { ITsconfig } from '@/types';
|
|
7
7
|
|
|
8
8
|
const tsPathsTransform: typeof import('../utils/tspaths-transform') =
|
|
@@ -261,7 +261,11 @@ const taskMain = async ({
|
|
|
261
261
|
};
|
|
262
262
|
|
|
263
263
|
(async () => {
|
|
264
|
-
|
|
264
|
+
let options: CoreOptions | undefined;
|
|
265
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
266
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
267
|
+
}
|
|
268
|
+
const { resolved } = await core.cli.init([], options);
|
|
265
269
|
await core.manager.run(async () => {
|
|
266
270
|
try {
|
|
267
271
|
await taskMain({ modernConfig: resolved });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface ITaskConfig {
|
|
2
|
+
srcRootDir: string; // 源码的根目录
|
|
3
|
+
willCompilerDirOrFile: string; // 用于编译的源码文件或者源码目录
|
|
4
|
+
distDir: string;
|
|
5
|
+
appDirectory: string;
|
|
6
|
+
sourceMaps: boolean;
|
|
7
|
+
syntax: 'es5' | 'es6+';
|
|
8
|
+
type: 'module' | 'commonjs';
|
|
9
|
+
tsconfigPath: string;
|
|
10
|
+
copyDirs?: string;
|
|
11
|
+
compiler?: 'babel' | 'esbuild' | 'swc';
|
|
12
|
+
watch: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const initEnv = ({
|
|
16
|
+
syntax,
|
|
17
|
+
type,
|
|
18
|
+
}: {
|
|
19
|
+
syntax: ITaskConfig['syntax'];
|
|
20
|
+
type: ITaskConfig['type'];
|
|
21
|
+
}) => {
|
|
22
|
+
if (syntax === 'es6+' && type === 'commonjs') {
|
|
23
|
+
return 'CJS_ES6';
|
|
24
|
+
} else if (syntax === 'es6+' && type === 'module') {
|
|
25
|
+
return 'ESM_ES6';
|
|
26
|
+
} else if (syntax === 'es5' && type === 'module') {
|
|
27
|
+
return 'ESM_ES5';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return '';
|
|
31
|
+
};
|