]> git.wincent.com - wincent.git/commitdiff
refactor: run TypeScript using n + node + yarn instead of Deno
authorGreg Hurrell <greg@hurrell.net>
Wed, 18 Mar 2020 23:52:32 +0000 (00:52 +0100)
committerGreg Hurrell <greg@hurrell.net>
Fri, 20 Mar 2020 09:53:24 +0000 (10:53 +0100)
Because is the only obvious way I can see to have TypeScript-checked
output that I can actually edit in Vim without the LSP client spewing
errors all over the place.

.gitignore
install-next
lib/.gitignore [new file with mode: 0644]
lib/main.ts [deleted file]
lib/other.ts [deleted file]
package.json
src/log.ts [new file with mode: 0644]
src/main.ts [new file with mode: 0644]
tsconfig.json
vendor/node/.gitignore [new file with mode: 0644]
yarn.lock [new file with mode: 0644]

index b5d0b77ccdd7fdb3eef56c6cdeb734ebe2c4bc8b..0a18ada96135981cf73ead01c9cc2ae05e105316 100644 (file)
@@ -1,5 +1,6 @@
 *.pyc
 /media
+/node_modules
 /python
 /roles/dotfiles/files/.gh.json
 /roles/dotfiles/files/.hammerspoon/iterm.lua
index 1d7e1d67f86950a773397eaff0605a9a21ffc92a..e255abb9ab6d9dc8662707b78217f6227ee13c69 100755 (executable)
@@ -3,11 +3,13 @@
 set -e
 
 REPO_ROOT="${BASH_SOURCE%/*}"
-DENO_BASE="$REPO_ROOT/vendor/deno"
-DENO_INSTALLER="$DENO_BASE/install.sh"
-DENO_INSTALL="$DENO_BASE/local"
-DENO_EXE="$DENO_INSTALL/bin/deno"
-DENO_TYPES="$DENO_BASE/types.d.ts"
+MAIN_EXE="$REPO_ROOT/lib/main.js"
+VENDOR_ROOT="$REPO_ROOT/vendor"
+N_EXE="$VENDOR_ROOT/n/bin/n"
+N_PREFIX="$VENDOR_ROOT/node"
+YARN_EXE="$VENDOR_ROOT/yarn-v1.22.4/bin/yarn"
+
+export N_PREFIX
 
 for ARG in "$@"; do
   if [ "$ARG" = "--force" -o "$ARG" = "-f" ]; then
@@ -15,27 +17,24 @@ for ARG in "$@"; do
   fi
 done
 
-if [[ ! -e "$DENO_INSTALLER" || $FORCE ]]; then
-  echo "[status] Fetching Deno installer"
-  command curl -fsSL -o "$DENO_INSTALLER" https://deno.land/x/install/install.sh
-else
-  echo "[skip] Fetch Deno installer; use -f to force re-fetch"
+if [[ ! -x $N_EXE ]]; then
+  echo "[abort] No executable at $N_EXE; did you forget to \`git submodule init\`?"
+  exit 1
 fi
 
-if [[ ! -e "$DENO_EXE" || $FORCE ]]; then
-  echo "[status] Run Deno installer"
-  export DENO_INSTALL
-  command sh "$DENO_INSTALLER"
-else
-  echo "[skip] Run Deno installer; use -f to force re-install"
+if ! "$N_EXE" which lts &> /dev/null; then
+  echo "[status] Installing Node LTS version"
+  "$N_EXE" lts
 fi
 
-if [[ ! -e "$DENO_TYPES" || $FORCE ]]; then
-  echo "[status] Generate Deno types"
-  "$DENO_EXE" types > "$DENO_TYPES"
-else
-  echo "[skip] Generate Deno types; use -f to force re-generation"
-fi
+echo "[status] Installing TypeScript"
+
+"$N_EXE" exec lts "$YARN_EXE" --frozen-lockfile --no-default-rc --no-progress --silent
+
+echo "[status] Building"
+
+"$N_EXE" exec lts "$YARN_EXE" run --silent tsc
 
 echo "[status] Running main"
-"$DENO_EXE" run --allow-all lib/main.ts "$@"
+
+"$N_EXE" run lts "$MAIN_EXE" "$@"
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..120f485
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!/.gitignore
diff --git a/lib/main.ts b/lib/main.ts
deleted file mode 100644 (file)
index 4890837..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-// This is only for the benefit of the LanguageClient.
-// @ts-ignore
-import type Deno from '../vendor/deno/types.d.ts';
-
-// @ts-ignore
-import test from './other.ts';
-
-test(Deno.args);
diff --git a/lib/other.ts b/lib/other.ts
deleted file mode 100644 (file)
index 247226c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function(args: Array<string>) {
-  console.log(...args);
-}
index 2c780556e83166b08809a285c29861ca3d96dde7..8c90c44ce55c567ee8c156134900c9ae6426ca37 100644 (file)
   "scripts": {
     "format:check": "npx prettier --check \"**/*.js\" \"*.json\" \"*.md\" roles/dotfiles/files/.zsh/liferay/bin/portool",
     "format": "npx prettier --write \"**/*.js\" \"*.json\" \"*.md\" roles/dotfiles/files/.zsh/liferay/bin/portool"
+  },
+  "dependencies": {
+    "typescript": "3.8.3"
+  },
+  "devDependencies": {
+    "@types/node": "*"
   }
 }
diff --git a/src/log.ts b/src/log.ts
new file mode 100644 (file)
index 0000000..999959a
--- /dev/null
@@ -0,0 +1,3 @@
+export default function log(...args: Array<any>) {
+  console.log(...args);
+}
diff --git a/src/main.ts b/src/main.ts
new file mode 100644 (file)
index 0000000..e11433d
--- /dev/null
@@ -0,0 +1,6 @@
+import log from './log';
+
+// argv[0] = node executable
+// argv[1] = JS script
+// argv[2] = script arg 0 etc
+log(process.argv);
index e1529ad3cc9fd2e643e7ced3cb25ac9573b1f52a..060fb05ee1fbdc41ea579f6af67c1b2d2e66aecd 100644 (file)
@@ -1,3 +1,9 @@
 {
-  "include": ["src/**/*.ts", "vendor/deno/types.d.ts"]
+  "compilerOptions": {
+    "module": "CommonJS",
+    "outDir": "./lib",
+    "strict": true,
+    "target": "ES2019"
+  },
+  "include": ["src/**/*.ts"]
 }
diff --git a/vendor/node/.gitignore b/vendor/node/.gitignore
new file mode 100644 (file)
index 0000000..120f485
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!/.gitignore
diff --git a/yarn.lock b/yarn.lock
new file mode 100644 (file)
index 0000000..ac2abc4
--- /dev/null
+++ b/yarn.lock
@@ -0,0 +1,13 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"@types/node@*":
+  version "13.9.2"
+  resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.2.tgz#ace1880c03594cc3e80206d96847157d8e7fa349"
+  integrity sha512-bnoqK579sAYrQbp73wwglccjJ4sfRdKU7WNEZ5FW4K2U6Kc0/eZ5kvXG0JKsEKFB50zrFmfFt52/cvBbZa7eXg==
+
+typescript@3.8.3:
+  version "3.8.3"
+  resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
+  integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==