Skip to content

Commit

Permalink
fix: working in pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Apr 14, 2024
1 parent b6ebbca commit 8dae536
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/hexo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Database from 'warehouse';
import { magenta, underline } from 'picocolors';
import { EventEmitter } from 'events';
import { readFile } from 'hexo-fs';
import { realpath } from 'node:fs/promises';
import Module from 'module';
import { runInThisContext } from 'vm';
const { version } = require('../../package.json');
Expand Down Expand Up @@ -471,11 +472,12 @@ class Hexo extends EventEmitter {
}

loadPlugin(path: string, callback?: NodeJSLikeCallback<any>): Promise<any> {
return readFile(path).then(script => {
// use real path to support pnpm
return Promise.all([readFile(path), realpath(path)]).then(([script, rpath]) => {
// Based on: https://github.com/nodejs/node-v0.x-archive/blob/v0.10.33/src/node.js#L516
const module = new Module(path);
module.filename = path;
module.paths = Module._nodeModulePaths(path);
module.paths = Module._nodeModulePaths(rpath);

function req(path: string) {
return module.require(path);
Expand Down

0 comments on commit 8dae536

Please sign in to comment.