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

Commit bbb8345

Browse files
committed
refactor(compiler): fix
1 parent 2a48667 commit bbb8345

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

compiler/src/index.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
3-
import * as ts from 'typescript';
3+
import ts from 'typescript';
4+
import fg from 'fast-glob';
45
import { cleanUp } from './clean-up';
56
import { createBuildIn } from '../../src/core/method/create-build-in-helper.js';
67
import { setBuildIn } from '../../src/core/method/set-build-in-helper.js';
78
import { globalBuildIn } from '../../src/core/method/global-build-in-helper.js';
89
import { rootBuildIn } from '../../src/core/method/root-build-in-helper.js';
9-
const fg = require('fast-glob');
1010

11-
function isStyleClass(filePath: string): boolean {
11+
function isCSSX(filePath: string): boolean {
1212
const content = fs.readFileSync(filePath, 'utf8');
1313
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
1414

@@ -32,22 +32,18 @@ function isStyleClass(filePath: string): boolean {
3232
return isUsed;
3333
}
3434

35-
(async () => {
36-
await cleanUp();
37-
let appRoot = '';
35+
async function getAppRoot(): Promise<string> {
3836
const threeLevelsUp = path.join(process.cwd(), '../../../../..');
3937
const pnpmExists = fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'));
4038

41-
if (pnpmExists) {
42-
appRoot = path.join(process.cwd(), '../../../../../');
43-
} else {
44-
appRoot = path.join(process.cwd(), '../../');
45-
}
46-
const pattern = [path.join(appRoot, '**/*.{ts,tsx}')];
47-
const files = (await fg(pattern)) as string[];
48-
const styleFiles = files.filter(file => {
49-
return isStyleClass(file);
50-
});
39+
return pnpmExists ? path.join(process.cwd(), '../../../../../') : path.join(process.cwd(), '../../');
40+
}
41+
42+
(async () => {
43+
await cleanUp();
44+
const appRoot = await getAppRoot();
45+
const files = await fg([path.join(appRoot, '**/*.{ts,tsx}')]);
46+
const styleFiles = files.filter(isCSSX);
5147
console.log('\n💬 The following CSS caches were accepted:\n');
5248
for (const file of styleFiles) {
5349
const filePath = path.resolve(file);

0 commit comments

Comments
 (0)