Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions bolt/src/PackageConfig.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,31 @@ class PackageConfig {
}

static validate(config) {
if ((config.packageType === "base" || config.packageType === "runtime" || config.packageType === "application") &&
if (typeof config === "object" && config !== null &&
typeof config.packageType === "string" &&
typeof config.id === "string" &&
typeof config.version === "string" &&
typeof config.entryPoint === "string" &&
Comment thread
astolcenburg marked this conversation as resolved.
typeof config.name === "string") {
typeof config.name === "string" &&
(config.versionName === undefined || typeof config.versionName === "string")) {
return;
} else {
throw new Error(`Invalid config:\n ${JSON.stringify(config, null, 2)}`);
}
}

static isKnownPackageType(packageType) {
switch (packageType) {
case "base":
case "runtime":
case "application":
case "service":
case "resource":
return true;
}
return false;
}

static fromPath(path) {
try {
const data = JSON.parse(readFileSync(path));
Expand Down
12 changes: 4 additions & 8 deletions bolt/src/pack.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ const { ZIPPackageBuilder } = require('./ZIPPackageBuilder.cjs');
const { commonOptions } = require('./commonOptions.cjs');
const { exec, execv, assertFile } = require('./utils.cjs');
const { statSync, mkdirSync, rmSync, readFileSync } = require('node:fs');
const { PackageConfig } = require('./PackageConfig.cjs');

function validateConfig(config) {
if ((config.packageType === "base" || config.packageType === "runtime" || config.packageType === "application") &&
typeof config.id === "string" &&
typeof config.version === "string" &&
typeof config.versionName === "string" &&
typeof config.name === "string") {
return;
} else {
throw new Error(`Invalid config:\n ${JSON.stringify(config, null, 2)}`);
PackageConfig.validate(config);
if (!PackageConfig.isKnownPackageType(config.packageType)) {
console.warn(`Warning: Unknown packageType: ${config.packageType}`);
}
}

Expand Down