From 9541d509134b8ae21e71ff3f1cca8ffc761d6b27 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 8 May 2023 17:24:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20default=20generator=20in?= =?UTF-8?q?=20manifest=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 default generator in manifest * chore: 🤖 add changeset * fix: 🐛 build * test: 💍 default generator value * chore: 🤖 revert the version changes --- .changeset/curly-ears-remember.md | 5 +++++ packages/dotlottie-js/src/common/dotlottie-common.ts | 4 +++- packages/dotlottie-js/src/index.ts | 1 - packages/dotlottie-js/src/node/dotlottie.ts | 8 +++++++- .../dotlottie-js/src/tests/dotlottie-js-browser.spec.ts | 7 +++++++ packages/dotlottie-js/src/tests/dotlottie-js-node.spec.ts | 7 +++++++ packages/dotlottie-js/tsconfig.build.json | 2 +- 7 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .changeset/curly-ears-remember.md diff --git a/.changeset/curly-ears-remember.md b/.changeset/curly-ears-remember.md new file mode 100644 index 0000000..2f81655 --- /dev/null +++ b/.changeset/curly-ears-remember.md @@ -0,0 +1,5 @@ +--- +"@dotlottie/dotlottie-js": patch +--- + +fix: 🐛 default generator in manifest diff --git a/packages/dotlottie-js/src/common/dotlottie-common.ts b/packages/dotlottie-js/src/common/dotlottie-common.ts index 777618d..16b0eb0 100644 --- a/packages/dotlottie-js/src/common/dotlottie-common.ts +++ b/packages/dotlottie-js/src/common/dotlottie-common.ts @@ -4,6 +4,8 @@ import type { Animation } from '@lottiefiles/lottie-types'; +import pkg from '../../package.json'; + import type { DotLottiePlugin } from './dotlottie-plugin'; import type { AnimationOptions, LottieAnimationCommon } from './lottie-animation-common'; import type { LottieImageCommon } from './lottie-image-common'; @@ -50,7 +52,7 @@ export class DotLottieCommon { this._description = options?.description ?? ''; - this._generator = options?.generator ?? 'dotLottie-js_v2.0'; + this._generator = options?.generator ?? `${pkg.name}@${pkg.version}`; this._keywords = options?.keywords ?? 'dotLottie'; diff --git a/packages/dotlottie-js/src/index.ts b/packages/dotlottie-js/src/index.ts index a4ff612..619c03b 100644 --- a/packages/dotlottie-js/src/index.ts +++ b/packages/dotlottie-js/src/index.ts @@ -2,7 +2,6 @@ * Copyright 2023 Design Barn Inc. */ -// export * from './main'; export * from './dotlottie'; export * from './lottie-animation'; export * from './lottie-image'; diff --git a/packages/dotlottie-js/src/node/dotlottie.ts b/packages/dotlottie-js/src/node/dotlottie.ts index 8e9e342..8a34c45 100644 --- a/packages/dotlottie-js/src/node/dotlottie.ts +++ b/packages/dotlottie-js/src/node/dotlottie.ts @@ -6,6 +6,7 @@ import type { Animation } from '@lottiefiles/lottie-types'; import type { Zippable } from 'fflate'; import { strToU8, unzip, zip, strFromU8 } from 'fflate'; +import pkg from '../../package.json'; import { createError, DotLottieCommon } from '../common'; import type { DotLottieOptions, DotLottiePlugin, AnimationOptions } from '../common'; @@ -16,7 +17,12 @@ import { base64ToUint8Array, getExtensionTypeFromBase64 } from './utils'; export class DotLottie extends DotLottieCommon { public constructor(options?: DotLottieOptions) { - super(options); + const generator = options?.generator ?? `${pkg.name}/node@${pkg.version}`; + + super({ + ...options, + generator, + }); if (this.enableDuplicateImageOptimization) this.addPlugins(new DuplicateImageDetector()); } diff --git a/packages/dotlottie-js/src/tests/dotlottie-js-browser.spec.ts b/packages/dotlottie-js/src/tests/dotlottie-js-browser.spec.ts index 885988b..35c3b8a 100644 --- a/packages/dotlottie-js/src/tests/dotlottie-js-browser.spec.ts +++ b/packages/dotlottie-js/src/tests/dotlottie-js-browser.spec.ts @@ -7,6 +7,7 @@ import { Base64 } from 'js-base64'; import { DotLottie, LottieAnimation } from '..'; +import pkg from '../../package.json'; import type { AnimationData, Manifest } from '../common'; import { DotLottiePlugin } from '../common'; @@ -108,6 +109,12 @@ describe('setGenerator', () => { expect(dotlottie.generator).toBe(generator); }); + + it('has proper generator when no input provided', () => { + const dotLottie = new DotLottie(); + + expect(dotLottie.generator).toBe(`${pkg.name}@${pkg.version}`); + }); }); describe('setKeywords', () => { diff --git a/packages/dotlottie-js/src/tests/dotlottie-js-node.spec.ts b/packages/dotlottie-js/src/tests/dotlottie-js-node.spec.ts index 091898e..4affb25 100644 --- a/packages/dotlottie-js/src/tests/dotlottie-js-node.spec.ts +++ b/packages/dotlottie-js/src/tests/dotlottie-js-node.spec.ts @@ -6,6 +6,7 @@ import { Base64 } from 'js-base64'; +import pkg from '../../package.json'; import type { AnimationData, Manifest } from '../common'; import { DotLottiePlugin } from '../common'; import { DotLottie, LottieAnimation } from '../node'; @@ -108,6 +109,12 @@ describe('setGenerator', () => { expect(dotlottie.generator).toBe(generator); }); + + it('has proper generator when no input provided', () => { + const dotLottie = new DotLottie(); + + expect(dotLottie.generator).toBe(`${pkg.name}/node@${pkg.version}`); + }); }); describe('setKeywords', () => { diff --git a/packages/dotlottie-js/tsconfig.build.json b/packages/dotlottie-js/tsconfig.build.json index d3626e7..9926199 100644 --- a/packages/dotlottie-js/tsconfig.build.json +++ b/packages/dotlottie-js/tsconfig.build.json @@ -8,7 +8,7 @@ "outDir": "./dist", // Source root directory - "rootDir": "./src" + "rootDir": "." }, // Files included in compilation