-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support high speed store for tarball download (#276)
- Loading branch information
Showing
11 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "high-speed-store", | ||
"devDependencies": { | ||
"@types/react": "15.0.4", | ||
"@types/react-dom": "0.14.18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const co = require('co'); | ||
const path = require('path'); | ||
const fs = require('mz/fs'); | ||
const mkdirp = require('mz-modules/mkdirp'); | ||
const utility = require('utility'); | ||
const urllib = require('urllib'); | ||
|
||
exports.getStream = function* (url) { | ||
const dir = path.join(__dirname, 'tmp'); | ||
yield mkdirp(dir); | ||
const file = path.join(dir, utility.md5(url) + path.extname(url)); | ||
if (yield fs.exists(file)) { | ||
return fs.createReadStream(file); | ||
} | ||
|
||
const writeStream = fs.createWriteStream(file); | ||
yield urllib.request(url, { | ||
writeStream, | ||
timeout: 10000, | ||
followRedirect: true, | ||
}); | ||
return fs.createReadStream(file); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const coffee = require('coffee'); | ||
const rimraf = require('rimraf'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
describe('test/high-speed-store.test.js', () => { | ||
const cwd = path.join(__dirname, 'fixtures', 'high-speed-store'); | ||
const storeScript = path.join(cwd, 'store.js'); | ||
const bin = path.join(__dirname, '../bin/install.js'); | ||
|
||
function cleanup() { | ||
rimraf.sync(path.join(cwd, 'node_modules')); | ||
rimraf.sync(path.join(cwd, 'tmp')); | ||
} | ||
|
||
beforeEach(cleanup); | ||
afterEach(cleanup); | ||
|
||
it('should get tarball stream from store', function* () { | ||
yield coffee.fork(bin, [ '-d', `--high-speed-store=${storeScript}` ], { cwd }) | ||
.debug() | ||
.expect('code', 0) | ||
.expect('stdout', /All packages installed/) | ||
.end(); | ||
const pkg = require(path.join(cwd, 'node_modules/@types/react-dom/node_modules/@types/react/package.json')); | ||
assert(pkg.version === '15.0.4'); | ||
assert(fs.readdirSync(path.join(cwd, 'tmp')).length === 2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters