-
Notifications
You must be signed in to change notification settings - Fork 92
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 support for packages to nickel-lang-core #2094
base: master
Are you sure you want to change the base?
Conversation
/// | ||
/// Like [`normalize_abs_path`], this works only on the path itself | ||
/// (i.e. not the filesystem) and does not follow symlinks. | ||
pub fn normalize_rel_path(path: &Path) -> PathBuf { |
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 needed this utility function in the upcoming nickel_lang_package
crate. Putting it next to normalize_abs_path
seemed reasonable, but it doesn't actually need to be in this crate.
Bencher Report
Click to view all benchmark results
|
/// A table mapping FileIds to the package that they belong to. | ||
/// | ||
/// Path dependencies have already been canonicalized to absolute paths. | ||
package: HashMap<FileId, PathBuf>, |
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.
Nitpick: what about packages
or package_map
? A singular package
being a HashMap<_, _>
is a tad surprising IMHO
/// A path or a package, like the name says. | ||
/// | ||
/// Paths come with a choice of import formats. Packages are always in nickel format, for now. | ||
pub enum PathOrPackage<'a> { |
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.
Nitpick: maybe we can find a more abstract/generic name? One day if we allow for bare URLs for example? (probably won't, but let's imagine). Maybe ImportLoc
, ImportSpec
, AbstractLoc
, ImportPath
, or something better.
@@ -209,6 +209,9 @@ pub enum Term { | |||
#[serde(skip)] | |||
Import { path: OsString, format: InputFormat }, | |||
|
|||
#[serde(skip)] | |||
ImportPkg(Ident), |
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.
Although we are getting rid of Term
, adding a new variant impacts quite a few places with pattern matching where we don't care about imports. Should we just rename PathOrPackage
to something like Import
, taking an owned OsString
, and use that type as the parameter of Term::Import
? After all the'yre all imports. What do you think?
These are the changes to the core crate, picked out from the
npm
branch.Essentially, this enables the
import pkg
syntax, and introducesPackageMap
for figuring out how to interpret those import statements.It also includes deserialization support for enum variants, because I ran into that while working on manifest files. That's unrelated to most of the changes here, so I could break it out as a separate PR if you want.