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';
|
import { tableFile, aliasesFile, asciiFile, charactersFile } from './build';
|
||||||
|
|
||||||
|
const mime = import('mime');
|
||||||
|
|
||||||
const buster = require.main?.require('./src/meta').config['cache-buster'];
|
const buster = require.main?.require('./src/meta').config['cache-buster'];
|
||||||
const winston = require.main?.require('winston');
|
const winston = require.main?.require('winston');
|
||||||
|
|
||||||
|
@ -302,14 +304,6 @@ export async function email(
|
||||||
return data;
|
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: {
|
export async function activitypubNote(data: {
|
||||||
object: {
|
object: {
|
||||||
source: { content: string },
|
source: { content: string },
|
||||||
|
@ -327,7 +321,7 @@ export async function activitypubNote(data: {
|
||||||
},
|
},
|
||||||
post: unknown
|
post: unknown
|
||||||
}): Promise<any> {
|
}): Promise<any> {
|
||||||
const mime = await importMime();
|
const getType = (await mime).default.getType;
|
||||||
|
|
||||||
const emojiContext = {
|
const emojiContext = {
|
||||||
toot: 'http://joinmastodon.org/ns#',
|
toot: 'http://joinmastodon.org/ns#',
|
||||||
|
@ -353,15 +347,15 @@ export async function activitypubNote(data: {
|
||||||
return;
|
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({
|
data.object.tag.push({
|
||||||
id: emoji.name,
|
id: url,
|
||||||
type: 'Emoji',
|
type: 'Emoji',
|
||||||
name: whole,
|
name: whole,
|
||||||
icon: {
|
icon: {
|
||||||
type: 'Image',
|
type: 'Image',
|
||||||
mediaType: mime.getType(emoji.image) || '',
|
mediaType: getType(emoji.image) || '',
|
||||||
url: `${route}/${emoji.image}?${buster}`,
|
url,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "5.1.15",
|
"version": "5.1.15",
|
||||||
"description": "Adds extensible emoji functionality to NodeBB",
|
"description": "Adds extensible emoji functionality to NodeBB",
|
||||||
"main": "build/lib",
|
"main": "build/lib",
|
||||||
|
"type": "commonjs",
|
||||||
"author": "Peter Jaszkowiak <p.jaszkow@gmail.com> (https://github.com/pitaj)",
|
"author": "Peter Jaszkowiak <p.jaszkow@gmail.com> (https://github.com/pitaj)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/NodeBB/nodebb-plugin-emoji",
|
"homepage": "https://github.com/NodeBB/nodebb-plugin-emoji",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"library": "build/lib",
|
"library": ".",
|
||||||
"scss": [
|
"scss": [
|
||||||
"public/style.scss"
|
"public/style.scss"
|
||||||
],
|
],
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
"outDir": "build/lib",
|
"outDir": "build/lib",
|
||||||
"lib": ["es2019"],
|
"lib": ["es2019"],
|
||||||
"target": "es2019",
|
"target": "es2019",
|
||||||
"module": "commonjs",
|
"module": "node16",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node16",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"alwaysStrict": true,
|
"alwaysStrict": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"sourceMap": true
|
"sourceMap": true,
|
||||||
|
"skipLibCheck": true
|
||||||
},
|
},
|
||||||
"typeAcquisition": {
|
"typeAcquisition": {
|
||||||
"enable": false
|
"enable": false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue