@yarnpkg/esbuild-plugin-pnp
Advanced tools
Comparing version 1.0.0-rc.2 to 1.0.0-rc.3
import type { OnLoadArgs, OnLoadResult, OnResolveArgs, OnResolveResult, Plugin } from 'esbuild'; | ||
declare type OnResolveParams = { | ||
resolvedPath: string | null; | ||
error?: Error; | ||
}; | ||
export declare type PluginOptions = { | ||
@@ -6,5 +10,6 @@ baseDir?: string; | ||
filter?: RegExp; | ||
onResolve?: (args: OnResolveArgs, resolvedPath: string | null) => Promise<OnResolveResult | null>; | ||
onResolve?: (args: OnResolveArgs, params: OnResolveParams) => Promise<OnResolveResult | null>; | ||
onLoad?: (args: OnLoadArgs) => Promise<OnLoadResult>; | ||
}; | ||
export declare function pnpPlugin({ baseDir, extensions, filter, onResolve, onLoad, }?: PluginOptions): Plugin; | ||
export {}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const fs = (0, tslib_1.__importStar)(require("fs")); | ||
const fs = tslib_1.__importStar(require("fs")); | ||
const matchAll = /()/; | ||
@@ -15,3 +15,23 @@ const defaultExtensions = [`.tsx`, `.ts`, `.jsx`, `.mjs`, `.cjs`, `.js`, `.css`, `.json`]; | ||
} | ||
async function defaultOnResolve(args, resolvedPath) { | ||
async function defaultOnResolve(args, { resolvedPath, error }) { | ||
const problems = error ? [{ text: error.message }] : []; | ||
// Sometimes dynamic resolve calls might be wrapped in a try / catch, | ||
// but ESBuild neither skips them nor does it provide a way for us to tell. | ||
// Because of that, we downgrade all errors to warnings in these situations. | ||
// Issue: https://github.com/evanw/esbuild/issues/1127 | ||
let mergeWith; | ||
switch (args.kind) { | ||
case `require-call`: | ||
case `require-resolve`: | ||
case `dynamic-import`: | ||
{ | ||
mergeWith = { warnings: problems }; | ||
} | ||
break; | ||
default: | ||
{ | ||
mergeWith = { errors: problems }; | ||
} | ||
break; | ||
} | ||
if (resolvedPath !== null) { | ||
@@ -21,3 +41,3 @@ return { namespace: `pnp`, path: resolvedPath }; | ||
else { | ||
return { external: true }; | ||
return { external: true, ...mergeWith }; | ||
} | ||
@@ -41,7 +61,14 @@ } | ||
return undefined; | ||
const path = pnpApi.resolveRequest(args.path, effectiveImporter, { | ||
considerBuiltins: true, | ||
extensions, | ||
}); | ||
return onResolve(args, path); | ||
let path = null; | ||
let error; | ||
try { | ||
path = pnpApi.resolveRequest(args.path, effectiveImporter, { | ||
considerBuiltins: true, | ||
extensions, | ||
}); | ||
} | ||
catch (e) { | ||
error = e; | ||
} | ||
return onResolve(args, { resolvedPath: path, error }); | ||
}); | ||
@@ -48,0 +75,0 @@ // We register on the build to prevent ESBuild from reading the files |
{ | ||
"name": "@yarnpkg/esbuild-plugin-pnp", | ||
"version": "1.0.0-rc.2", | ||
"version": "1.0.0-rc.3", | ||
"license": "BSD-2-Clause", | ||
@@ -10,7 +10,7 @@ "main": "./lib/index.js", | ||
"peerDependencies": { | ||
"esbuild": "^0.8.36" | ||
"esbuild": ">=0.8.36" | ||
}, | ||
"devDependencies": { | ||
"@yarnpkg/pnp": "^3.0.0-rc.2", | ||
"esbuild": "npm:esbuild-wasm@^0.8.36" | ||
"@yarnpkg/pnp": "3.0.0-rc.3", | ||
"esbuild": "npm:esbuild-wasm@^0.11.20" | ||
}, | ||
@@ -36,7 +36,7 @@ "scripts": { | ||
"engines": { | ||
"node": ">=10.19.0" | ||
"node": ">=12 <14 || 14.2 - 14.9 || >14.10.0" | ||
}, | ||
"stableVersion": "0.0.1", | ||
"bin": "./lib/cli.js", | ||
"typings": "./lib/index.d.ts" | ||
"typings": "./lib/index.d.ts", | ||
"bin": "./lib/cli.js" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
4970
94
1