@salesforce/core 3.31.18 → 3.31.19
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/schema/validator.js +1 -0
- package/lib/sfProject.js +24 -32
- package/package.json +1 -1
package/lib/schema/validator.js
CHANGED
|
@@ -76,6 +76,7 @@ class SchemaValidator {
|
|
|
76
76
|
const externalSchemas = this.loadExternalSchemas(schema);
|
|
77
77
|
const ajv = new ajv_1.default({
|
|
78
78
|
allErrors: true,
|
|
79
|
+
allowUnionTypes: true,
|
|
79
80
|
schemas: externalSchemas,
|
|
80
81
|
useDefaults: true,
|
|
81
82
|
// TODO: We may someday want to enable strictSchema. This is disabled for now
|
package/lib/sfProject.js
CHANGED
|
@@ -59,13 +59,11 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
59
59
|
async read() {
|
|
60
60
|
const contents = await super.read();
|
|
61
61
|
this.validateKeys();
|
|
62
|
-
await this.schemaValidate();
|
|
63
62
|
return contents;
|
|
64
63
|
}
|
|
65
64
|
readSync() {
|
|
66
65
|
const contents = super.readSync();
|
|
67
66
|
this.validateKeys();
|
|
68
|
-
this.schemaValidateSync();
|
|
69
67
|
return contents;
|
|
70
68
|
}
|
|
71
69
|
async write(newContents) {
|
|
@@ -73,7 +71,6 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
73
71
|
this.setContents(newContents);
|
|
74
72
|
}
|
|
75
73
|
this.validateKeys();
|
|
76
|
-
await this.schemaValidate();
|
|
77
74
|
return super.write();
|
|
78
75
|
}
|
|
79
76
|
writeSync(newContents) {
|
|
@@ -81,7 +78,6 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
81
78
|
this.setContents(newContents);
|
|
82
79
|
}
|
|
83
80
|
this.validateKeys();
|
|
84
|
-
this.schemaValidateSync();
|
|
85
81
|
return super.writeSync();
|
|
86
82
|
}
|
|
87
83
|
getContents() {
|
|
@@ -108,21 +104,19 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
108
104
|
// read calls back into this method after necessarily setting this.hasRead=true
|
|
109
105
|
await this.read();
|
|
110
106
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
try {
|
|
108
|
+
const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
|
|
109
|
+
const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
|
|
110
|
+
await validator.validate(this.getContents());
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
const error = err;
|
|
114
|
+
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
115
|
+
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
116
|
+
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
120
|
-
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
121
|
-
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
125
|
-
}
|
|
118
|
+
else {
|
|
119
|
+
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
}
|
|
@@ -147,21 +141,19 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
147
141
|
// read calls back into this method after necessarily setting this.hasRead=true
|
|
148
142
|
this.readSync();
|
|
149
143
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
144
|
+
try {
|
|
145
|
+
const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
|
|
146
|
+
const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
|
|
147
|
+
validator.validateSync(this.getContents());
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
const error = err;
|
|
151
|
+
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
152
|
+
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
153
|
+
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
155
154
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
159
|
-
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
160
|
-
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
164
|
-
}
|
|
155
|
+
else {
|
|
156
|
+
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
165
157
|
}
|
|
166
158
|
}
|
|
167
159
|
}
|