@plumeria/webpack-plugin 4.1.3 → 4.2.1

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -21
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -21,16 +21,7 @@ function loader(source) {
21
21
  }
22
22
  this.clearDependencies();
23
23
  this.addDependency(this.resourcePath);
24
- utils_1.tables.staticTable = (0, utils_1.scanForCreateStatic)((path) => this.addDependency(path));
25
- const { keyframesHashTableLocal, keyframesObjectTableLocal } = (0, utils_1.scanForKeyframes)((path) => this.addDependency(path));
26
- utils_1.tables.keyframesHashTable = keyframesHashTableLocal;
27
- utils_1.tables.keyframesObjectTable = keyframesObjectTableLocal;
28
- const { viewTransitionHashTableLocal, viewTransitionObjectTableLocal } = (0, utils_1.scanForViewTransition)((path) => this.addDependency(path));
29
- utils_1.tables.viewTransitionHashTable = viewTransitionHashTableLocal;
30
- utils_1.tables.viewTransitionObjectTable = viewTransitionObjectTableLocal;
31
- const { themeTableLocal, createThemeObjectTableLocal } = (0, utils_1.scanForCreateTheme)((path) => this.addDependency(path));
32
- utils_1.tables.themeTable = themeTableLocal;
33
- utils_1.tables.createThemeObjectTable = createThemeObjectTableLocal;
24
+ (0, utils_1.scanAll)((path) => this.addDependency(path));
34
25
  const extractedSheets = [];
35
26
  const fileStyles = {};
36
27
  const ast = (0, core_1.parseSync)(source, {
@@ -39,7 +30,41 @@ function loader(source) {
39
30
  target: 'es2022',
40
31
  });
41
32
  const localConsts = (0, utils_1.collectLocalConsts)(ast);
42
- Object.assign(utils_1.tables.staticTable, localConsts);
33
+ const resourcePath = this.resourcePath;
34
+ const importMap = {};
35
+ (0, utils_1.traverse)(ast, {
36
+ ImportDeclaration({ node }) {
37
+ const sourcePath = node.source.value;
38
+ const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
39
+ if (actualPath && fs_1.default.existsSync(actualPath)) {
40
+ node.specifiers.forEach((specifier) => {
41
+ if (specifier.type === 'ImportSpecifier') {
42
+ const importedName = specifier.imported
43
+ ? specifier.imported.value
44
+ : specifier.local.value;
45
+ const localName = specifier.local.value;
46
+ const uniqueKey = `${actualPath}-${importedName}`;
47
+ if (utils_1.tables.staticTable[uniqueKey]) {
48
+ importMap[localName] = utils_1.tables.staticTable[uniqueKey];
49
+ }
50
+ if (utils_1.tables.keyframesHashTable[uniqueKey]) {
51
+ importMap[localName] = utils_1.tables.keyframesHashTable[uniqueKey];
52
+ }
53
+ if (utils_1.tables.viewTransitionHashTable[uniqueKey]) {
54
+ importMap[localName] = utils_1.tables.viewTransitionHashTable[uniqueKey];
55
+ }
56
+ if (utils_1.tables.themeTable[uniqueKey]) {
57
+ importMap[localName] = utils_1.tables.themeTable[uniqueKey];
58
+ }
59
+ }
60
+ });
61
+ }
62
+ },
63
+ });
64
+ const mergedStaticTable = Object.assign(Object.create(utils_1.tables.staticTable), localConsts, importMap);
65
+ const mergedKeyframesTable = Object.assign(Object.create(utils_1.tables.keyframesHashTable), importMap);
66
+ const mergedViewTransitionTable = Object.assign(Object.create(utils_1.tables.viewTransitionHashTable), importMap);
67
+ const mergedThemeTable = Object.assign(Object.create(utils_1.tables.themeTable), importMap);
43
68
  const isTSFile = this.resourcePath.endsWith('.ts') && !this.resourcePath.endsWith('.tsx');
44
69
  const localCreateStyles = {};
45
70
  const replacements = [];
@@ -57,7 +82,7 @@ function loader(source) {
57
82
  const propName = node.init.callee.property.value;
58
83
  if (propName === 'create' &&
59
84
  utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
60
- const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
85
+ const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
61
86
  if (obj) {
62
87
  const hashMap = {};
63
88
  Object.entries(obj).forEach(([key, style]) => {
@@ -155,7 +180,7 @@ function loader(source) {
155
180
  if (propName === 'keyframes' &&
156
181
  args.length > 0 &&
157
182
  utils_1.t.isObjectExpression(args[0].expression)) {
158
- const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
183
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
159
184
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
160
185
  utils_1.tables.keyframesObjectTable[hash] = obj;
161
186
  replacements.push({
@@ -167,7 +192,7 @@ function loader(source) {
167
192
  else if (propName === 'viewTransition' &&
168
193
  args.length > 0 &&
169
194
  utils_1.t.isObjectExpression(args[0].expression)) {
170
- const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
195
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
171
196
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
172
197
  utils_1.tables.viewTransitionObjectTable[hash] = obj;
173
198
  (0, utils_1.extractOndemandStyles)(obj, extractedSheets);
@@ -181,7 +206,7 @@ function loader(source) {
181
206
  else if (propName === 'createTheme' &&
182
207
  args.length > 0 &&
183
208
  utils_1.t.isObjectExpression(args[0].expression)) {
184
- const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
209
+ const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
185
210
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
186
211
  utils_1.tables.createThemeObjectTable[hash] = obj;
187
212
  }
@@ -213,14 +238,10 @@ function loader(source) {
213
238
  return;
214
239
  const styleInfo = localCreateStyles[node.value];
215
240
  if (styleInfo && !styleInfo.hasDynamicAccess) {
216
- const fullHashMap = {};
217
- Object.entries(styleInfo.hashMap).forEach(([key, atomMap]) => {
218
- fullHashMap[key] = Object.values(atomMap).join(' ');
219
- });
220
241
  replacements.push({
221
242
  start: node.span.start - ast.span.start,
222
243
  end: node.span.end - ast.span.start,
223
- content: JSON.stringify(fullHashMap),
244
+ content: JSON.stringify(styleInfo.hashMap),
224
245
  });
225
246
  }
226
247
  },
@@ -280,7 +301,7 @@ function loader(source) {
280
301
  const merged = args.reduce((acc, arg) => {
281
302
  const expr = arg.expression;
282
303
  if (utils_1.t.isObjectExpression(expr)) {
283
- const obj = (0, utils_1.objectExpressionToObject)(expr, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
304
+ const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
284
305
  return obj ? (0, utils_1.deepMerge)(acc, obj) : acc;
285
306
  }
286
307
  else if (utils_1.t.isMemberExpression(expr) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/webpack-plugin",
3
- "version": "4.1.3",
3
+ "version": "4.2.1",
4
4
  "description": "Plumeria Webpack plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^4.1.3"
25
+ "@plumeria/utils": "^4.2.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",