Skip to content

Commit

Permalink
3️⃣ Make third lib depend on 'left-pad' from NPM, and '@libs/logger' …
Browse files Browse the repository at this point in the history
…from JSR.
  • Loading branch information
masonmark committed Jun 16, 2024
1 parent d7965d2 commit 5b2b4cc
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"deno.enable": true,
"deno.disablePaths": [
"**/bun.spec.ts",
"./libs/ts/detect-runtimwwwe"
]
}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
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/[email protected]
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:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.scopes]
"@jsr" = "https://npm.jsr.io"
67 changes: 65 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions libs/ts/detect-runtime/Loginator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as mod from "@libs/logger";

const logEverything = true;

export const Loginator = new mod.Logger();
10 changes: 10 additions & 0 deletions libs/ts/detect-runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions libs/ts/detect-runtime/leftPadRuntimeName.ts
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5b2b4cc

Please sign in to comment.