@oclif/plugin-command-snapshot 5.4.0 → 6.0.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.
@@ -1,8 +1,8 @@
1
- import { Operation } from 'just-diff';
1
+ import { type Operation } from 'just-diff';
2
2
  import SnapshotCommand from '../../snapshot-command.js';
3
3
  export type SchemaComparison = Array<{
4
4
  op: Operation;
5
- path: (number | string)[];
5
+ path: Array<number | string>;
6
6
  value: unknown;
7
7
  }>;
8
8
  export default class SchemaCompare extends SnapshotCommand {
@@ -61,22 +61,22 @@ export default class SchemaCompare extends SnapshotCommand {
61
61
  const objPath = change.path.join('.');
62
62
  const existing = get(existingSchema, objPath);
63
63
  const latest = get(latestSchema, objPath);
64
- const [commandId] = objPath.split('.definitions');
64
+ const [commandId] = objPath.split('.definitions', 1);
65
65
  const readablePath = objPath.replace(`${commandId}.`, '');
66
66
  if (!humanReadableChanges[commandId]) {
67
67
  humanReadableChanges[commandId] = [];
68
68
  }
69
- const lastElementIsNum = isNumber(lastPathElement);
70
- const basePath = lastElementIsNum ? readablePath.replace(`.${lastPathElement}`, '') : readablePath;
69
+ const isLastElementNum = isNumber(lastPathElement);
70
+ const basePath = isLastElementNum ? readablePath.replace(`.${lastPathElement}`, '') : readablePath;
71
71
  switch (change.op) {
72
72
  case 'add': {
73
- humanReadableChanges[commandId].push(lastElementIsNum
73
+ humanReadableChanges[commandId].push(isLastElementNum
74
74
  ? `Array item at ${underline(basePath)} was ${cyan('added')} to latest schema`
75
75
  : `${underline(readablePath)} was ${cyan('added')} to latest schema`);
76
76
  break;
77
77
  }
78
78
  case 'remove': {
79
- humanReadableChanges[commandId].push(lastElementIsNum
79
+ humanReadableChanges[commandId].push(isLastElementNum
80
80
  ? `Array item at ${underline(basePath)} was ${cyan('not found')} in latest schema`
81
81
  : `${underline(readablePath)} was ${cyan('not found')} in latest schema`);
82
82
  break;
@@ -111,8 +111,8 @@ export default class SchemaCompare extends SnapshotCommand {
111
111
  }
112
112
  readExistingSchema(filePath) {
113
113
  const contents = fs.readdirSync(filePath);
114
- const folderIsVersioned = contents.every((c) => semver.valid(c));
115
- const schemasDir = folderIsVersioned ? path.join(filePath, semver.rsort(contents)[0] || '') : filePath;
114
+ const isFolderVersioned = contents.every((c) => semver.valid(c));
115
+ const schemasDir = isFolderVersioned ? path.join(filePath, semver.rsort(contents)[0] || '') : filePath;
116
116
  const schemaFiles = getAllFiles(schemasDir, '.json');
117
117
  let schemas = {
118
118
  commands: {},
@@ -1,8 +1,6 @@
1
- import { Schema } from 'ts-json-schema-generator';
1
+ import { type Schema } from 'ts-json-schema-generator';
2
2
  import SnapshotCommand from '../../snapshot-command.js';
3
- export type SchemasMap = {
4
- [key: string]: Schema;
5
- };
3
+ export type SchemasMap = Record<string, Schema>;
6
4
  export type Schemas = {
7
5
  commands: SchemasMap;
8
6
  hooks: SchemasMap;
@@ -15,11 +13,11 @@ type SchemaGenerateOptions = {
15
13
  ignoreVoid?: boolean;
16
14
  };
17
15
  export declare class SchemaGenerator {
18
- private base;
16
+ private readonly base;
19
17
  private classToId;
20
- private commandGlobs;
21
- private commandsDir;
22
- private ignoreVoid;
18
+ private readonly commandGlobs;
19
+ private readonly commandsDir;
20
+ private readonly ignoreVoid;
23
21
  constructor(options: SchemaGenerateOptions);
24
22
  generate(): Promise<Schemas>;
25
23
  private determineCommandId;
@@ -144,28 +144,28 @@ export class SchemaGenerator {
144
144
  const contents = fs.readFileSync(file, 'utf8');
145
145
  const [returnType] = returnTypeRegex.exec(contents) || [];
146
146
  if (!returnType || returnType === 'void') {
147
- return { hookId: null, returnType: null };
147
+ return { hookId: undefined, returnType: undefined };
148
148
  }
149
149
  const hooks = this.base.config.pjson.oclif?.hooks ?? {};
150
150
  const hookId = Object.keys(hooks).find((key) => {
151
151
  const hookFiles = (Array.isArray(hooks[key]) ? hooks[key] : [hooks[key]]);
152
- const hookFileNames = hookFiles.map((f) => path.basename(f).split('.')[0]);
153
- const currentFileName = path.basename(file).split('.')[0];
152
+ const hookFileNames = hookFiles.map((f) => path.basename(f).split('.', 1)[0]);
153
+ const currentFileName = path.basename(file).split('.', 1)[0];
154
154
  return hookFileNames.includes(currentFileName);
155
155
  });
156
156
  if (!hookId) {
157
- return { hookId: null, returnType: null };
157
+ return { hookId: undefined, returnType: undefined };
158
158
  }
159
159
  this.validateReturnType(returnType, hookId);
160
160
  return { hookId, returnType };
161
161
  }
162
162
  validateReturnType(returnType, commandId) {
163
163
  const notAllowed = this.ignoreVoid ? ['any', 'unknown'] : ['any', 'unknown', 'void'];
164
- const vagueTypes = ['JsonMap', 'JsonCollection', 'AnyJson'];
165
164
  if (notAllowed.includes(returnType)) {
166
165
  throw new Error(`${returnType} (from ${commandId}) is not allowed. Please use a more specific type.`);
167
166
  }
168
- else if (vagueTypes.includes(returnType)) {
167
+ const vagueTypes = ['JsonMap', 'JsonCollection', 'AnyJson'];
168
+ if (vagueTypes.includes(returnType)) {
169
169
  throw new Error(`${returnType} (from ${commandId}) is too vague. Please use a more specific type.`);
170
170
  }
171
171
  }
@@ -1,9 +1,9 @@
1
- import SnapshotCommand, { SnapshotEntry } from '../../snapshot-command.js';
2
- interface Change {
1
+ import SnapshotCommand, { type SnapshotEntry } from '../../snapshot-command.js';
2
+ type Change = {
3
3
  added?: boolean;
4
4
  name: string;
5
5
  removed?: boolean;
6
- }
6
+ };
7
7
  type CommandChange = Change & {
8
8
  alias: Change[];
9
9
  chars: Change[];
@@ -36,26 +36,26 @@ export default class Compare extends SnapshotCommand {
36
36
  for (const initialCommand of initialCommands) {
37
37
  const updatedCommand = updatedCommands.find((updatedCommand) => {
38
38
  // Protect against old snapshot files that don't have the plugin entry filled out.
39
- const samePlugin = initialCommand.plugin ? initialCommand.plugin === updatedCommand.plugin : true;
40
- return initialCommand.command === updatedCommand.name && samePlugin;
39
+ const isSamePlugin = initialCommand.plugin ? initialCommand.plugin === updatedCommand.plugin : true;
40
+ return initialCommand.command === updatedCommand.name && isSamePlugin;
41
41
  });
42
42
  if (updatedCommand) {
43
43
  const changedFlags = this.diffCommandProperty(initialCommand.flags, updatedCommand.flags).changedProperty;
44
44
  const changedAlias = this.diffCommandProperty(initialCommand.alias, updatedCommand.alias).changedProperty;
45
45
  const changedChars = this.diffCommandProperty(initialCommand.flagChars, updatedCommand.chars).changedProperty;
46
- const flagsChanged = changedFlags.length > 0;
47
- const aliasChanged = changedAlias.length > 0;
48
- const charsChanged = changedChars.length > 0;
49
- if (aliasChanged) {
46
+ const isFlagsChanged = changedFlags.length > 0;
47
+ const isAliasChanged = changedAlias.length > 0;
48
+ const isCharsChanged = changedChars.length > 0;
49
+ if (isAliasChanged) {
50
50
  updatedCommand.alias = changedAlias;
51
51
  }
52
- if (charsChanged) {
52
+ if (isCharsChanged) {
53
53
  updatedCommand.chars = changedChars;
54
54
  }
55
- if (flagsChanged) {
55
+ if (isFlagsChanged) {
56
56
  updatedCommand.flags = changedFlags;
57
57
  }
58
- if (flagsChanged || aliasChanged || charsChanged) {
58
+ if (isFlagsChanged || isAliasChanged || isCharsChanged) {
59
59
  diffCommands.push(updatedCommand);
60
60
  }
61
61
  }
@@ -117,10 +117,11 @@ export default class Compare extends SnapshotCommand {
117
117
  const removedProperty = difference(initial, updatedPropertyNames);
118
118
  const changedProperty = [];
119
119
  for (const update of updated) {
120
- if (addedProperty.includes(update.name)) {
121
- update.added = true;
122
- changedProperty.push(update);
120
+ if (!addedProperty.includes(update.name)) {
121
+ continue;
123
122
  }
123
+ update.added = true;
124
+ changedProperty.push(update);
124
125
  }
125
126
  for (const remove of removedProperty) {
126
127
  changedProperty.push({ name: remove, removed: true });
@@ -1,4 +1,4 @@
1
- import SnapshotCommand, { SnapshotEntry } from '../../snapshot-command.js';
1
+ import SnapshotCommand, { type SnapshotEntry } from '../../snapshot-command.js';
2
2
  export type Snapshots = SnapshotEntry[];
3
3
  export default class Generate extends SnapshotCommand {
4
4
  static flags: {
@@ -145,5 +145,5 @@
145
145
  ]
146
146
  }
147
147
  },
148
- "version": "5.4.0"
148
+ "version": "6.0.1"
149
149
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@oclif/plugin-command-snapshot",
3
3
  "description": "generates and compares OCLIF plugins snapshot files",
4
- "version": "5.4.0",
4
+ "version": "6.0.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/plugin-command-snapshot/issues",
7
7
  "bin": {
8
8
  "oclif-snapshot": "bin/run.js"
9
9
  },
10
10
  "dependencies": {
11
- "@oclif/core": "^4",
11
+ "@oclif/core": "^5.0.0",
12
12
  "ansis": "^3.17.0",
13
13
  "globby": "^14.1.0",
14
14
  "just-diff": "^5.2.0",
@@ -23,7 +23,7 @@
23
23
  "@eslint/compat": "^1.4.1",
24
24
  "@oclif/plugin-help": "^6",
25
25
  "@oclif/prettier-config": "^0.2.1",
26
- "@oclif/test": "^4",
26
+ "@oclif/test": "^5.0.0",
27
27
  "@types/chai": "^4.3.17",
28
28
  "@types/lodash.difference": "^4.5.9",
29
29
  "@types/lodash.get": "^4.4.9",
@@ -46,10 +46,10 @@
46
46
  "shx": "^0.4.0",
47
47
  "sinon": "^18.0.1",
48
48
  "ts-node": "^10.9.2",
49
- "typescript": "^5.7.3"
49
+ "typescript": "^6"
50
50
  },
51
51
  "engines": {
52
- "node": ">=18.0.0"
52
+ "node": ">=22.0.0"
53
53
  },
54
54
  "exports": "./lib/index.js",
55
55
  "files": [