8000 chore: simplify adder interface by manuel3108 · Pull Request #89 · sveltejs/cli · GitHub
[go: up one dir, main page]

Skip to content

chore: simplify adder interface #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fix findRoot
  • Loading branch information
AdrianGonz97 committed Oct 11, 2024
commit 42f78821a8d127cbde9132dfcf76603635a678f4
26 changes: 17 additions & 9 deletions packages/cli/commands/add/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function createEmptyWorkspace<Args extends OptionDefinition>() {

export function createWorkspace<Args extends OptionDefinition>(cwd: string): Workspace<Args> {
const workspace = createEmptyWorkspace<Args>();
workspace.cwd = cwd;
workspace.cwd = path.resolve(cwd);

let usesTypescript = fs.existsSync(path.join(cwd, commonFilePaths.viteConfigTS));

Expand All @@ -36,8 +36,14 @@ export function createWorkspace<Args extends OptionDefinition>(cwd: string): Wor
let directory = workspace.cwd;
const root = findRoot(workspace.cwd);
while (directory && directory !== root) {
const { data: packageJson } = getPackageJson(workspace.cwd);
dependencies = { ...packageJson.devDependencies, ...packageJson.dependencies, ...dependencies };
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
const { data: packageJson } = getPackageJson(directory);
dependencies = {
...packageJson.devDependencies,
...packageJson.dependencies,
...dependencies
};
}
directory = path.dirname(directory);
}
// removes the version ranges (e.g. `^` is removed from: `^9.0.0`)
Expand All @@ -58,12 +64,14 @@ function findRoot(cwd: string): string {
const { root } = path.parse(cwd);
let directory = cwd;
while (directory && directory !== root) {
if (fs.existsSync(path.join(directory, 'pnpm-workspace.yaml'))) {
return directory;
}
const { data } = getPackageJson(directory);
if (data.workspaces) {
return directory;
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
if (fs.existsSync(path.join(directory, 'pnpm-workspace.yaml'))) {
return directory;
}
const { data } = getPackageJson(directory);
if (data.workspaces) {
return directory;
}
}
directory = path.dirname(directory);
}
Expand Down
0