Skip to content

Commit 31a3ccb

Browse files
committed
refactoring
1 parent 1db9d16 commit 31a3ccb

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
const chalk = require('chalk');
11+
const {echo, exec} = require('shelljs');
12+
13+
const detectPackageUnreleasedChanges = (
14+
packageRelativePathFromRoot,
15+
packageName,
16+
) => {
17+
const hashOfLastCommitInsidePackage = exec(
18+
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
19+
{cwd: ROOT_LOCATION, silent: true},
20+
).stdout.trim();
21+
22+
const hashOfLastCommitThatChangedVersion = exec(
23+
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
24+
{cwd: ROOT_LOCATION, silent: true},
25+
).stdout.trim();
26+
27+
if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
28+
echo(
29+
`\uD83D\uDD0E No changes for package ${chalk.green(
30+
packageName,
31+
)} since last version bump`,
32+
);
33+
return false;
34+
} else {
35+
echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
36+
exec(
37+
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
38+
{
39+
cwd: ROOT_LOCATION,
40+
},
41+
);
42+
echo();
43+
44+
return true;
45+
}
46+
};
47+
48+
module.exports = detectPackageUnreleasedChanges;

scripts/monorepo/bump-all-updated-packages/index.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
const forEachPackage = require('../for-each-package');
2626
const checkForGitChanges = require('../check-for-git-changes');
2727
const bumpPackageVersion = require('./bump-package-version');
28+
const detectPackageUnreleasedChanges = require('./bump-utils');
2829

2930
const ROOT_LOCATION = path.join(__dirname, '..', '..', '..');
3031

@@ -37,41 +38,6 @@ const {
3738
})
3839
.strict();
3940

40-
const detectPackageUnreleasedChanges = (
41-
packageRelativePathFromRoot,
42-
packageName,
43-
) => {
44-
const hashOfLastCommitInsidePackage = exec(
45-
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
46-
{cwd: ROOT_LOCATION, silent: true},
47-
).stdout.trim();
48-
49-
const hashOfLastCommitThatChangedVersion = exec(
50-
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
51-
{cwd: ROOT_LOCATION, silent: true},
52-
).stdout.trim();
53-
54-
if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
55-
echo(
56-
`\uD83D\uDD0E No changes for package ${chalk.green(
57-
packageName,
58-
)} since last version bump`,
59-
);
60-
return false;
61-
} else {
62-
echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
63-
exec(
64-
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
65-
{
66-
cwd: ROOT_LOCATION,
67-
},
68-
);
69-
echo();
70-
71-
return true;
72-
}
73-
};
74-
7541
const buildExecutor =
7642
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) =>
7743
async () => {
@@ -249,5 +215,3 @@ const main = async () => {
249215
};
250216

251217
main();
252-
253-
module.exports = {detectPackageUnreleasedChanges};

0 commit comments

Comments
 (0)