@cubing/dev-config 0.6.3 → 0.6.4
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/bin/package.json.ts +24 -15
- package/package.json +1 -1
package/bin/package.json.ts
CHANGED
|
@@ -260,8 +260,11 @@ function field<T>(
|
|
|
260
260
|
optional?: boolean;
|
|
261
261
|
additionalChecks?: { [requirementMessage: string]: (t: T) => boolean };
|
|
262
262
|
skipPrintingSuccess?: boolean;
|
|
263
|
+
mustBePopulatedMessage?: string;
|
|
263
264
|
},
|
|
264
265
|
) {
|
|
266
|
+
const mustBePopulatedMessage = () =>
|
|
267
|
+
options?.mustBePopulatedMessage ?? "Field must be populated.";
|
|
265
268
|
const { breadcrumbString, maybeValue } = traverse(breadcrumbs);
|
|
266
269
|
if (!maybeValue) {
|
|
267
270
|
if (options?.optional) {
|
|
@@ -270,7 +273,7 @@ function field<T>(
|
|
|
270
273
|
}
|
|
271
274
|
return;
|
|
272
275
|
} else {
|
|
273
|
-
console.log(`❌ ${breadcrumbString} —
|
|
276
|
+
console.log(`❌ ${breadcrumbString} — ${mustBePopulatedMessage()}`);
|
|
274
277
|
exitCode = 1;
|
|
275
278
|
return;
|
|
276
279
|
}
|
|
@@ -294,9 +297,11 @@ function field<T>(
|
|
|
294
297
|
}
|
|
295
298
|
} else {
|
|
296
299
|
if (category === "undefined") {
|
|
297
|
-
console.log(`❌ ${breadcrumbString} —
|
|
300
|
+
console.log(`❌ ${breadcrumbString} — ${mustBePopulatedMessage()}.`);
|
|
298
301
|
} else if (type === "undefined") {
|
|
299
|
-
console.log(
|
|
302
|
+
console.log(
|
|
303
|
+
`❌ ${breadcrumbString} — Field is populated (but must not be).`,
|
|
304
|
+
);
|
|
300
305
|
} else {
|
|
301
306
|
if (Array.isArray(type)) {
|
|
302
307
|
console.log(
|
|
@@ -313,7 +318,7 @@ function field<T>(
|
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
320
|
|
|
316
|
-
function
|
|
321
|
+
function mustNotBePopulated(breadcrumbs: Breadcrumbs) {
|
|
317
322
|
const { breadcrumbString, maybeValue } = traverse(breadcrumbs);
|
|
318
323
|
if (maybeValue) {
|
|
319
324
|
console.log(`❌ ${breadcrumbString} — Must not be present.`);
|
|
@@ -393,6 +398,19 @@ field(["type"], "string", {
|
|
|
393
398
|
'Type must be `"module"`.': (type: string) => type === "module",
|
|
394
399
|
},
|
|
395
400
|
});
|
|
401
|
+
if ("main" in packageJSON || "types" in packageJSON) {
|
|
402
|
+
field(["main"], "string", {
|
|
403
|
+
mustBePopulatedMessage: 'Must be populated if "types" is populated.',
|
|
404
|
+
});
|
|
405
|
+
field(["types"], "string", {
|
|
406
|
+
mustBePopulatedMessage: 'Must be populated if "main" is populated.',
|
|
407
|
+
});
|
|
408
|
+
} else {
|
|
409
|
+
console.log("☑️ .main");
|
|
410
|
+
console.log("☑️ .types");
|
|
411
|
+
}
|
|
412
|
+
mustNotBePopulated(["module"]);
|
|
413
|
+
mustNotBePopulated(["browser"]);
|
|
396
414
|
field(["exports"], "object");
|
|
397
415
|
field(["bin"], "object", { optional: true });
|
|
398
416
|
field(["dependencies"], "object", { optional: true });
|
|
@@ -407,15 +425,6 @@ field(["files"], "array");
|
|
|
407
425
|
field(["scripts"], "object");
|
|
408
426
|
// Set to `"# no-op"` if needed.
|
|
409
427
|
field(["scripts", "prepublishOnly"], "string");
|
|
410
|
-
if ("main" in packageJSON || "types" in packageJSON) {
|
|
411
|
-
field(["main"], "string");
|
|
412
|
-
field(["types"], "string");
|
|
413
|
-
} else {
|
|
414
|
-
console.log("☑️ .main");
|
|
415
|
-
console.log("☑️ .types");
|
|
416
|
-
}
|
|
417
|
-
mustNotBePresent(["module"]);
|
|
418
|
-
mustNotBePresent(["browser"]);
|
|
419
428
|
|
|
420
429
|
console.log("Checking paths of binaries and exports:");
|
|
421
430
|
|
|
@@ -500,14 +509,14 @@ function checkPath(
|
|
|
500
509
|
// TODO: allow folders (with a required trailing slash)?
|
|
501
510
|
if (!(await resolvedPath.existsAsFile())) {
|
|
502
511
|
exitCode = 1;
|
|
503
|
-
return `❌ ${breadcrumbString} —
|
|
512
|
+
return `❌ ${breadcrumbString} — Path is not present on disk. — ${value}`;
|
|
504
513
|
}
|
|
505
514
|
if (options.mustBeExecutable) {
|
|
506
515
|
if (!((await resolvedPath.stat()).mode ^ constants.X_OK)) {
|
|
507
516
|
// This is not considered fixable because the binary may be the output
|
|
508
517
|
// of a build process. In that case, the build process is responsible
|
|
509
518
|
// for marking it as executable.
|
|
510
|
-
return `❌ ${breadcrumbString} —
|
|
519
|
+
return `❌ ${breadcrumbString} — File at path must be executable — ${value}`;
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
return `✅ ${breadcrumbString} — OK — ${value}`;
|