Skip to content

fix(element-plus): get esm package version, closes #194 #232

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

Merged
merged 5 commits into from
Dec 6, 2021

Conversation

nabaonan
Copy link
Collaborator

@nabaonan nabaonan commented Dec 4, 2021

fix issue 194 use resolve instead commonjs require() to read package.json version

@sxzz
Copy link
Member

sxzz commented Dec 4, 2021

How about using https://www.npmjs.com/package/local-pkg to get version?

@antfu
Copy link
Member

antfu commented Dec 4, 2021

@sxzz sxzz changed the title fix(element-plus): fix issue 194 use resolve method instead of require fix(element-plus): get esm package version, closes #194 Dec 4, 2021
@nabaonan
Copy link
Collaborator Author

nabaonan commented Dec 4, 2021

How about using https://www.npmjs.com/package/local-pkg to get version?
it is great idea!!

@nabaonan nabaonan requested a review from sxzz as a code owner December 4, 2021 18:04
@nabaonan
Copy link
Collaborator Author

nabaonan commented Dec 5, 2021

the resolver's return type is promise, and not pass the tests, is the resolver type must not be a promise?

@sxzz
Copy link
Member

sxzz commented Dec 5, 2021

@antfu Maybe we can add a sync version to local-pkg

@nabaonan
Copy link
Collaborator Author

nabaonan commented Dec 5, 2021

sync

but getPkgVersion method must be a sync method, i didn't found a good method to resolve it , do you have any other good idea to make async method to sync.

@antfu
Copy link
Member

antfu commented Dec 5, 2021

You can just make getPkgVersion async and move the usage inside resolve which supports awats.

@antfu
Copy link
Member

antfu commented Dec 5, 2021

export function ElementPlusResolver(
  options: ElementPlusResolverOptions = {},
): ComponentResolver[] {
  let optionsResolved: ElementPlusResolverOptionsResolved | undefined

  async function resolveOptions() {
    if (optionsResolved)
      return optionsResolved
    optionsResolved = {
      ssr: false,
      version: await getPkgVersion('element-plus', '1.1.0-beta.21'),
      importStyle: 'css',
      directives: true,
      ...options,
    }
    return optionsResolved
  }

  return [
    {
      type: 'component',
      resolve: async(name: string) => {
        return resolveComponent(name, await resolveOptions())
      },
    },
    {
      type: 'directive',
      resolve: async(name: string) => {
        return resolveDirective(name, await resolveOptions())
      },
    },
  ]
}

@antfu antfu merged commit 1455aad into unplugin:main Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESM throw a Error 'Dynamic require of "element-plus/package.json" is not supported'
3 participants
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