Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: improve node cli experience #1095

Merged
merged 6 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,34 @@ jobs:
target
!target/**/db/full/*
!target/**/paritydb/full/*
examples-node:
name: Examples (Node)
runs-on: ubuntu-latest
timeout-minutes: 15
needs: cache
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.0
with:
deno-version: v1.33.3
- uses: actions/cache@v3
with:
path: ~/.cache/deno
key: cache-${{ env.CAPI_SHA }}
- run: deno run -A _tasks/use_remote.ts
- run: deno task dnt --server ${{ env.CAPI_SHA }} --examples
- uses: actions/setup-node@v3
with:
node-version: "20"
- run: deno task test:eg:node
- name: Archive target
uses: actions/upload-artifact@v3
if: failure() || cancelled()
with:
name: examples-node-target
path: |
target
!target/**/db/full/*
!target/**/paritydb/full/*

# TODO: https://github.com/paritytech/capi/issues/1096
# examples-node:
# name: Examples (Node)
# runs-on: ubuntu-latest
# timeout-minutes: 15
# needs: cache
# steps:
# - uses: actions/checkout@v3
# - uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.0
# with:
# deno-version: v1.33.3
# - uses: actions/cache@v3
# with:
# path: ~/.cache/deno
# key: cache-${{ env.CAPI_SHA }}
# - run: deno run -A _tasks/use_remote.ts
# - run: deno task dnt --server ${{ env.CAPI_SHA }} --examples
# - uses: actions/setup-node@v3
# with:
# node-version: "20"
# - run: deno task test:eg:node
# - name: Archive target
# uses: actions/upload-artifact@v3
# if: failure() || cancelled()
# with:
# name: examples-node-target
# path: |
# target
# !target/**/db/full/*
# !target/**/paritydb/full/*
33 changes: 18 additions & 15 deletions _tasks/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,13 @@ await Promise.all([
compilerOptions: {
importHelpers: true,
sourceMap: true,
target: "ES2021",
lib: ["es2022.error"],
target: "ES2022",
lib: ["ES2022", "DOM"],
},
entryPoints: [
{
name: ".",
path: "./mod.ts",
},
{
kind: "bin",
name: "capi",
path: "./main.ts",
},
{ name: ".", path: "./mod.ts" },
{ name: "./loader", path: "./deps/shims/loader.node.ts" },
{ kind: "bin", name: "capi", path: "./main.ts" },
...entryPoints,
],
mappings: {
Expand All @@ -119,6 +113,7 @@ await Promise.all([
version: "8.13.0",
},
"./deps/shims/shim-deno.ts": "@deno/shim-deno",
"./deps/shims/ts-node-esm.ts": "ts-node/esm",
"node:net": "node:net",
"node:http": "node:http",
"node:stream": "node:stream",
Expand Down Expand Up @@ -152,14 +147,19 @@ await Promise.all([
await Promise.all([
fs.copy(
path.join(capiOutDir, "src/rune/_empty.d.ts"),
path.join(capiOutDir, "types/rune/_empty.d.ts"),
path.join(capiOutDir, "esm/rune/_empty.d.ts"),
{ overwrite: true },
),
fs.copy(
path.join(capiOutDir, "src/rune/_empty.d.ts"),
path.join(capiOutDir, "script/rune/_empty.d.ts"),
{ overwrite: true },
),
editFile(
path.join(capiOutDir, "esm/main.js"),
(content) =>
content
.replace(/^#!.+/, "#!/usr/bin/env -S node --loader ts-node/esm"),
.replace(/^#!.+/, "#!/usr/bin/env -S node --loader capi/loader"),
),
editFile(
path.join(capiOutDir, "esm/_dnt.shims.js"),
Expand Down Expand Up @@ -209,9 +209,12 @@ if (buildExamples) {
importHelpers: true,
sourceMap: true,
target: "ES2021",
lib: ["es2022.error", "dom.iterable"],
lib: ["ES2022", "DOM"],
},
entryPoints: exampleEntryPoints,
entryPoints: [
...exampleEntryPoints,
{ name: "./deps/ed25519", path: "./deps/ed25519.ts" },
],
mappings: {
"https://deno.land/x/polkadot@0.2.38/keyring/mod.ts": {
name: "@polkadot/keyring",
Expand Down
4 changes: 2 additions & 2 deletions cli/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function withCommonOptions(command: Command) {
.option("-o, --out <out:string>", "Metadata and codegen output directory", {
default: "target/capi",
})
.option("-s, --server <server:string>", "", { default: "https://capi.dev/" })
.option("-s, --server <server:string>", "")
}

interface SyncProps {
Expand Down Expand Up @@ -83,7 +83,7 @@ async function setup(props: SyncProps) {
)
}
const baseUrl = await syncNets(
props.server ?? `https://capi.dev/${version}/`,
props.server ?? `https://capi.dev/@${version}/`,
devnetTempDir,
netSpecs,
)
Expand Down
2 changes: 1 addition & 1 deletion deps/dnt.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/dnt@0.34.0/mod.ts"
export * from "https://deno.land/x/dnt@0.37.0/mod.ts"
1 change: 1 addition & 0 deletions deps/shims/loader.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ts-node-esm.ts"
1 change: 1 addition & 0 deletions deps/shims/ts-node-esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This will be shimmed to `ts-node/esm` by DNT
2 changes: 1 addition & 1 deletion server/detectVersion.node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function detectVersion(): string | undefined {
const packageJsonPath = new URL("../package.json", import.meta.url)
const packageJsonPath = new URL("../../package.json", import.meta.url)
try {
Deno.statSync(packageJsonPath)
const packageJson = Deno.readTextFileSync(packageJsonPath)
Expand Down