@nocobase/build 0.13.0-alpha.1 → 0.13.0-alpha.10

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.
@@ -4,7 +4,7 @@ const { existsSync } = require('fs');
4
4
  const { join } = require('path');
5
5
  const yParser = require('yargs-parser');
6
6
  const chalk = require('chalk');
7
- const signale = require('signale');
7
+ const { build } = require('../lib');
8
8
 
9
9
  // print version and @local
10
10
  const args = yParser(process.argv.slice(2), {
@@ -26,46 +26,4 @@ const updater = require('update-notifier');
26
26
  const pkg = require('../package.json');
27
27
  updater({ pkg }).notify({ defer: true });
28
28
 
29
- function stripEmptyKeys(obj) {
30
- Object.keys(obj).forEach((key) => {
31
- if (!obj[key] || (Array.isArray(obj[key]) && !obj[key].length)) {
32
- delete obj[key];
33
- }
34
- });
35
- return obj;
36
- }
37
-
38
- function build() {
39
- // Parse buildArgs from cli
40
- const buildArgs = stripEmptyKeys({
41
- esm: args.esm && { type: args.esm === true ? 'rollup' : args.esm },
42
- cjs: args.cjs && { type: args.cjs === true ? 'rollup' : args.cjs },
43
- umd: args.umd && { name: args.umd === true ? undefined : args.umd },
44
- file: args.file,
45
- target: args.target,
46
- entry: args._,
47
- config: args.config,
48
- });
49
-
50
- if (buildArgs.file && buildArgs.entry && buildArgs.entry.length > 1) {
51
- signale.error(
52
- new Error(`Cannot specify file when have multiple entries (${buildArgs.entry.join(', ')})`)
53
- );
54
- process.exit(1);
55
- }
56
-
57
- require('../lib/build')
58
- .default({
59
- cwd: args.root || process.cwd(),
60
- watch: args.w || args.watch,
61
- clean: args.clean,
62
- buildArgs,
63
- packages: args._ || [],
64
- })
65
- .catch((e) => {
66
- signale.error(e);
67
- process.exit(1);
68
- });
69
- }
70
-
71
- build();
29
+ build(args._);
package/lib/build.js CHANGED
@@ -1,344 +1,106 @@
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
- var assert = _interopRequireWildcard(require("assert"));
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
- var _fs = require("fs");
13
- var _lodash = require("lodash");
14
- var _path = require("path");
15
- var _rimraf = _interopRequireDefault(require("rimraf"));
16
- var _signale = _interopRequireDefault(require("signale"));
17
- var _babel = _interopRequireDefault(require("./babel"));
18
- var _buildPlugin = require("./buildPlugin");
19
- var _getUserConfig = _interopRequireWildcard(require("./getUserConfig"));
20
- var _randomColor = _interopRequireDefault(require("./randomColor"));
21
- var _registerBabel = _interopRequireDefault(require("./registerBabel"));
22
- var _rollup = _interopRequireDefault(require("./rollup"));
23
- var _utils = require("./utils");
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
- 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); }
26
- 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; }
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; }
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; }
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); }
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); } }
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); }); }; }
34
- 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; } } }; }
35
- 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); }
36
- 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; }
37
- function getBundleOpts(opts) {
38
- const cwd = opts.cwd,
39
- _opts$buildArgs = opts.buildArgs,
40
- buildArgs = _opts$buildArgs === void 0 ? {} : _opts$buildArgs,
41
- _opts$rootConfig = opts.rootConfig,
42
- rootConfig = _opts$rootConfig === void 0 ? {} : _opts$rootConfig;
43
- const entry = (0, _utils.getExistFiles)({
44
- cwd,
45
- files: ['src/index.tsx', 'src/index.ts', 'src/index.jsx', 'src/index.js', 'src/server/index.ts', 'src/server/index.js', 'src/client/index.js', 'src/client/index.ts', 'src/client/index.tsx'],
46
- onlyOne: false,
47
- returnRelative: true
48
- });
49
- const userConfig = (0, _getUserConfig.default)({
50
- cwd,
51
- customPath: buildArgs.config
52
- });
53
- const userConfigs = Array.isArray(userConfig) ? userConfig : [userConfig];
54
- return userConfigs.map(userConfig => {
55
- const bundleOpts = (0, _lodash.merge)({
56
- entry
57
- }, rootConfig, userConfig, buildArgs);
58
-
59
- // Support config esm: 'rollup' and cjs: 'rollup'
60
- if (typeof bundleOpts.esm === 'string') {
61
- bundleOpts.esm = {
62
- type: bundleOpts.esm
63
- };
64
- }
65
- if (typeof bundleOpts.cjs === 'string') {
66
- bundleOpts.cjs = {
67
- type: bundleOpts.cjs
68
- };
69
- }
70
- return bundleOpts;
71
- });
72
- }
73
- function validateBundleOpts(bundleOpts, {
74
- cwd,
75
- rootPath
76
- }) {
77
- if (bundleOpts.runtimeHelpers) {
78
- const pkgPath = (0, _path.join)(cwd, 'package.json');
79
- assert.ok((0, _fs.existsSync)(pkgPath), `@babel/runtime dependency is required to use runtimeHelpers`);
80
- const pkg = JSON.parse((0, _fs.readFileSync)(pkgPath, 'utf-8'));
81
- assert.ok((pkg.dependencies || {})['@babel/runtime'], `@babel/runtime dependency is required to use runtimeHelpers`);
82
- }
83
- if (bundleOpts.cjs && bundleOpts.cjs.lazy && bundleOpts.cjs.type === 'rollup') {
84
- throw new Error(`
85
- cjs.lazy don't support rollup.
86
- `.trim());
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
87
16
  }
88
- if (!bundleOpts.esm && !bundleOpts.cjs && !bundleOpts.umd) {
89
- throw new Error(`
90
- None format of ${_chalk.default.cyan('cjs | esm | umd')} is configured, checkout https://github.com/umijs/father for usage details.
91
- `.trim());
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var build_exports = {};
29
+ __export(build_exports, {
30
+ build: () => build,
31
+ buildPackage: () => buildPackage,
32
+ buildPackages: () => buildPackages
33
+ });
34
+ module.exports = __toCommonJS(build_exports);
35
+ var import_execa = __toESM(require("execa"));
36
+ var import_chalk = __toESM(require("chalk"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_constant = require("./constant");
39
+ var import_buildClient = require("./buildClient");
40
+ var import_buildCjs = require("./buildCjs");
41
+ var import_buildPlugin = require("./buildPlugin");
42
+ var import_buildDeclaration = require("./buildDeclaration");
43
+ var import_utils = require("./utils");
44
+ var import_getPackages = require("./utils/getPackages");
45
+ async function build(pkgs) {
46
+ const packages = (0, import_getPackages.getPackages)(pkgs);
47
+ const pluginPackages = (0, import_constant.getPluginPackages)(packages);
48
+ const cjsPackages = (0, import_constant.getCjsPackages)(packages);
49
+ const presetsPackages = (0, import_constant.getPresetsPackages)(packages);
50
+ await buildPackages(cjsPackages, "lib", import_buildCjs.buildCjs);
51
+ const clientCore = packages.find((item) => item.location === import_constant.CORE_CLIENT);
52
+ if (clientCore) {
53
+ await buildPackage(clientCore, "es", import_buildClient.buildClient);
92
54
  }
93
- if (bundleOpts.entry) {
94
- const tsConfigPath = (0, _path.join)(cwd, 'tsconfig.json');
95
- const tsConfig = (0, _fs.existsSync)(tsConfigPath) || rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, 'tsconfig.json'));
96
- if (!tsConfig && (Array.isArray(bundleOpts.entry) && bundleOpts.entry.some(isTypescriptFile) || !Array.isArray(bundleOpts.entry) && isTypescriptFile(bundleOpts.entry))) {
97
- _signale.default.info(`Project using ${_chalk.default.cyan('typescript')} but tsconfig.json not exists. Use default config.`);
98
- }
55
+ await buildPackages(pluginPackages, "dist", import_buildPlugin.buildPlugin);
56
+ await buildPackages(presetsPackages, "lib", import_buildCjs.buildCjs);
57
+ const appClient = packages.find((item) => item.location === import_constant.CORE_APP);
58
+ if (appClient) {
59
+ await runScript(["umi", "build"], import_constant.ROOT_PATH, {
60
+ APP_ROOT: import_path.default.join(import_constant.CORE_APP, "client")
61
+ });
99
62
  }
100
63
  }
101
- function isTypescriptFile(filePath) {
102
- return filePath.endsWith('.ts') || filePath.endsWith('.tsx');
103
- }
104
- function isPluginPackage(name) {
105
- const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '').split(',');
106
- var _iterator = _createForOfIteratorHelper(prefixes),
107
- _step;
108
- try {
109
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
110
- const prefix = _step.value;
111
- if (prefix.includes('preset')) {
112
- continue;
113
- }
114
- if (name.startsWith(prefix)) {
115
- return true;
116
- }
117
- }
118
- } catch (err) {
119
- _iterator.e(err);
120
- } finally {
121
- _iterator.f();
64
+ async function buildPackages(packages, targetDir, doBuildPackage) {
65
+ for await (const pkg of packages) {
66
+ await buildPackage(pkg, targetDir, doBuildPackage);
122
67
  }
123
- return false;
124
- }
125
- function build(_x) {
126
- return _build.apply(this, arguments);
127
68
  }
128
- function _build() {
129
- _build = _asyncToGenerator(function* (opts, extraOpts = {}) {
130
- const cwd = opts.cwd,
131
- rootPath = opts.rootPath,
132
- watch = opts.watch,
133
- _opts$buildArgs2 = opts.buildArgs,
134
- buildArgs = _opts$buildArgs2 === void 0 ? {} : _opts$buildArgs2,
135
- _opts$clean = opts.clean,
136
- clean = _opts$clean === void 0 ? true : _opts$clean;
137
- const pkg = extraOpts.pkg;
138
- const dispose = [];
139
- const customConfigPath = buildArgs.config && ((0, _path.isAbsolute)(buildArgs.config) ? buildArgs.config : (0, _path.join)(process.cwd(), buildArgs.config));
140
-
141
- // register babel for config files
142
- (0, _registerBabel.default)({
143
- cwd,
144
- only: customConfigPath ? _getUserConfig.CONFIG_FILES.concat(customConfigPath) : _getUserConfig.CONFIG_FILES
145
- });
146
- const pkgName = (typeof pkg === 'string' ? pkg : pkg === null || pkg === void 0 ? void 0 : pkg.name) || 'unknown';
147
- function log(msg, ...args) {
148
- console.log(`${pkg ? `${(0, _randomColor.default)(`${pkgName}`)}: ` : ''}${msg}`, ...args);
149
- }
150
-
151
- // Get user config
152
- const bundleOptsArray = getBundleOpts(opts);
153
- const isPlugin = isPluginPackage(pkgName);
154
-
155
- // Clean dist
156
- if (clean && !isPlugin) {
157
- log(_chalk.default.gray(`Clean dist directory`));
158
- _rimraf.default.sync((0, _path.join)(cwd, 'dist'));
159
- }
160
- var _iterator2 = _createForOfIteratorHelper(bundleOptsArray),
161
- _step2;
162
- try {
163
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
164
- const bundleOpts = _step2.value;
165
- validateBundleOpts(bundleOpts, {
166
- cwd,
167
- rootPath
168
- });
169
-
170
- // Build umd
171
- if (bundleOpts.umd) {
172
- log(`Build umd`);
173
- yield (0, _rollup.default)({
174
- cwd,
175
- rootPath,
176
- log,
177
- type: 'umd',
178
- entry: bundleOpts.entry,
179
- watch,
180
- dispose,
181
- bundleOpts
182
- });
183
- }
184
-
185
- // Build cjs
186
- if (bundleOpts.cjs) {
187
- const cjs = bundleOpts.cjs;
188
- log(`Build ${isPlugin ? 'd.ts' : 'cjs'} with ${cjs.type}`);
189
- if (cjs.type === 'babel') {
190
- yield (0, _babel.default)({
191
- cwd,
192
- rootPath,
193
- watch,
194
- dispose,
195
- isPlugin,
196
- type: 'cjs',
197
- log,
198
- bundleOpts
199
- });
200
- if (isPlugin) {
201
- log(cwd);
202
- (0, _buildPlugin.deleteJsFiles)(cwd, log);
203
- yield (0, _buildPlugin.buildPluginServer)(cwd, log);
204
- yield (0, _buildPlugin.buildPluginClient)(cwd, log);
205
- const buildFile = (0, _path.join)(cwd, 'build.js');
206
- if ((0, _fs.existsSync)(buildFile)) {
207
- log('build others');
208
- try {
209
- yield require(buildFile).run(log);
210
- } catch (error) {
211
- console.error(error);
212
- }
213
- }
214
- }
215
- } else {
216
- yield (0, _rollup.default)({
217
- cwd,
218
- rootPath,
219
- log,
220
- type: 'cjs',
221
- entry: bundleOpts.entry,
222
- watch,
223
- dispose,
224
- bundleOpts
225
- });
226
- }
227
- }
228
-
229
- // Build esm
230
- if (bundleOpts.esm) {
231
- const esm = bundleOpts.esm;
232
- log(`Build esm with ${esm.type}`);
233
- const importLibToEs = esm && esm.importLibToEs;
234
- if (esm && esm.type === 'babel') {
235
- yield (0, _babel.default)({
236
- cwd,
237
- rootPath,
238
- watch,
239
- dispose,
240
- type: 'esm',
241
- importLibToEs,
242
- log,
243
- bundleOpts
244
- });
245
- } else {
246
- yield (0, _rollup.default)({
247
- cwd,
248
- rootPath,
249
- log,
250
- type: 'esm',
251
- entry: bundleOpts.entry,
252
- importLibToEs,
253
- watch,
254
- dispose,
255
- bundleOpts
256
- });
257
- }
258
- }
259
- }
260
- } catch (err) {
261
- _iterator2.e(err);
262
- } finally {
263
- _iterator2.f();
264
- }
265
- return dispose;
266
- });
267
- return _build.apply(this, arguments);
268
- }
269
- function getPkgRelativePath(cwd, pkg) {
270
- const basePath = cwd.split(_path.sep).join('/') + '/packages/';
271
- const dir = pkg.contents.split(_path.sep).join('/');
272
- return dir.substring(basePath.length);
273
- }
274
- function buildForLerna(_x2) {
275
- return _buildForLerna.apply(this, arguments);
69
+ async function buildPackage(pkg, targetDir, doBuildPackage) {
70
+ const sourcemap = process.argv.includes("--sourcemap");
71
+ const noDeclaration = process.argv.includes("--no-dts");
72
+ const log = (0, import_utils.getPkgLog)(pkg.name);
73
+ const packageJson = (0, import_utils.getPackageJson)(pkg.location);
74
+ log(`${import_chalk.default.bold((0, import_utils.toUnixPath)(pkg.location.replace(import_constant.PACKAGES_PATH, "").slice(1)))} build start`);
75
+ if (packageJson?.scripts?.prebuild) {
76
+ log("prebuild");
77
+ await runScript(["prebuild"], pkg.location);
78
+ await packageJson.prebuild(pkg.location);
79
+ }
80
+ await doBuildPackage(pkg.location, sourcemap, log);
81
+ if (!noDeclaration) {
82
+ log("build declaration");
83
+ await (0, import_buildDeclaration.buildDeclaration)(pkg.location, targetDir);
84
+ }
85
+ if (packageJson?.scripts?.postbuild) {
86
+ log("postbuild");
87
+ await runScript(["postbuild"], pkg.location);
88
+ }
276
89
  }
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;
286
-
287
- // register babel for config files
288
- (0, _registerBabel.default)({
289
- cwd,
290
- only: _getUserConfig.CONFIG_FILES
291
- });
292
- const userConfig = (0, _lodash.merge)((0, _getUserConfig.default)({
293
- cwd
294
- }), rootConfig, buildArgs);
295
- let pkgs = yield (0, _utils.getLernaPackages)(cwd, userConfig.pkgFilter);
296
- // support define pkgs in lerna
297
- if (userConfig.pkgs) {
298
- pkgs = pkgs.filter(pkg => userConfig.pkgs.includes(getPkgRelativePath(cwd, pkg)));
299
- }
300
- const dispose = [];
301
- var _iterator3 = _createForOfIteratorHelper(pkgs),
302
- _step3;
303
- try {
304
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
305
- const pkg = _step3.value;
306
- const pkgName = getPkgRelativePath(cwd, pkg);
307
- if (userConfig.excludePkgs && userConfig.excludePkgs.includes(pkgName)) {
308
- continue;
309
- }
310
- if (packages.length && !packages.includes(pkgName)) continue;
311
- // build error when .DS_Store includes in packages root
312
- const pkgPath = pkg.contents;
313
- assert.ok((0, _fs.existsSync)((0, _path.join)(pkgPath, 'package.json')), `package.json not found in packages/${pkg}`);
314
- process.chdir(pkgPath);
315
- dispose.push(...(yield build(_objectSpread(_objectSpread({}, opts), {}, {
316
- buildArgs: opts.buildArgs,
317
- rootConfig: userConfig,
318
- cwd: pkgPath,
319
- rootPath: cwd
320
- }), {
321
- pkg
322
- })));
323
- }
324
- } catch (err) {
325
- _iterator3.e(err);
326
- } finally {
327
- _iterator3.f();
90
+ function runScript(args, cwd, envs = {}) {
91
+ return (0, import_execa.default)("yarn", args, {
92
+ cwd,
93
+ stdio: "inherit",
94
+ env: {
95
+ ...process.env,
96
+ ...envs,
97
+ NODE_ENV: "production"
328
98
  }
329
- return dispose;
330
99
  });
331
- return _buildForLerna.apply(this, arguments);
332
- }
333
- function _default(_x3) {
334
- return _ref.apply(this, arguments);
335
100
  }
336
- function _ref() {
337
- _ref = _asyncToGenerator(function* (opts) {
338
- const useLerna = (0, _fs.existsSync)((0, _path.join)(opts.cwd, 'lerna.json'));
339
- const isLerna = useLerna && process.env.LERNA !== 'none';
340
- const dispose = isLerna ? yield buildForLerna(opts) : yield build(opts);
341
- return () => dispose.forEach(e => e());
342
- });
343
- return _ref.apply(this, arguments);
344
- }
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ build,
104
+ buildPackage,
105
+ buildPackages
106
+ });
@@ -0,0 +1,68 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var buildCjs_exports = {};
29
+ __export(buildCjs_exports, {
30
+ buildCjs: () => buildCjs
31
+ });
32
+ module.exports = __toCommonJS(buildCjs_exports);
33
+ var import_tsup = require("tsup");
34
+ var import_fast_glob = __toESM(require("fast-glob"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_chalk = __toESM(require("chalk"));
37
+ var import_constant = require("./constant");
38
+ function buildCjs(cwd, sourcemap = false, log) {
39
+ log("build cjs");
40
+ const entry = import_fast_glob.default.globSync(["src/**", ...import_constant.globExcludeFiles], { cwd, absolute: true });
41
+ const outDir = import_path.default.join(cwd, "lib");
42
+ const otherExts = Array.from(new Set(entry.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item))));
43
+ if (otherExts.length) {
44
+ log("%s will not be processed, only be copied to the lib directory.", import_chalk.default.yellow(otherExts.join(",")));
45
+ }
46
+ return (0, import_tsup.build)({
47
+ entry,
48
+ splitting: false,
49
+ clean: true,
50
+ bundle: false,
51
+ silent: true,
52
+ sourcemap,
53
+ treeshake: false,
54
+ target: "node16",
55
+ keepNames: true,
56
+ outDir,
57
+ loader: {
58
+ ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
59
+ ".json": "copy"
60
+ },
61
+ format: "cjs",
62
+ skipNodeModulesBundle: true
63
+ });
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ buildCjs
68
+ });
@@ -0,0 +1,105 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var buildClient_exports = {};
29
+ __export(buildClient_exports, {
30
+ buildClient: () => buildClient,
31
+ buildLib: () => buildLib,
32
+ buildLocale: () => buildLocale
33
+ });
34
+ module.exports = __toCommonJS(buildClient_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_fast_glob = __toESM(require("fast-glob"));
37
+ var import_vite = require("vite");
38
+ var import_tsup = require("tsup");
39
+ var import_vite_plugin_lib_inject_css = require("vite-plugin-lib-inject-css");
40
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
41
+ var import_constant = require("./constant");
42
+ async function buildClient(cwd, sourcemap = false, log) {
43
+ log("build client");
44
+ await Promise.all([buildLib(cwd, sourcemap, "cjs"), buildLib(cwd, sourcemap, "es")]);
45
+ await buildLocale(cwd);
46
+ }
47
+ function buildLib(cwd, sourcemap, format) {
48
+ const outDir = import_path.default.resolve(cwd, format === "cjs" ? "lib" : "es");
49
+ const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
50
+ const cwdWin = cwd.replaceAll(/\\/g, "/");
51
+ const cwdUnix = cwd.replaceAll(/\//g, "\\");
52
+ return (0, import_vite.build)({
53
+ mode: "production",
54
+ define: {
55
+ "process.env.NODE_ENV": JSON.stringify("production")
56
+ },
57
+ build: {
58
+ minify: false,
59
+ outDir,
60
+ cssCodeSplit: true,
61
+ emptyOutDir: true,
62
+ sourcemap,
63
+ lib: {
64
+ entry,
65
+ formats: [format],
66
+ fileName: "index"
67
+ },
68
+ target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
69
+ rollupOptions: {
70
+ cache: true,
71
+ treeshake: true,
72
+ external(id) {
73
+ if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
74
+ return false;
75
+ }
76
+ return true;
77
+ }
78
+ }
79
+ },
80
+ plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_lib_inject_css.libInjectCss)()]
81
+ });
82
+ }
83
+ function buildLocale(cwd) {
84
+ const entry = import_fast_glob.default.globSync(["src/locale/**", ...import_constant.globExcludeFiles], { cwd, absolute: true });
85
+ const outDir = import_path.default.resolve(cwd, "lib", "locale");
86
+ return (0, import_tsup.build)({
87
+ entry,
88
+ splitting: false,
89
+ clean: false,
90
+ bundle: false,
91
+ silent: true,
92
+ treeshake: false,
93
+ target: "node16",
94
+ keepNames: true,
95
+ outDir,
96
+ format: "cjs",
97
+ skipNodeModulesBundle: true
98
+ });
99
+ }
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ buildClient,
103
+ buildLib,
104
+ buildLocale
105
+ });