Skip to content

feat: support usage of globs in cli mode#434

Closed
thepassle wants to merge 3 commits intoparcel-bundler:masterfrom
thepassle:feat/cli-globs
Closed

feat: support usage of globs in cli mode#434
thepassle wants to merge 3 commits intoparcel-bundler:masterfrom
thepassle:feat/cli-globs

Conversation

@thepassle
Copy link

@thepassle thepassle commented Feb 22, 2023

EDIT: I seemed to have fixed the issue 🙂 The PR can be reviewed now

image
🎉

this PR isnt quite finished, it seems to be almost working, but I'm running into one issue that I cant quite figure out, I was hoping you could give me some pointers on that one, @devongovett ?

The issue is the following:

error[E0308]: `if` and `else` have incompatible types
   --> src/main.rs:252:11
    |
249 |           let css_modules_filename = if let Some(name) = css_modules {
    |  ____________________________________-
250 | |           name
    | |           ---- expected because of this
251 | |         } else {
252 | |           infer_css_modules_filename(&output_file)?
    | |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |           |
    | |           expected `&std::string::String`, found struct `std::string::String`
    | |           help: consider borrowing here: `&infer_css_modules_filename(&output_file)?`
253 | |         };
    | |_________- `if` and `else` have incompatible types

For more information about this error, try `rustc --explain E0308`.
error: could not compile `lightningcss` due to previous error

fixes #90

match glob(g) {
Ok(file_paths) => {
for file in file_paths {
if let Ok(f) = file {
Copy link
Author

@thepassle thepassle Feb 22, 2023

Choose a reason for hiding this comment

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

I was also wondering if you could give me some pointers on this code, there's quite a bit of nested pattern matching going on, is there a cleaner/more idiomatic way to approach this? Or is this considered fine?

Copy link
Member

Choose a reason for hiding this comment

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

One question I have is if we need to expand globs ourselves here or not? Usually the shell (e.g. bash) will expand globs before executing the program, so the glob itself will never reach it, it'll just be a list of files.

Copy link
Author

Choose a reason for hiding this comment

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

During development I used the following command to run the cli:

⚡ cargo run --features="cli" "*.css"
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s
     Running `target/debug/lightningcss '*.css'`
html {
  color: red;
}

body {
  background: green;
}

Having the quotes around the glob does seem needed, if you provide the glob without quotes, it does indeed get expanded by the shell, and result in the following:

⚡ cargo run --features="cli" *.css
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/lightningcss test.css test2.css`
error: Found argument 'test2.css' which wasn't expected, or isn't valid in this context

USAGE:
    lightningcss [OPTIONS] [INPUT_FILE]

For more information try --help

@devongovett
Copy link
Member

Hey sorry it took so long for me to get back to you on this. I think we will need to change a few things.

At the moment, this will take only glob literal, which you need to quote to prevent your shell from expanding them. It would be nice if you could do lightningcss a.css b.css too. Then we wouldn't need to implement globs ourselves either, because lightningcss *.css would be expanded by your shell into multiple files and we get glob support for free.

In addition, at the moment this will compile each file, but then output them all concatenated together to stdout. If you use the -o option to output to a file, they will overwrite each other so only the last one is output. We'll need a way to somehow output each file with a different filename, perhaps by specifying a directory and preserving the filename of each input file.

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.

Support multiple files with CLI

2 participants