Giter VIP home page Giter VIP logo

dem's Introduction

dem

Build Status

  • A simple module version manager for Deno.
  • dem creates dem.json and links script files with version.
    • linked scripts are stored in vendor directory.
  • dem provides an easy way to update dependencies.

Example

Using https://deno.land/std/http/server.ts at v0.51.0

  • dem.json
    • generated file like a package.json
{
  "modules": [
    {
      "protocol": "https",
      "path": "deno.land/std",
      "version": "v0.51.0",
      "files": [
        "/http/server.ts"
      ]
    }
  ]
}
  • vendor/https/deno.land/std/http/server.ts
    • generated linked script includes version specified in dem.json
export * from "https://deno.land/[email protected]/http/server.ts";
  • example.ts
    • script to run
// You can import module without the version.
import { serve } from "./vendor/https/deno.land/std/http/server.ts";

Install

deno install --allow-read --allow-write --allow-net -f -n dem https://deno.land/x/[email protected]/cmd.ts

Usage

Getting Started

1. dem init to create dem.json

$ dem init
successfully initialized the project.

2. dem add to add module.

$ dem add https://deno.land/[email protected]
successfully added new module: https://deno.land/std, version: v0.51.0

3. Edit your script and import module from vendor.

example.ts

import * as path from './vendor/https/deno.land/std/fs/path.ts';

console.log(path.join(Deno.cwd(), 'example'));

4. dem ensure to resolve modules.

$ dem ensure
successfully created link: https://deno.land/[email protected]/fs/path.ts

5. Run your script.

$ deno example.ts

Standard Usage

Updating module

  • dem update updates versions in dem.json and linked scripts.
$ dem update https://deno.land/[email protected]
successfully updated module: https://deno.land/std, version: v0.52.0

Advanced Usage

Alias

  • With alias, shortened script paths are available.

example.ts

// Original
import * as dejs from "./vendor/https/deno.land/x/dejs/mod.ts"
// With alias
import * as dejs from "./vendor/dejs.ts"

How to use alias

  1. execute dem alias.
# create alias for module.
$ dem alias https://deno.land/x/dejs/mod.ts dejs.ts # ./vendor/dejs.ts will be created.
  1. import script using alias path
import * as dejs from "./vendor/dejs.ts"
  1. run dem ensure.
# create link for `./vendor/https/deno.land/x/dejs/mod.ts`.
$ dem ensure

Commands

dem init                                          # initialize dem.json
dem add https://deno.land/x/[email protected]            # add module `dejs` and set its version to `0.1.0`
dem link https://deno.land/x/dejs/mod.ts          # create link of `[email protected]/mod.ts` and put it into vendor.
dem update https://deno.land/x/[email protected]         # update module to `0.2.0`
dem unlink https://deno.land/x/dejs/mod.ts        # remove link of `[email protected]/mod.ts`.
dem remove https://deno.land/x/dejs               # remove module `dejs`
dem ensure                                        # resolve file paths of added modules used in project and link them.
dem prune                                         # remove unused modules and linked scripts.
dem alias https://deno.land/x/dejs/mod.ts dejs.ts # create alias for module and put it into vendor.
dem unalias dejs.ts                               # remove alias for module.

Unsupported features

  • default export
  • manage .d.ts file

Author

syumai

License

MIT

dem's People

Contributors

michael-spengler avatar syumai avatar uki00a avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dem's Issues

Problem with dem ensure

When i use dem ensure for this project and I started the code. I got Uncaught SyntaxError: The requested module './vendor/https/jspm.dev/typescript/lib/typescript.js' does not provide an export named 'default'

So I looked the code and the hasDefaultExport function return false even if a module a export default. I rewrite the code to get working but that's my first step with typescript and I think my code could be better.

Here is the full function

export function hasDefaultExport(body: string): boolean {
  const sourceFile = ts.createSourceFile("", body, ts.ScriptTarget.ES2020);
  let hasDefault = false;
  sourceFile.forEachChild((node: ts.Node) => {
    if(ts.isExportDeclaration(node)){
      const exportClause: ts.NamedExports = node.exportClause as ts.NamedExports;
      if(exportClause !== undefined){
        hasDefault = hasDefault || (exportClause.elements[0].name.escapedText as string === 'default');
      }
    }
  });
  return hasDefault;
}

dem add/ensure doesn't create anything in vendor/

Perhaps I am misunderstanding dem, but it seems dem add should be files in vendor? But I am not seeing this happening. Thus far, only dem alias does anything to vendor/ .

Using dem 0.9.9:

  1. dem init
    sucessfully initialized dem.json
  2. jq . dem.json
{
  "modules": [],
  "aliases": {}
}
  1. dem add https://deno.land/x/[email protected]
    successfully added new module: https://deno.land/x/dejs, version: 0.9.3
  2. jq .modules dem.json
[
  {
    "protocol": "https",
    "path": "deno.land/x/dejs",
    "version": "0.9.3",
    "files": []
  }
]

But, there is no vendor directory (if I create vendor/ beforehand, nothing is placed inside of it).

Support .d.ts

Patterns

  • Compiler hint
// @deno-types="./vendor/https/deno.land/std/foo/bar.d.ts"
import * as bar from "./bar.js";
  • Triple-slash reference in .js
/// <reference types="./vendor/https/deno.land/std/foo/bar.d.ts" />
export const bar = "bar";

Fix build

try non- esm.sh typescript module

Make easier to update TypeScript

  • This module is using old version of TypeScript to parse import section
    • This is used for dem ensure / dem prune
  • Add ability to patch TypeScript automatically.

Support alias

Not sure if something like this is already supported:

{
  "modules": [
    {
      "protocol": "https",
      "path": "deno.land/std",
      "version": "v0.51.0",
      "files": [
        "/http/server.ts"
      ],
      "alias": "server.ts"
    }
  ]
}
import { serve } from './vendor/server.ts"

dem update Error

PS C:> deno --version
deno 1.16.3 (release, x86_64-pc-windows-msvc)
v8 9.7.106.5
typescript 4.4.2
PS C:> dem version
dem: 0.9.9
PS C:> dem update
error: Uncaught (in promise) TypeError: Invalid URL
const u = new URL(name);
^
at Object.opSync (deno:core/01_core.js:142:12)
at opUrlParse (deno:ext/url/00_url.js:47:27)
at new URL (deno:ext/url/00_url.js:320:20)
at Function.parse (https://deno.land/x/[email protected]/module.ts:20:15)
at App.updateModule (https://deno.land/x/[email protected]/mod.ts:159:31)
at main (https://deno.land/x/[email protected]/cmd.ts:74:11)
PS C:>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.