@nocobase/build 0.7.0-alpha.56
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/LICENSE +201 -0
- package/README.md +0 -0
- package/bin/nocobase-build.js +71 -0
- package/lib/babel.js +252 -0
- package/lib/build.js +351 -0
- package/lib/es5ImcompatibleVersions.js +51 -0
- package/lib/getBabelConfig.js +75 -0
- package/lib/getRollupConfig.js +320 -0
- package/lib/getUserConfig.js +99 -0
- package/lib/importLibToEs.js +38 -0
- package/lib/index.js +13 -0
- package/lib/normalizeBundleOpts.js +35 -0
- package/lib/randomColor.js +32 -0
- package/lib/registerBabel.js +38 -0
- package/lib/rollup.js +144 -0
- package/lib/schema.js +213 -0
- package/lib/types.d.js +1 -0
- package/lib/utils/getLernaPackages/index.js +63 -0
- package/lib/utils/index.js +48 -0
- package/package.json +78 -0
- package/src/babel.ts +257 -0
- package/src/build.ts +260 -0
- package/src/es5ImcompatibleVersions.ts +33 -0
- package/src/getBabelConfig.ts +95 -0
- package/src/getRollupConfig.ts +343 -0
- package/src/getUserConfig.ts +87 -0
- package/src/importLibToEs.js +26 -0
- package/src/index.ts +3 -0
- package/src/normalizeBundleOpts.ts +24 -0
- package/src/randomColor.ts +34 -0
- package/src/registerBabel.ts +23 -0
- package/src/rollup.ts +77 -0
- package/src/schema.ts +175 -0
- package/src/types.d.ts +118 -0
- package/src/utils/getLernaPackages/fixtures/customize/core/core1/package.json +7 -0
- package/src/utils/getLernaPackages/fixtures/customize/core/core1/src/index.js +2 -0
- package/src/utils/getLernaPackages/fixtures/customize/core/core2/package.json +5 -0
- package/src/utils/getLernaPackages/fixtures/customize/core/core2/src/index.js +2 -0
- package/src/utils/getLernaPackages/fixtures/customize/lerna.json +6 -0
- package/src/utils/getLernaPackages/fixtures/customize/package.json +4 -0
- package/src/utils/getLernaPackages/fixtures/customize/packages/bar/package.json +4 -0
- package/src/utils/getLernaPackages/fixtures/customize/packages/bar/src/index.js +2 -0
- package/src/utils/getLernaPackages/fixtures/customize/packages/foo/package.json +7 -0
- package/src/utils/getLernaPackages/fixtures/customize/packages/foo/src/index.js +2 -0
- package/src/utils/getLernaPackages/fixtures/default/lerna.json +1 -0
- package/src/utils/getLernaPackages/fixtures/default/package.json +4 -0
- package/src/utils/getLernaPackages/fixtures/default/packages/bar/package.json +4 -0
- package/src/utils/getLernaPackages/fixtures/default/packages/bar/src/index.js +2 -0
- package/src/utils/getLernaPackages/fixtures/default/packages/foo/package.json +7 -0
- package/src/utils/getLernaPackages/fixtures/default/packages/foo/src/index.js +2 -0
- package/src/utils/getLernaPackages/index.ts +57 -0
- package/src/utils/index.ts +13 -0
- package/template/tsconfig.json +23 -0
package/lib/build.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.build = build;
|
|
7
|
+
exports.buildForLerna = buildForLerna;
|
|
8
|
+
exports.default = _default;
|
|
9
|
+
exports.getBundleOpts = getBundleOpts;
|
|
10
|
+
|
|
11
|
+
var assert = _interopRequireWildcard(require("assert"));
|
|
12
|
+
|
|
13
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
|
+
|
|
15
|
+
var _fs = require("fs");
|
|
16
|
+
|
|
17
|
+
var _lodash = require("lodash");
|
|
18
|
+
|
|
19
|
+
var _path = require("path");
|
|
20
|
+
|
|
21
|
+
var _rimraf = _interopRequireDefault(require("rimraf"));
|
|
22
|
+
|
|
23
|
+
var _signale = _interopRequireDefault(require("signale"));
|
|
24
|
+
|
|
25
|
+
var _babel = _interopRequireDefault(require("./babel"));
|
|
26
|
+
|
|
27
|
+
var _getUserConfig = _interopRequireWildcard(require("./getUserConfig"));
|
|
28
|
+
|
|
29
|
+
var _randomColor = _interopRequireDefault(require("./randomColor"));
|
|
30
|
+
|
|
31
|
+
var _registerBabel = _interopRequireDefault(require("./registerBabel"));
|
|
32
|
+
|
|
33
|
+
var _rollup = _interopRequireDefault(require("./rollup"));
|
|
34
|
+
|
|
35
|
+
var _utils = require("./utils");
|
|
36
|
+
|
|
37
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
|
+
|
|
39
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
40
|
+
|
|
41
|
+
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; }
|
|
42
|
+
|
|
43
|
+
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; }
|
|
44
|
+
|
|
45
|
+
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; }
|
|
46
|
+
|
|
47
|
+
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; }
|
|
48
|
+
|
|
49
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
50
|
+
|
|
51
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
52
|
+
|
|
53
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
54
|
+
|
|
55
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
56
|
+
|
|
57
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
58
|
+
|
|
59
|
+
function getBundleOpts(opts) {
|
|
60
|
+
const cwd = opts.cwd,
|
|
61
|
+
_opts$buildArgs = opts.buildArgs,
|
|
62
|
+
buildArgs = _opts$buildArgs === void 0 ? {} : _opts$buildArgs,
|
|
63
|
+
_opts$rootConfig = opts.rootConfig,
|
|
64
|
+
rootConfig = _opts$rootConfig === void 0 ? {} : _opts$rootConfig;
|
|
65
|
+
const entry = (0, _utils.getExistFile)({
|
|
66
|
+
cwd,
|
|
67
|
+
files: ['src/index.tsx', 'src/index.ts', 'src/index.jsx', 'src/index.js'],
|
|
68
|
+
returnRelative: true
|
|
69
|
+
});
|
|
70
|
+
const userConfig = (0, _getUserConfig.default)({
|
|
71
|
+
cwd,
|
|
72
|
+
customPath: buildArgs.config
|
|
73
|
+
});
|
|
74
|
+
const userConfigs = Array.isArray(userConfig) ? userConfig : [userConfig];
|
|
75
|
+
return userConfigs.map(userConfig => {
|
|
76
|
+
const bundleOpts = (0, _lodash.merge)({
|
|
77
|
+
entry
|
|
78
|
+
}, rootConfig, userConfig, buildArgs); // Support config esm: 'rollup' and cjs: 'rollup'
|
|
79
|
+
|
|
80
|
+
if (typeof bundleOpts.esm === 'string') {
|
|
81
|
+
bundleOpts.esm = {
|
|
82
|
+
type: bundleOpts.esm
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (typeof bundleOpts.cjs === 'string') {
|
|
87
|
+
bundleOpts.cjs = {
|
|
88
|
+
type: bundleOpts.cjs
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return bundleOpts;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function validateBundleOpts(bundleOpts, {
|
|
97
|
+
cwd,
|
|
98
|
+
rootPath
|
|
99
|
+
}) {
|
|
100
|
+
if (bundleOpts.runtimeHelpers) {
|
|
101
|
+
const pkgPath = (0, _path.join)(cwd, 'package.json');
|
|
102
|
+
assert.ok((0, _fs.existsSync)(pkgPath), `@babel/runtime dependency is required to use runtimeHelpers`);
|
|
103
|
+
const pkg = JSON.parse((0, _fs.readFileSync)(pkgPath, 'utf-8'));
|
|
104
|
+
assert.ok((pkg.dependencies || {})['@babel/runtime'], `@babel/runtime dependency is required to use runtimeHelpers`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (bundleOpts.cjs && bundleOpts.cjs.lazy && bundleOpts.cjs.type === 'rollup') {
|
|
108
|
+
throw new Error(`
|
|
109
|
+
cjs.lazy don't support rollup.
|
|
110
|
+
`.trim());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!bundleOpts.esm && !bundleOpts.cjs && !bundleOpts.umd) {
|
|
114
|
+
throw new Error(`
|
|
115
|
+
None format of ${_chalk.default.cyan('cjs | esm | umd')} is configured, checkout https://github.com/umijs/father for usage details.
|
|
116
|
+
`.trim());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (bundleOpts.entry) {
|
|
120
|
+
const tsConfigPath = (0, _path.join)(cwd, 'tsconfig.json');
|
|
121
|
+
const tsConfig = (0, _fs.existsSync)(tsConfigPath) || rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, 'tsconfig.json'));
|
|
122
|
+
|
|
123
|
+
if (!tsConfig && (Array.isArray(bundleOpts.entry) && bundleOpts.entry.some(isTypescriptFile) || !Array.isArray(bundleOpts.entry) && isTypescriptFile(bundleOpts.entry))) {
|
|
124
|
+
_signale.default.info(`Project using ${_chalk.default.cyan('typescript')} but tsconfig.json not exists. Use default config.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isTypescriptFile(filePath) {
|
|
130
|
+
return filePath.endsWith('.ts') || filePath.endsWith('.tsx');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function build(_x) {
|
|
134
|
+
return _build.apply(this, arguments);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function _build() {
|
|
138
|
+
_build = _asyncToGenerator(function* (opts, extraOpts = {}) {
|
|
139
|
+
const cwd = opts.cwd,
|
|
140
|
+
rootPath = opts.rootPath,
|
|
141
|
+
watch = opts.watch,
|
|
142
|
+
_opts$buildArgs2 = opts.buildArgs,
|
|
143
|
+
buildArgs = _opts$buildArgs2 === void 0 ? {} : _opts$buildArgs2,
|
|
144
|
+
_opts$clean = opts.clean,
|
|
145
|
+
clean = _opts$clean === void 0 ? true : _opts$clean;
|
|
146
|
+
const pkg = extraOpts.pkg;
|
|
147
|
+
const dispose = [];
|
|
148
|
+
const customConfigPath = buildArgs.config && ((0, _path.isAbsolute)(buildArgs.config) ? buildArgs.config : (0, _path.join)(process.cwd(), buildArgs.config)); // register babel for config files
|
|
149
|
+
|
|
150
|
+
(0, _registerBabel.default)({
|
|
151
|
+
cwd,
|
|
152
|
+
only: customConfigPath ? _getUserConfig.CONFIG_FILES.concat(customConfigPath) : _getUserConfig.CONFIG_FILES
|
|
153
|
+
});
|
|
154
|
+
const pkgName = (typeof pkg === 'string' ? pkg : pkg === null || pkg === void 0 ? void 0 : pkg.name) || 'unknown';
|
|
155
|
+
|
|
156
|
+
function log(msg) {
|
|
157
|
+
console.log(`${pkg ? `${(0, _randomColor.default)(`${pkgName}`)}: ` : ''}${msg}`);
|
|
158
|
+
} // Get user config
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
const bundleOptsArray = getBundleOpts(opts);
|
|
162
|
+
|
|
163
|
+
var _iterator = _createForOfIteratorHelper(bundleOptsArray),
|
|
164
|
+
_step;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
168
|
+
const bundleOpts = _step.value;
|
|
169
|
+
validateBundleOpts(bundleOpts, {
|
|
170
|
+
cwd,
|
|
171
|
+
rootPath
|
|
172
|
+
}); // Clean dist
|
|
173
|
+
|
|
174
|
+
if (clean) {
|
|
175
|
+
log(_chalk.default.gray(`Clean dist directory`));
|
|
176
|
+
|
|
177
|
+
_rimraf.default.sync((0, _path.join)(cwd, 'dist'));
|
|
178
|
+
} // Build umd
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
if (bundleOpts.umd) {
|
|
182
|
+
log(`Build umd`);
|
|
183
|
+
yield (0, _rollup.default)({
|
|
184
|
+
cwd,
|
|
185
|
+
rootPath,
|
|
186
|
+
log,
|
|
187
|
+
type: 'umd',
|
|
188
|
+
entry: bundleOpts.entry,
|
|
189
|
+
watch,
|
|
190
|
+
dispose,
|
|
191
|
+
bundleOpts
|
|
192
|
+
});
|
|
193
|
+
} // Build cjs
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if (bundleOpts.cjs) {
|
|
197
|
+
const cjs = bundleOpts.cjs;
|
|
198
|
+
log(`Build cjs with ${cjs.type}`);
|
|
199
|
+
|
|
200
|
+
if (cjs.type === 'babel') {
|
|
201
|
+
yield (0, _babel.default)({
|
|
202
|
+
cwd,
|
|
203
|
+
rootPath,
|
|
204
|
+
watch,
|
|
205
|
+
dispose,
|
|
206
|
+
type: 'cjs',
|
|
207
|
+
log,
|
|
208
|
+
bundleOpts
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
yield (0, _rollup.default)({
|
|
212
|
+
cwd,
|
|
213
|
+
rootPath,
|
|
214
|
+
log,
|
|
215
|
+
type: 'cjs',
|
|
216
|
+
entry: bundleOpts.entry,
|
|
217
|
+
watch,
|
|
218
|
+
dispose,
|
|
219
|
+
bundleOpts
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
} // Build esm
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if (bundleOpts.esm) {
|
|
226
|
+
const esm = bundleOpts.esm;
|
|
227
|
+
log(`Build esm with ${esm.type}`);
|
|
228
|
+
const importLibToEs = esm && esm.importLibToEs;
|
|
229
|
+
|
|
230
|
+
if (esm && esm.type === 'babel') {
|
|
231
|
+
yield (0, _babel.default)({
|
|
232
|
+
cwd,
|
|
233
|
+
rootPath,
|
|
234
|
+
watch,
|
|
235
|
+
dispose,
|
|
236
|
+
type: 'esm',
|
|
237
|
+
importLibToEs,
|
|
238
|
+
log,
|
|
239
|
+
bundleOpts
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
yield (0, _rollup.default)({
|
|
243
|
+
cwd,
|
|
244
|
+
rootPath,
|
|
245
|
+
log,
|
|
246
|
+
type: 'esm',
|
|
247
|
+
entry: bundleOpts.entry,
|
|
248
|
+
importLibToEs,
|
|
249
|
+
watch,
|
|
250
|
+
dispose,
|
|
251
|
+
bundleOpts
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} catch (err) {
|
|
257
|
+
_iterator.e(err);
|
|
258
|
+
} finally {
|
|
259
|
+
_iterator.f();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return dispose;
|
|
263
|
+
});
|
|
264
|
+
return _build.apply(this, arguments);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function getPkgRelativePath(cwd, pkg) {
|
|
268
|
+
const basePath = cwd.split(_path.sep).join('/') + '/packages/';
|
|
269
|
+
const dir = pkg.contents.split(_path.sep).join('/');
|
|
270
|
+
return dir.substring(basePath.length);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function buildForLerna(_x2) {
|
|
274
|
+
return _buildForLerna.apply(this, arguments);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function _buildForLerna() {
|
|
278
|
+
_buildForLerna = _asyncToGenerator(function* (opts) {
|
|
279
|
+
const cwd = opts.cwd,
|
|
280
|
+
_opts$rootConfig2 = opts.rootConfig,
|
|
281
|
+
rootConfig = _opts$rootConfig2 === void 0 ? {} : _opts$rootConfig2,
|
|
282
|
+
_opts$buildArgs3 = opts.buildArgs,
|
|
283
|
+
buildArgs = _opts$buildArgs3 === void 0 ? {} : _opts$buildArgs3,
|
|
284
|
+
_opts$packages = opts.packages,
|
|
285
|
+
packages = _opts$packages === void 0 ? [] : _opts$packages; // register babel for config files
|
|
286
|
+
|
|
287
|
+
(0, _registerBabel.default)({
|
|
288
|
+
cwd,
|
|
289
|
+
only: _getUserConfig.CONFIG_FILES
|
|
290
|
+
});
|
|
291
|
+
const userConfig = (0, _lodash.merge)((0, _getUserConfig.default)({
|
|
292
|
+
cwd
|
|
293
|
+
}), rootConfig, buildArgs);
|
|
294
|
+
let pkgs = yield (0, _utils.getLernaPackages)(cwd, userConfig.pkgFilter); // support define pkgs in lerna
|
|
295
|
+
|
|
296
|
+
if (userConfig.pkgs) {
|
|
297
|
+
pkgs = pkgs.filter(pkg => userConfig.pkgs.includes(getPkgRelativePath(cwd, pkg)));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const dispose = [];
|
|
301
|
+
|
|
302
|
+
var _iterator2 = _createForOfIteratorHelper(pkgs),
|
|
303
|
+
_step2;
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
307
|
+
const pkg = _step2.value;
|
|
308
|
+
const pkgName = getPkgRelativePath(cwd, pkg);
|
|
309
|
+
|
|
310
|
+
if (userConfig.excludePkgs && userConfig.excludePkgs.includes(pkgName)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (packages.length && !packages.includes(pkgName)) continue; // build error when .DS_Store includes in packages root
|
|
315
|
+
|
|
316
|
+
const pkgPath = pkg.contents;
|
|
317
|
+
assert.ok((0, _fs.existsSync)((0, _path.join)(pkgPath, 'package.json')), `package.json not found in packages/${pkg}`);
|
|
318
|
+
process.chdir(pkgPath);
|
|
319
|
+
dispose.push(...(yield build(_objectSpread(_objectSpread({}, opts), {}, {
|
|
320
|
+
buildArgs: opts.buildArgs,
|
|
321
|
+
rootConfig: userConfig,
|
|
322
|
+
cwd: pkgPath,
|
|
323
|
+
rootPath: cwd
|
|
324
|
+
}), {
|
|
325
|
+
pkg
|
|
326
|
+
})));
|
|
327
|
+
}
|
|
328
|
+
} catch (err) {
|
|
329
|
+
_iterator2.e(err);
|
|
330
|
+
} finally {
|
|
331
|
+
_iterator2.f();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return dispose;
|
|
335
|
+
});
|
|
336
|
+
return _buildForLerna.apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function _default(_x3) {
|
|
340
|
+
return _ref.apply(this, arguments);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function _ref() {
|
|
344
|
+
_ref = _asyncToGenerator(function* (opts) {
|
|
345
|
+
const useLerna = (0, _fs.existsSync)((0, _path.join)(opts.cwd, 'lerna.json'));
|
|
346
|
+
const isLerna = useLerna && process.env.LERNA !== 'none';
|
|
347
|
+
const dispose = isLerna ? yield buildForLerna(opts) : yield build(opts);
|
|
348
|
+
return () => dispose.forEach(e => e());
|
|
349
|
+
});
|
|
350
|
+
return _ref.apply(this, arguments);
|
|
351
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPkgPath = getPkgPath;
|
|
7
|
+
exports.shouldTransform = shouldTransform;
|
|
8
|
+
|
|
9
|
+
var _path = require("path");
|
|
10
|
+
|
|
11
|
+
var _pkgUp = _interopRequireDefault(require("pkg-up"));
|
|
12
|
+
|
|
13
|
+
var _semver = require("semver");
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
// 参考:
|
|
18
|
+
// https://github.com/umijs/umi/blob/2.x/packages/af-webpack/src/getWebpackConfig/es5ImcompatibleVersions.js
|
|
19
|
+
const pkgPathCache = {};
|
|
20
|
+
const pkgCache = {};
|
|
21
|
+
|
|
22
|
+
const _require = require('es5-imcompatible-versions/package.json'),
|
|
23
|
+
config = _require.config['es5-imcompatible-versions'];
|
|
24
|
+
|
|
25
|
+
function getPkgPath(filePath) {
|
|
26
|
+
const dir = (0, _path.dirname)(filePath);
|
|
27
|
+
if (dir in pkgPathCache) return pkgPathCache[dir];
|
|
28
|
+
pkgPathCache[dir] = _pkgUp.default.sync({
|
|
29
|
+
cwd: filePath
|
|
30
|
+
});
|
|
31
|
+
return pkgPathCache[dir];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function shouldTransform(pkgPath) {
|
|
35
|
+
if (pkgPath in pkgCache) return pkgCache[pkgPath];
|
|
36
|
+
|
|
37
|
+
const _require2 = require(pkgPath),
|
|
38
|
+
name = _require2.name,
|
|
39
|
+
version = _require2.version;
|
|
40
|
+
|
|
41
|
+
pkgCache[pkgPath] = isMatch(name, version);
|
|
42
|
+
return pkgCache[pkgPath];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isMatch(name, version) {
|
|
46
|
+
if (config[name]) {
|
|
47
|
+
return Object.keys(config[name]).some(sv => (0, _semver.satisfies)(version, sv));
|
|
48
|
+
} else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
var _path = require("path");
|
|
9
|
+
|
|
10
|
+
function transformImportLess2Css() {
|
|
11
|
+
return {
|
|
12
|
+
name: 'transform-import-less-to-css',
|
|
13
|
+
visitor: {
|
|
14
|
+
ImportDeclaration(path, source) {
|
|
15
|
+
const re = /\.less$/;
|
|
16
|
+
|
|
17
|
+
if (re.test(path.node.source.value)) {
|
|
18
|
+
path.node.source.value = path.node.source.value.replace(re, '.css');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _default(opts) {
|
|
27
|
+
const target = opts.target,
|
|
28
|
+
typescript = opts.typescript,
|
|
29
|
+
type = opts.type,
|
|
30
|
+
runtimeHelpers = opts.runtimeHelpers,
|
|
31
|
+
filePath = opts.filePath,
|
|
32
|
+
browserFiles = opts.browserFiles,
|
|
33
|
+
nodeFiles = opts.nodeFiles,
|
|
34
|
+
nodeVersion = opts.nodeVersion,
|
|
35
|
+
lazy = opts.lazy,
|
|
36
|
+
lessInBabelMode = opts.lessInBabelMode;
|
|
37
|
+
let isBrowser = target === 'browser'; // rollup 场景下不会传入 filePath
|
|
38
|
+
|
|
39
|
+
if (filePath) {
|
|
40
|
+
if ((0, _path.extname)(filePath) === '.tsx' || (0, _path.extname)(filePath) === '.jsx') {
|
|
41
|
+
isBrowser = true;
|
|
42
|
+
} else {
|
|
43
|
+
if (isBrowser) {
|
|
44
|
+
if (nodeFiles.includes(filePath)) isBrowser = false;
|
|
45
|
+
} else {
|
|
46
|
+
if (browserFiles.includes(filePath)) isBrowser = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const targets = isBrowser ? {
|
|
52
|
+
browsers: ['last 2 versions', 'IE 10']
|
|
53
|
+
} : {
|
|
54
|
+
node: nodeVersion || 6
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
opts: {
|
|
58
|
+
presets: [...(typescript ? [require.resolve('@babel/preset-typescript')] : []), [require.resolve('@babel/preset-env'), {
|
|
59
|
+
targets,
|
|
60
|
+
modules: type === 'esm' ? false : 'auto'
|
|
61
|
+
}], ...(isBrowser ? [require.resolve('@babel/preset-react')] : [])],
|
|
62
|
+
plugins: [...(type === 'cjs' && lazy && !isBrowser ? [[require.resolve('@babel/plugin-transform-modules-commonjs'), {
|
|
63
|
+
lazy: true
|
|
64
|
+
}]] : []), ...(lessInBabelMode ? [transformImportLess2Css] : []), ...(isBrowser ? [require.resolve('babel-plugin-react-require')] : []), require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('@babel/plugin-proposal-export-default-from'), require.resolve('@babel/plugin-proposal-export-namespace-from'), require.resolve('@babel/plugin-proposal-do-expressions'), require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), require.resolve('@babel/plugin-proposal-optional-chaining'), [require.resolve('@babel/plugin-proposal-decorators'), {
|
|
65
|
+
legacy: true
|
|
66
|
+
}], [require.resolve('@babel/plugin-proposal-class-properties'), {
|
|
67
|
+
loose: true
|
|
68
|
+
}], ...(runtimeHelpers ? [[require.resolve('@babel/plugin-transform-runtime'), {
|
|
69
|
+
useESModules: isBrowser && type === 'esm',
|
|
70
|
+
version: require('@babel/runtime/package.json').version
|
|
71
|
+
}]] : []), ...(process.env.COVERAGE ? [require.resolve('babel-plugin-istanbul')] : [])]
|
|
72
|
+
},
|
|
73
|
+
isBrowser
|
|
74
|
+
};
|
|
75
|
+
}
|