@adonisjs/fold
Advanced tools
Comparing version 6.0.1 to 6.0.2
@@ -21,6 +21,3 @@ /// <reference types="node" /> | ||
use<T extends any = any>(name: string, relativeFrom?: string): T; | ||
useEsm<T extends any = any>(name: string, relativeFrom?: string): { | ||
default: T; | ||
__esModule: true; | ||
}; | ||
useEsm<T extends any = any>(name: string, relativeFrom?: string): T; | ||
make<T extends any = any>(name: string, relativeFrom?: string): T; | ||
@@ -27,0 +24,0 @@ useFake<T extends any = any>(name: string): T; |
@@ -23,2 +23,3 @@ import { IocContract, BindCallback } from '../Contracts'; | ||
private _requireModule; | ||
private _toEsm; | ||
private _resolve; | ||
@@ -38,6 +39,3 @@ private _resolveAndMake; | ||
use<T extends any = any>(namespace: string, relativeFrom?: string): T; | ||
useEsm<T extends any = any>(namespace: string, relativeFrom?: string): { | ||
default: T; | ||
__esModule: true; | ||
}; | ||
useEsm<T extends any = any>(namespace: string, relativeFrom?: string): T; | ||
make<T extends any = any>(namespace: any, relativeFrom?: string): T; | ||
@@ -44,0 +42,0 @@ useFake<T extends any = any>(namespace: string): T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("@poppinss/utils"); | ||
const path_1 = require("path"); | ||
@@ -49,3 +48,3 @@ const Tracer_1 = require("./Tracer"); | ||
const absPath = this._makeRequirePath(baseNamespace, namespace); | ||
const importValue = utils_1.esmRequire(absPath); | ||
const importValue = require(absPath); | ||
this._autoloadsCache.set(namespace, { diskPath: absPath, cachedValue: importValue }); | ||
@@ -81,8 +80,15 @@ } | ||
} | ||
_resolve(name, relativeFrom) { | ||
_toEsm(value) { | ||
const esm = { | ||
default: value, | ||
}; | ||
Object.defineProperty(esm, '__esModule', { value: true }); | ||
return esm; | ||
} | ||
_resolve(name, asEsm, relativeFrom) { | ||
if (this.hasBinding(name)) { | ||
return this._resolveBinding(name); | ||
return asEsm ? this._toEsm(this._resolveBinding(name)) : this._resolveBinding(name); | ||
} | ||
if (this.hasAlias(name)) { | ||
return this._resolve(this.getAliasNamespace(name)); | ||
return this._resolve(this.getAliasNamespace(name), asEsm); | ||
} | ||
@@ -102,6 +108,8 @@ if (this.isAutoloadNamespace(name)) { | ||
if (this.hasAlias(name)) { | ||
return this._resolve(this.getAliasNamespace(name)); | ||
return this._resolve(this.getAliasNamespace(name), false); | ||
} | ||
if (this.isAutoloadNamespace(name)) { | ||
return this._makeInstanceOf(this._autoload(name), relativeFrom); | ||
const value = this._autoload(name); | ||
const normalizedValue = value && value.__esModule && value.default ? value.default : value; | ||
return this._makeInstanceOf(normalizedValue, relativeFrom); | ||
} | ||
@@ -180,3 +188,3 @@ return this._requireModule(name, relativeFrom); | ||
use(namespace, relativeFrom) { | ||
const value = this._resolve(namespace, relativeFrom); | ||
const value = this._resolve(namespace, false, relativeFrom); | ||
if (!this._useProxies) { | ||
@@ -194,6 +202,20 @@ return value; | ||
useEsm(namespace, relativeFrom) { | ||
return { | ||
default: this.use(namespace, relativeFrom), | ||
__esModule: true, | ||
}; | ||
const value = this._resolve(namespace, true, relativeFrom); | ||
if (!value.__esModule) { | ||
throw new Error(`${namespace} must be an ES module`); | ||
} | ||
if (!this._useProxies || !value.default) { | ||
return value; | ||
} | ||
if (this._isObject(value.default)) { | ||
return { | ||
default: new IoCProxy_1.IoCProxyObject(namespace, value.default, this), | ||
}; | ||
} | ||
if (this._isClass(value.default)) { | ||
return { | ||
default: IoCProxy_1.IocProxyClass(namespace, value.default, this), | ||
}; | ||
} | ||
return value; | ||
} | ||
@@ -200,0 +222,0 @@ make(namespace, relativeFrom) { |
{ | ||
"name": "@adonisjs/fold", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"description": "Dependency manager and ioc container for your next NodeJs application", | ||
@@ -36,5 +36,5 @@ "scripts": { | ||
"devDependencies": { | ||
"@adonisjs/dev-utils": "^1.4.0", | ||
"@adonisjs/mrm-preset": "^2.0.3", | ||
"@types/node": "^12.0.2", | ||
"clear-module": "^3.2.0", | ||
"commitizen": "^3.1.1", | ||
@@ -44,3 +44,2 @@ "cz-conventional-changelog": "^2.1.0", | ||
"doctoc": "^1.4.0", | ||
"fs-extra": "^8.0.1", | ||
"husky": "^2.3.0", | ||
@@ -47,0 +46,0 @@ "japa": "^2.0.10", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41750
19
602
4