Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ npm install @cosense/std

2. Import the library:

**Only ESM syntax is supported.**
You can use both ESM and CommonJS syntax:

```typescript
// ESM syntax
Expand Down
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
"@cosense/std/browser/websocket": "./websocket/mod.ts",
"@cosense/std/rest": "./rest/mod.ts",
"@cosense/std/websocket": "./websocket/mod.ts",
"@cosense/types": "jsr:@cosense/types@^0.11.0",
"@cosense/types": "jsr:@cosense/types@^0.11.2",
"@deno/dnt": "jsr:@deno/dnt@^0.42.3",
"@progfay/scrapbox-parser": "jsr:@progfay/scrapbox-parser@^10.0.1",
"@std/assert": "jsr:@std/assert@1",
"@std/async": "jsr:@std/async@^1.0.14",
"@std/encoding": "jsr:@std/encoding@1",
"@std/http": "jsr:@std/http@^1.0.13",
"@std/json": "jsr:@std/json@^1.0.0",
"@std/jsonc": "jsr:@std/jsonc@^1.0.2",
"@std/testing": "jsr:@std/testing@^1.0.9",
"@takker/md5": "jsr:@takker/md5@0.1",
"@takker/onp": "./vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts",
Expand Down
58 changes: 51 additions & 7 deletions deno.lock

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

133 changes: 29 additions & 104 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { build, emptyDir } from "@deno/dnt";
import { parse } from "@std/jsonc";

await emptyDir("./npm");

Expand All @@ -12,104 +13,22 @@ await Deno.writeTextFile(
(await Deno.readTextFile("./deno.jsonc")).replace(
"jsr:@progfay/scrapbox-parser",
"npm:@progfay/scrapbox-parser",
).replace(
"jsr:@cosense/types",
"npm:@cosense/types",
),
);

const config = parse(await Deno.readTextFile("./deno.jsonc")) as {
exports: Record<string, string>;
};

await build({
entryPoints: [
"./mod.ts",
{
name: "./browser",
path: "./browser/mod.ts",
},
{
name: "./browser/dom",
path: "./browser/dom/mod.ts",
},
{
name: "./browser/websocket",
path: "./websocket/mod.ts",
},
{
name: "./parseAbsoluteLink",
path: "./parseAbsoluteLink.ts",
},
{
name: "./rest",
path: "./rest/mod.ts",
},
{
name: "./text",
path: "./text.ts",
},
{
name: "./title",
path: "./title.ts",
},
{
name: "./websocket",
path: "./websocket/mod.ts",
},
{
name: "./unstable-api",
path: "./api.ts",
},
{
name: "./unstable-api/pages",
path: "./api/pages.ts",
},
{
name: "./unstable-api/pages/project",
path: "./api/pages/project.ts",
},
{
name: "./unstable-api/pages/project/replace",
path: "./api/pages/project/replace.ts",
},
{
name: "./unstable-api/pages/project/replace/links",
path: "./api/pages/project/replace/links.ts",
},
{
name: "./unstable-api/pages/project/search",
path: "./api/pages/project/search.ts",
},
{
name: "./unstable-api/pages/project/search/query",
path: "./api/pages/project/search/query.ts",
},
{
name: "./unstable-api/pages/project/search/titles",
path: "./api/pages/project/search/titles.ts",
},
{
name: "./unstable-api/pages/project/title",
path: "./api/pages/project/title.ts",
},
{
name: "./unstable-api/pages/projects",
path: "./api/projects.ts",
},
{
name: "./unstable-api/pages/projects/project",
path: "./api/projects/project.ts",
},
{
name: "./unstable-api/pages/project/title/text",
path: "./api/pages/project/title/text.ts",
},
{
name: "./unstable-api/pages/project/title/icon",
path: "./api/pages/project/title/icon.ts",
},
{
name: "./unstable-api/users",
path: "./api/users.ts",
},
{
name: "./unstable-api/users/me",
path: "./api/users/me.ts",
},
...Object.entries(config.exports).flatMap(
([name, path]) => name === "." ? [] : [{ name, path }],
),
],
outDir: "./npm",
shims: { deno: "dev" },
Expand Down Expand Up @@ -141,8 +60,7 @@ await build({
configFile: new URL("../deno_node.jsonc", import.meta.url).href,
// Don't run type checking during build to avoid Node.js compatibility issues
typeCheck: false,
declaration: "separate",
scriptModule: false,
declaration: "inline",
compilerOptions: {
lib: ["ESNext", "DOM", "DOM.Iterable"],
target: "ES2023",
Expand All @@ -153,18 +71,25 @@ await build({

// ignore snapshot testing & related test files on Node distribution
const emptyTestFiles = [
"npm/esm/browser/dom/extractCodeFiles.test.js",
"npm/esm/parser/anchor-fm.test.js",
"npm/esm/parser/spotify.test.js",
"npm/esm/parser/youtube.test.js",
"npm/esm/rest/getCodeBlocks.test.js",
"npm/esm/rest/pages.test.js",
"npm/esm/rest/project.test.js",
"npm/esm/websocket/_codeBlock.test.js",
"npm/esm/websocket/diffToChanges.test.js",
"browser/dom/extractCodeFiles.test.js",
"parser/anchor-fm.test.js",
"parser/spotify.test.js",
"parser/youtube.test.js",
"rest/getCodeBlocks.test.js",
"rest/pages.test.js",
"rest/project.test.js",
"websocket/_codeBlock.test.js",
"websocket/diffToChanges.test.js",
];
await Promise.all(
emptyTestFiles.map((filePath) => Deno.writeTextFile(filePath, "")),
emptyTestFiles.map((filePath) =>
Deno.writeTextFile(`npm/esm/${filePath}`, "")
),
);
await Promise.all(
emptyTestFiles.map((filePath) =>
Deno.writeTextFile(`npm/script/${filePath}`, "")
),
);
},
});