Comments (14)
That test scenario is perfect. That's what we have currently in our project. Some folders work, while others didn't so I had to specifically add an export for that folder.
from esmock.
@dschnare the PR was just updated so that the tests will pass in windows. Feel free to recommend any changes
from esmock.
if the overall approach is okay (as it seems to be) its good for me if the PR is accepted. Later on, when needed, the place that expands the asterisks on the right side could be improved for supporting more situations.
from esmock.
Reference: https://nodejs.org/docs/latest-v18.x/api/packages.html#subpath-patterns
from esmock.
Interestingly, this error only occurs for me for some subpaths and not others from a package. To workaround I had to use the pattern to catch most subpaths then have an explicit export for subpaths that cause the error.
{
"exports": {
"./*": {
"default": "./src/*/index.js",
"types": "./types/*/index.d.ts"
},
"./my-path": {
"default": "./src/my-path/index.js",
"types": "./src/my-path/index.d.ts"
}
}
}
from esmock.
@dschnare subpaths are supported and if one is not resolved correctly that's a bug. esmock uses resolvewithplus to resolve module ids, so that's where the solution should happen.
Node's dsl esm pattern language is tricky to parse. For resolvewithplus, official node examples were copied to unit-tests used by resolvewithplus and when missing cases have been discovered they've been resolved in new versions of resolvewithplus
from esmock.
@dschnare I have not seen wildcard export namespace names before, eg {"exports":{"./namepace*": { ... }}}
that usage does not appear to be documented at the link you shared.
from esmock.
from esmock.
@dschnare thanks for reporting. Its always good to learn about these cases I didn't know about.
from esmock.
@dschnare is this what you think the exports, directory and file layout should look like for unit-testing this?
{
"name": "asterisk-dir-name",
"type": "module",
"exports": {
"./*": {
"default": "./src/*/index.js",
"types": "./types/*/index.d.ts"
}
}
}
.
├── package.json
├── src
│ └── mystuff
│ └── index.js
└── types
└── mystuff
└── index.d.ts
from esmock.
@dschnare I wonder specifically how the named-property asterisk and then its nested, matched value must correspond to each other and the specifier used to import such a module.
For example, should the outer "./*" return any directory or only a directory that corresponds with the imported moduleId?
Maybe we should first implement any basic solution and then refine that later as any edge-cases are reported to fail.
from esmock.
@dschnare iambumblehead/resolvewithplus#65
from esmock.
@iambumblehead It looks like from the documentation that the subpath pattern ./*
would match any path like "mymodule/something", "mymodule/something/cool", etc. And technically *
could be included multiple times in the export pattern. This I didn't know, but interesting.
All instances of
*
on the right hand side will then be replaced with this value, including if it contains any / separators.
from esmock.
@iambumblehead I understood that incorrectly. The *
can appear multiple times on the right side. On the left side it appears it should only occur once.
from esmock.
Related Issues (20)
- yarn pnp issues HOT 14
- Is it possible to mock json imports with assert? HOT 6
- Support Yarn PnP resolver out of the box HOT 11
- Get rid of old Node versions support HOT 8
- resolve error introduced with 2.5.2 HOT 10
- Error when mocking a file that exports an array. HOT 1
- c8 incorrect branch coverage; modules and `import` globals HOT 11
- how to mock globalThis HOT 4
- import('node:fs/promises') called within a library does not seem to be replaced HOT 30
- Path alias support HOT 1
- Unexpected strict mode reserved word syntax error when mocking express HOT 2
- incompatible with eslint-plugin-import HOT 3
- Version 2.6.3 changed the way to mock libraries HOT 7
- ESMock seems to wrongfully alter Sinon stubs. HOT 1
- Using `import:` to mock globals messes up coverage (with c8) HOT 7
- [Question] Is it possible to mock indirect imports? HOT 10
- Scoped mocks failing with pnpm but working with npm HOT 9
- esmock static import for classes not matching HOT 3
- upstream issue, worker threads unable to register loader HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esmock.