-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-setup.js
More file actions
80 lines (69 loc) · 3.03 KB
/
Copy pathtest-setup.js
File metadata and controls
80 lines (69 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
// Simple script to test our Turbo workspace setup
console.log('🚀 Testing Turbo Workspace Setup\n');
const fs = require('fs');
const path = require('path');
// Path validation utility to prevent directory traversal
function validatePath(inputPath, basePath = __dirname) {
const normalizedPath = path.normalize(inputPath);
const resolvedPath = path.resolve(basePath, normalizedPath);
const resolvedBase = path.resolve(basePath);
// Ensure the resolved path is within the base directory
if (!resolvedPath.startsWith(resolvedBase)) {
throw new Error(`Path traversal attempt detected: ${inputPath}`);
}
return resolvedPath;
}
// Test 1: Check if packages exist
console.log('📦 Checking packages...');
const packages = ['components', 'elements', 'types', 'utils', 'stores', 'actions', 'static'];
packages.forEach(pkg => {
try {
// Validate package name to prevent malicious input
if (pkg.includes('..') || pkg.includes('/') || pkg.includes('\\')) {
console.log(` ❌ ${pkg} (invalid package name)`);
return;
}
const pkgPath = validatePath(path.join('packages', pkg));
const exists = fs.existsSync(pkgPath);
console.log(` ${exists ? '✅' : '❌'} ${pkg}`);
} catch (error) {
console.log(` ❌ ${pkg} (path validation error)`);
}
});
// Test 2: Check if product apps exist
console.log('\n🏗️ Checking product apps...');
const products = ['nucleus', 'memotron', 'gathery', 'pointron'];
products.forEach(product => {
try {
// Validate product name to prevent malicious input
if (product.includes('..') || product.includes('/') || product.includes('\\')) {
console.log(` ❌ ${product} (invalid product name)`);
return;
}
const productPath = validatePath(path.join('client', 'products', product));
const exists = fs.existsSync(productPath);
const packageJsonPath = validatePath(path.join('client', 'products', product, 'package.json'));
const hasPackageJson = fs.existsSync(packageJsonPath);
console.log(` ${exists ? '✅' : '❌'} ${product} ${hasPackageJson ? '(has package.json)' : '(missing package.json)'}`);
} catch (error) {
console.log(` ❌ ${product} (path validation error)`);
}
});
// Test 3: Check turbo configuration
console.log('\n⚙️ Checking Turbo config...');
try {
const turboPath = validatePath('turbo.json');
const rootPkgPath = validatePath('package.json');
const turboExists = fs.existsSync(turboPath);
const rootPkgExists = fs.existsSync(rootPkgPath);
console.log(` ${turboExists ? '✅' : '❌'} turbo.json`);
console.log(` ${rootPkgExists ? '✅' : '❌'} root package.json`);
} catch (error) {
console.log(' ❌ Error validating config file paths');
}
console.log('\n🎉 Setup verification complete!');
console.log('\n🔧 Next steps:');
console.log('1. Run "npm run dev" to start all apps in development mode');
console.log('2. Run "npm run build" to build all packages and apps');
console.log('3. Migrate import statements gradually from $lib/client/* to $components, $elements, etc.');