@nodejs-loaders/media
Advanced tools
| export const exts: Set<string>; | ||
| declare function resolveMedia(specifier: string, context: import("module").ResolveHookContext, nextResolve: (specifier: string, context?: import("module").ResolveHookContext) => import("module").ResolveFnOutput | Promise<import("module").ResolveFnOutput>): import("module").ResolveFnOutput | Promise<import("module").ResolveFnOutput>; | ||
| declare function loadMedia(url: string, context: import("module").LoadHookContext, nextLoad: (url: string, context?: import("module").LoadHookContext) => import("module").LoadFnOutput | Promise<import("module").LoadFnOutput>): import("module").LoadFnOutput | Promise<import("module").LoadFnOutput>; | ||
| export { resolveMedia as resolve, loadMedia as load }; | ||
| //# sourceMappingURL=media.d.mts.map |
| {"version":3,"file":"media.d.mts","sourceRoot":"","sources":["media.mjs"],"names":[],"mappings":"AA0CA,+BAoBG;uIACsoP,CAAC;kHAA4nD,CAAC"} |
+45
-38
@@ -5,30 +5,37 @@ import process from 'node:process'; | ||
| /** | ||
| * @type {import('node:module').ResolveHook} | ||
| */ | ||
| async function resolveMedia(specifier, ctx, nextResolve) { | ||
| const nextResult = await nextResolve(specifier); | ||
| const nextResult = await nextResolve(specifier); | ||
| // Check against the fully resolved URL, not just the specifier, in case another loader has | ||
| // something to contribute to the resolution. | ||
| if (!exts.has(getFilenameExt(nextResult.url))) return nextResult; | ||
| // Check against the fully resolved URL, not just the specifier, in case another loader has | ||
| // something to contribute to the resolution. | ||
| if (!exts.has(getFilenameExt(nextResult.url))) return nextResult; | ||
| return { | ||
| ...ctx, | ||
| format: 'media', | ||
| url: nextResult.url, | ||
| } | ||
| return { | ||
| ...ctx, | ||
| // @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493 | ||
| format: 'media', | ||
| url: nextResult.url, | ||
| }; | ||
| } | ||
| export { resolveMedia as resolve } | ||
| export { resolveMedia as resolve }; | ||
| /** | ||
| * @type {import('node:module').LoadHook} | ||
| */ | ||
| async function loadMedia(url, ctx, nextLoad) { | ||
| if (ctx.format !== 'media') return nextLoad(url); | ||
| // @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493 | ||
| if (ctx.format !== 'media') return nextLoad(url); | ||
| const source = `export default '${url.replace(cwd, '[…]')}';`; | ||
| const source = `export default '${url.replace(cwd, '[…]')}';`; | ||
| return { | ||
| format: 'module', | ||
| shortCircuit: true, // There's nothing else for another loader to do, so signal to stop. | ||
| source, | ||
| }; | ||
| return { | ||
| format: 'module', | ||
| shortCircuit: true, // There's nothing else for another loader to do, so signal to stop. | ||
| source, | ||
| }; | ||
| } | ||
| export { loadMedia as load } | ||
| export { loadMedia as load }; | ||
@@ -38,21 +45,21 @@ const cwd = process.cwd(); | ||
| export const exts = new Set([ | ||
| /** | ||
| * A/V | ||
| */ | ||
| '.av1', | ||
| '.mp3', | ||
| '.mp3', | ||
| '.mp4', | ||
| '.ogg', | ||
| '.webm', | ||
| /** | ||
| * images | ||
| */ | ||
| '.avif', | ||
| '.gif', | ||
| '.ico', | ||
| '.jpeg', | ||
| '.jpg', | ||
| '.png', | ||
| '.webp', | ||
| /** | ||
| * A/V | ||
| */ | ||
| '.av1', | ||
| '.mp3', | ||
| '.mp3', | ||
| '.mp4', | ||
| '.ogg', | ||
| '.webm', | ||
| /** | ||
| * images | ||
| */ | ||
| '.avif', | ||
| '.gif', | ||
| '.ico', | ||
| '.jpeg', | ||
| '.jpg', | ||
| '.png', | ||
| '.webp', | ||
| ]); |
+13
-4
| { | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "name": "@nodejs-loaders/media", | ||
| "description": "Extend node to support media imports via customization hooks.", | ||
| "type": "module", | ||
| "author": "Jacob Smith", | ||
| "maintainers": [ | ||
| "Augustin Mauroy" | ||
| "Augustin Mauroy", | ||
| "Jacob Smith" | ||
| ], | ||
| "license": "ISC", | ||
| "main": "./media.mjs", | ||
| "types": "./media.d.mts", | ||
| "keywords": [ | ||
| "audio", | ||
| "customisation hook", | ||
| "customization hooks", | ||
| "images", | ||
@@ -18,4 +21,8 @@ "video", | ||
| "media", | ||
| "node", | ||
| "node.js" | ||
| ], | ||
| "engines": { | ||
| "node": ">=22 || ^20.6.0 || ^18.19.0" | ||
| }, | ||
| "dependencies": { | ||
@@ -25,4 +32,6 @@ "@nodejs-loaders/parse-filename": "1.0.0" | ||
| "repository": { | ||
| "url": "https://github.com/JakobJingleheimer/nodejs-loaders" | ||
| "type": "git", | ||
| "url": "git+https://github.com/nodejs-loaders/nodejs-loaders.git", | ||
| "directory": "packages/media" | ||
| } | ||
| } |
+5
-3
| # Nodejs Loaders: Media | ||
| <img src="https://raw.githubusercontent.com/JakobJingleheimer/nodejs-loaders/refs/heads/main/logo.svg" height="100" width="100" alt="@node.js loaders logo" /> | ||
| <img src="https://raw.githubusercontent.com/nodejs-loaders/nodejs-loaders/refs/heads/main/logo.svg" height="100" width="100" alt="@node.js loaders logo" /> | ||
| [](https://www.npmjs.com/package/nodejs-loaders/media) | ||
|  | ||
| [](https://www.npmjs.com/package/nodejs-loaders/media) | ||
|  | ||
@@ -12,2 +12,4 @@ **Environment**: test | ||
| **Compatible APIs**: [`module.register`](https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options) | ||
| ```js | ||
@@ -14,0 +16,0 @@ import photo from './team.jpg'; // photo = '[…]/team.jpg' |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3996
58.63%5
66.67%54
17.39%41
5.13%0
-100%