Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@nodejs-loaders/media

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodejs-loaders/media - npm Package Compare versions

Comparing version
1.0.1
to
1.1.0
+6
media.loader.d.mts
export const exts: Set<string>;
export type FileURL = import("../types.d.ts").FileURL;
declare function resolveMedia(specifier: string, context: import("module").ResolveHookContext, nextResolve: (specifier: string, context?: Partial<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?: Partial<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.loader.d.mts.map
{"version":3,"file":"media.loader.d.mts","sourceRoot":"","sources":["media.loader.mjs"],"names":[],"mappings":"AA8CA,+BAoBG;sBA9DW,OAAO,eAAe,EAAE,OAAO;uIA+Dy0e,CAAC;kHAAo8C,CAAC"}
import process from 'node:process';
import { getFilenameExt } from '@nodejs-loaders/parse-filename';
/** @typedef {import('../types.d.ts').FileURL} FileURL */
/**
* @type {import('node:module').ResolveHook}
*/
async function resolveMedia(specifier, ctx, nextResolve) {
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(/** @type {FileURL} */ (nextResult.url)))) {
return nextResult;
}
return {
...ctx,
// @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493
format: 'media',
url: nextResult.url,
};
}
export { resolveMedia as resolve };
/**
* @type {import('node:module').LoadHook}
*/
async function loadMedia(url, ctx, nextLoad) {
// @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493
if (ctx.format !== 'media') return nextLoad(url);
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,
};
}
export { loadMedia as load };
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',
]);
+1
-4

@@ -1,5 +0,2 @@

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 };
export * from "./media.loader.mjs";
//# sourceMappingURL=media.d.mts.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"media.d.mts","sourceRoot":"","sources":["media.mjs"],"names":[],"mappings":"AA0CA,+BAoBG;uIACsoP,CAAC;kHAA4nD,CAAC"}
{"version":3,"file":"media.d.mts","sourceRoot":"","sources":["media.mjs"],"names":[],"mappings":""}

@@ -1,63 +0,8 @@

import process from 'node:process';
import { isMainThread } from 'node:worker_threads';
import module from 'node:module';
import { getFilenameExt } from '@nodejs-loaders/parse-filename';
/**
* @type {import('node:module').ResolveHook}
*/
async function resolveMedia(specifier, ctx, nextResolve) {
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;
return {
...ctx,
// @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493
format: 'media',
url: nextResult.url,
};
if (isMainThread && 'register' in module) {
module.register('./media.loader.mjs', import.meta.url);
}
export { resolveMedia as resolve };
/**
* @type {import('node:module').LoadHook}
*/
async function loadMedia(url, ctx, nextLoad) {
// @ts-ignore https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71493
if (ctx.format !== 'media') return nextLoad(url);
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,
};
}
export { loadMedia as load };
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',
]);
export * from './media.loader.mjs';
{
"version": "1.0.1",
"version": "1.1.0",
"name": "@nodejs-loaders/media",

@@ -4,0 +4,0 @@ "description": "Extend node to support media imports via customization hooks.",

@@ -41,1 +41,5 @@ # Nodejs Loaders: Media

</details>
## Alternatives
* [`esm-loader-images`](https://github.com/brev/esm-loaders/tree/main/packages/esm-loader-images#readme) - This alternative loader just supports images.