From 88e54e0e87c274bf980418d328bbb2fff76679e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A4=8D=E6=88=90=E6=A8=91?= Date: Tue, 9 Aug 2022 12:21:46 +0800 Subject: [PATCH] fix: remove import.meta --- src/core/options.ts | 3 ++- src/core/utils.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/options.ts b/src/core/options.ts index 18b58de0..44a5f6bf 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -4,6 +4,7 @@ import { slash, toArray } from '@antfu/utils' import { isPackageExists } from 'local-pkg' import type { ComponentResolver, ComponentResolverObject, Options, ResolvedOptions } from '../types' import { detectTypeImports } from './type-imports/detect' +import { getFileUrl } from './utils' export const defaultOptions: Omit, 'include' | 'exclude' | 'transformer' | 'globs' | 'directives' | 'types'> = { dirs: 'src/components', @@ -76,7 +77,7 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions return resolved } -const _require = typeof require === 'undefined' ? createRequire(import.meta.url) : require +const _require = typeof require === 'undefined' ? createRequire(getFileUrl()) : require function getVueVersion() { try { const vue = _require('vue') diff --git a/src/core/utils.ts b/src/core/utils.ts index 39cec494..0111d796 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -213,3 +213,14 @@ export function resolveImportPath(importName: string): string | undefined { preserveSymlinks: false, }) } + +// @see https://jacobdeichert.ca/blog/2020/02/a-super-hacky-alternative-to-import-meta-url/ +export function getFileUrl() { + const stackTraceFrames = String(new Error('fake error').stack) + .replace(/^Error.*\n/, '') + .split('\n') + + const callerFrame = stackTraceFrames[1] + + return callerFrame.match(/file:.*\.m?js/)?.[0] ?? '' +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy