@umijs/bundler-esbuild 4.0.0-rc.7 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/build.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -20,40 +11,47 @@ const alias_1 = __importDefault(require("./plugins/alias"));
20
11
  const externals_1 = __importDefault(require("./plugins/externals"));
21
12
  const less_1 = __importDefault(require("./plugins/less"));
22
13
  const style_1 = require("./plugins/style");
23
- function build(opts) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const outputPath = opts.config.outputPath || (0, path_1.join)(opts.cwd, 'dist');
26
- if (opts.clean) {
27
- utils_1.rimraf.sync(outputPath);
28
- }
29
- return yield (0, esbuild_1.build)({
30
- entryPoints: opts.entry,
31
- bundle: true,
32
- format: opts.format || 'iife',
33
- logLevel: 'error',
34
- // splitting: true,
35
- sourcemap: opts.sourcemap,
36
- outdir: outputPath,
37
- metafile: true,
38
- plugins: [
39
- (0, less_1.default)(Object.assign({ modifyVars: opts.config.theme, javascriptEnabled: true, alias: opts.config.alias,
40
- // ref: https://github.com/umijs/umi-next/pull/214
41
- inlineStyle: opts.inlineStyle, config: opts.config }, opts.config.lessLoader)),
42
- opts.config.alias && (0, alias_1.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
43
- opts.config.externals && (0, externals_1.default)(opts.config.externals),
44
- (0, style_1.style)({
45
- inlineStyle: opts.inlineStyle,
46
- config: opts.config,
47
- }),
48
- ].filter(Boolean),
49
- define: Object.assign({
50
- // __dirname sham
51
- __dirname: JSON.stringify('__dirname'), 'process.env.NODE_ENV': JSON.stringify(opts.mode || 'development') }, opts.config.define),
52
- loader: {
53
- '.svg': 'dataurl',
54
- '.ttf': 'dataurl',
55
- },
56
- });
14
+ async function build(opts) {
15
+ const outputPath = opts.config.outputPath || (0, path_1.join)(opts.cwd, 'dist');
16
+ if (opts.clean) {
17
+ utils_1.rimraf.sync(outputPath);
18
+ }
19
+ return await (0, esbuild_1.build)({
20
+ entryPoints: opts.entry,
21
+ bundle: true,
22
+ format: opts.format || 'iife',
23
+ logLevel: 'error',
24
+ // splitting: true,
25
+ sourcemap: opts.sourcemap,
26
+ outdir: outputPath,
27
+ metafile: true,
28
+ plugins: [
29
+ (0, less_1.default)({
30
+ modifyVars: opts.config.theme,
31
+ javascriptEnabled: true,
32
+ alias: opts.config.alias,
33
+ // ref: https://github.com/umijs/umi-next/pull/214
34
+ inlineStyle: opts.inlineStyle,
35
+ config: opts.config,
36
+ ...opts.config.lessLoader,
37
+ }),
38
+ opts.config.alias && (0, alias_1.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
39
+ opts.config.externals && (0, externals_1.default)(opts.config.externals),
40
+ (0, style_1.style)({
41
+ inlineStyle: opts.inlineStyle,
42
+ config: opts.config,
43
+ }),
44
+ ].filter(Boolean),
45
+ define: {
46
+ // __dirname sham
47
+ __dirname: JSON.stringify('__dirname'),
48
+ 'process.env.NODE_ENV': JSON.stringify(opts.mode || 'development'),
49
+ ...opts.config.define,
50
+ },
51
+ loader: {
52
+ '.svg': 'dataurl',
53
+ '.ttf': 'dataurl',
54
+ },
57
55
  });
58
56
  }
59
57
  exports.build = build;
package/dist/cli.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -38,11 +29,11 @@ if ((0, fs_1.existsSync)(configFile)) {
38
29
  }
39
30
  Object.assign(config, args);
40
31
  if (command === 'build') {
41
- (() => __awaiter(void 0, void 0, void 0, function* () {
32
+ (async () => {
42
33
  process.env.NODE_ENV = 'production';
43
34
  (0, assert_1.default)(entry, `Build failed: entry not found.`);
44
35
  try {
45
- yield (0, build_1.build)({
36
+ await (0, build_1.build)({
46
37
  config,
47
38
  cwd,
48
39
  entry: {
@@ -53,7 +44,7 @@ if (command === 'build') {
53
44
  catch (e) {
54
45
  console.error(e);
55
46
  }
56
- }))();
47
+ })();
57
48
  }
58
49
  else {
59
50
  error(`Unsupported command ${command}.`);
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -21,11 +12,9 @@ const resolver = enhanced_resolve_1.default.create({
21
12
  // TODO: support exports
22
13
  exportsFields: [],
23
14
  });
24
- function resolve(context, path) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return new Promise((resolve, reject) => {
27
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
28
- });
15
+ async function resolve(context, path) {
16
+ return new Promise((resolve, reject) => {
17
+ resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
29
18
  });
30
19
  }
31
20
  // https://esbuild.github.io/plugins/#resolve-callbacks
@@ -43,22 +32,22 @@ exports.default = (options = {}) => {
43
32
  else {
44
33
  filter = new RegExp(`^${key}$`);
45
34
  }
46
- onResolve({ filter: filter }, (args) => __awaiter(this, void 0, void 0, function* () {
47
- const path = yield resolve(args.importer, args.path.replace(filter, value));
35
+ onResolve({ filter: filter }, async (args) => {
36
+ const path = await resolve(args.importer, args.path.replace(filter, value));
48
37
  return {
49
38
  path,
50
39
  };
51
- }));
40
+ });
52
41
  if (!key.endsWith('/') &&
53
42
  (0, fs_1.existsSync)(value) &&
54
43
  (0, fs_1.statSync)(value).isDirectory()) {
55
44
  const filter = new RegExp(`^${addSlashAffix(key)}`);
56
- onResolve({ filter }, (args) => __awaiter(this, void 0, void 0, function* () {
57
- const path = yield resolve(args.importer, args.path.replace(filter, addSlashAffix(value)));
45
+ onResolve({ filter }, async (args) => {
46
+ const path = await resolve(args.importer, args.path.replace(filter, addSlashAffix(value)));
58
47
  return {
59
48
  path,
60
49
  };
61
- }));
50
+ });
62
51
  }
63
52
  });
64
53
  },
@@ -1,3 +1,3 @@
1
1
  import { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
2
- declare const _default: (options?: Record<string, string> | undefined) => Plugin;
2
+ declare const _default: (options?: Record<string, string>) => Plugin;
3
3
  export default _default;
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ alias: Record<string, string>;
3
+ }
4
+ export default class LessAliasPlugin {
5
+ private options;
6
+ constructor(options: Options);
7
+ install(less: LessStatic, pluginManager: Less.PluginManager): void;
8
+ }
9
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@umijs/utils");
4
+ const utils_2 = require("./utils");
5
+ function matches(pattern, importee) {
6
+ if (pattern instanceof RegExp) {
7
+ return pattern.test(importee);
8
+ }
9
+ if (importee.length < pattern.length) {
10
+ return false;
11
+ }
12
+ if (importee === pattern) {
13
+ return true;
14
+ }
15
+ return importee.startsWith(pattern + '/');
16
+ }
17
+ class LessAliasPlugin {
18
+ constructor(options) {
19
+ this.options = options;
20
+ }
21
+ install(less, pluginManager) {
22
+ const alias = (0, utils_2.parseAlias)(this.options.alias);
23
+ function resolveId(filename) {
24
+ if (!filename) {
25
+ return null;
26
+ }
27
+ // First match is supposed to be the correct one
28
+ const matchedEntry = alias.find((entry) => matches(entry.find, filename));
29
+ if (!matchedEntry) {
30
+ return filename;
31
+ }
32
+ const resolvedPath = filename.replace(matchedEntry.find, matchedEntry.replacement);
33
+ return resolvedPath;
34
+ }
35
+ class AliasePlugin extends less.FileManager {
36
+ loadFile(filename, currentDirectory, options, enviroment) {
37
+ let resolved;
38
+ try {
39
+ resolved = resolveId(filename);
40
+ }
41
+ catch (error) {
42
+ utils_1.logger.error(error);
43
+ }
44
+ if (!resolved) {
45
+ const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
46
+ utils_1.logger.error(error);
47
+ throw error;
48
+ }
49
+ return super.loadFile(resolved, currentDirectory, options, enviroment);
50
+ }
51
+ loadFileSync(filename, currentDirectory, options, enviroment) {
52
+ let resolved;
53
+ try {
54
+ resolved = resolveId(filename);
55
+ }
56
+ catch (error) {
57
+ utils_1.logger.error(error);
58
+ }
59
+ if (!resolved) {
60
+ const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
61
+ utils_1.logger.error(error);
62
+ throw error;
63
+ }
64
+ return super.loadFileSync(resolved, currentDirectory, options, enviroment);
65
+ }
66
+ }
67
+ pluginManager.addFileManager(new AliasePlugin());
68
+ }
69
+ }
70
+ exports.default = LessAliasPlugin;
@@ -0,0 +1,4 @@
1
+ export interface Alias {
2
+ find: string | RegExp;
3
+ replacement: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { Alias } from './types';
2
+ export declare function parseAlias(alias: Record<string, string>): Alias[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAlias = void 0;
4
+ function hoistAlias(alias) {
5
+ function getFinalReplacement(oAlias, replacement, index) {
6
+ //过滤重复配置,防止死循环
7
+ const newAlias = oAlias.slice();
8
+ newAlias.splice(index, 1);
9
+ //遍历找到需要深层替换的配置
10
+ for (let i = 0; i < newAlias.length; i++) {
11
+ if (newAlias[i].find.test(replacement)) {
12
+ replacement = replacement.replace(newAlias[i].find, newAlias[i].replacement);
13
+ return getFinalReplacement(newAlias, replacement, i);
14
+ }
15
+ }
16
+ return replacement;
17
+ }
18
+ alias.forEach((rule, index, alias) => {
19
+ rule.replacement = getFinalReplacement(alias, rule.replacement, index);
20
+ });
21
+ return alias;
22
+ }
23
+ function parseAlias(alias) {
24
+ const wholeAlias = [
25
+ // to support less-loader ~ for local deps, refer: https://github.com/vitejs/vite/issues/2185
26
+ { find: /^~/, replacement: '' },
27
+ ];
28
+ const userAlias = Object.entries(alias).map(([name, target]) => ({
29
+ find: new RegExp(`^~?${name.replace(/(?<!\$)$/, '(?=/|$)')}`),
30
+ replacement: target,
31
+ }));
32
+ wholeAlias.unshift(...userAlias);
33
+ return hoistAlias(wholeAlias);
34
+ }
35
+ exports.parseAlias = parseAlias;
@@ -1,36 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  exports.aliasLessImportPath = void 0;
7
+ const less_1 = __importDefault(require("@umijs/bundler-utils/compiled/less"));
27
8
  const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
28
9
  const fs_1 = require("fs");
29
- const less_1 = __importDefault(require("@umijs/bundler-utils/compiled/less"));
30
- const less_plugin_aliases_1 = __importDefault(require("less-plugin-aliases"));
31
10
  const path_1 = __importDefault(require("path"));
32
11
  const postcssProcess_1 = require("../utils/postcssProcess");
33
12
  const sortByAffix_1 = require("../utils/sortByAffix");
13
+ const less_plugin_alias_1 = __importDefault(require("./less-plugin-alias"));
34
14
  const resolver = enhanced_resolve_1.default.create({
35
15
  mainFields: ['module', 'browser', 'main'],
36
16
  extensions: [
@@ -47,27 +27,25 @@ const resolver = enhanced_resolve_1.default.create({
47
27
  // TODO: support exports
48
28
  exportsFields: [],
49
29
  });
50
- function resolve(context, path) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- return new Promise((resolve, reject) => {
53
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
54
- });
30
+ async function resolve(context, path) {
31
+ return new Promise((resolve, reject) => {
32
+ resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
55
33
  });
56
34
  }
57
- const aliasLessImports = (ctx, alias, importer) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const aliasLessImports = async (ctx, alias, importer) => {
58
36
  const importRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/;
59
37
  const globalImportRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/g;
60
38
  const match = ctx.match(globalImportRegex) || [];
61
39
  for (const el of match) {
62
40
  const [imp, _, filePath] = el.match(importRegex) || [];
63
- let aliaPath = yield (0, exports.aliasLessImportPath)(filePath, alias, importer);
41
+ let aliaPath = await (0, exports.aliasLessImportPath)(filePath, alias, importer);
64
42
  if (aliaPath) {
65
43
  ctx = ctx.replace(imp, el.replace(filePath, aliaPath));
66
44
  }
67
45
  }
68
46
  return ctx;
69
- });
70
- const aliasLessImportPath = (filePath, alias, importer) => __awaiter(void 0, void 0, void 0, function* () {
47
+ };
48
+ const aliasLessImportPath = async (filePath, alias, importer) => {
71
49
  // ~ 写法在 esbuild 中无实际意义
72
50
  let aliaPath = filePath.startsWith('~')
73
51
  ? filePath.replace('~', '')
@@ -79,23 +57,23 @@ const aliasLessImportPath = (filePath, alias, importer) => __awaiter(void 0, voi
79
57
  pathSegments[0] = alias[key];
80
58
  aliaPath = pathSegments.join('/');
81
59
  aliaPath = path_1.default.extname(aliaPath) ? aliaPath : `${aliaPath}.less`;
82
- return yield resolve(importer, aliaPath);
60
+ return await resolve(importer, aliaPath);
83
61
  }
84
62
  }
85
63
  return null;
86
- });
64
+ };
87
65
  exports.aliasLessImportPath = aliasLessImportPath;
88
66
  exports.default = (options = {}) => {
89
- const { alias, inlineStyle, config } = options, lessOptions = __rest(options, ["alias", "inlineStyle", "config"]);
67
+ const { alias, inlineStyle, config, ...lessOptions } = options;
90
68
  return {
91
69
  name: 'less',
92
70
  setup({ onResolve, onLoad }) {
93
- onResolve({ filter: /\.less$/, namespace: 'file' }, (args) => __awaiter(this, void 0, void 0, function* () {
71
+ onResolve({ filter: /\.less$/, namespace: 'file' }, async (args) => {
94
72
  let filePath = args.path;
95
73
  let isMatchedAlias = false;
96
74
  // first match alias
97
75
  if (!!alias) {
98
- const aliasMatchPath = yield (0, exports.aliasLessImportPath)(filePath, alias, args.path);
76
+ const aliasMatchPath = await (0, exports.aliasLessImportPath)(filePath, alias, args.path);
99
77
  if (aliasMatchPath) {
100
78
  isMatchedAlias = true;
101
79
  filePath = aliasMatchPath;
@@ -105,7 +83,7 @@ exports.default = (options = {}) => {
105
83
  if (!isMatchedAlias) {
106
84
  const isImportFromDeps = !path_1.default.isAbsolute(filePath) && !filePath.startsWith('.');
107
85
  if (isImportFromDeps) {
108
- filePath = yield resolve(process.cwd(), filePath);
86
+ filePath = await resolve(process.cwd(), filePath);
109
87
  }
110
88
  else {
111
89
  filePath = path_1.default.resolve(process.cwd(), path_1.default.relative(process.cwd(), args.resolveDir), args.path);
@@ -115,7 +93,7 @@ exports.default = (options = {}) => {
115
93
  path: filePath,
116
94
  namespace: inlineStyle ? 'less-file' : 'file',
117
95
  };
118
- }));
96
+ });
119
97
  if (inlineStyle) {
120
98
  onResolve({ filter: /\.less$/, namespace: 'less-file' }, (args) => {
121
99
  return { path: args.path, namespace: 'less-content' };
@@ -125,32 +103,35 @@ exports.default = (options = {}) => {
125
103
  namespace: 'style-helper',
126
104
  sideEffects: false,
127
105
  }));
128
- onLoad({ filter: /.*/, namespace: 'less-file' }, (args) => __awaiter(this, void 0, void 0, function* () {
129
- return ({
130
- contents: `
106
+ onLoad({ filter: /.*/, namespace: 'less-file' }, async (args) => ({
107
+ contents: `
131
108
  import { injectStyle } from "__style_helper__"
132
109
  import css from ${JSON.stringify(args.path)}
133
110
  injectStyle(css)
134
111
  export default{}
135
112
  `,
136
- });
137
113
  }));
138
114
  }
139
- onLoad({ filter: /\.less$/, namespace: inlineStyle ? 'less-content' : 'file' }, (args) => __awaiter(this, void 0, void 0, function* () {
140
- let content = yield fs_1.promises.readFile(args.path, 'utf-8');
115
+ onLoad({ filter: /\.less$/, namespace: inlineStyle ? 'less-content' : 'file' }, async (args) => {
116
+ let content = await fs_1.promises.readFile(args.path, 'utf-8');
141
117
  if (!!alias) {
142
- content = yield aliasLessImports(content, alias, args.path);
118
+ content = await aliasLessImports(content, alias, args.path);
143
119
  }
144
120
  const dir = path_1.default.dirname(args.path);
145
121
  const filename = path_1.default.basename(args.path);
146
122
  try {
147
- const result = yield less_1.default.render(content, Object.assign(Object.assign({ plugins: [
148
- new less_plugin_aliases_1.default({
149
- prefix: '~',
150
- aliases: alias || {},
123
+ const result = await less_1.default.render(content, {
124
+ plugins: [
125
+ new less_plugin_alias_1.default({
126
+ alias: alias || {},
151
127
  }),
152
- ], filename, rootpath: dir }, lessOptions), { paths: [...(lessOptions.paths || []), dir] }));
153
- const postcssrResult = yield (0, postcssProcess_1.postcssProcess)(config, result.css, args.path);
128
+ ],
129
+ filename,
130
+ rootpath: dir,
131
+ ...lessOptions,
132
+ paths: [...(lessOptions.paths || []), dir],
133
+ });
134
+ const postcssrResult = await (0, postcssProcess_1.postcssProcess)(config, result.css, args.path);
154
135
  return {
155
136
  contents: postcssrResult.css,
156
137
  loader: inlineStyle ? 'text' : 'css',
@@ -173,7 +154,7 @@ exports.default = (options = {}) => {
173
154
  resolveDir: dir,
174
155
  };
175
156
  }
176
- }));
157
+ });
177
158
  },
178
159
  };
179
160
  };
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -56,9 +47,8 @@ function style({ minify = true, charset = 'utf8', inlineStyle, config, } = {}) {
56
47
  namespace: 'style-helper',
57
48
  sideEffects: false,
58
49
  }));
59
- onLoad({ filter: /.*/, namespace: 'style-helper' }, () => __awaiter(this, void 0, void 0, function* () {
60
- return ({
61
- contents: `
50
+ onLoad({ filter: /.*/, namespace: 'style-helper' }, async () => ({
51
+ contents: `
62
52
  export function injectStyle(text) {
63
53
  if (typeof document !== 'undefined') {
64
54
  var style = document.createElement('style')
@@ -68,24 +58,21 @@ function style({ minify = true, charset = 'utf8', inlineStyle, config, } = {}) {
68
58
  }
69
59
  }
70
60
  `,
71
- });
72
61
  }));
73
- onLoad({ filter: /.*/, namespace: 'style-stub' }, (args) => __awaiter(this, void 0, void 0, function* () {
74
- return ({
75
- contents: `
62
+ onLoad({ filter: /.*/, namespace: 'style-stub' }, async (args) => ({
63
+ contents: `
76
64
  import { injectStyle } from "__style_helper__"
77
65
  import css from ${JSON.stringify(args.path)}
78
66
  injectStyle(css)
79
67
  `,
80
- });
81
68
  }));
82
69
  }
83
70
  onLoad({
84
71
  filter: inlineStyle ? /.*/ : /\.css$/,
85
72
  namespace: inlineStyle ? 'style-content' : 'file',
86
- }, (args) => __awaiter(this, void 0, void 0, function* () {
87
- const options = Object.assign({ entryPoints: [args.path] }, opt);
88
- const { errors, warnings, outputFiles } = yield esbuild_1.default.build(options);
73
+ }, async (args) => {
74
+ const options = { entryPoints: [args.path], ...opt };
75
+ const { errors, warnings, outputFiles } = await esbuild_1.default.build(options);
89
76
  if (errors.length > 0) {
90
77
  return {
91
78
  errors,
@@ -96,7 +83,7 @@ function style({ minify = true, charset = 'utf8', inlineStyle, config, } = {}) {
96
83
  }
97
84
  const dir = path_1.default.dirname(args.path);
98
85
  try {
99
- const result = yield (0, postcssProcess_1.postcssProcess)(config, outputFiles[0].text, args.path);
86
+ const result = await (0, postcssProcess_1.postcssProcess)(config, outputFiles[0].text, args.path);
100
87
  return {
101
88
  errors,
102
89
  warnings,
@@ -120,7 +107,7 @@ function style({ minify = true, charset = 'utf8', inlineStyle, config, } = {}) {
120
107
  resolveDir: dir,
121
108
  };
122
109
  }
123
- }));
110
+ });
124
111
  },
125
112
  };
126
113
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,19 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.postcssProcess = void 0;
16
7
  const postcss_1 = __importDefault(require("postcss"));
17
8
  const getBrowserlist_1 = require("./getBrowserlist");
18
- function postcssProcess(config, css, path) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return yield (0, postcss_1.default)([
21
- require('postcss-flexbugs-fixes'),
22
- require('postcss-preset-env')({
23
- browsers: (0, getBrowserlist_1.getBrowserlist)((config === null || config === void 0 ? void 0 : config.targets) || {}),
24
- autoprefixer: Object.assign({ flexbox: 'no-2009' }, config === null || config === void 0 ? void 0 : config.autoprefixer),
25
- stage: 3,
26
- }),
27
- ].concat((config === null || config === void 0 ? void 0 : config.extraPostCSSPlugins) || [])).process(css, {
28
- from: path,
29
- to: path,
30
- });
9
+ async function postcssProcess(config, css, path) {
10
+ return await (0, postcss_1.default)([
11
+ require('postcss-flexbugs-fixes'),
12
+ require('postcss-preset-env')({
13
+ browsers: (0, getBrowserlist_1.getBrowserlist)((config === null || config === void 0 ? void 0 : config.targets) || {}),
14
+ autoprefixer: {
15
+ flexbox: 'no-2009',
16
+ ...config === null || config === void 0 ? void 0 : config.autoprefixer,
17
+ },
18
+ stage: 3,
19
+ }),
20
+ ].concat((config === null || config === void 0 ? void 0 : config.extraPostCSSPlugins) || [])).process(css, {
21
+ from: path,
22
+ to: path,
31
23
  });
32
24
  }
33
25
  exports.postcssProcess = postcssProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-esbuild",
3
- "version": "4.0.0-rc.7",
3
+ "version": "4.0.0",
4
4
  "description": "@umijs/bundler-esbuild",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-esbuild#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -19,18 +19,17 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "build": "pnpm tsc",
22
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
22
+ "build:deps": "umi-scripts bundleDeps",
23
23
  "dev": "pnpm build -- --watch",
24
- "test": "jest -c ../../jest.turbo.config.ts"
24
+ "test": "umi-scripts jest-turbo"
25
25
  },
26
26
  "dependencies": {
27
- "@umijs/bundler-utils": "4.0.0-rc.7",
28
- "@umijs/utils": "4.0.0-rc.7",
29
- "enhanced-resolve": "5.9.2",
30
- "less-plugin-aliases": "^1.0.3",
31
- "postcss": "^8.4.12",
27
+ "@umijs/bundler-utils": "4.0.0",
28
+ "@umijs/utils": "4.0.0",
29
+ "enhanced-resolve": "5.9.3",
30
+ "postcss": "^8.4.13",
32
31
  "postcss-flexbugs-fixes": "5.0.2",
33
- "postcss-preset-env": "7.4.2"
32
+ "postcss-preset-env": "7.5.0"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@alitajs/postcss-plugin-px2rem": "^0.0.1"