@plumeria/compiler 0.8.4 → 0.8.6
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/LICENSE +21 -0
- package/bin/css.mjs +1 -5
- package/dist/index.js +31 -24
- package/package.json +7 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/bin/css.mjs
CHANGED
|
@@ -20,15 +20,11 @@ try {
|
|
|
20
20
|
? findPnpmPath('@plumeria+compiler@', 'node_modules/@plumeria')
|
|
21
21
|
: path.join(process.cwd(), 'node_modules/@plumeria');
|
|
22
22
|
|
|
23
|
-
const rscutePath = isPnpm
|
|
24
|
-
? findPnpmPath('rscute@', 'node_modules/rscute/dist/execute.js')
|
|
25
|
-
: path.join(process.cwd(), 'node_modules/rscute/dist/execute.js');
|
|
26
|
-
|
|
27
23
|
const a1 = process.argv.includes('--view') ? '--view' : '';
|
|
28
24
|
const a2 = process.argv.includes('--paths') ? '--paths' : '';
|
|
29
25
|
const argv = [a1, a2].join(' ');
|
|
30
26
|
|
|
31
|
-
execSync(`node
|
|
27
|
+
execSync(`node --import jttx compiler/dist/index.js ` + argv, {
|
|
32
28
|
stdio: 'inherit',
|
|
33
29
|
cwd: plumeriaPath,
|
|
34
30
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
|
-
import
|
|
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';
|
|
6
7
|
import { transform } from 'lightningcss';
|
|
7
8
|
import { parseSync } from '@swc/core';
|
|
8
|
-
import { execute } from 'rscute';
|
|
9
9
|
import { buildGlobal, buildCreate } from '@plumeria/core/build-helper';
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const projectRoot = process.cwd().split('node_modules')[0];
|
|
11
|
+
const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
|
|
12
|
+
const coreFilePath = path.join(directPath, 'stylesheet/core.css');
|
|
13
|
+
const cleanUp = async () => {
|
|
14
|
+
if (process.env.CI && existsSync(coreFilePath)) {
|
|
15
|
+
unlinkSync(coreFilePath);
|
|
16
|
+
console.log('File deleted successfully');
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
await writeFile(coreFilePath, '', 'utf-8');
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.error('An error occurred:', err);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
async function isCSS(filePath) {
|
|
26
|
+
const code = await readFile(filePath, 'utf8');
|
|
12
27
|
const ast = parseSync(code, {
|
|
13
28
|
syntax: 'typescript',
|
|
14
29
|
tsx: filePath.endsWith('.tsx'),
|
|
@@ -40,28 +55,17 @@ function isCSS(filePath) {
|
|
|
40
55
|
visit(ast);
|
|
41
56
|
return found;
|
|
42
57
|
}
|
|
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
58
|
async function optimizeCSS() {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
59
|
+
const cssCode = await readFile(coreFilePath, 'utf8');
|
|
60
|
+
const merged = postcss([
|
|
57
61
|
combineSelectors({ removeDuplicatedProperties: true }),
|
|
58
|
-
]).process(
|
|
62
|
+
]).process(cssCode, {
|
|
59
63
|
from: coreFilePath,
|
|
60
64
|
to: coreFilePath,
|
|
61
65
|
});
|
|
62
|
-
const
|
|
66
|
+
const light = transform({
|
|
63
67
|
filename: coreFilePath,
|
|
64
|
-
code: Buffer.from(
|
|
68
|
+
code: Buffer.from(merged.css),
|
|
65
69
|
minify: true,
|
|
66
70
|
targets: {
|
|
67
71
|
safari: 16,
|
|
@@ -70,11 +74,12 @@ async function optimizeCSS() {
|
|
|
70
74
|
chrome: 110,
|
|
71
75
|
},
|
|
72
76
|
});
|
|
73
|
-
|
|
77
|
+
const optimizedCss = Buffer.from(light.code).toString('utf-8');
|
|
78
|
+
await writeFile(coreFilePath, optimizedCss, 'utf-8');
|
|
74
79
|
}
|
|
75
80
|
async function getAppRoot() {
|
|
76
81
|
const threeLevelsUp = path.join(process.cwd(), '../../../../..');
|
|
77
|
-
return
|
|
82
|
+
return existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
|
|
78
83
|
? path.join(process.cwd(), '../../../../../')
|
|
79
84
|
: path.join(process.cwd(), '../../');
|
|
80
85
|
}
|
|
@@ -84,9 +89,10 @@ async function getAppRoot() {
|
|
|
84
89
|
const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
|
|
85
90
|
ignore: ['**/node_modules/**', '**/dist/**', '**/.next/**'],
|
|
86
91
|
});
|
|
87
|
-
const
|
|
92
|
+
const results = await Promise.all(files.map((file) => isCSS(file)));
|
|
93
|
+
const styleFiles = files.filter((_, i) => results[i]);
|
|
88
94
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
89
|
-
await
|
|
95
|
+
await import(path.resolve(styleFiles[i]));
|
|
90
96
|
if (process.argv.includes('--paths'))
|
|
91
97
|
console.log(styleFiles[i]);
|
|
92
98
|
}
|
|
@@ -95,6 +101,7 @@ async function getAppRoot() {
|
|
|
95
101
|
}
|
|
96
102
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
97
103
|
await buildCreate(coreFilePath);
|
|
104
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
98
105
|
}
|
|
99
106
|
await optimizeCSS();
|
|
100
107
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "A faster compiler for Plumeria",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"bin": {
|
|
19
19
|
"css": "./bin/css.mjs"
|
|
20
20
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "rimraf dist && tsc"
|
|
23
|
-
},
|
|
24
21
|
"dependencies": {
|
|
25
22
|
"@swc/core": "^1.11.22",
|
|
26
23
|
"fast-glob": "^3.3.3",
|
|
24
|
+
"jttx": "^1.2.1",
|
|
27
25
|
"lightningcss": "^1.29.3",
|
|
28
26
|
"postcss": "^8.5.3",
|
|
29
|
-
"postcss-combine-duplicated-selectors": "^10.0.3"
|
|
30
|
-
"rscute": "^0.2.1"
|
|
27
|
+
"postcss-combine-duplicated-selectors": "^10.0.3"
|
|
31
28
|
},
|
|
32
29
|
"publishConfig": {
|
|
33
30
|
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "rimraf dist && tsc"
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|