@modern-js/module-tools 1.1.1 → 1.1.4-beta.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 +47 -0
- package/dist/js/modern/cli/new.js +2 -2
- package/dist/js/modern/commands/dev.js +12 -5
- package/dist/js/modern/features/build/build-platform.js +21 -18
- package/dist/js/modern/features/build/build-watch.js +8 -1
- package/dist/js/modern/features/build/index.js +18 -8
- package/dist/js/modern/tasks/build-source-code.js +16 -21
- 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 +11 -3
- package/dist/js/modern/utils/babel.js +2 -2
- package/dist/js/modern/utils/init-env.js +14 -0
- package/dist/js/node/cli/new.js +2 -2
- package/dist/js/node/commands/dev.js +13 -6
- package/dist/js/node/features/build/build-platform.js +21 -18
- package/dist/js/node/features/build/build-watch.js +8 -1
- package/dist/js/node/features/build/index.js +18 -7
- package/dist/js/node/tasks/build-source-code.js +18 -24
- 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 +11 -3
- package/dist/js/node/utils/babel.js +2 -2
- package/dist/js/node/utils/init-env.js +23 -0
- package/dist/types/index.d.ts +3 -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 -13
- package/src/commands/dev.ts +5 -3
- package/src/features/build/build-platform.ts +27 -20
- package/src/features/build/build-watch.ts +7 -1
- package/src/features/build/index.ts +17 -7
- 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/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
|
+
};
|