Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chialab/esbuild-plugin-meta-url

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chialab/esbuild-plugin-meta-url - npm Package Compare versions

Comparing version 0.4.5 to 0.4.6

42

lib/index.js

@@ -25,18 +25,8 @@ import { promises } from 'fs';

* @param {import('esbuild').OnLoadArgs & { contents?: string }} args
* @return {Promise<import('esbuild').OnLoadResult>}
*/
async function loadFile({ path: filePath, contents }) {
return {
contents: contents || await readFile(filePath),
loader: 'file',
};
}
/**
* @param {import('esbuild').OnLoadArgs & { contents?: string }} args
* @param {import('esbuild').BuildOptions} options
* @param {import('esbuild')} esbuild
* @param {string} contents
* @return {Promise<import('esbuild').OnLoadResult>}
*/
async function transformUrls({ path: filePath, contents }, options, esbuild) {
async function transformUrls({ path: filePath }, options, esbuild, contents = '') {
contents = contents || await readFile(filePath, 'utf-8');

@@ -104,3 +94,3 @@ if (!contents.match(URL_REGEX)) {

const plugin = {
name: 'url',
name: 'meta-url',
setup(build, { transform } = { transform: null }) {

@@ -113,31 +103,11 @@ let options = build.initialOptions;

build.onResolve({ filter: /^https?:\/\// }, ({ path: filePath }) => ({ path: filePath, external: true }));
build.onResolve({ filter: /\.file$/ }, async ({ path: filePath, importer }) => ({
path: await resolve(filePath.replace(/\.file$/, ''), importer),
namespace: 'url',
}));
if (transform) {
let args = /** @type {import('esbuild').OnLoadArgs} */ (/** @type {unknown} */ (transform));
if (args.namespace === 'url') {
return /** @type {void} */ (/** @type {unknown} */ (loadFile(args)));
}
if (!keys.includes(path.extname(args.path))) {
return /** @type {void} */ (/** @type {unknown} */ (loadFile(args)));
}
let { args, contents } = /** @type {{ args: import('esbuild').OnLoadArgs, contents?: string }} */ (/** @type {unknown} */ (transform));
if (args.path.match(tsxRegex)) {
return /** @type {void} */ (/** @type {unknown} */ (transformUrls(args, options, esbuild)));
return /** @type {void} */ (/** @type {unknown} */ (transformUrls(args, options, esbuild, contents)));
}
return /** @type {void} */ (/** @type {unknown} */ (args));
return;
}
build.onLoad({ filter: /\./, namespace: 'url' }, (args) => loadFile(args));
build.onLoad({ filter: /\./, namespace: 'file' }, (args) => {
if (keys.includes(path.extname(args.path))) {
return;
}
return loadFile(args);
});
build.onLoad({ filter: tsxRegex, namespace: 'file' }, (args) => transformUrls(args, options, esbuild));

@@ -144,0 +114,0 @@ },

4

package.json
{
"name": "@chialab/esbuild-plugin-meta-url",
"type": "module",
"version": "0.4.5",
"version": "0.4.6",
"description": "A file loader plugin for esbuild for constructed URLs using import metadata.",

@@ -33,3 +33,3 @@ "main": "lib/index.js",

},
"gitHead": "071fac5bd3f272ada30e29e06074fbb2688532d6"
"gitHead": "d396d0f6dfa3ff1e43455468b3fef3cf14b705fe"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc