Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prioritize import specigier over packagejson exported type #68

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resolvewithplus",
"version": "2.1.5",
"version": "2.1.6",
"description": "resolvewith with extra power",
"readmeFilename": "README.md",
"license": "ISC",
Expand Down
4 changes: 3 additions & 1 deletion resolvewithplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ const esmparse = (spec, specifier, opts = {}) => {
// if dynamic 'spectype', lookup 'commonjs' or 'module'
// according to package.json
specname = specname === spectype
? getspectypenamedexportdefault(opts.packagejsontype)
? isDirPathRe.test(specifier)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole logic looks a bit... suspicious for me - it's a kind of mix of 'how to resolve exact import' (exports field logic) and 'how to detect module type - CJS or ESM' (type field). but, if it works - let's merge

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree :/

? getspectypenamedexportdefault(opts.packagejsontype)
: specifier
: specname,
esmparse(spec[specname], specifier, opts))
), false)
Expand Down
3 changes: 2 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"got": "12.0.1",
"koa": "^2.13.4",
"optfn": "~0.0.x",
"yargs": "^17.3.1"
"yargs": "^17.3.1",
"openai": "^4.80.0"
},
"scripts": {
"mini": "cd .. && npx esbuild resolvewithplus.js --minify --allow-overwrite --outfile=resolvewithplus.js",
Expand Down
4 changes: 4 additions & 0 deletions tests/tests-basic/tests-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ test('should return fileurl paths, as import.meta.resolve', async () => {
await metaresolve('yargs', fullpathfileurl),
resolvewithplus('yargs', fullpath))

assert.strictEqual(
await metaresolve('openai', fullpathfileurl),
resolvewithplus('openai', fullpath))

assert.strictEqual(
await metaresolve('got', fullpathfileurl),
resolvewithplus('got', fullpath))
Expand Down
Loading