Skip to content

Commit 09fc776

Browse files
committed
core packaging for cjs
1 parent 56e2a6b commit 09fc776

File tree

5 files changed

+45
-51
lines changed

5 files changed

+45
-51
lines changed

bin/cjs-fix-imports.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,19 @@ import {
77
} from "https://deno.land/std@0.136.0/path/mod.ts";
88

99
const argv = parseArgs(
10-
Deno.args,
11-
{
12-
alias: {
13-
o: ["out"],
10+
Deno.args,
11+
{
12+
alias: {
13+
o: ["out"],
14+
},
15+
boolean: true,
16+
string: ["out"],
17+
default: {
18+
o: "lib",
19+
},
1420
},
15-
boolean: true,
16-
string: ["out"],
17-
default: {
18-
o: "lib",
19-
},
20-
},
2121
);
2222

23-
const libs = {
24-
"jsr:@nats-io/nkeys": "@nats-io/nkeys",
25-
"jsr:@nats-io/nuid": "@nats-io/nuid"
26-
}
27-
28-
2923

3024

3125
// resolve the specified directories to fq
@@ -57,22 +51,23 @@ if (argv.debug) {
5751

5852
if (!dirs.length || argv.h || argv.help) {
5953
console.log(
60-
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
54+
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`,
6155
);
6256
Deno.exit(1);
6357
}
6458

6559
// create out if not exist
6660
await Deno.lstat(out)
67-
.catch(async () => {
68-
await Deno.mkdir(out);
69-
});
61+
.catch(async () => {
62+
await Deno.mkdir(out);
63+
});
7064

7165
// process each file - remove extensions from requires/import
7266
for (const fn of files) {
7367
const data = await Deno.readFile(fn);
7468
let txt = new TextDecoder().decode(data);
7569

70+
7671
let mod = txt.replace(/jsr:@nats-io\/nkeys/gim, "nkeys.js");
7772
mod = mod.replace(/jsr:@nats-io\/nuid/gim, "nuid");
7873
if(!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) {

nats-base-client/package.json

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
{
2-
"name": "nats-core",
3-
"version": "3.0.0-14",
2+
"name": "@nats-io/nats-core",
3+
"version": "3.0.0-16",
44
"files": [
55
"lib/",
66
"esm/"
77
],
88
"types": "./lib/mod.d.js",
99
"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-
}
10+
".": "./lib/mod.js",
11+
"./internal": "./lib/internal_mod.js"
1812
},
13+
"license": "Apache-2.0",
14+
"private": false,
1915
"scripts": {
2016
"test": "echo \"Error: no test specified\" && exit 1",
2117
"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 .",
18+
"pre-process": "npm run clean && deno run -A bin/cjs-fix-imports.ts -o ./cjs ./src",
2319
"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"
20+
"build": "npm run build-cjs",
21+
"prepack": "npm run build"
2622
},
2723
"keywords": [],
28-
"author": "",
29-
"license": "ISC",
30-
"description": "",
24+
"author": {
25+
"name": "The NATS Authors"
26+
},
27+
"description": "nats-core library - this library implements all the base functionality for NATS javascript clients",
3128
"dependencies": {
3229
"nkeys.js": "^1.1.0",
3330
"nuid": "^2.0.0",

nats-base-client/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "Node16",
4+
"module": "nodenext",
55
"outDir": "lib/",
6-
"moduleResolution": "node16",
6+
"moduleResolution": "nodenext",
77
"sourceMap": true,
88
"declaration": true,
99
"allowJs": true,
@@ -12,4 +12,4 @@
1212
"include": [
1313
"cjs/**/*"
1414
]
15-
}
15+
}

test_helpers/connect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {connect} from "jsr:@nats-io/nats-transport-deno@3.0.0-2";

test_helpers/mod.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525

2626
import { NatsServer } from "./launcher.ts";
2727
import { red, yellow } from "jsr:@std/fmt/colors";
28-
import { connect } from "../src/mod.ts";
28+
import { connect } from "./connect.ts";
29+
export { connect } from "./connect.ts";
2930
import {ConnectFn} from "../nats-base-client/core.ts";
3031
export { check } from "./check.ts";
3132
export { Lock } from "./lock.ts";
@@ -57,8 +58,8 @@ export function jsopts() {
5758
}
5859

5960
export function jetstreamExportServerConf(
60-
opts: unknown = {},
61-
prefix = "IPA.>",
61+
opts: unknown = {},
62+
prefix = "IPA.>",
6263
): Record<string, unknown> {
6364
const template = {
6465
"no_auth_user": "a",
@@ -87,7 +88,7 @@ export function jetstreamExportServerConf(
8788
}
8889

8990
export function jetstreamServerConf(
90-
opts: unknown = {},
91+
opts: unknown = {},
9192
): Record<string, unknown> {
9293
const conf = Object.assign(jsopts(), opts);
9394
if (typeof conf.jetstream.store_dir !== "string") {
@@ -107,15 +108,15 @@ export async function _setup(fn: ConnectFn, serverConf?: Record<string, unknown>
107108
}
108109

109110
export function setup(
110-
serverConf?: Record<string, unknown>,
111-
clientOpts?: Partial<ConnectionOptions>,
111+
serverConf?: Record<string, unknown>,
112+
clientOpts?: Partial<ConnectionOptions>,
112113
): Promise<{ ns: NatsServer; nc: NatsConnection }> {
113114
return _setup(connect, serverConf, clientOpts);
114115
}
115116

116117
export async function cleanup(
117-
ns: NatsServer,
118-
...nc: NatsConnection[]
118+
ns: NatsServer,
119+
...nc: NatsConnection[]
119120
): Promise<void> {
120121
const conns: Promise<void>[] = [];
121122
nc.forEach((v) => {
@@ -126,16 +127,16 @@ export async function cleanup(
126127
}
127128

128129
export async function notCompatible(
129-
ns: NatsServer,
130-
nc: NatsConnection,
131-
version?: string,
130+
ns: NatsServer,
131+
nc: NatsConnection,
132+
version?: string,
132133
): Promise<boolean> {
133134
version = version ?? "2.3.3";
134135
const varz = await ns.varz() as unknown as Record<string, string>;
135136
const sv = parseSemVer(varz.version);
136137
if (compare(sv, parseSemVer(version)) < 0) {
137138
const m = new TextEncoder().encode(yellow(
138-
`skipping test as server (${varz.version}) doesn't implement required feature from ${version} `,
139+
`skipping test as server (${varz.version}) doesn't implement required feature from ${version} `,
139140
));
140141
await Deno.stdout.write(m);
141142
await cleanup(ns, nc);

0 commit comments

Comments
 (0)