- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { createCache } from './cache.js';
|
|
const isRunOnBrowser = !fs.readFileSync;
|
|
const nodeModuleCache = createCache();
|
|
const nodeModulesCache = createCache();
|
|
/**
|
|
* Find package directory in node_modules
|
|
*/
|
|
function findPackageInNodeModules(dir, packageName) {
|
|
if (isRunOnBrowser)
|
|
return null;
|
|
const nodeModulesPath = path.join(dir, 'node_modules');
|
|
const packagePath = path.join(nodeModulesPath, packageName);
|
|
try {
|
|
const stats = fs.statSync(packagePath);
|
|
if (stats.isDirectory()) {
|
|
return packagePath;
|
|
}
|
|
}
|
|
catch {
|
|
// ignore if directory not found
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* Get first found package path from node_modules
|
|
*/
|
|
export function getNodeModule(packageName, startPath = 'a.js') {
|
|
if (isRunOnBrowser)
|
|
return null;
|
|
const cacheKey = `${startPath}:${packageName}`;
|
|
const cached = nodeModulesCache.get(cacheKey);
|
|
if (cached) {
|
|
return cached[0] ?? null;
|
|
}
|
|
const startDir = path.dirname(path.resolve(startPath));
|
|
let dir = startDir;
|
|
let prevDir = '';
|
|
do {
|
|
// check cache
|
|
const cachePath = nodeModuleCache.get(`${dir}:${packageName}`);
|
|
if (cachePath) {
|
|
if (cachePath !== null) {
|
|
nodeModulesCache.set(cacheKey, [cachePath]);
|
|
return cachePath;
|
|
}
|
|
}
|
|
else {
|
|
// search new
|
|
const packagePath = findPackageInNodeModules(dir, packageName);
|
|
nodeModuleCache.set(`${dir}:${packageName}`, packagePath);
|
|
if (packagePath) {
|
|
nodeModulesCache.set(cacheKey, [packagePath]);
|
|
return packagePath;
|
|
}
|
|
}
|
|
// go to parent
|
|
prevDir = dir;
|
|
dir = path.resolve(dir, '..');
|
|
} while (dir !== prevDir);
|
|
nodeModulesCache.set(cacheKey, []);
|
|
return null;
|
|
}
|