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

@koishijs/loader

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koishijs/loader - npm Package Compare versions

Comparing version 4.2.7 to 4.3.0

1

lib/index.d.ts

@@ -8,2 +8,3 @@ import { Loader } from './shared';

init(filename?: string): Promise<void>;
migrate(): Promise<void>;
readConfig(): Promise<import("@koishijs/core").Context.Config>;

@@ -10,0 +11,0 @@ import(name: string): Promise<any>;

@@ -40,2 +40,3 @@ var __create = Object.create;

var import_fs = require("fs");
var import_package = require("../package.json");
var dotenv = __toESM(require("dotenv"));

@@ -61,2 +62,25 @@ var import_ns_require = __toESM(require("ns-require"));

}
async migrate() {
if (this.config["port"]) {
const { port, host, maxPort, selfUrl } = this.config;
delete this.config["port"];
delete this.config["host"];
delete this.config["maxPort"];
delete this.config["selfUrl"];
this.config.plugins = {
server: { port, host, maxPort, selfUrl },
...this.config.plugins
};
try {
const version = import_package.dependencies["@koishijs/plugin-server"];
const data = JSON.parse(await import_fs.promises.readFile("package.json", "utf8"));
data.dependencies["@koishijs/plugin-server"] = version;
data.dependencies = Object.fromEntries(Object.entries(data.dependencies).sort(([a], [b]) => a.localeCompare(b)));
await import_fs.promises.writeFile("package.json", JSON.stringify(data, null, 2) + "\n");
} catch {
logger.warn("cannot find package.json, please install @koishijs/plugin-server manually");
}
}
await super.migrate();
}
async readConfig() {

@@ -63,0 +87,0 @@ for (const key of this.localKeys) {

7

lib/shared.d.ts

@@ -32,3 +32,3 @@ /// <reference types="node" />

[Loader.kRecord]?: Dict<ForkScope<C>>;
alias?: string;
key?: string;
}

@@ -55,2 +55,3 @@ }

envFiles: string[];
names: Set<string>;
cache: Dict<string>;

@@ -64,2 +65,4 @@ prolog: Logger.Record[];

private findConfig;
private migrateGroup;
migrate(): Promise<void>;
readConfig(): Promise<Context.Config>;

@@ -83,5 +86,5 @@ writeConfig(silent?: boolean): Promise<void>;

unloadPlugin(ctx: Context, key: string): void;
paths(scope: EffectScope, suffix?: string[]): string[];
paths(scope: EffectScope): string[];
createApp(): Promise<Context>;
}
export {};

@@ -111,2 +111,3 @@ var __create = Object.create;

envFiles;
names = /* @__PURE__ */ new Set();
cache = /* @__PURE__ */ Object.create(null);

@@ -168,2 +169,28 @@ prolog = [];

}
migrateGroup(plugins) {
const backup = { ...plugins };
for (const key in backup)
delete plugins[key];
for (const key in backup) {
if (key.startsWith("$")) {
plugins[key] = backup[key];
continue;
}
const [name] = key.split(":", 1);
const isGroup = name === "group" || name === "~group";
if (isGroup)
this.migrateGroup(backup[key]);
let ident = key.slice(name.length + 1);
if (ident && !this.names.has(ident)) {
this.names.add(ident);
plugins[key] = backup[key];
continue;
}
ident = Math.random().toString(36).slice(2, 8);
plugins[`${name}:${ident}`] = backup[key];
}
}
async migrate() {
this.migrateGroup(this.config.plugins);
}
async readConfig() {

@@ -178,2 +205,5 @@ if (this.mime === "application/yaml") {

}
await this.migrate();
if (this.writable)
await this.writeConfig(true);
return new import_core.Context.Config(this.interpolate(this.config));

@@ -263,3 +293,3 @@ }

ctx[_Loader.ancestor] = fork.uid;
fork.alias = key.slice(name.length + 1);
fork.key = key.slice(name.length + 1);
parent.scope[_Loader.kRecord][key] = fork;

@@ -303,18 +333,11 @@ }

}
paths(scope, suffix = []) {
if (scope === scope.parent.scope) {
return [suffix.slice(1).join("/")];
}
paths(scope) {
if (scope === scope.parent.scope)
return [];
if (scope.runtime === scope) {
return [].concat(...scope.runtime.children.map((child2) => this.paths(child2, suffix)));
return [].concat(...scope.runtime.children.map((child) => this.paths(child)));
}
const child = scope;
scope = scope.parent.scope;
const record = scope[_Loader.kRecord];
if (!record)
return this.paths(scope, suffix);
const entry = Object.entries(record).find(([, value]) => value === child);
if (!entry)
return [];
return this.paths(scope, [entry[0], ...suffix]);
if (scope.key)
return [scope.key];
return this.paths(scope.parent.scope);
}

@@ -321,0 +344,0 @@ async createApp() {

{
"name": "@koishijs/loader",
"description": "Config Loader for Koishi",
"version": "4.2.7",
"version": "4.3.0",
"main": "lib/index.js",

@@ -44,9 +44,10 @@ "module": "lib/shared.mjs",

"peerDependencies": {
"@koishijs/core": "4.15.7"
"@koishijs/core": "4.16.0"
},
"devDependencies": {
"@koishijs/core": "4.15.7",
"@types/js-yaml": "^4.0.8"
"@koishijs/core": "4.16.0",
"@types/js-yaml": "^4.0.9"
},
"dependencies": {
"@koishijs/plugin-server": "^0.1.3",
"dotenv": "^16.3.1",

@@ -53,0 +54,0 @@ "js-yaml": "^4.1.0",

import { Logger } from '@koishijs/core'
import { Loader } from './shared'
import { promises as fs } from 'fs'
// @ts-ignore
import { dependencies } from '../package.json'
import * as dotenv from 'dotenv'

@@ -32,2 +34,26 @@ import ns from 'ns-require'

async migrate() {
if (this.config['port']) {
const { port, host, maxPort, selfUrl } = this.config as any
delete this.config['port']
delete this.config['host']
delete this.config['maxPort']
delete this.config['selfUrl']
this.config.plugins = {
server: { port, host, maxPort, selfUrl },
...this.config.plugins,
}
try {
const version = dependencies['@koishijs/plugin-server']
const data = JSON.parse(await fs.readFile('package.json', 'utf8'))
data.dependencies['@koishijs/plugin-server'] = version
data.dependencies = Object.fromEntries(Object.entries(data.dependencies).sort(([a], [b]) => a.localeCompare(b)))
await fs.writeFile('package.json', JSON.stringify(data, null, 2) + '\n')
} catch {
logger.warn('cannot find package.json, please install @koishijs/plugin-server manually')
}
}
await super.migrate()
}
async readConfig() {

@@ -34,0 +60,0 @@ // remove local env variables

@@ -42,3 +42,3 @@ import { Context, Dict, EffectScope, ForkScope, interpolate, isNullable, Logger, Plugin, Universal, valueMap, version } from '@koishijs/core'

[Loader.kRecord]?: Dict<ForkScope<C>>
alias?: string
key?: string
}

@@ -126,2 +126,3 @@ }

public envFiles: string[]
public names = new Set<string>()
public cache: Dict<string> = Object.create(null)

@@ -190,2 +191,28 @@ public prolog: Logger.Record[] = []

private migrateGroup(plugins: Dict) {
const backup = { ...plugins }
for (const key in backup) delete plugins[key]
for (const key in backup) {
if (key.startsWith('$')) {
plugins[key] = backup[key]
continue
}
const [name] = key.split(':', 1)
const isGroup = name === 'group' || name === '~group'
if (isGroup) this.migrateGroup(backup[key])
let ident = key.slice(name.length + 1)
if (ident && !this.names.has(ident)) {
this.names.add(ident)
plugins[key] = backup[key]
continue
}
ident = Math.random().toString(36).slice(2, 8)
plugins[`${name}:${ident}`] = backup[key]
}
}
async migrate() {
this.migrateGroup(this.config.plugins)
}
async readConfig() {

@@ -202,2 +229,4 @@ if (this.mime === 'application/yaml') {

await this.migrate()
if (this.writable) await this.writeConfig(true)
return new Context.Config(this.interpolate(this.config))

@@ -289,3 +318,3 @@ }

ctx[Loader.ancestor] = fork.uid
fork.alias = key.slice(name.length + 1)
fork.key = key.slice(name.length + 1)
parent.scope[Loader.kRecord][key] = fork

@@ -333,20 +362,13 @@ }

paths(scope: EffectScope, suffix: string[] = []): string[] {
paths(scope: EffectScope): string[] {
// root scope
if (scope === scope.parent.scope) {
return [suffix.slice(1).join('/')]
}
if (scope === scope.parent.scope) return []
// runtime scope
if (scope.runtime === scope) {
return [].concat(...scope.runtime.children.map(child => this.paths(child, suffix)))
return [].concat(...scope.runtime.children.map(child => this.paths(child)))
}
const child = scope
scope = scope.parent.scope
const record = scope[Loader.kRecord]
if (!record) return this.paths(scope, suffix)
const entry = Object.entries(record).find(([, value]) => value === child)
if (!entry) return []
return this.paths(scope, [entry[0], ...suffix])
if (scope.key) return [scope.key]
return this.paths(scope.parent.scope)
}

@@ -353,0 +375,0 @@

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