@plumeria/compiler 0.8.3 → 0.8.4

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/bin/css.mjs CHANGED
@@ -5,17 +5,6 @@ import path from 'path';
5
5
  import { execSync } from 'child_process';
6
6
  import { styleText } from 'util';
7
7
 
8
- function findPnpmPath(arg1, arg2) {
9
- const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
10
- const pnpmDir = fs.readdirSync(pnpmPath).find((dir) => dir.startsWith(arg1));
11
-
12
- if (!pnpmDir) {
13
- throw new Error(`Could not find ${arg1} package in pnpm directory`);
14
- }
15
-
16
- return path.join(pnpmPath, pnpmDir, arg2);
17
- }
18
-
19
8
  try {
20
9
  const checkMark = styleText('greenBright', '✓');
21
10
  const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
@@ -32,11 +21,14 @@ try {
32
21
  : path.join(process.cwd(), 'node_modules/@plumeria');
33
22
 
34
23
  const rscutePath = isPnpm
35
- ? findPnpmPath('rscute@', 'node_modules/rscute/dist/jit.js')
36
- : path.join(process.cwd(), 'node_modules/rscute/dist/jit.js');
24
+ ? findPnpmPath('rscute@', 'node_modules/rscute/dist/execute.js')
25
+ : path.join(process.cwd(), 'node_modules/rscute/dist/execute.js');
26
+
27
+ const a1 = process.argv.includes('--view') ? '--view' : '';
28
+ const a2 = process.argv.includes('--paths') ? '--paths' : '';
29
+ const argv = [a1, a2].join(' ');
37
30
 
38
- const argv = process.argv.includes('--log') ? ' --log' : '';
39
- execSync(`node ${rscutePath} compiler/dist/index.js` + argv, {
31
+ execSync(`node ${rscutePath} compiler/dist/index.js ` + argv, {
40
32
  stdio: 'inherit',
41
33
  cwd: plumeriaPath,
42
34
  });
@@ -47,3 +39,14 @@ try {
47
39
  console.error('Compilation failed:', error.message);
48
40
  process.exit(1);
49
41
  }
42
+
43
+ function findPnpmPath(arg1, arg2) {
44
+ const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
45
+ const pnpmDir = fs.readdirSync(pnpmPath).find((dir) => dir.startsWith(arg1));
46
+
47
+ if (!pnpmDir) {
48
+ throw new Error(`Could not find ${arg1} package in pnpm directory`);
49
+ }
50
+
51
+ return path.join(pnpmPath, pnpmDir, arg2);
52
+ }
package/dist/index.js CHANGED
@@ -1,17 +1,49 @@
1
1
  import * as path from 'path';
2
2
  import * as fs from 'fs';
3
- import ts from 'typescript';
4
3
  import fg from 'fast-glob';
4
+ import postcss from 'postcss';
5
+ import combineSelectors from 'postcss-combine-duplicated-selectors';
6
+ import { transform } from 'lightningcss';
7
+ import { parseSync } from '@swc/core';
8
+ import { execute } from 'rscute';
5
9
  import { buildGlobal, buildCreate } from '@plumeria/core/build-helper';
6
- import { JIT } from 'rscute';
10
+ function isCSS(filePath) {
11
+ const code = fs.readFileSync(filePath, 'utf8');
12
+ const ast = parseSync(code, {
13
+ syntax: 'typescript',
14
+ tsx: filePath.endsWith('.tsx'),
15
+ decorators: false,
16
+ dynamicImport: true,
17
+ });
18
+ let found = false;
19
+ function visit(node) {
20
+ if (node.type === 'MemberExpression' && node.property?.value) {
21
+ if (node.object?.type === 'Identifier' && node.object.value === 'css') {
22
+ if (node.property.value === 'create' ||
23
+ node.property.value === 'global') {
24
+ found = true;
25
+ }
26
+ }
27
+ }
28
+ for (const key in node) {
29
+ const value = node[key];
30
+ if (value && typeof value === 'object') {
31
+ if (Array.isArray(value)) {
32
+ value.forEach(visit);
33
+ }
34
+ else {
35
+ visit(value);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ visit(ast);
41
+ return found;
42
+ }
7
43
  const projectRoot = process.cwd().split('node_modules')[0];
8
44
  const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
9
45
  const coreFilePath = path.join(directPath, 'stylesheet/core.css');
10
46
  const cleanUp = async () => {
11
- if (process.env.CI && fs.existsSync(coreFilePath)) {
12
- fs.unlinkSync(coreFilePath);
13
- console.log('File deleted successfully');
14
- }
15
47
  try {
16
48
  fs.writeFileSync(coreFilePath, '', 'utf-8');
17
49
  }
@@ -19,18 +51,26 @@ const cleanUp = async () => {
19
51
  console.error('An error occurred:', err);
20
52
  }
21
53
  };
22
- function isCSS(filePath) {
23
- const content = fs.readFileSync(filePath, 'utf8');
24
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
25
- const checker = (node) => {
26
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
27
- const expressionText = node.expression.getText(sourceFile);
28
- const methodName = node.name.getText(sourceFile);
29
- return (expressionText === 'css' && ['create', 'global'].includes(methodName));
30
- }
31
- return ts.forEachChild(node, checker) || false;
32
- };
33
- return checker(sourceFile);
54
+ async function optimizeCSS() {
55
+ const code = fs.readFileSync(coreFilePath, 'utf8');
56
+ const mergedResult = postcss([
57
+ combineSelectors({ removeDuplicatedProperties: true }),
58
+ ]).process(code, {
59
+ from: coreFilePath,
60
+ to: coreFilePath,
61
+ });
62
+ const prefixResult = transform({
63
+ filename: coreFilePath,
64
+ code: Buffer.from(mergedResult.css),
65
+ minify: true,
66
+ targets: {
67
+ safari: 16,
68
+ edge: 110,
69
+ firefox: 110,
70
+ chrome: 110,
71
+ },
72
+ });
73
+ fs.writeFileSync(coreFilePath, prefixResult.code);
34
74
  }
35
75
  async function getAppRoot() {
36
76
  const threeLevelsUp = path.join(process.cwd(), '../../../../..');
@@ -46,7 +86,9 @@ async function getAppRoot() {
46
86
  });
47
87
  const styleFiles = files.filter(isCSS);
48
88
  for (let i = 0; i < styleFiles.length; i++) {
49
- await JIT(path.resolve(styleFiles[i]));
89
+ await execute(path.resolve(styleFiles[i]));
90
+ if (process.argv.includes('--paths'))
91
+ console.log(styleFiles[i]);
50
92
  }
51
93
  for (let i = 0; i < styleFiles.length; i++) {
52
94
  await buildGlobal(coreFilePath);
@@ -54,4 +96,5 @@ async function getAppRoot() {
54
96
  for (let i = 0; i < styleFiles.length; i++) {
55
97
  await buildCreate(coreFilePath);
56
98
  }
99
+ await optimizeCSS();
57
100
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "A faster compiler for Plumeria",
5
5
  "keywords": [
6
6
  "css",
@@ -18,14 +18,18 @@
18
18
  "bin": {
19
19
  "css": "./bin/css.mjs"
20
20
  },
21
+ "scripts": {
22
+ "build": "rimraf dist && tsc"
23
+ },
21
24
  "dependencies": {
22
- "fast-glob": "3.3.3",
23
- "rscute": "0.1.7"
25
+ "@swc/core": "^1.11.22",
26
+ "fast-glob": "^3.3.3",
27
+ "lightningcss": "^1.29.3",
28
+ "postcss": "^8.5.3",
29
+ "postcss-combine-duplicated-selectors": "^10.0.3",
30
+ "rscute": "^0.2.1"
24
31
  },
25
32
  "publishConfig": {
26
33
  "access": "public"
27
- },
28
- "scripts": {
29
- "build": "rimraf dist && tsc"
30
34
  }
31
- }
35
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) zss-in-js contributer
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.