From 1d8a434f21a567add9ea9e6f471fd00c579756a3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 6 Aug 2024 01:34:19 +0200 Subject: [PATCH] netteForms: restructured package, includes UMD and ESM (BC break) --- eslint.config.js | 2 +- rollup.config.js | 41 +++++++++++++++++++++++++----- src/assets/{ => dist}/package.json | 12 ++++----- src/assets/index.esm.ts | 7 +++++ src/assets/index.umd.ts | 2 +- tests/netteForms/karma.conf.ts | 2 +- 6 files changed, 49 insertions(+), 17 deletions(-) rename src/assets/{ => dist}/package.json (68%) create mode 100644 src/assets/index.esm.ts diff --git a/eslint.config.js b/eslint.config.js index a1b94f6e..2496b0b6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,7 +7,7 @@ export default [ { ignores: [ '*/', '!src/', '!tests/', - '**/netteForms*.*', + '**/dist/', ], }, diff --git a/rollup.config.js b/rollup.config.js index 8a369754..95ba912a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -34,21 +34,21 @@ function spaces2tabs() { export default [ - { + { // TODO: consider the possibility of cutting off the UMD versions completely due to collision input: 'src/assets/index.umd.ts', output: [ { format: 'umd', name: 'Nette', - dir: 'src/assets', - entryFileNames: 'netteForms.js', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.umd.js', generatedCode: 'es2015', }, { format: 'umd', name: 'Nette', - dir: 'src/assets', - entryFileNames: 'netteForms.min.js', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.umd.min.js', generatedCode: 'es2015', plugins: [ terser(), @@ -65,9 +65,36 @@ export default [ }, { - input: 'src/assets/index.umd.ts', + input: 'src/assets/index.esm.ts', + output: [ + { + format: 'es', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.esm.js', + generatedCode: 'es2015', + }, + { + format: 'es', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.esm.min.js', + generatedCode: 'es2015', + plugins: [ + terser(), + ], + }, + ], + plugins: [ + json(), + nodeResolve(), + typescript(), + spaces2tabs(), + ], + }, + + { + input: 'src/assets/index.esm.ts', output: [{ - file: 'src/assets/netteForms.d.ts', + file: 'src/assets/dist/nette-forms.d.ts', format: 'es', }], plugins: [ diff --git a/src/assets/package.json b/src/assets/dist/package.json similarity index 68% rename from src/assets/package.json rename to src/assets/dist/package.json index fda9428e..3aabed2d 100644 --- a/src/assets/package.json +++ b/src/assets/dist/package.json @@ -1,6 +1,6 @@ { "name": "nette-forms", - "version": "3.5.0", + "version": "4.0.0", "description": "Client side script for Nette Forms Component", "keywords": [ "nette", @@ -10,12 +10,10 @@ "homepage": "https://nette.org", "author": "David Grudl (https://davidgrudl.com)", "license": "BSD-3-Clause", - "main": "src/assets/netteForms.js", - "types": "src/assets/netteForms.d.ts", - "unpkg": "src/assets/netteForms.min.js", - "files": [ - "src/assets" - ], + "main": "nette-forms.umd.js", + "module": "nette-forms.esm.js", + "types": "nette-forms.d.ts", + "unpkg": "nette-forms.umd.min.js", "repository": { "type": "git", "url": "git+https://github.com/nette/forms.git", diff --git a/src/assets/index.esm.ts b/src/assets/index.esm.ts new file mode 100644 index 00000000..5be89db1 --- /dev/null +++ b/src/assets/index.esm.ts @@ -0,0 +1,7 @@ +import { FormValidator } from './formValidator'; + +// TODO +export function initialize() { +} + +export { FormValidator }; diff --git a/src/assets/index.umd.ts b/src/assets/index.umd.ts index 55621a62..1e73639f 100644 --- a/src/assets/index.umd.ts +++ b/src/assets/index.umd.ts @@ -1,6 +1,6 @@ import { FormValidator } from './formValidator'; import { webalize } from './webalize'; -import { version } from './package.json'; +import { version } from './dist/package.json'; type NetteForms = FormValidator & { version: string; webalize: typeof webalize }; let nette = new FormValidator as NetteForms; diff --git a/tests/netteForms/karma.conf.ts b/tests/netteForms/karma.conf.ts index 3712c64d..059cb3d0 100644 --- a/tests/netteForms/karma.conf.ts +++ b/tests/netteForms/karma.conf.ts @@ -4,7 +4,7 @@ module.exports = function (config) { frameworks: ['jasmine'], browsers: ['ChromeHeadless'], files: [ - '../../src/assets/netteForms.js', + '../../src/assets/dist/nette-forms.umd.js', 'spec/*Spec.js', ], autoWatch: false,