Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit a927a6a

Browse files
committed
perf(compiler/index.ts): It is no longer necessary to specify css in the file extension.
1 parent bce6832 commit a927a6a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

compiler/src/index.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
3+
import * as ts from 'typescript';
34
import { cleanUp } from './clean-up';
45
import { createBuildIn } from '../../src/core/method/create-build-in-helper';
56
import { setBuildIn } from '../../src/core/method/set-build-in-helper';
67
import { globalBuildIn } from '../../src/core/method/global-build-in-helper';
78
import { rootBuildIn } from '../../src/core/method/root-build-in-helper';
8-
// eslint-disable-next-line @typescript-eslint/no-var-requires
9-
const fg = require('fast-glob');
9+
10+
function isStyleClass(filePath: string): boolean {
11+
const content = fs.readFileSync(filePath, 'utf8');
12+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
13+
14+
let isUsed = false;
15+
16+
function checkNode(node: ts.Node) {
17+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
18+
const expressionText = node.expression.getText(sourceFile);
19+
const methodName = node.name.getText(sourceFile);
20+
const methods = ['create', 'set', 'root', 'global'];
21+
if (expressionText === 'cssx' && methods.includes(methodName)) {
22+
isUsed = true;
23+
}
24+
}
25+
26+
ts.forEachChild(node, checkNode);
27+
}
28+
29+
checkNode(sourceFile);
30+
31+
return isUsed;
32+
}
1033

1134
(async () => {
1235
await cleanUp();
@@ -19,10 +42,13 @@ const fg = require('fast-glob');
1942
} else {
2043
appRoot = path.join(process.cwd(), '../../');
2144
}
22-
const csstsPattern = [path.join(appRoot, '**/*.css.ts'), path.join(appRoot, '**/*.css.tsx')];
23-
const files = await fg(csstsPattern);
45+
const csstsPattern = [path.join(appRoot, '**/*.ts'), path.join(appRoot, '**/*.tsx')];
46+
const files = fs.globSync(csstsPattern);
47+
const styleFiles = files.filter(file => {
48+
return isStyleClass(file);
49+
});
2450
console.log('\n💬 The following CSS caches were accepted:\n');
25-
for (const file of files) {
51+
for (const file of styleFiles) {
2652
const filePath = path.resolve(file);
2753
await import(filePath);
2854
createBuildIn();

0 commit comments

Comments
 (0)