-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 CLI defaults for input and output directory #7966
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! looks good to me so far 👍
I saw on some projects that I think the rules should be: if directory x exists pick another one. Note that the build destination directories are usually not committed and thus not exisinting. |
That's a good point about I don't think the rule you're proposing will work either though. The first time I build Maybe we should just use the path from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. I think this is a great start, but there are definitely concerns I have.
|
||
outDirOptions.some(function(outDir) { | ||
if (fs.existsSync(outDir)) { | ||
return outDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return isn't going to do what you want because it is inside of the .some
callback, not inside getOutDir
.
const packageJson = JSON.parse(fs.readFileSync("package.json")); | ||
|
||
if (packageJson && packageJson.main) { | ||
return path.dirname(packageJson.main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's valid for a package.json#main
to actually be a folder, so this will have issues, I'd suggest that we do
const basedir = process.cwd();
const filepath = require.resolve(path.resolve(basedir, packageJson.main));
return path.dirname(filepath);
so that we resolve the specific file first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we may want to skip here if the dirname that is returned is the root of the package and not a subfolder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this second comment are you saying if dirname
is the same as the basepath
then we should just default to something like lib
or dist
(instead of writing the output to the root of the package)?
@@ -124,6 +125,7 @@ commander.option( | |||
commander.option( | |||
"-d, --out-dir [out]", | |||
"Compile an input directory of modules into an output directory", | |||
getOutDir(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to break the check at https://github.com/iansu/babel/blob/3ec44323aa3477de09dc5b836a0f7233fc6b2967/packages/babel-cli/src/babel/index.js#L9 because there will always be a dir. We should invert that so that if the user specifies --out-file
, it uses the file approach.
This is going to break Babel's ability to write to stdout:
process.stdout.write(result.code + "\n"); |
--out-file -
to say "output to stdout".
@@ -152,6 +154,10 @@ export default function parseArgv(args: Array<string>) { | |||
|
|||
const errors = []; | |||
|
|||
if (commander.args.length === 0) { | |||
commander.args.push("src"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to break
babel/packages/babel-cli/src/babel/file.js
Line 228 in 6b91d64
await stdin(); |
babel - ...
where the -
in place of a filename means it will read from stdin.
} | ||
} | ||
|
||
outDirOptions.some(function(outDir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think skipping the lib
and dist
and only using package.json
might be reasonable, given the concern about lib
, but it definitely has risks either way.
@loganfsmyth Thanks for the review. I will try to address those comments as well as some of the previous discussion later today. The stdin/stdout thing is definitely an issue. That's why a bunch of tests are currently failing. Using |
Using // index.js
module.exports = require('esm')(module)('./lib') +1 for @loganfsmyth's suggestion of skipping |
@iansu Any update on this? |
Yes! I made the suggested changes but haven't had a chance to test them yet. It kind of fell off my radar. Thanks for the reminder. I will try to push an update soon. |
@iansu Let me know if I can lend a hand. Still looking for my first contribution to babel. |
When running
babel
with no arguments input directory will default tosrc
and output directory will default to:main
field inpackage.json
lib
if it existsdist
if it existslib
Work in progress. To do: