@modern-js/module-tools 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/js/modern/features/build/build-watch.js +8 -1
- package/dist/js/modern/tasks/build-source-code.js +16 -8
- 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/node/features/build/build-watch.js +8 -1
- package/dist/js/node/tasks/build-source-code.js +16 -8
- 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/types/tasks/build-source-code.d.ts +4 -1
- package/package.json +8 -8
- package/src/features/build/build-watch.ts +7 -1
- package/src/tasks/build-source-code.ts +19 -9
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @modern-js/module-tools
|
|
2
2
|
|
|
3
|
+
## 1.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ca7dcb32: support BUILD_FORMAT env and fix watch feature not work
|
|
8
|
+
- Updated dependencies [90eeb72c]
|
|
9
|
+
- Updated dependencies [e04914ce]
|
|
10
|
+
- Updated dependencies [e12b3d0b]
|
|
11
|
+
- Updated dependencies [ca7dcb32]
|
|
12
|
+
- Updated dependencies [e12b3d0b]
|
|
13
|
+
- Updated dependencies [5a4c557e]
|
|
14
|
+
- Updated dependencies [e04914ce]
|
|
15
|
+
- Updated dependencies [0c81020f]
|
|
16
|
+
- Updated dependencies [ca7dcb32]
|
|
17
|
+
- Updated dependencies [ecb344dc]
|
|
18
|
+
- @modern-js/core@1.2.0
|
|
19
|
+
- @modern-js/new-action@1.2.0
|
|
20
|
+
- @modern-js/babel-preset-module@1.1.2
|
|
21
|
+
- @modern-js/plugin-analyze@1.1.2
|
|
22
|
+
- @modern-js/babel-compiler@1.1.3
|
|
23
|
+
- @modern-js/utils@1.1.5
|
|
24
|
+
|
|
3
25
|
## 1.1.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -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,
|
|
@@ -118,11 +118,11 @@ export const initEnv = ({
|
|
|
118
118
|
type
|
|
119
119
|
}) => {
|
|
120
120
|
if (syntax === 'es6+' && type === 'commonjs') {
|
|
121
|
-
return '
|
|
121
|
+
return 'CJS_ES6';
|
|
122
122
|
} else if (syntax === 'es6+' && type === 'module') {
|
|
123
|
-
return '
|
|
123
|
+
return 'ESM_ES6';
|
|
124
124
|
} else if (syntax === 'es5' && type === 'module') {
|
|
125
|
-
return '
|
|
125
|
+
return 'ESM_ES5';
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
return '';
|
|
@@ -143,11 +143,11 @@ const defaultConfig = {
|
|
|
143
143
|
const taskMain = async ({
|
|
144
144
|
modernConfig
|
|
145
145
|
}) => {
|
|
146
|
-
//
|
|
146
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
147
147
|
const processArgv = argv(process.argv.slice(2));
|
|
148
|
-
const config = processArgv(defaultConfig);
|
|
149
|
-
|
|
150
|
-
const compiler = Compiler.babel; //
|
|
148
|
+
const config = processArgv(defaultConfig);
|
|
149
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
150
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
151
151
|
|
|
152
152
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
153
153
|
sourceAbsDir: config.srcRootDir,
|
|
@@ -196,9 +196,17 @@ const taskMain = async ({
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
(async () => {
|
|
199
|
+
let options;
|
|
200
|
+
|
|
201
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
202
|
+
({
|
|
203
|
+
options
|
|
204
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
205
|
+
}
|
|
206
|
+
|
|
199
207
|
const {
|
|
200
208
|
resolved
|
|
201
|
-
} = await core.cli.init();
|
|
209
|
+
} = await core.cli.init([], options);
|
|
202
210
|
await core.manager.run(async () => {
|
|
203
211
|
try {
|
|
204
212
|
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 "./build-source-code";
|
|
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({
|
|
@@ -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,
|
|
@@ -141,11 +141,11 @@ const initEnv = ({
|
|
|
141
141
|
type
|
|
142
142
|
}) => {
|
|
143
143
|
if (syntax === 'es6+' && type === 'commonjs') {
|
|
144
|
-
return '
|
|
144
|
+
return 'CJS_ES6';
|
|
145
145
|
} else if (syntax === 'es6+' && type === 'module') {
|
|
146
|
-
return '
|
|
146
|
+
return 'ESM_ES6';
|
|
147
147
|
} else if (syntax === 'es5' && type === 'module') {
|
|
148
|
-
return '
|
|
148
|
+
return 'ESM_ES5';
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
return '';
|
|
@@ -168,11 +168,11 @@ const defaultConfig = {
|
|
|
168
168
|
const taskMain = async ({
|
|
169
169
|
modernConfig
|
|
170
170
|
}) => {
|
|
171
|
-
//
|
|
171
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
172
172
|
const processArgv = argv(process.argv.slice(2));
|
|
173
|
-
const config = processArgv(defaultConfig);
|
|
174
|
-
|
|
175
|
-
const compiler = Compiler.babel; //
|
|
173
|
+
const config = processArgv(defaultConfig);
|
|
174
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
175
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
176
176
|
|
|
177
177
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
178
178
|
sourceAbsDir: config.srcRootDir,
|
|
@@ -222,9 +222,17 @@ const taskMain = async ({
|
|
|
222
222
|
};
|
|
223
223
|
|
|
224
224
|
(async () => {
|
|
225
|
+
let options;
|
|
226
|
+
|
|
227
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
228
|
+
({
|
|
229
|
+
options
|
|
230
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
231
|
+
}
|
|
232
|
+
|
|
225
233
|
const {
|
|
226
234
|
resolved
|
|
227
|
-
} = await core.cli.init();
|
|
235
|
+
} = await core.cli.init([], options);
|
|
228
236
|
await core.manager.run(async () => {
|
|
229
237
|
try {
|
|
230
238
|
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 _buildSourceCode = require("./build-source-code");
|
|
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, _buildSourceCode.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({
|
|
@@ -25,7 +25,10 @@ export declare const buildSourceCode: (config: IBuildSourceCodeConfig) => Promis
|
|
|
25
25
|
export declare const initEnv: ({
|
|
26
26
|
syntax,
|
|
27
27
|
type
|
|
28
|
-
}:
|
|
28
|
+
}: {
|
|
29
|
+
syntax: ITaskConfig['syntax'];
|
|
30
|
+
type: ITaskConfig['type'];
|
|
31
|
+
}) => "" | "CJS_ES6" | "ESM_ES6" | "ESM_ES5";
|
|
29
32
|
interface ITaskConfig {
|
|
30
33
|
srcRootDir: string;
|
|
31
34
|
willCompilerDirOrFile: string;
|
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.3",
|
|
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.
|
|
48
|
-
"@modern-js/babel-preset-module": "^1.1.
|
|
49
|
-
"@modern-js/core": "^1.
|
|
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
50
|
"@modern-js/css-config": "^1.1.2",
|
|
51
51
|
"@modern-js/i18n-cli-language-detector": "^1.1.1",
|
|
52
52
|
"@modern-js/module-tools-hooks": "^1.1.2",
|
|
53
|
-
"@modern-js/new-action": "^1.
|
|
54
|
-
"@modern-js/plugin-analyze": "^1.1.
|
|
53
|
+
"@modern-js/new-action": "^1.2.0",
|
|
54
|
+
"@modern-js/plugin-analyze": "^1.1.2",
|
|
55
55
|
"@modern-js/plugin-changeset": "^1.1.1",
|
|
56
56
|
"@modern-js/plugin-fast-refresh": "^1.1.1",
|
|
57
57
|
"@modern-js/plugin-i18n": "^1.1.1",
|
|
58
58
|
"@modern-js/style-compiler": "^1.1.3",
|
|
59
|
-
"@modern-js/utils": "^1.1.
|
|
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",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"commander": "^8.1.0",
|
|
90
90
|
"typescript": "^4",
|
|
91
91
|
"@modern-js/plugin-testing": "^1.1.1",
|
|
92
|
-
"@modern-js/module-tools": "^1.1.
|
|
92
|
+
"@modern-js/module-tools": "^1.1.2"
|
|
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,5 +1,5 @@
|
|
|
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
5
|
|
|
@@ -138,13 +138,19 @@ const generatorRealFiles = (virtualDists: IVirtualDist[]) => {
|
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
export const initEnv = ({
|
|
141
|
+
export const initEnv = ({
|
|
142
|
+
syntax,
|
|
143
|
+
type,
|
|
144
|
+
}: {
|
|
145
|
+
syntax: ITaskConfig['syntax'];
|
|
146
|
+
type: ITaskConfig['type'];
|
|
147
|
+
}) => {
|
|
142
148
|
if (syntax === 'es6+' && type === 'commonjs') {
|
|
143
|
-
return '
|
|
149
|
+
return 'CJS_ES6';
|
|
144
150
|
} else if (syntax === 'es6+' && type === 'module') {
|
|
145
|
-
return '
|
|
151
|
+
return 'ESM_ES6';
|
|
146
152
|
} else if (syntax === 'es5' && type === 'module') {
|
|
147
|
-
return '
|
|
153
|
+
return 'ESM_ES5';
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
return '';
|
|
@@ -180,11 +186,11 @@ const taskMain = async ({
|
|
|
180
186
|
}: {
|
|
181
187
|
modernConfig: NormalizedConfig;
|
|
182
188
|
}) => {
|
|
183
|
-
//
|
|
189
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
184
190
|
const processArgv = argv(process.argv.slice(2));
|
|
185
191
|
const config = processArgv<ITaskConfig>(defaultConfig);
|
|
186
|
-
|
|
187
|
-
const compiler = Compiler.babel; //
|
|
192
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
193
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
188
194
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
189
195
|
sourceAbsDir: config.srcRootDir,
|
|
190
196
|
tsconfigPath: config.tsconfigPath,
|
|
@@ -229,7 +235,11 @@ const taskMain = async ({
|
|
|
229
235
|
};
|
|
230
236
|
|
|
231
237
|
(async () => {
|
|
232
|
-
|
|
238
|
+
let options: CoreOptions | undefined;
|
|
239
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
240
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
241
|
+
}
|
|
242
|
+
const { resolved } = await core.cli.init([], options);
|
|
233
243
|
await core.manager.run(async () => {
|
|
234
244
|
try {
|
|
235
245
|
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 './build-source-code';
|
|
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 });
|