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

Commit 9f79ab9

Browse files
committed
fix(*): removed find-project-root func it was freaky
1 parent 1876b8f commit 9f79ab9

File tree

5 files changed

+31
-117
lines changed

5 files changed

+31
-117
lines changed

bin/typedcssx.mjs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
#!/usr/bin/env node
22

3-
import { findProjectRoot } from '../lib/find-project-root.mjs';
43
import { execSync } from 'child_process';
54
import { fileURLToPath } from 'url';
65
import { join, dirname } from 'path';
76

87
const __filename = fileURLToPath(import.meta.url);
98
const __dirname = dirname(__filename);
109

11-
(async () => {
12-
if (process.argv.includes('--compile')) {
13-
try {
14-
const packageRoot = await findProjectRoot(__dirname);
15-
if (!packageRoot) {
16-
throw new Error('Could not find Next.js project root');
17-
}
10+
if (process.argv.includes('--compile')) {
11+
try {
12+
console.log('Running TypeScript compiler...');
13+
execSync('npm run compiler', {
14+
stdio: 'inherit',
15+
cwd: join(__dirname, '../../typedcssx'),
16+
});
1817

19-
console.log('Running TypeScript compiler...');
20-
execSync('npx tsc --noEmit compiler/src/index.ts', {
21-
stdio: 'inherit',
22-
cwd: join(packageRoot, 'node_modules/typedcssx'),
23-
});
24-
25-
execSync('npx tsx compiler/src/index.ts', {
26-
stdio: 'inherit',
27-
cwd: join(packageRoot, 'node_modules/typedcssx'),
28-
});
29-
30-
console.log('Compilation completed successfully.');
31-
} catch (error) {
32-
console.error('Compilation failed:', error.message);
33-
process.exit(1);
34-
}
35-
} else {
36-
console.log('Usage: typedcssx --compile');
18+
console.log('Compilation completed successfully.');
19+
} catch (error) {
20+
console.error('Compilation failed:', error.message);
21+
process.exit(1);
3722
}
38-
})();
23+
} else {
24+
console.log('Usage: typedcssx --compile');
25+
}

compiler/src/clean-up.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1-
import { findProjectRoot } from '../../lib/find-project-root.mjs';
2-
import { existsSync, writeFileSync } from 'fs';
1+
import { writeFileSync } from 'fs';
32
import { join } from 'path';
43

54
export const cleanUp = async () => {
6-
const projectRoot = await findProjectRoot(__dirname);
7-
8-
if (!projectRoot) {
9-
console.error('Next.js project root not found');
10-
return;
11-
}
12-
13-
const srcDir = join(projectRoot, 'src');
14-
let stylesDir: string;
15-
16-
if (existsSync(srcDir)) {
17-
stylesDir = join(srcDir, 'styles');
18-
} else {
19-
stylesDir = join(projectRoot, 'styles');
20-
}
21-
225
const styleFilePath = join(__dirname, '../../src/core/styles/style.module.css');
23-
const globalFilePath = join(stylesDir, 'typedcssx-global.css');
6+
const globalFilePath = join(__dirname, '../../src/core/styles/style.module.css');
247

258
try {
269
writeFileSync(styleFilePath, '/*______________________________*/', 'utf-8');
2710
console.log('...💫(reseted module css)');
28-
if (existsSync(stylesDir)) {
29-
writeFileSync(globalFilePath, '/*______________________________*/', 'utf-8');
30-
}
11+
writeFileSync(globalFilePath, '/*______________________________*/', 'utf-8');
3112
console.log('...💫(reseted global css)');
3213
} catch (err) {
3314
console.error('An error occurred:', err);

lib/find-project-root.d.mts

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/find-project-root.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/_internal/utils/build-in.ts

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
11
'use server';
22

3-
import { readFileSync, appendFileSync, mkdirSync, existsSync } from 'fs';
3+
import { readFileSync, appendFileSync, existsSync } from 'fs';
44
import { isServer } from './helper';
5-
import { join, dirname } from 'path';
6-
import * as fs from 'fs';
7-
8-
// Those affected by builds that exist in dist
9-
// Functions required on the outside and inside
10-
async function findProjectRoot(startPath: string): Promise<string | null> {
11-
if (!isServer) return null;
12-
let currentPath = startPath;
13-
while (currentPath !== '/') {
14-
const packageJsonPath = join(currentPath, 'package.json');
15-
const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lockb'].some(file => fs.existsSync(join(currentPath, file)));
16-
if (fs.existsSync(packageJsonPath) && lockFiles) {
17-
return currentPath;
18-
}
19-
currentPath = dirname(currentPath);
20-
}
21-
return null;
22-
}
5+
import { join } from 'path';
236

247
export const buildIn = async (styleSheet: string, global?: string): Promise<void> => {
25-
const projectRoot = await findProjectRoot(__dirname);
26-
27-
if (!projectRoot) {
28-
console.error('Next.js project root not found');
29-
return;
30-
}
31-
32-
const srcDir = join(projectRoot, 'src');
33-
let stylesDir: string;
34-
35-
if (existsSync(srcDir)) {
36-
stylesDir = join(srcDir, 'styles');
37-
} else {
38-
stylesDir = join(projectRoot, 'styles');
39-
}
40-
418
const styleFilePath = join(__dirname, '../../core/styles/style.module.css');
42-
const globalFilePath = join(stylesDir, 'typedcssx-global.css');
9+
const globalFilePath = join(__dirname, '../../core/styles/global.css');
4310

4411
const filePath = global === '--global' ? globalFilePath : styleFilePath;
4512
const message = global === '--global' ? ' ✅ Generating global static css \n' : ' ✅ Generating module static css \n';
4613

47-
if (!existsSync(stylesDir)) {
48-
mkdirSync(stylesDir);
49-
}
50-
51-
if (isServer) {
52-
try {
53-
if (existsSync(filePath)) {
54-
const cssData = readFileSync(filePath, 'utf-8');
55-
if (!cssData.includes(styleSheet)) {
56-
appendFileSync(filePath, styleSheet, 'utf-8');
57-
console.log(message + styleSheet);
58-
}
59-
} else {
14+
if (!isServer) return;
15+
try {
16+
if (existsSync(filePath)) {
17+
const cssData = readFileSync(filePath, 'utf-8');
18+
if (!cssData.includes(styleSheet)) {
6019
appendFileSync(filePath, styleSheet, 'utf-8');
6120
console.log(message + styleSheet);
6221
}
63-
} catch (error) {
64-
console.error('Error writing to file:', error);
65-
console.error('Stack trace:', error);
22+
} else {
23+
appendFileSync(filePath, styleSheet, 'utf-8');
24+
console.log(message + styleSheet);
6625
}
26+
} catch (error) {
27+
console.error('Error writing to file:', error);
28+
console.error('Stack trace:', error);
6729
}
6830
};

0 commit comments

Comments
 (0)