@hubspot/npm-scripts 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,7 +174,7 @@ Run your publish jobs in a [GitHub environment](https://docs.github.com/en/actio
174
174
  - **Interactive prompts**: Confirms release details before publishing
175
175
  - **Automatic tagging**: Creates git tags and pushes to repository
176
176
  - **GitHub integration**: Opens PR and release pages automatically
177
- - **Clean working tree required**: Fails before changing anything if `git status` shows uncommitted changes, because the rollback runs `git checkout .`
177
+ - **Clean working tree required**: Fails before changing anything if `git status` shows uncommitted changes, because the rollback runs `git checkout HEAD -- .`
178
178
  - **Rollback support**: Cleans up on failure
179
179
 
180
180
  ### Repo Sync Script Builder (`buildRepoSyncScript`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/npm-scripts",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Scripts for working with npm packages in the HubSpot ecosystem",
5
5
  "author": "",
6
6
  "license": "Apache-2.0",
@@ -64,7 +64,7 @@ describe('git', () => {
64
64
  it('should only checkout files when deleteTag is false', async () => {
65
65
  mockedExec.mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
66
66
  await gitCleanup('1.0.0', false);
67
- expect(mockedExec).toHaveBeenCalledWith('git checkout .');
67
+ expect(mockedExec).toHaveBeenCalledWith('git checkout HEAD -- .');
68
68
  expect(mockedExec).not.toHaveBeenCalledWith('git reset HEAD~');
69
69
  expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git tag -d'));
70
70
  });
@@ -72,14 +72,14 @@ describe('git', () => {
72
72
  mockedExec.mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
73
73
  await gitCleanup('1.0.0', true);
74
74
  expect(mockedExec).toHaveBeenCalledWith('git reset HEAD~');
75
- expect(mockedExec).toHaveBeenCalledWith('git checkout .');
75
+ expect(mockedExec).toHaveBeenCalledWith('git checkout HEAD -- .');
76
76
  expect(mockedExec).toHaveBeenCalledWith('git tag -d v1.0.0');
77
77
  });
78
78
  it('should checkout originalBranch and delete tempBranch when both are provided', async () => {
79
79
  mockedExec.mockImplementation(() => Promise.resolve({ stdout: '', stderr: '' }));
80
80
  await gitCleanup('1.0.0', true, 'v1.0.0-publish', 'master');
81
81
  expect(mockedExec).toHaveBeenCalledWith('git reset HEAD~');
82
- expect(mockedExec).toHaveBeenCalledWith('git checkout .');
82
+ expect(mockedExec).toHaveBeenCalledWith('git checkout HEAD -- .');
83
83
  expect(mockedExec).toHaveBeenCalledWith('git tag -d v1.0.0');
84
84
  expect(mockedExec).toHaveBeenCalledWith('git checkout master');
85
85
  expect(mockedExec).toHaveBeenCalledWith('git branch -D v1.0.0-publish');
package/src/utils/git.js CHANGED
@@ -51,7 +51,7 @@ export async function gitCleanup(newVersion, deleteTag, tempBranch, originalBran
51
51
  await exec(`git reset HEAD~`);
52
52
  await exec(`git tag -d v${newVersion}`);
53
53
  }
54
- await exec(`git checkout .`);
54
+ await exec(`git checkout HEAD -- .`);
55
55
  if (tempBranch && originalBranch) {
56
56
  try {
57
57
  await exec(`git checkout ${originalBranch}`);
@@ -158,6 +158,7 @@ describe('release/steps', () => {
158
158
  localVersion: '1.0.0',
159
159
  versionIncrement: INCREMENT.PATCH,
160
160
  })).rejects.toMatchObject({ exitCode: EXIT_CODES.SUCCESS });
161
+ expect(logger.log).toHaveBeenCalledWith('\nTo release your changes on the next tag first, run the next release command instead, e.g. `yarn beta-release -v patch`');
161
162
  });
162
163
  it('should not prompt when skipPrompts is true', async () => {
163
164
  await confirmRelease({
@@ -551,6 +552,7 @@ describe('release/steps', () => {
551
552
  expect(logger.log).toHaveBeenCalledWith(`View workflow in GitHub: ${RUN.url}`);
552
553
  expect(logger.success).toHaveBeenCalledWith(`Published ${PACKAGE_NAME}@1.0.0-experimental.3 on the experimental tag`);
553
554
  expect(logger.log).toHaveBeenCalledWith(`Install it with: yarn add ${PACKAGE_NAME}@1.0.0-experimental.3`);
555
+ expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('npm can take a few minutes'));
554
556
  });
555
557
  it('should only print the dispatch command on dry run', async () => {
556
558
  await runExperimentalWorkflow({ ...BASE_ARGS, isDryRun: true });
@@ -705,6 +707,10 @@ describe('release/steps', () => {
705
707
  'git push -u origin v1.0.1-beta.0-publish',
706
708
  ]);
707
709
  });
710
+ it('should note that npm takes a few minutes to make the version available', async () => {
711
+ await openReleasePr(BASE_ARGS);
712
+ expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('npm can take a few minutes'));
713
+ });
708
714
  it('should open the PR with gh using an argument list', async () => {
709
715
  await openReleasePr({
710
716
  ...BASE_ARGS,
@@ -808,13 +814,13 @@ describe('release/steps', () => {
808
814
  message: '',
809
815
  });
810
816
  expect(mockedGitCleanup).not.toHaveBeenCalled();
811
- expect(logger.error).toHaveBeenCalledWith('Automatic cleanup failed. To restore your repository, run: git reset HEAD~ && git checkout . && git checkout main && git branch -D v1.0.1-beta.0-publish');
817
+ expect(logger.error).toHaveBeenCalledWith('Automatic cleanup failed. To restore your repository, run: git reset HEAD~ && git checkout HEAD -- . && git checkout main && git branch -D v1.0.1-beta.0-publish');
812
818
  });
813
819
  it('should print recovery commands when gitCleanup fails', async () => {
814
820
  failOn('yarn version');
815
821
  mockedGitCleanup.mockRejectedValue(new Error('unmerged paths'));
816
822
  await expect(openReleasePr(BASE_ARGS)).rejects.toThrow(ReleaseError);
817
- expect(logger.error).toHaveBeenCalledWith('Automatic cleanup failed. To restore your repository, run: git checkout . && git checkout main && git branch -D v1.0.1-beta.0-publish');
823
+ expect(logger.error).toHaveBeenCalledWith('Automatic cleanup failed. To restore your repository, run: git checkout HEAD -- . && git checkout main && git branch -D v1.0.1-beta.0-publish');
818
824
  });
819
825
  it('should tell the user how to finish or undo when PR creation fails after the push', async () => {
820
826
  mockedExecFile.mockRejectedValue(new Error('gh pr create failed'));
@@ -950,6 +956,7 @@ describe('release/steps', () => {
950
956
  await logReleaseSuccess(BASE_ARGS);
951
957
  expect(logger.success).toHaveBeenCalledWith(`${PACKAGE_NAME} version 1.0.1-beta.0 published successfully`);
952
958
  expect(logger.log).toHaveBeenCalledWith(`https://www.npmjs.com/package/${PACKAGE_NAME}?activeTab=versions`);
959
+ expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('npm can take a few minutes'));
953
960
  });
954
961
  it('should not log the GitHub release reminder for next tag', async () => {
955
962
  await logReleaseSuccess(BASE_ARGS);
@@ -17,6 +17,7 @@ const execFile = promisify(_execFile);
17
17
  const WORKFLOW_RUN_POLL_ATTEMPTS = 10;
18
18
  const WORKFLOW_RUN_POLL_INTERVAL_MS = 3000;
19
19
  const WORKFLOW_RUN_MAX_STATUS_ERRORS = 5;
20
+ const NPM_AVAILABILITY_NOTE = 'npm can take a few minutes to make a new version available after it publishes, so installing it may fail until then.';
20
21
  export async function resolveVersionIncrement(tag, versionIncrement, skipPrompts) {
21
22
  if (versionIncrement) {
22
23
  return versionIncrement;
@@ -63,7 +64,7 @@ export async function confirmRelease({ isDryRun, currentVersion, currentVersionL
63
64
  default: false,
64
65
  });
65
66
  if (!proceed) {
66
- logger.log(`\nTo release your changes on the next tag, run \`yarn release -v=${versionIncrement} -t=next\``);
67
+ logger.log(`\nTo release your changes on the ${TAG.NEXT} tag first, run the ${TAG.NEXT} release command instead, e.g. \`yarn beta-release -v ${versionIncrement}\``);
67
68
  throw new ReleaseError('', EXIT_CODES.SUCCESS);
68
69
  }
69
70
  }
@@ -127,7 +128,7 @@ export async function ensureNpmAuth(isDryRun, registry, skipPrompts) {
127
128
  export async function ensureCleanWorkingTree() {
128
129
  const { stdout } = await exec('git status --porcelain');
129
130
  if (stdout.trim()) {
130
- throw new ReleaseError(`Working tree has uncommitted changes. Commit or stash them before releasing, because the release rolls back with \`git checkout .\` and would discard them:\n${stdout.trimEnd()}`);
131
+ throw new ReleaseError(`Working tree has uncommitted changes. Commit or stash them before releasing, because the release rolls back with \`git checkout HEAD -- .\` and would discard them:\n${stdout.trimEnd()}`);
131
132
  }
132
133
  }
133
134
  function getGitHost(repositoryUrl) {
@@ -354,6 +355,7 @@ export async function runExperimentalWorkflow({ workflow, mainBranch, branch, sh
354
355
  }
355
356
  logger.success(`Published ${packageName}@${version} on the experimental tag`);
356
357
  logger.log(`Install it with: yarn add ${packageName}@${version}`);
358
+ logger.log(NPM_AVAILABILITY_NOTE);
357
359
  }
358
360
  export async function openReleasePr({ tag, newVersion, isDryRun, baseBranch, repositoryUrl, headBranch, onTempBranch, tempBranch, originalBranch, }) {
359
361
  const title = `chore: release v${newVersion}`;
@@ -393,6 +395,7 @@ export async function openReleasePr({ tag, newVersion, isDryRun, baseBranch, rep
393
395
  const { stdout } = await execFile('gh', prArgs);
394
396
  logger.success(`Release PR opened: ${stdout.trim()}`);
395
397
  logger.log(`Merging it publishes v${newVersion} to npm on the ${tag} tag from CI.`);
398
+ logger.log(NPM_AVAILABILITY_NOTE);
396
399
  }
397
400
  catch (e) {
398
401
  logger.error(e);
@@ -412,7 +415,7 @@ export async function openReleasePr({ tag, newVersion, isDryRun, baseBranch, rep
412
415
  logger.error(cleanupError);
413
416
  const recoveryCommands = [
414
417
  committed ? 'git reset HEAD~' : undefined,
415
- 'git checkout .',
418
+ 'git checkout HEAD -- .',
416
419
  onTempBranch ? `git checkout ${originalBranch}` : undefined,
417
420
  onTempBranch ? `git branch -D ${tempBranch}` : undefined,
418
421
  ].filter(Boolean);
@@ -479,6 +482,7 @@ export async function finalizeRelease({ isDryRun, isExperimental, newVersion, lo
479
482
  export async function logReleaseSuccess({ packageName, newVersion, tag, repositoryUrl, isDryRun, postLatestRelease, }) {
480
483
  logger.success(`${packageName} version ${newVersion} published successfully`);
481
484
  logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
485
+ logger.log(NPM_AVAILABILITY_NOTE);
482
486
  if (tag !== TAG.LATEST && tag !== TAG.PREVIOUS) {
483
487
  return;
484
488
  }