Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hostedAt: null,
mainFile: "main.ts",
mode: Mode.development,
nightly: false,
now: x.now,
outDir: "dist",
rootDir: x.rootDir,
sassVariableGetter: "getGlobal",
sassVariables: {},
sourceDir: "src",
verbose: false,
});
export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
items: {
...Metadata.DEFAULT_ITEMS,
version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
},
warnings: Metadata.DEFAULT_WARNINGS,
underscoresAsHyphens: true,
} as const;
export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
const buildConfig = (
// We intentionally ignore any errors here; they will be handled by our Webpack plugin.
overrideBuildConfig(x.buildConfig, x.env).buildConfig
);
const {
allowJs,
id,
mainFile,
mainFile: "main.ts",
mode: Mode.development,
nightly: false,
now: x.now,
outDir: "dist",
rootDir: x.rootDir,
sassVariableGetter: "getGlobal",
sassVariables: {},
sourceDir: "src",
verbose: false,
});
export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
items: {
...Metadata.DEFAULT_ITEMS,
version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
},
warnings: Metadata.DEFAULT_WARNINGS,
underscoresAsHyphens: true,
} as const;
export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
const buildConfig = (
// We intentionally ignore any errors here; they will be handled by our Webpack plugin.
overrideBuildConfig(x.buildConfig, x.env).buildConfig
);
const {
allowJs,
id,
mainFile,
mode,
errors.some(e => e.kind !== Kind.INVALID_KEY) // Key rules cannot be customized.
? "\n" + Msg.metadataValidationHint
now: x.now,
outDir: "dist",
rootDir: x.rootDir,
sassVariableGetter: "getGlobal",
sassVariables: {},
sourceDir: "src",
verbose: false,
});
export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
items: {
...Metadata.DEFAULT_ITEMS,
version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
},
warnings: Metadata.DEFAULT_WARNINGS,
underscoresAsHyphens: true,
} as const;
export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
const buildConfig = (
// We intentionally ignore any errors here; they will be handled by our Webpack plugin.
overrideBuildConfig(x.buildConfig, x.env).buildConfig
);
const {
allowJs,
id,
mainFile,
mode,
nightly,
now,
outDir,
compilation => {
const logger = compilation.getLogger(UserscripterWebpackPlugin.name);
// Validate environment variables:
const overridden = overrideBuildConfig(w.buildConfig, w.env);
compilation.errors.push(...overridden.errors.map(compose(Error, Msg.envVarError)));
// Validate build config:
const configErrors = buildConfigErrors(overridden.buildConfig);
compilation.errors.push(...configErrors.map(compose(Error, Msg.buildConfigError)));
// Validate metadata:
const metadataValidationResult = Metadata.validateWith(w.metadataSchema)(w.metadata(w.buildConfig));
if (Metadata.isLeft(metadataValidationResult)) {
compilation.errors.push(...metadataValidationResult.Left.map(compose(Error, Msg.metadataError)));
} else {
compilation.warnings.push(...metadataValidationResult.Right.warnings.map(Msg.metadataWarning));
}
// Log metadata:
const metadataAsset = distFileName(w.buildConfig.id, "meta");
logger.info((compilation.assets[metadataAsset] as RawSource).source());
},
);
compilation => {
const logger = compilation.getLogger(UserscripterWebpackPlugin.name);
// Validate environment variables:
const overridden = overrideBuildConfig(w.buildConfig, w.env);
compilation.errors.push(...overridden.errors.map(compose(Error, Msg.envVarError)));
// Validate build config:
const configErrors = buildConfigErrors(overridden.buildConfig);
compilation.errors.push(...configErrors.map(compose(Error, Msg.buildConfigError)));
// Validate metadata:
const metadataValidationResult = Metadata.validateWith(w.metadataSchema)(w.metadata(w.buildConfig));
if (Metadata.isLeft(metadataValidationResult)) {
compilation.errors.push(...metadataValidationResult.Left.map(compose(Error, Msg.metadataError)));
} else {
compilation.warnings.push(...metadataValidationResult.Right.warnings.map(Msg.metadataWarning));
}
// Log metadata:
const metadataAsset = distFileName(w.buildConfig.id, "meta");
logger.info((compilation.assets[metadataAsset] as RawSource).source());
},
);
export const metadataError = (error: ValidationError) => {
switch (error.kind) {
case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
default: throw new Error("Unknown metadata error.");
}
}
export const metadataError = (error: ValidationError) => {
switch (error.kind) {
case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
default: throw new Error("Unknown metadata error.");
}
}
export const metadataError = (error: ValidationError) => {
switch (error.kind) {
case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
default: throw new Error("Unknown metadata error.");
}
}
export const metadataError = (error: ValidationError) => {
switch (error.kind) {
case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
default: throw new Error("Unknown metadata error.");
}
}