@plumeria/turbopack-loader 6.0.0 → 6.0.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -34
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ if (process.env.NODE_ENV === 'production') {
14
14
  fs_1.default.writeFileSync(VIRTUAL_FILE_PATH, '/** Placeholder file */', 'utf-8');
15
15
  }
16
16
  async function loader(source) {
17
- const loaderContext = this;
18
17
  const callback = this.async();
19
18
  const isProduction = process.env.NODE_ENV === 'production';
20
19
  if (this.resourcePath.includes('node_modules') ||
@@ -23,12 +22,21 @@ async function loader(source) {
23
22
  }
24
23
  this.clearDependencies();
25
24
  this.addDependency(this.resourcePath);
26
- const scannedTables = (0, utils_1.scanAll)();
27
25
  const ast = (0, core_1.parseSync)(source, {
28
26
  syntax: 'typescript',
29
27
  tsx: true,
30
28
  target: 'es2022',
31
29
  });
30
+ for (const node of ast.body) {
31
+ if (node.type === 'ImportDeclaration') {
32
+ const sourcePath = node.source.value;
33
+ const actualPath = (0, utils_1.resolveImportPath)(sourcePath, this.resourcePath);
34
+ if (actualPath) {
35
+ this.addDependency(actualPath);
36
+ }
37
+ }
38
+ }
39
+ const scannedTables = (0, utils_1.scanAll)();
32
40
  const localConsts = (0, utils_1.collectLocalConsts)(ast);
33
41
  const resourcePath = this.resourcePath;
34
42
  const importMap = {};
@@ -37,7 +45,6 @@ async function loader(source) {
37
45
  const sourcePath = node.source.value;
38
46
  const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
39
47
  if (actualPath) {
40
- loaderContext.addDependency(actualPath);
41
48
  node.specifiers.forEach((specifier) => {
42
49
  if (specifier.type === 'ImportSpecifier') {
43
50
  const importedName = specifier.imported
@@ -118,6 +125,11 @@ async function loader(source) {
118
125
  const localCreateStyles = {};
119
126
  const replacements = [];
120
127
  const extractedSheets = [];
128
+ const addSheet = (sheet) => {
129
+ if (!extractedSheets.includes(sheet)) {
130
+ extractedSheets.push(sheet);
131
+ }
132
+ };
121
133
  const processedDecls = new Set();
122
134
  const idSpans = new Set();
123
135
  const excludedSpans = new Set();
@@ -152,7 +164,7 @@ async function loader(source) {
152
164
  if (!isProduction) {
153
165
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
154
166
  records.forEach((r) => {
155
- extractedSheets.push(r.sheet);
167
+ addSheet(r.sheet);
156
168
  });
157
169
  }
158
170
  const atomMap = {};
@@ -313,7 +325,7 @@ async function loader(source) {
313
325
  const records = (0, utils_1.getStyleRecords)(key, style, 2);
314
326
  if (!isProduction) {
315
327
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
316
- records.forEach((r) => extractedSheets.push(r.sheet));
328
+ records.forEach((r) => addSheet(r.sheet));
317
329
  }
318
330
  }
319
331
  });
@@ -347,7 +359,7 @@ async function loader(source) {
347
359
  const records = (0, utils_1.getStyleRecords)(propName, style, 2);
348
360
  if (!isProduction) {
349
361
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
350
- records.forEach((r) => extractedSheets.push(r.sheet));
362
+ records.forEach((r) => addSheet(r.sheet));
351
363
  }
352
364
  const atomMap = {};
353
365
  records.forEach((r) => (atomMap[r.key] = r.hash));
@@ -560,7 +572,7 @@ async function loader(source) {
560
572
  const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
561
573
  const records = (0, utils_1.getStyleRecords)(hash, baseStyle, 2);
562
574
  if (!isProduction) {
563
- records.forEach((r) => extractedSheets.push(r.sheet));
575
+ records.forEach((r) => addSheet(r.sheet));
564
576
  }
565
577
  const className = records.map((r) => r.hash).join(' ');
566
578
  replacements.push({
@@ -573,22 +585,10 @@ async function loader(source) {
573
585
  const table = {};
574
586
  const combinations = 1 << conditionals.length;
575
587
  for (let i = 0; i < combinations; i++) {
576
- const currentClassNames = [];
588
+ let currentStyle = { ...baseStyle };
577
589
  const seenGroups = new Set();
578
590
  let impossible = false;
579
- if (Object.keys(baseStyle).length > 0) {
580
- if (!isProduction) {
581
- (0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
582
- }
583
- const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
584
- const records = (0, utils_1.getStyleRecords)(hash, baseStyle, 2);
585
- if (!isProduction) {
586
- records.forEach((r) => extractedSheets.push(r.sheet));
587
- }
588
- currentClassNames.push(...records.map((r) => r.hash));
589
- }
590
591
  for (let j = 0; j < conditionals.length; j++) {
591
- let targetStyle = {};
592
592
  if ((i >> j) & 1) {
593
593
  if (conditionals[j].groupId !== undefined) {
594
594
  if (seenGroups.has(conditionals[j].groupId)) {
@@ -597,28 +597,28 @@ async function loader(source) {
597
597
  }
598
598
  seenGroups.add(conditionals[j].groupId);
599
599
  }
600
- targetStyle = conditionals[j].truthy;
600
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
601
601
  }
602
602
  else {
603
- targetStyle = conditionals[j].falsy;
604
- }
605
- if (Object.keys(targetStyle).length > 0) {
606
- if (!isProduction) {
607
- (0, utils_1.extractOndemandStyles)(targetStyle, extractedSheets, scannedTables);
608
- }
609
- const hash = (0, zss_engine_1.genBase36Hash)(targetStyle, 1, 8);
610
- const records = (0, utils_1.getStyleRecords)(hash, targetStyle, 2);
611
- if (!isProduction) {
612
- records.forEach((r) => extractedSheets.push(r.sheet));
613
- }
614
- currentClassNames.push(...records.map((r) => r.hash));
603
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].falsy);
615
604
  }
616
605
  }
617
606
  if (impossible) {
618
607
  table[i] = '';
619
608
  continue;
620
609
  }
621
- table[i] = currentClassNames.join(' ');
610
+ if (process.env.NODE_ENV !== 'production') {
611
+ (0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
612
+ }
613
+ const hash = (0, zss_engine_1.genBase36Hash)(currentStyle, 1, 8);
614
+ const records = (0, utils_1.getStyleRecords)(hash, currentStyle, 2);
615
+ if (process.env.NODE_ENV !== 'production') {
616
+ records.forEach((r) => extractedSheets.push(r.sheet));
617
+ }
618
+ const className = records
619
+ .map((r) => r.hash)
620
+ .join(' ');
621
+ table[i] = className;
622
622
  }
623
623
  let indexExpr = '';
624
624
  if (conditionals.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "Plumeria Turbopack-loader",
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": "^6.0.0"
25
+ "@plumeria/utils": "^6.0.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",