Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/core/src/cli/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export async function detect(
}

const { packageJson } = packageManager.primaryPackageJson;

return detectFrameworkPreset(packageJson);
} catch (e) {
return ProjectType.UNDETECTED;
Expand Down
5 changes: 3 additions & 2 deletions code/core/src/common/utils/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { WriteStream } from 'node:fs';
import { createWriteStream, mkdirSync } from 'node:fs';
import { readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
import { copyFile, readFile, realpath, rm, writeFile } from 'node:fs/promises';
import os from 'node:os';
import { join } from 'node:path';

Expand Down Expand Up @@ -147,10 +147,11 @@ export const createLogStream = async (

return new Promise((resolve, reject) => {
logStream.once('open', () => {
const moveLogFile = async () => rename(temporaryLogPath, finalLogPath);
const clearLogFile = async () => writeFile(temporaryLogPath, '');
const removeLogFile = async () => rm(temporaryLogPath, { recursive: true, force: true });
const readLogFile = async () => readFile(temporaryLogPath, { encoding: 'utf8' });
// Can't use rename because it doesn't work across disks.
const moveLogFile = async () => copyFile(temporaryLogPath, finalLogPath).then(removeLogFile);
resolve({ logStream, moveLogFile, clearLogFile, removeLogFile, readLogFile });
});
logStream.once('error', reject);
Expand Down
59 changes: 21 additions & 38 deletions code/core/src/common/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,49 @@ export const getProjectRoot = () => {
return projectRoot;
}

let result;
// Allow manual override in cases where auto-detect doesn't work
if (process.env.STORYBOOK_PROJECT_ROOT) {
return process.env.STORYBOOK_PROJECT_ROOT;
}

try {
const found = findUpSync('.git', { type: 'directory' });
const found =
findUpSync('.git', { type: 'directory' }) ||
findUpSync('.svn', { type: 'directory' }) ||
findUpSync('.hg', { type: 'directory' });
if (found) {
result = join(found, '..');
projectRoot = join(found, '..');
return projectRoot;
}
} catch (e) {
//
process.stdout.write(`\nerror searching for repository root: ${e}\n`);
}

try {
const found = findUpSync('.svn', { type: 'directory' });
const found = findUpSync(LOCK_FILES, { type: 'file' });
if (found) {
result = result || join(found, '..');
projectRoot = join(found, '..');
return projectRoot;
}
} catch (e) {
//
process.stdout.write(`\nerror searching for lock file: ${e}\n`);
}

try {
const found = findUpSync('.hg', { type: 'directory' });
if (found) {
result = result || join(found, '..');
}
} catch (e) {
//
}

try {
const splitDirname = __dirname.split('node_modules');
const isSplitDirnameReachable = !relative(splitDirname[0], process.cwd()).startsWith('..');
result =
result ||
(isSplitDirnameReachable
? splitDirname.length >= 2
? splitDirname[0]
: undefined
: undefined);
} catch (e) {
//
}

try {
const found = findUpSync(LOCK_FILES, {
type: 'file',
});
if (found) {
result = result || join(found, '..');
const [basePath, rest] = __dirname.split(`${sep}node_modules${sep}`, 2);
if (
rest &&
!basePath.includes(`${sep}npm-cache${sep}`) &&
!relative(basePath, process.cwd()).startsWith('..')
) {
projectRoot = basePath;
return projectRoot;
}
} catch (e) {
//
process.stdout.write(`\nerror searching for splitDirname: ${e}\n`);
}

projectRoot = result || process.cwd();

projectRoot = process.cwd();
return projectRoot;
};

Expand Down