@plumeria/compiler 0.6.5 → 0.7.3

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
@@ -1,12 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { execSync } from 'child_process';
3
+ import fs from 'fs';
4
4
  import path from 'path';
5
+ import { execSync } from 'child_process';
5
6
  import { styleText } from 'util';
6
- import fs from 'fs';
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
+ }
7
18
 
8
19
  try {
9
- process.env.PATH = `${path.resolve(process.cwd(), 'node_modules', '.bin')}:${process.env.PATH}`;
10
20
  const checkMark = styleText('greenBright', '✓');
11
21
  const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
12
22
  const typecheck = process.argv.includes('--type-check');
@@ -18,11 +28,15 @@ try {
18
28
  });
19
29
 
20
30
  const plumeriaPath = isPnpm
21
- ? findPnpmPlumeriaPath()
31
+ ? findPnpmPath('@plumeria+compiler@', 'node_modules/@plumeria')
22
32
  : path.join(process.cwd(), 'node_modules/@plumeria');
23
33
 
34
+ const rscutePath = isPnpm
35
+ ? findPnpmPath('rscute@', 'node_modules/rscute/dist/execute.js')
36
+ : path.join(process.cwd(), 'node_modules/rscute/dist/execute.js');
37
+
24
38
  const argv = process.argv.includes('--log') ? ' --log' : '';
25
- execSync('rscute compiler/src/index.ts' + argv, {
39
+ execSync(`node ${rscutePath} compiler/dist/index.js` + argv, {
26
40
  stdio: 'inherit',
27
41
  cwd: plumeriaPath,
28
42
  });
@@ -33,16 +47,3 @@ try {
33
47
  console.error('Compilation failed:', error.message);
34
48
  process.exit(1);
35
49
  }
36
-
37
- function findPnpmPlumeriaPath() {
38
- const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
39
- const plumeriaDir = fs
40
- .readdirSync(pnpmPath)
41
- .find((dir) => dir.startsWith('@plumeria+compiler@'));
42
-
43
- if (!plumeriaDir) {
44
- throw new Error('Could not find @plumeria package in pnpm directory');
45
- }
46
-
47
- return path.join(pnpmPath, plumeriaDir, 'node_modules/@plumeria');
48
- }
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import { execute } from 'rscute';
4
+ import ts from 'typescript';
5
+ import fg from 'fast-glob';
6
+ import { buildCreate } from '@plumeria/core/dist/method/create-build-helper';
7
+ import { buildGlobal } from '@plumeria/core/dist/method/global-build-helper';
8
+ const cleanUp = async () => {
9
+ const projectRoot = process.cwd().split('node_modules')[0];
10
+ const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
11
+ const coreFilePath = path.join(directPath, 'stylesheet/core.css');
12
+ try {
13
+ fs.writeFileSync(coreFilePath, '', 'utf-8');
14
+ }
15
+ catch (err) {
16
+ console.error('An error occurred:', err);
17
+ }
18
+ };
19
+ function isCSS(filePath) {
20
+ const content = fs.readFileSync(filePath, 'utf8');
21
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
22
+ const checker = (node) => {
23
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
24
+ const expressionText = node.expression.getText(sourceFile);
25
+ const methodName = node.name.getText(sourceFile);
26
+ return (expressionText === 'css' && ['create', 'global'].includes(methodName));
27
+ }
28
+ return ts.forEachChild(node, checker) || false;
29
+ };
30
+ return checker(sourceFile);
31
+ }
32
+ async function getAppRoot() {
33
+ const threeLevelsUp = path.join(process.cwd(), '../../../../..');
34
+ return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
35
+ ? path.join(process.cwd(), '../../../../../')
36
+ : path.join(process.cwd(), '../../');
37
+ }
38
+ (async () => {
39
+ await cleanUp();
40
+ const appRoot = await getAppRoot();
41
+ const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
42
+ ignore: [
43
+ '**/main.{js,ts}/**',
44
+ '**/dist/**',
45
+ '**/.next/**',
46
+ '**/node_modules/**',
47
+ ],
48
+ });
49
+ const styleFiles = files.filter(isCSS);
50
+ for (let i = 0; i < styleFiles.length; i++) {
51
+ await execute(path.resolve(styleFiles[i]));
52
+ }
53
+ for (let i = 0; i < styleFiles.length; i++) {
54
+ await buildGlobal();
55
+ }
56
+ for (let i = 0; i < styleFiles.length; i++) {
57
+ await buildCreate();
58
+ }
59
+ })();
package/package.json CHANGED
@@ -1,33 +1,31 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.6.5",
4
- "description": "Compiler for Plumeria that build and optimizes",
3
+ "version": "0.7.3",
4
+ "description": "A faster compiler for Plumeria",
5
5
  "keywords": [
6
- "react",
7
6
  "css",
8
7
  "css-in-js",
9
8
  "plumeria",
10
- "styling"
9
+ "rscute",
10
+ "compiler"
11
11
  ],
12
12
  "repository": "github:zss-in-js/plumeria",
13
13
  "license": "MIT",
14
14
  "files": [
15
- "bin",
16
- "src"
15
+ "bin/",
16
+ "dist/"
17
17
  ],
18
18
  "bin": {
19
19
  "css": "./bin/css.mjs"
20
20
  },
21
+ "scripts": {
22
+ "build": "rimraf dist && tsc"
23
+ },
21
24
  "dependencies": {
22
- "rscute": "^0.0.7",
23
25
  "fast-glob": "^3.3.3",
24
- "postcss": "^8.4.49",
25
- "postcss-combine-duplicated-selectors": "^10.0.3"
26
+ "rscute": "^0.0.14"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public"
29
- },
30
- "scripts": {
31
- "build": "echo 'Build unnecessary'"
32
30
  }
33
- }
31
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 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/src/index.ts DELETED
@@ -1,90 +0,0 @@
1
- import { fileURLToPath } from 'url';
2
- import * as path from 'path';
3
- import * as fs from 'fs';
4
- import { execute } from 'rscute';
5
- import ts from 'typescript';
6
- import fg from 'fast-glob';
7
- import { buildCreate } from '@plumeria/core/dist/method/create-build-helper';
8
- import { buildGlobal } from '@plumeria/core/dist/method/global-build-helper';
9
- import postcss from 'postcss';
10
- import combineSelectors from 'postcss-combine-duplicated-selectors';
11
-
12
- export const cleanUp = async () => {
13
- const projectRoot = process.cwd().split('node_modules')[0];
14
- const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
15
- const coreFilePath = path.join(directPath, 'stylesheet/core.css');
16
-
17
- try {
18
- fs.writeFileSync(coreFilePath, '', 'utf-8');
19
- } catch (err) {
20
- console.error('An error occurred:', err);
21
- }
22
- };
23
-
24
- function isCSS(filePath: string): boolean {
25
- const content = fs.readFileSync(filePath, 'utf8');
26
- const sourceFile = ts.createSourceFile(
27
- filePath,
28
- content,
29
- ts.ScriptTarget.Latest,
30
- true,
31
- );
32
-
33
- const checker = (node: ts.Node): boolean => {
34
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
35
- const expressionText = node.expression.getText(sourceFile);
36
- const methodName = node.name.getText(sourceFile);
37
- return (
38
- expressionText === 'css' && ['create', 'global'].includes(methodName)
39
- );
40
- }
41
- return ts.forEachChild(node, checker) || false;
42
- };
43
-
44
- return checker(sourceFile);
45
- }
46
-
47
- async function getAppRoot(): Promise<string> {
48
- const threeLevelsUp = path.join(process.cwd(), '../../../../..');
49
- return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
50
- ? path.join(process.cwd(), '../../../../../')
51
- : path.join(process.cwd(), '../../');
52
- }
53
-
54
- async function optimizeCSS() {
55
- const corePackagePath = import.meta.resolve('@plumeria/core/package.json');
56
- const corePath = path.dirname(fileURLToPath(new URL(corePackagePath)));
57
- const cssPath = path.join(corePath, 'stylesheet/core.css');
58
- const cssContent = fs.readFileSync(cssPath, 'utf8');
59
- const result = postcss([
60
- combineSelectors({ removeDuplicatedProperties: true }),
61
- ]).process(cssContent, {
62
- from: cssPath,
63
- to: cssPath,
64
- });
65
- fs.writeFileSync(cssPath, result.css);
66
- }
67
-
68
- (async () => {
69
- await cleanUp();
70
- const appRoot = await getAppRoot();
71
- const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
72
- ignore: [
73
- '**/main.{js,ts}/**',
74
- '**/dist/**',
75
- '**/.next/**',
76
- '**/node_modules/**',
77
- ],
78
- });
79
- const styleFiles = files.filter(isCSS);
80
- for (let i = 0; i < styleFiles.length; i++) {
81
- await execute(path.resolve(styleFiles[i]));
82
- }
83
- for (let i = 0; i < styleFiles.length; i++) {
84
- await buildGlobal();
85
- }
86
- for (let i = 0; i < styleFiles.length; i++) {
87
- await buildCreate();
88
- }
89
- await optimizeCSS();
90
- })();