Skip to content

Commit

Permalink
Do not import package.json (#911)
Browse files Browse the repository at this point in the history
* Do not import package.json

* fixes
  • Loading branch information
szmarczak authored and sindresorhus committed Nov 3, 2019
1 parent b403a68 commit 95bed1e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -9,13 +9,13 @@
"node": ">=10"
},
"scripts": {
"test": "xo && nyc ava && tsc --noEmit",
"test": "xo && tsc --noEmit && nyc ava",
"release": "np",
"build": "del-cli dist && tsc",
"prepare": "npm run build"
},
"files": [
"dist"
"dist/source"
],
"keywords": [
"http",
Expand Down
6 changes: 1 addition & 5 deletions source/index.ts
@@ -1,10 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import create from './create';
import {Defaults} from './utils/types.js';

const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));

const defaults: Partial<Defaults> = {
options: {
method: 'GET',
Expand Down Expand Up @@ -39,7 +35,7 @@ const defaults: Partial<Defaults> = {
]
},
headers: {
'user-agent': `${packageJson.name}/${packageJson.version} (https://github.com/sindresorhus/got)`
'user-agent': 'got (https://github.com/sindresorhus/got)'
},
hooks: {
beforeRequest: [],
Expand Down
3 changes: 2 additions & 1 deletion test/error.ts
Expand Up @@ -152,7 +152,8 @@ test('`http.request` pipe error', async t => {
},
on: () => {},
once: () => {},
emit: () => {}
emit: () => {},
prependOnceListener: () => {}
};
},
throwHttpErrors: false
Expand Down
5 changes: 2 additions & 3 deletions test/headers.ts
Expand Up @@ -5,7 +5,6 @@ import test from 'ava';
import FormData = require('form-data');
import got from '../source';
import supportsBrotli from '../source/utils/supports-brotli';
import packageJson = require('../package.json');
import withServer from './helpers/with-server';

type TestReturn = Record<string, Record<string, unknown>>;
Expand All @@ -19,7 +18,7 @@ test('`user-agent`', withServer, async (t, server, got) => {
server.get('/', echoHeaders);

const headers = await got('').json();
t.is(headers['user-agent'], `${packageJson.name}/${packageJson.version} (https://github.com/sindresorhus/got)`);
t.is(headers['user-agent'], 'got (https://github.com/sindresorhus/got)');
});

test('`accept-encoding`', withServer, async (t, server, got) => {
Expand Down Expand Up @@ -54,7 +53,7 @@ test('does not remove user headers from `url` object argument', withServer, asyn
})).body;

t.is(headers.accept, 'application/json');
t.is(headers['user-agent'], `${packageJson.name}/${packageJson.version} (https://github.com/sindresorhus/got)`);
t.is(headers['user-agent'], 'got (https://github.com/sindresorhus/got)');
t.is(headers['accept-encoding'], supportsBrotli ? 'gzip, deflate, br' : 'gzip, deflate');
t.is(headers['x-request-id'], 'value');
});
Expand Down

0 comments on commit 95bed1e

Please sign in to comment.