@hubspot/npm-scripts 0.0.2 → 0.0.3-experimental.0

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
@@ -1,4 +1,4 @@
1
- # Dev-Experience-Fe-Scripts
1
+ # @hubspot/npm-scripts
2
2
 
3
3
  **A collection of scripts for internal HubSpot npm package development and management.**
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/npm-scripts",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-experimental.0",
4
4
  "description": "Scripts for working with npm packages in the HubSpot ecosystem",
5
5
  "author": "",
6
6
  "license": "Apache-2.0",
@@ -23,7 +23,7 @@
23
23
  "fs-extra": "^11.3.2",
24
24
  "open": "^10.2.0",
25
25
  "semver": "^7.7.2",
26
- "yargs": "^18.0.0"
26
+ "yargs": "17.7.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@eslint/js": "^9.36.0",
package/src/linking.js CHANGED
@@ -2,7 +2,7 @@ import os from 'os';
2
2
  import path from 'path';
3
3
  import { execSync } from 'node:child_process';
4
4
  import chalk from 'chalk';
5
- import { checkbox } from '@inquirer/prompts';
5
+ import { checkbox } from './utils/prompting.js';
6
6
  import fs from 'fs-extra';
7
7
  import findup from 'findup-sync';
8
8
  import { logger } from './utils/logging.js';
@@ -19,10 +19,19 @@ function getSymLinksInDirectory(directory) {
19
19
  });
20
20
  }
21
21
  function getPackageName(node_modules_dir, packages) {
22
- return packages.map((item) => {
23
- const { name } = fs.readJsonSync(path.join(node_modules_dir, item, packageJson));
24
- return name;
25
- });
22
+ return packages
23
+ .map((item) => {
24
+ const pathToOpen = path.join(node_modules_dir, item, packageJson);
25
+ try {
26
+ const { name } = fs.readJsonSync(pathToOpen);
27
+ return name;
28
+ }
29
+ catch (err) {
30
+ logger.warn(`Unable to open "${pathToOpen}", if @hubspot/${item} is a dependency of this project it is not installed. If you would like to link it, add it as a project dependency and install it.\n`);
31
+ return undefined;
32
+ }
33
+ })
34
+ .filter((item) => item !== undefined);
26
35
  }
27
36
  const yarnLinkPath = path.join(os.homedir(), '.config', 'yarn', 'link', hubspotPackageNamespace);
28
37
  (async () => {
@@ -47,10 +56,10 @@ const yarnLinkPath = path.join(os.homedir(), '.config', 'yarn', 'link', hubspotP
47
56
  }
48
57
  let packagesToLink = [];
49
58
  try {
50
- packagesToLink = await checkbox({
59
+ packagesToLink = (await checkbox({
51
60
  message: 'Which packages would you like to link? - To get packages to show in this list, run `yarn link` from inside the local copy that package.',
52
61
  choices,
53
- });
62
+ }));
54
63
  }
55
64
  catch (e) {
56
65
  if (e instanceof Error && e.name === 'ExitPromptError') {
package/src/release.js CHANGED
@@ -3,13 +3,13 @@ import { promisify } from 'util';
3
3
  import yargs from 'yargs';
4
4
  import semver from 'semver';
5
5
  import open from 'open';
6
+ import fs from 'fs-extra';
6
7
  import { logger } from './utils/logging.js';
7
8
  import { EXIT_CODES } from './utils/process.js';
8
9
  import { DEFAULT_MAIN_BRANCH, INCREMENT, PRERELEASE_IDENTIFIER, TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
9
- import { confirm, input } from '@inquirer/prompts';
10
- import fs from 'fs-extra';
11
10
  import { gitCleanup, getCurrentGitBranch } from './utils/git.js';
12
11
  import { getDistTags, publish, updateNextTag } from './utils/npm.js';
12
+ import { confirm, input } from './utils/prompting.js';
13
13
  const exec = promisify(_exec);
14
14
  function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, }) {
15
15
  return async function handler({ versionIncrement, tag, dryRun, }) {
@@ -101,8 +101,9 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
101
101
  await publish(tag, otp, isDryRun, registry);
102
102
  }
103
103
  catch (e) {
104
+ logger.error(e);
104
105
  logger.error('An error occurred while releasing the CLI. Correct the error and re-run `yarn build`.');
105
- await gitCleanup(newVersion);
106
+ await gitCleanup(newVersion, !isExperimental);
106
107
  process.exit(EXIT_CODES.ERROR);
107
108
  }
108
109
  const gitCommand = `git push --atomic origin ${tempBranch} v${newVersion}`;
@@ -117,7 +118,7 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
117
118
  }
118
119
  }
119
120
  if (isDryRun) {
120
- await gitCleanup(newVersion);
121
+ await gitCleanup(newVersion, !isExperimental);
121
122
  logger.log(`\nDry run: skipping push to Github`);
122
123
  logger.log('Dry run release finished successfully');
123
124
  process.exit(EXIT_CODES.SUCCESS);
@@ -1,2 +1,2 @@
1
1
  export declare function getCurrentGitBranch(): Promise<string>;
2
- export declare function gitCleanup(newVersion: string): Promise<void>;
2
+ export declare function gitCleanup(newVersion: string, deleteTag: boolean): Promise<void>;
package/src/utils/git.js CHANGED
@@ -5,8 +5,10 @@ export async function getCurrentGitBranch() {
5
5
  const { stdout } = await exec('git rev-parse --abbrev-ref HEAD');
6
6
  return stdout.trim();
7
7
  }
8
- export async function gitCleanup(newVersion) {
8
+ export async function gitCleanup(newVersion, deleteTag) {
9
9
  await exec(`git reset HEAD~`);
10
10
  await exec(`git checkout .`);
11
- await exec(`git tag -d v${newVersion}`);
11
+ if (deleteTag) {
12
+ await exec(`git tag -d v${newVersion}`);
13
+ }
12
14
  }
@@ -2,6 +2,7 @@ export declare const logger: {
2
2
  log(...args: unknown[]): void;
3
3
  info(...args: unknown[]): void;
4
4
  success(...args: unknown[]): void;
5
+ warn(...args: unknown[]): void;
5
6
  error(...args: unknown[]): void;
6
7
  table(...args: unknown[]): void;
7
8
  };
@@ -9,6 +9,9 @@ export const logger = {
9
9
  success(...args) {
10
10
  console.log(`${chalk.cyan('[SUCCESS]')}`, ...args);
11
11
  },
12
+ warn(...args) {
13
+ console.log(`${chalk.yellow('[WARN]')}`, ...args);
14
+ },
12
15
  error(...args) {
13
16
  console.log(`${chalk.red('[ERROR]')}`, ...args);
14
17
  },
@@ -0,0 +1,6 @@
1
+ import _confirm from '@inquirer/confirm';
2
+ import _input from '@inquirer/input';
3
+ import _checkbox from '@inquirer/checkbox';
4
+ export declare function confirm(...args: Parameters<typeof _confirm>): Promise<ReturnType<typeof _confirm>>;
5
+ export declare function input(...args: Parameters<typeof _input>): Promise<ReturnType<typeof _input>>;
6
+ export declare function checkbox(...args: Parameters<typeof _checkbox>): Promise<ReturnType<typeof _checkbox>>;
@@ -0,0 +1,38 @@
1
+ import _confirm from '@inquirer/confirm';
2
+ import _input from '@inquirer/input';
3
+ import _checkbox from '@inquirer/checkbox';
4
+ import { EXIT_CODES } from './process.js';
5
+ import { logger } from './logging.js';
6
+ function exitIfPromptError(e) {
7
+ if (e instanceof Error && e.name === 'ExitPromptError') {
8
+ logger.log('Exiting...');
9
+ process.exit(EXIT_CODES.SUCCESS);
10
+ }
11
+ }
12
+ export async function confirm(...args) {
13
+ try {
14
+ return await _confirm(...args);
15
+ }
16
+ catch (e) {
17
+ exitIfPromptError(e);
18
+ throw e;
19
+ }
20
+ }
21
+ export async function input(...args) {
22
+ try {
23
+ return await _input(...args);
24
+ }
25
+ catch (e) {
26
+ exitIfPromptError(e);
27
+ throw e;
28
+ }
29
+ }
30
+ export async function checkbox(...args) {
31
+ try {
32
+ return await _checkbox(...args);
33
+ }
34
+ catch (e) {
35
+ exitIfPromptError(e);
36
+ throw e;
37
+ }
38
+ }