A way to manage nodules for Deno

栏目: IT技术 · 发布时间: 4年前

内容简介:Package management for deno

Welcome to Trex :cat:‍:dragon:

A way to manage nodules for Deno

Package management for deno

A way to manage nodules for Deno

What is Trex?

is a Package management for deno similar to npm but maintaining the deno philosophy. packages are cached and only one import_map.json file is generated.

// import_map.json

{
    "imports":  {
	"http/":  "https://deno.land/std/http/"
    }
}

For more information about the import maps in deno import maps

Content

installation:

install from nest.land module registry

$  deno install -A --unstable https://x.nest.land/Trex@1.0.0-rc1/Trex.ts

note: You should have the last version 1.0.0 >= of deno for no errors.

or in your terminal you can write

$  deno install -A --unstable https://deno.land/x/trex/Trex.ts

we shorten the install command so it's not that long

The resources that Trex uses are:

  • --allow-net
  • --allow-read
  • --allow-write
  • --allow-run
  • --allow-env

you can give those permissions explicitly

update Trex using

$  deno install -f -A --unstable https://deno.land/x/trex/Trex.ts

or use:

$ Trex update

for versions 0.2.0 or higher.

check for the installation of the Trex tool writing in the terminal:

$  Trex --version

and the console should presente the Trex version.

for any help of the commands of Trex write:

$  Trex --help

for a better implementation of this tool you can use the tool Commands of deno Commands

How to use

in your command line write:

$ Trex install --map fs http fmt

note: you can use Trex i --map fs http fmt

--map installs packages from the standard library and those hosted at deno.land/x

install package from nest.land or a repository (click me)

Install a package hosted on nest.land

$ Trex install --nest opine@0.13.0

note: if you install a package using nest.land you must specify the version, example: $ Trex i --nest opine@0.13.0

Install a package from some repository

$ Trex install --pkg [user]/[repo or repo@tag]/[path/to/file] [packageName]

example:

$ Trex install --pkg oakserver/oak/mod.ts oak

this downloads oak directly from its repository

an import_map.json file will be created with the following.

{
  "imports": {
    "fs/": "https://deno.land/std/fs/",
    "http/": "https://deno.land/std/http/",
    "fmt/": "https://deno.land/std/fmt/"
  }
}

example.

create a test file

// server.ts
import { serve } from "http/server.ts";
import { green } from "fmt/colors.ts";

const server = serve({ port: 8000 });
console.log(green("http://localhost:8000/"));

for await (const req of server) {
  req.respond({ body: "Hello World\n" });
}

run in terminal

$ deno run --allow-net --importmap=import_map.json --unstable server.ts

note: it is important to use --importmap=import_map.json --unstable

using third party packages

example using oak

$ Trex i --map oak

in import_map.json

{
  "imports": {
    "fs/": "https://deno.land/std/fs/",
    "http/": "https://deno.land/std/http/",
    "fmt/": "https://deno.land/std/fmt/",
    "oak": "https://deno.land/x/oak/mod.ts"
  }
}

note: third party packages are added using mod.ts

in server.ts

// server.ts
import { Application } from "oak";

const app = new Application();

app.use((ctx) => {
  ctx.response.body = "Hello World!";
});

await app.listen({ port: 8000 });

run in terminal

$ deno run --allow-net --importmap=import_map.json --unstable server.ts

download packages from an import_map.json file.

$ Trex install

this downloads all the packages listed in the import_map.json similar to npm install

add custom package

in your command line write:

$ Trex --custom React=https://dev.jspm.io/react/index.js

in import_map.json

{
  "imports": {
    "fs/": "https://deno.land/std/fs/",
    "http/": "https://deno.land/std/http/",
    "fmt/": "https://deno.land/std/fmt/",
    "oak": "https://deno.land/x/oak/mod.ts",
    "React": "https://dev.jspm.io/react/index.js"
  }
}

install tools like velociraptor or Commands

list of tools you can install

in your command line write:

$ Trex getTool Commands

this will install the tool

note: If you are a linux/MacOs user you'll have to specificate the PATH manually when the tool gets installed the will appear in your terminal export PATH="/home/username/.deno/bin:$PATH"

delete a package

in your command line write:

$ Trex delete React

to remove a specific version from the cache and import_map.json, it only works with standard packages and those installed from deno.land/x

$ Trex delete fs@0.52.0

in import_map.json

{
  "imports": {
    "fs/": "https://deno.land/std/fs/",
    "http/": "https://deno.land/std/http/",
    "fmt/": "https://deno.land/std/fmt/",
    "oak": "https://deno.land/x/oak/mod.ts"
  }
}

The packages in the standard library or those installed from deno.land/x will be removed from the cache.

install another version of a package

write the name of the package more @<Version>

example:

$ Trex install --map fs@0.54.0

in import_map.json

{
  "imports": {
    "fs/": "https://deno.land/std@0.54.0/fs/"
  }
}

note: can be used with third party packages.

check the versions of dependencies using

$ Trex --deps

you should see something like that on the console.

// in import_map.json
{
  "imports": {
    "oak": "https://deno.land/x/oak@v4.0.0/mod.ts",
    "http/": "https://deno.land/std@0.51.0/http/"
  }
}
name module url version latest upToDate
oak oak " https://deno.land/x/oak@v4.0.0/mod.ts " "v4.0.0" "v5.0.0" false
http/ std " https://deno.land/std@0.54.0/http/ " "0.54.0" "0.54.0" true

thanks to Fzwael this functionality is based on your tool deno-check-updates

see pacakge dependency tree.

$ Trex treeDeps fs

you should see this in the terminal

local: C:\Users\trex\AppData\Local\deno\deps\https\deno.land\434fe4a7be02d187573484b382f4c1fec5b023d27d1dcf4f768f300799a073e0
type: TypeScript
compiled: C:\Users\trex\AppData\Local\deno\gen\https\deno.land\std\fs\mod.ts.js
map: C:\Users\trex\AppData\Local\deno\gen\https\deno.land\std\fs\mod.ts.js.map
deps:
https://deno.land/std/fs/mod.ts
  ├─┬ https://deno.land/std/fs/empty_dir.ts
  │ └─┬ https://deno.land/std/path/mod.ts
  │   ├── https://deno.land/std/path/_constants.ts
  │   ├─┬ https://deno.land/std/path/win32.ts
  │   │ ├── https://deno.land/std/path/_constants.ts
  │   │ ├─┬ https://deno.land/std/path/_util.ts
  │   │ │ └── https://deno.land/std/path/_constants.ts
  │   │ └── https://deno.land/std/_util/assert.ts
  │   ├─┬ https://deno.land/std/path/posix.ts
  │   │ ├── https://deno.land/std/path/_constants.ts
  │   │ └── https://deno.land/std/path/_util.ts
  │   ├─┬ https://deno.land/std/path/common.ts
  │   │ └─┬ https://deno.land/std/path/separator.ts
  │   │   └── https://deno.land/std/path/_constants.ts
  │   ├── https://deno.land/std/path/separator.ts
  │   ├── https://deno.land/std/path/_interface.ts
  │   └─┬ https://deno.land/std/path/glob.ts
  │     ├── https://deno.land/std/path/separator.ts
  │     ├─┬ https://deno.land/std/path/_globrex.ts
  │     │ └── https://deno.land/std/path/_constants.ts
  │     ├── https://deno.land/std/path/mod.ts
  │     └── https://deno.land/std/_util/assert.ts
  ├─┬ https://deno.land/std/fs/ensure_dir.ts
  │ └─┬ https://deno.land/std/fs/_util.ts
  │   └── https://deno.land/std/path/mod.ts
  ├─┬ https://deno.land/std/fs/ensure_file.ts
  │ ├── https://deno.land/std/path/mod.ts
  │ ├── https://deno.land/std/fs/ensure_dir.ts
  │ └── https://deno.land/std/fs/_util.ts
  ├─┬ https://deno.land/std/fs/ensure_link.ts
  │ ├── https://deno.land/std/path/mod.ts
  │ ├── https://deno.land/std/fs/ensure_dir.ts
  │ ├── https://deno.land/std/fs/exists.ts
  │ └── https://deno.land/std/fs/_util.ts
  ├─┬ https://deno.land/std/fs/ensure_symlink.ts
  │ ├── https://deno.land/std/path/mod.ts
  │ ├── https://deno.land/std/fs/ensure_dir.ts
  │ ├── https://deno.land/std/fs/exists.ts
  │ └── https://deno.land/std/fs/_util.ts
  ├── https://deno.land/std/fs/exists.ts
  ├─┬ https://deno.land/std/fs/expand_glob.ts
  │ ├── https://deno.land/std/path/mod.ts
  │ ├─┬ https://deno.land/std/fs/walk.ts
  │ │ ├── https://deno.land/std/_util/assert.ts
  │ │ └── https://deno.land/std/path/mod.ts
  │ └── https://deno.land/std/_util/assert.ts
  ├─┬ https://deno.land/std/fs/move.ts
  │ ├── https://deno.land/std/fs/exists.ts
  │ └── https://deno.land/std/fs/_util.ts
  ├─┬ https://deno.land/std/fs/copy.ts
  │ ├── https://deno.land/std/path/mod.ts
  │ ├── https://deno.land/std/fs/ensure_dir.ts
  │ ├── https://deno.land/std/fs/_util.ts
  │ └── https://deno.land/std/_util/assert.ts
  ├── https://deno.land/std/fs/read_file_str.ts
  ├── https://deno.land/std/fs/write_file_str.ts
  ├── https://deno.land/std/fs/read_json.ts
  ├── https://deno.land/std/fs/write_json.ts
  ├── https://deno.land/std/fs/walk.ts
  └── https://deno.land/std/fs/eol.ts

Integrity checking & lock files

Let's say your module depends on remote module . When you compile your module for the first time is retrieved, compiled and cached. It will remain this way until you run your module on a new machine (say in production) or reload the cache (through for example). But what happens if the content in the remote url is changed? This could lead to your production module running with different dependency code than your local module. Deno's solution to avoid this is to use integrity checking and lock files.

info from deno page

use:

$ Trex --lock file.ts

this generates a lock.json file.

if in input file you use import_map.json you can specify it.

$ Trex --lock --importmap file.ts

for more information this is the deno document

Contributing

contributions are welcome, create a pull request and send us your feature, first check the CONTRIBUTING GUIDELINES .

LICENSE MIT

A way to manage nodules for Deno

Trex is powered by

A way to manage nodules for Deno A way to manage nodules for Deno A way to manage nodules for Deno


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Compilers

Compilers

Alfred V. Aho、Monica S. Lam、Ravi Sethi、Jeffrey D. Ullman / Addison Wesley / 2006-9-10 / USD 186.80

This book provides the foundation for understanding the theory and pracitce of compilers. Revised and updated, it reflects the current state of compilation. Every chapter has been completely revised ......一起来看看 《Compilers》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具