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 more dir api for Deno #3491

Merged
merged 15 commits into from
Dec 15, 2019
Merged

Add more dir api for Deno #3491

merged 15 commits into from
Dec 15, 2019

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Dec 12, 2019

close #3488

depend on https://crates.io/crates/dirs

  • Deno.cacheDir()
  • Deno.configDir()
  • Deno.dataDir()
  • Deno.dataLocalDir()
  • Deno.audioDir()
  • Deno.desktopDir()
  • Deno.documentDir()
  • Deno.downloadDir()
  • Deno.fontDir()
  • Deno.pictureDir()
  • Deno.publicDir()
  • Deno.templateDir()
  • Deno.videoDir()

If the directory does not exist, an exception is thrown

E.g. Deno.downloadDir()

Not every Linux has a download directory

TODO:

  • test case

cli/js/os.ts Outdated Show resolved Hide resolved
@axetroy
Copy link
Contributor Author

axetroy commented Dec 14, 2019

/cc @ry it's ready for review

cli/ops/os.rs Outdated Show resolved Hide resolved
cli/ops/os.rs Outdated
"public" => dirs::public_dir(),
"template" => dirs::template_dir(),
"video" => dirs::video_dir(),
_ => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this case tested?

Copy link
Contributor Author

@axetroy axetroy Dec 14, 2019

Choose a reason for hiding this comment

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

No test cases needed here.

I change this to panic when not match.

So if not match the case, an exception will be thrown and the CI won't pass

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be tested to confirm it returns an error (not panics)

Copy link
Contributor Author

@axetroy axetroy Dec 15, 2019

Choose a reason for hiding this comment

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

Now it returns an error

But I'm not sure where this test case should be written

Maybe cli/js/os_test.ts or cli/js/dispatch_json.ts?

@ry
Copy link
Member

ry commented Dec 14, 2019

I think it’s better not to panic - because users can still trigger that by calling the op directly. Better to return Err(...)

I’m not at my computer to give a good example but you should be able to look through the other ops and find an example of returning an error.

cli/js/os.ts Outdated
const path = sendSync(dispatch.OP_GET_DIR, { name: "cache" });
if (!path) {
throw new Error("Could not get user cache directory.");
}
Copy link
Member

Choose a reason for hiding this comment

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

All of these places where you throw new Error can be removed if you return the error from the op.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@axetroy
Copy link
Contributor Author

axetroy commented Dec 15, 2019

@ry
I don't think OP should be open for users
This should only be allowed to be called inside Deno

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@ry ry merged commit de94698 into denoland:master Dec 15, 2019
bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Dec 28, 2019
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.

want: more dir api for system
4 participants