@cubing/dev-config 0.6.3 → 0.6.5
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 +30 -16
- 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
|
|
|
@@ -424,12 +433,17 @@ await using _ = {
|
|
|
424
433
|
[Symbol.asyncDispose]: () => tempDir.rm_rf(),
|
|
425
434
|
};
|
|
426
435
|
const extractionDir = await tempDir.join("extracted").mkdir();
|
|
436
|
+
// TODO: is there a 100% reliable way to test against paths that *will* be packed?
|
|
437
|
+
// Note that this has to take into account `.gitignore`, `.npmignore`, and `"files"` — with globs and excludes.
|
|
438
|
+
// For now, we print the command to make it clear that some heavy lifting is going on (and that it's not our fault that it's slow).
|
|
427
439
|
const data: { filename: string }[] = await new PrintableShellCommand("npm", [
|
|
428
440
|
"pack",
|
|
429
441
|
"--json",
|
|
430
442
|
"--ignore-scripts",
|
|
431
443
|
["--pack-destination", tempDir],
|
|
432
|
-
])
|
|
444
|
+
])
|
|
445
|
+
.print()
|
|
446
|
+
.json();
|
|
433
447
|
const tgzPath = tempDir.join(data[0].filename);
|
|
434
448
|
await new PrintableShellCommand("tar", [
|
|
435
449
|
["-C", extractionDir],
|
|
@@ -500,14 +514,14 @@ function checkPath(
|
|
|
500
514
|
// TODO: allow folders (with a required trailing slash)?
|
|
501
515
|
if (!(await resolvedPath.existsAsFile())) {
|
|
502
516
|
exitCode = 1;
|
|
503
|
-
return `❌ ${breadcrumbString} —
|
|
517
|
+
return `❌ ${breadcrumbString} — Path is not present on disk. — ${value}`;
|
|
504
518
|
}
|
|
505
519
|
if (options.mustBeExecutable) {
|
|
506
520
|
if (!((await resolvedPath.stat()).mode ^ constants.X_OK)) {
|
|
507
521
|
// This is not considered fixable because the binary may be the output
|
|
508
522
|
// of a build process. In that case, the build process is responsible
|
|
509
523
|
// for marking it as executable.
|
|
510
|
-
return `❌ ${breadcrumbString} —
|
|
524
|
+
return `❌ ${breadcrumbString} — File at path must be executable — ${value}`;
|
|
511
525
|
}
|
|
512
526
|
}
|
|
513
527
|
return `✅ ${breadcrumbString} — OK — ${value}`;
|