Skip to content

Commit

Permalink
fix: update command looks at devDeps (#3276)
Browse files Browse the repository at this point in the history
Fix #3275
  • Loading branch information
alexghr committed Nov 20, 2023
1 parent caa7e10 commit 54ee38d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
43 changes: 24 additions & 19 deletions yarn-project/cli/src/update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { DependencyChanges } from './common.js';
export async function readPackageJson(projectPath: string): Promise<{
/** dependencies */
dependencies?: Record<string, string>;
/** devDependencies */
devDependencies?: Record<string, string>;
}> {
const configFilepath = resolve(join(projectPath, 'package.json'));
const pkg = JSON.parse(await readFile(configFilepath, 'utf-8'));
Expand Down Expand Up @@ -63,31 +65,34 @@ export async function updateAztecDeps(
dependencies: [],
};

if (!pkg.dependencies) {
return changes;
}

log(`Updating @aztec packages to ${aztecVersion} in ${relative(process.cwd(), changes.file)}`);
const version = aztecVersion.version;

for (const name of Object.keys(pkg.dependencies)) {
if (!name.startsWith('@aztec/')) {
continue;
}

// different release schedule
if (name === '@aztec/aztec-ui') {
for (const depType of ['dependencies', 'devDependencies'] as const) {
const dependencies = pkg[depType];
if (!dependencies) {
continue;
}

if (pkg.dependencies[name] !== version) {
changes.dependencies.push({
name,
from: pkg.dependencies[name],
to: version,
});

pkg.dependencies[name] = version;
for (const name of Object.keys(dependencies)) {
if (!name.startsWith('@aztec/')) {
continue;
}

// different release schedule
if (name === '@aztec/aztec-ui') {
continue;
}

if (dependencies[name] !== version) {
changes.dependencies.push({
name,
from: dependencies[name],
to: version,
});

dependencies[name] = version;
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion yarn-project/cli/src/update/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ async function getNpmSandboxVersion(projectPath: string, log: LogFn): Promise<Se
try {
const pkg = await readPackageJson(projectPath);
// use coerce instead of parse because it eliminates semver operators like ~ and ^
return coerce(pkg.dependencies?.[SANDBOX_PACKAGE]);
if (pkg.dependencies?.[SANDBOX_PACKAGE]) {
return coerce(pkg.dependencies[SANDBOX_PACKAGE]);
} else if (pkg.devDependencies?.[SANDBOX_PACKAGE]) {
return coerce(pkg.devDependencies[SANDBOX_PACKAGE]);
} else {
return null;
}
} catch (err) {
if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
log(`No package.json found in ${projectPath}`);
Expand Down

0 comments on commit 54ee38d

Please sign in to comment.