@umijs/bundler-esbuild 4.0.0-rc.1 → 4.0.0-rc.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/dist/build.d.ts CHANGED
@@ -15,5 +15,7 @@ interface IOpts {
15
15
  extraBabelPresets?: IBabelPlugin[];
16
16
  inlineStyle?: boolean;
17
17
  }
18
- export declare function build(opts: IOpts): Promise<import("@umijs/bundler-utils/compiled/esbuild").BuildResult>;
18
+ export declare function build(opts: IOpts): Promise<import("@umijs/bundler-utils/compiled/esbuild").BuildResult & {
19
+ metafile: import("@umijs/bundler-utils/compiled/esbuild").Metafile;
20
+ }>;
19
21
  export {};
@@ -1,6 +1,7 @@
1
1
  /// <reference types="less" />
2
2
  import { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
3
3
  import { IConfig } from '../types';
4
+ export declare const aliasLessImportPath: (filePath: string, alias: Record<string, string>, importer: string) => Promise<string | null>;
4
5
  declare const _default: (options?: Less.Options & {
5
6
  alias?: Record<string, string>;
6
7
  inlineStyle?: boolean;
@@ -23,6 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.aliasLessImportPath = void 0;
26
27
  const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
27
28
  const fs_1 = require("fs");
28
29
  const less_1 = __importDefault(require("less"));
@@ -59,7 +60,7 @@ const aliasLessImports = (ctx, alias, importer) => __awaiter(void 0, void 0, voi
59
60
  const match = ctx.match(globalImportRegex) || [];
60
61
  for (const el of match) {
61
62
  const [imp, _, filePath] = el.match(importRegex) || [];
62
- let aliaPath = yield aliasLessImportPath(filePath, alias, importer);
63
+ let aliaPath = yield (0, exports.aliasLessImportPath)(filePath, alias, importer);
63
64
  if (aliaPath) {
64
65
  ctx = ctx.replace(imp, el.replace(filePath, aliaPath));
65
66
  }
@@ -73,16 +74,17 @@ const aliasLessImportPath = (filePath, alias, importer) => __awaiter(void 0, voi
73
74
  : filePath;
74
75
  const keys = (0, sortByAffix_1.sortByAffix)({ arr: Object.keys(alias), affix: '$' });
75
76
  for (const key of keys) {
76
- const value = alias[key];
77
- const filter = new RegExp(`^${key}`);
78
- if (filter.test(aliaPath)) {
79
- aliaPath = aliaPath.replace(filter, value);
77
+ const pathSegments = aliaPath.split('/');
78
+ if (pathSegments[0] === key) {
79
+ pathSegments[0] = alias[key];
80
+ aliaPath = pathSegments.join('/');
80
81
  aliaPath = path_1.default.extname(aliaPath) ? aliaPath : `${aliaPath}.less`;
81
82
  return yield resolve(importer, aliaPath);
82
83
  }
83
84
  }
84
85
  return null;
85
86
  });
87
+ exports.aliasLessImportPath = aliasLessImportPath;
86
88
  exports.default = (options = {}) => {
87
89
  const { alias, inlineStyle, config } = options, lessOptions = __rest(options, ["alias", "inlineStyle", "config"]);
88
90
  return {
@@ -90,14 +92,24 @@ exports.default = (options = {}) => {
90
92
  setup({ onResolve, onLoad }) {
91
93
  onResolve({ filter: /\.less$/, namespace: 'file' }, (args) => __awaiter(this, void 0, void 0, function* () {
92
94
  let filePath = args.path;
95
+ let isMatchedAlias = false;
96
+ // first match alias
93
97
  if (!!alias) {
94
- filePath =
95
- (yield aliasLessImportPath(filePath, alias, args.path)) ||
96
- path_1.default.resolve(process.cwd(), path_1.default.relative(process.cwd(), args.resolveDir), args.path);
98
+ const aliasMatchPath = yield (0, exports.aliasLessImportPath)(filePath, alias, args.path);
99
+ if (aliasMatchPath) {
100
+ isMatchedAlias = true;
101
+ filePath = aliasMatchPath;
102
+ }
97
103
  }
98
- else {
99
- //没有别名也要对路径进行处理
100
- filePath = path_1.default.resolve(process.cwd(), path_1.default.relative(process.cwd(), args.resolveDir), args.path);
104
+ // if alias not matched, identify whether import from deps (node_modules)
105
+ if (!isMatchedAlias) {
106
+ const isImportFromDeps = !path_1.default.isAbsolute(filePath) && !filePath.startsWith('.');
107
+ if (isImportFromDeps) {
108
+ filePath = yield resolve(process.cwd(), filePath);
109
+ }
110
+ else {
111
+ filePath = path_1.default.resolve(process.cwd(), path_1.default.relative(process.cwd(), args.resolveDir), args.path);
112
+ }
101
113
  }
102
114
  return {
103
115
  path: filePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-esbuild",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.2",
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",
@@ -23,14 +23,14 @@
23
23
  "dev": "pnpm build -- --watch"
24
24
  },
25
25
  "dependencies": {
26
- "@umijs/bundler-utils": "4.0.0-rc.1",
27
- "@umijs/utils": "4.0.0-rc.1",
28
- "enhanced-resolve": "5.8.3",
26
+ "@umijs/bundler-utils": "4.0.0-rc.2",
27
+ "@umijs/utils": "4.0.0-rc.2",
28
+ "enhanced-resolve": "5.9.0",
29
29
  "less": "4.1.2",
30
30
  "less-plugin-aliases": "^1.0.3",
31
- "postcss": "^8.4.4",
31
+ "postcss": "^8.4.6",
32
32
  "postcss-flexbugs-fixes": "5.0.2",
33
- "postcss-preset-env": "7.0.1"
33
+ "postcss-preset-env": "7.4.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@alitajs/postcss-plugin-px2rem": "^0.0.1",