mirror of
https://hk.gh-proxy.com/https://github.com/NodeBB/nodebb-plugin-emoji.git
synced 2025-10-04 01:20:58 +08:00
fix mime import transpilation
Dynamic `import('mime')` was compiling to `require` which led to a runtime error. Fixed the tsconfig to correctly support `import()` in CJS modules and simplified the code a bit.
This commit is contained in:
parent
265b68333c
commit
d09a8e3557
4 changed files with 13 additions and 17 deletions
20
lib/parse.ts
20
lib/parse.ts
|
@ -2,6 +2,8 @@ import { readFile } from 'fs-extra';
|
|||
|
||||
import { tableFile, aliasesFile, asciiFile, charactersFile } from './build';
|
||||
|
||||
const mime = import('mime');
|
||||
|
||||
const buster = require.main?.require('./src/meta').config['cache-buster'];
|
||||
const winston = require.main?.require('winston');
|
||||
|
||||
|
@ -302,14 +304,6 @@ export async function email(
|
|||
return data;
|
||||
}
|
||||
|
||||
let mimeModule: typeof import('mime') | null = null;
|
||||
async function importMime(): Promise<typeof import('mime').default> {
|
||||
if (!mimeModule) {
|
||||
mimeModule = await import('mime');
|
||||
}
|
||||
return mimeModule.default;
|
||||
}
|
||||
|
||||
export async function activitypubNote(data: {
|
||||
object: {
|
||||
source: { content: string },
|
||||
|
@ -327,7 +321,7 @@ export async function activitypubNote(data: {
|
|||
},
|
||||
post: unknown
|
||||
}): Promise<any> {
|
||||
const mime = await importMime();
|
||||
const getType = (await mime).default.getType;
|
||||
|
||||
const emojiContext = {
|
||||
toot: 'http://joinmastodon.org/ns#',
|
||||
|
@ -353,15 +347,15 @@ export async function activitypubNote(data: {
|
|||
return;
|
||||
}
|
||||
|
||||
const route = `${options.baseUrl}/plugins/nodebb-plugin-emoji/emoji/${emoji.pack}`;
|
||||
const url = `${options.baseUrl}/plugins/nodebb-plugin-emoji/emoji/${emoji.pack}/${emoji.image}?${buster}`;
|
||||
data.object.tag.push({
|
||||
id: emoji.name,
|
||||
id: url,
|
||||
type: 'Emoji',
|
||||
name: whole,
|
||||
icon: {
|
||||
type: 'Image',
|
||||
mediaType: mime.getType(emoji.image) || '',
|
||||
url: `${route}/${emoji.image}?${buster}`,
|
||||
mediaType: getType(emoji.image) || '',
|
||||
url,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"version": "5.1.15",
|
||||
"description": "Adds extensible emoji functionality to NodeBB",
|
||||
"main": "build/lib",
|
||||
"type": "commonjs",
|
||||
"author": "Peter Jaszkowiak <p.jaszkow@gmail.com> (https://github.com/pitaj)",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/NodeBB/nodebb-plugin-emoji",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"library": "build/lib",
|
||||
"library": ".",
|
||||
"scss": [
|
||||
"public/style.scss"
|
||||
],
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
"outDir": "build/lib",
|
||||
"lib": ["es2019"],
|
||||
"target": "es2019",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"module": "node16",
|
||||
"moduleResolution": "node16",
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"alwaysStrict": true,
|
||||
"strictNullChecks": true,
|
||||
"sourceMap": true
|
||||
"sourceMap": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"typeAcquisition": {
|
||||
"enable": false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue