Skip to content

Commit

Permalink
feat: support uncompressing symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Jul 26, 2019
1 parent 7d605fe commit 083a415
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ npm-debug.log*
coverage
.vscode
test/fixtures/types/*.js
yarn.lock
yarn.lock
!test/fixtures/symlink/node_modules
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ node_js:
- '6'
- '8'
- '10'
- '11'
- '12'
before_install:
- npm i npminstall -g
install:
- npm i npminstall && npminstall
- npminstall
script:
- npm run ci
after_script:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ environment:
- nodejs_version: '6'
- nodejs_version: '8'
- nodejs_version: '10'
- nodejs_version: '11'
- nodejs_version: '12'

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
8 changes: 8 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ exports.makeUncompressFn = StreamClass => {
done();
});
});
} else if (header.type === 'symlink') {
// symlink
const src = path.join(destDir, header.name);
const target = path.resolve(path.dirname(src), header.linkname);
fs.symlink(target, src, err => {
if (err) return reject(err);
stream.resume();
});
} else { // directory
mkdirp(path.join(destDir, header.name), err => {
if (err) return reject(err);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"node": ">= 4.0.0"
},
"ci": {
"version": "4, 6, 8, 10, 11",
"version": "4, 6, 8, 10, 12",
"license": {
"year": "2017",
"fullname": "node-modules and other contributors"
Expand Down
Binary file added test/fixtures/symlink.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/symlink/README.md
1 change: 1 addition & 0 deletions test/fixtures/symlink/cli
30 changes: 30 additions & 0 deletions test/fixtures/symlink/node_modules/_enums@1.0.3@enums/History.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/fixtures/symlink/node_modules/_enums@1.0.3@enums/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions test/fixtures/symlink/node_modules/_enums@1.0.3@enums/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions test/fixtures/symlink/node_modules/_enums@1.0.3@enums/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/symlink/node_modules/cli

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/symlink/node_modules/enums

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions test/tgz/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ describe('test/tgz/index.test.js', () => {
assert(originStat.mode === destStat.mode);
});

it.only('tgz.uncompress(sourceFile, destDir) with symlink', function* () {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'symlink.tgz');
const destDir = path.join(os.tmpdir(), uuid.v4());
const originalDir = path.join(__dirname, '..', 'fixtures', 'symlink');
yield compressing.tgz.uncompress(sourceFile, destDir);
console.log(destDir);

assert(fs.lstatSync(path.join(destDir, 'README.md')).isSymbolicLink());
assert(fs.lstatSync(path.join(destDir, 'cli')).isSymbolicLink());
assert(fs.lstatSync(path.join(destDir, 'node_modules/enums')).isSymbolicLink());
assert(fs.readFileSync(path.join(destDir, 'README.md'), 'utf-8').includes('Usage'));

const res = dircompare.compareSync(originalDir, destDir);
assert(res.distinct === 0);

const destStat = fs.lstatSync(path.join(destDir, 'cli'));
const originStat = fs.lstatSync(path.join(originalDir, 'cli'));
const format = stats => '0' + (stats.mode & parseInt('777', 8)).toString(8);
console.log(format(destStat), format(originStat));
assert(originStat.mode === destStat.mode);
});

it('tgz.uncompress(sourceStream, destDir)', function* () {
const sourceStream = fs.createReadStream(path.join(__dirname, '..', 'fixtures', 'xxx.tgz'));
const destDir = path.join(os.tmpdir(), uuid.v4());
Expand Down

0 comments on commit 083a415

Please sign in to comment.