@nocobase/build 0.9.1-alpha.2 → 0.9.2-alpha.2
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/lib/babel.js +42 -96
- package/lib/build.js +41 -88
- package/lib/es5ImcompatibleVersions.js +4 -14
- package/lib/getBabelConfig.js +11 -17
- package/lib/getRollupConfig.js +63 -96
- package/lib/getUserConfig.js +0 -19
- package/lib/importLibToEs.js +0 -8
- package/lib/index.js +0 -3
- package/lib/normalizeBundleOpts.js +0 -8
- package/lib/randomColor.js +0 -8
- package/lib/registerBabel.js +8 -16
- package/lib/rollup.js +12 -41
- package/lib/utils/getLernaPackages/index.js +7 -17
- package/lib/utils/index.js +1 -10
- package/package.json +2 -2
package/lib/babel.js
CHANGED
|
@@ -4,116 +4,86 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _path = require("path");
|
|
9
|
-
|
|
10
8
|
var _fs = require("fs");
|
|
11
|
-
|
|
12
9
|
var _vinylFs = _interopRequireDefault(require("vinyl-fs"));
|
|
13
|
-
|
|
14
10
|
var _signale = _interopRequireDefault(require("signale"));
|
|
15
|
-
|
|
16
11
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
17
|
-
|
|
18
12
|
var _rimraf = _interopRequireDefault(require("rimraf"));
|
|
19
|
-
|
|
20
13
|
var _through = _interopRequireDefault(require("through2"));
|
|
21
|
-
|
|
22
14
|
var _slash = _interopRequireDefault(require("slash2"));
|
|
23
|
-
|
|
24
15
|
var chokidar = _interopRequireWildcard(require("chokidar"));
|
|
25
|
-
|
|
26
16
|
var babel = _interopRequireWildcard(require("@babel/core"));
|
|
27
|
-
|
|
28
17
|
var _gulpTypescript = _interopRequireDefault(require("gulp-typescript"));
|
|
29
|
-
|
|
30
18
|
var _gulpLess = _interopRequireDefault(require("gulp-less"));
|
|
31
|
-
|
|
32
19
|
var _gulpPlumber = _interopRequireDefault(require("gulp-plumber"));
|
|
33
|
-
|
|
34
20
|
var _gulpIf = _interopRequireDefault(require("gulp-if"));
|
|
35
|
-
|
|
36
21
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
37
|
-
|
|
38
22
|
var _getBabelConfig2 = _interopRequireDefault(require("./getBabelConfig"));
|
|
39
|
-
|
|
40
23
|
var ts = _interopRequireWildcard(require("typescript"));
|
|
41
|
-
|
|
42
24
|
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); }
|
|
43
|
-
|
|
44
25
|
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; }
|
|
45
|
-
|
|
46
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
|
-
|
|
48
27
|
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; }
|
|
49
|
-
|
|
50
28
|
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; }
|
|
51
|
-
|
|
52
|
-
function
|
|
53
|
-
|
|
29
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
31
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
54
32
|
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); } }
|
|
55
|
-
|
|
56
33
|
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); }); }; }
|
|
57
|
-
|
|
58
34
|
function _default(_x) {
|
|
59
35
|
return _ref.apply(this, arguments);
|
|
60
36
|
}
|
|
61
|
-
|
|
62
37
|
function _ref() {
|
|
63
38
|
_ref = _asyncToGenerator(function* (opts) {
|
|
64
39
|
const cwd = opts.cwd,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
rootPath = opts.rootPath,
|
|
41
|
+
type = opts.type,
|
|
42
|
+
watch = opts.watch,
|
|
43
|
+
dispose = opts.dispose,
|
|
44
|
+
importLibToEs = opts.importLibToEs,
|
|
45
|
+
log = opts.log,
|
|
46
|
+
_opts$bundleOpts = opts.bundleOpts,
|
|
47
|
+
_opts$bundleOpts$targ = _opts$bundleOpts.target,
|
|
48
|
+
target = _opts$bundleOpts$targ === void 0 ? "browser" : _opts$bundleOpts$targ,
|
|
49
|
+
runtimeHelpers = _opts$bundleOpts.runtimeHelpers,
|
|
50
|
+
_opts$bundleOpts$extr = _opts$bundleOpts.extraBabelPresets,
|
|
51
|
+
extraBabelPresets = _opts$bundleOpts$extr === void 0 ? [] : _opts$bundleOpts$extr,
|
|
52
|
+
_opts$bundleOpts$extr2 = _opts$bundleOpts.extraBabelPlugins,
|
|
53
|
+
extraBabelPlugins = _opts$bundleOpts$extr2 === void 0 ? [] : _opts$bundleOpts$extr2,
|
|
54
|
+
_opts$bundleOpts$brow = _opts$bundleOpts.browserFiles,
|
|
55
|
+
browserFiles = _opts$bundleOpts$brow === void 0 ? [] : _opts$bundleOpts$brow,
|
|
56
|
+
_opts$bundleOpts$node = _opts$bundleOpts.nodeFiles,
|
|
57
|
+
nodeFiles = _opts$bundleOpts$node === void 0 ? [] : _opts$bundleOpts$node,
|
|
58
|
+
nodeVersion = _opts$bundleOpts.nodeVersion,
|
|
59
|
+
disableTypeCheck = _opts$bundleOpts.disableTypeCheck,
|
|
60
|
+
cjs = _opts$bundleOpts.cjs,
|
|
61
|
+
lessInBabelMode = _opts$bundleOpts.lessInBabelMode;
|
|
87
62
|
const srcPath = (0, _path.join)(cwd, "src");
|
|
88
63
|
const targetDir = type === "esm" ? "es" : "lib";
|
|
89
64
|
const targetPath = (0, _path.join)(cwd, targetDir);
|
|
90
65
|
log(_chalk.default.gray(`Clean ${targetDir} directory`));
|
|
91
|
-
|
|
92
66
|
_rimraf.default.sync(targetPath);
|
|
93
|
-
|
|
94
67
|
function transform(opts) {
|
|
95
68
|
const file = opts.file,
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
type = opts.type;
|
|
98
70
|
const _getBabelConfig = (0, _getBabelConfig2.default)({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
71
|
+
target,
|
|
72
|
+
type,
|
|
73
|
+
typescript: true,
|
|
74
|
+
runtimeHelpers,
|
|
75
|
+
filePath: (0, _slash.default)((0, _path.relative)(cwd, file.path)),
|
|
76
|
+
browserFiles,
|
|
77
|
+
nodeFiles,
|
|
78
|
+
nodeVersion,
|
|
79
|
+
lazy: cjs && cjs.lazy,
|
|
80
|
+
lessInBabelMode
|
|
81
|
+
}),
|
|
82
|
+
babelOpts = _getBabelConfig.opts,
|
|
83
|
+
isBrowser = _getBabelConfig.isBrowser;
|
|
113
84
|
if (importLibToEs && type === "esm") {
|
|
114
85
|
babelOpts.plugins.push(require.resolve("../lib/importLibToEs"));
|
|
115
86
|
}
|
|
116
|
-
|
|
117
87
|
babelOpts.presets.push(...extraBabelPresets);
|
|
118
88
|
babelOpts.plugins.push(...extraBabelPlugins);
|
|
119
89
|
const relFile = (0, _slash.default)(file.path).replace(`${cwd}/`, "");
|
|
@@ -124,71 +94,54 @@ function _ref() {
|
|
|
124
94
|
configFile: false
|
|
125
95
|
})).code;
|
|
126
96
|
}
|
|
97
|
+
|
|
127
98
|
/**
|
|
128
99
|
* tsconfig.json is not valid json file
|
|
129
100
|
* https://github.com/Microsoft/TypeScript/issues/20384
|
|
130
101
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
102
|
function parseTsconfig(path) {
|
|
134
103
|
const readFile = path => (0, _fs.readFileSync)(path, "utf-8");
|
|
135
|
-
|
|
136
104
|
const result = ts.readConfigFile(path, readFile);
|
|
137
|
-
|
|
138
105
|
if (result.error) {
|
|
139
106
|
return;
|
|
140
107
|
}
|
|
141
|
-
|
|
142
108
|
const pkgTsConfig = result.config;
|
|
143
|
-
|
|
144
109
|
if (pkgTsConfig.extends) {
|
|
145
110
|
const rootTsConfigPath = (0, _slash.default)((0, _path.relative)(cwd, pkgTsConfig.extends));
|
|
146
111
|
const rootTsConfig = parseTsconfig(rootTsConfigPath);
|
|
147
|
-
|
|
148
112
|
if (rootTsConfig) {
|
|
149
113
|
const mergedConfig = _objectSpread(_objectSpread(_objectSpread({}, rootTsConfig), pkgTsConfig), {}, {
|
|
150
114
|
compilerOptions: _objectSpread(_objectSpread({}, rootTsConfig.compilerOptions), pkgTsConfig.compilerOptions)
|
|
151
115
|
});
|
|
152
|
-
|
|
153
116
|
return mergedConfig;
|
|
154
117
|
}
|
|
155
118
|
}
|
|
156
|
-
|
|
157
119
|
return pkgTsConfig;
|
|
158
120
|
}
|
|
159
|
-
|
|
160
121
|
function getTsconfigCompilerOptions(path) {
|
|
161
122
|
const config = parseTsconfig(path);
|
|
162
123
|
return config ? config.compilerOptions : undefined;
|
|
163
124
|
}
|
|
164
|
-
|
|
165
125
|
function getTSConfig() {
|
|
166
126
|
const tsconfigPath = (0, _path.join)(cwd, "tsconfig.json");
|
|
167
127
|
const templateTsconfigPath = (0, _path.join)(__dirname, "../template/tsconfig.json");
|
|
168
|
-
|
|
169
128
|
if ((0, _fs.existsSync)(tsconfigPath)) {
|
|
170
129
|
return getTsconfigCompilerOptions(tsconfigPath) || {};
|
|
171
130
|
}
|
|
172
|
-
|
|
173
131
|
if (rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, "tsconfig.json"))) {
|
|
174
132
|
return getTsconfigCompilerOptions((0, _path.join)(rootPath, "tsconfig.json")) || {};
|
|
175
133
|
}
|
|
176
|
-
|
|
177
134
|
return getTsconfigCompilerOptions(templateTsconfigPath) || {};
|
|
178
135
|
}
|
|
179
|
-
|
|
180
136
|
function createStream(src) {
|
|
181
137
|
const tsConfig = getTSConfig();
|
|
182
138
|
const babelTransformRegexp = disableTypeCheck ? /\.(t|j)sx?$/ : /\.jsx?$/;
|
|
183
|
-
|
|
184
139
|
function isTsFile(path) {
|
|
185
140
|
return /\.tsx?$/.test(path) && !path.endsWith(".d.ts");
|
|
186
141
|
}
|
|
187
|
-
|
|
188
142
|
function isTransform(path) {
|
|
189
143
|
return babelTransformRegexp.test(path) && !path.endsWith(".d.ts");
|
|
190
144
|
}
|
|
191
|
-
|
|
192
145
|
return _vinylFs.default.src(src, {
|
|
193
146
|
allowEmpty: true,
|
|
194
147
|
base: srcPath
|
|
@@ -197,19 +150,17 @@ function _ref() {
|
|
|
197
150
|
file.contents = Buffer.from(transform({
|
|
198
151
|
file,
|
|
199
152
|
type
|
|
200
|
-
}));
|
|
201
|
-
|
|
153
|
+
}));
|
|
154
|
+
// .jsx -> .js
|
|
202
155
|
file.path = file.path.replace((0, _path.extname)(file.path), ".js");
|
|
203
156
|
cb(null, file);
|
|
204
157
|
} catch (e) {
|
|
205
158
|
_signale.default.error(`Compiled faild: ${file.path}`);
|
|
206
|
-
|
|
207
159
|
console.log(e);
|
|
208
160
|
cb(null);
|
|
209
161
|
}
|
|
210
162
|
}))).pipe(_vinylFs.default.dest(targetPath));
|
|
211
163
|
}
|
|
212
|
-
|
|
213
164
|
return new Promise(resolve => {
|
|
214
165
|
const patterns = [(0, _path.join)(srcPath, "**/*"), `!${(0, _path.join)(srcPath, "**/fixtures{,/**}")}`, `!${(0, _path.join)(srcPath, "**/demos{,/**}")}`, `!${(0, _path.join)(srcPath, "**/__test__{,/**}")}`, `!${(0, _path.join)(srcPath, "**/__tests__{,/**}")}`, `!${(0, _path.join)(srcPath, "**/*.mdx")}`, `!${(0, _path.join)(srcPath, "**/*.md")}`, `!${(0, _path.join)(srcPath, "**/*.+(test|e2e|spec).+(js|jsx|ts|tsx)")}`, `!${(0, _path.join)(srcPath, "**/tsconfig{,.*}.json")}`, `!${(0, _path.join)(srcPath, ".umi{,-production,-test}{,/**}")}`];
|
|
215
166
|
createStream(patterns).on("end", () => {
|
|
@@ -219,20 +170,16 @@ function _ref() {
|
|
|
219
170
|
ignoreInitial: true
|
|
220
171
|
});
|
|
221
172
|
const files = [];
|
|
222
|
-
|
|
223
173
|
function compileFiles() {
|
|
224
174
|
while (files.length) {
|
|
225
175
|
createStream(files.pop());
|
|
226
176
|
}
|
|
227
177
|
}
|
|
228
|
-
|
|
229
178
|
const debouncedCompileFiles = _lodash.default.debounce(compileFiles, 1000);
|
|
230
|
-
|
|
231
179
|
watcher.on("all", (event, fullPath) => {
|
|
232
180
|
const relPath = fullPath.replace(srcPath, "");
|
|
233
181
|
log(`[${event}] ${(0, _slash.default)((0, _path.join)(srcPath, relPath)).replace(`${cwd}/`, "")}`);
|
|
234
182
|
if (!(0, _fs.existsSync)(fullPath)) return;
|
|
235
|
-
|
|
236
183
|
if ((0, _fs.statSync)(fullPath).isFile()) {
|
|
237
184
|
if (!files.includes(fullPath)) files.push(fullPath);
|
|
238
185
|
debouncedCompileFiles();
|
|
@@ -243,7 +190,6 @@ function _ref() {
|
|
|
243
190
|
});
|
|
244
191
|
dispose === null || dispose === void 0 ? void 0 : dispose.push(() => watcher.close());
|
|
245
192
|
}
|
|
246
|
-
|
|
247
193
|
resolve();
|
|
248
194
|
});
|
|
249
195
|
});
|
package/lib/build.js
CHANGED
|
@@ -7,61 +7,38 @@ exports.build = build;
|
|
|
7
7
|
exports.buildForLerna = buildForLerna;
|
|
8
8
|
exports.default = _default;
|
|
9
9
|
exports.getBundleOpts = getBundleOpts;
|
|
10
|
-
|
|
11
10
|
var assert = _interopRequireWildcard(require("assert"));
|
|
12
|
-
|
|
13
11
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
|
-
|
|
15
12
|
var _fs = require("fs");
|
|
16
|
-
|
|
17
13
|
var _lodash = require("lodash");
|
|
18
|
-
|
|
19
14
|
var _path = require("path");
|
|
20
|
-
|
|
21
15
|
var _rimraf = _interopRequireDefault(require("rimraf"));
|
|
22
|
-
|
|
23
16
|
var _signale = _interopRequireDefault(require("signale"));
|
|
24
|
-
|
|
25
17
|
var _babel = _interopRequireDefault(require("./babel"));
|
|
26
|
-
|
|
27
18
|
var _getUserConfig = _interopRequireWildcard(require("./getUserConfig"));
|
|
28
|
-
|
|
29
19
|
var _randomColor = _interopRequireDefault(require("./randomColor"));
|
|
30
|
-
|
|
31
20
|
var _registerBabel = _interopRequireDefault(require("./registerBabel"));
|
|
32
|
-
|
|
33
21
|
var _rollup = _interopRequireDefault(require("./rollup"));
|
|
34
|
-
|
|
35
22
|
var _utils = require("./utils");
|
|
36
|
-
|
|
37
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
|
-
|
|
39
24
|
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
25
|
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
26
|
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
27
|
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
|
|
48
|
-
|
|
28
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
30
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
49
31
|
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
32
|
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
33
|
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
34
|
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
35
|
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
36
|
function getBundleOpts(opts) {
|
|
60
37
|
const cwd = opts.cwd,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
_opts$buildArgs = opts.buildArgs,
|
|
39
|
+
buildArgs = _opts$buildArgs === void 0 ? {} : _opts$buildArgs,
|
|
40
|
+
_opts$rootConfig = opts.rootConfig,
|
|
41
|
+
rootConfig = _opts$rootConfig === void 0 ? {} : _opts$rootConfig;
|
|
65
42
|
const entry = (0, _utils.getExistFile)({
|
|
66
43
|
cwd,
|
|
67
44
|
files: ['src/index.tsx', 'src/index.ts', 'src/index.jsx', 'src/index.js'],
|
|
@@ -75,24 +52,22 @@ function getBundleOpts(opts) {
|
|
|
75
52
|
return userConfigs.map(userConfig => {
|
|
76
53
|
const bundleOpts = (0, _lodash.merge)({
|
|
77
54
|
entry
|
|
78
|
-
}, rootConfig, userConfig, buildArgs);
|
|
55
|
+
}, rootConfig, userConfig, buildArgs);
|
|
79
56
|
|
|
57
|
+
// Support config esm: 'rollup' and cjs: 'rollup'
|
|
80
58
|
if (typeof bundleOpts.esm === 'string') {
|
|
81
59
|
bundleOpts.esm = {
|
|
82
60
|
type: bundleOpts.esm
|
|
83
61
|
};
|
|
84
62
|
}
|
|
85
|
-
|
|
86
63
|
if (typeof bundleOpts.cjs === 'string') {
|
|
87
64
|
bundleOpts.cjs = {
|
|
88
65
|
type: bundleOpts.cjs
|
|
89
66
|
};
|
|
90
67
|
}
|
|
91
|
-
|
|
92
68
|
return bundleOpts;
|
|
93
69
|
});
|
|
94
70
|
}
|
|
95
|
-
|
|
96
71
|
function validateBundleOpts(bundleOpts, {
|
|
97
72
|
cwd,
|
|
98
73
|
rootPath
|
|
@@ -103,81 +78,72 @@ function validateBundleOpts(bundleOpts, {
|
|
|
103
78
|
const pkg = JSON.parse((0, _fs.readFileSync)(pkgPath, 'utf-8'));
|
|
104
79
|
assert.ok((pkg.dependencies || {})['@babel/runtime'], `@babel/runtime dependency is required to use runtimeHelpers`);
|
|
105
80
|
}
|
|
106
|
-
|
|
107
81
|
if (bundleOpts.cjs && bundleOpts.cjs.lazy && bundleOpts.cjs.type === 'rollup') {
|
|
108
82
|
throw new Error(`
|
|
109
83
|
cjs.lazy don't support rollup.
|
|
110
84
|
`.trim());
|
|
111
85
|
}
|
|
112
|
-
|
|
113
86
|
if (!bundleOpts.esm && !bundleOpts.cjs && !bundleOpts.umd) {
|
|
114
87
|
throw new Error(`
|
|
115
88
|
None format of ${_chalk.default.cyan('cjs | esm | umd')} is configured, checkout https://github.com/umijs/father for usage details.
|
|
116
89
|
`.trim());
|
|
117
90
|
}
|
|
118
|
-
|
|
119
91
|
if (bundleOpts.entry) {
|
|
120
92
|
const tsConfigPath = (0, _path.join)(cwd, 'tsconfig.json');
|
|
121
93
|
const tsConfig = (0, _fs.existsSync)(tsConfigPath) || rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, 'tsconfig.json'));
|
|
122
|
-
|
|
123
94
|
if (!tsConfig && (Array.isArray(bundleOpts.entry) && bundleOpts.entry.some(isTypescriptFile) || !Array.isArray(bundleOpts.entry) && isTypescriptFile(bundleOpts.entry))) {
|
|
124
95
|
_signale.default.info(`Project using ${_chalk.default.cyan('typescript')} but tsconfig.json not exists. Use default config.`);
|
|
125
96
|
}
|
|
126
97
|
}
|
|
127
98
|
}
|
|
128
|
-
|
|
129
99
|
function isTypescriptFile(filePath) {
|
|
130
100
|
return filePath.endsWith('.ts') || filePath.endsWith('.tsx');
|
|
131
101
|
}
|
|
132
|
-
|
|
133
102
|
function build(_x) {
|
|
134
103
|
return _build.apply(this, arguments);
|
|
135
104
|
}
|
|
136
|
-
|
|
137
105
|
function _build() {
|
|
138
106
|
_build = _asyncToGenerator(function* (opts, extraOpts = {}) {
|
|
139
107
|
const cwd = opts.cwd,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
108
|
+
rootPath = opts.rootPath,
|
|
109
|
+
watch = opts.watch,
|
|
110
|
+
_opts$buildArgs2 = opts.buildArgs,
|
|
111
|
+
buildArgs = _opts$buildArgs2 === void 0 ? {} : _opts$buildArgs2,
|
|
112
|
+
_opts$clean = opts.clean,
|
|
113
|
+
clean = _opts$clean === void 0 ? true : _opts$clean;
|
|
146
114
|
const pkg = extraOpts.pkg;
|
|
147
115
|
const dispose = [];
|
|
148
|
-
const customConfigPath = buildArgs.config && ((0, _path.isAbsolute)(buildArgs.config) ? buildArgs.config : (0, _path.join)(process.cwd(), buildArgs.config));
|
|
116
|
+
const customConfigPath = buildArgs.config && ((0, _path.isAbsolute)(buildArgs.config) ? buildArgs.config : (0, _path.join)(process.cwd(), buildArgs.config));
|
|
149
117
|
|
|
118
|
+
// register babel for config files
|
|
150
119
|
(0, _registerBabel.default)({
|
|
151
120
|
cwd,
|
|
152
121
|
only: customConfigPath ? _getUserConfig.CONFIG_FILES.concat(customConfigPath) : _getUserConfig.CONFIG_FILES
|
|
153
122
|
});
|
|
154
123
|
const pkgName = (typeof pkg === 'string' ? pkg : pkg === null || pkg === void 0 ? void 0 : pkg.name) || 'unknown';
|
|
155
|
-
|
|
156
124
|
function log(msg) {
|
|
157
125
|
console.log(`${pkg ? `${(0, _randomColor.default)(`${pkgName}`)}: ` : ''}${msg}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
126
|
+
}
|
|
160
127
|
|
|
128
|
+
// Get user config
|
|
161
129
|
const bundleOptsArray = getBundleOpts(opts);
|
|
162
|
-
|
|
163
130
|
var _iterator = _createForOfIteratorHelper(bundleOptsArray),
|
|
164
|
-
|
|
165
|
-
|
|
131
|
+
_step;
|
|
166
132
|
try {
|
|
167
133
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
168
134
|
const bundleOpts = _step.value;
|
|
169
135
|
validateBundleOpts(bundleOpts, {
|
|
170
136
|
cwd,
|
|
171
137
|
rootPath
|
|
172
|
-
});
|
|
138
|
+
});
|
|
173
139
|
|
|
140
|
+
// Clean dist
|
|
174
141
|
if (clean) {
|
|
175
142
|
log(_chalk.default.gray(`Clean dist directory`));
|
|
176
|
-
|
|
177
143
|
_rimraf.default.sync((0, _path.join)(cwd, 'dist'));
|
|
178
|
-
}
|
|
179
|
-
|
|
144
|
+
}
|
|
180
145
|
|
|
146
|
+
// Build umd
|
|
181
147
|
if (bundleOpts.umd) {
|
|
182
148
|
log(`Build umd`);
|
|
183
149
|
yield (0, _rollup.default)({
|
|
@@ -190,13 +156,12 @@ function _build() {
|
|
|
190
156
|
dispose,
|
|
191
157
|
bundleOpts
|
|
192
158
|
});
|
|
193
|
-
}
|
|
194
|
-
|
|
159
|
+
}
|
|
195
160
|
|
|
161
|
+
// Build cjs
|
|
196
162
|
if (bundleOpts.cjs) {
|
|
197
163
|
const cjs = bundleOpts.cjs;
|
|
198
164
|
log(`Build cjs with ${cjs.type}`);
|
|
199
|
-
|
|
200
165
|
if (cjs.type === 'babel') {
|
|
201
166
|
yield (0, _babel.default)({
|
|
202
167
|
cwd,
|
|
@@ -219,14 +184,13 @@ function _build() {
|
|
|
219
184
|
bundleOpts
|
|
220
185
|
});
|
|
221
186
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
187
|
+
}
|
|
224
188
|
|
|
189
|
+
// Build esm
|
|
225
190
|
if (bundleOpts.esm) {
|
|
226
191
|
const esm = bundleOpts.esm;
|
|
227
192
|
log(`Build esm with ${esm.type}`);
|
|
228
193
|
const importLibToEs = esm && esm.importLibToEs;
|
|
229
|
-
|
|
230
194
|
if (esm && esm.type === 'babel') {
|
|
231
195
|
yield (0, _babel.default)({
|
|
232
196
|
cwd,
|
|
@@ -258,32 +222,29 @@ function _build() {
|
|
|
258
222
|
} finally {
|
|
259
223
|
_iterator.f();
|
|
260
224
|
}
|
|
261
|
-
|
|
262
225
|
return dispose;
|
|
263
226
|
});
|
|
264
227
|
return _build.apply(this, arguments);
|
|
265
228
|
}
|
|
266
|
-
|
|
267
229
|
function getPkgRelativePath(cwd, pkg) {
|
|
268
230
|
const basePath = cwd.split(_path.sep).join('/') + '/packages/';
|
|
269
231
|
const dir = pkg.contents.split(_path.sep).join('/');
|
|
270
232
|
return dir.substring(basePath.length);
|
|
271
233
|
}
|
|
272
|
-
|
|
273
234
|
function buildForLerna(_x2) {
|
|
274
235
|
return _buildForLerna.apply(this, arguments);
|
|
275
236
|
}
|
|
276
|
-
|
|
277
237
|
function _buildForLerna() {
|
|
278
238
|
_buildForLerna = _asyncToGenerator(function* (opts) {
|
|
279
239
|
const cwd = opts.cwd,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
240
|
+
_opts$rootConfig2 = opts.rootConfig,
|
|
241
|
+
rootConfig = _opts$rootConfig2 === void 0 ? {} : _opts$rootConfig2,
|
|
242
|
+
_opts$buildArgs3 = opts.buildArgs,
|
|
243
|
+
buildArgs = _opts$buildArgs3 === void 0 ? {} : _opts$buildArgs3,
|
|
244
|
+
_opts$packages = opts.packages,
|
|
245
|
+
packages = _opts$packages === void 0 ? [] : _opts$packages;
|
|
246
|
+
|
|
247
|
+
// register babel for config files
|
|
287
248
|
(0, _registerBabel.default)({
|
|
288
249
|
cwd,
|
|
289
250
|
only: _getUserConfig.CONFIG_FILES
|
|
@@ -291,28 +252,23 @@ function _buildForLerna() {
|
|
|
291
252
|
const userConfig = (0, _lodash.merge)((0, _getUserConfig.default)({
|
|
292
253
|
cwd
|
|
293
254
|
}), rootConfig, buildArgs);
|
|
294
|
-
let pkgs = yield (0, _utils.getLernaPackages)(cwd, userConfig.pkgFilter);
|
|
295
|
-
|
|
255
|
+
let pkgs = yield (0, _utils.getLernaPackages)(cwd, userConfig.pkgFilter);
|
|
256
|
+
// support define pkgs in lerna
|
|
296
257
|
if (userConfig.pkgs) {
|
|
297
258
|
pkgs = pkgs.filter(pkg => userConfig.pkgs.includes(getPkgRelativePath(cwd, pkg)));
|
|
298
259
|
}
|
|
299
|
-
|
|
300
260
|
const dispose = [];
|
|
301
|
-
|
|
302
261
|
var _iterator2 = _createForOfIteratorHelper(pkgs),
|
|
303
|
-
|
|
304
|
-
|
|
262
|
+
_step2;
|
|
305
263
|
try {
|
|
306
264
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
307
265
|
const pkg = _step2.value;
|
|
308
266
|
const pkgName = getPkgRelativePath(cwd, pkg);
|
|
309
|
-
|
|
310
267
|
if (userConfig.excludePkgs && userConfig.excludePkgs.includes(pkgName)) {
|
|
311
268
|
continue;
|
|
312
269
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
270
|
+
if (packages.length && !packages.includes(pkgName)) continue;
|
|
271
|
+
// build error when .DS_Store includes in packages root
|
|
316
272
|
const pkgPath = pkg.contents;
|
|
317
273
|
assert.ok((0, _fs.existsSync)((0, _path.join)(pkgPath, 'package.json')), `package.json not found in packages/${pkg}`);
|
|
318
274
|
process.chdir(pkgPath);
|
|
@@ -330,16 +286,13 @@ function _buildForLerna() {
|
|
|
330
286
|
} finally {
|
|
331
287
|
_iterator2.f();
|
|
332
288
|
}
|
|
333
|
-
|
|
334
289
|
return dispose;
|
|
335
290
|
});
|
|
336
291
|
return _buildForLerna.apply(this, arguments);
|
|
337
292
|
}
|
|
338
|
-
|
|
339
293
|
function _default(_x3) {
|
|
340
294
|
return _ref.apply(this, arguments);
|
|
341
295
|
}
|
|
342
|
-
|
|
343
296
|
function _ref() {
|
|
344
297
|
_ref = _asyncToGenerator(function* (opts) {
|
|
345
298
|
const useLerna = (0, _fs.existsSync)((0, _path.join)(opts.cwd, 'lerna.json'));
|
|
@@ -5,23 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getPkgPath = getPkgPath;
|
|
7
7
|
exports.shouldTransform = shouldTransform;
|
|
8
|
-
|
|
9
8
|
var _path = require("path");
|
|
10
|
-
|
|
11
9
|
var _pkgUp = _interopRequireDefault(require("pkg-up"));
|
|
12
|
-
|
|
13
10
|
var _semver = require("semver");
|
|
14
|
-
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
12
|
// 参考:
|
|
18
13
|
// https://github.com/umijs/umi/blob/2.x/packages/af-webpack/src/getWebpackConfig/es5ImcompatibleVersions.js
|
|
14
|
+
|
|
19
15
|
const pkgPathCache = {};
|
|
20
16
|
const pkgCache = {};
|
|
21
|
-
|
|
22
17
|
const _require = require('es5-imcompatible-versions/package.json'),
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
config = _require.config['es5-imcompatible-versions'];
|
|
25
19
|
function getPkgPath(filePath) {
|
|
26
20
|
const dir = (0, _path.dirname)(filePath);
|
|
27
21
|
if (dir in pkgPathCache) return pkgPathCache[dir];
|
|
@@ -30,18 +24,14 @@ function getPkgPath(filePath) {
|
|
|
30
24
|
});
|
|
31
25
|
return pkgPathCache[dir];
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
function shouldTransform(pkgPath) {
|
|
35
28
|
if (pkgPath in pkgCache) return pkgCache[pkgPath];
|
|
36
|
-
|
|
37
29
|
const _require2 = require(pkgPath),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
name = _require2.name,
|
|
31
|
+
version = _require2.version;
|
|
41
32
|
pkgCache[pkgPath] = isMatch(name, version);
|
|
42
33
|
return pkgCache[pkgPath];
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
function isMatch(name, version) {
|
|
46
36
|
if (config[name]) {
|
|
47
37
|
return Object.keys(config[name]).some(sv => (0, _semver.satisfies)(version, sv));
|