New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@secretlint/config-loader

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secretlint/config-loader - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1-next.19

24

lib/index.d.ts

@@ -1,2 +0,7 @@

import { SecretLintConfigDescriptor, SecretLintCoreDescriptor, SecretLintUnionRuleCreator } from "@secretlint/types";
import { SecretLintConfigDescriptor, SecretLintCoreDescriptor, SecretLintUnionRuleCreator, SecretLintRuleModule } from "@secretlint/types";
export declare function importSecretlintCreator(moduleExports?: SecretLintRuleModule): SecretLintUnionRuleCreator;
export declare class AggregateError extends Error {
errors: Error[];
constructor(errors: Error[], message: string);
}
export declare type SecretLintConfigLoaderOptions = {

@@ -24,7 +29,2 @@ cwd?: string;

configFilePath: string;
} | {
ok: false;
configFilePath?: string;
rawConfig?: SecretLintConfigDescriptor;
errors: Error[];
};

@@ -35,5 +35,2 @@ export declare type SecretLintConfigLoaderRawResult = {

rawConfig: SecretLintConfigDescriptor;
} | {
ok: false;
errors: Error[];
};

@@ -63,5 +60,2 @@ export declare type SecretLintLoadPackagesFromRawConfigOptions = {

config: SecretLintCoreDescriptor;
} | {
ok: false;
errors: Error[];
};

@@ -72,3 +66,3 @@ /**

*/
export declare const loadPackagesFromRawConfig: (options: SecretLintLoadPackagesFromRawConfigOptions) => SecretLintLoadPackagesFromRawConfigResult;
export declare const loadPackagesFromRawConfig: (options: SecretLintLoadPackagesFromRawConfigOptions) => Promise<SecretLintLoadPackagesFromRawConfigResult>;
/**

@@ -78,3 +72,3 @@ * Load config file and return config object that is loaded rule instance.

*/
export declare const loadConfig: (options: SecretLintConfigLoaderOptions) => SecretLintConfigLoaderResult;
export declare const loadConfig: (options: SecretLintConfigLoaderOptions) => Promise<SecretLintConfigLoaderResult>;
/**

@@ -85,2 +79,2 @@ * Load config file and return config object that is not loaded rule instance

*/
export declare const loadRawConfig: (options: SecretLintConfigLoaderOptions) => SecretLintConfigLoaderRawResult;
export declare const loadRawConfig: (options: SecretLintConfigLoaderOptions) => Promise<SecretLintConfigLoaderRawResult>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadRawConfig = exports.loadConfig = exports.loadPackagesFromRawConfig = void 0;
exports.loadRawConfig = exports.loadConfig = exports.loadPackagesFromRawConfig = exports.AggregateError = exports.importSecretlintCreator = void 0;
const rc_config_loader_1 = require("rc-config-loader");
const profiler_1 = require("@secretlint/profiler");
const SecretLintModuleResolver_1 = require("./SecretLintModuleResolver");
const module_interop_1 = require("@textlint/module-interop");
const config_validator_1 = require("@secretlint/config-validator");
function importSecretlintCreator(moduleExports) {
if (!moduleExports) {
throw new Error("Secretlint rule should export { creator }. module is undefined");
}
if (!("creator" in moduleExports)) {
throw new Error("Secretlint rule should export { creator }. module does not export creator object.");
}
return moduleExports.creator;
}
exports.importSecretlintCreator = importSecretlintCreator;
class AggregateError extends Error {
constructor(errors, message) {
const detailsMessage = errors.map((error) => error.message).join("\n\n");
super(message + "\n\n" + detailsMessage);
this.errors = errors;
}
}
exports.AggregateError = AggregateError;
// FIXME: https://github.com/microsoft/TypeScript/issues/43329
// module: node12 will be replace it
const _importDynamic = new Function("modulePath", "return import(modulePath)");
/**

@@ -13,10 +33,7 @@ * Load packages in RawConfig and return loaded config object

*/
const loadPackagesFromRawConfig = (options) => {
const loadPackagesFromRawConfig = async (options) => {
// Early validation, validate rawConfig by JSON Schema
const resultValidateRawConfig = config_validator_1.validateRawConfig(options.rawConfig);
const resultValidateRawConfig = (0, config_validator_1.validateRawConfig)(options.rawConfig);
if (!resultValidateRawConfig.ok) {
return {
ok: false,
errors: [resultValidateRawConfig.error],
};
throw resultValidateRawConfig.error;
}

@@ -32,3 +49,3 @@ profiler_1.secretLintProfiler.mark({

const rules = [];
options.rawConfig.rules.forEach((configDescriptorRule) => {
for (const configDescriptorRule of options.rawConfig.rules) {
try {

@@ -46,3 +63,3 @@ profiler_1.secretLintProfiler.mark({

? replacedDefinition.rule
: module_interop_1.moduleInterop(require(moduleResolver.resolveRulePackageName(configDescriptorRule.id)));
: importSecretlintCreator(await _importDynamic(moduleResolver.resolveRulePackageName(configDescriptorRule.id)));
const secretLintConfigDescriptorRules = "rules" in configDescriptorRule && Array.isArray(configDescriptorRule.rules)

@@ -66,5 +83,5 @@ ? configDescriptorRule.rules.filter((rule) => rule !== undefined)

catch (error) {
errors.push(error);
errors.push(error instanceof Error ? error : new Error(String(error)));
}
});
}
profiler_1.secretLintProfiler.mark({

@@ -74,6 +91,3 @@ type: "@config-loader>resolve-modules::end",

if (errors.length > 0) {
return {
ok: false,
errors,
};
throw new AggregateError(errors, "secretlint loading errors");
}

@@ -86,8 +100,5 @@ const loadedConfig = {

// This validator require actual `rule` creator for `disabledMessage` option.
const resultValidateConfig = config_validator_1.validateConfig(loadedConfig);
const resultValidateConfig = (0, config_validator_1.validateConfig)(loadedConfig);
if (!resultValidateConfig.ok) {
return {
ok: false,
errors: [resultValidateConfig.error],
};
throw resultValidateConfig.error;
}

@@ -104,20 +115,14 @@ return {

*/
const loadConfig = (options) => {
const loadConfig = async (options) => {
profiler_1.secretLintProfiler.mark({
type: "@config-loader>load-config-file::start",
});
const rawResult = exports.loadRawConfig(options);
const rawResult = await (0, exports.loadRawConfig)(options);
profiler_1.secretLintProfiler.mark({
type: "@config-loader>load-config-file::end",
});
if (!rawResult.ok) {
return {
ok: false,
errors: rawResult.errors,
};
}
profiler_1.secretLintProfiler.mark({
type: "@config-loader>load-packages::start",
});
const result = exports.loadPackagesFromRawConfig({
const result = await (0, exports.loadPackagesFromRawConfig)({
rawConfig: rawResult.rawConfig,

@@ -130,9 +135,2 @@ node_moduleDir: options.node_moduleDir,

});
if (!result.ok) {
return {
ok: false,
configFilePath: rawResult.configFilePath,
errors: result.errors,
};
}
return {

@@ -150,37 +148,24 @@ ok: true,

*/
const loadRawConfig = (options) => {
try {
const results = rc_config_loader_1.rcFile("secretlint", {
cwd: options.cwd,
configFileName: options.configFilePath,
packageJSON: {
fieldName: "secretlint",
},
});
// Not Found
if (!results) {
return {
ok: false,
errors: [
new Error(`secretlint config is not found
const loadRawConfig = async (options) => {
const results = (0, rc_config_loader_1.rcFile)("secretlint", {
cwd: options.cwd,
configFileName: options.configFilePath,
packageJSON: {
fieldName: "secretlint",
},
});
// Not Found
if (!results) {
throw new Error(`secretlint config is not found
Secrelint require .secretlintrc config file.
The config file define the use of rules.`),
],
};
}
return {
ok: true,
rawConfig: results.config,
configFilePath: results.filePath,
};
The config file define the use of rules.`);
}
catch (error) {
return {
ok: false,
errors: [error],
};
}
return {
ok: true,
rawConfig: results.config,
configFilePath: results.filePath,
};
};
exports.loadRawConfig = loadRawConfig;
//# sourceMappingURL=index.js.map

@@ -57,3 +57,3 @@ // LICENSE : MIT

const baseDir = this.baseDirectory;
const fullPackageName = package_name_util_1.createFullPackageName("secretlint-rule-", packageName);
const fullPackageName = (0, package_name_util_1.createFullPackageName)("secretlint-rule-", packageName);
// <rule-name> or secretlint-rule-<rule-name>

@@ -78,3 +78,3 @@ const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));

const baseDir = this.baseDirectory;
const fullPackageName = package_name_util_1.createFullPackageName("secretlint-filter-rule-", packageName);
const fullPackageName = (0, package_name_util_1.createFullPackageName)("secretlint-filter-rule-", packageName);
// <rule-name> or secretlint-filter-rule-<rule-name> or @scope/<rule-name>

@@ -99,3 +99,3 @@ const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));

const baseDir = this.baseDirectory;
const fullPackageName = package_name_util_1.createFullPackageName("secretlint-plugin-", packageName);
const fullPackageName = (0, package_name_util_1.createFullPackageName)("secretlint-plugin-", packageName);
// <plugin-name> or secretlint-plugin-<rule-name>

@@ -141,3 +141,3 @@ const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));

.replace(/^@([^/]+)\/preset-(.*)$/, `@$1/$2`);
const fullPackageName = package_name_util_1.createFullPackageName(PREFIX, packageNameWithoutPreset);
const fullPackageName = (0, package_name_util_1.createFullPackageName)(PREFIX, packageNameWithoutPreset);
const fullFullPackageName = `${PREFIX}${packageNameWithoutPreset}`;

@@ -171,3 +171,3 @@ const pkgPath =

const baseDir = this.baseDirectory;
const fullPackageName = package_name_util_1.createFullPackageName("secretlint-config-", packageName);
const fullPackageName = (0, package_name_util_1.createFullPackageName)("secretlint-config-", packageName);
// <plugin-name> or secretlint-config-<rule-name>

@@ -174,0 +174,0 @@ const pkgPath = tryResolve(path.join(baseDir, fullPackageName)) || tryResolve(path.join(baseDir, packageName));

{
"name": "@secretlint/config-loader",
"version": "3.3.0",
"version": "3.3.1-next.19+2c93303",
"description": "Config loader for secretlint.",

@@ -21,7 +21,2 @@ "keywords": [

"author": "azu",
"files": [
"bin/",
"lib/",
"src/"
],
"main": "lib/index.js",

@@ -33,2 +28,7 @@ "types": "lib/index.d.ts",

},
"files": [
"bin/",
"lib/",
"src/"
],
"scripts": {

@@ -48,14 +48,13 @@ "build": "cross-env NODE_ENV=production tsc -p .",

"dependencies": {
"@secretlint/config-validator": "^3.3.0",
"@secretlint/profiler": "^3.1.0",
"@secretlint/types": "^3.3.0",
"@textlint/module-interop": "^1.0.2",
"@secretlint/config-validator": "^3.3.1-next.19+2c93303",
"@secretlint/profiler": "^3.3.1-next.19+2c93303",
"@secretlint/types": "^3.3.1-next.19+2c93303",
"debug": "^4.1.1",
"rc-config-loader": "^3.0.0",
"rc-config-loader": "^4.0.0",
"try-resolve": "^1.0.1"
},
"devDependencies": {
"@secretlint/secretlint-rule-example": "^3.3.0",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.41",
"@secretlint/secretlint-rule-example": "^3.3.1-next.19+2c93303",
"@types/mocha": "^9.0.0",
"@types/node": "^16.9.1",
"cross-env": "^7.0.3",

@@ -69,6 +68,9 @@ "mocha": "^9.0.1",

},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"publishConfig": {
"access": "public"
},
"gitHead": "f6ee7794184c8cfb89c0bcd87e11e58d99301b25"
"gitHead": "2c93303d1fd60f10601af494489dc55eeb5669a8"
}

@@ -8,8 +8,31 @@ import { rcFile } from "rc-config-loader";

SecretLintUnionRuleCreator,
SecretLintRuleModule,
} from "@secretlint/types";
import { secretLintProfiler } from "@secretlint/profiler";
import { SecretLintModuleResolver } from "./SecretLintModuleResolver";
import { moduleInterop } from "@textlint/module-interop";
import { validateConfig, validateRawConfig } from "@secretlint/config-validator";
export function importSecretlintCreator(moduleExports?: SecretLintRuleModule): SecretLintUnionRuleCreator {
if (!moduleExports) {
throw new Error("Secretlint rule should export { creator }. module is undefined");
}
if (!("creator" in moduleExports)) {
throw new Error("Secretlint rule should export { creator }. module does not export creator object.");
}
return moduleExports.creator;
}
export class AggregateError extends Error {
errors: Error[];
constructor(errors: Error[], message: string) {
const detailsMessage = errors.map((error) => error.message).join("\n\n");
super(message + "\n\n" + detailsMessage);
this.errors = errors;
}
}
// FIXME: https://github.com/microsoft/TypeScript/issues/43329
// module: node12 will be replace it
const _importDynamic = new Function("modulePath", "return import(modulePath)");
export type SecretLintConfigLoaderOptions = {

@@ -34,26 +57,13 @@ cwd?: string;

};
export type SecretLintConfigLoaderResult =
| {
ok: true;
config: SecretLintCoreDescriptor; // Core Option object
configFilePath: string;
}
| {
// load config error
ok: false;
configFilePath?: string;
rawConfig?: SecretLintConfigDescriptor; // Config Raw object
errors: Error[];
};
export type SecretLintConfigLoaderResult = {
ok: true;
config: SecretLintCoreDescriptor; // Core Option object
configFilePath: string;
};
export type SecretLintConfigLoaderRawResult =
| {
ok: true;
configFilePath: string;
rawConfig: SecretLintConfigDescriptor; // Config Raw object
}
| {
ok: false;
errors: Error[];
};
export type SecretLintConfigLoaderRawResult = {
ok: true;
configFilePath: string;
rawConfig: SecretLintConfigDescriptor; // Config Raw object
};
export type SecretLintLoadPackagesFromRawConfigOptions = {

@@ -79,12 +89,6 @@ /**

};
export type SecretLintLoadPackagesFromRawConfigResult =
| {
ok: true;
config: SecretLintCoreDescriptor; // Core Option object
}
| {
// load config error
ok: false;
errors: Error[];
};
export type SecretLintLoadPackagesFromRawConfigResult = {
ok: true;
config: SecretLintCoreDescriptor; // Core Option object
};

@@ -95,12 +99,9 @@ /**

*/
export const loadPackagesFromRawConfig = (
export const loadPackagesFromRawConfig = async (
options: SecretLintLoadPackagesFromRawConfigOptions
): SecretLintLoadPackagesFromRawConfigResult => {
): Promise<SecretLintLoadPackagesFromRawConfigResult> => {
// Early validation, validate rawConfig by JSON Schema
const resultValidateRawConfig = validateRawConfig(options.rawConfig);
if (!resultValidateRawConfig.ok) {
return {
ok: false,
errors: [resultValidateRawConfig.error],
};
throw resultValidateRawConfig.error;
}

@@ -116,3 +117,3 @@ secretLintProfiler.mark({

const rules: SecretLintCoreDescriptorUnionRule[] = [];
options.rawConfig.rules.forEach((configDescriptorRule) => {
for (const configDescriptorRule of options.rawConfig.rules) {
try {

@@ -131,3 +132,5 @@ secretLintProfiler.mark({

? replacedDefinition.rule
: moduleInterop(require(moduleResolver.resolveRulePackageName(configDescriptorRule.id)));
: importSecretlintCreator(
await _importDynamic(moduleResolver.resolveRulePackageName(configDescriptorRule.id))
);
const secretLintConfigDescriptorRules: SecretLintCoreDescriptorRule[] | undefined =

@@ -154,5 +157,5 @@ "rules" in configDescriptorRule && Array.isArray(configDescriptorRule.rules)

} catch (error) {
errors.push(error);
errors.push(error instanceof Error ? error : new Error(String(error)));
}
});
}
secretLintProfiler.mark({

@@ -162,6 +165,3 @@ type: "@config-loader>resolve-modules::end",

if (errors.length > 0) {
return {
ok: false,
errors,
};
throw new AggregateError(errors, "secretlint loading errors");
}

@@ -176,6 +176,3 @@ const loadedConfig: SecretLintCoreDescriptor = {

if (!resultValidateConfig.ok) {
return {
ok: false,
errors: [resultValidateConfig.error],
};
throw resultValidateConfig.error;
}

@@ -191,20 +188,14 @@ return {

*/
export const loadConfig = (options: SecretLintConfigLoaderOptions): SecretLintConfigLoaderResult => {
export const loadConfig = async (options: SecretLintConfigLoaderOptions): Promise<SecretLintConfigLoaderResult> => {
secretLintProfiler.mark({
type: "@config-loader>load-config-file::start",
});
const rawResult = loadRawConfig(options);
const rawResult = await loadRawConfig(options);
secretLintProfiler.mark({
type: "@config-loader>load-config-file::end",
});
if (!rawResult.ok) {
return {
ok: false,
errors: rawResult.errors,
};
}
secretLintProfiler.mark({
type: "@config-loader>load-packages::start",
});
const result = loadPackagesFromRawConfig({
const result = await loadPackagesFromRawConfig({
rawConfig: rawResult.rawConfig,

@@ -217,9 +208,2 @@ node_moduleDir: options.node_moduleDir,

});
if (!result.ok) {
return {
ok: false,
configFilePath: rawResult.configFilePath,
errors: result.errors,
};
}
return {

@@ -236,34 +220,24 @@ ok: true,

*/
export const loadRawConfig = (options: SecretLintConfigLoaderOptions): SecretLintConfigLoaderRawResult => {
try {
const results = rcFile<SecretLintConfigDescriptor>("secretlint", {
cwd: options.cwd,
configFileName: options.configFilePath,
packageJSON: {
fieldName: "secretlint",
},
});
// Not Found
if (!results) {
return {
ok: false,
errors: [
new Error(`secretlint config is not found
export const loadRawConfig = async (
options: SecretLintConfigLoaderOptions
): Promise<SecretLintConfigLoaderRawResult> => {
const results = rcFile<SecretLintConfigDescriptor>("secretlint", {
cwd: options.cwd,
configFileName: options.configFilePath,
packageJSON: {
fieldName: "secretlint",
},
});
// Not Found
if (!results) {
throw new Error(`secretlint config is not found
Secrelint require .secretlintrc config file.
The config file define the use of rules.`),
],
};
}
return {
ok: true,
rawConfig: results.config,
configFilePath: results.filePath,
};
} catch (error) {
return {
ok: false,
errors: [error],
};
The config file define the use of rules.`);
}
return {
ok: true,
rawConfig: results.config,
configFilePath: results.filePath,
};
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc