From 30818675137df73e82d72e29b45a458997a44c36 Mon Sep 17 00:00:00 2001 From: Michael Gerullis Date: Tue, 13 Apr 2021 15:15:19 +0200 Subject: [PATCH 1/3] Add script for generating .d.ts files --- .eslintrc | 3 ++- package.json | 4 +++- tsconfig.build-types.json | 10 ++++++++++ types/index.d.ts | 15 +++++++++++++++ types/lib/array-to-object.d.ts | 1 + yarn.lock | 5 +++++ 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tsconfig.build-types.json create mode 100644 types/index.d.ts create mode 100644 types/lib/array-to-object.d.ts diff --git a/.eslintrc b/.eslintrc index bee50275..b745e246 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,5 +11,6 @@ "extends": "@avalanche/eslint-config", "rules": { "compat/compat": "error" - } + }, + "ignorePatterns": ["**/*.d.ts"], } diff --git a/package.json b/package.json index b800317f..973b7869 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "scripts:umd": "rollup --config --output.format umd --name vuex-map-fields --output.file dist/index.js src/index.js", "scripts:es": "rollup --config --output.format es --name vuex-map-fields --output.file dist/index.esm.js src/index.js", "scripts:minify": "uglifyjs --compress --mangle --comments --output dist/index.min.js dist/index.js && uglifyjs --compress --mangle --comments --output dist/index.esm.min.js dist/index.esm.js", - "scripts": "yarn run scripts:umd && yarn run scripts:es && yarn run scripts:minify", + "scripts:typing": "tsc --project tsconfig.build-types.json", + "scripts": "yarn run scripts:umd && yarn run scripts:es && yarn run scripts:minify && yarn run scripts:typing", "build": "yarn run scripts", "fake-publish": "yarn run build && sh test/utils/fake-publish.sh", "lint:scripts": "yarn run fake-publish && eslint --ignore-path .gitignore .", @@ -42,6 +43,7 @@ "jest": "^26.4.2", "rollup": "^2.28.2", "rollup-plugin-babel": "^4.4.0", + "typescript": "^4.2.4", "uglify-es": "^3.3.9", "vue": "^2.6.12", "vue-template-compiler": "^2.6.12", diff --git a/tsconfig.build-types.json b/tsconfig.build-types.json new file mode 100644 index 00000000..dbed4753 --- /dev/null +++ b/tsconfig.build-types.json @@ -0,0 +1,10 @@ +{ + "include": ["src/**/*"], + "exclude": ["src/**/*.spec.js"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "types" + } +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..cec16091 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,15 @@ +export function getField(state: any): (path: any) => any; +export function updateField(state: any, { path, value }: { + path: any; + value: any; +}): void; +export function mapFields(...params: any[]): any; +export function mapMultiRowFields(...params: any[]): any; +export function createHelpers({ getterType, mutationType }: { + getterType: any; + mutationType: any; +}): { + [x: number]: typeof updateField; + mapFields: (...params: any[]) => any; + mapMultiRowFields: (...params: any[]) => any; +}; diff --git a/types/lib/array-to-object.d.ts b/types/lib/array-to-object.d.ts new file mode 100644 index 00000000..646d923b --- /dev/null +++ b/types/lib/array-to-object.d.ts @@ -0,0 +1 @@ +export default function arrayToObject(fields?: any[]): any; diff --git a/yarn.lock b/yarn.lock index 3bdfc67e..58e263c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5093,6 +5093,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.2.4: + version "4.2.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961" + integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg== + uglify-es@^3.3.9: version "3.3.9" resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677" From d02a96dcdb2a4757e6279c25ffc88cffe528158e Mon Sep 17 00:00:00 2001 From: Michael Gerullis Date: Tue, 13 Apr 2021 15:28:52 +0200 Subject: [PATCH 2/3] Use filder named after project --- .eslintrc | 2 +- tsconfig.build-types.json | 2 +- types/{ => vuex-map-fields}/index.d.ts | 0 types/{ => vuex-map-fields}/lib/array-to-object.d.ts | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename types/{ => vuex-map-fields}/index.d.ts (100%) rename types/{ => vuex-map-fields}/lib/array-to-object.d.ts (100%) diff --git a/.eslintrc b/.eslintrc index b745e246..733025f0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,5 +12,5 @@ "rules": { "compat/compat": "error" }, - "ignorePatterns": ["**/*.d.ts"], + "ignorePatterns": ["**/*.d.ts"] } diff --git a/tsconfig.build-types.json b/tsconfig.build-types.json index dbed4753..967cb6fc 100644 --- a/tsconfig.build-types.json +++ b/tsconfig.build-types.json @@ -5,6 +5,6 @@ "allowJs": true, "declaration": true, "emitDeclarationOnly": true, - "outDir": "types" + "outDir": "types/vuex-map-fields" } } \ No newline at end of file diff --git a/types/index.d.ts b/types/vuex-map-fields/index.d.ts similarity index 100% rename from types/index.d.ts rename to types/vuex-map-fields/index.d.ts diff --git a/types/lib/array-to-object.d.ts b/types/vuex-map-fields/lib/array-to-object.d.ts similarity index 100% rename from types/lib/array-to-object.d.ts rename to types/vuex-map-fields/lib/array-to-object.d.ts From ea43b241ff0f082ab0d9fe3b9beac950a2d6613b Mon Sep 17 00:00:00 2001 From: Michael Gerullis Date: Tue, 13 Apr 2021 15:53:39 +0200 Subject: [PATCH 3/3] - Add types field to package.json - Add whitespace --- package.json | 1 + tsconfig.build-types.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 973b7869..ae561859 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "vuex": "^3.5.1" }, "main": "dist/index.js", + "types": "types/vuex-map-fields/index.d.ts", "module": "dist/index.esm.js", "repository": { "type": "git", diff --git a/tsconfig.build-types.json b/tsconfig.build-types.json index 967cb6fc..11da3bc4 100644 --- a/tsconfig.build-types.json +++ b/tsconfig.build-types.json @@ -7,4 +7,4 @@ "emitDeclarationOnly": true, "outDir": "types/vuex-map-fields" } -} \ No newline at end of file +}