refactor(@vant/cli): migrate to ESM package
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { get } from 'lodash';
|
||||
import { existsSync } from 'fs-extra';
|
||||
import { get } from 'lodash-es';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { createRequire } from 'module';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { join, dirname, isAbsolute } from 'path';
|
||||
|
||||
function findRootDir(dir: string): string {
|
||||
@@ -25,12 +27,13 @@ export const VETUR_DIR = join(ROOT, 'vetur');
|
||||
export const SITE_DIST_DIR = join(ROOT, 'site-dist');
|
||||
export const VANT_CONFIG_FILE = join(ROOT, 'vant.config.js');
|
||||
export const PACKAGE_JSON_FILE = join(ROOT, 'package.json');
|
||||
export const ROOT_POSTCSS_CONFIG_FILE = join(ROOT, 'postcss.config.js');
|
||||
|
||||
// Relative paths
|
||||
export const DIST_DIR = join(__dirname, '../../dist');
|
||||
export const CONFIG_DIR = join(__dirname, '../config');
|
||||
export const SITE_SRC_DIR = join(__dirname, '../../site');
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
export const CJS_DIR = join(__dirname, '..', '..', 'cjs');
|
||||
export const DIST_DIR = join(__dirname, '..', '..', 'dist');
|
||||
export const CONFIG_DIR = join(__dirname, '..', 'config');
|
||||
export const SITE_SRC_DIR = join(__dirname, '..', '..', 'site');
|
||||
|
||||
// Dist files
|
||||
export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'package-entry.js');
|
||||
@@ -43,23 +46,19 @@ export const SITE_DESKTOP_SHARED_FILE = join(
|
||||
export const STYLE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
||||
|
||||
// Config files
|
||||
export const POSTCSS_CONFIG_FILE = join(CONFIG_DIR, 'postcss.config.js');
|
||||
export const JEST_SETUP_FILE = join(CONFIG_DIR, 'jest.setup.js');
|
||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||
export const JEST_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js');
|
||||
export const JEST_FILE_MOCK_FILE = join(CONFIG_DIR, 'jest.file-mock.js');
|
||||
export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js');
|
||||
export const POSTCSS_CONFIG_FILE = join(CJS_DIR, 'postcss.config.cjs');
|
||||
export const JEST_CONFIG_FILE = join(CJS_DIR, 'jest.config.cjs');
|
||||
|
||||
export const SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx'];
|
||||
export const STYLE_EXTS = ['.css', '.less', '.scss'];
|
||||
|
||||
export function getPackageJson() {
|
||||
delete require.cache[PACKAGE_JSON_FILE];
|
||||
|
||||
return require(PACKAGE_JSON_FILE);
|
||||
const rawJson = readFileSync(PACKAGE_JSON_FILE, 'utf-8');
|
||||
return JSON.parse(rawJson);
|
||||
}
|
||||
|
||||
export function getVantConfig() {
|
||||
const require = createRequire(import.meta.url);
|
||||
delete require.cache[VANT_CONFIG_FILE];
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { get } from 'lodash';
|
||||
import { get } from 'lodash-es';
|
||||
import { existsSync } from 'fs';
|
||||
import { join, isAbsolute } from 'path';
|
||||
import { getVantConfig } from '../common';
|
||||
import { STYLE_DIR, SRC_DIR } from './constant';
|
||||
import { getVantConfig } from '../common/index.js';
|
||||
import { STYLE_DIR, SRC_DIR } from './constant.js';
|
||||
|
||||
type CSS_LANG = 'css' | 'less' | 'scss';
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { get } from 'lodash';
|
||||
import fse from 'fs-extra';
|
||||
import { get } from 'lodash-es';
|
||||
import { sep, join } from 'path';
|
||||
import {
|
||||
lstatSync,
|
||||
existsSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
outputFileSync,
|
||||
} from 'fs-extra';
|
||||
import { SRC_DIR, getVantConfig } from './constant';
|
||||
import { SRC_DIR, getVantConfig } from './constant.js';
|
||||
import type { InlineConfig } 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$');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import ora from 'ora';
|
||||
import chalk from 'chalk';
|
||||
import consola from 'consola';
|
||||
import { ROOT } from '../common/constant';
|
||||
import { ROOT } from '../common/constant.js';
|
||||
|
||||
export function slimPath(path: string) {
|
||||
return chalk.yellow(path.replace(ROOT, ''));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import execa from 'execa';
|
||||
import { consola } from './logger';
|
||||
import { consola } from './logger.js';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
let hasYarnCache: boolean;
|
||||
|
||||
Reference in New Issue
Block a user