Skip to content

Commit

Permalink
fix: projectLocation should be set correctly. (#189)
Browse files Browse the repository at this point in the history
* If a projectLocation was overriden, it was not being used when checking for the files it should be loading.  The archive creator was also not paying attention to the projectLocation property.

fixes #188
  • Loading branch information
lholmquist committed Feb 13, 2018
1 parent e123bfb commit 4e061a9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/docker-archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ async function createArchive (config) {
// Look to see if any files are specified in the package.json
if (config.projectPackage.files && config.projectPackage.files.length > 0) {
// Removes all nonexistent files and use that list
const normalizedFileList = helpers.normalizeFileList(config.projectPackage.files);
// make sure we send in the projectLocation in case the user isn't in the CWD
const normalizedFileList = helpers.normalizeFileList(config.projectPackage.files, config.projectLocation);
if (normalizedFileList.nonexistent.length > 0) {
logger.warning(`The following files do not exist: ${normalizedFileList.nonexistent}`);
}
Expand All @@ -45,7 +46,8 @@ async function createArchive (config) {
logger.info(`creating archive of ${includedFiles.join(', ')}`);
await helpers.createDir(`${config.projectLocation}/${DEFAULT_BUILD_LOCATION}`);
return tar.create({
file: `${DEFAULT_BUILD_LOCATION}/archive.tar`
cwd: config.projectLocation, // Don't forget to be in the projectLocation
file: `${config.projectLocation}/${DEFAULT_BUILD_LOCATION}/archive.tar`
}, includedFiles);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ function yamlToJson (yamlToParse) {
return jsyaml.safeLoad(yamlToParse);
}

function normalizeFileList (fileList) {
function normalizeFileList (fileList, projectLocation) {
const result = {
existing: [],
nonexistent: []
};
fileList.forEach((file) => {
if (fs.existsSync(file)) {
if (fs.existsSync(`${projectLocation}/${file}`)) {
result.existing.push(file);
} else {
result.nonexistent.push(file);
Expand Down
40 changes: 40 additions & 0 deletions test/docker-archiver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,43 @@ test('test logger no warning', (t) => {
t.end();
});
});

test('change in project location', (t) => {
const config = {
projectLocation: '/this/is/a/dir',
projectPackage: {
files: ['file1', 'file2']
}
};

const dockerArchiver = proxyquire('../lib/docker-archiver', {
'./helpers': {
createDir: () => {
return Promise.resolve();
},
cleanUp: () => {
return Promise.resolve();
},
normalizeFileList: (files, projectLocation) => {
t.equal(projectLocation, config.projectLocation, 'projectLocation should be here');
console.log(projectLocation);
return {
nonexistent: [],
existing: ['file3']
};
}
},
tar: {
create: (options) => {
t.equal(options.cwd, config.projectLocation, 'project location should be here');
t.equal(options.file, '/this/is/a/dir/tmp/nodeshift/build/archive.tar', 'project location should be on the path');
return Promise.resolve();
}
}
});

dockerArchiver.archiveAndTar(config).then(() => {
t.pass('should cleanup stuff');
t.end();
});
});
2 changes: 1 addition & 1 deletion test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('checks existing and nonexistent files', (t) => {
t.plan(2);
const fileList = require('../package.json').files;
fileList.push('bar');
const result = helpers.normalizeFileList(fileList);
const result = helpers.normalizeFileList(fileList, process.cwd());
t.deepEqual(result.existing, [ 'package.json', 'README.md', 'LICENSE', 'index.js', 'lib', 'bin' ], `existing files: ${result.existing}`);
t.deepEqual(result.nonexistent, ['example.js', 'bar'], 'example.js and bar do not exist.');
t.end();
Expand Down

0 comments on commit 4e061a9

Please sign in to comment.