Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@artus/core

Package Overview
Dependencies
Maintainers
7
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@artus/core - npm Package Compare versions

Comparing version 1.0.0-beta.11 to 1.0.0-beta.12

1

lib/constant.d.ts

@@ -29,2 +29,3 @@ export declare const DEFAULT_LOADER = "module";

export declare const DEFAULT_EXCLUDES: string[];
export declare const DEFAULT_EXTENSIONS: string[];
export declare const FRAMEWORK_PATTERN = "framework.*";

@@ -31,0 +32,0 @@ export declare const PLUGIN_CONFIG_PATTERN = "plugin.*";

3

lib/constant.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_CONFIG_DIR = exports.DEFAULT_LOADER_LIST_WITH_ORDER = exports.EXCEPTION_FILE = exports.PACKAGE_JSON = exports.PLUGIN_META = exports.CONFIG_PATTERN = exports.PLUGIN_CONFIG_PATTERN = exports.FRAMEWORK_PATTERN = exports.DEFAULT_EXCLUDES = exports.HOOK_CONFIG_HANDLE = exports.HOOK_FILE_LOADER = exports.CONSTRUCTOR_PARAMS_CONTEXT = exports.CONSTRUCTOR_PARAMS_CONTAINER = exports.CONSTRUCTOR_PARAMS_APP = exports.CONSTRUCTOR_PARAMS = exports.HOOK_NAME_META_PREFIX = exports.ARTUS_DEFAULT_CONFIG_ENV = exports.ARTUS_SERVER_ENV = exports.ARTUS_EXCEPTION_DEFAULT_LOCALE = exports.ArtusInjectEnum = exports.ArtusInjectPrefix = exports.LOADER_NAME_META = exports.DEFAULT_LOADER = void 0;
exports.DEFAULT_CONFIG_DIR = exports.DEFAULT_LOADER_LIST_WITH_ORDER = exports.EXCEPTION_FILE = exports.PACKAGE_JSON = exports.PLUGIN_META = exports.CONFIG_PATTERN = exports.PLUGIN_CONFIG_PATTERN = exports.FRAMEWORK_PATTERN = exports.DEFAULT_EXTENSIONS = exports.DEFAULT_EXCLUDES = exports.HOOK_CONFIG_HANDLE = exports.HOOK_FILE_LOADER = exports.CONSTRUCTOR_PARAMS_CONTEXT = exports.CONSTRUCTOR_PARAMS_CONTAINER = exports.CONSTRUCTOR_PARAMS_APP = exports.CONSTRUCTOR_PARAMS = exports.HOOK_NAME_META_PREFIX = exports.ARTUS_DEFAULT_CONFIG_ENV = exports.ARTUS_SERVER_ENV = exports.ARTUS_EXCEPTION_DEFAULT_LOCALE = exports.ArtusInjectEnum = exports.ArtusInjectPrefix = exports.LOADER_NAME_META = exports.DEFAULT_LOADER = void 0;
exports.DEFAULT_LOADER = 'module';

@@ -44,2 +44,3 @@ exports.LOADER_NAME_META = 'loader:name';

];
exports.DEFAULT_EXTENSIONS = ['.js', '.json', '.node', '.yaml'];
exports.FRAMEWORK_PATTERN = 'framework.*';

@@ -46,0 +47,0 @@ exports.PLUGIN_CONFIG_PATTERN = 'plugin.*';

import { ConfigObject } from '../configuration';
import { ManifestItem } from '../types';
import { ManifestItem, Metadata } from '../types';
export interface FrameworkConfig {

@@ -13,2 +13,3 @@ path?: string;

static handle(root: string, config: FrameworkConfig): Promise<string>;
static checkAndLoadMetadata(frameworkDir: string): Promise<Metadata>;
}

@@ -7,2 +7,4 @@ "use strict";

const configuration_1 = tslib_1.__importDefault(require("../configuration"));
const fs_1 = require("../utils/fs");
const load_meta_file_1 = require("../utils/load_meta_file");
class FrameworkHandler {

@@ -32,4 +34,39 @@ static async mergeConfig(env, frameworks, done) {

}
static async checkAndLoadMetadata(frameworkDir) {
// check import path
if (!await (0, fs_1.exisis)(frameworkDir)) {
throw new Error(`load framework import path ${frameworkDir} is not exists.`);
}
let find = false;
const fileNameList = [
'meta.yaml',
'meta.yml',
'meta.json',
];
let metadata;
for (const fileName of fileNameList) {
const metaFilePath = path_1.default.resolve(frameworkDir, fileName);
try {
if (!await (0, fs_1.exisis)(metaFilePath)) {
continue;
}
metadata = await (0, load_meta_file_1.loadMetaFile)({
path: metaFilePath,
extname: path_1.default.extname(metaFilePath),
filename: fileName,
});
find = true;
break;
}
catch (e) {
throw new Error(`load framework metadata <${frameworkDir}> failed, err: ${e}`);
}
}
if (!find) {
throw new Error(`load framework import path ${frameworkDir} can't find meta file.`);
}
return metadata;
}
}
exports.FrameworkHandler = FrameworkHandler;
//# sourceMappingURL=handler.js.map

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

import { Metadata } from '../types';
export declare enum PluginType {

@@ -5,7 +6,5 @@ simple = "simple",

}
export interface PluginMetadata {
name: string;
export interface PluginMetadata extends Metadata {
dependencies?: PluginDependencyItem[];
type?: PluginType;
configDir?: string;
}

@@ -12,0 +11,0 @@ export interface PluginDependencyItem {

@@ -5,3 +5,2 @@ import 'reflect-metadata';

export declare class Scanner {
private moduleExtensions;
private options;

@@ -22,4 +21,5 @@ private itemMap;

private formatWalkOptions;
private amendOptions;
private getItemsFromMap;
private writeFile;
}

@@ -18,7 +18,6 @@ "use strict";

var _a, _b;
this.moduleExtensions = ['.js', '.json', '.node'];
this.itemMap = new Map();
this.tmpConfigStore = new Map();
this.configHandle = new configuration_1.default();
this.options = Object.assign(Object.assign({ appName: 'app', needWriteFile: true, useRelativePath: true, configDir: constant_1.DEFAULT_CONFIG_DIR, loaderListGenerator: (defaultLoaderList) => defaultLoaderList }, options), { excluded: constant_1.DEFAULT_EXCLUDES.concat((_a = options.excluded) !== null && _a !== void 0 ? _a : []), extensions: [...new Set(this.moduleExtensions.concat((_b = options.extensions) !== null && _b !== void 0 ? _b : [], ['.yaml']))] });
this.options = Object.assign(Object.assign({ appName: 'app', needWriteFile: true, useRelativePath: true, configDir: constant_1.DEFAULT_CONFIG_DIR, loaderListGenerator: (defaultLoaderList) => defaultLoaderList }, options), { exclude: [...new Set(constant_1.DEFAULT_EXCLUDES.concat((_a = options.exclude) !== null && _a !== void 0 ? _a : []))], extensions: [...new Set(constant_1.DEFAULT_EXTENSIONS.concat((_b = options.extensions) !== null && _b !== void 0 ? _b : []))] });
}

@@ -73,3 +72,5 @@ async initItemMap() {

for (const frameworkDir of frameworkDirs) {
await this.walk(frameworkDir, this.formatWalkOptions('framework', frameworkDir));
const frameworkMetadata = await framework_1.FrameworkHandler.checkAndLoadMetadata(frameworkDir);
const frameworkOptions = this.formatWalkOptions('framework', frameworkDir, frameworkDir, frameworkMetadata);
await this.walk(frameworkDir, frameworkOptions);
}

@@ -87,3 +88,4 @@ // 2. scan all file in plugin

this.setPluginMeta(plugin);
await this.walk(plugin.importPath, this.formatWalkOptions('plugin', plugin.importPath, plugin.name, plugin.metadata.configDir));
const pluginOpts = this.formatWalkOptions('plugin', plugin.importPath, plugin.name, plugin.metadata);
await this.walk(plugin.importPath, pluginOpts);
}

@@ -126,3 +128,3 @@ // 3. scan all file in app

const extname = path.extname(filename);
if (utils_1.ScanUtils.isExclude(filename, extname, this.options.excluded, this.options.extensions)) {
if (utils_1.ScanUtils.isExclude(filename, extname, this.options.exclude, this.options.extensions)) {
return null;

@@ -178,11 +180,11 @@ }

}
formatWalkOptions(source, baseDir, unitName, configDir) {
formatWalkOptions(source, baseDir, unitName, metadata) {
const commonOptions = {
extensions: this.options.extensions,
excluded: this.options.excluded,
exclude: this.options.exclude,
itemMap: this.itemMap,
};
unitName !== null && unitName !== void 0 ? unitName : (unitName = baseDir);
configDir !== null && configDir !== void 0 ? configDir : (configDir = this.options.configDir);
return Object.assign({}, commonOptions, {
const configDir = this.options.configDir;
let result = Object.assign({}, commonOptions, {
source,

@@ -193,3 +195,31 @@ baseDir,

});
// metadata takes priority
if (metadata) {
result = this.amendOptions(result, metadata);
}
return result;
}
amendOptions(walkOptions, metadata) {
// plugin/framework exclude take priority over user app's
if (metadata === null || metadata === void 0 ? void 0 : metadata.exclude) {
walkOptions.exclude = constant_1.DEFAULT_EXCLUDES.concat(metadata.exclude);
}
else {
walkOptions.exclude = constant_1.DEFAULT_EXCLUDES;
}
// plugin/framework extensions take priority over user app's
// if (metadata?.extensions) {
// walkOptions.extensions = DEFAULT_EXTENSIONS.concat(metadata.extensions);
// } else {
// walkOptions.extensions = DEFAULT_EXTENSIONS;
// }
// plugin/framework configDir take priority over user app's
if (metadata === null || metadata === void 0 ? void 0 : metadata.configDir) {
walkOptions.configDir = metadata.configDir;
}
else {
walkOptions.configDir = constant_1.DEFAULT_CONFIG_DIR;
}
return walkOptions;
}
getItemsFromMap(relative, appRoot) {

@@ -196,0 +226,0 @@ let items = [];

@@ -7,3 +7,3 @@ import { BaseLoader, ManifestItem } from "../loader";

useRelativePath: boolean;
excluded: string[];
exclude: string[];
configDir: string;

@@ -18,3 +18,3 @@ envs?: string[];

extensions: string[];
excluded: string[];
exclude: string[];
itemMap: Map<string, ManifestItem[]>;

@@ -21,0 +21,0 @@ unitName?: string;

@@ -7,4 +7,4 @@ import 'reflect-metadata';

static walk(root: string, options: WalkOptions): Promise<void>;
static isExclude(filename: string, extname: string, excluded: string[], extensions: string[]): boolean;
static isExclude(filename: string, extname: string, exclude: string[], extensions: string[]): boolean;
static exist(dir: string, filenames: string[]): boolean;
}

@@ -30,3 +30,3 @@ "use strict";

const extname = path.extname(realPath);
if (this.isExclude(item, extname, options.excluded, options.extensions)) {
if (this.isExclude(item, extname, options.exclude, options.extensions)) {
continue;

@@ -71,6 +71,6 @@ }

}
static isExclude(filename, extname, excluded, extensions) {
static isExclude(filename, extname, exclude, extensions) {
let result = false;
if (!result && excluded) {
result = (0, utils_1.isMatch)(filename, excluded);
if (exclude) {
result = (0, utils_1.isMatch)(filename, exclude);
}

@@ -77,0 +77,0 @@ if (!result && extname) {

@@ -30,2 +30,8 @@ import { Container } from '@artus/injection';

}
export interface Metadata {
name: string;
exclude?: string[];
extensions?: string[];
configDir?: string;
}
export * from './loader/types';
{
"name": "@artus/core",
"version": "1.0.0-beta.11",
"version": "1.0.0-beta.12",
"description": "Core package of Artus",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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