diff --git a/package-lock.json b/package-lock.json index 7fc620dce..4df222c00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12185,6 +12185,12 @@ "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", "dev": true }, + "package-json-type": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/package-json-type/-/package-json-type-1.0.3.tgz", + "integrity": "sha512-Bey4gdRuOwDbS8Fj1qA3/pTq5r8pqiI5E3tjSqCdhaLSsyGG364VFzXLTIexN5AaNGe/vgdBzLfoKdr7EVg2KQ==", + "dev": true + }, "parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", diff --git a/package.json b/package.json index 7955f9432..68bffb95b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "eslint-plugin-jest": "23.8.1", "eslint-plugin-prettier": "3.1.2", "jest": "25.1.0", + "package-json-type": "1.0.3", "prettier": "1.19.1", "rimraf": "3.0.2", "semantic-release": "17.0.4", diff --git a/src/constants.ts b/src/constants.ts index 44da394bb..070776859 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,5 @@ -import { name, version } from '../package.json' +import pkg from './package' -export const USER_AGENT = `${name}/${version}` +export const USER_AGENT = `${pkg.name}/${pkg.version}` export const JSON_CONTENT_TYPE = 'application/json' diff --git a/src/package.ts b/src/package.ts new file mode 100644 index 000000000..63e5db6ec --- /dev/null +++ b/src/package.ts @@ -0,0 +1,9 @@ +import { readFileSync } from 'fs' +import { join } from 'path' +import { IPackageJson } from 'package-json-type' + +const packageJson: IPackageJson = JSON.parse( + readFileSync(join(__dirname, '../package.json'), { encoding: 'utf8' }), +) + +export default packageJson diff --git a/test/package.test.ts b/test/package.test.ts new file mode 100644 index 000000000..0370c5404 --- /dev/null +++ b/test/package.test.ts @@ -0,0 +1,11 @@ +import pkg from '../src/package' + +describe('package', () => { + it('should have package name', () => { + expect(pkg.name).toBe('amazon-advertising-api-sdk') + }) + + it('should have package version', () => { + expect(pkg.version).toMatch(/^\d+\.\d+\.\d+$/) + }) +})