bdarcus / csl-next

An experimental reimagining of CSL
Mozilla Public License 2.0
8 stars 0 forks source link

Partially-revert Deno-first structure #153

Open bdarcus opened 1 year ago

bdarcus commented 1 year ago

I think recent Deno enhancements should make this feasible.

See:

https://www.susanpotter.net/snippets/basic-deno-development-workflow-that-generates-node-artifacts/

The strategy, I think, would mean making use of importmaps for import statements. With that, I think that will provide compatibility for deno, node, bun, AND browsers.

I had already added the maps to deno.json; just need to change the import statements to use them.

And then, of course, ditch the dnt-based strategy., and use esbuild to compile the typescript code.

Testing can be handled via CI.


Here's a simple example with deno, bun, and node compatibility.

❯ cat test.ts
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: test.ts
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ import url from 'node:url';
   2   │ import edtf from 'npm:edtf@^4.4.1'
   3   │
   4   │ export function isValidSlug(slug: string): boolean {
   5   │   return slug.length > 0;
   6   │ }
   7   │
   8   │ export function isValidId(id: number): boolean {
   9   │   return id > 0;
  10   │ }
  11   │
  12   │ export function isValidTitle(title: string): boolean {
  13   │   return title.length > 0;
  14   │ }
  15   │
  16   │ export function isValidUrl(url: string): boolean {
  17   │   return url.parse(url).ok;
  18   │ }
  19   │
  20   │ console.log(isValidSlug("One two"));
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

❯ bun run test.ts
true

❯ deno run test.ts
true

❯ esbuild --bundle ./*.ts --platform=node > test.js

❯ node test.js
true