-
-
Save isaacs/0843fbfe907f39e081e48079c641869f to your computer and use it in GitHub Desktop.
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
$ tar cvf x.tar package | |
a package | |
a package/.gitignore | |
$ node rename.js | |
entry package/ | |
extracting package/ | |
entry package/.gitignore | |
renaming package/.gitignore to package/.npmignore | |
extracting package/.npmignore | |
$ tree output/ | |
output/ | |
└── .npmignore | |
0 directories, 1 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
'use strict' | |
const tar = require('./') | |
const file = 'x.tar' | |
const mkdirp = require('mkdirp') | |
const path = require('path') | |
const rimraf = require('rimraf') | |
rimraf.sync('output') | |
mkdirp.sync('output') | |
const sawIgnores = new Set() | |
tar.x({ | |
file: file, | |
cwd: 'output', | |
strip: 1, | |
onentry: entry => { | |
console.error('entry', entry.path) | |
// Note: This mirrors logic in the fs read operations that are | |
// employed during tarball creation, in the fstream-npm module. | |
// It is duplicated here to handle tarballs that are created | |
// using other means, such as system tar or git archive. | |
if (entry.type.toLowerCase() === 'file') { | |
const base = path.basename(entry.path) | |
if (base === '.npmignore') { | |
sawIgnores.add(entry.path) | |
} else if (base === '.gitignore') { | |
const npmignore = entry.path.replace(/\.gitignore$/, '.npmignore') | |
if (!sawIgnores.has(npmignore)) { | |
// Rename, may be clobbered later. | |
console.log('renaming', entry.path, 'to', npmignore) | |
entry.path = npmignore | |
} | |
} | |
} | |
console.log('extracting', entry.path) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment