diff --git a/package.json b/package.json index ba911b31a6a..34f52ee5048 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,7 @@ "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.30.0", "rollup-plugin-inject-process-env": "^1.3.1", + "rollup-plugin-dts": "^2.0.0", "semver": "^7.3.5", "semver-regex": "^2.0.0", "showdown": "^1.9.1", diff --git a/packages/core/docs/api/models/Form.md b/packages/core/docs/api/models/Form.md index 6af8f7f982e..24d6a241330 100644 --- a/packages/core/docs/api/models/Form.md +++ b/packages/core/docs/api/models/Form.md @@ -240,7 +240,7 @@ interface deleteValuesIn { FormPathPattern API 参考 [FormPath](/api/entry/form-path#formpathpattern) -### deleteIntialValuesIn +### deleteInitialValuesIn #### 描述 diff --git a/packages/core/src/__tests__/form.spec.ts b/packages/core/src/__tests__/form.spec.ts index b0dac11de93..738f4d4af36 100644 --- a/packages/core/src/__tests__/form.spec.ts +++ b/packages/core/src/__tests__/form.spec.ts @@ -192,7 +192,7 @@ test('deleteValuesIn/deleteInitialValuesIn', () => { expect(form.values.aa).toEqual(123) expect(form.values.bb).toEqual(123) form.deleteValuesIn('aa') - form.deleteIntialValuesIn('bb') + form.deleteInitialValuesIn('bb') expect(form.existValuesIn('aa')).toBeFalsy() expect(form.existInitialValuesIn('bb')).toBeFalsy() }) diff --git a/packages/core/src/models/Form.ts b/packages/core/src/models/Form.ts index 8069c66deea..c06f4fb6e2f 100644 --- a/packages/core/src/models/Form.ts +++ b/packages/core/src/models/Form.ts @@ -159,7 +159,7 @@ export class Form { setPattern: batch, setDisplay: batch, setState: batch, - deleteIntialValuesIn: batch, + deleteInitialValuesIn: batch, deleteValuesIn: batch, setSubmitting: batch, setValidating: batch, @@ -450,7 +450,7 @@ export class Form { }) } - deleteIntialValuesIn = (pattern: FormPathPattern) => { + deleteInitialValuesIn = (pattern: FormPathPattern) => { untracked(() => { FormPath.deleteIn(this.initialValues, pattern) }) diff --git a/scripts/rollup.base.js b/scripts/rollup.base.js index d4d9bcc47cb..a552e8b5772 100644 --- a/scripts/rollup.base.js +++ b/scripts/rollup.base.js @@ -4,6 +4,7 @@ import resolve from 'rollup-plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' import externalGlobals from 'rollup-plugin-external-globals' import injectProcessEnv from 'rollup-plugin-inject-process-env' +import dts from 'rollup-plugin-dts' import { terser } from 'rollup-plugin-terser' const presets = () => { @@ -62,6 +63,20 @@ const createEnvPlugin = (env) => { } const inputFilePath = path.join(process.cwd(), 'src/index.ts') + +const bundleDtsPackages = [ + 'formily.core', + 'formily.react', + 'formily.vue', + 'formily.validator', + 'formily.shared', + 'formily.path', + 'formily.json-schema', + 'formily.reactive', + 'formily.reactive-react', + 'formily.reactive-vue', +] + export const removeImportStyleFromInputFilePlugin = () => ({ name: 'remove-import-style-from-input-file', transform(code, id) { @@ -74,38 +89,53 @@ export const removeImportStyleFromInputFilePlugin = () => ({ }, }) -export default (filename, targetName, ...plugins) => [ - { - input: 'src/index.ts', - output: { - format: 'umd', - file: `dist/${filename}.umd.development.js`, - name: targetName, - sourcemap: true, - amd: { - id: filename, +export default (filename, targetName, ...plugins) => { + const base = [ + { + input: 'src/index.ts', + output: { + format: 'umd', + file: `dist/${filename}.umd.development.js`, + name: targetName, + sourcemap: true, + amd: { + id: filename, + }, }, + external: ['react', 'react-dom', 'react-is'], + plugins: [...presets(), ...plugins, createEnvPlugin('development')], }, - external: ['react', 'react-dom', 'react-is'], - plugins: [...presets(), ...plugins, createEnvPlugin('development')], - }, - { - input: 'src/index.ts', - output: { - format: 'umd', - file: `dist/${filename}.umd.production.js`, - name: targetName, - sourcemap: true, - amd: { - id: filename, + { + input: 'src/index.ts', + output: { + format: 'umd', + file: `dist/${filename}.umd.production.js`, + name: targetName, + sourcemap: true, + amd: { + id: filename, + }, }, + external: ['react', 'react-dom', 'react-is'], + plugins: [ + ...presets(), + terser(), + ...plugins, + createEnvPlugin('production'), + ], }, - external: ['react', 'react-dom', 'react-is'], - plugins: [ - ...presets(), - terser(), - ...plugins, - createEnvPlugin('production'), - ], - }, -] + ] + + if (bundleDtsPackages.includes(filename)) { + base.push({ + input: 'esm/index.d.ts', + output: { + format: 'es', + file: `dist/${filename}.d.ts`, + }, + plugins: [dts(), ...plugins], + }) + } + + return base +} diff --git a/yarn.lock b/yarn.lock index 15c37288b1e..570c461a65e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16342,6 +16342,15 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" +rollup-plugin-dts@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-2.0.1.tgz#333f50a637e199a073d490b198746f3c6bd07701" + integrity sha512-y38NSXIY37YExCumbGBTL5dXg7pL7XD+Kbe98iEHWFN9yiKJf7t4kKBOkml5ylUDjQIXBnNClGDeRktc1T5dmA== + dependencies: + magic-string "^0.25.7" + optionalDependencies: + "@babel/code-frame" "^7.10.4" + rollup-plugin-external-globals@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/rollup-plugin-external-globals/-/rollup-plugin-external-globals-0.6.1.tgz#861c260b5727144e0fd1b424b103f9f0282fc365"