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

feat(unstable): package manager #20517

Merged
merged 13 commits into from Sep 18, 2023
Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Sep 15, 2023

Note: Extremely experimental

As discussed in https://deno.com/blog/package-json-support#a-new-major-version and #17495 but making the specifiers non-Deno specific.

This PR adds an unstable built-in package manager to Deno, but it is currently not usable because the registry infrastructure hasn't been setup and it points to a non-existent url by default. The default registry url can be configured via the DENO_REGISTRY_URL environment variable.

Using and installing packages

Packages are referenced via semvered specifiers, which can be defined in an application or package's import map:

// deno.jsonc
{
  "imports": {
    "path": "jsr:@std/path@1"
  }
}

Next, use the specifier in a JavaScript or TypeScript file:

// main.ts
import * as path from "path";

console.log(path.join("folder", "main.json"));

Then it's as simple as:

$ deno run main.ts
folder/main.json

Inline specifiers

Of course, these specifiers can be directly used inline in the code, which is useful for single file scripts or when distributing code:

import { readInt } from "jsr:@std/io@1/read_int";
// ...etc...

Details

  1. There is no separate install command.
    • Packages are automatically updated based on what's in the code. This works similarly to Rust's cargo run.
    • There is no need to have to remember to run a separate install command on first run or when the dependencies are upgraded (a significant source of wasted time other ecosystems)
  2. These specifiers resolve to https: specifiers.
    • The underlying https: specifiers can be imported without duplication of a module.
    • Tooling to generate an import map that can then be used in browsers and other tooling will be added in the future.
    • All existing Deno tooling works well with these because everything is still https: specifiers under the hood.
  3. These specifiers are much faster on first run than https: specifiers because there is no waterfalling within a package and the module graph information is computed ahead of time and distributed by the registry.
  4. These specifiers are efficient because only the imported code is downloaded.

The specific details on how packages might be created and distributed will be outlined soon for further discussion before stabilization. Again, to emphasize, this is all unstable experimental work.

Ref #17475
Ref #17495 -- won't close that one until this is fully functional

@@ -61,7 +60,7 @@ itest!(bundle_jsximportsource_importmap_config {
itest!(jsx_not_checked {
args: "check check/jsx_not_checked/main.jsx",
output: "check/jsx_not_checked/main.out",
envs: env_vars_for_npm_tests_no_sync_download(),
envs: env_vars_for_npm_tests(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is some additional cleanup I forgot to do in #20504

output_lines.push(format!(
"<FOUND>{}</FOUND>",
colors::gray(annotate_whitespace(expected))
));
Copy link
Member Author

Choose a reason for hiding this comment

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

image

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

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +1 to +3
import value from "jsr:@denotest/deps/mod.ts";

console.log(value);
Copy link
Member

Choose a reason for hiding this comment

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

How are these files getting served?

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't part of the test registry which is in testdata/jsr/registry, so this is just a normal file in the testdata directory.

@lilnasy
Copy link

lilnasy commented Sep 15, 2023

What does jsr mean? Is it an acronym?

@roj1512
Copy link
Contributor

roj1512 commented Sep 16, 2023

image

use util::TestContextBuilder;

itest!(no_module_graph_run {
args: "run jsr/no_module_graph/main.ts",
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'm not requiring an --unstable flag here at the moment because this feature is currently not usable so it will error every time anyway.

@dsherret dsherret merged commit 0709c05 into denoland:main Sep 18, 2023
13 checks passed
@dsherret dsherret deleted the feat_jsr_specifiers branch September 18, 2023 14:46
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.

None yet

5 participants