@plumeria/compiler 0.8.4 → 0.8.5

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 +29 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as path from 'path';
2
- import * as fs from 'fs';
2
+ import { unlinkSync, existsSync } from 'fs';
3
+ import { readFile, writeFile } from 'fs/promises';
3
4
  import fg from 'fast-glob';
4
5
  import postcss from 'postcss';
5
6
  import combineSelectors from 'postcss-combine-duplicated-selectors';
@@ -7,8 +8,23 @@ import { transform } from 'lightningcss';
7
8
  import { parseSync } from '@swc/core';
8
9
  import { execute } from 'rscute';
9
10
  import { buildGlobal, buildCreate } from '@plumeria/core/build-helper';
10
- function isCSS(filePath) {
11
- const code = fs.readFileSync(filePath, 'utf8');
11
+ const projectRoot = process.cwd().split('node_modules')[0];
12
+ const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
13
+ const coreFilePath = path.join(directPath, 'stylesheet/core.css');
14
+ const cleanUp = async () => {
15
+ if (process.env.CI && existsSync(coreFilePath)) {
16
+ unlinkSync(coreFilePath);
17
+ console.log('File deleted successfully');
18
+ }
19
+ try {
20
+ await writeFile(coreFilePath, '', 'utf-8');
21
+ }
22
+ catch (err) {
23
+ console.error('An error occurred:', err);
24
+ }
25
+ };
26
+ async function isCSS(filePath) {
27
+ const code = await readFile(filePath, 'utf8');
12
28
  const ast = parseSync(code, {
13
29
  syntax: 'typescript',
14
30
  tsx: filePath.endsWith('.tsx'),
@@ -40,28 +56,17 @@ function isCSS(filePath) {
40
56
  visit(ast);
41
57
  return found;
42
58
  }
43
- const projectRoot = process.cwd().split('node_modules')[0];
44
- const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
45
- const coreFilePath = path.join(directPath, 'stylesheet/core.css');
46
- const cleanUp = async () => {
47
- try {
48
- fs.writeFileSync(coreFilePath, '', 'utf-8');
49
- }
50
- catch (err) {
51
- console.error('An error occurred:', err);
52
- }
53
- };
54
59
  async function optimizeCSS() {
55
- const code = fs.readFileSync(coreFilePath, 'utf8');
56
- const mergedResult = postcss([
60
+ const cssCode = await readFile(coreFilePath, 'utf8');
61
+ const merged = postcss([
57
62
  combineSelectors({ removeDuplicatedProperties: true }),
58
- ]).process(code, {
63
+ ]).process(cssCode, {
59
64
  from: coreFilePath,
60
65
  to: coreFilePath,
61
66
  });
62
- const prefixResult = transform({
67
+ const light = transform({
63
68
  filename: coreFilePath,
64
- code: Buffer.from(mergedResult.css),
69
+ code: Buffer.from(merged.css),
65
70
  minify: true,
66
71
  targets: {
67
72
  safari: 16,
@@ -70,11 +75,12 @@ async function optimizeCSS() {
70
75
  chrome: 110,
71
76
  },
72
77
  });
73
- fs.writeFileSync(coreFilePath, prefixResult.code);
78
+ const optimizedCss = Buffer.from(light.code).toString('utf-8');
79
+ await writeFile(coreFilePath, optimizedCss, 'utf-8');
74
80
  }
75
81
  async function getAppRoot() {
76
82
  const threeLevelsUp = path.join(process.cwd(), '../../../../..');
77
- return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
83
+ return existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
78
84
  ? path.join(process.cwd(), '../../../../../')
79
85
  : path.join(process.cwd(), '../../');
80
86
  }
@@ -84,7 +90,8 @@ async function getAppRoot() {
84
90
  const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
85
91
  ignore: ['**/node_modules/**', '**/dist/**', '**/.next/**'],
86
92
  });
87
- const styleFiles = files.filter(isCSS);
93
+ const results = await Promise.all(files.map((file) => isCSS(file)));
94
+ const styleFiles = files.filter((_, i) => results[i]);
88
95
  for (let i = 0; i < styleFiles.length; i++) {
89
96
  await execute(path.resolve(styleFiles[i]));
90
97
  if (process.argv.includes('--paths'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "A faster compiler for Plumeria",
5
5
  "keywords": [
6
6
  "css",