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.7 to 0.5.8

7

CHANGELOG.md

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

### [0.5.8](https://github.com/oclif/core/compare/v0.5.7...v0.5.8) (2021-05-26)
### Features
* strengthened ModuleLoader & unit tests; now supports mixed ESM / CJS plugins ([#163](https://github.com/oclif/core/issues/163)) ([788bf17](https://github.com/oclif/core/commit/788bf175b7e39b7d61fc07279e5cedca2fdbd540))
### [0.5.7](https://github.com/oclif/core/compare/v0.5.6...v0.5.7) (2021-05-17)

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

2

lib/config/plugin.js

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

const patterns = [
'**/*.+(js|ts|tsx)',
'**/*.+(js|cjs|mjs|ts|tsx)',
'!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)',

@@ -137,0 +137,0 @@ ];

@@ -61,4 +61,5 @@ import { Config as IConfig } from './interfaces';

* Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
* the `modulePath` is resolved from the root of the provided config. `path.resolve` is used for ESM and `tsPath`
* for non-ESM paths.
* the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
* If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
* '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
*

@@ -65,0 +66,0 @@ * @param {IConfig|IPlugin} config - Oclif config or plugin config.

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

const url = require("url");
const fs = require("fs-extra");
const errors_1 = require("./errors");

@@ -10,2 +11,6 @@ const Config = require("./config");

/**
* Defines file extension resolution when source files do not have an extension.
*/
const s_EXTENSIONS = ['.js', '.mjs', '.cjs'];
/**
* Provides a mechanism to use dynamic import / import() with tsconfig -> module: commonJS as otherwise import() gets

@@ -39,4 +44,6 @@ * transpiled to require().

static async load(config, modulePath) {
const { isESM, filePath } = ModuleLoader.resolvePath(config, modulePath);
let filePath;
let isESM;
try {
({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
// It is important to await on _importDynamic to catch the error code.

@@ -47,3 +54,3 @@ return isESM ? await _importDynamic(url.pathToFileURL(filePath)) : require(filePath);

if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath}`);
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
}

@@ -71,4 +78,6 @@ throw error;

static async loadWithData(config, modulePath) {
const { isESM, filePath } = ModuleLoader.resolvePath(config, modulePath);
let filePath;
let isESM;
try {
({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
const module = isESM ? await _importDynamic(url.pathToFileURL(filePath)) : require(filePath);

@@ -79,3 +88,3 @@ return { isESM, module, filePath };

if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath}`);
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
}

@@ -107,4 +116,5 @@ throw error;

* Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
* the `modulePath` is resolved from the root of the provided config. `path.resolve` is used for ESM and `tsPath`
* for non-ESM paths.
* the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
* If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
* '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
*

@@ -117,3 +127,3 @@ * @param {IConfig|IPlugin} config - Oclif config or plugin config.

static resolvePath(config, modulePath) {
let isESM = config.pjson.type === 'module';
let isESM;
let filePath;

@@ -125,3 +135,14 @@ try {

catch (error) {
filePath = isESM ? path.resolve(path.join(config.root, modulePath)) : Config.tsPath(config.root, modulePath);
filePath = Config.tsPath(config.root, modulePath);
// Try all supported extensions.
if (!fs.existsSync(filePath)) {
for (const extension of s_EXTENSIONS) {
const testPath = `${filePath}${extension}`;
if (fs.existsSync(testPath)) {
filePath = testPath;
break;
}
}
}
isESM = ModuleLoader.isPathModule(filePath);
}

@@ -128,0 +149,0 @@ return { isESM, filePath };

{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "0.5.7",
"version": "0.5.8",
"author": "Jeff Dickey @jdxcode",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/oclif/core/issues",

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