Skip to content

Commit 56e2a6b

Browse files
committed
packages for core
1 parent 3b2d342 commit 56e2a6b

File tree

7 files changed

+168
-145
lines changed

7 files changed

+168
-145
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ settings.json
2626
coverage/
2727

2828
# Dependency directories
29-
node_modules
29+
**/node_modules/
3030

3131
# Optional npm cache directory
3232
.npm
@@ -36,3 +36,4 @@ vcs.xml
3636

3737
# we copy package.json to read the version so ts, webpack, etc are happy
3838
src/package.json
39+

bin/cjs-fix-imports.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { parseArgs } from "jsr:@std/cli@0.224.3/parse-args"
2+
import {
3+
basename,
4+
extname,
5+
join,
6+
resolve,
7+
} from "https://deno.land/std@0.136.0/path/mod.ts";
8+
9+
const argv = parseArgs(
10+
Deno.args,
11+
{
12+
alias: {
13+
o: ["out"],
14+
},
15+
boolean: true,
16+
string: ["out"],
17+
default: {
18+
o: "lib",
19+
},
20+
},
21+
);
22+
23+
const libs = {
24+
"jsr:@nats-io/nkeys": "@nats-io/nkeys",
25+
"jsr:@nats-io/nuid": "@nats-io/nuid"
26+
}
27+
28+
29+
30+
31+
// resolve the specified directories to fq
32+
let dirs = (argv._ as string[]).map((n) => {
33+
return resolve(n);
34+
});
35+
// resolve the out dir
36+
const out = resolve(argv.o);
37+
38+
// collect a list of all the files
39+
const files: string[] = [];
40+
for (const d of dirs) {
41+
for await (const fn of Deno.readDir(d)) {
42+
const ext = extname(fn.name);
43+
if (ext === ".ts" || ext === ".js") {
44+
files.push(join(d, fn.name));
45+
}
46+
}
47+
}
48+
49+
dirs.flat();
50+
51+
if (argv.debug) {
52+
console.log(`src: ${dirs.join(" ")}`);
53+
console.log(`out: ${out}`);
54+
console.log(`files: ${files.join(",")}`);
55+
Deno.exit(0);
56+
}
57+
58+
if (!dirs.length || argv.h || argv.help) {
59+
console.log(
60+
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
61+
);
62+
Deno.exit(1);
63+
}
64+
65+
// create out if not exist
66+
await Deno.lstat(out)
67+
.catch(async () => {
68+
await Deno.mkdir(out);
69+
});
70+
71+
// process each file - remove extensions from requires/import
72+
for (const fn of files) {
73+
const data = await Deno.readFile(fn);
74+
let txt = new TextDecoder().decode(data);
75+
76+
let mod = txt.replace(/jsr:@nats-io\/nkeys/gim, "nkeys.js");
77+
mod = mod.replace(/jsr:@nats-io\/nuid/gim, "nuid");
78+
if(!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) {
79+
mod = mod.replace(/from\s+"(\S+).[t|j]s"/gim, 'from "$1"');
80+
}
81+
82+
// // mod = mod.replace(/require\("(\S+).[j|t]s"\)/gim, 'require("$1")');
83+
//
84+
// // some of the imports are references to external projects
85+
// // that in node we resolve with requires - if we encounter one that
86+
// // the script is not configured for, the build fails
87+
// while (true) {
88+
// const m = mod.match(/(export [\s\S]+ from\s+"(https:\/\/\S+)")/);
89+
// if (m) {
90+
// for (const k of requires.keys()) {
91+
// if (m[2].indexOf(k) === 0) {
92+
// const entry = requires.get(k);
93+
// mod = mod.replace(
94+
// m[0],
95+
// `export const ${entry!.arg} = require("${entry!.lib}")`,
96+
// );
97+
// break;
98+
// }
99+
// }
100+
// } else {
101+
// break;
102+
// }
103+
// }
104+
105+
const target = join(out, basename(fn));
106+
await Deno.writeFile(target, new TextEncoder().encode(mod));
107+
if (txt.length !== mod.length) {
108+
console.log(`${target}`);
109+
}
110+
}

nats-base-client/deno.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"./internal": "./internal_mod.ts"
77
},
88
"publish": {
9-
"include": [
10-
"./**/*"
9+
"exclude": [
10+
"./tests/**/*",
11+
"./unsafe_tests/**/*"
1112
]
1213
},
1314
"imports": {
1415
"jsr:@nats-io/nkeys": "jsr:@nats-io/nkeys@1.1.1-1",
15-
"jsr:@nats-io/nuid": "jsr:@nats-io/nkeys@2.0.0"
16+
"jsr:@nats-io/nuid": "jsr:@nats-io/nuid@2.0.0"
1617
}
1718
}

nats-base-client/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "nats-core",
3+
"version": "3.0.0-14",
4+
"files": [
5+
"lib/",
6+
"esm/"
7+
],
8+
"types": "./lib/mod.d.js",
9+
"exports": {
10+
".": {
11+
"require": "./lib/mod.js",
12+
"module": "./esm/mod.mjs"
13+
},
14+
"./internal": {
15+
"require": "./lib/internal_mod.js",
16+
"module": "./esm/internal_mod.mjs"
17+
}
18+
},
19+
"scripts": {
20+
"test": "echo \"Error: no test specified\" && exit 1",
21+
"clean": "shx rm -Rf ./lib ./cjs ./esm && shx mkdir esm",
22+
"pre-process": "npm run clean && deno run -A ../bin/cjs-fix-imports.ts -o ./cjs .",
23+
"build-cjs": "npm run pre-process && tsc",
24+
"build-esm": "deno bundle mod.ts esm/mod.mjs && deno bundle internal_mod.ts esm/internal_mod.mjs",
25+
"build": "npm run build-cjs && npm run build-esm"
26+
},
27+
"keywords": [],
28+
"author": "",
29+
"license": "ISC",
30+
"description": "",
31+
"dependencies": {
32+
"nkeys.js": "^1.1.0",
33+
"nuid": "^2.0.0",
34+
"shx": "^0.3.4",
35+
"typescript": "^5.4.5"
36+
}
37+
}

nats-base-client/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "Node16",
5+
"outDir": "lib/",
6+
"moduleResolution": "node16",
7+
"sourceMap": true,
8+
"declaration": true,
9+
"allowJs": true,
10+
"removeComments": false,
11+
},
12+
"include": [
13+
"cjs/**/*"
14+
]
15+
}

nuid/jsr.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

nuid/src/mod.ts

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)