Socket
Socket
Sign inDemoInstall

@oclif/core

Package Overview
Dependencies
Maintainers
5
Versions
396
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/core - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

lib/errors/errors/module-load.d.ts

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

### [0.5.6](https://github.com/oclif/core/compare/v0.5.5...v0.5.6) (2021-05-13)
### Features
* integrate ESM loading of commands & hooks ([#160](https://github.com/oclif/core/issues/160)) ([ff47444](https://github.com/oclif/core/commit/ff47444b549566e40015d33f29d2687b74a980f4))
### [0.5.5](https://github.com/oclif/core/compare/v0.5.4...v0.5.5) (2021-04-26)

@@ -7,0 +14,0 @@

37

lib/config/config.js

@@ -11,5 +11,5 @@ "use strict";

const Plugin = require("./plugin");
const ts_node_1 = require("./ts-node");
const util_3 = require("./util");
const util_4 = require("../util");
const module_loader_1 = require("../module-loader");
// eslint-disable-next-line new-cap

@@ -129,3 +129,10 @@ const debug = util_2.Debug();

debug('start %s hook', event);
const promises = this.plugins.map(p => {
const search = (m) => {
if (typeof m === 'function')
return m;
if (m.default && typeof m.default === 'function')
return m.default;
return Object.values(m).find((m) => typeof m === 'function');
};
for (const p of this.plugins) {
const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'));

@@ -148,15 +155,10 @@ const context = {

};
return Promise.all((p.hooks[event] || [])
.map(async (hook) => {
const hooks = p.hooks[event] || [];
for (const hook of hooks) {
try {
const f = ts_node_1.tsPath(p.root, hook);
debug('start', f);
const search = (m) => {
if (typeof m === 'function')
return m;
if (m.default && typeof m.default === 'function')
return m.default;
return Object.values(m).find((m) => typeof m === 'function');
};
await search(require(f)).call(context, Object.assign(Object.assign({}, opts), { config: this }));
/* eslint-disable no-await-in-loop */
const { isESM, module, filePath } = await module_loader_1.default.loadWithData(p, hook);
debug('start', isESM ? '(import)' : '(require)', filePath);
await search(module).call(context, Object.assign(Object.assign({}, opts), { config: this }));
/* eslint-enable no-await-in-loop */
debug('done');

@@ -169,5 +171,4 @@ }

}
}));
});
await Promise.all(promises);
}
}
debug('%s hook done', event);

@@ -182,3 +183,3 @@ }

}
const command = c.load();
const command = await c.load();
await this.runHook('prerun', { Command: command, argv });

@@ -185,0 +186,0 @@ const result = await command.run(argv, this);

@@ -33,6 +33,6 @@ import { Plugin as IPlugin, PluginOptions } from '../interfaces/plugin';

must: true;
}): Command.Class;
}): Promise<Command.Class>;
findCommand(id: string, opts?: {
must: boolean;
}): Command.Class | undefined;
}): Promise<Command.Class | undefined>;
protected _manifest(ignoreManifest: boolean, errorOnManifestCreate?: boolean): Promise<Manifest>;

@@ -39,0 +39,0 @@ protected warn(err: any, scope?: string): void;

@@ -11,2 +11,3 @@ "use strict";

const util_4 = require("../util");
const module_loader_1 = require("../module-loader");
const _pjson = require('../../package.json');

@@ -105,3 +106,3 @@ function topicsToArray(input, base) {

this.commands = Object.entries(this.manifest.commands)
.map(([id, c]) => (Object.assign(Object.assign({}, c), { load: () => this.findCommand(id, { must: true }) })));
.map(([id, c]) => (Object.assign(Object.assign({}, c), { load: async () => this.findCommand(id, { must: true }) })));
this.commands.sort((a, b) => {

@@ -148,4 +149,4 @@ if (a.id < b.id)

}
findCommand(id, opts = {}) {
const fetch = () => {
async findCommand(id, opts = {}) {
const fetch = async () => {
if (!this.commandsDir)

@@ -160,7 +161,8 @@ return;

};
const p = require.resolve(path.join(this.commandsDir, ...id.split(':')));
this._debug('require', p);
let m;
try {
m = require(p);
const p = path.join(this.pjson.oclif.commands, ...id.split(':'));
const { isESM, module, filePath } = await module_loader_1.default.loadWithData(this, p);
this._debug(isESM ? '(import)' : '(require)', filePath);
m = module;
}

@@ -179,3 +181,3 @@ catch (error) {

};
const cmd = fetch();
const cmd = await fetch();
if (!cmd && opts.must)

@@ -216,5 +218,5 @@ errors_1.error(`command ${id} not found`);

// eslint-disable-next-line array-callback-return
commands: this.commandIDs.map(id => {
commands: (await Promise.all(this.commandIDs.map(async (id) => {
try {
return [id, config_1.toCached(this.findCommand(id, { must: true }), this)];
return [id, config_1.toCached(await this.findCommand(id, { must: true }), this)];
}

@@ -228,3 +230,3 @@ catch (error) {

}
})
})))
.filter((f) => Boolean(f))

@@ -231,0 +233,0 @@ .reduce((commands, [id, c]) => {

export { handle } from './handle';
export { ExitError } from './errors/exit';
export { ModuleLoadError } from './errors/module-load';
export { CLIError } from './errors/cli';

@@ -4,0 +5,0 @@ export { Logger } from './logger';

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

exports.ExitError = exit_1.ExitError;
var module_load_1 = require("./errors/module-load");
exports.ModuleLoadError = module_load_1.ModuleLoadError;
var cli_1 = require("./errors/cli");

@@ -10,0 +12,0 @@ exports.CLIError = cli_1.CLIError;

@@ -72,4 +72,4 @@ import { Config, LoadOptions } from './config';

interface Plugin extends Command {
load(): Class;
load(): Promise<Class>;
}
}

@@ -67,7 +67,7 @@ import { Command } from './command';

must: true;
}): Command.Class;
}): Promise<Command.Class>;
findCommand(id: string, opts?: {
must: boolean;
}): Command.Class | undefined;
}): Promise<Command.Class> | undefined;
load(): Promise<void>;
}
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "0.5.5",
"version": "0.5.6",
"author": "Jeff Dickey @jdxcode",

@@ -14,2 +14,3 @@ "bugs": "https://github.com/oclif/core/issues",

"fs-extra": "^9.0.1",
"get-package-type": "^0.1.0",
"globby": "^11.0.1",

@@ -34,2 +35,3 @@ "indent-string": "^4.0.0",

"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.3",
"@types/clean-stack": "^2.1.1",

@@ -50,2 +52,3 @@ "@types/fs-extra": "^9.0.1",

"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"commitlint": "^12.1.1",

@@ -52,0 +55,0 @@ "eslint": "^7.3.1",

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