Skip to content

Commit

Permalink
Remove cacheable-request, rename pacakge to got-lite
Browse files Browse the repository at this point in the history
brings npm pkg from 0.75MB to 0.45MB

after yarn autoclean --force, down to 0.25MB

from this PR: sindresorhus#284

next big savings is removing progress, from sindresorhus#322
  • Loading branch information
jotto committed Nov 30, 2017
1 parent dce4725 commit 0ee0490
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 112 deletions.
57 changes: 57 additions & 0 deletions cacheable-request-stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const EventEmitter = require('events');

class CacheableRequest {
constructor(request, cacheAdapter) {
if (typeof request !== 'function') {
throw new TypeError('Parameter `request` must be a function');
}

return this.createCacheableRequest(request);
}

createCacheableRequest(request) {
return (opts, cb) => {
const ee = new EventEmitter();

const makeRequest = opts => {
const handler = response => {
ee.emit('response', response);
if (typeof cb === 'function') {
cb(response);
}
};

try {
const req = request(opts, handler);
ee.emit('request', req);
} catch (err) {
ee.emit('error', new CacheableRequest.RequestError(err));
}
};

process.nextTick(() => makeRequest(opts))

return ee;
};
}
}

CacheableRequest.RequestError = class extends Error {
constructor(err) {
super(err.message);
this.name = 'RequestError';
Object.assign(this, err);
}
};

CacheableRequest.CacheError = class extends Error {
constructor(err) {
super(err.message);
this.name = 'CacheError';
Object.assign(this, err);
}
};

module.exports = CacheableRequest;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Transform = require('stream').Transform;
const urlLib = require('url');
const fs = require('fs');
const querystring = require('querystring');
const CacheableRequest = require('cacheable-request');
const CacheableRequest = require('./cacheable-request-stub');
const duplexer3 = require('duplexer3');
const intoStream = require('into-stream');
const is = require('@sindresorhus/is');
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "got",
"version": "8.0.0",
"name": "got-lite",
"version": "8.0.1",
"description": "Simplified HTTP requests",
"license": "MIT",
"repository": "sindresorhus/got",
Expand Down Expand Up @@ -29,7 +29,8 @@
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"files": [
"index.js"
"index.js",
"cacheable-request-stub.js"
],
"keywords": [
"http",
Expand All @@ -51,7 +52,6 @@
],
"dependencies": {
"@sindresorhus/is": "^0.6.0",
"cacheable-request": "^2.1.1",
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4",
"get-stream": "^3.0.0",
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## This is a fork of got that reduces npm package size

This fork removes cacheable-request, introduced in https://github.com/sindresorhus/got/pull/284 bringing the npm package from 0.75MB to 0.45MB.

Run `yarn autoclean --init && yarn autoclean --force` to bring it down even more to 0.25MB

The use case is Lambda@Edge or other environments where code size is important

<h1 align="center">
<br>
<img width="360" src="https://rawgit.com/sindresorhus/got/master/media/logo.svg" alt="got">
Expand Down
107 changes: 0 additions & 107 deletions test/cache.js

This file was deleted.

0 comments on commit 0ee0490

Please sign in to comment.