Skip to content

fix: remove import.meta #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Required<Options>, 'include' | 'exclude' | 'transformer' | 'globs' | 'directives' | 'types'> = {
dirs: 'src/components',
Expand Down Expand Up @@ -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')
Expand Down
11 changes: 11 additions & 0 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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