@oclif/plugin-command-snapshot 5.1.9 → 5.2.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.
@@ -7,7 +7,7 @@ export type SchemaComparison = Array<{
7
7
  }>;
8
8
  export default class SchemaCompare extends SnapshotCommand {
9
9
  static flags: {
10
- filepath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ filepath: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
11
  };
12
12
  run(): Promise<SchemaComparison>;
13
13
  private readExistingSchema;
@@ -1,9 +1,9 @@
1
1
  import { Flags, toConfiguredId } from '@oclif/core';
2
- import chalk from 'chalk';
2
+ import { bold, cyan, underline } from 'ansis';
3
3
  import { diff } from 'just-diff';
4
4
  import get from 'lodash.get';
5
- import * as fs from 'node:fs';
6
- import * as path from 'node:path';
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
7
  import * as semver from 'semver';
8
8
  import SnapshotCommand from '../../snapshot-command.js';
9
9
  import { GLOB_PATTERNS, getAllFiles, getKeyNameFromFilename } from '../../util.js';
@@ -69,19 +69,19 @@ export default class SchemaCompare extends SnapshotCommand {
69
69
  const basePath = lastElementIsNum ? readablePath.replace(`.${lastPathElement}`, '') : readablePath;
70
70
  switch (change.op) {
71
71
  case 'replace': {
72
- humanReadableChanges[commandId].push(`${chalk.underline(readablePath)} was changed from ${chalk.cyan(existing)} to ${chalk.cyan(latest)}`);
72
+ humanReadableChanges[commandId].push(`${underline(readablePath)} was changed from ${cyan(existing)} to ${cyan(latest)}`);
73
73
  break;
74
74
  }
75
75
  case 'add': {
76
76
  humanReadableChanges[commandId].push(lastElementIsNum
77
- ? `Array item at ${chalk.underline(basePath)} was ${chalk.cyan('added')} to latest schema`
78
- : `${chalk.underline(readablePath)} was ${chalk.cyan('added')} to latest schema`);
77
+ ? `Array item at ${underline(basePath)} was ${cyan('added')} to latest schema`
78
+ : `${underline(readablePath)} was ${cyan('added')} to latest schema`);
79
79
  break;
80
80
  }
81
81
  case 'remove': {
82
82
  humanReadableChanges[commandId].push(lastElementIsNum
83
- ? `Array item at ${chalk.underline(basePath)} was ${chalk.cyan('not found')} in latest schema`
84
- : `${chalk.underline(readablePath)} was ${chalk.cyan('not found')} in latest schema`);
83
+ ? `Array item at ${underline(basePath)} was ${cyan('not found')} in latest schema`
84
+ : `${underline(readablePath)} was ${cyan('not found')} in latest schema`);
85
85
  break;
86
86
  }
87
87
  default: {
@@ -94,17 +94,17 @@ export default class SchemaCompare extends SnapshotCommand {
94
94
  return [];
95
95
  }
96
96
  this.log();
97
- this.log(chalk.bold.red('Found the following schema changes:'));
97
+ this.log(bold.red('Found the following schema changes:'));
98
98
  for (const [commandId, changes] of Object.entries(humanReadableChanges)) {
99
99
  this.log();
100
- this.log(chalk.bold(commandId));
100
+ this.log(bold(commandId));
101
101
  for (const change of changes) {
102
102
  this.log(` - ${change}`);
103
103
  }
104
104
  }
105
105
  this.log();
106
106
  const bin = process.platform === 'win32' ? 'bin\\dev.cmd' : 'bin/dev.js';
107
- this.log('If intended, please update the schema file(s) and run again:', chalk.bold(`${bin} ${toConfiguredId('schema:generate', this.config)}`));
107
+ this.log('If intended, please update the schema file(s) and run again:', bold(`${bin} ${toConfiguredId('schema:generate', this.config)}`));
108
108
  process.exitCode = 1;
109
109
  return changes;
110
110
  }
@@ -44,9 +44,9 @@ export declare class SchemaGenerator {
44
44
  }
45
45
  export default class SchemaGenerate extends SnapshotCommand {
46
46
  static flags: {
47
- filepath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
48
- ignorevoid: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
49
- singlefile: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
47
+ filepath: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
48
+ ignorevoid: import("@oclif/core/interfaces").BooleanFlag<boolean>;
49
+ singlefile: import("@oclif/core/interfaces").BooleanFlag<boolean>;
50
50
  };
51
51
  run(): Promise<GenerateResponse>;
52
52
  }
@@ -1,8 +1,8 @@
1
- import { Flags } from '@oclif/core';
2
- import chalk from 'chalk';
1
+ import { Flags, ux } from '@oclif/core';
2
+ import { red } from 'ansis';
3
3
  import { globbySync } from 'globby';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
6
  import { createGenerator } from 'ts-json-schema-generator';
7
7
  import SnapshotCommand from '../../snapshot-command.js';
8
8
  import { GLOB_PATTERNS, getAllFiles, getSchemaFileName } from '../../util.js';
@@ -60,7 +60,7 @@ export class SchemaGenerator {
60
60
  catch (error) {
61
61
  if (error instanceof Error) {
62
62
  const error_ = error.message.toLowerCase().includes('no root type')
63
- ? new Error(`Schema generator could not find the ${chalk.red(returnType)} type. Please make sure that ${chalk.red(returnType)} is exported.`)
63
+ ? new Error(`Schema generator could not find the ${red(returnType)} type. Please make sure that ${red(returnType)} is exported.`)
64
64
  : error;
65
65
  throw error_;
66
66
  }
@@ -76,8 +76,23 @@ export class SchemaGenerator {
76
76
  return getAllFiles(path.join(rootDir, 'commands'), '.ts');
77
77
  }
78
78
  getAllHookFiles() {
79
- // eslint-disable-next-line unicorn/no-array-reduce
80
- const hookFiles = Object.values(this.base.config.pjson.oclif?.hooks ?? {}).reduce((x, y) => (Array.isArray(y) ? [...x, ...y] : [...x, y]), []);
79
+ const hookFiles = Object.values(this.base.config.pjson.oclif?.hooks ?? {})
80
+ .flatMap((hook) => {
81
+ if (Array.isArray(hook)) {
82
+ return hook.map((h) => {
83
+ if (typeof h === 'string')
84
+ return h;
85
+ ux.warn(`Identifier/target based hooks are not supported: ${h}`);
86
+ return null;
87
+ });
88
+ }
89
+ if (typeof hook === 'string') {
90
+ return hook;
91
+ }
92
+ ux.warn(`Identifier/target based hooks are not supported: ${hook}`);
93
+ return null;
94
+ })
95
+ .filter((h) => typeof h === 'string');
81
96
  const { outDir, rootDir } = this.getDirs();
82
97
  return hookFiles.map((h) => `${path.resolve(h)}.ts`.replace(outDir, rootDir));
83
98
  }
@@ -18,7 +18,7 @@ export type CompareResponse = {
18
18
  };
19
19
  export default class Compare extends SnapshotCommand {
20
20
  static flags: {
21
- filepath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
21
+ filepath: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
22
22
  };
23
23
  get changed(): CommandChange[];
24
24
  /**
@@ -1,7 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
- import chalk from 'chalk';
2
+ import { green, red } from 'ansis';
3
3
  import difference from 'lodash.difference';
4
- import * as fs from 'node:fs';
4
+ import fs from 'node:fs';
5
5
  import { EOL } from 'node:os';
6
6
  import SnapshotCommand from '../../snapshot-command.js';
7
7
  export default class Compare extends SnapshotCommand {
@@ -72,12 +72,12 @@ export default class Compare extends SnapshotCommand {
72
72
  }
73
73
  // Fail the process since there are changes to the snapshot file
74
74
  process.exitCode = 1;
75
- this.log(`The following commands and flags have modified: (${chalk.green('+')} added, ${chalk.red('-')} removed)${EOL}`);
75
+ this.log(`The following commands and flags have modified: (${green('+')} added, ${red('-')} removed)${EOL}`);
76
76
  for (const command of removedCommands) {
77
- this.log(chalk.red(`\t-${command}`));
77
+ this.log(red(`\t-${command}`));
78
78
  }
79
79
  for (const command of addedCommands) {
80
- this.log(chalk.green(`\t+${command}`));
80
+ this.log(green(`\t+${command}`));
81
81
  }
82
82
  const removedProperties = [];
83
83
  const printCommandDiff = (properties, propertyName) => {
@@ -85,7 +85,7 @@ export default class Compare extends SnapshotCommand {
85
85
  this.log(`\t ${propertyName}:`);
86
86
  for (const prop of properties) {
87
87
  if (prop.added || prop.removed) {
88
- const color = prop.added ? chalk.green : chalk.red;
88
+ const color = prop.added ? green : red;
89
89
  this.log(color(`\t\t${prop.added ? '+' : '-'}${prop.name}`));
90
90
  }
91
91
  if (prop.removed)
@@ -101,7 +101,7 @@ export default class Compare extends SnapshotCommand {
101
101
  this.log(`${EOL}Command, flag, flag characters, or alias differences detected. If intended, please update the snapshot file and run again.`);
102
102
  // Check if existent commands, or properties (flags, aliases) have been deleted
103
103
  if (removedCommands.length > 0 || removedProperties.length > 0) {
104
- this.log(chalk.red(`${EOL}Since there are deletions, a major version bump is required.`));
104
+ this.log(red(`${EOL}Since there are deletions, a major version bump is required.`));
105
105
  }
106
106
  return { addedCommands, diffCommands, removedCommands, removedFlags: removedCommands };
107
107
  }
@@ -2,7 +2,7 @@ import SnapshotCommand, { SnapshotEntry } from '../../snapshot-command.js';
2
2
  export type Snapshots = SnapshotEntry[];
3
3
  export default class Generate extends SnapshotCommand {
4
4
  static flags: {
5
- filepath: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
5
+ filepath: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
6
  };
7
7
  run(): Promise<Snapshots>;
8
8
  }
@@ -145,5 +145,5 @@
145
145
  ]
146
146
  }
147
147
  },
148
- "version": "5.1.9"
148
+ "version": "5.2.1"
149
149
  }
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@oclif/plugin-command-snapshot",
3
3
  "description": "generates and compares OCLIF plugins snapshot files",
4
- "version": "5.1.9",
4
+ "version": "5.2.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/plugin-command-snapshot/issues",
7
7
  "dependencies": {
8
- "@oclif/core": "3.26.6",
9
- "@types/lodash.difference": "^4.5.9",
10
- "chalk": "^5.3.0",
8
+ "@oclif/core": "^4",
9
+ "ansis": "^3.2.0",
11
10
  "globby": "^14.0.1",
12
11
  "just-diff": "^5.2.0",
13
12
  "lodash.difference": "^4.5.0",
@@ -17,30 +16,32 @@
17
16
  "ts-json-schema-generator": "^1.5.1"
18
17
  },
19
18
  "devDependencies": {
20
- "@commitlint/config-conventional": "^18.6.3",
19
+ "@commitlint/config-conventional": "^19",
21
20
  "@oclif/plugin-help": "^6",
22
21
  "@oclif/prettier-config": "^0.2.1",
23
- "@oclif/test": "^3.2.12",
22
+ "@oclif/test": "^4",
24
23
  "@types/chai": "^4.3.11",
24
+ "@types/lodash.difference": "^4.5.9",
25
25
  "@types/lodash.get": "^4.4.9",
26
26
  "@types/lodash.sortby": "^4.7.9",
27
27
  "@types/mocha": "^10.0.6",
28
28
  "@types/node": "^18",
29
29
  "@types/semver": "^7.5.8",
30
+ "@types/sinon": "^17.0.3",
30
31
  "chai": "^4",
31
- "commitlint": "^18.6.1",
32
+ "commitlint": "^19",
32
33
  "eslint": "^8.57.0",
33
34
  "eslint-config-oclif": "^5.2.0",
34
35
  "eslint-config-oclif-typescript": "^3.1.7",
35
36
  "eslint-config-prettier": "^9.1.0",
36
37
  "husky": "^9",
37
- "lint-staged": "^15.2.2",
38
+ "lint-staged": "^15.2.5",
38
39
  "mocha": "^10.4.0",
39
40
  "nyc": "^15",
40
- "oclif": "^4.10.2",
41
+ "oclif": "^4.12.0",
41
42
  "prettier": "^3.2.5",
42
43
  "shx": "^0.3.4",
43
- "sinon": "^17.0.1",
44
+ "sinon": "^18.0.0",
44
45
  "ts-node": "^10.9.2",
45
46
  "typescript": "^5.4.4"
46
47
  },