refactor: replace createRequire with import.meta.resolve in config-loader and gitLoader
This commit is contained in:
@@ -2,7 +2,7 @@ import fs from "fs"
|
||||
import path from "path"
|
||||
import YAML from "yaml"
|
||||
import { styleText } from "util"
|
||||
import { createRequire } from "node:module"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { QuartzConfig, GlobalConfiguration, FullPageLayout } from "../../cfg"
|
||||
import { QuartzComponent, QuartzComponentConstructor } from "../../components/types"
|
||||
import { PluginTypes } from "../types"
|
||||
@@ -205,10 +205,9 @@ async function resolvePluginManifest(source: PluginSource): Promise<PluginManife
|
||||
async function readManifestFromPackageJson(source: PluginSource): Promise<PluginManifest | null> {
|
||||
try {
|
||||
const gitSpec = parsePluginSource(source)
|
||||
const require = createRequire(import.meta.url)
|
||||
let pkgPath: string
|
||||
if (gitSpec.npmPackage) {
|
||||
pkgPath = require.resolve(`${gitSpec.name}/package.json`, { paths: [process.cwd()] })
|
||||
pkgPath = fileURLToPath(import.meta.resolve(`${gitSpec.name}/package.json`))
|
||||
} else {
|
||||
const pluginDir = path.join(process.cwd(), ".quartz", "plugins", gitSpec.name)
|
||||
pkgPath = path.join(pluginDir, "package.json")
|
||||
|
||||
@@ -4,7 +4,7 @@ import { execSync } from "child_process"
|
||||
import git from "isomorphic-git"
|
||||
import http from "isomorphic-git/http/node"
|
||||
import { styleText } from "util"
|
||||
import { createRequire } from "module"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { pathToFileURL } from "url"
|
||||
import { PluginSource } from "./types"
|
||||
|
||||
@@ -990,8 +990,7 @@ export async function regeneratePluginIndex(
|
||||
for (const npmPkg of options.npmPackages ?? []) {
|
||||
let distIndex: string | undefined
|
||||
try {
|
||||
const esmRequire = createRequire(import.meta.url)
|
||||
const pkgJsonPath = esmRequire.resolve(`${npmPkg}/package.json`)
|
||||
const pkgJsonPath = fileURLToPath(import.meta.resolve(`${npmPkg}/package.json`))
|
||||
distIndex = path.join(path.dirname(pkgJsonPath), "dist", "index.d.ts")
|
||||
} catch {
|
||||
if (options.verbose) {
|
||||
|
||||
Reference in New Issue
Block a user