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