Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overwrite protection to parent directory #358

Merged
merged 4 commits into from
Mar 31, 2018

Conversation

oligriffiths
Copy link
Contributor

@oligriffiths oligriffiths commented Mar 20, 2018

This PR ensures that if using the --overwrite option and target is a parent directory of the project, the process will exit(1).
This is inline with ember-cli.
Also adds some more tests for --overwrite option.

Question, why do we even allow the target directory to be a literal parent of the project, I don't really see why you would want that?

@oligriffiths
Copy link
Contributor Author

hmm, tests failing but not locally

@oligriffiths oligriffiths force-pushed the oli/parent-output-path branch 2 times, most recently from 00a816e to 50db293 Compare March 20, 2018 03:34
@oligriffiths
Copy link
Contributor Author

@rwjblue do you know of any reason to allow [target] to be a direct parent directory to the build file?

test/cli_test.js Outdated
@@ -36,6 +36,9 @@ describe('cli', function() {
});

describe('build', function() {
beforeEach(function() {
rimraf.sync('dist');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generally not have to cleanup both before and after like this. Having to cleanup before generally indicates some other test is leaving us in an invalid starting state...

@oligriffiths
Copy link
Contributor Author

I think I found the problem.
Was talking with Toby, but it seems that when mocking process.exit(), statements after the exit line are run in unit tests because the process does NOT exit and continues to run. With no return statement this means a build can run when an error is produced. I will whip up a quick test of this theory but this is what I’m seeing in existing tests.

lib/cli.js Outdated
);
process.exit(1);
}
}

function isParentDirectory(outputPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can use findup-sync to detect project root by locating package.json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check

@oligriffiths oligriffiths force-pushed the oli/parent-output-path branch from b8d799e to 80efdec Compare March 31, 2018 02:55
function guardOutputDir(outputDir, removeExisting) {
if (fs.existsSync(outputDir)) {
if (removeExisting) {
rimraf.sync(outputDir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing rimraf as broccoli already handles doing a diff of the output directory and the new files to be added/removed, so rimraf actually makes it less efficient. https://github.com/broccolijs/broccoli/blob/master/lib/cli.js#L104

@oligriffiths
Copy link
Contributor Author

@rwjblue @chrmod updated, tests passing.

@rwjblue
Copy link
Member

rwjblue commented Mar 31, 2018

Good work, thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants