@umijs/bundler-utoopack 4.6.42 → 4.6.43

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/dist/config.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { IOpts as IConfigOpts } from '@umijs/bundler-webpack';
2
2
  import type { BundleOptions } from '@utoo/pack';
3
3
  import type { IOpts } from './types';
4
+ export declare function mergeExtraPostcssPlugins(postcssConfig: any, extraPlugins?: any[]): any;
4
5
  export declare function getProdUtooPackConfig(opts: IOpts): Promise<BundleOptions>;
5
6
  export declare type IDevOpts = {
6
7
  afterMiddlewares?: any[];
package/dist/config.js CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var config_exports = {};
31
31
  __export(config_exports, {
32
32
  getDevUtooPackConfig: () => getDevUtooPackConfig,
33
- getProdUtooPackConfig: () => getProdUtooPackConfig
33
+ getProdUtooPackConfig: () => getProdUtooPackConfig,
34
+ mergeExtraPostcssPlugins: () => mergeExtraPostcssPlugins
34
35
  });
35
36
  module.exports = __toCommonJS(config_exports);
36
37
  var import_bundler_webpack = require("@umijs/bundler-webpack");
@@ -185,6 +186,61 @@ function getSvgModuleRules(opts) {
185
186
  }
186
187
  };
187
188
  }
189
+ function appendPostcssPlugin(postcssConfig, plugin) {
190
+ const [pluginName, pluginOptions = {}] = plugin;
191
+ if (postcssConfig == null) {
192
+ return {
193
+ plugins: {
194
+ [pluginName]: pluginOptions
195
+ }
196
+ };
197
+ }
198
+ if (!import_utils.lodash.isPlainObject(postcssConfig)) {
199
+ throw new Error(
200
+ `Utoopack styles.postcss must be an object when extraPostCSSPlugins is used.`
201
+ );
202
+ }
203
+ const existingPlugins = postcssConfig.plugins;
204
+ if (existingPlugins != null && !import_utils.lodash.isPlainObject(existingPlugins)) {
205
+ throw new Error(
206
+ `Utoopack styles.postcss.plugins must be an object when extraPostCSSPlugins is used.`
207
+ );
208
+ }
209
+ return {
210
+ ...postcssConfig,
211
+ plugins: {
212
+ ...existingPlugins || {},
213
+ [pluginName]: pluginOptions
214
+ }
215
+ };
216
+ }
217
+ function normalizeExtraPostcssPlugin(plugin) {
218
+ if (typeof plugin === "string") {
219
+ return [[plugin, {}]];
220
+ }
221
+ if (Array.isArray(plugin) && typeof plugin[0] === "string" && plugin.length <= 2) {
222
+ return [[plugin[0], plugin[1] ?? {}]];
223
+ }
224
+ if (import_utils.lodash.isPlainObject(plugin)) {
225
+ return Object.entries(plugin);
226
+ }
227
+ throw new Error(
228
+ `Utoopack only supports JSON-serializable extraPostCSSPlugins entries. Please use plugin names or [pluginName, options] tuples instead.`
229
+ );
230
+ }
231
+ function mergeExtraPostcssPlugins(postcssConfig, extraPlugins = []) {
232
+ return extraPlugins.reduce((memo, plugin) => {
233
+ return normalizeExtraPostcssPlugin(plugin).reduce(
234
+ (ret, normalizedPlugin) => {
235
+ return appendPostcssPlugin(ret, normalizedPlugin);
236
+ },
237
+ memo
238
+ );
239
+ }, postcssConfig);
240
+ }
241
+ function getUserUtoopackConfig(utoopackConfig = {}) {
242
+ return import_utils.lodash.omit(utoopackConfig, ["root"]);
243
+ }
188
244
  async function getProdUtooPackConfig(opts) {
189
245
  var _a;
190
246
  const webpackConfig = await (0, import_bundler_webpack.getConfig)({
@@ -241,6 +297,7 @@ async function getProdUtooPackConfig(opts) {
241
297
  svgo = {},
242
298
  inlineLimit
243
299
  } = opts.config;
300
+ const userUtoopackConfig = getUserUtoopackConfig(opts.config.utoopack);
244
301
  utooBundlerOpts = {
245
302
  ...utooBundlerOpts,
246
303
  config: import_utils.lodash.merge(
@@ -267,15 +324,16 @@ async function getProdUtooPackConfig(opts) {
267
324
  javascriptEnabled: true,
268
325
  ...opts.config.lessLoader
269
326
  },
327
+ // postcss: normalizedPostcssConfig,
270
328
  sass: opts.config.sassLoader ?? void 0,
271
- emotion: emotion || void 0
329
+ emotion
272
330
  },
273
331
  define,
274
332
  nodePolyfill: true,
275
333
  externals: getNormalizedExternals(userExternals),
276
334
  ...getSvgModuleRules({ svgr, svgo, inlineLimit })
277
335
  },
278
- opts.config.utoopack || {}
336
+ userUtoopackConfig
279
337
  )
280
338
  };
281
339
  return utooBundlerOpts;
@@ -336,6 +394,7 @@ async function getDevUtooPackConfig(opts) {
336
394
  svgo = {},
337
395
  inlineLimit
338
396
  } = opts.config;
397
+ const userUtoopackConfig = getUserUtoopackConfig(opts.config.utoopack);
339
398
  utooBundlerOpts = {
340
399
  ...utooBundlerOpts,
341
400
  config: import_utils.lodash.merge(
@@ -361,8 +420,9 @@ async function getDevUtooPackConfig(opts) {
361
420
  javascriptEnabled: true,
362
421
  ...opts.config.lessLoader
363
422
  },
423
+ // postcss: normalizedPostcssPlugin,
364
424
  sass: opts.config.sassLoader ?? void 0,
365
- emotion: emotion || void 0
425
+ emotion
366
426
  },
367
427
  define,
368
428
  // dev enable persistent cache by default
@@ -371,7 +431,7 @@ async function getDevUtooPackConfig(opts) {
371
431
  externals: getNormalizedExternals(userExternals),
372
432
  ...getSvgModuleRules({ svgr, svgo, inlineLimit })
373
433
  },
374
- opts.config.utoopack || {}
434
+ userUtoopackConfig
375
435
  ),
376
436
  watch: {
377
437
  enable: true
@@ -383,5 +443,6 @@ async function getDevUtooPackConfig(opts) {
383
443
  // Annotate the CommonJS export names for ESM import in node:
384
444
  0 && (module.exports = {
385
445
  getDevUtooPackConfig,
386
- getProdUtooPackConfig
446
+ getProdUtooPackConfig,
447
+ mergeExtraPostcssPlugins
387
448
  });
package/dist/index.js CHANGED
@@ -43,13 +43,20 @@ var import_fs = __toESM(require("fs"));
43
43
  var import_http = __toESM(require("http"));
44
44
  var import_path = __toESM(require("path"));
45
45
  var import_config = require("./config");
46
+ var import_util = require("./util");
46
47
  var import_pack = require("@utoo/pack");
47
48
  __reExport(src_exports, require("./config"), module.exports);
49
+ function getUtoopackRootDir(cwd, utoopackConfig, findRootDir2) {
50
+ if (typeof (utoopackConfig == null ? void 0 : utoopackConfig.root) === "string") {
51
+ return import_path.default.resolve(cwd, utoopackConfig.root);
52
+ }
53
+ return findRootDir2(cwd);
54
+ }
48
55
  async function build(opts) {
49
56
  var _a;
50
57
  const { cwd, onBuildComplete } = opts;
51
58
  const { build: utooPackBuild, findRootDir: findRootDir2 } = require("@utoo/pack");
52
- const rootDir = findRootDir2(cwd);
59
+ const rootDir = getUtoopackRootDir(cwd, opts.config.utoopack, findRootDir2);
53
60
  const utooPackConfig = await (0, import_config.getProdUtooPackConfig)({
54
61
  ...opts,
55
62
  rootDir
@@ -89,7 +96,7 @@ async function dev(opts) {
89
96
  throw new Error("opts should be supplied");
90
97
  }
91
98
  const { findRootDir: findRootDir2, serve: utooPackServe } = require("@utoo/pack");
92
- const rootDir = findRootDir2(cwd);
99
+ const rootDir = getUtoopackRootDir(cwd, opts.config.utoopack, findRootDir2);
93
100
  const utooPackConfig = await (0, import_config.getDevUtooPackConfig)({
94
101
  ...opts,
95
102
  rootDir
@@ -177,7 +184,7 @@ async function dev(opts) {
177
184
  }
178
185
  server.listen(port, () => {
179
186
  const protocol = opts.config.https ? "https:" : "http:";
180
- const banner = getDevBanner(
187
+ const banner = (0, import_util.getDevBanner)(
181
188
  protocol,
182
189
  opts.host,
183
190
  port,
@@ -228,16 +235,6 @@ async function dev(opts) {
228
235
  console.error(e.message);
229
236
  }
230
237
  }
231
- function getDevBanner(protocol, host, port, ip) {
232
- const hostStr = host === "0.0.0.0" ? "localhost" : host;
233
- const messages = [];
234
- messages.push(" App listening at:");
235
- messages.push(
236
- ` - Local: ${import_utils.chalk.cyan(`${protocol}//${hostStr}:${port}`)}`
237
- );
238
- messages.push(` - Network: ${import_utils.chalk.cyan(`${protocol}//${ip}:${port}`)}`);
239
- return messages.join("\n");
240
- }
241
238
  // Annotate the CommonJS export names for ESM import in node:
242
239
  0 && (module.exports = {
243
240
  build,
package/dist/util.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function getDevBanner(protocol: string, host?: string, port?: number, ip?: string): string;
package/dist/util.js ADDED
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util.ts
20
+ var util_exports = {};
21
+ __export(util_exports, {
22
+ getDevBanner: () => getDevBanner
23
+ });
24
+ module.exports = __toCommonJS(util_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ function getDevBanner(protocol, host, port, ip) {
27
+ const hostStr = host === "0.0.0.0" ? "localhost" : host;
28
+ const messages = [];
29
+ messages.push(" App listening at:");
30
+ messages.push(
31
+ ` - Local: ${import_utils.chalk.cyan(`${protocol}//${hostStr}:${port}`)}`
32
+ );
33
+ messages.push(` - Network: ${import_utils.chalk.cyan(`${protocol}//${ip}:${port}`)}`);
34
+ return messages.join("\n");
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ getDevBanner
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.6.42",
3
+ "version": "4.6.43",
4
4
  "description": "@umijs/bundler-utoopack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "@utoo/pack": "1.3.9",
11
+ "@utoo/pack": "1.3.10",
12
12
  "compression": "^1.7.4",
13
13
  "connect-history-api-fallback": "^2.0.0",
14
14
  "cors": "^2.8.5",
@@ -19,8 +19,8 @@
19
19
  "postcss": "^8.4.21",
20
20
  "sass": "1.54.0",
21
21
  "sass-loader": "13.2.0",
22
- "@umijs/bundler-utils": "4.6.42",
23
- "@umijs/bundler-webpack": "4.6.42"
22
+ "@umijs/bundler-utils": "4.6.43",
23
+ "@umijs/bundler-webpack": "4.6.43"
24
24
  },
25
25
  "devDependencies": {
26
26
  "father": "4.1.5"