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 support for packages to nickel-lang-core #2094

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jneem
Copy link
Member

@jneem jneem commented Nov 15, 2024

These are the changes to the core crate, picked out from the npm branch.

Essentially, this enables the import pkg syntax, and introduces PackageMap 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.

///
/// 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 {
Copy link
Member Author

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.

Copy link
Contributor

@jneem jneem requested a review from yannham November 15, 2024 04:47
/// A table mapping FileIds to the package that they belong to.
///
/// Path dependencies have already been canonicalized to absolute paths.
package: HashMap<FileId, PathBuf>,
Copy link
Member

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> {
Copy link
Member

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),
Copy link
Member

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?

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.

2 participants