diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3015315 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "deno.enable": true, + "deno.disablePaths": [ + "**/bun.spec.ts", + "./libs/ts/detect-runtimwwwe" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index bd940de..4b5dbcd 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,71 @@ Can we construct a megarepo that contains multiple, interdependent TypeScript li ## Change log +### 3️⃣ lib 3: `@axhxrx/detect-runtime` + +Next, add a junk lib that imports the first two. This one will also import `left-pad`, of NPM fame. 😉 That's my test for "can use old NPM package". + +```text +➜ detect-runtime git:(main) ✗ bun add left-pad +bun add v1.1.13 (bd6a6051) + +installed left-pad@1.3.0 + +1 package installed [559.00ms] +➜ detect-runtime git:(main) ✗ +``` + +~~**PROBLEM:** This makes Deno's language server start freaking out.~~ Oh wait, it doesn't. It actually works fine, I just had a typo. Wow! Cool. + +OK and now we have a third lib, which imports the other two from the monorepo, **and** [left-pad](https://www.npmjs.com/package/left-pad) from NPM. + +Cool let's add a dependency on a JSR package, too, although we will have to use the Nody way (but we're using Bun so I will use `bunx` and not `npx`): + +```text +➜ detect-runtime git:(main) ✗ bunx jsr add @libs/logger + +Installing @libs/logger... +$ bun add @libs/logger@npm:@jsr/libs__logger +bun add v1.1.13 (bd6a6051) + +installed @libs/logger@1.1.2 + +1 package installed [655.00ms] + +Completed in 682ms +➜ detect-runtime git:(main) ✗ bun run index.ts +``` +Hmm it works in Bun, but not Deno: + +```text +➜ detect-runtime git:(main) ✗ bun run index.ts + + Hello via Bun! + The date is: 2024-06-16 16:04:56 + (via @axhxrx/date) + +{ + name: "Bun", + version: "1.1.13", + isDeno: false, + isBun: true, + isNode: false, + isUnknown: false, +} +-------------------- + Bun +-------------------- + INFO │ +0.011 Loginator message { + name: "zfx", +} +➜ detect-runtime git:(main) ✗ deno run index.ts +error: npm package '@jsr/libs__logger' does not exist. +➜ detect-runtime git:(main) ✗ deno run index.ts +``` + +I think this might be some unrelated bug in Deno/JSR though. I'll tackle that separately. + + ### 2️⃣ lib 2: `axhxrx/date` Since Deno doesn't use `package.json` and all that `node_modules` mess, but we need to have that, use Bun to generate an empty library: diff --git a/bun.lockb b/bun.lockb index c5d5904..13d7c38 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..bea1efe --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[install.scopes] +"@jsr" = "https://npm.jsr.io" diff --git a/deno.lock b/deno.lock index b921f1c..87f94ac 100644 --- a/deno.lock +++ b/deno.lock @@ -3,7 +3,10 @@ "packages": { "specifiers": { "jsr:@std/assert": "jsr:@std/assert@0.221.0", - "jsr:@std/fmt@^0.221.0": "jsr:@std/fmt@0.221.0" + "jsr:@std/fmt@^0.221.0": "jsr:@std/fmt@0.221.0", + "npm:@types/bun@latest": "npm:@types/bun@1.1.4", + "npm:jsr@^0.12.4": "npm:jsr@0.12.4", + "npm:left-pad@^1.3.0": "npm:left-pad@1.3.0" }, "jsr": { "@std/assert@0.221.0": { @@ -15,6 +18,65 @@ "@std/fmt@0.221.0": { "integrity": "379fed69bdd9731110f26b9085aeb740606b20428ce6af31ef6bd45ef8efa62a" } + }, + "npm": { + "@types/bun@1.1.4": { + "integrity": "sha512-ejSuv/3s0hTHj/nkkLzBlHxm4JxOPygbLNi0kzM6ooq8rOiQvIUCv7RRErTaWSfb+QVnKz6x7qlp8N86bGDiIg==", + "dependencies": { + "bun-types": "bun-types@1.1.13" + } + }, + "@types/node@18.16.19": { + "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==", + "dependencies": {} + }, + "@types/node@20.12.14": { + "integrity": "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg==", + "dependencies": { + "undici-types": "undici-types@5.26.5" + } + }, + "@types/ws@8.5.10": { + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dependencies": { + "@types/node": "@types/node@18.16.19" + } + }, + "bun-types@1.1.13": { + "integrity": "sha512-G/TqF0SsMQGLr4g7K3B2BK8BrPEA1EqCNwxZbyRdj5M4t54zvwyaqvRJOW34kuPqc2IvNNalRU3swc8B4oc4FA==", + "dependencies": { + "@types/node": "@types/node@20.12.14", + "@types/ws": "@types/ws@8.5.10" + } + }, + "jsr@0.12.4": { + "integrity": "sha512-ZWDvqQE8014fWz9QBrkiuvRQ8mH97PRD13VIDzoMXDem3ff2S+wfXw+YAvrZE0aKzxh9FuHJX0HQRQ2MUHshig==", + "dependencies": { + "kolorist": "kolorist@1.8.0", + "node-stream-zip": "node-stream-zip@1.15.0", + "semiver": "semiver@1.1.0" + } + }, + "kolorist@1.8.0": { + "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==", + "dependencies": {} + }, + "left-pad@1.3.0": { + "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==", + "dependencies": {} + }, + "node-stream-zip@1.15.0": { + "integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==", + "dependencies": {} + }, + "semiver@1.1.0": { + "integrity": "sha512-QNI2ChmuioGC1/xjyYwyZYADILWyW6AmS1UH6gDj/SFUUUS4MBAWs/7mxnkRPc/F4iHezDP+O8t0dO8WHiEOdg==", + "dependencies": {} + }, + "undici-types@5.26.5": { + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dependencies": {} + } } }, "remote": {}, @@ -22,7 +84,8 @@ "packageJson": { "dependencies": [ "npm:@types/bun@latest", - "npm:jsr@^0.12.4" + "npm:jsr@^0.12.4", + "npm:left-pad@^1.3.0" ] } } diff --git a/libs/ts/detect-runtime/Loginator.ts b/libs/ts/detect-runtime/Loginator.ts new file mode 100644 index 0000000..197cb27 --- /dev/null +++ b/libs/ts/detect-runtime/Loginator.ts @@ -0,0 +1,5 @@ +import * as mod from "@libs/logger"; + +const logEverything = true; + +export const Loginator = new mod.Logger(); \ No newline at end of file diff --git a/libs/ts/detect-runtime/index.ts b/libs/ts/detect-runtime/index.ts index 06157ac..57f2de1 100644 --- a/libs/ts/detect-runtime/index.ts +++ b/libs/ts/detect-runtime/index.ts @@ -4,6 +4,8 @@ import { dateToFormat } from '@axhxrx/date'; import { assertNever } from '@axhxrx/assert-never'; import { detectRuntime } from './detectRuntime.ts'; +import { leftPaddedRuntimeName } from "./leftPadRuntimeName.ts"; +import { Loginator } from './Loginator.ts'; const result = detectRuntime(); @@ -17,6 +19,14 @@ if (import.meta.main) (via @axhxrx/date) `); console.log(result); + + console.log('--------------------') + console.log(leftPaddedRuntimeName(result)); + console.log('--------------------') + + const logger = Loginator; + + logger.info("Loginator message", { name: "zfx" }); } if (result.isNode || result.isUnknown) diff --git a/libs/ts/detect-runtime/leftPadRuntimeName.ts b/libs/ts/detect-runtime/leftPadRuntimeName.ts new file mode 100644 index 0000000..8d52ecf --- /dev/null +++ b/libs/ts/detect-runtime/leftPadRuntimeName.ts @@ -0,0 +1,10 @@ +import { default as leftPadThatBoooch } from 'left-pad'; + +import type { DetectedRuntime } from "./DetectedRuntime.ts"; +/** + This function just tests consumption of an NPM package. There's no other point. + */ +export const leftPaddedRuntimeName = (runtimeInfo: DetectedRuntime): string => +{ + return leftPadThatBoooch(runtimeInfo.name, 20); +} \ No newline at end of file diff --git a/package.json b/package.json index 9b77db0..57ee6a3 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "typescript": "^5.4.5" }, "dependencies": { - "jsr": "^0.12.4" + "@libs/logger": "npm:@jsr/libs__logger", + "jsr": "^0.12.4", + "left-pad": "^1.3.0" } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 1ba9cec..7b398d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,10 @@ }, "rootDir": ".", "baseUrl": ".", + + // @masonmark 2024-06-16: Had to enable this to use ancient NPM dep + "esModuleInterop": true, + // Enable latest features "lib": ["ESNext", "DOM"], "target": "ESNext",