mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
chore: for the statistics only
permalink: http://whatthecommit.com/f6cb5f952917639c9e28f94ae495bd59
This commit is contained in:
@@ -1,40 +1,39 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'node:path'
|
||||
import { require } from '../utilities/require.js'
|
||||
import { type Plugin } from 'esbuild'
|
||||
import { basename } from 'node:path'
|
||||
import fs from 'fs/promises';
|
||||
import path from 'node:path';
|
||||
import { require } from '../utilities/require.js';
|
||||
import { type Plugin } from 'esbuild';
|
||||
import { basename } from 'node:path';
|
||||
|
||||
export const validExtensions = ['.ts','.js', '.json', '.png', '.jpg', '.jpeg', '.webp']
|
||||
export const validExtensions = ['.ts', '.js', '.json', '.png', '.jpg', '.jpeg', '.webp'];
|
||||
|
||||
//https://github.com/evanw/esbuild/issues/1051
|
||||
export const imageLoader = {
|
||||
name: 'attachment-loader',
|
||||
setup: b => {
|
||||
const filter = new RegExp(`\.${validExtensions.slice(3).join('|')}$`)
|
||||
b.onResolve({ filter }, args => {
|
||||
setup: (b) => {
|
||||
const filter = new RegExp(`\.${validExtensions.slice(3).join('|')}$`);
|
||||
b.onResolve({ filter }, (args) => {
|
||||
//if the module is being imported, resolve the path and transform to the js stub
|
||||
if(args.importer) {
|
||||
const newPath = path
|
||||
if (args.importer) {
|
||||
const newPath = path
|
||||
.format({ ...path.parse(args.path), base: '', ext: '.js' })
|
||||
.split(path.sep)
|
||||
.join(path.posix.sep)
|
||||
return { path: newPath, namespace: 'attachment-loader', external: true }
|
||||
.join(path.posix.sep);
|
||||
return { path: newPath, namespace: 'attachment-loader', external: true };
|
||||
}
|
||||
// if the file is actually the attachment, resolve the full dir
|
||||
return { path: require.resolve(args.path, { paths: [args.resolveDir] }), namespace: 'attachment-loader' }
|
||||
})
|
||||
// if the file is actually the attachment, resolve the full dir
|
||||
return { path: require.resolve(args.path, { paths: [args.resolveDir] }), namespace: 'attachment-loader' };
|
||||
});
|
||||
|
||||
b.onLoad({ filter: /.*/, namespace: 'attachment-loader' },
|
||||
async (args) => {
|
||||
const base64 = await fs.readFile(args.path).then(s => s.toString('base64'))
|
||||
return {
|
||||
contents: `
|
||||
b.onLoad({ filter: /.*/, namespace: 'attachment-loader' }, async (args) => {
|
||||
const base64 = await fs.readFile(args.path).then((s) => s.toString('base64'));
|
||||
return {
|
||||
contents: `
|
||||
var __toBuffer = (base64) => Buffer.from(base64, "base64");
|
||||
module.exports = {
|
||||
name: '${basename(args.path)}',
|
||||
attachment: __toBuffer("${base64}")
|
||||
}`,
|
||||
}
|
||||
})
|
||||
}
|
||||
} satisfies Plugin
|
||||
};
|
||||
});
|
||||
},
|
||||
} satisfies Plugin;
|
||||
|
||||
Reference in New Issue
Block a user