fix(vant-cli): support defineOptions named (#12734)

This commit is contained in:
wChenonly 2024-03-26 22:06:18 +08:00 committed by GitHub
parent 41fb2cc9ed
commit 933e73a4f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,15 +1,15 @@
import fse from 'fs-extra';
import { sep, join } from 'node:path';
import { SRC_DIR, getVantConfig } from './constant.js';
import { InlineConfig, loadConfigFromFile, mergeConfig } from 'vite';
import { type InlineConfig, loadConfigFromFile, mergeConfig } from 'vite';
const { lstatSync, existsSync, readdirSync, readFileSync, outputFileSync } =
fse;
export const EXT_REGEXP = /\.\w+$/;
export const SFC_REGEXP = /\.(vue)$/;
export const DEMO_REGEXP = new RegExp('\\' + sep + 'demo$');
export const TEST_REGEXP = new RegExp('\\' + sep + 'test$');
export const DEMO_REGEXP = new RegExp(`\\${sep}demo$`);
export const TEST_REGEXP = new RegExp(`\\${sep}test$`);
export const ASSET_REGEXP = /\.(png|jpe?g|gif|webp|ico|jfif|svg|woff2?|ttf)$/i;
export const STYLE_REGEXP = /\.(css|less|scss)$/;
export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/;
@ -24,8 +24,12 @@ export function replaceExt(path: string, ext: string) {
return path.replace(EXT_REGEXP, ext);
}
export function hasDefaultExport(code: string) {
return code.includes('export default') || code.includes('export { default }');
export function hasExportOrDefineOptions(code: string) {
return (
code.includes('export default') ||
code.includes('export { default }') ||
code.includes('defineOptions')
);
}
export function getComponents() {
@ -38,7 +42,7 @@ export function getComponents() {
ENTRY_EXTS.some((ext) => {
const path = join(SRC_DIR, dir, `index.${ext}`);
if (existsSync(path)) {
return hasDefaultExport(readFileSync(path, 'utf-8'));
return hasExportOrDefineOptions(readFileSync(path, 'utf-8'));
}
return false;
@ -71,8 +75,8 @@ export function pascalize(str: string): string {
export function decamelize(str: string, sep = '-') {
return str
.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
.replace(/([A-Z])([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
.replace(/([a-z\d])([A-Z])/g, `$1${sep}$2`)
.replace(/([A-Z])([A-Z][a-z\d]+)/g, `$1${sep}$2`)
.toLowerCase();
}