From a6979d9c54b1b805e1b2af8319239d63ca61c894 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:38:18 +0900 Subject: [PATCH 1/3] feat: Support for Node.js commonjs package and replace `jsr:@cosense/std` with `npm:@cosense/std` in the npm package version --- deno.jsonc | 2 +- deno.lock | 49 +++++++++++++++++++++++++++++++++++++------- scripts/build_npm.ts | 33 ++++++++++++++++++----------- 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 135a05f..53f67b3 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -47,7 +47,7 @@ "@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", diff --git a/deno.lock b/deno.lock index f7e95b5..0fda29f 100644 --- a/deno.lock +++ b/deno.lock @@ -3,24 +3,32 @@ "specifiers": { "jsr:@core/iterutil@0.9": "0.9.0", "jsr:@core/unknownutil@4": "4.3.0", - "jsr:@cosense/types@0.11": "0.11.0", + "jsr:@cosense/types@~0.11.2": "0.11.2", "jsr:@david/code-block-writer@^13.0.3": "13.0.3", "jsr:@deno/dnt@~0.42.3": "0.42.3", "jsr:@progfay/scrapbox-parser@^10.0.1": "10.0.1", "jsr:@std/assert@1": "1.0.13", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/async@^1.0.14": "1.0.14", + "jsr:@std/cli@^1.0.21": "1.0.21", + "jsr:@std/data-structures@^1.0.9": "1.0.9", "jsr:@std/encoding@1": "1.0.10", + "jsr:@std/encoding@^1.0.10": "1.0.10", "jsr:@std/fmt@1": "1.0.8", + "jsr:@std/fmt@^1.0.8": "1.0.8", "jsr:@std/fs@1": "1.0.19", "jsr:@std/fs@^1.0.19": "1.0.19", + "jsr:@std/html@^1.0.4": "1.0.4", "jsr:@std/http@^1.0.13": "1.0.20", "jsr:@std/internal@^1.0.10": "1.0.10", "jsr:@std/internal@^1.0.6": "1.0.10", "jsr:@std/internal@^1.0.9": "1.0.10", "jsr:@std/json@1": "1.0.2", + "jsr:@std/media-types@^1.1.0": "1.1.0", + "jsr:@std/net@^1.0.4": "1.0.4", "jsr:@std/path@1": "1.1.1", "jsr:@std/path@^1.1.1": "1.1.1", + "jsr:@std/streams@^1.0.10": "1.0.10", "jsr:@std/streams@^1.0.9": "1.0.10", "jsr:@std/testing@^1.0.9": "1.0.15", "jsr:@takker/md5@0.1": "0.1.0", @@ -36,8 +44,8 @@ "@core/unknownutil@4.3.0": { "integrity": "538a3687ffa81028e91d148818047df219663d0da671d906cecd165581ae55cc" }, - "@cosense/types@0.11.0": { - "integrity": "6e1d8768b1be162e635ec0c611092b49c528a623ef3e73c7cd95acab04ba2c10" + "@cosense/types@0.11.2": { + "integrity": "2aefb44f9e39af2c233ea1f2af62934980e3632b02df1a462fa43b058893b756" }, "@david/code-block-writer@13.0.3": { "integrity": "f98c77d320f5957899a61bfb7a9bead7c6d83ad1515daee92dbacc861e13bb7f" @@ -46,7 +54,7 @@ "integrity": "62a917a0492f3c8af002dce90605bb0d41f7d29debc06aca40dba72ab65d8ae3", "dependencies": [ "jsr:@david/code-block-writer", - "jsr:@std/fmt", + "jsr:@std/fmt@1", "jsr:@std/fs@1", "jsr:@std/path@1", "jsr:@ts-morph/bootstrap" @@ -64,6 +72,12 @@ "@std/async@1.0.14": { "integrity": "62e954a418652c704d37563a3e54a37d4cf0268a9dcaeac1660cc652880b5326" }, + "@std/cli@1.0.21": { + "integrity": "cd25b050bdf6282e321854e3822bee624f07aca7636a3a76d95f77a3a919ca2a" + }, + "@std/data-structures@1.0.9": { + "integrity": "033d6e17e64bf1f84a614e647c1b015fa2576ae3312305821e1a4cb20674bb4d" + }, "@std/encoding@1.0.10": { "integrity": "8783c6384a2d13abd5e9e87a7ae0520a30e9f56aeeaa3bdf910a3eaaf5c811a1" }, @@ -77,8 +91,22 @@ "jsr:@std/path@^1.1.1" ] }, + "@std/html@1.0.4": { + "integrity": "eff3497c08164e6ada49b7f81a28b5108087033823153d065e3f89467dd3d50e" + }, "@std/http@1.0.20": { - "integrity": "b5cc33fc001bccce65ed4c51815668c9891c69ccd908295997e983d8f56070a1" + "integrity": "b5cc33fc001bccce65ed4c51815668c9891c69ccd908295997e983d8f56070a1", + "dependencies": [ + "jsr:@std/cli", + "jsr:@std/encoding@^1.0.10", + "jsr:@std/fmt@^1.0.8", + "jsr:@std/fs@^1.0.19", + "jsr:@std/html", + "jsr:@std/media-types", + "jsr:@std/net", + "jsr:@std/path@^1.1.1", + "jsr:@std/streams@^1.0.10" + ] }, "@std/internal@1.0.10": { "integrity": "e3be62ce42cab0e177c27698e5d9800122f67b766a0bea6ca4867886cbde8cf7" @@ -86,9 +114,15 @@ "@std/json@1.0.2": { "integrity": "d9e5497801c15fb679f55a2c01c7794ad7a5dfda4dd1bebab5e409cb5e0d34d4", "dependencies": [ - "jsr:@std/streams" + "jsr:@std/streams@^1.0.9" ] }, + "@std/media-types@1.1.0": { + "integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4" + }, + "@std/net@1.0.4": { + "integrity": "2f403b455ebbccf83d8a027d29c5a9e3a2452fea39bb2da7f2c04af09c8bc852" + }, "@std/path@1.1.1": { "integrity": "fe00026bd3a7e6a27f73709b83c607798be40e20c81dde655ce34052fd82ec76", "dependencies": [ @@ -102,6 +136,7 @@ "integrity": "a490169f5ccb0f3ae9c94fbc69d2cd43603f2cffb41713a85f99bbb0e3087cbc", "dependencies": [ "jsr:@std/assert@^1.0.13", + "jsr:@std/data-structures", "jsr:@std/fs@^1.0.19", "jsr:@std/internal@^1.0.10", "jsr:@std/path@^1.1.1" @@ -180,7 +215,7 @@ "dependencies": [ "jsr:@core/iterutil@0.9", "jsr:@core/unknownutil@4", - "jsr:@cosense/types@0.11", + "jsr:@cosense/types@~0.11.2", "jsr:@deno/dnt@~0.42.3", "jsr:@progfay/scrapbox-parser@^10.0.1", "jsr:@std/assert@1", diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index 507fcd0..cf4ca97 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -12,6 +12,9 @@ await Deno.writeTextFile( (await Deno.readTextFile("./deno.jsonc")).replace( "jsr:@progfay/scrapbox-parser", "npm:@progfay/scrapbox-parser", + ).replace( + "jsr:@cosense/types", + "npm:@cosense/types", ), ); @@ -141,8 +144,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", @@ -153,18 +155,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}`, "") + ), ); }, }); From 6db3f03895f12508bc92734e35218f93a641795a Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:40:53 +0900 Subject: [PATCH 2/3] docs: update README to indicate support for both ESM and CommonJS syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a238ff1..ad6201f 100644 --- a/README.md +++ b/README.md @@ -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 From b8f04fd15067f38acfcd96334cf7f6173ebc5303 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:53:17 +0900 Subject: [PATCH 3/3] fix(package): ensure all submodule paths are included in the npm package --- deno.jsonc | 1 + deno.lock | 9 ++++ scripts/build_npm.ts | 100 ++++--------------------------------------- 3 files changed, 18 insertions(+), 92 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 53f67b3..dae0fb1 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -55,6 +55,7 @@ "@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", diff --git a/deno.lock b/deno.lock index 0fda29f..d93eccc 100644 --- a/deno.lock +++ b/deno.lock @@ -24,6 +24,8 @@ "jsr:@std/internal@^1.0.6": "1.0.10", "jsr:@std/internal@^1.0.9": "1.0.10", "jsr:@std/json@1": "1.0.2", + "jsr:@std/json@^1.0.2": "1.0.2", + "jsr:@std/jsonc@^1.0.2": "1.0.2", "jsr:@std/media-types@^1.1.0": "1.1.0", "jsr:@std/net@^1.0.4": "1.0.4", "jsr:@std/path@1": "1.1.1", @@ -117,6 +119,12 @@ "jsr:@std/streams@^1.0.9" ] }, + "@std/jsonc@1.0.2": { + "integrity": "909605dae3af22bd75b1cbda8d64a32cf1fd2cf6efa3f9e224aba6d22c0f44c7", + "dependencies": [ + "jsr:@std/json@^1.0.2" + ] + }, "@std/media-types@1.1.0": { "integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4" }, @@ -223,6 +231,7 @@ "jsr:@std/encoding@1", "jsr:@std/http@^1.0.13", "jsr:@std/json@1", + "jsr:@std/jsonc@^1.0.2", "jsr:@std/testing@^1.0.9", "jsr:@takker/md5@0.1", "npm:option-t@53", diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index cf4ca97..c4220ab 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -1,4 +1,5 @@ import { build, emptyDir } from "@deno/dnt"; +import { parse } from "@std/jsonc"; await emptyDir("./npm"); @@ -18,101 +19,16 @@ await Deno.writeTextFile( ), ); +const config = parse(await Deno.readTextFile("./deno.jsonc")) as { + exports: Record; +}; + 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" },