@plumeria/turbopack-loader 16.5.0 → 17.0.0

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,3 +1,8 @@
1
+ export interface LoaderOptions {
2
+ include?: string[];
3
+ exclude?: string[];
4
+ styleProp?: string;
5
+ }
1
6
  interface LoaderContext {
2
7
  resourcePath: string;
3
8
  context: string;
@@ -5,6 +10,8 @@ interface LoaderContext {
5
10
  async: () => (err: Error | null, content?: string) => void;
6
11
  addDependency: (path: string) => void;
7
12
  clearDependencies: () => void;
13
+ getOptions?: () => LoaderOptions | undefined;
14
+ query?: LoaderOptions | string;
8
15
  }
9
16
  export default function loader(this: LoaderContext, source: string): Promise<void>;
10
17
  export {};
package/dist/index.js CHANGED
@@ -39,10 +39,52 @@ const fs = __importStar(require("fs"));
39
39
  const path = __importStar(require("path"));
40
40
  const zss_engine_1 = require("zss-engine");
41
41
  const utils_1 = require("@plumeria/utils");
42
+ const compiler_1 = require("@plumeria/compiler");
42
43
  const split_css_rules_1 = require("./split-css-rules");
43
44
  const file_lock_1 = require("./file-lock");
45
+ const GENERATED_MARKER = '/* plumeria: generated */';
46
+ const DEFAULT_INCLUDE = ['**/*.{js,jsx,ts,tsx}'];
47
+ const DEFAULT_EXCLUDE = ['**/node_modules/**', '**/dist/**', '**/.next/**'];
48
+ let productionCss = null;
49
+ async function generateProductionCss(virtualFilePath, options) {
50
+ const lockDir = virtualFilePath + '.lock';
51
+ await (0, file_lock_1.acquireLock)(lockDir);
52
+ try {
53
+ let current = '';
54
+ try {
55
+ current = fs.readFileSync(virtualFilePath, 'utf-8');
56
+ }
57
+ catch (e) {
58
+ }
59
+ if (current.startsWith(GENERATED_MARKER))
60
+ return;
61
+ const css = (0, compiler_1.compileCSS)({
62
+ include: options.include ?? DEFAULT_INCLUDE,
63
+ exclude: options.exclude ?? DEFAULT_EXCLUDE,
64
+ cwd: process.cwd(),
65
+ styleProp: options.styleProp ?? utils_1.DEFAULT_STYLE_PROP,
66
+ });
67
+ const optimized = await (0, utils_1.optimizer)(css);
68
+ const tempPath = `${virtualFilePath}.${process.pid}.tmp`;
69
+ fs.writeFileSync(tempPath, `${GENERATED_MARKER}\n${optimized}`, 'utf-8');
70
+ fs.renameSync(tempPath, virtualFilePath);
71
+ }
72
+ finally {
73
+ (0, file_lock_1.releaseLockSync)(lockDir);
74
+ }
75
+ }
76
+ const ensureProductionCss = (virtualFilePath, options) => {
77
+ if (!productionCss) {
78
+ productionCss = generateProductionCss(virtualFilePath, options);
79
+ }
80
+ return productionCss;
81
+ };
44
82
  async function loader(source) {
45
83
  const callback = this.async();
84
+ const loaderOptions = this.getOptions?.() ??
85
+ (typeof this.query === 'object' ? this.query : undefined) ??
86
+ {};
87
+ const styleProp = loaderOptions.styleProp ?? utils_1.DEFAULT_STYLE_PROP;
46
88
  const resourcePath = this.resourcePath;
47
89
  const isProduction = process.env.NODE_ENV === 'production';
48
90
  const VIRTUAL_FILE_PATH = path.resolve(__dirname, '..', 'zero-virtual.css');
@@ -1420,7 +1462,7 @@ async function loader(source) {
1420
1462
  if (node.name.type !== 'Identifier')
1421
1463
  return;
1422
1464
  const attrName = node.name.value;
1423
- if (attrName !== 'styleName') {
1465
+ if (attrName !== styleProp) {
1424
1466
  let parentTagName = '';
1425
1467
  for (const [, val] of jsxOpeningElementMap) {
1426
1468
  const found = val.attributes
@@ -1757,8 +1799,9 @@ async function loader(source) {
1757
1799
  relativeImportPath = './' + relativeImportPath;
1758
1800
  }
1759
1801
  const postfix = `\nimport "${relativeImportPath}";`;
1760
- if (process.env.NODE_ENV === 'production') {
1761
- return callback(null, transformedSource);
1802
+ if (isProduction) {
1803
+ await ensureProductionCss(VIRTUAL_FILE_PATH, loaderOptions);
1804
+ return callback(null, transformedSource + postfix);
1762
1805
  }
1763
1806
  if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
1764
1807
  const LOCK_DIR_PATH = VIRTUAL_FILE_PATH + '.lock';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "16.5.0",
3
+ "version": "17.0.0",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,8 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^16.5.0"
25
+ "@plumeria/compiler": "^17.0.0",
26
+ "@plumeria/utils": "^17.0.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@swc/core": "1.15.43",