Skip to content

Commit

Permalink
By default loosen the node&npm engine when bumpting 📤
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Oct 8, 2024
1 parent a0a011e commit a123bdd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/bump-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ const {makeError, formatEventualSuffix} = require('./core/utils');

const bumpNodeVersion = async (latestNode, config) => {
process.stdout.write(c.bold.blue(`\n\n⬆️ About to bump node version:\n`));
const {exact, loose} = config.node;
const nodeVersion = _.trimCharsStart('v', latestNode.version);
await Promise.all([
updateServerless(nodeVersion, config.node.serverless),
updateTravis(nodeVersion, config.node.travis),
updatePackageEngines(nodeVersion, latestNode.npm, config.node.package, !!config.exact),
updatePackageEngines(nodeVersion, latestNode.npm, config.node.package, {exact, loose}),
updateNvmrc(nodeVersion, config.node.nvmrc),
updateDockerfile(nodeVersion, config.node.dockerfile),
config.lernaMonorepo && updateLearnaPackageEngines(nodeVersion, latestNode.npm, !!config.exact)
config.lernaMonorepo && updateLearnaPackageEngines(nodeVersion, latestNode.npm, {exact, loose})
]);

const messageSuffix = formatEventualSuffix(config.argv.message);
Expand Down
6 changes: 6 additions & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ const generateDefaultConfig = () => {
travis: fs.existsSync('.travis.yml'),
package: true,
serverless: fs.existsSync('serverless.yml')
/* optional default config
loose: true,
exact: false
*/
},
dependencies: [
{
Expand Down Expand Up @@ -118,6 +122,8 @@ const resolveConfig = async (config, configPath, argv) => {
base.node.package = defaultWithPath(base.node.package, 'package.json');
base.node.serverless = defaultWithPath(base.node.serverless, 'serverless.yml');
}
base.exact = base.node.exact || argv.exact;
base.loose = base.node.loose !== false && argv.loose; // default logic
base.argv = argv;
base.forceFlag = argv.force ? '--force' : '--force-with-lease';
base.lernaMonorepo = base.node.lerna || argv.lerna;
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ const yargs = require('yargs')
boolean: true,
alias: 'f'
})
.option('exact', {
describe: 'Keep exact version',
boolean: true,
default: false
})
.option('loose', {
describe: `For loose version for nodes version. This will replace exisiting range constraint (^, ~ or none).
Use --no-loose to disable or place loose: false in config in the node section)`,
boolean: true,
default: true
})
.option('config', {
describe: 'Override update-node configuration default path',
string: true,
Expand Down
14 changes: 8 additions & 6 deletions src/updatees/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ const readPackage = packagePath => {

const getSemverPrefix = _.pipe(s => s && s.match(/^(\D*)\d+/), _.at(1));

const updatePackageEngines = async (node, npm, pkg, exact = false) => {
const updatePackageEngines = async (node, npm, pkg, {exact = false, loose = true}) => {
// TODO: maybe support forcing the choice of prefix (example, to restore loose range like >=)

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'
if (_.isArray(pkg)) return pMap(pkg, p => updatePackageEngines(node, npm, p, exact));
if (_.isArray(pkg)) return pMap(pkg, p => updatePackageEngines(node, npm, p, {exact, loose}));

if (!pkg) return;

const prefix = exact ? EXACT_PREFIX : loose ? '>=' : '';

const newPackage = _.pipe(
_.update('engines.node', existingVersion =>
node ? `${exact ? EXACT_PREFIX : getSemverPrefix(existingVersion)}${node}` : existingVersion
node ? `${prefix ? prefix : getSemverPrefix(existingVersion)}${node}` : existingVersion
),
_.update('engines.npm', existingVersion =>
npm ? `${exact ? EXACT_PREFIX : getSemverPrefix(existingVersion)}${npm}` : existingVersion
npm ? `${prefix ? prefix : getSemverPrefix(existingVersion)}${npm}` : existingVersion
)
)(await readPackage(pkg));

Expand Down Expand Up @@ -96,7 +98,7 @@ const updateLock = async (packageManager = 'npm') => {
]);
};

const updateLearnaPackageEngines = async (nodeVersion, npmVersion, exact) => {
const updateLearnaPackageEngines = async (nodeVersion, npmVersion, {exact, loose}) => {
const lernaPackages = _.map(
({location}) => `${chompCurrentFolder(location)}/package.json`,
JSON.parse(
Expand All @@ -106,7 +108,7 @@ const updateLearnaPackageEngines = async (nodeVersion, npmVersion, exact) => {
}).all
)
);
return updatePackageEngines(nodeVersion, npmVersion, lernaPackages, exact);
return updatePackageEngines(nodeVersion, npmVersion, lernaPackages, {exact, loose});

// note: serverlesses are supposed to be declared to level
};
Expand Down

0 comments on commit a123bdd

Please sign in to comment.