@plumeria/compiler 3.1.0 → 4.0.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.
@@ -0,0 +1,7 @@
1
+ interface CompilerOptions {
2
+ include: string;
3
+ exclude: string[];
4
+ cwd?: string;
5
+ }
6
+ export declare function compileCSS(options: CompilerOptions): string;
7
+ export {};
package/dist/index.js CHANGED
@@ -3,14 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compileCSS = compileCSS;
6
7
  const core_1 = require("@swc/core");
7
8
  const zss_engine_1 = require("zss-engine");
8
- const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const utils_1 = require("@plumeria/utils");
11
- const optimizer_1 = require("./optimizer");
12
- async function compile(options) {
13
- const { pattern, output, cwd = process.cwd() } = options;
11
+ function compileCSS(options) {
12
+ const { include, exclude, cwd = process.cwd() } = options;
14
13
  let staticTable = null;
15
14
  let keyframesData = null;
16
15
  let viewTransitionData = null;
@@ -148,6 +147,8 @@ async function compile(options) {
148
147
  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);
149
148
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
150
149
  utils_1.tables.viewTransitionObjectTable[hash] = obj;
150
+ (0, utils_1.extractOndemandStyles)(obj, extractedSheets);
151
+ (0, utils_1.extractOndemandStyles)({ vt: `vt-${hash}` }, extractedSheets);
151
152
  }
152
153
  else if (callee.property.value === 'createTheme' &&
153
154
  args.length > 0 &&
@@ -159,40 +160,17 @@ async function compile(options) {
159
160
  }
160
161
  },
161
162
  });
162
- const uniqueSheets = [];
163
- const seen = new Set();
164
- for (let i = extractedSheets.length - 1; i >= 0; i--) {
165
- if (!seen.has(extractedSheets[i])) {
166
- seen.add(extractedSheets[i]);
167
- uniqueSheets.unshift(extractedSheets[i]);
168
- }
169
- }
170
- return uniqueSheets;
163
+ return extractedSheets;
171
164
  };
172
- const files = fs_1.default.globSync(pattern, {
165
+ const files = fs_1.default.globSync(include, {
173
166
  cwd,
174
- exclude: ['**/node_modules/**', '**/dist/**', '**/.next/**'],
167
+ exclude: exclude,
175
168
  });
176
- files.forEach((file) => {
169
+ for (const file of files) {
177
170
  const sheets = processFile(file);
178
- sheets.forEach((sheet) => {
179
- allSheets.delete(sheet);
171
+ for (const sheet of sheets) {
180
172
  allSheets.add(sheet);
181
- });
182
- });
183
- const outputPath = path_1.default.resolve(cwd, output);
184
- const css = Array.from(allSheets).join('\n');
185
- const outputDir = path_1.default.dirname(outputPath);
186
- if (!fs_1.default.existsSync(outputDir)) {
187
- fs_1.default.mkdirSync(outputDir, { recursive: true });
173
+ }
188
174
  }
189
- const optCSS = await (0, optimizer_1.optimizeCSS)(css);
190
- fs_1.default.writeFileSync(outputPath, optCSS);
191
- }
192
- async function main() {
193
- const coreFilePath = require.resolve('@plumeria/core/stylesheet.css');
194
- await compile({ pattern: '**/*.{js,jsx,ts,tsx}', output: coreFilePath });
175
+ return Array.from(allSheets).join('\n');
195
176
  }
196
- main().catch((err) => {
197
- console.error(err);
198
- });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "3.1.0",
4
- "description": "Plumeria swc based compiler",
3
+ "version": "4.0.1",
4
+ "description": "Plumeria swc based compiler for statically extracting css",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/refirst11",
@@ -15,30 +15,24 @@
15
15
  "url": "https://github.com/zss-in-js/plumeria/issues"
16
16
  },
17
17
  "sideEffects": false,
18
+ "main": "dist/index.js",
19
+ "types": "dist/index.d.ts",
18
20
  "files": [
19
- "bin/",
20
21
  "dist/"
21
22
  ],
22
- "bin": {
23
- "css": "./bin/css.js"
24
- },
25
23
  "dependencies": {
26
- "rscute": "^1.1.5",
27
- "lightningcss": "^1.30.2",
28
- "postcss": "^8.5.6",
29
- "postcss-combine-media-query": "^2.1.0",
30
- "@plumeria/utils": "^3.1.0"
24
+ "@plumeria/utils": "^4.0.1"
31
25
  },
32
26
  "devDependencies": {
33
27
  "@swc/core": "1.15.2",
34
- "zss-engine": "2.1.2",
35
- "@plumeria/core": "^3.1.0"
28
+ "zss-engine": "2.1.2"
36
29
  },
37
30
  "publishConfig": {
38
31
  "access": "public",
39
32
  "provenance": true
40
33
  },
41
34
  "scripts": {
42
- "build": "rimraf dist && tsc"
35
+ "build": "rimraf dist && pnpm cjs",
36
+ "cjs": "tsc --project tsconfig.cjs.json"
43
37
  }
44
38
  }
package/bin/css.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- const path = require('path');
3
- require('rscute/register').register();
4
- require(path.resolve(__dirname, '../dist/index.js'));
package/dist/optimizer.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.optimizeCSS = optimizeCSS;
7
- const postcss_1 = __importDefault(require("postcss"));
8
- const postcss_combine_media_query_1 = __importDefault(require("postcss-combine-media-query"));
9
- const lightningcss_1 = require("lightningcss");
10
- async function optimizeCSS(cssCode) {
11
- const merged = await (0, postcss_1.default)([(0, postcss_combine_media_query_1.default)()]).process(cssCode, {
12
- from: undefined,
13
- });
14
- const light = (0, lightningcss_1.transform)({
15
- filename: 'stylesheet.css',
16
- code: Buffer.from(merged.css),
17
- minify: process.env.NODE_ENV === 'production',
18
- targets: {
19
- safari: 16,
20
- edge: 110,
21
- firefox: 110,
22
- chrome: 110,
23
- },
24
- });
25
- return Buffer.from(light.code).toString('utf-8');
26
- }