-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `@lerna/get-packed` | ||
|
||
> Read contents of package tarball created by npm pack | ||
## Usage | ||
|
||
``` | ||
const getPacked = require('@lerna/get-packed'); | ||
// TODO: DEMONSTRATE API | ||
``` |
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,9 @@ | ||
"use strict"; | ||
|
||
const getPacked = require(".."); | ||
|
||
describe("@lerna/get-packed", () => { | ||
it("needs tests", () => { | ||
expect(getPacked).toBeDefined(); | ||
}); | ||
}); |
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,68 @@ | ||
"use strict"; | ||
|
||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const ssri = require("ssri"); | ||
const tar = require("tar"); | ||
|
||
module.exports = getPacked; | ||
|
||
function getPacked(pkg, tarFilePath) { | ||
const bundledWanted = new Set(pkg.bundleDependencies || pkg.bundledDependencies || []); | ||
const bundled = new Set(); | ||
const files = []; | ||
|
||
let totalEntries = 0; | ||
let totalEntrySize = 0; | ||
|
||
return tar | ||
.list({ | ||
file: tarFilePath, | ||
onentry(entry) { | ||
totalEntries += 1; | ||
totalEntrySize += entry.size; | ||
|
||
const p = entry.path; | ||
|
||
if (p.startsWith("package/node_modules/")) { | ||
const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1]; | ||
|
||
if (bundledWanted.has(name)) { | ||
bundled.add(name); | ||
} | ||
} else { | ||
files.push({ | ||
path: entry.path.replace(/^package\//, ""), | ||
size: entry.size, | ||
mode: entry.mode, | ||
}); | ||
} | ||
}, | ||
strip: 1, | ||
}) | ||
.then(() => | ||
Promise.all([ | ||
fs.stat(tarFilePath), | ||
ssri.fromStream(fs.createReadStream(tarFilePath), { | ||
algorithms: ["sha1", "sha512"], | ||
}), | ||
]) | ||
) | ||
.then(([{ size }, { sha1, sha512 }]) => { | ||
const shasum = sha1[0].hexDigest(); | ||
|
||
return { | ||
id: `${pkg.name}@${pkg.version}`, | ||
name: pkg.name, | ||
version: pkg.version, | ||
size, | ||
unpackedSize: totalEntrySize, | ||
shasum, | ||
integrity: ssri.parse(sha512[0]), | ||
filename: path.basename(tarFilePath), | ||
files, | ||
entryCount: totalEntries, | ||
bundled: Array.from(bundled), | ||
}; | ||
}); | ||
} |
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,33 @@ | ||
{ | ||
"name": "@lerna/get-packed", | ||
"version": "3.6.0", | ||
"description": "Read contents of package tarball created by npm pack", | ||
"keywords": [ | ||
"lerna", | ||
"npm", | ||
"pack", | ||
"tarball" | ||
], | ||
"author": "Daniel Stockman <[email protected]>", | ||
"homepage": "https://github.com/lerna/lerna/tree/master/utils/get-packed#readme", | ||
"license": "MIT", | ||
"main": "lib/get-packed.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/lerna/lerna.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^7.0.0", | ||
"ssri": "^6.0.1", | ||
"tar": "^4.4.8" | ||
} | ||
} |