Skip to content

Commit

Permalink
[FAB-9072] unconditionally ignore node_modules folder
Browse files Browse the repository at this point in the history
Change-Id: I3f25f9b3826b9f3ab914c1245428367643b5464c
Signed-off-by: zhaochy <zhaochy_2015@hotmail.com>
  • Loading branch information
zhaochy1990 committed Mar 24, 2018
1 parent 54488fe commit 763dc5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions fabric-client/lib/packager/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class NodePackager extends BasePackager {
files = [];
}

// ignore the node_modules folder by default
files = files.filter(f => f.indexOf('node_modules') !== 0);

files.forEach((entry) => {
let desc = {
name: path.join('src', entry).split('\\').join('/'), // for windows style paths
Expand Down
23 changes: 19 additions & 4 deletions test/unit/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ test('\n\n** Golang Packager tests **\n\n', function(t) {
});
});

const npmignore1 = '**/node_modules';
// ignore the dummy.js
const npmignore1 = 'dummy.js';
const destDir = path.join(testutil.getTempDir(), 'test-node-chaincode');
const tmpFile = path.join(testutil.getTempDir(), 'test-node-chaincode.tar.gz');
const targzDir = path.join(testutil.getTempDir(), 'test-node-chaincode-tar-gz');
Expand Down Expand Up @@ -189,11 +190,25 @@ test('\n\n** Node.js Packager tests **\n\n', function(t) {
fs.removeSync(destDir);
fs.copySync(testutil.NODE_CHAINCODE_PATH, destDir);

fs.outputFileSync(path.join(destDir, '.npmignore'), npmignore1);
fs.outputFileSync(path.join(destDir, 'node_modules/dummy/package.json'), 'dummy package.json content');
fs.outputFileSync(path.join(destDir, 'dummy.js'), 'this is the content of dummy.js');

return Packager.package(destDir, 'node', false);

}).then((data) => {
return check(data, () => {
let checkPath = path.join(targzDir, 'src', 'chaincode.js');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "src/chaincode.js" file');
checkPath = path.join(targzDir, 'src', 'package.json');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "src/package.json" file');
checkPath = path.join(targzDir, 'src', 'dummy.js');
t.equal(fs.existsSync(checkPath), true, 'dummy.js should exist this time, because we does not ignore it');
checkPath = path.join(targzDir, 'src', 'node_modules');
t.equal(fs.existsSync(checkPath), false, 'The tar.gz file produced by Packager.package() does not have the "node_modules" folder');
});
}).then(() => {
// ignore the dummy.js
fs.outputFileSync(path.join(destDir, '.npmignore'), npmignore1);
return Packager.package(destDir, 'node', false);
}).then((data) => {
return check(data, () => {
let checkPath = path.join(targzDir, 'src', 'chaincode.js');
Expand All @@ -217,7 +232,7 @@ test('\n\n** Node.js Packager tests **\n\n', function(t) {
checkPath = path.join(targzDir, 'src', 'some.other.file');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "src/some.other.file" file');
checkPath = path.join(targzDir, 'src', 'node_modules');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "node_modules" folder');
t.equal(fs.existsSync(checkPath), false, 'The tar.gz file produced by Packager.package() does not has the "node_modules" folder');
});
}).then(()=>{
return Packager.package(destDir, 'node', false, testutil.METADATA_PATH);
Expand Down

0 comments on commit 763dc5d

Please sign in to comment.