Skip to content

Commit

Permalink
feat(element-plus): support nightly option (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored and sxzz committed Aug 30, 2023
1 parent f83d9c4 commit 48d7821
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/core/resolvers/element-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface ElementPlusResolverOptions {
* a list of component names that have no styles, so resolving their styles file should be prevented
*/
noStylesComponents?: string[]

/**
* nightly version
*/
nightly?: boolean
}

type ElementPlusResolverOptionsResolved = Required<Omit<ElementPlusResolverOptions, 'exclude'>> &
Expand Down Expand Up @@ -73,9 +78,9 @@ function getSideEffectsLegacy(
}

function getSideEffects(dirName: string, options: ElementPlusResolverOptionsResolved): SideEffectsInfo | undefined {
const { importStyle, ssr } = options
const themeFolder = 'element-plus/theme-chalk'
const esComponentsFolder = 'element-plus/es/components'
const { importStyle, ssr, nightly } = options
const themeFolder = nightly ? '@element-plus/nightly/theme-chalk' : 'element-plus/theme-chalk'
const esComponentsFolder = nightly ? '@element-plus/nightly/es/components' : 'element-plus/es/components'

if (importStyle === 'sass') {
return ssr
Expand Down Expand Up @@ -104,13 +109,13 @@ function resolveComponent(name: string, options: ElementPlusResolverOptionsResol
}

const partialName = kebabCase(name.slice(2))// ElTableColumn -> table-column
const { version, ssr } = options
const { version, ssr, nightly } = options

// >=1.1.0-beta.1
if (compare(version, '1.1.0-beta.1', '>=')) {
if (compare(version, '1.1.0-beta.1', '>=') || nightly) {
return {
name,
from: `element-plus/${ssr ? 'lib' : 'es'}`,
from: `${nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`,
sideEffects: getSideEffects(partialName, options),
}
}
Expand Down Expand Up @@ -144,13 +149,13 @@ function resolveDirective(name: string, options: ElementPlusResolverOptionsResol
if (!directive)
return

const { version, ssr } = options
const { version, ssr, nightly } = options

// >=1.1.0-beta.1
if (compare(version, '1.1.0-beta.1', '>=')) {
if (compare(version, '1.1.0-beta.1', '>=') || nightly) {
return {
name: directive.importName,
from: `element-plus/${ssr ? 'lib' : 'es'}`,
from: `${nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`,
sideEffects: getSideEffects(directive.styleName, options),
}
}
Expand Down Expand Up @@ -183,6 +188,7 @@ export function ElementPlusResolver(
directives: true,
exclude: undefined,
noStylesComponents: options.noStylesComponents || [],
nightly: false,
...options,
}
return optionsResolved
Expand Down

0 comments on commit 48d7821

Please sign in to comment.