@modern-js/module-tools 1.5.7 → 1.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +40 -27
- package/dist/js/modern/features/build/bundle/index.js +6 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/modern/features/build/bundleless/index.js +13 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +84 -19
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +293 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +29 -137
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +104 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +50 -29
- package/dist/js/node/features/build/bundle/index.js +17 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/node/features/build/bundleless/index.js +26 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +92 -19
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +322 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +31 -145
- package/dist/js/node/index.js +5 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +113 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/cli/new.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +4 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
- package/dist/types/features/build/normalize.d.ts +18 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +9 -31
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +179 -0
- package/dist/types/schema/index.d.ts +166 -18
- package/dist/types/schema/output.d.ts +170 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +45 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/dist/types/utils/logger.d.ts +2 -0
- package/package.json +28 -15
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -207
- package/dist/js/modern/tasks/build-style.js +0 -168
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
- package/dist/js/modern/tasks/build-watch-style.js +0 -215
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -233
- package/dist/js/node/tasks/build-style.js +0 -183
- package/dist/js/node/tasks/build-watch-source-code.js +0 -173
- package/dist/js/node/tasks/build-watch-style.js +0 -232
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runSpeedy = exports.getDefine = exports.getAlias = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _speedyCore = require("@speedy-js/speedy-core");
|
|
11
|
+
|
|
12
|
+
var _speedyPluginEs = require("@speedy-js/speedy-plugin-es5");
|
|
13
|
+
|
|
14
|
+
var _utils = require("@modern-js/utils");
|
|
15
|
+
|
|
16
|
+
var _error = require("../error");
|
|
17
|
+
|
|
18
|
+
var _utils2 = require("../utils");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
const getAlias = api => {
|
|
29
|
+
const {
|
|
30
|
+
appDirectory,
|
|
31
|
+
srcDirectory
|
|
32
|
+
} = api.useAppContext();
|
|
33
|
+
const {
|
|
34
|
+
source
|
|
35
|
+
} = api.useResolvedConfigContext(); // TODO: maybe check tsconfig `paths`
|
|
36
|
+
|
|
37
|
+
const defaultAlias = {
|
|
38
|
+
'@': srcDirectory
|
|
39
|
+
};
|
|
40
|
+
const alias = (0, _utils.applyOptionsChain)(defaultAlias, source === null || source === void 0 ? void 0 : source.alias);
|
|
41
|
+
return Object.keys(alias).reduce((o, name) => {
|
|
42
|
+
return _objectSpread(_objectSpread({}, o), {}, {
|
|
43
|
+
[name]: (0, _utils.ensureAbsolutePath)(appDirectory, alias[name])
|
|
44
|
+
});
|
|
45
|
+
}, {});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.getAlias = getAlias;
|
|
49
|
+
|
|
50
|
+
const getDefine = api => {
|
|
51
|
+
const {
|
|
52
|
+
source: {
|
|
53
|
+
envVars,
|
|
54
|
+
globalVars
|
|
55
|
+
}
|
|
56
|
+
} = api.useResolvedConfigContext();
|
|
57
|
+
const envVarsDefine = ['NODE_ENV', ...(envVars || [])].reduce((memo, name) => {
|
|
58
|
+
memo[`process.env.${name}`] = JSON.stringify(process.env[name]);
|
|
59
|
+
return memo;
|
|
60
|
+
}, {});
|
|
61
|
+
const globalVarsDefine = Object.keys(globalVars || {}).reduce((memo, name) => {
|
|
62
|
+
memo[name] = globalVars ? JSON.stringify(globalVars[name]) : '';
|
|
63
|
+
return memo;
|
|
64
|
+
}, {});
|
|
65
|
+
return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.getDefine = getDefine;
|
|
69
|
+
|
|
70
|
+
const getStyleOptionFromModern = async api => {
|
|
71
|
+
const runner = api.useHookRunners();
|
|
72
|
+
const {
|
|
73
|
+
appDirectory
|
|
74
|
+
} = api.useAppContext();
|
|
75
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
76
|
+
const lessOption = await runner.moduleLessConfig({
|
|
77
|
+
modernConfig
|
|
78
|
+
}, {
|
|
79
|
+
onLast: async _ => undefined
|
|
80
|
+
});
|
|
81
|
+
const sassOption = await runner.moduleSassConfig({
|
|
82
|
+
modernConfig
|
|
83
|
+
}, {
|
|
84
|
+
onLast: async _ => undefined
|
|
85
|
+
});
|
|
86
|
+
const tailwindPlugin = await runner.moduleTailwindConfig({
|
|
87
|
+
modernConfig
|
|
88
|
+
}, {
|
|
89
|
+
onLast: async _ => undefined
|
|
90
|
+
});
|
|
91
|
+
const postcssOption = (0, _utils2.getPostcssOption)(appDirectory, modernConfig);
|
|
92
|
+
|
|
93
|
+
if (tailwindPlugin) {
|
|
94
|
+
var _postcssOption$plugin;
|
|
95
|
+
|
|
96
|
+
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
|
|
101
|
+
sass: sassOption,
|
|
102
|
+
postcss: _objectSpread(_objectSpread({}, postcssOption.options), {}, {
|
|
103
|
+
plugins: postcssOption.plugins
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const runSpeedy = async (api, config) => {
|
|
109
|
+
const {
|
|
110
|
+
appDirectory
|
|
111
|
+
} = api.useAppContext();
|
|
112
|
+
const {
|
|
113
|
+
output: {
|
|
114
|
+
path: distPath = 'dist'
|
|
115
|
+
},
|
|
116
|
+
tools: {
|
|
117
|
+
speedy: userSpeedyConfig
|
|
118
|
+
}
|
|
119
|
+
} = api.useResolvedConfigContext();
|
|
120
|
+
const {
|
|
121
|
+
target,
|
|
122
|
+
watch,
|
|
123
|
+
bundleOptions,
|
|
124
|
+
outputPath,
|
|
125
|
+
format,
|
|
126
|
+
sourceMap
|
|
127
|
+
} = config;
|
|
128
|
+
const {
|
|
129
|
+
entry,
|
|
130
|
+
platform,
|
|
131
|
+
splitting,
|
|
132
|
+
minify,
|
|
133
|
+
externals
|
|
134
|
+
} = bundleOptions;
|
|
135
|
+
|
|
136
|
+
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
137
|
+
|
|
138
|
+
const titleText = `[Bundle:Speedy:${format}_${target}]`;
|
|
139
|
+
await getStyleOptionFromModern(api);
|
|
140
|
+
const alias = getAlias(api);
|
|
141
|
+
const define = getDefine(api);
|
|
142
|
+
|
|
143
|
+
const watchPlugin = () => {
|
|
144
|
+
return {
|
|
145
|
+
name: 'watch-plugin',
|
|
146
|
+
|
|
147
|
+
apply(compiler) {
|
|
148
|
+
compiler.hooks.watchChange.tap('watch-plugin', async () => {
|
|
149
|
+
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const plugins = target === 'es5' ? [(0, _speedyPluginEs.es5InputPlugin)()] : [];
|
|
157
|
+
plugins.push(watchPlugin());
|
|
158
|
+
const internalSpeedyConfig = {
|
|
159
|
+
command: 'build',
|
|
160
|
+
mode: 'production',
|
|
161
|
+
html: false,
|
|
162
|
+
preset: 'webapp',
|
|
163
|
+
// support css and json
|
|
164
|
+
platform,
|
|
165
|
+
watch,
|
|
166
|
+
input: entry,
|
|
167
|
+
target,
|
|
168
|
+
clearScreen: false,
|
|
169
|
+
output: {
|
|
170
|
+
path: distDir,
|
|
171
|
+
format,
|
|
172
|
+
splitting,
|
|
173
|
+
filename: '[name]'
|
|
174
|
+
},
|
|
175
|
+
// style,
|
|
176
|
+
resolve: {
|
|
177
|
+
alias
|
|
178
|
+
},
|
|
179
|
+
define,
|
|
180
|
+
sourceMap,
|
|
181
|
+
minify,
|
|
182
|
+
external: externals,
|
|
183
|
+
plugins
|
|
184
|
+
};
|
|
185
|
+
const speedyConfig = (0, _utils.applyOptionsChain)(internalSpeedyConfig, userSpeedyConfig);
|
|
186
|
+
const compiler = await _speedyCore.SpeedyBundler.create(speedyConfig);
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
if (watch) {
|
|
190
|
+
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await compiler.build();
|
|
194
|
+
} catch (e) {
|
|
195
|
+
/**
|
|
196
|
+
* in watch mode
|
|
197
|
+
* use speedy watch log
|
|
198
|
+
*/
|
|
199
|
+
if (e instanceof Error) {
|
|
200
|
+
throw new _error.InternalBuildError(e, {
|
|
201
|
+
target,
|
|
202
|
+
format,
|
|
203
|
+
buildType: 'bundle'
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
exports.runSpeedy = runSpeedy;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copyStaticAssets = void 0;
|
|
7
|
+
|
|
3
8
|
var path = _interopRequireWildcard(require("path"));
|
|
4
9
|
|
|
5
10
|
var _utils = require("@modern-js/utils");
|
|
@@ -8,13 +13,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
8
13
|
|
|
9
14
|
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
15
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
14
|
-
|
|
15
|
-
const copyUtils = _utils.Import.lazy('../utils/copy', require);
|
|
16
|
+
const copyUtils = _utils.Import.lazy('../../../utils/copy', require);
|
|
16
17
|
|
|
17
|
-
const STYLE_DIRS = 'styles';
|
|
18
18
|
const SRC_DIRS = 'src';
|
|
19
19
|
|
|
20
20
|
const copyAssets = ({
|
|
@@ -38,11 +38,13 @@ const copyAssets = ({
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const watchAssets = ({
|
|
41
|
+
const watchAssets = (api, {
|
|
42
42
|
targetDir,
|
|
43
43
|
outputDir
|
|
44
44
|
}) => {
|
|
45
|
-
|
|
45
|
+
const appContext = api.useAppContext();
|
|
46
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
47
|
+
(0, _utils.watch)(`${targetDir}/**/*.*`, async ({
|
|
46
48
|
changeType,
|
|
47
49
|
changedFilePath
|
|
48
50
|
}) => {
|
|
@@ -57,73 +59,53 @@ const watchAssets = ({
|
|
|
57
59
|
const file = path.relative(targetDir, changedFilePath);
|
|
58
60
|
|
|
59
61
|
_utils.fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
|
|
62
|
+
|
|
63
|
+
await copyUtils.copyTask({
|
|
64
|
+
modernConfig,
|
|
65
|
+
appContext
|
|
66
|
+
});
|
|
60
67
|
}, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
|
|
61
68
|
};
|
|
62
69
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const config = processArgv({});
|
|
70
|
+
const copyStaticAssets = async (api, config) => {
|
|
71
|
+
var _bundlelessOptions$so;
|
|
72
|
+
|
|
73
|
+
const appContext = api.useAppContext();
|
|
74
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
69
75
|
const {
|
|
70
76
|
appDirectory
|
|
71
77
|
} = appContext;
|
|
72
78
|
const {
|
|
73
|
-
|
|
74
|
-
assetsPath = 'styles',
|
|
75
|
-
path: outputPath = 'dist'
|
|
79
|
+
path: distPath = 'dist'
|
|
76
80
|
} = modernConfig.output;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const {
|
|
82
|
+
outputPath,
|
|
83
|
+
bundlelessOptions
|
|
84
|
+
} = config;
|
|
85
|
+
const {
|
|
86
|
+
static: {
|
|
87
|
+
path: staticPath = './'
|
|
88
|
+
} = {
|
|
89
|
+
path: './'
|
|
90
|
+
}
|
|
91
|
+
} = bundlelessOptions;
|
|
92
|
+
const srcDir = path.join(appDirectory, (_bundlelessOptions$so = bundlelessOptions.sourceDir) !== null && _bundlelessOptions$so !== void 0 ? _bundlelessOptions$so : SRC_DIRS);
|
|
93
|
+
const outputDirToSrc = path.join(appDirectory, distPath, outputPath, staticPath);
|
|
81
94
|
copyAssets({
|
|
82
95
|
targetDir: srcDir,
|
|
83
96
|
outputDir: outputDirToSrc
|
|
84
97
|
});
|
|
85
|
-
|
|
86
|
-
targetDir: styleDir,
|
|
87
|
-
outputDir: outputDirToStyle
|
|
88
|
-
});
|
|
89
|
-
copyUtils.copyTask({
|
|
98
|
+
await copyUtils.copyTask({
|
|
90
99
|
modernConfig,
|
|
91
100
|
appContext
|
|
92
101
|
});
|
|
93
102
|
|
|
94
103
|
if (config.watch) {
|
|
95
|
-
watchAssets({
|
|
104
|
+
watchAssets(api, {
|
|
96
105
|
targetDir: srcDir,
|
|
97
106
|
outputDir: outputDirToSrc
|
|
98
107
|
});
|
|
99
|
-
watchAssets({
|
|
100
|
-
targetDir: styleDir,
|
|
101
|
-
outputDir: outputDirToStyle
|
|
102
|
-
});
|
|
103
108
|
}
|
|
104
109
|
};
|
|
105
110
|
|
|
106
|
-
|
|
107
|
-
let options;
|
|
108
|
-
|
|
109
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
110
|
-
({
|
|
111
|
-
options
|
|
112
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const {
|
|
116
|
-
resolved: modernConfig,
|
|
117
|
-
appContext
|
|
118
|
-
} = await core.cli.init([], options);
|
|
119
|
-
core.manager.run(() => {
|
|
120
|
-
try {
|
|
121
|
-
taskMain({
|
|
122
|
-
modernConfig,
|
|
123
|
-
appContext
|
|
124
|
-
});
|
|
125
|
-
} catch (e) {
|
|
126
|
-
console.error(e.message);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
})();
|
|
111
|
+
exports.copyStaticAssets = copyStaticAssets;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.genDts = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
3
10
|
var _utils = require("@modern-js/utils");
|
|
4
11
|
|
|
5
|
-
var
|
|
12
|
+
var _error = require("../../error");
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
var _utils2 = require("../../utils");
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
var _utils3 = require("./utils");
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
const utils = _utils.Import.lazy('./utils', require);
|
|
14
21
|
|
|
15
22
|
const getProjectTsconfig = tsconfigPath => {
|
|
16
23
|
if (!tsconfigPath || !_utils.fs.existsSync(tsconfigPath)) {
|
|
@@ -21,7 +28,6 @@ const getProjectTsconfig = tsconfigPath => {
|
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
const resolveLog = (childProgress, {
|
|
24
|
-
tsCheck: _tsCheck = false,
|
|
25
31
|
watch: _watch = false
|
|
26
32
|
} = {}) => {
|
|
27
33
|
var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
|
|
@@ -32,11 +38,8 @@ const resolveLog = (childProgress, {
|
|
|
32
38
|
* watch 模式下,则使用这里的信息
|
|
33
39
|
*/
|
|
34
40
|
(_childProgress$stdout = childProgress.stdout) === null || _childProgress$stdout === void 0 ? void 0 : _childProgress$stdout.on('data', data => {
|
|
35
|
-
if (!_tsCheck) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
41
|
if (_watch) {
|
|
42
|
+
console.info((0, _utils2.watchSectionTitle)('[Bundleless:DTS]', _utils2.SectionTitleStatus.Log));
|
|
40
43
|
console.info(data.toString());
|
|
41
44
|
}
|
|
42
45
|
}); // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
|
|
@@ -53,96 +56,79 @@ const generatorDts = async (_, config) => {
|
|
|
53
56
|
const {
|
|
54
57
|
tsconfigPath,
|
|
55
58
|
distDir,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
appDirectory
|
|
59
|
-
},
|
|
60
|
-
tsCheck = false,
|
|
59
|
+
sourceDir = 'src',
|
|
60
|
+
appDirectory,
|
|
61
61
|
watch = false
|
|
62
62
|
} = config;
|
|
63
63
|
const userTsconfig = getProjectTsconfig(tsconfigPath);
|
|
64
64
|
const willDeleteTsconfigPath = utils.generatorTsConfig(userTsconfig, {
|
|
65
65
|
appDirectory,
|
|
66
66
|
distDir,
|
|
67
|
-
sourceDir
|
|
67
|
+
sourceDir
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
const tscBinFile = (0, _utils2.getTscBinPath)(appDirectory);
|
|
69
|
+
const tscBinFile = (0, _utils3.getTscBinPath)(appDirectory);
|
|
71
70
|
const watchParams = watch ? ['-w'] : [];
|
|
72
|
-
const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath,
|
|
71
|
+
const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath,
|
|
72
|
+
/* Required parameter, use it stdout have color */
|
|
73
|
+
'--pretty', // https://github.com/microsoft/TypeScript/issues/21824
|
|
74
|
+
'--preserveWatchOutput', ...watchParams], {
|
|
73
75
|
stdio: 'pipe',
|
|
74
76
|
cwd: appDirectory
|
|
75
77
|
});
|
|
76
78
|
resolveLog(childProgress, {
|
|
77
|
-
tsCheck,
|
|
78
79
|
watch
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
try {
|
|
82
83
|
await childProgress;
|
|
83
|
-
console.info('[TSC Compiler]: Successfully');
|
|
84
84
|
} catch (e) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
console.error(e.stdout);
|
|
90
|
-
} else {
|
|
91
|
-
console.error(e);
|
|
85
|
+
if (e instanceof Error) {
|
|
86
|
+
throw new _error.InternalDTSError(e, {
|
|
87
|
+
buildType: 'bundleless'
|
|
88
|
+
});
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
_utils.fs.removeSync(willDeleteTsconfigPath);
|
|
96
93
|
};
|
|
97
94
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
distDir: 'dist/types',
|
|
106
|
-
tsconfigPath: './tsconfig.json',
|
|
107
|
-
sourceDirName: 'src'
|
|
108
|
-
});
|
|
109
|
-
const option = {
|
|
110
|
-
srcDir: config.srcDir,
|
|
111
|
-
distDir: config.distDir,
|
|
112
|
-
projectData: {
|
|
113
|
-
appDirectory: config.appDirectory
|
|
95
|
+
const genDts = async (api, config) => {
|
|
96
|
+
const {
|
|
97
|
+
outputPath,
|
|
98
|
+
tsconfig: tsconfigPath,
|
|
99
|
+
watch,
|
|
100
|
+
bundlelessOptions: {
|
|
101
|
+
sourceDir
|
|
114
102
|
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
tsCheck: config.tsCheck,
|
|
118
|
-
sourceDirName: config.sourceDirName
|
|
119
|
-
};
|
|
120
|
-
await generatorDts(modernConfig, option); // // TODO: watch 模式下无法转换
|
|
121
|
-
|
|
122
|
-
utils.resolveAlias(modernConfig, option);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
(async () => {
|
|
126
|
-
let options;
|
|
103
|
+
enableDts
|
|
104
|
+
} = config;
|
|
127
105
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
options
|
|
131
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
106
|
+
if (!enableDts) {
|
|
107
|
+
return;
|
|
132
108
|
}
|
|
133
109
|
|
|
134
110
|
const {
|
|
135
|
-
|
|
136
|
-
} =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
} catch (e) {
|
|
143
|
-
console.error(e.message);
|
|
144
|
-
|
|
145
|
-
_utils.fs.removeSync(removeTsconfigPath);
|
|
111
|
+
appDirectory
|
|
112
|
+
} = api.useAppContext();
|
|
113
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
114
|
+
const {
|
|
115
|
+
output: {
|
|
116
|
+
path: distPath = 'dist'
|
|
146
117
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
118
|
+
} = modernConfig;
|
|
119
|
+
|
|
120
|
+
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
121
|
+
|
|
122
|
+
const option = {
|
|
123
|
+
appDirectory,
|
|
124
|
+
distDir,
|
|
125
|
+
tsconfigPath,
|
|
126
|
+
watch,
|
|
127
|
+
sourceDir
|
|
128
|
+
};
|
|
129
|
+
await generatorDts(modernConfig, option); // TODO: watch 模式下无法转换
|
|
130
|
+
|
|
131
|
+
utils.resolveAlias(modernConfig, option);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
exports.genDts = genDts;
|
|
@@ -21,11 +21,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
21
21
|
|
|
22
22
|
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; }
|
|
23
23
|
|
|
24
|
-
const babel = _utils.Import.lazy('
|
|
24
|
+
const babel = _utils.Import.lazy('../../../../utils/babel', require);
|
|
25
25
|
|
|
26
|
-
const tsPathsTransform = _utils.Import.lazy('
|
|
26
|
+
const tsPathsTransform = _utils.Import.lazy('../../../../utils/tspaths-transform', require);
|
|
27
27
|
|
|
28
|
-
const constants = _utils.Import.lazy('
|
|
28
|
+
const constants = _utils.Import.lazy('../../../../utils/constants', require);
|
|
29
29
|
|
|
30
30
|
const generatorTsConfig = (projectTsconfig, {
|
|
31
31
|
appDirectory,
|
|
@@ -87,14 +87,14 @@ const resolveAlias = (modernConfig, config, watchFilenames = []) => {
|
|
|
87
87
|
absolute: true
|
|
88
88
|
});
|
|
89
89
|
const alias = babel.getFinalAlias(modernConfig, {
|
|
90
|
-
appDirectory: config.
|
|
91
|
-
tsconfigPath: config.tsconfigPath || path.join(config.
|
|
90
|
+
appDirectory: config.appDirectory,
|
|
91
|
+
tsconfigPath: config.tsconfigPath || path.join(config.appDirectory, './tsconfig.json'),
|
|
92
92
|
sourceAbsDir: config.distDir
|
|
93
93
|
});
|
|
94
94
|
const mergedPaths = alias.isTsPath ? alias.paths || {} : _objectSpread(_objectSpread({}, defaultPaths), alias.paths || {});
|
|
95
95
|
const result = tsPathsTransform.transformDtsAlias({
|
|
96
96
|
filenames: dtsFilenames,
|
|
97
|
-
baseUrl: path.join(config.
|
|
97
|
+
baseUrl: path.join(config.appDirectory, output.path || 'dist'),
|
|
98
98
|
paths: mergedPaths
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.build = void 0;
|
|
7
|
+
|
|
8
|
+
var _runBabel = require("./runBabel");
|
|
9
|
+
|
|
10
|
+
var _style = require("./style");
|
|
11
|
+
|
|
12
|
+
var _generatorDts = require("./generator-dts");
|
|
13
|
+
|
|
14
|
+
var _copyAssets = require("./copy-assets");
|
|
15
|
+
|
|
16
|
+
const build = async (api, config, legacyOptions) => {
|
|
17
|
+
if (legacyOptions !== null && legacyOptions !== void 0 && legacyOptions.styleOnly) {
|
|
18
|
+
await (0, _style.buildStyle)(api, config);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const tasks = config.dtsOnly ? [(0, _generatorDts.genDts)(api, config)] : [(0, _runBabel.runBabelBuild)(api, config), (0, _generatorDts.genDts)(api, config), (0, _style.buildStyle)(api, config), (0, _copyAssets.copyStaticAssets)(api, config)];
|
|
23
|
+
await Promise.all(tasks);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.build = build;
|