diff --git a/packages/cli-shared/package.json b/packages/cli-shared/package.json index db64610..587986e 100644 --- a/packages/cli-shared/package.json +++ b/packages/cli-shared/package.json @@ -9,6 +9,7 @@ "homepage": "https://github.com/xus-code/bundle-tools/tree/master/packages/cli-utils#readme", "license": "MIT", "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist" ], @@ -53,4 +54,4 @@ "@types/rimraf": "^3.0.0", "@types/yargs-parser": "^20.2.0" } -} \ No newline at end of file +} diff --git a/packages/plugin-cmd-lib/README.md b/packages/cli-types/README.md similarity index 51% rename from packages/plugin-cmd-lib/README.md rename to packages/cli-types/README.md index 5ed7bd3..52a3aa7 100644 --- a/packages/plugin-cmd-lib/README.md +++ b/packages/cli-types/README.md @@ -1,11 +1,11 @@ -# `cli` +# `@xus/cli-types` > TODO: description ## Usage ``` -const cli = require('cli'); +const cliUtils = require('@xus/cli-types'); // TODO: DEMONSTRATE API ``` diff --git a/packages/cli-types/package.json b/packages/cli-types/package.json new file mode 100644 index 0000000..81d1f28 --- /dev/null +++ b/packages/cli-types/package.json @@ -0,0 +1,36 @@ +{ + "name": "@xus/cli-types", + "version": "0.1.0", + "description": "cli utils", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "keywords": [ + "utils" + ], + "author": "guo.xu ", + "homepage": "https://github.com/xus-code/bundle-tools/tree/master/packages/cli-utils#readme", + "license": "MIT", + "files": [ + "dist" + ], + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/xus-code/cli.git" + }, + "bugs": { + "url": "https://github.com/xus-code/cli/issues" + }, + "scripts": { + "build:types": "tsc" + }, + "dependencies": { + "@xus/cli-shared": "^0.1.4", + "@xus/core": "^0.1.5", + "@xus/rollup-chain": "^0.2.6", + "esbuild": "^0.9.2", + "webpack-chain": "^6.5.1" + } +} diff --git a/packages/cli-types/src/index.ts b/packages/cli-types/src/index.ts new file mode 100644 index 0000000..11e0a12 --- /dev/null +++ b/packages/cli-types/src/index.ts @@ -0,0 +1,26 @@ +import webpackChain from 'webpack-chain' +// empty +import { IPlugin, IPreset, IConfig } from './types' + +type IReturnArg = (args: T) => T + +type PartialDeep> = { + [K in keyof T]?: T[K] extends Record + ? PartialDeep + : T[K] +} + +export const defineConfig: IReturnArg> = (config) => config + +export const createPlugin: IReturnArg = (plugin) => plugin + +export const createPreset: IReturnArg = (preset) => preset + +// types +export * from './types' + +export type { IArgs, IRawArgs, ICommand } from '@xus/core' + +export type { IRollupChain, IRollupChainConfig } from '@xus/rollup-chain' + +export type IWebpackChain = webpackChain diff --git a/packages/cli-types/src/types.ts b/packages/cli-types/src/types.ts new file mode 100644 index 0000000..e30f4cb --- /dev/null +++ b/packages/cli-types/src/types.ts @@ -0,0 +1,124 @@ +import { + IPlugin as IPluginBase, + IFastHookRegister, + IArgs, + IRawArgs, + IPluginAPI as IPluginAPIBase, + IPathManager, + IConfigManager, + IEnvManager, + IPluginManager, + IProjectConfig +} from '@xus/core' +import type { IBabelRegister, IRunCmdMessage } from '@xus/cli-shared' +// preset api +import type { IRollupChain, IRollupChainConfig } from '@xus/rollup-chain' +import webpackChain from 'webpack-chain' +import { TransformOptions } from 'esbuild' + +// Hooks Types +// type IEvent = any +// type ISerial = any +// type IParallel = any +// type IAdd = any + +// IPluginAPI +type noopFn = () => any + +export interface IPluginAPI extends IPluginAPIBase { + // service api + BabelRegister: IBabelRegister + // service lifycycle + onSetuped: (config: IConfig) => void + onRunCmd: noopFn + getCmdArgs: () => { args: IArgs; rawArgs: IRawArgs } + modifyProjectConfig: (config: IConfig) => void + + // path manager + cwd: IPathManager['cwd'] + cwdPkg: IPathManager['cwdPkg'] + userConfigPath: IPathManager['userConfigPath'] + getPathBasedOnCtx: IPathManager['getPathBasedOnCtx'] + getLernaPkgs: IPathManager['getLernaPkgs'] + + // env manager + mode: IEnvManager['mode'] + babelEnv: IEnvManager['babelEnv'] + getEnv: IEnvManager['getEnv'] + setEnv: IEnvManager['setEnv'] + getCliEnv: IEnvManager['getCliEnv'] + setCliEnv: IEnvManager['setCliEnv'] + + // config manager + projectConfig: IConfig + cwdPkgJson: IConfigManager['cwdPkgJson'] + loadConfig: IConfigManager['loadConfig'] + + // plugin manager + skipPlugin: IPluginManager['skipPlugin'] + + // rollup + modifyRollupConfig: IFastHookRegister<(rc: IRollupChain) => IRollupChain> + getRollupConfig: () => Promise + // webpack + modifyWebpackConfig: IFastHookRegister<(wc: webpackChain) => webpackChain> + getWebpackConfig: () => Promise +} + +// IConfig +export interface IConfig extends IProjectConfig { + libBuild: { + libName: string + // transform: 'esbuild' | 'babel' + minify: false | 'esbuild' | 'terser' + target: 'esnext' | TransformOptions['target'] + formats: ('esm' | 'cjs' | 'iife' | 'umd')[] + rollTypes: boolean + sourcemap: boolean + alwaysEmptyDistDir: boolean + + // lerna mode + pkgsOrder: string[] + + // insider + rollupChain: (rc: IRollupChain) => IRollupChain + } + lint: { + eslint: + | boolean + | { + include?: string + ext?: string[] + } + stylelint: + | boolean + | { + include?: string[] + } + } + changelog: { + filename: string + mainTemplate: string + headerPartial: string + commitPartial: string + } + release: { + // before hooks for run lint test build... + beforeRelease: { + bin: string + args: string[] + message: IRunCmdMessage + }[] + // in lenra mode to ensure pkg publish order + order: string[] + branch: string + } +} + +// IPlugin +export type IPlugin = IPluginBase<(api: IPluginAPI) => void> + +// IPreset +export interface IPreset { + plugins: IPlugin[] +} diff --git a/packages/plugin-build-lib/tsconfig.json b/packages/cli-types/tsconfig.json similarity index 100% rename from packages/plugin-build-lib/tsconfig.json rename to packages/cli-types/tsconfig.json diff --git a/packages/cli/package.json b/packages/cli/package.json index 74d22f9..7de45f7 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -30,8 +30,9 @@ "url": "https://github.com/xus-code/bundle-tools/issues" }, "dependencies": { + "@xus/cli-types": "^0.1.0", "@xus/cli-shared": "^0.1.4", "@xus/core": "^0.1.5", "@xus/preset-built-in": "^0.1.7" } -} \ No newline at end of file +} diff --git a/packages/cli/src/exports/create.ts b/packages/cli/src/exports/create.ts deleted file mode 100644 index bf25c44..0000000 --- a/packages/cli/src/exports/create.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { IPlugin as IPluginBase, IProjectConfig } from '@xus/core' -import type { - ILibBuildConfig, - ILintConfig, - IChangelogConfig, - IReleaseConfig -} from '@xus/preset-built-in' -import type { IPluginAPI } from './pluginAPI' - -export interface IConfig extends IProjectConfig { - libBuild: ILibBuildConfig - lint: ILintConfig - changelog: IChangelogConfig - release: IReleaseConfig -} - -type IDeepPartial = { - [K in keyof T]?: - | (T[K] extends Record ? IDeepPartial : T[K]) - | undefined -} - -export type IPlugin = IPluginBase<(api: IPluginAPI) => void> - -export interface IPreset { - plugins: IPlugin[] -} - -export const createPlugin = (plugin: IPlugin) => plugin -export const createPreset = (preset: IPreset) => preset - -export const defineConfig = (config: IDeepPartial) => config diff --git a/packages/cli/src/exports/index.ts b/packages/cli/src/exports/index.ts deleted file mode 100644 index b524b5e..0000000 --- a/packages/cli/src/exports/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './create' -export * from './pluginAPI' diff --git a/packages/cli/src/exports/pluginAPI.ts b/packages/cli/src/exports/pluginAPI.ts deleted file mode 100644 index 09e1258..0000000 --- a/packages/cli/src/exports/pluginAPI.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { - IPluginAPI as IPluginAPIBase, - IPathManager, - IConfigManager, - IEnvManager, - IPluginManager, - IArgs, - IRawArgs -} from '@xus/core' -import type { IBabelRegister } from '@xus/cli-shared' -import { IBuildLibMethods } from '@xus/preset-built-in' -import type { IConfig } from './create' - -type noopFn = () => any - -export interface IPluginAPI extends IPluginAPIBase { - // service api - BabelRegister: IBabelRegister - // service lifycycle - onPluginReady: noopFn - onRunCmd: noopFn - getCmdArgs: () => { args: IArgs; rawArgs: IRawArgs } - - // path manager - cwd: IPathManager['cwd'] - cwdPkg: IPathManager['cwdPkg'] - userConfigPath: IPathManager['userConfigPath'] - getPathBasedOnCtx: IPathManager['getPathBasedOnCtx'] - getLernaPkgs: IPathManager['getLernaPkgs'] - - // env manager - mode: IEnvManager['mode'] - babelEnv: IEnvManager['babelEnv'] - getEnv: IEnvManager['getEnv'] - setEnv: IEnvManager['setEnv'] - getCliEnv: IEnvManager['getCliEnv'] - setCliEnv: IEnvManager['setCliEnv'] - - // config manager - projectConfig: IConfig - cwdPkgJson: IConfigManager['cwdPkgJson'] - loadConfig: IConfigManager['loadConfig'] - - // plugin manager - skipPlugin: IPluginManager['skipPlugin'] - - // build lib plugin - modifyLibBundler: IBuildLibMethods['modifyLibBundler'] - modifyRollupConfig: IBuildLibMethods['modifyRollupConfig'] - getRollupChainConfig: IBuildLibMethods['getRollupChainConfig'] - onLibBuildFailed: IBuildLibMethods['onLibBuildFailed'] - onLibBuildSucceed: IBuildLibMethods['onLibBuildSucceed'] - runLibBuild: IBuildLibMethods['runLibBuild'] -} diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 50c4dcb..903bba0 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,15 +1,5 @@ export * from '@xus/cli-shared' export { CliService, HookTypes } from '@xus/core' -// compose plugin with core -export * from './exports' -// plugins -export * from '@xus/preset-built-in' // types -export type { - IArgs, - IRawArgs, - ICommand, - IHook, - IFastHookRegister -} from '@xus/core' +export * from '@xus/cli-types' diff --git a/packages/core/src/cli/Service.ts b/packages/core/src/cli/Service.ts index f9b67a5..f9c0501 100644 --- a/packages/core/src/cli/Service.ts +++ b/packages/core/src/cli/Service.ts @@ -1,5 +1,11 @@ // types -import type { ICliServerOps, ICommand, IArgs, IRawArgs } from '../types' +import type { + ICliServerOps, + ICommand, + IArgs, + IRawArgs, + IProjectConfig +} from '../types' import { Logger, BabelRegister } from '@xus/cli-shared' import { CliServiceStage, HookTypes } from '../enums' import { CONFIG_FILES } from '../constants' @@ -102,7 +108,7 @@ export class CliService { this.PluginManager.applyPlugins() // plugin register hooks ready await this.HookManager.apply({ - name: 'pluginsReady', + name: 'onSetuped', type: HookTypes.event, args: this.ConfigManager.projectConfig }) @@ -111,9 +117,16 @@ export class CliService { getPluginAPI(ops: { pluginName: string }) { const api = new PluginAPI({ ...ops, service: this }) // register service lifycycle - ;['onConfigReady', 'onPluginReady', 'onRunCmd'].forEach((methodName) => { + ;['onSetuped', 'onRunCmd'].forEach((methodName) => { api.registerMethod({ methodName, throwOnExist: false }) }) + api.registerMethod({ + methodName: 'modifyProjectConfig', + throwOnExist: false, + fn: (config: IProjectConfig) => { + this.ConfigManager.modifyProjectConfig(config) + } + }) // register cmd args getter api.registerMethod({ methodName: 'getCmdArgs', @@ -201,7 +214,7 @@ export class CliService { // 4. emit a start event this.setStage(CliServiceStage.runCmd) await this.HookManager.apply({ - name: 'runCmd', + name: 'onRunCmd', type: HookTypes.event }) // for api diff --git a/packages/core/src/manager/ConfigManager.ts b/packages/core/src/manager/ConfigManager.ts index a094b60..d36f1ba 100644 --- a/packages/core/src/manager/ConfigManager.ts +++ b/packages/core/src/manager/ConfigManager.ts @@ -3,8 +3,6 @@ import type { ICliService } from '../cli/Service' import { Logger, loadModule, deepmerge, validateSchema } from '@xus/cli-shared' import { defaultProjectConfig, ProjectConfigSchema } from '../config' -type IProjectConfigPartial = Partial - type IConfigManagerOps = { service: ICliService } @@ -26,11 +24,11 @@ export class ConfigManager { this.pkgJson = this.resolvePkg() } - private resolvePkg(): IPackage { + private resolvePkg(): IPackage | null { try { return require(this.service.PathManager.cwdPkg) } catch (e) { - return {} + return null } } @@ -66,7 +64,7 @@ export class ConfigManager { // 1. load userConfig const path = this.service.PathManager.userConfigPath const userConfig = path - ? loadModule(path, (err) => { + ? loadModule(path, (err) => { logger.error(`user config load failed, ${err}`) }) : {} @@ -121,6 +119,10 @@ export class ConfigManager { const configContent = loadModule(configPath, onError) return configContent } + + modifyProjectConfig(config: IProjectConfig) { + this.finalConfig = deepmerge(this.projectConfig, config) + } } export type IConfigManager = InstanceType diff --git a/packages/core/src/manager/HookManager.ts b/packages/core/src/manager/HookManager.ts index e377ef7..34d068e 100644 --- a/packages/core/src/manager/HookManager.ts +++ b/packages/core/src/manager/HookManager.ts @@ -8,7 +8,7 @@ type IHookManagerOps = { service: ICliService } -const builtinHooks = ['configReady', 'pluginsReady', 'runCmd'] +const builtinHooks = ['configReady', 'onPluginsReady', 'onRunCmd'] const logger = new Logger(`xus:service:HookManager`) export class HookManager { diff --git a/packages/core/src/types/cli.ts b/packages/core/src/types/cli.ts index 62347a8..405824f 100644 --- a/packages/core/src/types/cli.ts +++ b/packages/core/src/types/cli.ts @@ -8,7 +8,8 @@ export type ICliServerOps = { } export interface IPackage { - name?: string + name: string + version: string dependencies?: Record devDependencies?: Record [key: string]: any diff --git a/packages/core/src/types/command.ts b/packages/core/src/types/command.ts index 8df53c7..97f23b2 100644 --- a/packages/core/src/types/command.ts +++ b/packages/core/src/types/command.ts @@ -1,7 +1,10 @@ import type { IArgs, IRawArgs } from '.' // commands -export type ICommandFn = (args: IArgs, rawArgs: IRawArgs) => any | Promise +export type ICommandFn = IArgs> = ( + args: T, + rawArgs: IRawArgs +) => any | Promise export interface ICommandOps { desc?: string usage?: string @@ -12,8 +15,8 @@ export interface ICommandOps { [key: string]: string } } -export interface ICommand { +export interface ICommand { pluginName: string ops: ICommandOps | null - fn: ICommandFn + fn: ICommandFn } diff --git a/packages/core/src/types/plugin.ts b/packages/core/src/types/plugin.ts index 1fe62ad..e733b83 100644 --- a/packages/core/src/types/plugin.ts +++ b/packages/core/src/types/plugin.ts @@ -1,7 +1,7 @@ import type { IConfigSchema } from '@xus/cli-shared' // plugins / presets -// api type override in @xus/cli +// api type override in @xus/cli-types export type IPluginApply = (api: any) => void type IEnforce = 'post' | 'pre' diff --git a/packages/plugin-build-lib/.DS_Store b/packages/plugin-build-lib/.DS_Store deleted file mode 100644 index feca861..0000000 Binary files a/packages/plugin-build-lib/.DS_Store and /dev/null differ diff --git a/packages/plugin-build-lib/package.json b/packages/plugin-build-lib/package.json deleted file mode 100644 index 4283391..0000000 --- a/packages/plugin-build-lib/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@xus/plugin-build-lib", - "version": "0.1.6", - "description": "xus cli plugin build-lib", - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "keywords": [ - "cli", - "build" - ], - "author": "guo.xu ", - "homepage": "https://github.com/xus-code/bundle-tools/tree/master/packages/cli#readme", - "license": "MIT", - "files": [ - "dist" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/xus-code/bundle-tools.git" - }, - "scripts": { - "dev:blib": "tsc --watch", - "build:blib": "tsc" - }, - "bugs": { - "url": "https://github.com/xus-code/bundle-tools/issues" - }, - "dependencies": { - "@xus/cli": "^0.1.6", - "@xus/rollup-chain": "^0.2.3", - "rollup": "^2.40.0" - } -} \ No newline at end of file diff --git a/packages/plugin-build-lib/src/bundler/index.ts b/packages/plugin-build-lib/src/bundler/index.ts deleted file mode 100644 index f75e285..0000000 --- a/packages/plugin-build-lib/src/bundler/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './rollupBundler' - -export * from './types' diff --git a/packages/plugin-build-lib/src/bundler/rollupBundler.ts b/packages/plugin-build-lib/src/bundler/rollupBundler.ts deleted file mode 100644 index bd37829..0000000 --- a/packages/plugin-build-lib/src/bundler/rollupBundler.ts +++ /dev/null @@ -1,163 +0,0 @@ -import type { IPluginAPI } from '@xus/cli' -import type { IRollupChainConfig } from '@xus/rollup-chain' -import type { IBundlerImp, ILibBuildTargets } from '../plugin/types' -import type { IDoBuildOps } from './types' -import { Logger, isLernaPkg, chalk, orderBy } from '@xus/cli' -import { basename, join } from 'path' -import { rollup, watch } from 'rollup' -import rollupValidator from './validator' - -const logger = new Logger(`xus:bundler:rollup`) -export class RollupBundler implements IBundlerImp { - private api - - constructor(api: IPluginAPI) { - this.api = api - } - - private async getConfig(target: ILibBuildTargets) { - // get final config - const rollupChain = await this.api.getRollupChainConfig(target) - - logger.debug(`apply modify rollup config hook success`) - - return rollupChain.toConfig() - } - - private validConfig(config: IRollupChainConfig) { - rollupValidator(config) - } - - async build( - ops = { - targets: ['esm', 'cjs', 'browser'], - watch: false - } - ) { - logger.debug(`build ops `) - logger.debug(ops) - const { targets, ...rest } = ops - const islerna = isLernaPkg(this.api.cwd) - this.memoPkgs = null - for (const target of targets as ILibBuildTargets[]) { - logger.info( - chalk.yellow( - `[${rest.watch ? 'Watch' : 'Rollup'}] ${target} bundler start \n` - ) - ) - if (islerna) { - this.api.setCliEnv('Lerna_Root', this.api.cwd) - await this.doBuildForLerna({ - target, - ...rest - }) - } else { - await this.doBuild({ - target, - ...rest - }) - } - } - return { - watch: ops.watch - } - } - - private async doBuild(ops: IDoBuildOps) { - const { target, watch } = ops - logger.debug(`get rollup config: `) - const config = await this.getConfig(target) - logger.debug(config) - logger.debug(`do build in cwd `) - logger.debug(this.api.cwd) - // 1. get config - if (config) { - // 2. validate config - this.validConfig(config) - // real build - const { input, ...restConfig } = config - if (Array.isArray(input)) { - for (const i of input) { - await this.rollup( - { - input: i, - ...restConfig - }, - watch - ) - } - } else { - await this.rollup(config, watch) - } - } else { - logger.wran(`build target ${target} has no config to rollup`) - } - return {} - } - - private memoPkgs: string[] | null = null - private async doBuildForLerna(ops: IDoBuildOps) { - // lerna pkg - logger.debug(`do lerna pkgs build `) - if (!this.memoPkgs) { - const order = ops?.order - const pointPkg = ops?.pointPkg - const filterPkgs = this.api - .getLernaPkgs() - .filter((pkg) => (pointPkg ? pointPkg.includes(basename(pkg)) : true)) - // to order - if (!order) { - this.memoPkgs = filterPkgs - } else { - const fp = filterPkgs.map((p) => basename(p)) - const dirname = join(this.api.cwd, 'packages') - this.memoPkgs = orderBy(fp, order || []).map((o) => join(dirname, o)) - } - logger.debug(this.memoPkgs) - } - - const saveCwd = this.api.cwd - for (const pkg of this.memoPkgs) { - process.chdir(pkg) - await this.doBuild(ops) - } - process.chdir(saveCwd) - - logger.debug(`lerna pkgs build done back cwd`) - logger.debug(this.api.cwd) - return {} - } - - private async rollup(config: IRollupChainConfig, isWatch = false) { - if (isWatch) { - const watcher = watch([ - { - ...config, - watch: config?.watch ? config.watch : {} - } - ]) - watcher.on('event', (event: any) => { - if (event.error) { - this.api.logger.error(event.error) - } else if (event.code === 'START') { - this.api.logger.log(`Rebuild since file changed`) - } - }) - process.once('SIGINT', () => { - watcher.close() - }) - } else { - const { input, output, ...buildConfig } = config - logger.info(chalk.green(`[Write] ${input} -> ${output.file}`)) - const bundler = await rollup({ - input, - ...buildConfig, - watch: false - }) - await bundler.write(output) - await bundler.close() - } - } -} - -export type IRollupBundler = InstanceType diff --git a/packages/plugin-build-lib/src/bundler/types.ts b/packages/plugin-build-lib/src/bundler/types.ts deleted file mode 100644 index 033f966..0000000 --- a/packages/plugin-build-lib/src/bundler/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { ILibBuildTargets, ILibBuildOps } from '../plugin/types' - -export type IDoBuildOps = { - target: ILibBuildTargets -} & Omit diff --git a/packages/plugin-build-lib/src/index.ts b/packages/plugin-build-lib/src/index.ts deleted file mode 100644 index 227573f..0000000 --- a/packages/plugin-build-lib/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import cmdLibPlugin from './plugin' -export default cmdLibPlugin - -export * from '@xus/rollup-chain' -export * from './plugin/enum' -export * from './plugin/types' diff --git a/packages/plugin-build-lib/src/plugin/config.ts b/packages/plugin-build-lib/src/plugin/config.ts deleted file mode 100644 index 44347cf..0000000 --- a/packages/plugin-build-lib/src/plugin/config.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { ILibBuildConfig } from './types' -import { createSchema } from '@xus/cli' - -export const libBuildSchema = createSchema((joi) => - joi.object({ - targets: joi.array(), - pointPkgs: joi.array(), - pkgOrder: joi.array(), - rollupChain: joi.function(), - rollTypes: joi.boolean() - }) -) - -export const defaultLibBuildConfig: () => ILibBuildConfig = () => { - return { - targets: [], - rollTypes: false - } -} diff --git a/packages/plugin-build-lib/src/plugin/enum.ts b/packages/plugin-build-lib/src/plugin/enum.ts deleted file mode 100644 index 75a6ce8..0000000 --- a/packages/plugin-build-lib/src/plugin/enum.ts +++ /dev/null @@ -1,9 +0,0 @@ -export enum BuildLibMethods { - ModifyLibBundler = 'modifyLibBundler', - ModifyRollupConfig = 'modifyRollupConfig', - GetRollupChainConfig = 'getRollupChainConfig', - - OnLibBuildSucceed = 'onLibBuildSucceed', - OnLibBuildFailed = 'onLibBuildFailed', - RunLibBuild = 'runLibBuild' -} diff --git a/packages/plugin-build-lib/src/plugin/index.ts b/packages/plugin-build-lib/src/plugin/index.ts deleted file mode 100644 index fcb769b..0000000 --- a/packages/plugin-build-lib/src/plugin/index.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { IBundler, ILibBuildOps, ILibBuildTargets } from './types' -import RollupChain from '@xus/rollup-chain' -import { createPlugin, HookTypes } from '@xus/cli' -import { RollupBundler } from '../bundler' -import { defaultLibBuildConfig, libBuildSchema } from './config' -import { BuildLibMethods } from './enum' -import { getModifyConfigCtx } from './utils' - -export default createPlugin({ - name: 'lib:build', - enforce: 'pre', - apply(api) { - // global method - // fast hook register method - api.registerMethod({ - methodName: BuildLibMethods.ModifyLibBundler, - throwOnExist: false - }) - api.registerMethod({ - methodName: BuildLibMethods.ModifyRollupConfig, - throwOnExist: false - }) - api.registerMethod({ - methodName: BuildLibMethods.OnLibBuildSucceed, - throwOnExist: false - }) - api.registerMethod({ - methodName: BuildLibMethods.OnLibBuildFailed, - throwOnExist: false - }) - // quick get - api.registerMethod({ - methodName: BuildLibMethods.GetRollupChainConfig, - throwOnExist: false, - fn: async (target: ILibBuildTargets) => { - const rc = new RollupChain() - return await api.applyHook({ - name: BuildLibMethods.ModifyRollupConfig, - type: HookTypes.serial, - initialValue: rc, - args: getModifyConfigCtx(target) - }) - } - }) - api.registerMethod({ - methodName: BuildLibMethods.RunLibBuild, - throwOnExist: false, - fn: async (ops: ILibBuildOps) => { - api.logger.debug(`get lib bundler: `) - // get lib bundler - const LibBundler = await api.applyHook({ - name: BuildLibMethods.ModifyLibBundler, - type: HookTypes.serial, - initialValue: RollupBundler - }) - api.logger.debug(LibBundler) - - const libBundler = new LibBundler(api) - - try { - const stats = await libBundler.build(ops) - await api.applyHook({ - name: BuildLibMethods.OnLibBuildSucceed, - type: HookTypes.event, - args: stats - }) - } catch (e) { - await api.applyHook({ - name: BuildLibMethods.OnLibBuildFailed, - type: HookTypes.event, - args: e - }) - } - } - }) - }, - config: { - key: 'libBuild', - default: defaultLibBuildConfig, - schema: libBuildSchema - } -}) diff --git a/packages/plugin-build-lib/src/plugin/types.ts b/packages/plugin-build-lib/src/plugin/types.ts deleted file mode 100644 index d401896..0000000 --- a/packages/plugin-build-lib/src/plugin/types.ts +++ /dev/null @@ -1,78 +0,0 @@ -import type { IPluginAPI, IFastHookRegister } from '@xus/cli' -import type { IRollupChain } from '@xus/rollup-chain' -import { BuildLibMethods } from './enum' - -// for register method -export interface IBuildLibMethods { - [BuildLibMethods.ModifyLibBundler]: IFastHookRegister< - (bundler: IBundler) => IBundler - > - // modify config - [BuildLibMethods.ModifyRollupConfig]: IFastHookRegister< - (rollupChain: IRollupChain, ctx: IModifyRollupConfigCtx) => IRollupChain - > - [BuildLibMethods.GetRollupChainConfig]: ( - target: ILibBuildTargets - ) => Promise - // build event - [BuildLibMethods.OnLibBuildFailed]: IFastHookRegister<(e: any) => void> - [BuildLibMethods.OnLibBuildSucceed]: IFastHookRegister< - (stats: ILibBuildStats) => void - > - // fast get - [BuildLibMethods.RunLibBuild]: (ops: Partial) => void -} - -// for bundler imp -export interface ILibBuildStats { - info?: string - watch: boolean -} - -export interface ILibBuildOps { - targets: ILibBuildTargets[] - watch: boolean - pointPkg?: string[] - order?: string[] -} - -// for bundler -export interface IBundlerImp { - build: (ops: ILibBuildOps) => Promise - [key: string]: any -} - -export interface IBundler { - new (api: IPluginAPI): IBundlerImp -} - -// for esm tagret -type ITargets = 'esm' | 'cjs' | 'browser' | 'modern' -export type ILibBuildTargets = ITargets | 'rollTypes' - -export type IModifyRollupConfigCtx = { - [key in ILibBuildTargets]: boolean -} - -export interface ILibBuildConfig { - // lib build target: esm cjs broeser modern - targets: ITargets[] - /** - * point pkg name - * package/core - * pkg: ['core'] - */ - pointPkgs?: string[] - // to custom rollup config - rollupChain?: ( - rollupChain: IRollupChain, - ctx: Omit - ) => IRollupChain - /** - * lib packing is orderly when lerna mode - * like ['shared', 'core'] - * shared should be roll before core - */ - pkgOrder?: string[] - rollTypes?: boolean -} diff --git a/packages/plugin-build-lib/src/plugin/utils.ts b/packages/plugin-build-lib/src/plugin/utils.ts deleted file mode 100644 index ad045ef..0000000 --- a/packages/plugin-build-lib/src/plugin/utils.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { ILibBuildTargets } from './types' - -export const getModifyConfigCtx = (target: ILibBuildTargets) => { - const ctx = { - esm: false, - cjs: false, - browser: false, - modern: false, - rollTypes: false - } - ctx[target] = true - return ctx -} diff --git a/packages/plugin-cmd-lib/src/enum.ts b/packages/plugin-cmd-lib/src/enum.ts deleted file mode 100644 index cdc186f..0000000 --- a/packages/plugin-cmd-lib/src/enum.ts +++ /dev/null @@ -1,17 +0,0 @@ -export enum BuiltInRollupPlugin { - Commonjs = 'commonjs', - NodeResolve = 'nodeResolve', - Typescript = 'typescript', - Babel = 'babel', - Vue = 'vue', - Postcss = 'postcss', - Alias = 'alias', - Replace = 'replace', - Svgr = 'svgr', - Url = 'url', - Json = 'json', - Terser = 'terser', - Dts = 'dts' -} - -export const ExternalMatchBabelReg = new RegExp(/^@babel\/runtime/) diff --git a/packages/plugin-cmd-lib/src/getBabelConfig.ts b/packages/plugin-cmd-lib/src/getBabelConfig.ts deleted file mode 100644 index c040911..0000000 --- a/packages/plugin-cmd-lib/src/getBabelConfig.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { IModifyRollupConfigCtx } from '@xus/cli' - -export default (ctx: IModifyRollupConfigCtx, isVue = false) => { - const preset = isVue - ? require('@xus/babel-preset/lib/vue') - : require('@xus/babel-preset/lib/react') - if (ctx.esm) { - return { - presets: [ - [ - preset, - { - modules: false, - useESModules: true, - absoluteRuntime: false, - vueJSX: isVue - } - ] - ] - } - } else if (ctx.modern) { - return { - presets: [ - [ - preset, - { - modules: false, - usageMode: true, - useESModules: true, - useTransformRuntime: false, - useDynamicImport: true, - vueJSX: isVue - } - ] - ] - } - } else if (ctx.cjs) { - return { - presets: [ - [ - preset, - { - targets: { node: 'current' }, - absoluteRuntime: false, - useDynamicImport: true, - vueJSX: isVue - } - ] - ] - } - } else { - return { - presets: [ - [ - preset, - { - usageMode: true, - useTransformRuntime: false, - useDynamicImport: true, - vueJSX: isVue - } - ] - ] - } - } -} diff --git a/packages/plugin-cmd-lib/src/index.ts b/packages/plugin-cmd-lib/src/index.ts deleted file mode 100644 index 0274f24..0000000 --- a/packages/plugin-cmd-lib/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import cmdLib from './plugin' -export default cmdLib -export * from './enum' diff --git a/packages/plugin-cmd-lib/src/modify.ts b/packages/plugin-cmd-lib/src/modify.ts deleted file mode 100644 index b592733..0000000 --- a/packages/plugin-cmd-lib/src/modify.ts +++ /dev/null @@ -1,324 +0,0 @@ -import type { IRollupChain, IModifyRollupConfigCtx, IPluginAPI } from '@xus/cli' -import type { IPkg } from './types' -import { - getFileMeta, - lookUpFile, - resolve, - semver, - fastGlob, - removeDirOrFile -} from '@xus/cli' -import { readdirSync, statSync } from 'fs' -import { join, extname, dirname } from 'path' -import { BuiltInRollupPlugin, ExternalMatchBabelReg } from './enum' -import getBabelConfig from './getBabelConfig' -// rollup plugin -// @ts-ignore -import url from '@rollup/plugin-url' -// @ts-ignore -import svgr from '@svgr/rollup' -import json from '@rollup/plugin-json' -import alias from '@rollup/plugin-alias' -import replace from '@rollup/plugin-replace' -import commonjs from '@rollup/plugin-commonjs' -import nodeResolve from '@rollup/plugin-node-resolve' -import { terser } from 'rollup-plugin-terser' -import typescript2 from 'rollup-plugin-typescript2' -import babel from '@rollup/plugin-babel' -import vue2 from '@xus/rollup-plugin-vue2' -import vue3 from 'rollup-plugin-vue' -import dts from 'rollup-plugin-dts' -// css -import postcss from 'rollup-plugin-postcss' -import autoprefixer from 'autoprefixer' - -const extensions = ['.js', '.jsx', '.ts', '.tsx', '.vue'] - -let isCheckedTypes = false - -export const defaultInput = ( - rc: IRollupChain, - _: IModifyRollupConfigCtx, - api: IPluginAPI -) => { - api.logger.debug(`default input `) - // auto search entry index.(js|jsx|ts|tsx|vue) src/index.(js|jsx|ts|tsx|vue) - const fileMeta = - getFileMeta({ - base: api.cwd, - filenameWithoutExt: 'index', - type: 'lib' - }) || - getFileMeta({ - base: join(api.cwd, 'src'), - filenameWithoutExt: 'index', - type: 'lib' - }) - - if (fileMeta) { - rc.input(fileMeta.path) - } - - api.logger.debug(rc.get('input')) -} - -export const ensureOutput = ( - rc: IRollupChain, - ctx: IModifyRollupConfigCtx, - api: IPluginAPI -) => { - api.logger.debug(`ensure output `) - const isProd = api.mode === 'production' - let outFile = rc.output.get('file') as string - const globalName = rc.output.get('name') as string - if (!outFile) { - // auto gen output - rc.output.file(api.getPathBasedOnCtx('dist/index.js')) - outFile = rc.output.get('file') as string - } - - if (ctx.esm) { - rc.output.file(outFile.replace(/.js$/, getExt('esm', isProd))).format('es') - } else if (ctx.cjs) { - rc.output - .file(outFile.replace(/.js$/, getExt('cjs', isProd))) - .format('cjs') - .exports('named') - } else if (ctx.browser) { - if (!globalName) - throw new Error(`build for browser should has a global name`) - - rc.output - .file(outFile.replace(/.js$/, getExt('global', isProd))) - .format('umd') - .globals({ - vue: 'Vue', - react: 'React', - 'react-dom': 'ReactDom' - }) - .exports('named') - } else if (ctx.modern) { - rc.output - .file(outFile.replace(/.js$/, getExt('modern', isProd))) - .format('es') - } else if (ctx.rollTypes) { - const outDir = dirname(outFile) - rc.clear() - rc.input(join(outDir, 'index.d.ts')) - rc.plugin(BuiltInRollupPlugin.Dts).use(dts) - rc.output.file(join(outDir, 'index.d.ts')).format('es') - api.onLibBuildSucceed(async () => { - const match = await fastGlob([ - join(outDir, '**/*.d.ts'), - `!${join(outDir, 'index.d.ts')}` - ]) - const dir = readdirSync(outDir) - .map((d) => join(outDir, d)) - .filter((p) => statSync(p).isDirectory()) - await removeDirOrFile([...match, ...dir]) - }) - } - - if (isProd) { - rc.output.sourcemap(true) - } - - api.logger.debug(rc.output.get('file')) -} - -export const ensureCommonPlugin = ( - rc: IRollupChain, - ctx: IModifyRollupConfigCtx, - api: IPluginAPI -) => { - api.logger.debug(`ensure common plugin `) - // node and data source - rc.plugin(BuiltInRollupPlugin.Url).use(url) - rc.plugin(BuiltInRollupPlugin.Svgr).use(svgr).after(BuiltInRollupPlugin.Url) - rc.plugin(BuiltInRollupPlugin.NodeResolve).use(nodeResolve, [ - { - mainFields: ['jsnext:main', 'module', 'main'], - preferBuiltins: true, - extensions - } - ]) - if (ctx.browser || ctx.modern) { - // need rollup a full pkg - rc.plugin(BuiltInRollupPlugin.Commonjs) - .use(commonjs, [{ sourceMap: false }]) - .after(BuiltInRollupPlugin.NodeResolve) - } - - rc.plugin(BuiltInRollupPlugin.Json).use(json) - rc.plugin(BuiltInRollupPlugin.Alias).use(alias, [ - { - entries: [{ find: '@', replacement: join(api.cwd, 'src') }] - } - ]) - rc.plugin(BuiltInRollupPlugin.Replace).use(replace, [ - { - preventAssignment: true - } - ]) -} - -export const ensureCorePlugin = ( - rc: IRollupChain, - ctx: IModifyRollupConfigCtx, - api: IPluginAPI -) => { - api.logger.debug(`ensure core plugin `) - - // auto sniff vue - let vueVersion: null | number = null - try { - const Vue = require(resolve.sync('vue', { - basedir: api.getCliEnv('Lerna_Root') || api.cwd - })) - vueVersion = semver.major(Vue.version) - } catch (e) { - // - } - if (vueVersion === 2) { - rc.plugin(BuiltInRollupPlugin.Vue).use(vue2, [ - { - css: false, - exposeFilename: false - } - ]) - } else if (vueVersion === 3) { - rc.plugin(BuiltInRollupPlugin.Vue).use(vue3, [ - { - target: ctx.cjs ? 'node' : 'browser', - exposeFilename: false - } - ]) - } - api.logger.debug(`vue version ${vueVersion}`) - - // babel - // change cwd to lerna root for preset/vue sniff vue version - const cwd = api.cwd - const lernaRoot = api.getCliEnv('Lerna_Root') || cwd - process.chdir(lernaRoot) - const babelConfig = getBabelConfig(ctx, !!vueVersion) - process.chdir(cwd) - rc.plugin(BuiltInRollupPlugin.Babel).use(babel, [ - { - ...babelConfig, - babelHelpers: ctx.browser || ctx.modern ? 'bundled' : 'runtime', - exclude: /\/node_modules\//, - babelrc: false, - extensions - } - ]) - - // should after ensureInput to auto sniff ts - const entryExt = extname(rc.get('input') as string) - - const isTypescrip = entryExt === '.tsx' || entryExt === '.ts' - - if (isTypescrip) { - // 1. find tsconfig.json - const tsconfigPath = lookUpFile(api.cwd, ['tsconfig.json'], true) - if (!tsconfigPath) - throw new Error( - `current build for typescript, but don't have a tsconfig.json` - ) - - // vue jsxFactory h - const vueTsx = vueVersion ? { jsx: 'preserve', jsxFactory: 'h' } : {} - - rc.plugin(BuiltInRollupPlugin.Typescript) - .use(typescript2, [ - { - cwd: api.cwd, - check: !isCheckedTypes, - clean: true, - cacheRoot: `${api.cwd}/.rpts2_cache`, - tsconfig: tsconfigPath, - tsconfigDefaults: { - compilerOptions: { - ...vueTsx - } - }, - tsconfigOverride: { - compilerOptions: { - target: 'esnext', - module: 'esnext', - // sourceMap: !isCheckedTypes, - declaration: !isCheckedTypes - // declarationMap: !isCheckedTypes - } - } - } - ]) - // tsc --> babel - .before(BuiltInRollupPlugin.Babel) - - isCheckedTypes = true - } - - // terser - if (api.mode === 'production') { - rc.plugin(BuiltInRollupPlugin.Terser).use(terser, [ - { - module: ctx.esm || ctx.modern, - compress: { - ecma: 2015, - pure_getters: true - } - } - ]) - } - - // postcss - rc.plugin(BuiltInRollupPlugin.Postcss).use(postcss, [ - { - extract: true, - inject: false, - modules: false, - autoModules: true, - plugins: [autoprefixer({ remove: false })] - } - ]) -} - -export const ensureOtherConfig = ( - rc: IRollupChain, - ctx: IModifyRollupConfigCtx, - api: IPluginAPI -) => { - api.logger.debug(`ensure other plugin `) - - // get pkgJSON - let pkgJson: IPkg | null = null - try { - pkgJson = require(api.getPathBasedOnCtx('package.json')) - } catch (error) { - // - } - - if (pkgJson && (ctx.esm || ctx.cjs)) { - // auto external dep peerDep - ;[ - ...Object.keys(pkgJson.dependencies || {}), - ...Object.keys(pkgJson.peerDependencies || {}) - ].forEach((pkg) => { - rc.external.set(pkg) - }) - } - - // external - rc.external.set('vue').set('react').set('react-dom') - if (ctx.esm || ctx.cjs) { - rc.external.set(ExternalMatchBabelReg) - } - - api.logger.debug(`external: ${rc.external.values()}`) -} - -// helper -function getExt(mode: string, isProd = false) { - return isProd ? `.${mode}.prod.js` : `.${mode}.js` -} diff --git a/packages/plugin-cmd-lib/src/plugin.ts b/packages/plugin-cmd-lib/src/plugin.ts deleted file mode 100644 index c3a21d2..0000000 --- a/packages/plugin-cmd-lib/src/plugin.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { ILibBuildTargets } from '@xus/cli' -import { createPlugin } from '@xus/cli' -import { - defaultInput, - ensureOutput, - ensureCorePlugin, - ensureCommonPlugin, - ensureOtherConfig -} from './modify' - -const DefaultTargets = ['esm', 'cjs', 'browser', 'modern'] - -export default createPlugin({ - name: 'cmd:lib', - apply(api) { - api.registerCommand( - 'lib', - { - desc: 'bunlde js ts react for lib mode, based on rollup', - usage: 'xus lib', - options: { - '--pkg': 'point pkg dir name', - '--targets': 'point build target esm|cjs|browser|modern', - '--watch': 'watch mode', - '--rollTypes': 'to rollup types files' - } - }, - (args) => { - api.logger.debug(`raw args `) - api.logger.debug(args) - - const config = api.projectConfig.libBuild - // handle of args - let targets = (config?.targets || DefaultTargets) as ILibBuildTargets[] - if (args?.targets) { - targets = (args?.targets as string) - .split(',') - .filter((target) => - DefaultTargets.includes(target) - ) as ILibBuildTargets[] - } - if (args?.rollTypes || config?.rollTypes) { - targets.push('rollTypes') - } - - api.logger.debug(`build targets `) - api.logger.debug(targets) - - api.logger.debug(`modify config `) - // default config should run before user modify - api.modifyRollupConfig({ - fn(rc, ctx) { - defaultInput(rc, ctx, api) - ensureCommonPlugin(rc, ctx, api) - ensureCorePlugin(rc, ctx, api) - // external and so on - ensureOtherConfig(rc, ctx, api) - return rc - }, - stage: -100 - }) - - api.modifyRollupConfig({ - fn(rc, ctx) { - // user modify - if (config?.rollupChain) { - config.rollupChain(rc, ctx) - } - // ensure config should run after user modify - ensureOutput(rc, ctx, api) - return rc - }, - // last to run - stage: 100 - }) - - // run - api.logger.debug(`run lib build `) - const pointPkgs = args?.pkg - ? (args?.pkg as string).split(',') - : undefined - api.runLibBuild({ - targets: targets as ILibBuildTargets[], - pointPkg: config?.pointPkgs || pointPkgs || undefined, - watch: !!args?.watch, - order: config?.pkgOrder - }) - - // on success - api.onLibBuildSucceed((ops) => { - if (!ops?.watch) { - api.logger.success(`lib build succeed!!!`) - } - }) - // on failed - api.onLibBuildFailed((e) => { - api.logger.error(`lib build failed, ${e}`) - }) - } - ) - } -}) diff --git a/packages/plugin-cmd-lib/src/types.ts b/packages/plugin-cmd-lib/src/types.ts deleted file mode 100644 index 76670b7..0000000 --- a/packages/plugin-cmd-lib/src/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type IPkg = { - name: string - dependencies?: Record - devDependencies?: Record - peerDependencies?: Record -} diff --git a/packages/plugin-build-lib/README.md b/packages/plugin-cmd-roll-lib/README.md similarity index 100% rename from packages/plugin-build-lib/README.md rename to packages/plugin-cmd-roll-lib/README.md diff --git a/packages/plugin-cmd-lib/package.json b/packages/plugin-cmd-roll-lib/package.json similarity index 61% rename from packages/plugin-cmd-lib/package.json rename to packages/plugin-cmd-roll-lib/package.json index ca3d702..ba934a5 100644 --- a/packages/plugin-cmd-lib/package.json +++ b/packages/plugin-cmd-roll-lib/package.json @@ -1,6 +1,6 @@ { - "name": "@xus/plugin-cmd-lib", - "version": "0.1.7", + "name": "@xus/plugin-cmd-roll-lib", + "version": "0.1.0", "description": "a bundle for js ts react", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -19,38 +19,38 @@ "url": "git+https://github.com/xus-code/bundle-tools.git" }, "scripts": { - "dev:clib": "tsc --watch", - "build:clib": "tsc" + "dev:rolllib": "tsc --watch", + "build:rolllib": "tsc" }, "bugs": { "url": "https://github.com/xus-code/bundle-tools/issues" }, "dependencies": { "@rollup/plugin-alias": "^3.1.2", - "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^17.1.0", - "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.2.0", "@rollup/plugin-replace": "^2.4.1", - "@rollup/plugin-url": "^6.0.0", - "@svgr/rollup": "^5.5.0", - "@vue/compiler-sfc": "^3.0.6", + "@rollup/pluginutils": "^4.1.0", "@xus/babel-preset": "^0.1.11", - "@xus/cli": "^0.1.6", - "@xus/rollup-plugin-vue2": "^1.0.0", + "@xus/cli-shared": "^0.1.4", + "@xus/cli-types": "^0.1.0", + "@xus/core": "^0.1.5", "autoprefixer": "^10.2.4", + "crypto": "^1.0.1", + "esbuild": "^0.9.2", + "magic-string": "^0.25.7", + "mime": "^2.5.2", "postcss": "^8.2.6", - "rollup-plugin-dts": "^2.0.1", - "rollup-plugin-postcss": "^4.0.0", - "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-typescript2": "^0.30.0", - "rollup-plugin-vue": "^6.0.0-beta.10", - "vue-template-compiler": "^2.6.12" + "rollup": "^2.40.0", + "semver": "^7.3.4", + "terser": "^5.6.0", + "url": "^0.11.0" }, "devDependencies": { + "@types/mime": "^2.0.3", "@types/semver": "^7.3.4" }, "peerDependencies": { "core-js": "^3.9.0" } -} \ No newline at end of file +} diff --git a/packages/plugin-cmd-roll-lib/src/bundler/bundler.ts b/packages/plugin-cmd-roll-lib/src/bundler/bundler.ts new file mode 100644 index 0000000..d907b0c --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/bundler/bundler.ts @@ -0,0 +1,92 @@ +import type { IRollupBuildOps, IRollupBuildFn } from './types' +import { Logger, chalk, emptyDir, prompt } from '@xus/cli-shared' +import fs from 'fs' +import path from 'path' +import { rollup, watch } from 'rollup' +import rollupValidator from './validator' + +const logger = new Logger(`xus:bundler:rollup`) + +export const rollupBundler: IRollupBuildFn = async (ops) => { + logger.debug(`build ops `) + logger.debug(ops) + // logger.info(chalk.yellow(`${ops?.watch ? 'Watch' : 'Rollup'} start \n`)) + const { inputConfig } = ops + // 1. validate config + logger.debug(`validate input config: `) + rollupValidator(inputConfig) + // real build + await doBuild(ops) +} + +async function doBuild(ops: IRollupBuildOps) { + const { + pkgRoot, + isWatch = false, + isWrite = true, + inputConfig, + outputConfigs, + alwaysEmptyDistDir + } = ops + if (isWatch) { + logger.debug(`do watch: `) + const watcher = watch([ + { + ...ops.inputConfig, + ...ops.outputConfigs[0], + watch: inputConfig?.watch ? inputConfig.watch : {} + } + ]) + watcher.on('event', (event: any) => { + if (event.error) { + logger.error(event.error) + } else if (event.code === 'START') { + logger.log(`Rebuild since file changed`) + } + }) + process.once('SIGINT', () => { + watcher.close() + }) + } else { + logger.debug(`do rollup: `) + const bundler = await rollup({ + ...inputConfig, + watch: false + }) + + await ensureDir( + path.join(pkgRoot, outputConfigs[0].dir!), + alwaysEmptyDistDir + ) + logger.debug(`do ${isWrite ? 'write' : 'generate'}`) + for (const output of outputConfigs) { + logger.debug(output) + logger.info( + chalk.green(`[${isWrite ? 'Write' : 'Generate'}] ${output.format}`) + ) + await bundler[isWrite ? 'write' : 'generate'](output) + await bundler.write(output) + } + await bundler.close() + } +} + +async function ensureDir(dir: string, alwaysEmptyDistDir = false) { + if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) { + const files = fs.readdirSync(dir) + if (files.length > 0) { + if (alwaysEmptyDistDir) { + return emptyDir(dir) + } + const { yes } = await prompt<{ yes: boolean }>({ + type: 'confirm', + name: 'yes', + initial: 'Y', + message: + `dist directory ${dir} is not empty.\n` + + `Remove existing files and continue?` + }) + yes && emptyDir(dir) + } + } +} diff --git a/packages/plugin-cmd-roll-lib/src/bundler/index.ts b/packages/plugin-cmd-roll-lib/src/bundler/index.ts new file mode 100644 index 0000000..8727ebe --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/bundler/index.ts @@ -0,0 +1,2 @@ +export { rollupBundler } from './bundler' +export * from './types' diff --git a/packages/plugin-cmd-roll-lib/src/bundler/types.ts b/packages/plugin-cmd-roll-lib/src/bundler/types.ts new file mode 100644 index 0000000..31c00e2 --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/bundler/types.ts @@ -0,0 +1,12 @@ +import type { RollupOptions, OutputOptions } from 'rollup' + +export interface IRollupBuildOps { + inputConfig: Omit + outputConfigs: OutputOptions[] + isWatch: boolean + isWrite: boolean + pkgRoot: string + alwaysEmptyDistDir: boolean +} + +export type IRollupBuildFn = (ops: IRollupBuildOps) => Promise diff --git a/packages/plugin-build-lib/src/bundler/validator/index.ts b/packages/plugin-cmd-roll-lib/src/bundler/validator/index.ts similarity index 100% rename from packages/plugin-build-lib/src/bundler/validator/index.ts rename to packages/plugin-cmd-roll-lib/src/bundler/validator/index.ts diff --git a/packages/plugin-build-lib/src/bundler/validator/validPlugins.ts b/packages/plugin-cmd-roll-lib/src/bundler/validator/validPlugins.ts similarity index 100% rename from packages/plugin-build-lib/src/bundler/validator/validPlugins.ts rename to packages/plugin-cmd-roll-lib/src/bundler/validator/validPlugins.ts diff --git a/packages/plugin-build-lib/src/bundler/validator/validRequired.ts b/packages/plugin-cmd-roll-lib/src/bundler/validator/validRequired.ts similarity index 77% rename from packages/plugin-build-lib/src/bundler/validator/validRequired.ts rename to packages/plugin-cmd-roll-lib/src/bundler/validator/validRequired.ts index cbc3032..59c24e7 100644 --- a/packages/plugin-build-lib/src/bundler/validator/validRequired.ts +++ b/packages/plugin-cmd-roll-lib/src/bundler/validator/validRequired.ts @@ -4,9 +4,6 @@ export default (config: RollupOptions) => { if (!config?.input) { throw new Error(`config has no input options`) } - if (!config?.output) { - throw new Error(`config has no output options`) - } if (!config?.plugins || config.plugins.length < 1) { throw new Error(`config has no plugins`) } diff --git a/packages/plugin-cmd-roll-lib/src/config/index.ts b/packages/plugin-cmd-roll-lib/src/config/index.ts new file mode 100644 index 0000000..10c284e --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/config/index.ts @@ -0,0 +1,35 @@ +import { createSchema } from '@xus/cli-shared' +import { IRollLibConfig } from '../types' + +export const libBuildSchema = createSchema((joi) => + joi.object({ + libName: joi.string(), + minify: [joi.string(), joi.boolean()], + target: [joi.string(), joi.array().items(joi.string())], + formats: joi.array().items(joi.string()), + rollTypes: joi.boolean(), + sourcemap: joi.boolean(), + alwaysEmptyDistDir: joi.boolean(), + + // lerna mode + pkgsOrder: joi.array().items(joi.string()), + pointPkgs: joi.array().items(joi.string()), + + rollupChain: joi.function() + }) +) + +export const defaultLibBuildConfig: () => IRollLibConfig = () => { + return { + libName: 'index', + minify: 'terser', + target: 'esnext', + formats: [], + rollTypes: true, + sourcemap: false, + alwaysEmptyDistDir: false, + + // lerna mode + pkgsOrder: [] + } +} diff --git a/packages/plugin-cmd-roll-lib/src/index.ts b/packages/plugin-cmd-roll-lib/src/index.ts new file mode 100644 index 0000000..6d7fe8d --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/index.ts @@ -0,0 +1,69 @@ +import { createPlugin } from '@xus/cli-types' +import { chalk } from '@xus/cli-shared' +import { basename } from 'path' +import { rollupBundler } from './bundler' +import { resolveConfig, generateBuildOps } from './resolveConfig' +import { modifyConfig } from './modify' +// config +import { libBuildSchema, defaultLibBuildConfig } from './config' + +export default createPlugin({ + name: 'cmd:lib:build', + apply(api) { + api.registerCommand( + 'lib-build', + { + desc: 'bunlde js ts react for lib mode, based on rollup/esbuild', + usage: 'xus roll-lib', + options: { + '--entry': 'point entry file', + '--outDir': 'point out file dir', + '--pkgs': 'point pkg dir name', + '--watch': 'watch mode', + '--rollTypes': 'to rollup types files', + '--sourcemap': 'to generate sourcemap' + } + }, + async (args) => { + api.logger.debug(`raw args `) + api.logger.debug(args) + + const config = api.projectConfig.libBuild + // handle of args and config + // resolveConfig + api.logger.debug(`resolve config `) + const resolvedConfig = resolveConfig(args, config, api) + // default config should run before user modify + api.logger.debug(`modify rollup config `) + api.modifyRollupConfig({ + fn(rc) { + modifyConfig(rc, resolvedConfig, api) + if (resolvedConfig?.rollupChain) { + resolvedConfig.rollupChain(rc) + } + return rc + }, + stage: -100 + }) + + api.logger.debug(`run lib build `) + for (const pkg of resolvedConfig.pkgs) { + const saveCwd = api.cwd + process.chdir(pkg) + // get all pkgs need to build + api.logger.debug(`generate buildOps `) + const buildOps = await generateBuildOps(pkg, resolvedConfig, api) + // to rollup + api.logger.info(chalk.yellow(`running for ${basename(pkg)}`)) + await rollupBundler(buildOps) + process.chdir(saveCwd) + } + } + ) + }, + config: { + key: 'libBuild', + schema: libBuildSchema, + default: defaultLibBuildConfig + } +}) diff --git a/packages/plugin-cmd-roll-lib/src/modify.ts b/packages/plugin-cmd-roll-lib/src/modify.ts new file mode 100644 index 0000000..eedde3c --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/modify.ts @@ -0,0 +1,88 @@ +import { IPluginAPI, IRollupChain } from '@xus/cli-types' +import { WarningHandler, RollupWarning } from 'rollup' +import { join } from 'path' +import { IResolvedConfig } from './types' +// plugin +import { esbuildPlugin } from './plugins/esbuild' +import { minifyPlugin } from './plugins/minify' +import { assetPlugin } from './plugins/asset' +import nodeResolve from '@rollup/plugin-node-resolve' +import commonjs from '@rollup/plugin-commonjs' +import alias from '@rollup/plugin-alias' +import replace from '@rollup/plugin-replace' + +const extensions = ['.js', '.jsx', '.ts', '.tsx'] + +export function modifyConfig( + rc: IRollupChain, + resolvedConfig: IResolvedConfig, + api: IPluginAPI +) { + // node resolve commonjs + rc.plugin('nodeResolve').use(nodeResolve, [ + { + mainFields: ['jsnext:main', 'module', 'main'], + preferBuiltins: true, + extensions + } + ]) + rc.plugin('commonjs').use(commonjs).after('commonjs') + + const sourcemap = !!resolvedConfig.sourcemap + const target = resolvedConfig.target + // esbuild + rc.plugin('$$esbuild').use(esbuildPlugin, [ + { + target, + sourcemap + } + ]) + // minify + rc.plugin('$$minify').use(minifyPlugin, [ + { + minify: resolvedConfig.minify, + esbuildMinifyOps: { + target, + sourcemap + }, + terserMinifyOps: { + sourceMap: sourcemap + } + } + ]) + + // css + + // asset + rc.plugin('asset').use(assetPlugin, [ + { + assetDir: 'assets', + assetRoot: join(api.cwd, 'assets'), + inlineLimit: 0 + } + ]) + + rc.plugin('alias').use(alias, [ + { + entries: [{ find: '@', replacement: join(api.cwd, 'src') }] + } + ]) + rc.plugin('replace').use(replace, [ + { + preventAssignment: true + } + ]) + + // external + + // onwran + rc.onwarn((wraning, onwran) => { + onRollupWraning(wraning, onwran) + }) +} + +const RollupWraningIgnoreList = ['THIS_IS_UNDEFINED'] +function onRollupWraning(wraning: RollupWarning, onwran: WarningHandler) { + if (RollupWraningIgnoreList.includes(wraning.code!)) return + onwran(wraning) +} diff --git a/packages/plugin-cmd-roll-lib/src/plugins/asset.ts b/packages/plugin-cmd-roll-lib/src/plugins/asset.ts new file mode 100644 index 0000000..9144b6c --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/plugins/asset.ts @@ -0,0 +1,189 @@ +import { Logger } from '@xus/cli-shared' +import path from 'path' +import fs from 'fs' +import mime from 'mime/lite' +import { parse as parseUrl } from 'url' +import MagicString from 'magic-string' +import { createHash } from 'crypto' +import { cleanUrl } from '../utils' +import { Plugin, PluginContext } from 'rollup' + +interface IAssestOps { + assetRoot?: string + assetDir?: string + inlineLimit?: number +} + +const logger = new Logger(`xus:rollup:asset`) + +const XUS_ASSET_PREFIX = `@assets` +// __XUS_ASSET_PROXY__{contentHash}__($_{postfix}_) +const AssetUrlQuotedRE = /"__XUS_ASSET_PROXY__([a-z\d]{8})__(?:\$_(.*?)__)?"/g + +function toXusAssestUrl(contentHash: string, postfix?: string) { + return `__XUS_ASSET_PROXY__${contentHash}__${postfix ? `$_${postfix}__` : ``}` +} + +const KNOWN_ASSET_TYPES = [ + // images + 'png', + 'jpe?g', + 'gif', + 'svg', + 'ico', + 'webp', + 'avif', + + // media + 'mp4', + 'webm', + 'ogg', + 'mp3', + 'wav', + 'flac', + 'aac', + + // fonts + 'woff2?', + 'eot', + 'ttf', + 'otf' +] + +const KnownAssetRE = new RegExp( + `\\.(` + KNOWN_ASSET_TYPES.join('|') + `)(\\?.*)?$` +) + +// ?raw special query mark asset keep raw and inline load +const rawRE = /(\?|&)raw(?:&|$)/ +// ?url special query mark asset url load +const urlRE = /(\?|&)url(?:&|$)/ + +const AssestCache = new Map() +const HashToFilenameCache = new Map() + +export function assetPlugin(ops?: IAssestOps): Plugin { + const { assetRoot = 'assets' } = ops! + return { + name: 'xus:asset', + resolveId(id) { + // before node resolve?? + const cleanId = cleanUrl(id) + if (KnownAssetRE.test(cleanId) && isExists(cleanId, assetRoot)) { + return id + } + return null + }, + load(id) { + if (rawRE.test(id)) { + logger.debug(`load raw assets: `, id) + const url = getAbsoluteUrl(id, assetRoot) + return `export default ${JSON.stringify( + fs.readFileSync(cleanUrl(url), 'utf-8') + )}` + } + if (KnownAssetRE.test(cleanUrl(id)) || urlRE.test(id)) { + const idWithoutUrl = getAbsoluteUrl(id, assetRoot) + .replace(urlRE, '$1') + .replace(/[\\?&]$/, '') + logger.debug(`load known asset: `, id) + const url = loadFile(idWithoutUrl, ops!, this) + return `export default ${JSON.stringify(url)}` + } + return null + }, + renderChunk(code, chunk) { + let match + let s + logger.debug(`render chunk source code: `) + logger.debug(code) + while ((match = AssetUrlQuotedRE.exec(code))) { + s = s || new MagicString(code) + const [full, hash, postfix = ''] = match + // out file url + const dirname = path.relative( + path.dirname(path.join('./', chunk.fileName)), + './' + ) + const filename = path.join( + dirname, + HashToFilenameCache.get(hash) + postfix + ) + s.overwrite( + match.index, + match.index + full.length, + JSON.stringify(filename.startsWith('.') ? filename : './' + filename) + ) + } + if (s) { + logger.debug(`after render asset to chunk: `) + logger.debug(s.toString()) + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + } + } + return null + } + } +} + +function loadFile(id: string, ops: IAssestOps, ctx: PluginContext) { + const cached = AssestCache.get(id) + if (cached) return cached + + const cleanId = cleanUrl(id) + const { search, hash } = parseUrl(id) + const postfix = (search || '') + (hash || '') + const content = fs.readFileSync(cleanId) + + const { inlineLimit, assetDir = 'assets' } = ops + let url = '' + if (content.length < Number(inlineLimit)) { + // inline base64 + logger.debug(`${id} load to base64`) + url = `data:${mime.getType(cleanId)};base64,${content.toString('base64')}` + logger.debug(`asset to base64 ${url.slice(0, 100)}...`) + } else { + // use url + logger.debug(`${id} load to url`) + const contentHash = createAssestHash(content) + if (!HashToFilenameCache.has(contentHash)) { + // emit file + const basename = path.basename(cleanId) + const ext = path.extname(basename) + const fileName = path.posix.join( + assetDir, + `${basename.slice(0, -ext.length)}.${contentHash}${ext}` + ) + logger.debug(`render file ${id} --> ${fileName}`) + HashToFilenameCache.set(contentHash, fileName) + ctx.emitFile({ + fileName, + type: 'asset', + source: content + }) + } + url = toXusAssestUrl(contentHash, postfix) + logger.debug(`asset to url proxy: `, url) + } + AssestCache.set(id, url) + return url +} + +function createAssestHash(content: Buffer) { + return createHash('sha256').update(content).digest('hex').slice(0, 8) +} + +function isExists(id: string, assetRoot: string) { + const url = getAbsoluteUrl(id, assetRoot) + return fs.existsSync(cleanUrl(url)) +} + +function getAbsoluteUrl(id: string, assetRoot: string) { + let url = id + if (id.startsWith(XUS_ASSET_PREFIX)) { + url = id.replace(XUS_ASSET_PREFIX, assetRoot) + } + return url +} diff --git a/packages/plugin-cmd-roll-lib/src/plugins/css.ts b/packages/plugin-cmd-roll-lib/src/plugins/css.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/plugin-cmd-roll-lib/src/plugins/esbuild.ts b/packages/plugin-cmd-roll-lib/src/plugins/esbuild.ts new file mode 100644 index 0000000..9b05d6b --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/plugins/esbuild.ts @@ -0,0 +1,102 @@ +import { Logger } from '@xus/cli-shared' +import { Plugin } from 'rollup' +import { createFilter } from '@rollup/pluginutils' +import * as esbuild from 'esbuild' +import { TransformOptions, Loader } from 'esbuild' +import { extname } from 'path' +import { cleanUrl } from '../utils' + +const logger = new Logger('xus:rollup:esbuild') + +interface IEsbuildOps extends TransformOptions { + include?: RegExp + exclude?: RegExp + jsxInject?: string +} + +export function esbuildPlugin(ops: IEsbuildOps = {}): Plugin { + const filter = createFilter( + ops?.include || /\.(jsx?|tsx?)$/, + ops?.exclude || undefined + ) + delete ops?.include + delete ops?.exclude + + return { + name: 'xus:esbuild:transform', + // tsx/ts/jsx -> js + async transform(code, importer) { + if (filter(importer)) { + const jsxInject = ops?.jsxInject + delete ops?.jsxInject + logger.debug(`esbuild transform (${importer})`) + logger.debug(`source code: `) + logger.debug(code) + const res = await transformByEsbuild(code, importer, ops) + if (jsxInject && /\.(?:j|t)sx\b/.test(importer)) { + res.code = jsxInject + ';' + res.code + } + return { + code: res.code, + map: res.map + } + } + return null + } + } +} + +export async function transformByEsbuild( + source: string, + filename: string, + ops: TransformOptions +) { + // get loader + let ext = extname( + /\.\w+$/.test(filename) ? filename : cleanUrl(filename) + ).slice(1) + if (ext === 'cjs' || ext === 'mjs') { + ext = 'js' + } + const loader = ext as Loader + // transform + const transformOps = { + ...ops, + sourcefile: filename, + loader, + sourcemap: true + } + try { + logger.debug(`transform with options: `) + logger.debug(transformOps) + const { code, map, warnings } = await esbuild.transform( + source, + transformOps + ) + logger.debug(`transform code: `) + logger.debug(code) + logger.debug(`transform sourcemap: `) + logger.debug(map) + // log wran + logger.debug(`transform wrannings: `) + logger.debug(warnings) + let wranMsg = '' + warnings.forEach((w) => { + wranMsg += w.text + '\n' + }) + wranMsg && logger.wran('transform ' + filename + ' wranning:' + wranMsg) + return { + code, + map: map ? JSON.parse(map) : {} + } + } catch (e) { + logger.debug(`esbuild error: `) + logger.debug(e) + let errorMsg = '' + e.errors.forEach((e: any) => { + errorMsg += e.text + '\n' + }) + logger.error(errorMsg) + throw e + } +} diff --git a/packages/plugin-cmd-roll-lib/src/plugins/minify.ts b/packages/plugin-cmd-roll-lib/src/plugins/minify.ts new file mode 100644 index 0000000..0e1d69d --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/plugins/minify.ts @@ -0,0 +1,42 @@ +import { Plugin } from 'rollup' +import { TransformOptions } from 'esbuild' +import { transformByEsbuild } from './esbuild' +import terser, { MinifyOptions } from 'terser' + +export interface IMinifyOps { + minify?: false | 'esbuild' | 'terser' + esbuildMinifyOps?: TransformOptions + terserMinifyOps?: MinifyOptions +} + +export function minifyPlugin(ops: IMinifyOps = {}): Plugin { + return { + name: 'xus:minify', + async renderChunk(source, chunk, outputOps) { + switch (ops.minify) { + case false: + return null + + case 'esbuild': + return await transformByEsbuild(source, chunk.fileName, { + ...ops.esbuildMinifyOps, + minify: true + }) + + case 'terser': + // eslint-disable-next-line no-case-declarations + const res = await terser.minify(source, { + ...ops.terserMinifyOps, + module: outputOps.format.startsWith('es'), + toplevel: outputOps.format === 'cjs', + safari10: true + }) + return { + code: res.code as string, + map: res.map + } + } + return null + } + } +} diff --git a/packages/plugin-cmd-roll-lib/src/resolveConfig/index.ts b/packages/plugin-cmd-roll-lib/src/resolveConfig/index.ts new file mode 100644 index 0000000..4067124 --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/resolveConfig/index.ts @@ -0,0 +1,139 @@ +import { IArgs, IPluginAPI } from '@xus/cli-types' +import { IRollupBuildOps } from '../bundler' +import { IRollLibConfig, IResolvedConfig } from '../types' +import { isLernaPkg, orderBy, getFileMeta } from '@xus/cli-shared' +import { relative, join, isAbsolute } from 'path' + +export function resolveConfig( + args: IArgs, + config: IRollLibConfig, + api: IPluginAPI +) { + // ensure entry + let entry = args?.entry + if (!entry) { + const fileMeta = + getFileMeta({ + base: api.cwd, + filenameWithoutExt: 'index', + type: 'lib' + }) || + getFileMeta({ + base: api.getPathBasedOnCtx('src'), + filenameWithoutExt: 'index', + type: 'lib' + }) + entry = fileMeta?.path + if (!entry) { + throw new Error(`[resolve config] roll-lib should have a entry`) + } + } + api.logger.debug(`[resolve config] entry: `) + api.logger.debug(entry) + + // ensure output + const outDir = args?.outDir || 'dist' + api.logger.debug(`[resolve config] output: `) + api.logger.debug(outDir) + + // order pkg + let pkgs: string[] = args?.pkgs ? args.pkgs.split(',') : null + if (isLernaPkg(api.cwd)) { + const lernaRoot = api.getPathBasedOnCtx('packages') + const pkgsOrder = config.pkgsOrder + if (!pkgs) { + pkgs = api.getLernaPkgs().map((p) => relative(lernaRoot, p)) + } + pkgs = orderBy(pkgs, pkgsOrder).map((p) => join(lernaRoot, p)) + } else { + pkgs = [api.cwd] + } + api.logger.debug(`[resolve config] pkgs: `) + api.logger.debug(pkgs) + + const resolvedConfig: IResolvedConfig = { + ...config, + rollTypes: !!args?.rollTypes || config.rollTypes, + sourcemap: !!args?.sourcemap || config.sourcemap, + pkgs, + entry, + outDir, + isWatch: !!args?.watch + } + + // do some ensure work + // TODO: support bundled runtime target or do a legacy plugin ?? + if ( + resolvedConfig.target === 'esnext' || + resolvedConfig.target?.includes('esnext') + ) { + resolvedConfig.target = 'es2019' + } + + if (resolvedConfig.formats.length < 1) { + resolvedConfig.formats = ['esm', 'cjs'] + } + api.logger.debug(`[resolve config] config`) + api.logger.debug(resolvedConfig) + return resolvedConfig +} + +export async function generateBuildOps( + pkgRoot: string, + resolvedConfig: IResolvedConfig, + api: IPluginAPI +): Promise { + const rollupConfig = await api.getRollupConfig() + const isProd = api.mode === 'production' + const { libName, outDir, formats, alwaysEmptyDistDir } = resolvedConfig + if (rollupConfig) { + api.logger.debug(`[generate buildOps] in ${pkgRoot}`) + const { output, ...inputOps } = rollupConfig + + // input to absolute + const entry = (inputOps.input = inputOps.input || resolvedConfig.entry) + const isSingleEntry = typeof entry === 'string' + if (typeof entry === 'string') { + !isAbsolute(entry) && (inputOps.input = join(pkgRoot, entry)) + } else { + Object.keys(entry).forEach((key) => { + !isAbsolute(entry[key]) && (entry[key] = join(pkgRoot, entry[key])) + }) + } + api.logger.debug(`[generate buildOps] final inputConfig: `) + api.logger.debug(inputOps) + + // output generate + const outputOps = formats.map((format) => { + const outputConfig = { + name: libName, + dir: outDir, + format, + exports: format === 'cjs' ? 'named' : 'auto', + namespaceToStringTag: true, + entryFileNames: isProd + ? `${isSingleEntry ? libName : '[name]'}.${format}.prod.js` + : `${isSingleEntry ? libName : '[name]'}.${format}.js`, + chunkFileNames: `[name].js`, + sourcemap: !!resolvedConfig?.sourcemap, + ...output + } + delete outputConfig.file + + return outputConfig + }) + api.logger.debug(`[generate buildOps] final outputConfig: `) + api.logger.debug(outputOps) + + return { + inputConfig: inputOps, + outputConfigs: outputOps, + isWatch: resolvedConfig.isWatch, + isWrite: true, + pkgRoot, + alwaysEmptyDistDir + } as IRollupBuildOps + } else { + throw new Error(`roll-lib need a rollup config`) + } +} diff --git a/packages/plugin-cmd-roll-lib/src/types.ts b/packages/plugin-cmd-roll-lib/src/types.ts new file mode 100644 index 0000000..334e00f --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/types.ts @@ -0,0 +1,29 @@ +import { IRollupChain } from '@xus/cli-types' +import { TransformOptions } from 'esbuild' + +export interface IRollLibConfig { + libName: string + // transform: 'esbuild' | 'babel' + minify: false | 'esbuild' | 'terser' + target: 'esnext' | TransformOptions['target'] + formats: ('esm' | 'cjs' | 'iife' | 'umd')[] + rollTypes: boolean + sourcemap: boolean + alwaysEmptyDistDir: boolean + + // lerna mode + pkgsOrder: string[] + + // insider + rollupChain?: (rc: IRollupChain) => IRollupChain +} + +export interface IResolvedConfig extends Omit { + entry: string + outDir: string + // ready to roll pkg root + pkgs: string[] + // TODOļ¼šassets / css + isWatch: boolean + // disabled esbuild handle +} diff --git a/packages/plugin-cmd-roll-lib/src/utils.ts b/packages/plugin-cmd-roll-lib/src/utils.ts new file mode 100644 index 0000000..eabaf65 --- /dev/null +++ b/packages/plugin-cmd-roll-lib/src/utils.ts @@ -0,0 +1,5 @@ +export const queryRE = /\?.*$/ +export const hashRE = /#.*$/ + +export const cleanUrl = (url: string) => + url.replace(hashRE, '').replace(queryRE, '') diff --git a/packages/plugin-cmd-lib/tsconfig.json b/packages/plugin-cmd-roll-lib/tsconfig.json similarity index 100% rename from packages/plugin-cmd-lib/tsconfig.json rename to packages/plugin-cmd-roll-lib/tsconfig.json diff --git a/packages/preset-built-in/package.json b/packages/preset-built-in/package.json index 2f97695..b475a71 100644 --- a/packages/preset-built-in/package.json +++ b/packages/preset-built-in/package.json @@ -26,13 +26,17 @@ "url": "https://github.com/xus-code/bundle-tools/issues" }, "dependencies": { - "@xus/cli": "^0.1.6", - "@xus/plugin-build-lib": "^0.1.6", - "@xus/plugin-cmd-lib": "^0.1.7", + "@xus/cli-types": "^0.1.0", + "@xus/cli-shared": "^0.1.4", + "@xus/core": "^0.1.5", + "@xus/plugin-cmd-roll-lib": "^0.1.0", + "@xus/rollup-chain": "^0.2.6", "conventional-changelog": "^3.1.24", - "release-it": "^14.4.1" + "release-it": "^14.4.1", + "rollup": "^2.41.1", + "webpack-chain": "^6.5.1" }, "devDependencies": { "@types/conventional-changelog": "^3.1.0" } -} \ No newline at end of file +} diff --git a/packages/preset-built-in/src/index.ts b/packages/preset-built-in/src/index.ts index 52a396f..4851cac 100644 --- a/packages/preset-built-in/src/index.ts +++ b/packages/preset-built-in/src/index.ts @@ -2,10 +2,6 @@ import presetBuiltIn from './preset' export default presetBuiltIn // types -export type { ILintConfig } from './plugin/config/lint' export type { IChangelogConfig } from './plugin/config/changelog' +export type { ILintConfig } from './plugin/config/lint' export type { IReleaseConfig } from './plugin/config/release' - -// export -export * from '@xus/plugin-build-lib' -export * from '@xus/plugin-cmd-lib' diff --git a/packages/preset-built-in/src/plugin/bundler/enum.ts b/packages/preset-built-in/src/plugin/bundler/enum.ts new file mode 100644 index 0000000..b4e7fa6 --- /dev/null +++ b/packages/preset-built-in/src/plugin/bundler/enum.ts @@ -0,0 +1,8 @@ +export enum BundlerMethods { + // rollup + modifyRollupConfig = 'modifyRollupConfig', + getRollupConfig = 'getRollupConfig', + // webpack + modifyWebpackConfig = 'modifyWebpackConfig', + getWebpackConfig = 'getWebpackConfig' +} diff --git a/packages/preset-built-in/src/plugin/bundler/index.ts b/packages/preset-built-in/src/plugin/bundler/index.ts new file mode 100644 index 0000000..06329e9 --- /dev/null +++ b/packages/preset-built-in/src/plugin/bundler/index.ts @@ -0,0 +1,49 @@ +import { createPlugin } from '@xus/cli-types' +import { HookTypes } from '@xus/core' +import { BundlerMethods } from './enum' +// chain +import rollupChain from '@xus/rollup-chain' +import webpackChain from 'webpack-chain' + +const PluginName = 'xus:bundler:rollup' +export default createPlugin({ + name: PluginName, + apply(api) { + // rollup config + api.registerMethod({ + methodName: BundlerMethods.modifyRollupConfig, + throwOnExist: false + }) + api.registerMethod({ + methodName: BundlerMethods.getRollupConfig, + throwOnExist: false, + fn: async () => { + const rc = new rollupChain() + await api.applyHook({ + name: BundlerMethods.modifyRollupConfig, + type: HookTypes.serial, + initialValue: rc + }) + return rc.toConfig() + } + }) + // webpack config + api.registerMethod({ + methodName: BundlerMethods.modifyWebpackConfig, + throwOnExist: false + }) + api.registerMethod({ + methodName: BundlerMethods.getWebpackConfig, + throwOnExist: false, + fn: async () => { + const wr = new webpackChain() + await api.applyHook({ + name: BundlerMethods.modifyWebpackConfig, + type: HookTypes.serial, + initialValue: wr + }) + return wr.toConfig() + } + }) + } +}) diff --git a/packages/preset-built-in/src/plugin/command/changelog.ts b/packages/preset-built-in/src/plugin/command/changelog.ts index dd2cbd0..7c49836 100644 --- a/packages/preset-built-in/src/plugin/command/changelog.ts +++ b/packages/preset-built-in/src/plugin/command/changelog.ts @@ -1,5 +1,5 @@ -import type { IPluginAPI } from '@xus/cli' -import { createPlugin, Spinner } from '@xus/cli' +import { createPlugin, IPluginAPI } from '@xus/cli-types' +import { Spinner } from '@xus/cli-shared' import conventionalChangelog from 'conventional-changelog' import { changelogSchema, defaultChangelogConfig } from '../config/changelog' import { createWriteStream, readFileSync } from 'fs' diff --git a/packages/preset-built-in/src/plugin/command/clean.ts b/packages/preset-built-in/src/plugin/command/clean.ts index 9f53047..2e995be 100644 --- a/packages/preset-built-in/src/plugin/command/clean.ts +++ b/packages/preset-built-in/src/plugin/command/clean.ts @@ -1,4 +1,5 @@ -import { createPlugin, removeDirOrFile, emptyDir } from '@xus/cli' +import { createPlugin } from '@xus/cli-types' +import { removeDirOrFile, emptyDir } from '@xus/cli-shared' import { existsSync } from 'fs' import { join, relative } from 'path' diff --git a/packages/preset-built-in/src/plugin/command/commitlint.ts b/packages/preset-built-in/src/plugin/command/commitlint.ts index 5b5d601..1a5c55c 100644 --- a/packages/preset-built-in/src/plugin/command/commitlint.ts +++ b/packages/preset-built-in/src/plugin/command/commitlint.ts @@ -1,4 +1,5 @@ -import { createPlugin, chalk } from '@xus/cli' +import { createPlugin } from '@xus/cli-types' +import { chalk } from '@xus/cli-shared' import { readFileSync } from 'fs' // const diff --git a/packages/preset-built-in/src/plugin/command/copy.ts b/packages/preset-built-in/src/plugin/command/copy.ts index ab572f4..9478a5b 100644 --- a/packages/preset-built-in/src/plugin/command/copy.ts +++ b/packages/preset-built-in/src/plugin/command/copy.ts @@ -1,4 +1,5 @@ -import { createPlugin, copy, Spinner } from '@xus/cli' +import { createPlugin } from '@xus/cli-types' +import { copy, Spinner } from '@xus/cli-shared' import { existsSync } from 'fs' import { join } from 'path' diff --git a/packages/preset-built-in/src/plugin/command/help.ts b/packages/preset-built-in/src/plugin/command/help.ts index 962e6ae..3a75497 100644 --- a/packages/preset-built-in/src/plugin/command/help.ts +++ b/packages/preset-built-in/src/plugin/command/help.ts @@ -1,11 +1,6 @@ -import { - // types - ICommand, - IArgs, - // usage - chalk, - createPlugin -} from '@xus/cli' +import { ICommand, IArgs } from '@xus/core' +import { chalk } from '@xus/cli-shared' +import { createPlugin } from '@xus/cli-types' export default createPlugin({ name: 'commandHelp', diff --git a/packages/preset-built-in/src/plugin/command/lint.ts b/packages/preset-built-in/src/plugin/command/lint.ts index f803bd3..b462b3c 100644 --- a/packages/preset-built-in/src/plugin/command/lint.ts +++ b/packages/preset-built-in/src/plugin/command/lint.ts @@ -1,4 +1,5 @@ -import { createPlugin, runCmd } from '@xus/cli' +import { createPlugin } from '@xus/cli-types' +import { runCmd } from '@xus/cli-shared' import { lintSchema, defaultLitConfig } from '../config/lint' export default createPlugin({ @@ -17,16 +18,15 @@ export default createPlugin({ if (lintConfig.eslint) { const eslint = lintConfig.eslint if (typeof eslint != 'boolean') { + const cext = eslint?.ext || [] const ext = - eslint.ext.length > 0 - ? eslint.ext - : ['.js', '.jsx', '.ts', '.tsx', '.vue'] + cext.length > 0 ? cext : ['.js', '.jsx', '.ts', '.tsx', '.vue'] const args = [ - eslint.include, + eslint?.include, '--fix', '--ext', ext.join(',') - ].filter(Boolean) + ].filter(Boolean) as string[] api.logger.debug(`run eslint with `) api.logger.debug(args) eslintRes = await runCmd('eslint', args, { @@ -40,9 +40,10 @@ export default createPlugin({ if (lintConfig.stylelint) { const stylelint = lintConfig.stylelint if (typeof stylelint != 'boolean') { + const ci = stylelint?.include || [] const include = - stylelint.include.length > 0 - ? stylelint.include + ci.length > 0 + ? ci : ['./**/*.css', './**/*.vue', './**/*.less', './**/*.sass'] const args = include.concat(['--fix']) api.logger.debug(`run stylelint with `) diff --git a/packages/preset-built-in/src/plugin/command/release.ts b/packages/preset-built-in/src/plugin/command/release.ts index 750978a..5006aa8 100644 --- a/packages/preset-built-in/src/plugin/command/release.ts +++ b/packages/preset-built-in/src/plugin/command/release.ts @@ -1,13 +1,12 @@ -import type { IPluginAPI } from '@xus/cli' +import { createPlugin, IPluginAPI } from '@xus/cli-types' import { - createPlugin, isLernaPkg, semver, prompt, orderBy, runCmd, chalk -} from '@xus/cli' +} from '@xus/cli-shared' import { join, relative } from 'path' import { existsSync, readFileSync, writeFileSync } from 'fs' import { diff --git a/packages/preset-built-in/src/plugin/config/changelog.ts b/packages/preset-built-in/src/plugin/config/changelog.ts index 6044b77..f040f70 100644 --- a/packages/preset-built-in/src/plugin/config/changelog.ts +++ b/packages/preset-built-in/src/plugin/config/changelog.ts @@ -1,4 +1,4 @@ -import { createSchema } from '@xus/cli' +import { createSchema } from '@xus/cli-shared' import { join } from 'path' export type IChangelogConfig = { diff --git a/packages/preset-built-in/src/plugin/config/lint.ts b/packages/preset-built-in/src/plugin/config/lint.ts index 04797f8..1c43430 100644 --- a/packages/preset-built-in/src/plugin/config/lint.ts +++ b/packages/preset-built-in/src/plugin/config/lint.ts @@ -1,4 +1,4 @@ -import { createSchema } from '@xus/cli' +import { createSchema } from '@xus/cli-shared' export type ILintConfig = { eslint: diff --git a/packages/preset-built-in/src/plugin/config/release.ts b/packages/preset-built-in/src/plugin/config/release.ts index 00ceb78..aab213e 100644 --- a/packages/preset-built-in/src/plugin/config/release.ts +++ b/packages/preset-built-in/src/plugin/config/release.ts @@ -1,5 +1,5 @@ -import type { IRunCmdMessage } from '@xus/cli' -import { createSchema } from '@xus/cli' +import type { IRunCmdMessage } from '@xus/cli-shared' +import { createSchema } from '@xus/cli-shared' type ICmd = { bin: string diff --git a/packages/preset-built-in/src/preset.ts b/packages/preset-built-in/src/preset.ts index c3c0545..7a67ad9 100644 --- a/packages/preset-built-in/src/preset.ts +++ b/packages/preset-built-in/src/preset.ts @@ -1,7 +1,4 @@ -import { createPreset } from '@xus/cli' -// lib build process plugins -import buildLib from '@xus/plugin-build-lib' -import cmdLib from '@xus/plugin-cmd-lib' +import { createPreset } from '@xus/cli-types' // cmd import cmdHelp from './plugin/command/help' import cmdCommitlint from './plugin/command/commitlint' @@ -10,10 +7,14 @@ import cmdCopy from './plugin/command/copy' import cmdLint from './plugin/command/lint' import cmdRelease from './plugin/command/release' import cmdChangelog from './plugin/command/changelog' +//bundler +import bundler from './plugin/bundler' +// lib build process plugins +import cmdRoll from '@xus/plugin-cmd-roll-lib' export default createPreset({ plugins: [ - buildLib, + bundler, cmdHelp, cmdCommitlint, cmdClean, @@ -21,6 +22,6 @@ export default createPreset({ cmdLint, cmdRelease, cmdChangelog, - cmdLib + cmdRoll ] }) diff --git a/yarn.lock b/yarn.lock index 1a2a749..8647dd1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2561,8 +2561,8 @@ "@rollup/pluginutils@^4.1.0": version "4.1.0" - resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.0.tgz#0dcc61c780e39257554feb7f77207dceca13c838" - integrity sha512-TrBhfJkFxA+ER+ew2U2/fHbebhLT/l/2pRk0hfj9KusXUuRXd2v0R58AfaZK9VXDQ4TogOSEmICVrQAA3zFnHQ== + resolved "https://registry.npm.taobao.org/@rollup/pluginutils/download/@rollup/pluginutils-4.1.0.tgz?cache=0&sync_timestamp=1603765619888&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40rollup%2Fpluginutils%2Fdownload%2F%40rollup%2Fpluginutils-4.1.0.tgz#0dcc61c780e39257554feb7f77207dceca13c838" + integrity sha1-Dcxhx4DjkldVT+t/dyB9zsoTyDg= dependencies: estree-walker "^2.0.1" picomatch "^2.2.2" @@ -2934,6 +2934,11 @@ dependencies: "@types/unist" "*" +"@types/mime@^2.0.3": + version "2.0.3" + resolved "https://registry.npm.taobao.org/@types/mime/download/@types/mime-2.0.3.tgz?cache=0&sync_timestamp=1613379303907&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fmime%2Fdownload%2F%40types%2Fmime-2.0.3.tgz#c893b73721db73699943bfc3653b1deb7faa4a3a" + integrity sha1-yJO3NyHbc2mZQ7/DZTsd63+qSjo= + "@types/minimatch@*", "@types/minimatch@^3.0.3": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -3384,8 +3389,13 @@ "@xus/rollup-chain@^0.2.3": version "0.2.3" - resolved "https://registry.yarnpkg.com/@xus/rollup-chain/-/rollup-chain-0.2.3.tgz#abd3b69ea6d065a84c5bd7c04750615eb6c4002f" - integrity sha512-sNhUrlPN7XMFTNFSG7+1cnVAb/ZFICZdEMuzSUdlzNgy+VUIfkUZC/5e/+GKcyTOGiOnYIxRbxj9w3Zq+rCM6Q== + resolved "https://registry.npm.taobao.org/@xus/rollup-chain/download/@xus/rollup-chain-0.2.3.tgz#abd3b69ea6d065a84c5bd7c04750615eb6c4002f" + integrity sha1-q9O2nqbQZahMW9fAR1BhXrbEAC8= + +"@xus/rollup-chain@^0.2.6": + version "0.2.6" + resolved "https://registry.yarnpkg.com/@xus/rollup-chain/-/rollup-chain-0.2.6.tgz#826b48b6737cfe9437a417ec5c3c3ca0b337f29c" + integrity sha512-0fso6+HTPrh7vxOTDgs8E6eV0sox95GHNpIYvA9Ct6fWIlGd9cKsP0jrwS2Yb66JSKRTlY5Z/NYZWRgTH2Jbzg== "@xus/rollup-plugin-vue2@^1.0.0": version "1.0.0" @@ -5054,6 +5064,11 @@ crypto-random-string@^2.0.0: resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" integrity sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA== +crypto@^1.0.1: + version "1.0.1" + resolved "https://registry.npm.taobao.org/crypto/download/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037" + integrity sha1-KvG3ytgXXSTIobB3glV5SiGAMDc= + css-color-names@0.0.4, css-color-names@^0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0" @@ -5378,6 +5393,11 @@ deep-is@^0.1.3, deep-is@~0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= +deepmerge@^1.5.2: + version "1.5.2" + resolved "https://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz?cache=0&sync_timestamp=1572279556265&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdeepmerge%2Fdownload%2Fdeepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753" + integrity sha1-EEmdhohEza1P7ghC34x/bwyVp1M= + deepmerge@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" @@ -5766,6 +5786,11 @@ es6-promisify@^5.0.0: dependencies: es6-promise "^4.0.3" +esbuild@^0.9.2: + version "0.9.2" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.9.2.tgz#7e9fde247c913ed8ee059e2648b0c53f7d00abe5" + integrity sha512-xE3oOILjnmN8PSjkG3lT9NBbd1DbxNqolJ5qNyrLhDWsFef3yTp/KTQz1C/x7BYFKbtrr9foYtKA6KA1zuNAUQ== + escalade@^3.1.1: version "3.1.1" resolved "https://npm.c2cloud.cn/escalade/download/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -7889,6 +7914,11 @@ istanbul-reports@^3.0.2: html-escaper "^2.0.0" istanbul-lib-report "^3.0.0" +javascript-stringify@^2.0.1: + version "2.0.1" + resolved "https://registry.npm.taobao.org/javascript-stringify/download/javascript-stringify-2.0.1.tgz#6ef358035310e35d667c675ed63d3eb7c1aa19e5" + integrity sha1-bvNYA1MQ411mfGde1j0+t8GqGeU= + jest-changed-files@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-26.6.2.tgz#f6198479e1cc66f22f9ae1e22acaa0b429c042d0" @@ -8823,7 +8853,7 @@ macos-release@^2.2.0: magic-string@^0.25.7: version "0.25.7" - resolved "https://npm.c2cloud.cn/magic-string/download/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" + resolved "https://registry.npm.taobao.org/magic-string/download/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" integrity sha1-P0l9b9NMZpxnmNy4IfLvMfVEUFE= dependencies: sourcemap-codec "^1.4.4" @@ -9128,7 +9158,7 @@ mime@^1.4.1: resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== -mime@^2.4.6: +mime@^2.4.6, mime@^2.5.2: version "2.5.2" resolved "https://registry.yarnpkg.com/mime/-/mime-2.5.2.tgz#6e3dc6cc2b9510643830e5f19d5cb753da5eeabe" integrity sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg== @@ -10945,6 +10975,11 @@ pumpify@^1.3.3: inherits "^2.0.3" pump "^2.0.0" +punycode@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" + integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0= + punycode@^2.1.0, punycode@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" @@ -10981,6 +11016,11 @@ query-string@^6.13.8: split-on-first "^1.0.0" strict-uri-encode "^2.0.0" +querystring@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" + integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA= + querystring@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd" @@ -11713,6 +11753,13 @@ rollup@^2.40.0: optionalDependencies: fsevents "~2.3.1" +rollup@^2.41.1: + version "2.41.1" + resolved "https://registry.npm.taobao.org/rollup/download/rollup-2.41.1.tgz#c7c7ada42b13be505facd516f13fb697c24c1116" + integrity sha1-x8etpCsTvlBfrNUW8T+2l8JMERY= + optionalDependencies: + fsevents "~2.3.1" + rsvp@^4.8.4: version "4.8.5" resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734" @@ -11839,8 +11886,8 @@ semver@7.0.0: semver@7.3.4, semver@7.x, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4: version "7.3.4" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" - integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw== + resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.4.tgz?cache=0&sync_timestamp=1606853731020&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" + integrity sha1-J6qn0uTKdkUvmNOt0JOnLJQ+3Jc= dependencies: lru-cache "^6.0.0" @@ -12796,7 +12843,7 @@ terminal-link@^2.0.0: ansi-escapes "^4.2.1" supports-hyperlinks "^2.0.0" -terser@^5.0.0: +terser@^5.0.0, terser@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/terser/-/terser-5.6.0.tgz#138cdf21c5e3100b1b3ddfddf720962f88badcd2" integrity sha512-vyqLMoqadC1uR0vywqOZzriDYzgEkNJFK4q9GeyOBHIbiECHiWLKcWfbQWAUaPfxkjDhapSlZB9f7fkMrvkVjA== @@ -13389,6 +13436,14 @@ url-parse-lax@^3.0.0: dependencies: prepend-http "^2.0.0" +url@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" + integrity sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE= + dependencies: + punycode "1.3.2" + querystring "0.2.0" + use@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" @@ -13599,6 +13654,14 @@ webidl-conversions@^6.1.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514" integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w== +webpack-chain@^6.5.1: + version "6.5.1" + resolved "https://registry.npm.taobao.org/webpack-chain/download/webpack-chain-6.5.1.tgz?cache=0&sync_timestamp=1595813222470&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fwebpack-chain%2Fdownload%2Fwebpack-chain-6.5.1.tgz#4f27284cbbb637e3c8fbdef43eef588d4d861206" + integrity sha1-TycoTLu2N+PI+970Pu9YjU2GEgY= + dependencies: + deepmerge "^1.5.2" + javascript-stringify "^2.0.1" + whatwg-encoding@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"