@modern-js/module-tools 1.5.8 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -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 -56
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -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 +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- 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 +111 -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/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -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 -56
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -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 +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +20 -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 +120 -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/js/node/utils/copy.js +1 -1
- package/dist/types/cli/build.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 +12 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/normalize.d.ts +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- 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 +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -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 +46 -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/package.json +23 -9
- 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 -208
- package/dist/js/modern/tasks/build-style.js +0 -169
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
- package/dist/js/modern/tasks/build-watch-style.js +0 -216
- 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 -234
- package/dist/js/node/tasks/build-style.js +0 -184
- package/dist/js/node/tasks/build-watch-source-code.js +0 -174
- package/dist/js/node/tasks/build-watch-style.js +0 -233
- 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
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var path = _interopRequireWildcard(require("path"));
|
|
4
|
-
|
|
5
|
-
var _utils = require("@modern-js/utils");
|
|
6
|
-
|
|
7
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
|
|
11
|
-
const logger = _utils.Import.lazy('../features/build/logger', require);
|
|
12
|
-
|
|
13
|
-
const cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
|
|
14
|
-
|
|
15
|
-
const hooks = _utils.Import.lazy('../hooks', require);
|
|
16
|
-
|
|
17
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
18
|
-
|
|
19
|
-
const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
|
|
20
|
-
|
|
21
|
-
const STYLE_DIRS = 'styles';
|
|
22
|
-
const SRC_STYLE_DIRS = 'src';
|
|
23
|
-
|
|
24
|
-
const checkStylesDirExist = option => {
|
|
25
|
-
const {
|
|
26
|
-
appDirectory
|
|
27
|
-
} = option;
|
|
28
|
-
return _utils.fs.existsSync(path.join(appDirectory, STYLE_DIRS));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const generatorFileAndReturnLog = (result, successMessage = '') => {
|
|
32
|
-
if (result.code === 0) {
|
|
33
|
-
for (const file of result.dists) {
|
|
34
|
-
_utils.fs.ensureFileSync(file.filename);
|
|
35
|
-
|
|
36
|
-
_utils.fs.writeFileSync(file.filename, file.content);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return successMessage;
|
|
40
|
-
} else {
|
|
41
|
-
return result.errors.join('\n');
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const getPostcssOption = (appDirectory, modernConfig) => {
|
|
46
|
-
var _postcssOption$postcs;
|
|
47
|
-
|
|
48
|
-
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
49
|
-
return {
|
|
50
|
-
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
51
|
-
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
52
|
-
options: {}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const copyOriginStyleFiles = ({
|
|
57
|
-
targetDir,
|
|
58
|
-
outputDir
|
|
59
|
-
}) => {
|
|
60
|
-
const styleFiles = _utils.glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
|
|
61
|
-
|
|
62
|
-
if (styleFiles.length > 0) {
|
|
63
|
-
_utils.fs.ensureDirSync(outputDir);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (const styleFile of styleFiles) {
|
|
67
|
-
const file = path.relative(targetDir, styleFile);
|
|
68
|
-
|
|
69
|
-
_utils.fs.ensureFileSync(path.join(outputDir, file));
|
|
70
|
-
|
|
71
|
-
_utils.fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const logCompilerMessage = compilerMessage => {
|
|
76
|
-
console.info(logger.clearFlag);
|
|
77
|
-
console.info(compilerMessage.src);
|
|
78
|
-
console.info(compilerMessage.styles);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const taskMain = async ({
|
|
82
|
-
modernConfig,
|
|
83
|
-
appContext
|
|
84
|
-
}) => {
|
|
85
|
-
const {
|
|
86
|
-
assetsPath = 'styles',
|
|
87
|
-
path: outputPath = 'dist',
|
|
88
|
-
jsPath = 'js',
|
|
89
|
-
importStyle
|
|
90
|
-
} = modernConfig.output;
|
|
91
|
-
const {
|
|
92
|
-
appDirectory
|
|
93
|
-
} = appContext;
|
|
94
|
-
const lessOption = await core.mountHook().moduleLessConfig({
|
|
95
|
-
modernConfig
|
|
96
|
-
}, {
|
|
97
|
-
onLast: async _ => null
|
|
98
|
-
});
|
|
99
|
-
const sassOption = await core.mountHook().moduleSassConfig({
|
|
100
|
-
modernConfig
|
|
101
|
-
}, {
|
|
102
|
-
onLast: async _ => null
|
|
103
|
-
});
|
|
104
|
-
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
105
|
-
const existStylesDir = checkStylesDirExist({
|
|
106
|
-
appDirectory
|
|
107
|
-
});
|
|
108
|
-
const compilerMessage = {
|
|
109
|
-
src: '',
|
|
110
|
-
styles: ''
|
|
111
|
-
}; // 编译 styles 目录样式
|
|
112
|
-
|
|
113
|
-
let styleEmitter = null;
|
|
114
|
-
|
|
115
|
-
if (existStylesDir) {
|
|
116
|
-
styleEmitter = compiler.styleCompiler({
|
|
117
|
-
watch: true,
|
|
118
|
-
projectDir: appDirectory,
|
|
119
|
-
stylesDir: path.resolve(appDirectory, STYLE_DIRS),
|
|
120
|
-
outDir: path.join(appDirectory, outputPath, assetsPath),
|
|
121
|
-
enableVirtualDist: true,
|
|
122
|
-
compilerOption: {
|
|
123
|
-
less: lessOption,
|
|
124
|
-
sass: sassOption,
|
|
125
|
-
postcss: postcssOption
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
styleEmitter.on(compiler.BuildWatchEvent.firstCompiler, styleResult => {
|
|
129
|
-
compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
130
|
-
logCompilerMessage(compilerMessage);
|
|
131
|
-
});
|
|
132
|
-
styleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
|
|
133
|
-
compilerMessage.styles = `[${assetsPath}] Compiling...`;
|
|
134
|
-
logCompilerMessage(compilerMessage);
|
|
135
|
-
});
|
|
136
|
-
styleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, styleResult => {
|
|
137
|
-
compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
138
|
-
logCompilerMessage(compilerMessage);
|
|
139
|
-
}); // await styleEmitter.watch();
|
|
140
|
-
} // 编译 src 内的样式代码
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
|
|
144
|
-
const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
|
|
145
|
-
|
|
146
|
-
if (importStyle === 'compiled-code') {
|
|
147
|
-
compilerMessage.src = `[src] Compiling`;
|
|
148
|
-
const srcStyleEmitter = compiler.styleCompiler({
|
|
149
|
-
watch: true,
|
|
150
|
-
projectDir: appDirectory,
|
|
151
|
-
stylesDir: srcDir,
|
|
152
|
-
outDir: outputDirToSrc,
|
|
153
|
-
enableVirtualDist: true,
|
|
154
|
-
compilerOption: {
|
|
155
|
-
less: lessOption,
|
|
156
|
-
sass: sassOption,
|
|
157
|
-
postcss: postcssOption
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.firstCompiler, srcStyleResult => {
|
|
161
|
-
compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
162
|
-
logCompilerMessage(compilerMessage);
|
|
163
|
-
});
|
|
164
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
|
|
165
|
-
compilerMessage.src = `[src] Compiling`;
|
|
166
|
-
logCompilerMessage(compilerMessage);
|
|
167
|
-
});
|
|
168
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, srcStyleResult => {
|
|
169
|
-
compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
170
|
-
logCompilerMessage(compilerMessage);
|
|
171
|
-
});
|
|
172
|
-
styleEmitter && (await styleEmitter.watch());
|
|
173
|
-
await srcStyleEmitter.watch();
|
|
174
|
-
} else {
|
|
175
|
-
compilerMessage.src = `['src' dir] Copying in progress`;
|
|
176
|
-
styleEmitter && (await styleEmitter.watch());
|
|
177
|
-
logCompilerMessage(compilerMessage);
|
|
178
|
-
copyOriginStyleFiles({
|
|
179
|
-
targetDir: srcDir,
|
|
180
|
-
outputDir: outputDirToSrc
|
|
181
|
-
});
|
|
182
|
-
compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
|
|
183
|
-
logCompilerMessage(compilerMessage);
|
|
184
|
-
(0, _utils.watch)(`${srcDir}/**/*.{css,less,sass,scss}`, ({
|
|
185
|
-
changeType,
|
|
186
|
-
changedFilePath
|
|
187
|
-
}) => {
|
|
188
|
-
compilerMessage.src = `['src' dir] Copying in progress`;
|
|
189
|
-
logCompilerMessage(compilerMessage);
|
|
190
|
-
|
|
191
|
-
if (changeType === _utils.WatchChangeType.UNLINK) {
|
|
192
|
-
const removeFile = path.normalize(`${outputDirToSrc}/${path.relative(srcDir, changedFilePath)}`);
|
|
193
|
-
|
|
194
|
-
_utils.fs.removeSync(removeFile);
|
|
195
|
-
} else {
|
|
196
|
-
copyOriginStyleFiles({
|
|
197
|
-
targetDir: srcDir,
|
|
198
|
-
outputDir: outputDirToSrc
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
|
|
203
|
-
logCompilerMessage(compilerMessage);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
(async () => {
|
|
209
|
-
let options;
|
|
210
|
-
|
|
211
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
212
|
-
({
|
|
213
|
-
options
|
|
214
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
hooks.buildLifeCycle();
|
|
218
|
-
const {
|
|
219
|
-
resolved: modernConfig,
|
|
220
|
-
appContext
|
|
221
|
-
} = await core.cli.init([], options);
|
|
222
|
-
|
|
223
|
-
(async () => {
|
|
224
|
-
try {
|
|
225
|
-
await taskMain({
|
|
226
|
-
modernConfig,
|
|
227
|
-
appContext
|
|
228
|
-
});
|
|
229
|
-
} catch (e) {
|
|
230
|
-
console.error(e);
|
|
231
|
-
}
|
|
232
|
-
})();
|
|
233
|
-
})();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { BabelOptions } from '@modern-js/babel-compiler';
|
|
2
|
-
import type { ITsconfig } from '../types';
|
|
3
|
-
export declare enum Compiler {
|
|
4
|
-
babel = 0,
|
|
5
|
-
esbuild = 1,
|
|
6
|
-
swc = 2,
|
|
7
|
-
}
|
|
8
|
-
interface IBuildSourceCodeConfig {
|
|
9
|
-
babelConfig: BabelOptions;
|
|
10
|
-
srcRootDir: string;
|
|
11
|
-
willCompilerDirOrFile: string;
|
|
12
|
-
distDir: string;
|
|
13
|
-
compiler: Compiler;
|
|
14
|
-
projectData: {
|
|
15
|
-
appDirectory: string;
|
|
16
|
-
};
|
|
17
|
-
sourceMaps?: boolean;
|
|
18
|
-
tsconfigPath: string;
|
|
19
|
-
}
|
|
20
|
-
export declare const getWillCompilerCode: (srcDirOrFile: string, option: {
|
|
21
|
-
tsconfig: ITsconfig | null;
|
|
22
|
-
isTsProject: boolean;
|
|
23
|
-
}) => string[];
|
|
24
|
-
export declare const buildSourceCode: (config: IBuildSourceCodeConfig) => Promise<import("@modern-js/babel-compiler").ICompilerResult>;
|
|
25
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const tempTsconfigName = "./tsconfig.temp.json";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|