diff --git a/.changeset/red-laws-scream.md b/.changeset/red-laws-scream.md new file mode 100644 index 000000000000..9080e7e04660 --- /dev/null +++ b/.changeset/red-laws-scream.md @@ -0,0 +1,6 @@ +--- +'@modern-js/module-tools': patch +--- + +chore(module-tools): remove unuse schema +chore(module-tools): 移除没有使用的 schema diff --git a/packages/solutions/module-tools/src/config/legacySchema.ts b/packages/solutions/module-tools/src/config/legacySchema.ts deleted file mode 100644 index a264b2018dbd..000000000000 --- a/packages/solutions/module-tools/src/config/legacySchema.ts +++ /dev/null @@ -1,197 +0,0 @@ -export const targets = [ - 'es5', - 'es6', - 'es2015', - 'es2016', - 'es2017', - 'es2018', - 'es2019', - 'es2020', - // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported. - 'esnext', -]; - -export const presets = [ - 'npm-library', - 'npm-library-with-umd', - 'npm-component', - 'npm-component-with-umd', - ...[ - 'npm-library', - 'npm-library-with-umd', - 'npm-component', - 'npm-component-with-umd', - ].reduce((ret, crt) => { - return [...ret, ...targets.map(t => `${crt}-${t}`)]; - }, []), -]; - -const properties = { - target: { - enum: targets, - }, - format: { - enum: ['cjs', 'esm', 'umd'], - }, - sourceMap: { - enum: [true, false, 'inline', 'external'], - }, - buildType: { - enum: ['bundle', 'bundleless'], - }, - bundleOptions: { - type: 'object', - properties: { - getModuleId: { - instanceof: 'Function', - }, - entry: { - type: 'object', - }, - splitting: { - type: 'boolean', - }, - externals: { - type: 'array', - items: { - anyOf: [ - { - instanceof: 'RegExp', - }, - { - typeof: 'string', - }, - ], - }, - }, - platform: { - enum: ['node', 'browser'], - }, - minify: { - enum: ['esbuild', 'terser', false], - }, - skipDeps: { - type: 'boolean', - }, - }, - }, - bundlelessOptions: { - type: 'object', - properties: { - sourceDir: { - type: 'string', - }, - style: { - type: 'object', - properties: { - compileMode: { - enum: ['all', 'only-compiled-code', 'only-source-code', false], - }, - path: { type: 'string' }, - }, - }, - static: { - type: 'object', - properties: { - path: { type: 'string' }, - }, - }, - }, - }, - - tsconfig: { - type: 'string', - }, - enableDts: { - type: 'boolean', - }, - dtsOnly: { - type: 'boolean', - }, - - outputPath: { type: 'string' }, -}; - -export const buildSchema = [ - { - target: 'output.buildConfig', - schema: { - if: { - type: 'array', - }, - then: { - items: [{ type: 'object', properties, additionalProperties: false }], - }, - else: { type: 'object', properties, additionalProperties: false }, - }, - }, - { - target: 'output.buildPreset', - schema: { - enum: presets, - }, - }, -]; - -const PACKAGE_MODE_LIST = [ - 'universal-js', - 'universal-js-lite', - 'browser-js', - 'browser-js-lite', - 'node-js', -]; - -export const outputSchema = [ - /** packageMode will deprecated */ - { - target: 'output.packageMode', - schema: { enum: PACKAGE_MODE_LIST }, - }, - /** packageFields will deprecated */ - { - target: 'output.packageFields', - schema: { typeof: 'object' }, - }, - /** enableSourceMap will deprecated */ - { - target: 'output.enableSourceMap', - schema: { typeof: 'boolean' }, - }, - /** importStyle will deprecated */ - { - target: 'output.importStyle', - schema: { - enum: ['compiled-code', 'source-code'], - }, - }, - /** assetsPath will deprecated */ - { - target: 'output.assetsPath', - schema: { - typeof: 'string', - default: 'styles', - }, - }, - ...buildSchema, -]; - -export const sourceSchema = [ - { - target: 'source.jsxTransformRuntime', - schema: { - // https://babeljs.io/docs/en/babel-preset-react#runtime - enum: ['classic', 'automatic'], - }, - }, -]; - -export const toolsSchema = [ - { - target: 'tools.speedy', - schema: { - typeof: ['object', 'function'], - }, - }, -]; - -export const legacySchema = [...sourceSchema, ...outputSchema, ...toolsSchema]; diff --git a/packages/solutions/module-tools/src/config/schema.ts b/packages/solutions/module-tools/src/config/schema.ts deleted file mode 100644 index d19c00b66cfd..000000000000 --- a/packages/solutions/module-tools/src/config/schema.ts +++ /dev/null @@ -1,252 +0,0 @@ -export const targets = [ - 'es5', - 'es6', - 'es2015', - 'es2016', - 'es2017', - 'es2018', - 'es2019', - 'es2020', - 'es2021', - 'es2022', - // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported. - 'esnext', -]; - -export const presets = [ - 'npm-library', - 'npm-library-with-umd', - 'npm-component', - 'npm-component-with-umd', - ...[ - 'npm-library', - 'npm-library-with-umd', - 'npm-component', - 'npm-component-with-umd', - ].reduce((ret, crt) => { - return [...ret, ...targets.map(t => `${crt}-${t}`)]; - }, []), - 'modern-js-node', - 'modern-js-universal', -]; -const buildConfigProperties = { - alias: { - typeof: ['object', 'function'], - }, - hooks: { - // TODO: improve it - type: 'array', - }, - resolve: { - // TODO: add properties - type: 'object', - }, - banner: { - // TODO: add properties - type: 'object', - }, - asset: { - type: 'object', - }, - autoExternal: { - if: { - type: 'object', - }, - then: { - properties: { - dependencies: { type: 'boolean' }, - peerDependencies: { type: 'boolean' }, - }, - }, - else: { type: 'boolean' }, - }, - buildType: { - enum: ['bundle', 'bundleless'], - }, - copy: { - type: 'object', - properties: { - patterns: { - type: 'array', - items: { - type: 'object', - properties: { - from: { type: 'string' }, - to: { type: 'string' }, - context: { type: 'string' }, - globOptions: { type: 'object' }, - }, - }, - }, - options: { - type: 'object', - properties: { - concurrency: { - type: 'number', - }, - }, - }, - }, - }, - define: { - typeof: 'object', - }, - dts: { - if: { type: 'object' }, - then: { - properties: { - distPath: { type: 'string' }, - tsconfigPath: { type: 'string' }, - abortOnError: { type: 'boolean' }, - respectExternal: { - type: 'boolean', - }, - }, - }, - else: { type: 'boolean' }, - }, - autoExtension: { - type: 'boolean', - }, - externals: { - type: 'array', - items: { - anyOf: [ - { - instanceof: 'RegExp', - }, - { - typeof: 'string', - }, - ], - }, - }, - format: { - enum: ['cjs', 'esm', 'iife', 'umd'], - }, - input: { - type: ['array', 'object'], - }, - jsx: { - enum: ['automatic', 'transform', 'preserve'], - }, - minify: { - if: { - type: 'object', - }, - else: { enum: ['esbuild', 'terser', false] }, - }, - outDir: { type: 'string' }, - platform: { - enum: ['node', 'browser'], - }, - sourceDir: { - typeof: 'string', - }, - sourceMap: { - enum: [true, false, 'inline', 'external'], - }, - splitting: { - type: 'boolean', - }, - style: { - // TODO: add properties - type: 'object', - }, - redirect: { - type: 'object', - }, - target: { - enum: targets, - }, - umdGlobals: { - type: 'object', - }, - esbuildOpitons: { - instanceof: 'Function', - }, - umdModuleName: { - anyOf: [ - { - instanceof: 'Function', - }, - { - typeof: 'string', - }, - ], - }, - shims: { - type: 'boolean', - }, - sideEffects: { - anyOf: [ - { - type: 'array', - items: { - instanceof: 'RegExp', - }, - }, - { - type: 'boolean', - }, - { - instanceof: 'Function', - }, - ], - }, - externalHelpers: { - type: 'boolean', - }, - tsconfig: { - type: 'string', - }, - transformImport: { - type: 'array', - }, - transformLodash: { - type: 'boolean', - }, - sourceType: { - enum: ['commonjs', 'module'], - }, -}; -export const buildConfig = { - target: 'buildConfig', - schema: { - if: { - type: 'array', - }, - then: { - items: [ - { - type: 'object', - properties: buildConfigProperties, - }, - ], - }, - else: { - type: 'object', - properties: buildConfigProperties, - }, - }, -}; -export const buildPreset = { - target: 'buildPreset', - schema: { - if: { type: 'string' }, - then: { - enum: presets, - }, - else: { typeof: 'function' }, - }, -}; - -export const legacy = { - target: 'legacy', - schema: { - type: 'boolean', - }, -}; - -export const schema = [buildConfig, buildPreset, legacy]; -export { legacySchema } from './legacySchema';