@plumeria/compiler 0.8.2 → 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 +18 -15
- package/dist/index.js +62 -19
- package/package.json +7 -3
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/
|
|
36
|
-
: path.join(process.cwd(), 'node_modules/rscute/dist/
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "A faster compiler for Plumeria",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -22,8 +22,12 @@
|
|
|
22
22
|
"build": "rimraf dist && tsc"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
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"
|
|
27
31
|
},
|
|
28
32
|
"publishConfig": {
|
|
29
33
|
"access": "public"
|