balm-core 4.23.0 → 4.23.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.
@@ -70,17 +70,22 @@ const gulpSass = options => transformObj((file, encoding, callback) => {
70
70
  const path = file.path;
71
71
 
72
72
  // Create alias
73
- if (!options.importers && Object.keys(BalmJS.config.scripts.alias).length) {
74
- options.importers = [];
75
- for (const [key, value] of Object.entries(BalmJS.config.scripts.alias)) {
76
- options.importers.push({
73
+ if (!options.importers) {
74
+ const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter(key => /^@\w+/.test(key));
75
+ if (aliasKeys.length) {
76
+ const aliasKeyRegex = new RegExp(`^${aliasKeys.join('|')}`);
77
+ options.importers = [{
77
78
  findFileUrl(url) {
78
- if (!url.startsWith(key)) return null;
79
- const newUrl = url.replace(new RegExp(`^${key}`), value);
80
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${url} -> ${newUrl}`);
81
- return pathToFileURL(newUrl);
79
+ let file = url;
80
+ const result = url.match(aliasKeyRegex);
81
+ const key = result ? result[0] : null;
82
+ if (key) {
83
+ file = url.replace(aliasKeyRegex, BalmJS.config.scripts.alias[key]);
84
+ BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${url} -> ${file}`);
85
+ }
86
+ return pathToFileURL(file);
82
87
  }
83
- });
88
+ }];
84
89
  }
85
90
  }
86
91
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "4.23.0",
3
+ "version": "4.23.2",
4
4
  "description": "BalmJS compiler core",
5
5
  "keywords": [
6
6
  "balm",
@@ -121,5 +121,5 @@
121
121
  "engines": {
122
122
  "node": ">=16"
123
123
  },
124
- "gitHead": "dd622fb3dd42f96992bf73fc238ebe8e725785b4"
124
+ "gitHead": "f0776661b321ddeab4abc03c62cc3ccf336c4a06"
125
125
  }
@@ -55,19 +55,24 @@ const gulpSass = (options) => transformObj((file, encoding, callback) => {
55
55
  return callback(null, file);
56
56
  }
57
57
  const path = file.path;
58
- if (!options.importers &&
59
- Object.keys(BalmJS.config.scripts.alias).length) {
60
- options.importers = [];
61
- for (const [key, value] of Object.entries(BalmJS.config.scripts.alias)) {
62
- options.importers.push({
63
- findFileUrl(url) {
64
- if (!url.startsWith(key))
65
- return null;
66
- const newUrl = url.replace(new RegExp(`^${key}`), value);
67
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${url} -> ${newUrl}`);
68
- return pathToFileURL(newUrl);
58
+ if (!options.importers) {
59
+ const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter((key) => /^@\w+/.test(key));
60
+ if (aliasKeys.length) {
61
+ const aliasKeyRegex = new RegExp(`^${aliasKeys.join('|')}`);
62
+ options.importers = [
63
+ {
64
+ findFileUrl(url) {
65
+ let file = url;
66
+ const result = url.match(aliasKeyRegex);
67
+ const key = result ? result[0] : null;
68
+ if (key) {
69
+ file = url.replace(aliasKeyRegex, BalmJS.config.scripts.alias[key]);
70
+ BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${url} -> ${file}`);
71
+ }
72
+ return pathToFileURL(file);
73
+ }
69
74
  }
70
- });
75
+ ];
71
76
  }
72
77
  }
73
78
  try {