Comments (2)
Hey, i'm working on a small library to have some sort of "HMR" with Node ( using the query params hack in the import path ) and I met this need today, so I wanted to share my use case
I need to add two methods in import.meta
: import.meta.hot.dipose
and import.meta.hot.decline
. Because using import.meta.hot.xxx
has become a sort a convention since Vite and co.
So to do this, I ended up injecting code via the load
hook. But this poses a problem: it totally breaks the source maps. Now, I don't know much about how source maps work, so maybe it's a simple problem to fix ( I will read more about it ), but I thought it was something that could be avoided if Node offered an API to initialize import.meta
.
I think, if an API is proposed, it should also be possible to access other properties in import.meta
.
In my case, import.meta.hot.decline
needs import.meta.url
. Here's some silly pseudo code to make my point clearer:
// loader.ts
// Let's say we can do that from a `load` hook
export const load: LoadHook = (url, context, nextLoad) => {
// maybe using the `context` property? I am not super aware of Nodejs internals
// so this is probably a dumb idea
context.initializeImportMeta(importMeta => {
return {
hot: {
dispose: () => {
// I can access the `import.meta` content through `importMeta`
myFunction(importMeta.url)
},
decline: () => {
myFunction(importMeta.url)
}
}
}
})
}
So having an API for that would allow us to avoid doing code transformations and breaking source maps. Using load
for the same result seems a bit hackish anyway
from loaders.
To give a bit more of context, it's already possible to customize import.meta
, using globalPreload
, but that's going away. Node.js 20.0.0 up to Node.js 20.5.1 are lacking that feature (it was removed "by accident" in the off-thread PR and was re-introduced by nodejs/node#48779), and no one has complained so I think it's fair to say it's not very high priority 🤷♂️
But I agree it's worth discussing, and if someone wanted to implement that, it would probably be well received.
from loaders.
Related Issues (20)
- Official `fs` overlay HOT 3
- Node.js Loaders Team Meeting 2023-11-21
- bug: CJS exports analysis reads directly from disk HOT 7
- Node.js Loaders Team Meeting 2023-12-05 HOT 9
- Node.js Loaders Team Meeting 2023-12-19
- Bad coverage information when loaders are used
- Node.js Loaders Team Meeting 2024-01-02
- Node.js Loaders Team Meeting 2024-01-16 HOT 2
- improve registration HOT 2
- Node.js Loaders Team Meeting 2024-01-30 HOT 3
- --experimental-loader breaks in Node 18.19 HOT 5
- Node.js Loaders Team Meeting 2024-02-13 HOT 1
- Node.js Loaders Team Meeting 2024-02-27 HOT 2
- Node.js Loaders Team Meeting 2024-03-12 HOT 1
- Node.js Loaders Team Meeting 2024-03-26 HOT 1
- Node.js Loaders Team Meeting 2024-04-09 HOT 15
- Node.js Loaders Team Meeting 2024-04-13
- Node.js Loaders Team Meeting 2024-04-23 HOT 3
- Node.js Loaders Team Meeting 2024-05-07 HOT 3
- Node.js Loaders Team Meeting 2024-05-23 HOT 3
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 loaders.