├── 01-deno-node-compat-app ├── deno.lock ├── main.ts ├── README.md └── package.json ├── 02-deno-canonical-app ├── deno.lock ├── main.ts ├── deno.json └── README.md └── 03-deno-lib ├── mod.test.ts ├── deno.json ├── mod.ts ├── scripts └── build_npm.ts └── .github └── workflows └── ci.yml /01-deno-node-compat-app/deno.lock: -------------------------------------------------------------------------------- 1 | { 2 | "etc": "..." 3 | } 4 | -------------------------------------------------------------------------------- /02-deno-canonical-app/deno.lock: -------------------------------------------------------------------------------- 1 | { 2 | "etc": "..." 3 | } 4 | -------------------------------------------------------------------------------- /03-deno-lib/mod.test.ts: -------------------------------------------------------------------------------- 1 | import { getMessage } from "./mod.ts"; 2 | 3 | Deno.test("gets message", () => { 4 | // etc.. 5 | }); -------------------------------------------------------------------------------- /02-deno-canonical-app/main.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import cowsay from "cowsay"; 3 | import $ from "dax"; 4 | 5 | const data = await $`echo hello`.text(); 6 | const message = cowsay.getMessage(data); 7 | 8 | console.log(chalk.green(message)); -------------------------------------------------------------------------------- /01-deno-node-compat-app/main.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import cowsay from "cowsay"; 3 | import $ from "dax"; 4 | 5 | const data = await $`echo hello`.text(); 6 | const message = cowsay.getMessage(data); 7 | 8 | console.log(chalk.green(message)); 9 | -------------------------------------------------------------------------------- /02-deno-canonical-app/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "main": "deno run -A main.ts" 4 | }, 5 | "imports": { 6 | "cowsay": "npm:cowsay@^1.0", 7 | "chalk": "npm:chalk@^1.0", 8 | "dax": "deno:dax@^23.0/mod.ts" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /03-deno-lib/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "build:npm": "deno run -A ./scripts/build_npm.ts" 4 | }, 5 | "imports": { 6 | "chalk": "npm:chalk@^1.0", 7 | "cowsay": "npm:chalk@^1.0", 8 | "dax": "deno:dax@~0.23/mod.ts" 9 | } 10 | } -------------------------------------------------------------------------------- /01-deno-node-compat-app/README.md: -------------------------------------------------------------------------------- 1 | 1. package.json specifies dependencies, which can be imported from npm or deno.land/x 2 | 1. "type": "module" is necessary 3 | 1. Lockfile used is deno.lock 4 | 1. `deno task` reads from deno.json first, then falls back to package.json. -------------------------------------------------------------------------------- /03-deno-lib/mod.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import cowsay from "cowsay"; 3 | import $ from "dax"; 4 | 5 | export async function getMessage() { 6 | const data = await $`echo hello`.text(); 7 | const message = cowsay.getSay(data); 8 | 9 | return chalk.green(message); 10 | } 11 | -------------------------------------------------------------------------------- /02-deno-canonical-app/README.md: -------------------------------------------------------------------------------- 1 | 1. deno.json supports the import map keys. 2 | - We suppress the extraneous import map diagnostic message. 3 | 1. Can specify an npm package via npm specifiers or deno.land/x package via deno specifiers. 4 | 1. Lockfile used is deno.lock 5 | 1. main.ts is identical in this 6 | -------------------------------------------------------------------------------- /01-deno-node-compat-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "01-deno-app", 3 | "version": "1.0.0", 4 | "description": "", 5 | "type": "module", 6 | "author": "", 7 | "license": "MIT", 8 | "scripts": { 9 | "main": "deno run -A main.ts" 10 | }, 11 | "dependencies": { 12 | "cowsay": "^1.0", 13 | "chalk": "npm:chalk@^1.0", 14 | "dax": "deno:dax@~23.0/mod.ts" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-deno-lib/scripts/build_npm.ts: -------------------------------------------------------------------------------- 1 | import { build } from "https://deno.land/x/dnt@0.32.1/mod.ts"; 2 | 3 | await build({ 4 | entryPoints: ["./mod.ts"], 5 | outDir: "./npm", 6 | test: true, 7 | importMap: "./deno.json", 8 | package: { 9 | name: "deno-lib", 10 | version: Deno.args[0], 11 | description: "Example of a deno lib that's also published to npm.", 12 | author: "David Sherret", 13 | license: "MIT", 14 | repository: "git+https://github.com/dsherret/deno_2.git", 15 | }, 16 | shims: { 17 | deno: { 18 | test: "dev", 19 | }, 20 | }, 21 | }); 22 | 23 | // post build steps 24 | Deno.copyFileSync("LICENSE", "npm/LICENSE"); 25 | Deno.copyFileSync("README.md", "npm/README.md"); 26 | -------------------------------------------------------------------------------- /03-deno-lib/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: test 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: denoland/setup-deno@v1 13 | 14 | - name: Test 15 | run: deno test -A 16 | 17 | - name: deno.land/x publish 18 | if: startsWith(github.ref, 'refs/tags/') 19 | use: denoland/publish@v1 20 | 21 | - uses: actions/setup-node@v2 22 | with: 23 | node-version: '16.x' 24 | registry-url: 'https://registry.npmjs.org' 25 | - name: Get tag version 26 | if: startsWith(github.ref, 'refs/tags/') 27 | id: get_tag_version 28 | run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//} 29 | - name: npm build 30 | run: deno task build:npm ${{steps.get_tag_version.outputs.TAG_VERSION}} 31 | - name: npm publish 32 | if: startsWith(github.ref, 'refs/tags/') 33 | env: 34 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 35 | run: | 36 | cd npm 37 | npm publish 38 | --------------------------------------------------------------------------------