Skip to content

Commit 90bba5a

Browse files
committed
☕ Export individual modules for JSR
1 parent 82ebdb4 commit 90bba5a

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

deno.jsonc

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,76 @@
11
{
22
"name": "@core/unknownutil",
33
"version": "0.0.0",
4-
"exports": "./mod.ts",
4+
"exports": {
5+
".": "./mod.ts",
6+
"./type": "./type.ts",
7+
"./assert": "./assert.ts",
8+
"./ensure": "./ensure.ts",
9+
"./maybe": "./maybe.ts",
10+
"./as": "./as/mod.ts",
11+
"./as/optional": "./as/optional.ts",
12+
"./as/readonly": "./as/readonly.ts",
13+
"./is": "./is/mod.ts",
14+
"./is/any": "./is/any.ts",
15+
"./is/array": "./is/array.ts",
16+
"./is/array-of": "./is/array_of.ts",
17+
"./is/async-function": "./is/async_function.ts",
18+
"./is/bigint": "./is/bigint.ts",
19+
"./is/boolean": "./is/boolean.ts",
20+
"./is/function": "./is/function.ts",
21+
"./is/instance-of": "./is/instance_of.ts",
22+
"./is/intersection-of": "./is/intersection_of.ts",
23+
"./is/literal-of": "./is/literal_of.ts",
24+
"./is/literal-one-of": "./is/literal_one_of.ts",
25+
"./is/map": "./is/map.ts",
26+
"./is/map-of": "./is/map_of.ts",
27+
"./is/mod": "./is/mod.ts",
28+
"./is/null": "./is/null.ts",
29+
"./is/nullish": "./is/nullish.ts",
30+
"./is/number": "./is/number.ts",
31+
"./is/object-of": "./is/object_of.ts",
32+
"./is/omit-of": "./is/omit_of.ts",
33+
"./is/parameters-of": "./is/parameters_of.ts",
34+
"./is/partial-of": "./is/partial_of.ts",
35+
"./is/pick-of": "./is/pick_of.ts",
36+
"./is/primitive": "./is/primitive.ts",
37+
"./is/readonly-of": "./is/readonly_of.ts",
38+
"./is/record": "./is/record.ts",
39+
"./is/record-object": "./is/record_object.ts",
40+
"./is/record-object-of": "./is/record_object_of.ts",
41+
"./is/record-of": "./is/record_of.ts",
42+
"./is/required-of": "./is/required_of.ts",
43+
"./is/set": "./is/set.ts",
44+
"./is/set-of": "./is/set_of.ts",
45+
"./is/strict-of": "./is/strict_of.ts",
46+
"./is/string": "./is/string.ts",
47+
"./is/symbol": "./is/symbol.ts",
48+
"./is/sync-function": "./is/sync_function.ts",
49+
"./is/tuple-of": "./is/tuple_of.ts",
50+
"./is/undefined": "./is/undefined.ts",
51+
"./is/uniform-tuple-of": "./is/uniform_tuple_of.ts",
52+
"./is/union-of": "./is/union_of.ts",
53+
"./is/unknown": "./is/unknown.ts"
54+
},
55+
"exclude": [
56+
".coverage/**"
57+
],
58+
"publish": {
59+
"include": [
60+
"**/*.ts",
61+
"README.md",
62+
"LICENSE"
63+
],
64+
"exclude": [
65+
"**/*_test.ts",
66+
".*"
67+
]
68+
},
569
"imports": {
670
"@core/unknownutil": "./mod.ts",
771
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
872
"@std/assert": "jsr:@std/assert@^0.221.0",
73+
"@std/jsonc": "jsr:@std/jsonc@^1.0.0",
974
"@std/path": "jsr:@std/path@^1.0.2",
1075
"@std/testing": "jsr:@std/testing@^0.221.0"
1176
},

mod_test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { assertArrayIncludes } from "@std/assert";
2+
import { basename, globToRegExp } from "@std/path";
3+
import { parse } from "@std/jsonc";
4+
import { ensure } from "./ensure.ts";
5+
import { is } from "./is/mod.ts";
6+
7+
const excludes = [
8+
"mod.ts",
9+
"*_test.ts",
10+
];
11+
12+
Deno.test("JSR exports must have all `as` modules", async () => {
13+
const moduleNames = await listModuleNames(
14+
new URL(import.meta.resolve("./as")),
15+
);
16+
const jsrExports = await loadJsrExports();
17+
assertArrayIncludes(Object.entries(jsrExports.exports), [
18+
["./as", "./as/mod.ts"],
19+
...moduleNames.map((
20+
v,
21+
) => [`./as/${v.replaceAll("_", "-")}`, `./as/${v}.ts`]),
22+
]);
23+
});
24+
25+
Deno.test("JSR exports must have all `is` modules", async () => {
26+
const moduleNames = await listModuleNames(
27+
new URL(import.meta.resolve("./is")),
28+
);
29+
const jsrExports = await loadJsrExports();
30+
assertArrayIncludes(Object.entries(jsrExports.exports), [
31+
["./is", "./is/mod.ts"],
32+
...moduleNames.map((
33+
v,
34+
) => [`./is/${v.replaceAll("_", "-")}`, `./is/${v}.ts`]),
35+
]);
36+
});
37+
38+
async function listModuleNames(path: URL | string): Promise<string[]> {
39+
const patterns = excludes.map((p) => globToRegExp(p));
40+
const names: string[] = [];
41+
for await (const entry of Deno.readDir(path)) {
42+
if (!entry.isFile || !entry.name.endsWith(".ts")) continue;
43+
if (patterns.some((p) => p.test(entry.name))) continue;
44+
names.push(basename(entry.name, ".ts"));
45+
}
46+
return names;
47+
}
48+
49+
async function loadJsrExports(): Promise<{ exports: Record<string, string> }> {
50+
const text = await Deno.readTextFile(
51+
new URL(import.meta.resolve("./deno.jsonc")),
52+
);
53+
const json = ensure(
54+
parse(text),
55+
is.ObjectOf({
56+
exports: is.RecordOf(is.String, is.String),
57+
}),
58+
);
59+
return { exports: json.exports };
60+
}

0 commit comments

Comments
 (0)