@oclif/plugin-command-snapshot 6.0.0 → 6.0.2
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/lib/commands/schema/compare.d.ts +2 -2
- package/lib/commands/schema/compare.js +7 -7
- package/lib/commands/schema/generate.d.ts +6 -8
- package/lib/commands/schema/generate.js +6 -6
- package/lib/commands/snapshot/compare.d.ts +3 -3
- package/lib/commands/snapshot/compare.js +13 -12
- package/lib/commands/snapshot/generate.d.ts +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -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:
|
|
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
|
|
70
|
-
const basePath =
|
|
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(
|
|
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(
|
|
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
|
|
115
|
-
const schemasDir =
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
40
|
-
return initialCommand.command === updatedCommand.name &&
|
|
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
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
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 (
|
|
52
|
+
if (isCharsChanged) {
|
|
53
53
|
updatedCommand.chars = changedChars;
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
55
|
+
if (isFlagsChanged) {
|
|
56
56
|
updatedCommand.flags = changedFlags;
|
|
57
57
|
}
|
|
58
|
-
if (
|
|
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
|
-
|
|
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: {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-command-snapshot",
|
|
3
3
|
"description": "generates and compares OCLIF plugins snapshot files",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-command-snapshot/issues",
|
|
7
7
|
"bin": {
|