From 08757920c85635a54637fcd590f6e9f0107a0240 Mon Sep 17 00:00:00 2001 From: Roman Filippov Date: Fri, 6 Mar 2020 14:56:27 +0700 Subject: [PATCH] fix: references to package.json importing package.json directly from the require / import system causes it to be bundled with the transpiled code in ./lib which then causes problems with release. Closes #249 --- package-lock.json | 6 ++++++ package.json | 1 + src/constants.ts | 4 ++-- src/package.ts | 9 +++++++++ test/package.test.ts | 11 +++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/package.ts create mode 100644 test/package.test.ts 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+$/) + }) +})