Skip to content

Commit

Permalink
update script comments and logging to reflect what it does
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Jan 8, 2024
1 parent 1b626f1 commit 3ccb900
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions scripts/replace-package.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Replace a package with symlinks to a specific directory.
// Example:
// REPLACE_PACKAGE=mongodb:/home/src/node-mongodb-native node scripts/replace-package.js
// will make 'mongodb' point to '/home/src/node-mongodb-native' in the root
// directory and all lerna packages.
// REPLACE_PACKAGE=mongodb:latest node scripts/replace-package.js
// will replace the 'mongodb' dep's version with latest in the root directory
// and all packages.
'use strict';
const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');

const replacement = process.env.REPLACE_PACKAGE;
if (!replacement) {
Expand All @@ -21,15 +19,14 @@ const { from, to } = parsed.groups;
for (const dir of ['.', ...fs.readdirSync('packages').map(dir => path.join('packages', dir))]) {
const packageJson = path.join(dir, 'package.json');
if (fs.existsSync(packageJson)) {
const target = pathToFileURL(path.resolve(to)).href;
const contents = JSON.parse(fs.readFileSync(packageJson));
for (const deps of [
contents.dependencies,
contents.devDependencies,
contents.optionalDependencies
]) {
if (deps && deps[from]) {
console.info('Replacing', from, 'in', dir, 'with', target);
console.info(`Replacing deps[${from}]: ${deps[from]} with ${to}`);
deps[from] = to;
}
}
Expand Down

0 comments on commit 3ccb900

Please sign in to comment.