@chialab/esbuild-plugin-meta-url
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -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 @@ }, |
{ | ||
"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" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7852
109