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

How do I use my own import map while vendoring? #14576

Closed
jimisaacs opened this issue May 12, 2022 · 9 comments
Closed

How do I use my own import map while vendoring? #14576

jimisaacs opened this issue May 12, 2022 · 9 comments
Labels
duplicate a duplicate of another issue vendor related to the vendor subcommand

Comments

@jimisaacs
Copy link

As far as I can tell, there's only one import map allowed as input in every command.

Would if you could pass --import-map to deno vendor, so that the generated import map output is merged the one specified as input?

@jimisaacs
Copy link
Author

jimisaacs commented May 12, 2022

It would be nice if it did this, but also walked the input import map to still vendor remote modules specified in the input import map. Though the entries of the input import map remain unchanged, though still merged with the generated import map.

This means that if the input import map just so happened to specify every remote module it could, then the final generated import map would look the same as the source one.

@jimisaacs
Copy link
Author

jimisaacs commented May 12, 2022

I actually didn't try it until just now, I think this is what it does

Edit: See followup

@jimisaacs
Copy link
Author

jimisaacs commented May 12, 2022

I might have spoke too soon.

I have this import map at src/import_map.json:

{
  "imports": {
    "oak": "https://deno.land/x/[email protected]/mod.ts",
    "react": "https://esm.sh/react@18",
    "react-dom/server": "https://esm.sh/react-dom@18/server"
  }
}

and deno vendor main.ts --import_map=src/import_map.json generated this:

{
  "imports": {
    "https://cdn.esm.sh/": "./cdn.esm.sh/",
    "https://deno.land/": "./deno.land/",
    "https://esm.sh/": "./esm.sh/",
    "https://raw.githubusercontent.com/": "./raw.githubusercontent.com/"
  },
  "scopes": {
    "./cdn.esm.sh/": {
      "/v78/[email protected]/deno/react.js": "./cdn.esm.sh/v78/[email protected]/deno/react.js"
    },
    "./deno.land/": {
      "oak": "./deno.land/x/[email protected]/mod.ts"
    },
    "./esm.sh/": {
      "react": "./esm.sh/[email protected]",
      "react-dom/server": "./esm.sh/react-dom@18/server.js"
    }
  }
}

Then when I run:

deno run --allow-net --allow-read --import-map ./vendor/import_map.json --cached-only main.ts

I get:

...
error: Relative import path "oak" not prefixed with / or ./ or ../ and not in import map from ...
...

@jimisaacs
Copy link
Author

jimisaacs commented May 12, 2022

Ok, from the previous example, I would expect the generated import_map.json to look like this, which works:

{
  "imports": {
    "oak": "https://deno.land/x/[email protected]/mod.ts",
    "react": "https://esm.sh/react@18",
    "react-dom/server": "https://esm.sh/react-dom@18/server",
    "https://cdn.esm.sh/": "./cdn.esm.sh/",
    "https://deno.land/": "./deno.land/",
    "https://esm.sh/": "./esm.sh/",
    "https://raw.githubusercontent.com/": "./raw.githubusercontent.com/"
  },
  "scopes": {
    "./cdn.esm.sh/": {
      "/v78/[email protected]/deno/react.js": "./cdn.esm.sh/v78/[email protected]/deno/react.js"
    }
  }
}

This feels like it could be a pretty straight forward transformation to be honest. It just keeps the existing mappings from the source input map, and resolves and adds to it to keep it local, as if the value of those mappings were what are actually used in source.

@jimisaacs
Copy link
Author

Found #13697, so this feels like a dupe

@jimisaacs
Copy link
Author

jimisaacs commented May 12, 2022

Hmm, seems my last throught is broken with --no-remote, which seems odd. I guess it makes sense if it is determining whether to to continue based on the shape of the strings in the imports section, versus how they resolve with an import_map 🤔

@jimisaacs
Copy link
Author

still it's close, as I think it might just need to walk the vendor generated map to get a the value starting with the origin.

@jimisaacs
Copy link
Author

I ended up writing this for now:
https://github.com/jimisaacs/source_vendor_import_map_fix_up

@dsherret dsherret added duplicate a duplicate of another issue vendor related to the vendor subcommand labels Jun 8, 2022
@dsherret
Copy link
Member

dsherret commented Jun 8, 2022

This is essentially #13697. Follow there for updates.

@dsherret dsherret closed this as completed Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue vendor related to the vendor subcommand
Projects
None yet
Development

No branches or pull requests

2 participants