@plumeria/webpack-plugin 0.15.1 → 0.15.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/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { Compiler } from 'webpack';
2
+ import { CSSObject } from './types';
2
3
  export declare class PlumeriaPlugin {
3
4
  private outputFileName;
4
5
  private stylesByFile;
5
6
  private outFile;
6
7
  constructor(outputFileName?: string);
7
8
  apply(compiler: Compiler): void;
8
- registerFileStyles(filePath: string, styles: Partial<any>): void;
9
+ registerFileStyles(filePath: string, styles: CSSObject): void;
9
10
  private generateOrderedCSS;
10
11
  private writeCSS;
11
12
  }
package/dist/index.js CHANGED
@@ -16,8 +16,11 @@ class PlumeriaPlugin {
16
16
  }
17
17
  apply(compiler) {
18
18
  this.outFile = path_1.default.resolve(__dirname, '..', this.outputFileName);
19
- compiler.hooks.compile.tap(PLUGIN_NAME, () => {
20
- this.stylesByFile.clear();
19
+ compiler.hooks.invalid.tap(PLUGIN_NAME, (filename) => {
20
+ if (filename) {
21
+ const absPath = path_1.default.resolve(filename);
22
+ this.stylesByFile.delete(absPath);
23
+ }
21
24
  });
22
25
  compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
23
26
  nmf.hooks.createModule.tap(PLUGIN_NAME, (createData) => {
@@ -30,7 +33,8 @@ class PlumeriaPlugin {
30
33
  });
31
34
  }
32
35
  registerFileStyles(filePath, styles) {
33
- const prev = this.stylesByFile.get(filePath) || {
36
+ const absPath = path_1.default.resolve(filePath);
37
+ const prev = this.stylesByFile.get(absPath) || {
34
38
  filePath,
35
39
  globalStyles: '',
36
40
  keyframeStyles: '',
@@ -38,7 +42,7 @@ class PlumeriaPlugin {
38
42
  themeStyles: '',
39
43
  baseStyles: '',
40
44
  };
41
- this.stylesByFile.set(filePath, { ...prev, ...styles });
45
+ this.stylesByFile.set(absPath, { ...prev, ...styles });
42
46
  this.writeCSS();
43
47
  }
44
48
  generateOrderedCSS() {
@@ -49,15 +53,15 @@ class PlumeriaPlugin {
49
53
  const themeStylesSet = new Set();
50
54
  const baseStylesSet = new Set();
51
55
  for (const s of allStyles) {
52
- if (s.globalStyles)
56
+ if (s.globalStyles.trim().length > 0)
53
57
  globalStylesSet.add(s.globalStyles);
54
- if (s.keyframeStyles)
58
+ if (s.keyframeStyles.trim().length > 0)
55
59
  keyframeStylesSet.add(s.keyframeStyles);
56
- if (s.varStyles)
60
+ if (s.varStyles.trim().length > 0)
57
61
  varStylesSet.add(s.varStyles);
58
- if (s.themeStyles)
62
+ if (s.themeStyles.trim().length > 0)
59
63
  themeStylesSet.add(s.themeStyles);
60
- if (s.baseStyles)
64
+ if (s.baseStyles.trim().length > 0)
61
65
  baseStylesSet.add(s.baseStyles);
62
66
  }
63
67
  return [
@@ -72,10 +76,8 @@ class PlumeriaPlugin {
72
76
  }
73
77
  writeCSS() {
74
78
  const css = this.generateOrderedCSS();
75
- if (css.trim().length > 0) {
76
- fs_1.default.mkdirSync(path_1.default.dirname(this.outFile), { recursive: true });
77
- fs_1.default.writeFileSync(this.outFile, css, 'utf-8');
78
- }
79
+ fs_1.default.mkdirSync(path_1.default.dirname(this.outFile), { recursive: true });
80
+ fs_1.default.writeFileSync(this.outFile, css, 'utf-8');
79
81
  }
80
82
  }
81
83
  exports.PlumeriaPlugin = PlumeriaPlugin;
@@ -343,12 +343,10 @@ function scanForDefineConsts() {
343
343
  for (const decl of declarations) {
344
344
  if (t.isVariableDeclarator(decl) &&
345
345
  t.isIdentifier(decl.id) &&
346
- decl.init &&
347
346
  t.isCallExpression(decl.init) &&
348
347
  t.isMemberExpression(decl.init.callee) &&
349
348
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
350
349
  t.isIdentifier(decl.init.callee.property, { name: 'defineConsts' }) &&
351
- decl.init.arguments.length === 1 &&
352
350
  t.isObjectExpression(decl.init.arguments[0])) {
353
351
  const varName = decl.id.name;
354
352
  const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, variableTable, themeTable);
@@ -389,12 +387,10 @@ function scanForKeyframes() {
389
387
  for (const decl of declarations) {
390
388
  if (t.isVariableDeclarator(decl) &&
391
389
  t.isIdentifier(decl.id) &&
392
- decl.init &&
393
390
  t.isCallExpression(decl.init) &&
394
391
  t.isMemberExpression(decl.init.callee) &&
395
392
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
396
393
  t.isIdentifier(decl.init.callee.property, { name: 'keyframes' }) &&
397
- decl.init.arguments.length === 1 &&
398
394
  t.isObjectExpression(decl.init.arguments[0])) {
399
395
  const varName = decl.id.name;
400
396
  const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, variableTable, themeTable);
@@ -440,12 +436,10 @@ function scanForDefineVars() {
440
436
  for (const decl of declarations) {
441
437
  if (t.isVariableDeclarator(decl) &&
442
438
  t.isIdentifier(decl.id) &&
443
- decl.init &&
444
439
  t.isCallExpression(decl.init) &&
445
440
  t.isMemberExpression(decl.init.callee) &&
446
441
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
447
442
  t.isIdentifier(decl.init.callee.property, { name: 'defineVars' }) &&
448
- decl.init.arguments.length === 1 &&
449
443
  t.isObjectExpression(decl.init.arguments[0])) {
450
444
  const varName = decl.id.name;
451
445
  const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, variableTableLocal, themeTable);
@@ -487,12 +481,10 @@ function scanForDefineTheme() {
487
481
  for (const decl of declarations) {
488
482
  if (t.isVariableDeclarator(decl) &&
489
483
  t.isIdentifier(decl.id) &&
490
- decl.init &&
491
484
  t.isCallExpression(decl.init) &&
492
485
  t.isMemberExpression(decl.init.callee) &&
493
486
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
494
487
  t.isIdentifier(decl.init.callee.property, { name: 'defineTheme' }) &&
495
- decl.init.arguments.length === 1 &&
496
488
  t.isObjectExpression(decl.init.arguments[0])) {
497
489
  const varName = decl.id.name;
498
490
  const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, variableTable, themeTableLocal);
@@ -514,7 +506,6 @@ function isCSSDefineFile(filePath, target) {
514
506
  sourceType: 'module',
515
507
  presets: [
516
508
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
517
- '@babel/preset-react',
518
509
  ],
519
510
  });
520
511
  }
@@ -541,12 +532,9 @@ function isCSSDefineFile(filePath, target) {
541
532
  return found;
542
533
  }
543
534
  function loader(source) {
544
- const callback = this.async();
535
+ this.clearDependencies();
545
536
  this.addDependency(this.resourcePath);
546
- const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
547
- for (const file of files) {
548
- this.addDependency(file);
549
- }
537
+ const callback = this.async();
550
538
  constTable = scanForDefineConsts.call(this);
551
539
  const { keyframesHashTableLocal, keyframesObjectTableLocal } = scanForKeyframes.call(this);
552
540
  keyframesHashTable = keyframesHashTableLocal;
@@ -565,7 +553,6 @@ function loader(source) {
565
553
  sourceType: 'module',
566
554
  presets: [
567
555
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
568
- '@babel/preset-react',
569
556
  ],
570
557
  });
571
558
  }
@@ -651,14 +638,16 @@ function loader(source) {
651
638
  const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
652
639
  const postfix = `\nimport ${virtualCssRequest};`;
653
640
  const pluginInstance = this._compiler?.options?.plugins.find((p) => p?.constructor?.name === 'PlumeriaPlugin');
641
+ const fileKey = this.resourcePath;
654
642
  if (pluginInstance) {
655
- if (!pluginInstance.__plumeriaRegistered) {
656
- pluginInstance.__plumeriaRegistered = new Set();
643
+ if (!pluginInstance?.__plumeriaRegistered) {
644
+ pluginInstance.__plumeriaRegistered = new Map();
657
645
  }
658
646
  const cache = pluginInstance.__plumeriaRegistered;
659
- if (!cache.has(virtualCssRequest)) {
660
- cache.add(virtualCssRequest);
661
- pluginInstance?.registerFileStyles(virtualCssRequest, fileStyles);
647
+ const previousRequest = cache.get(fileKey);
648
+ if (previousRequest !== virtualCssRequest) {
649
+ cache.set(fileKey, virtualCssRequest);
650
+ pluginInstance.registerFileStyles(fileKey, fileStyles);
662
651
  }
663
652
  }
664
653
  if (callback)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/webpack-plugin",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Plumeria Webpack plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,6 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "@babel/core": "^7.28.0",
20
- "@babel/preset-react": "^7.27.1",
21
20
  "@babel/preset-typescript": "^7.27.1",
22
21
  "@babel/types": "^7.28.2"
23
22
  },