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

@esbuild-plugins/node-resolve

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esbuild-plugins/node-resolve - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

6

CHANGELOG.md
# @esbuild-plugins/node-resolve
## 0.0.14
### Patch Changes
- 8f79800: Support for mainFields in resolveasync
## 0.0.13

@@ -4,0 +10,0 @@

5

dist/index.d.ts
import { OnResolveResult, Plugin } from 'esbuild';
import { Opts as ResolveOpts } from 'resolve';
export declare const resolveAsync: (id: string, opts: ResolveOpts) => Promise<string | void>;
declare type ResolveAsyncOpts = ResolveOpts & {
mainFields?: string[];
};
export declare const resolveAsync: (id: string, opts: ResolveAsyncOpts) => Promise<string | void>;
interface Options {

@@ -5,0 +8,0 @@ name?: string;

101

dist/index.js

@@ -49,2 +49,13 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __values = (this && this.__values) || function(o) {

@@ -74,9 +85,46 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

var debug = require('debug')(NAME);
exports.resolveAsync = util_1.promisify(resolve_1.default);
var isUsingYarnPnp = false;
try {
require('pnpapi');
isUsingYarnPnp = true;
}
catch (_a) { }
var resolveAsync = function (id, _a) { return __awaiter(void 0, void 0, void 0, function () {
function packageFilter(packageJSON) {
var e_1, _a;
if (!(mainFields === null || mainFields === void 0 ? void 0 : mainFields.length)) {
return packageJSON;
}
try {
// changes the main field to be another field
for (var mainFields_1 = __values(mainFields), mainFields_1_1 = mainFields_1.next(); !mainFields_1_1.done; mainFields_1_1 = mainFields_1.next()) {
var mainField = mainFields_1_1.value;
if (mainField === 'main') {
break;
}
var newMain = packageJSON[mainField];
if (newMain && typeof newMain === 'string') {
debug("set main to '" + mainField);
packageJSON['main'] = newMain;
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (mainFields_1_1 && !mainFields_1_1.done && (_a = mainFields_1.return)) _a.call(mainFields_1);
}
finally { if (e_1) throw e_1.error; }
}
return packageJSON;
}
var opts, res;
var mainFields = _a.mainFields, _opts = __rest(_a, ["mainFields"]);
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
opts = __assign(__assign({}, _opts), { preserveSymlinks: false, packageFilter: packageFilter });
return [4 /*yield*/, util_1.promisify(resolve_1.default)(id, opts)];
case 1:
res = _b.sent();
return [2 /*return*/, res];
}
});
}); };
exports.resolveAsync = resolveAsync;
function NodeResolvePlugin(_a) {

@@ -93,3 +141,3 @@ var onNonResolved = _a.onNonResolved, namespace = _a.namespace, extensions = _a.extensions, onResolved = _a.onResolved, resolveOptions = _a.resolveOptions, mainFields = _a.mainFields, _b = _a.name, name = _b === void 0 ? NAME : _b, isExtensionRequiredInImportPath = _a.isExtensionRequiredInImportPath, resolveSynchronously = _a.resolveSynchronously;

onLoad({ filter: filter, namespace: namespace }, function (args) { return __awaiter(_this, void 0, void 0, function () {
var contents, resolveDir, e_1;
var contents, resolveDir, e_2;
return __generator(this, function (_a) {

@@ -114,3 +162,3 @@ switch (_a.label) {

case 2:
e_1 = _a.sent();
e_2 = _a.sent();
return [2 /*return*/, null];

@@ -123,32 +171,3 @@ case 3: return [2 /*return*/];

return __awaiter(this, void 0, void 0, function () {
function packageFilter(packageJSON) {
var e_3, _a;
if (!(mainFields === null || mainFields === void 0 ? void 0 : mainFields.length)) {
return packageJSON;
}
try {
// changes the main field to be another field
for (var mainFields_1 = __values(mainFields), mainFields_1_1 = mainFields_1.next(); !mainFields_1_1.done; mainFields_1_1 = mainFields_1.next()) {
var mainField = mainFields_1_1.value;
if (mainField === 'main') {
break;
}
var newMain = packageJSON[mainField];
if (newMain && typeof newMain === 'string') {
debug("set main to '" + mainField);
packageJSON['main'] = newMain;
break;
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (mainFields_1_1 && !mainFields_1_1.done && (_a = mainFields_1.return)) _a.call(mainFields_1);
}
finally { if (e_3) throw e_3.error; }
}
return packageJSON;
}
var resolved, options, _a, e_2, res, res;
var resolved, options, _a, e_3, res, res;
return __generator(this, function (_b) {

@@ -165,3 +184,3 @@ switch (_b.label) {

options = __assign({ basedir: args.resolveDir, preserveSymlinks: false, extensions: extensions,
packageFilter: packageFilter }, resolveOptions);
mainFields: mainFields }, resolveOptions);
if (!resolveSynchronously) return [3 /*break*/, 2];

@@ -178,3 +197,3 @@ _a = resolve_1.default.sync(args.path, options);

case 5:
e_2 = _b.sent();
e_3 = _b.sent();
debug("not resolved " + args.path);

@@ -181,0 +200,0 @@ if (!onNonResolved) return [3 /*break*/, 7];

{
"name": "@esbuild-plugins/node-resolve",
"version": "0.0.13",
"version": "0.0.14",
"description": "",

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

@@ -12,6 +12,34 @@ import { OnResolveArgs, OnResolveResult, Plugin } from 'esbuild'

type ResolveAsyncOpts = ResolveOpts & { mainFields?: string[] }
export const resolveAsync: (
id: string,
opts: ResolveOpts,
) => Promise<string | void> = promisify(resolve as any)
opts: ResolveAsyncOpts,
) => Promise<string | void> = async (id, { mainFields, ..._opts }) => {
function packageFilter(packageJSON) {
if (!mainFields?.length) {
return packageJSON
}
// changes the main field to be another field
for (let mainField of mainFields) {
if (mainField === 'main') {
break
}
const newMain = packageJSON[mainField]
if (newMain && typeof newMain === 'string') {
debug(`set main to '${mainField}`)
packageJSON['main'] = newMain
break
}
}
return packageJSON
}
const opts: ResolveOpts = {
..._opts,
preserveSymlinks: false,
packageFilter,
}
const res = await promisify(resolve as any)(id, opts)
return res
}

@@ -38,9 +66,2 @@ interface Options {

let isUsingYarnPnp = false
try {
require('pnpapi')
isUsingYarnPnp = true
} catch {}
export function NodeResolvePlugin({

@@ -90,27 +111,10 @@ onNonResolved,

}
function packageFilter(packageJSON) {
if (!mainFields?.length) {
return packageJSON
}
// changes the main field to be another field
for (let mainField of mainFields) {
if (mainField === 'main') {
break
}
const newMain = packageJSON[mainField]
if (newMain && typeof newMain === 'string') {
debug(`set main to '${mainField}`)
packageJSON['main'] = newMain
break
}
}
return packageJSON
}
let resolved
try {
const options: ResolveOpts = {
const options: ResolveAsyncOpts = {
basedir: args.resolveDir,
preserveSymlinks: false,
extensions,
packageFilter,
mainFields,
...resolveOptions,

@@ -117,0 +121,0 @@ }

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