From 3e48ea35a0beeb90538324292da2dabde1ea6a00 Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Sun, 5 May 2024 02:02:28 +0900 Subject: [PATCH 1/3] export to jsr --- generate-exports.rb | 78 ++++++++++++++++++++++++++++++--------------- jsr.json | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 25 deletions(-) create mode 100644 jsr.json diff --git a/generate-exports.rb b/generate-exports.rb index 3bc2863..ab90a18 100644 --- a/generate-exports.rb +++ b/generate-exports.rb @@ -3,36 +3,64 @@ require 'json' require 'pp' -here = Pathname.new(__dir__) +@here = Pathname.new(__dir__) -src_dir = here / 'src' +def build_exports + src_dir = @here / 'src' -tsx_files = src_dir - .find - .select{|fn| fn.file? and fn.to_s =~ /\.tsx?$/i } - .reject{|fn| fn.to_s =~ /\.spec\./ } + ts_files = src_dir + .find + .select{|fn| fn.file? and fn.to_s =~ /\.tsx?$/i } + .reject{|fn| fn.to_s =~ /\.spec\./ } -exports = Hash[ - tsx_files - .sort - .map do |e| - relative_path = e.relative_path_from(src_dir) - relative_path_wo_ext = relative_path.sub(/\.[tj]sx?$/i, '').to_s - js_ext = if relative_path.fnmatch? '*.tsx' then 'jsx' else 'js' end + Hash[ + ts_files + .sort + .map do |e| + relative_path = e.relative_path_from(src_dir) + relative_path_wo_ext = relative_path.sub(/\.[tj]sx?$/i, '').to_s + orig_ext = relative_path.extname.slice(1, 1e9) + js_ext = if relative_path.fnmatch? '*.tsx' then 'jsx' else 'js' end - [ - "./lib/#{relative_path_wo_ext}", - { - import: "./lib/__esm/#{relative_path_wo_ext}.#{js_ext}", - require: "./lib/#{relative_path_wo_ext}.#{js_ext}", - type: "./lib/#{relative_path_wo_ext}.d.ts" - } + import_entry, import_spec = yield relative_path_wo_ext, js_ext, orig_ext + [import_entry, import_spec] + end + ] +end + +def rewrite_json json_path + v = JSON.parse(json_path.read, symbolize_names: true) + json_path.write JSON.pretty_generate(yield v) +end + +def rewrite_pkg_json + pkg_json = @here / 'package.json' + exports = build_exports do |relative_path_wo_ext, js_ext| + ["./lib/#{relative_path_wo_ext}", + { + import: "./lib/__esm/#{relative_path_wo_ext}.#{js_ext}", + require: "./lib/#{relative_path_wo_ext}.#{js_ext}", + type: "./lib/#{relative_path_wo_ext}.d.ts" + } ] end -] - -pkg_json = here / 'package.json' + rewrite_json pkg_json do |v| + {**v, exports: exports} + end +end -v = JSON.parse(pkg_json.read, symbolize_names: true) +def rewrite_jsr_json + jsr_json = @here / 'jsr.json' + exports = build_exports do |relative_path_wo_ext, js_ext, orig_ext| + [ + "./#{relative_path_wo_ext}", + "./src/#{relative_path_wo_ext}.#{orig_ext}", + ] + end + rewrite_json jsr_json do |v| + {**v, exports: exports} + end +end -pkg_json.write JSON.pretty_generate(**v, exports: exports) +rewrite_pkg_json +rewrite_jsr_json diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..03fbf9c --- /dev/null +++ b/jsr.json @@ -0,0 +1,71 @@ +{ + "name": "@ihate-work/ts-commonutil", + "version": "0.1.0", + "exports": { + "./algebra/monoid": "./src/algebra/monoid.ts", + "./algebra/topological-sort": "./src/algebra/topological-sort.ts", + "./algebra/total-ordered": "./src/algebra/total-ordered.ts", + "./binary-conversion/array-buffer": "./src/binary-conversion/array-buffer.ts", + "./binary-conversion/string": "./src/binary-conversion/string.ts", + "./binary-conversion/web": "./src/binary-conversion/web.ts", + "./collection/btree": "./src/collection/btree.ts", + "./collection/default-map": "./src/collection/default-map.ts", + "./collection/iterables": "./src/collection/iterables.ts", + "./collection/maps": "./src/collection/maps.ts", + "./collection/min-heap": "./src/collection/min-heap.ts", + "./collection/multiset": "./src/collection/multiset.ts", + "./collection/segment-tree": "./src/collection/segment-tree.ts", + "./collection/sets": "./src/collection/sets.ts", + "./concurrency/async-throttle": "./src/concurrency/async-throttle.ts", + "./concurrency/deferred": "./src/concurrency/deferred.ts", + "./concurrency/lazy-thenable": "./src/concurrency/lazy-thenable.ts", + "./concurrency/lease": "./src/concurrency/lease.ts", + "./concurrency/lockable": "./src/concurrency/lockable.ts", + "./concurrency/promise-container": "./src/concurrency/promise-container.ts", + "./concurrency/resource-pool": "./src/concurrency/resource-pool.ts", + "./concurrency/tic-toc": "./src/concurrency/tic-toc.ts", + "./concurrency/timing": "./src/concurrency/timing.ts", + "./event-emitter/typed-event-emitter": "./src/event-emitter/typed-event-emitter.ts", + "./fp-ts/monoid": "./src/fp-ts/monoid.ts", + "./frontend/dummy-img": "./src/frontend/dummy-img.ts", + "./frontend/fps-observable": "./src/frontend/fps-observable.ts", + "./frontend/measure-img": "./src/frontend/measure-img.ts", + "./frontend/observe-dom-mutation": "./src/frontend/observe-dom-mutation.ts", + "./index": "./src/index.ts", + "./logging/console-logger": "./src/logging/console-logger.ts", + "./logging/get-debug-namespace": "./src/logging/get-debug-namespace.ts", + "./logging/loglevel-logger": "./src/logging/loglevel-logger.ts", + "./logging/winston-logger": "./src/logging/winston-logger.ts", + "./node/fsp": "./src/node/fsp.ts", + "./node/index": "./src/node/index.ts", + "./node/subprocess": "./src/node/subprocess.ts", + "./react/component/aspect-ratio/aspect-ratio": "./src/react/component/aspect-ratio/aspect-ratio.ts", + "./react/component/font-awesome": "./src/react/component/font-awesome.tsx", + "./react/component/inspect-render-count": "./src/react/component/inspect-render-count.tsx", + "./react/component/pre-json": "./src/react/component/pre-json.tsx", + "./react/hook/use-async-effect": "./src/react/hook/use-async-effect.ts", + "./react/hook/use-concurrency-control": "./src/react/hook/use-concurrency-control.ts", + "./react/hook/use-depending-state": "./src/react/hook/use-depending-state.ts", + "./react/hook/use-fps": "./src/react/hook/use-fps.ts", + "./react/hook/use-in-server": "./src/react/hook/use-in-server.ts", + "./react/hook/use-life-cycle": "./src/react/hook/use-life-cycle.ts", + "./react/hook/use-mounted": "./src/react/hook/use-mounted.ts", + "./react/hook/use-observable-store": "./src/react/hook/use-observable-store.ts", + "./react/hook/use-prev": "./src/react/hook/use-prev.ts", + "./react/hook/use-promised": "./src/react/hook/use-promised.ts", + "./react/hook/use-versioned-memo": "./src/react/hook/use-versioned-memo.ts", + "./react/mobx/use-derived": "./src/react/mobx/use-derived.ts", + "./react/util/prop-of": "./src/react/util/prop-of.ts", + "./rxjs/distributions": "./src/rxjs/distributions.ts", + "./rxjs/stochastic-processes": "./src/rxjs/stochastic-processes.ts", + "./text/chunk-to-lines": "./src/text/chunk-to-lines.ts", + "./text/random-string": "./src/text/random-string.ts", + "./type/freeze": "./src/type/freeze.ts", + "./type/index": "./src/type/index.ts", + "./type/omit": "./src/type/omit.ts", + "./util/lru": "./src/util/lru.ts", + "./util/proxys": "./src/util/proxys.ts", + "./util/randoms": "./src/util/randoms.ts", + "./util/with-retry": "./src/util/with-retry.ts" + } +} \ No newline at end of file From fd7141323ef5548082915d00bd1f5c3de1f4a03e Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Wed, 15 May 2024 01:17:43 +0900 Subject: [PATCH 2/3] archive react component with scss --- .../react}/aspect-ratio/aspect-ratio-magic.scss | 0 .../component => obsolete/react}/aspect-ratio/aspect-ratio.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {src/react/component => obsolete/react}/aspect-ratio/aspect-ratio-magic.scss (100%) rename {src/react/component => obsolete/react}/aspect-ratio/aspect-ratio.ts (100%) diff --git a/src/react/component/aspect-ratio/aspect-ratio-magic.scss b/obsolete/react/aspect-ratio/aspect-ratio-magic.scss similarity index 100% rename from src/react/component/aspect-ratio/aspect-ratio-magic.scss rename to obsolete/react/aspect-ratio/aspect-ratio-magic.scss diff --git a/src/react/component/aspect-ratio/aspect-ratio.ts b/obsolete/react/aspect-ratio/aspect-ratio.ts similarity index 100% rename from src/react/component/aspect-ratio/aspect-ratio.ts rename to obsolete/react/aspect-ratio/aspect-ratio.ts From c42f4fad0fdf33ccd80dfcf159ae24c5925e4c5b Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Wed, 15 May 2024 01:19:37 +0900 Subject: [PATCH 3/3] publish as jsr package --- jsr.json | 1 - package.json | 325 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 323 insertions(+), 3 deletions(-) diff --git a/jsr.json b/jsr.json index 03fbf9c..94e5ffa 100644 --- a/jsr.json +++ b/jsr.json @@ -39,7 +39,6 @@ "./node/fsp": "./src/node/fsp.ts", "./node/index": "./src/node/index.ts", "./node/subprocess": "./src/node/subprocess.ts", - "./react/component/aspect-ratio/aspect-ratio": "./src/react/component/aspect-ratio/aspect-ratio.ts", "./react/component/font-awesome": "./src/react/component/font-awesome.tsx", "./react/component/inspect-render-count": "./src/react/component/inspect-render-count.tsx", "./react/component/pre-json": "./src/react/component/pre-json.tsx", diff --git a/package.json b/package.json index 551bda5..0b90cf5 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,330 @@ "typescript": "^5.4", "winston": "^3.8.0" }, - "exports": {}, + "exports": { + "./lib/algebra/monoid": { + "import": "./lib/__esm/algebra/monoid.js", + "require": "./lib/algebra/monoid.js", + "type": "./lib/algebra/monoid.d.ts" + }, + "./lib/algebra/topological-sort": { + "import": "./lib/__esm/algebra/topological-sort.js", + "require": "./lib/algebra/topological-sort.js", + "type": "./lib/algebra/topological-sort.d.ts" + }, + "./lib/algebra/total-ordered": { + "import": "./lib/__esm/algebra/total-ordered.js", + "require": "./lib/algebra/total-ordered.js", + "type": "./lib/algebra/total-ordered.d.ts" + }, + "./lib/binary-conversion/array-buffer": { + "import": "./lib/__esm/binary-conversion/array-buffer.js", + "require": "./lib/binary-conversion/array-buffer.js", + "type": "./lib/binary-conversion/array-buffer.d.ts" + }, + "./lib/binary-conversion/string": { + "import": "./lib/__esm/binary-conversion/string.js", + "require": "./lib/binary-conversion/string.js", + "type": "./lib/binary-conversion/string.d.ts" + }, + "./lib/binary-conversion/web": { + "import": "./lib/__esm/binary-conversion/web.js", + "require": "./lib/binary-conversion/web.js", + "type": "./lib/binary-conversion/web.d.ts" + }, + "./lib/collection/btree": { + "import": "./lib/__esm/collection/btree.js", + "require": "./lib/collection/btree.js", + "type": "./lib/collection/btree.d.ts" + }, + "./lib/collection/default-map": { + "import": "./lib/__esm/collection/default-map.js", + "require": "./lib/collection/default-map.js", + "type": "./lib/collection/default-map.d.ts" + }, + "./lib/collection/iterables": { + "import": "./lib/__esm/collection/iterables.js", + "require": "./lib/collection/iterables.js", + "type": "./lib/collection/iterables.d.ts" + }, + "./lib/collection/maps": { + "import": "./lib/__esm/collection/maps.js", + "require": "./lib/collection/maps.js", + "type": "./lib/collection/maps.d.ts" + }, + "./lib/collection/min-heap": { + "import": "./lib/__esm/collection/min-heap.js", + "require": "./lib/collection/min-heap.js", + "type": "./lib/collection/min-heap.d.ts" + }, + "./lib/collection/multiset": { + "import": "./lib/__esm/collection/multiset.js", + "require": "./lib/collection/multiset.js", + "type": "./lib/collection/multiset.d.ts" + }, + "./lib/collection/segment-tree": { + "import": "./lib/__esm/collection/segment-tree.js", + "require": "./lib/collection/segment-tree.js", + "type": "./lib/collection/segment-tree.d.ts" + }, + "./lib/collection/sets": { + "import": "./lib/__esm/collection/sets.js", + "require": "./lib/collection/sets.js", + "type": "./lib/collection/sets.d.ts" + }, + "./lib/concurrency/async-throttle": { + "import": "./lib/__esm/concurrency/async-throttle.js", + "require": "./lib/concurrency/async-throttle.js", + "type": "./lib/concurrency/async-throttle.d.ts" + }, + "./lib/concurrency/deferred": { + "import": "./lib/__esm/concurrency/deferred.js", + "require": "./lib/concurrency/deferred.js", + "type": "./lib/concurrency/deferred.d.ts" + }, + "./lib/concurrency/lazy-thenable": { + "import": "./lib/__esm/concurrency/lazy-thenable.js", + "require": "./lib/concurrency/lazy-thenable.js", + "type": "./lib/concurrency/lazy-thenable.d.ts" + }, + "./lib/concurrency/lease": { + "import": "./lib/__esm/concurrency/lease.js", + "require": "./lib/concurrency/lease.js", + "type": "./lib/concurrency/lease.d.ts" + }, + "./lib/concurrency/lockable": { + "import": "./lib/__esm/concurrency/lockable.js", + "require": "./lib/concurrency/lockable.js", + "type": "./lib/concurrency/lockable.d.ts" + }, + "./lib/concurrency/promise-container": { + "import": "./lib/__esm/concurrency/promise-container.js", + "require": "./lib/concurrency/promise-container.js", + "type": "./lib/concurrency/promise-container.d.ts" + }, + "./lib/concurrency/resource-pool": { + "import": "./lib/__esm/concurrency/resource-pool.js", + "require": "./lib/concurrency/resource-pool.js", + "type": "./lib/concurrency/resource-pool.d.ts" + }, + "./lib/concurrency/tic-toc": { + "import": "./lib/__esm/concurrency/tic-toc.js", + "require": "./lib/concurrency/tic-toc.js", + "type": "./lib/concurrency/tic-toc.d.ts" + }, + "./lib/concurrency/timing": { + "import": "./lib/__esm/concurrency/timing.js", + "require": "./lib/concurrency/timing.js", + "type": "./lib/concurrency/timing.d.ts" + }, + "./lib/event-emitter/typed-event-emitter": { + "import": "./lib/__esm/event-emitter/typed-event-emitter.js", + "require": "./lib/event-emitter/typed-event-emitter.js", + "type": "./lib/event-emitter/typed-event-emitter.d.ts" + }, + "./lib/fp-ts/monoid": { + "import": "./lib/__esm/fp-ts/monoid.js", + "require": "./lib/fp-ts/monoid.js", + "type": "./lib/fp-ts/monoid.d.ts" + }, + "./lib/frontend/dummy-img": { + "import": "./lib/__esm/frontend/dummy-img.js", + "require": "./lib/frontend/dummy-img.js", + "type": "./lib/frontend/dummy-img.d.ts" + }, + "./lib/frontend/fps-observable": { + "import": "./lib/__esm/frontend/fps-observable.js", + "require": "./lib/frontend/fps-observable.js", + "type": "./lib/frontend/fps-observable.d.ts" + }, + "./lib/frontend/measure-img": { + "import": "./lib/__esm/frontend/measure-img.js", + "require": "./lib/frontend/measure-img.js", + "type": "./lib/frontend/measure-img.d.ts" + }, + "./lib/frontend/observe-dom-mutation": { + "import": "./lib/__esm/frontend/observe-dom-mutation.js", + "require": "./lib/frontend/observe-dom-mutation.js", + "type": "./lib/frontend/observe-dom-mutation.d.ts" + }, + "./lib/index": { + "import": "./lib/__esm/index.js", + "require": "./lib/index.js", + "type": "./lib/index.d.ts" + }, + "./lib/logging/console-logger": { + "import": "./lib/__esm/logging/console-logger.js", + "require": "./lib/logging/console-logger.js", + "type": "./lib/logging/console-logger.d.ts" + }, + "./lib/logging/get-debug-namespace": { + "import": "./lib/__esm/logging/get-debug-namespace.js", + "require": "./lib/logging/get-debug-namespace.js", + "type": "./lib/logging/get-debug-namespace.d.ts" + }, + "./lib/logging/loglevel-logger": { + "import": "./lib/__esm/logging/loglevel-logger.js", + "require": "./lib/logging/loglevel-logger.js", + "type": "./lib/logging/loglevel-logger.d.ts" + }, + "./lib/logging/winston-logger": { + "import": "./lib/__esm/logging/winston-logger.js", + "require": "./lib/logging/winston-logger.js", + "type": "./lib/logging/winston-logger.d.ts" + }, + "./lib/node/fsp": { + "import": "./lib/__esm/node/fsp.js", + "require": "./lib/node/fsp.js", + "type": "./lib/node/fsp.d.ts" + }, + "./lib/node/index": { + "import": "./lib/__esm/node/index.js", + "require": "./lib/node/index.js", + "type": "./lib/node/index.d.ts" + }, + "./lib/node/subprocess": { + "import": "./lib/__esm/node/subprocess.js", + "require": "./lib/node/subprocess.js", + "type": "./lib/node/subprocess.d.ts" + }, + "./lib/react/component/font-awesome": { + "import": "./lib/__esm/react/component/font-awesome.jsx", + "require": "./lib/react/component/font-awesome.jsx", + "type": "./lib/react/component/font-awesome.d.ts" + }, + "./lib/react/component/inspect-render-count": { + "import": "./lib/__esm/react/component/inspect-render-count.jsx", + "require": "./lib/react/component/inspect-render-count.jsx", + "type": "./lib/react/component/inspect-render-count.d.ts" + }, + "./lib/react/component/pre-json": { + "import": "./lib/__esm/react/component/pre-json.jsx", + "require": "./lib/react/component/pre-json.jsx", + "type": "./lib/react/component/pre-json.d.ts" + }, + "./lib/react/hook/use-async-effect": { + "import": "./lib/__esm/react/hook/use-async-effect.js", + "require": "./lib/react/hook/use-async-effect.js", + "type": "./lib/react/hook/use-async-effect.d.ts" + }, + "./lib/react/hook/use-concurrency-control": { + "import": "./lib/__esm/react/hook/use-concurrency-control.js", + "require": "./lib/react/hook/use-concurrency-control.js", + "type": "./lib/react/hook/use-concurrency-control.d.ts" + }, + "./lib/react/hook/use-depending-state": { + "import": "./lib/__esm/react/hook/use-depending-state.js", + "require": "./lib/react/hook/use-depending-state.js", + "type": "./lib/react/hook/use-depending-state.d.ts" + }, + "./lib/react/hook/use-fps": { + "import": "./lib/__esm/react/hook/use-fps.js", + "require": "./lib/react/hook/use-fps.js", + "type": "./lib/react/hook/use-fps.d.ts" + }, + "./lib/react/hook/use-in-server": { + "import": "./lib/__esm/react/hook/use-in-server.js", + "require": "./lib/react/hook/use-in-server.js", + "type": "./lib/react/hook/use-in-server.d.ts" + }, + "./lib/react/hook/use-life-cycle": { + "import": "./lib/__esm/react/hook/use-life-cycle.js", + "require": "./lib/react/hook/use-life-cycle.js", + "type": "./lib/react/hook/use-life-cycle.d.ts" + }, + "./lib/react/hook/use-mounted": { + "import": "./lib/__esm/react/hook/use-mounted.js", + "require": "./lib/react/hook/use-mounted.js", + "type": "./lib/react/hook/use-mounted.d.ts" + }, + "./lib/react/hook/use-observable-store": { + "import": "./lib/__esm/react/hook/use-observable-store.js", + "require": "./lib/react/hook/use-observable-store.js", + "type": "./lib/react/hook/use-observable-store.d.ts" + }, + "./lib/react/hook/use-prev": { + "import": "./lib/__esm/react/hook/use-prev.js", + "require": "./lib/react/hook/use-prev.js", + "type": "./lib/react/hook/use-prev.d.ts" + }, + "./lib/react/hook/use-promised": { + "import": "./lib/__esm/react/hook/use-promised.js", + "require": "./lib/react/hook/use-promised.js", + "type": "./lib/react/hook/use-promised.d.ts" + }, + "./lib/react/hook/use-versioned-memo": { + "import": "./lib/__esm/react/hook/use-versioned-memo.js", + "require": "./lib/react/hook/use-versioned-memo.js", + "type": "./lib/react/hook/use-versioned-memo.d.ts" + }, + "./lib/react/mobx/use-derived": { + "import": "./lib/__esm/react/mobx/use-derived.js", + "require": "./lib/react/mobx/use-derived.js", + "type": "./lib/react/mobx/use-derived.d.ts" + }, + "./lib/react/util/prop-of": { + "import": "./lib/__esm/react/util/prop-of.js", + "require": "./lib/react/util/prop-of.js", + "type": "./lib/react/util/prop-of.d.ts" + }, + "./lib/rxjs/distributions": { + "import": "./lib/__esm/rxjs/distributions.js", + "require": "./lib/rxjs/distributions.js", + "type": "./lib/rxjs/distributions.d.ts" + }, + "./lib/rxjs/stochastic-processes": { + "import": "./lib/__esm/rxjs/stochastic-processes.js", + "require": "./lib/rxjs/stochastic-processes.js", + "type": "./lib/rxjs/stochastic-processes.d.ts" + }, + "./lib/text/chunk-to-lines": { + "import": "./lib/__esm/text/chunk-to-lines.js", + "require": "./lib/text/chunk-to-lines.js", + "type": "./lib/text/chunk-to-lines.d.ts" + }, + "./lib/text/random-string": { + "import": "./lib/__esm/text/random-string.js", + "require": "./lib/text/random-string.js", + "type": "./lib/text/random-string.d.ts" + }, + "./lib/type/freeze": { + "import": "./lib/__esm/type/freeze.js", + "require": "./lib/type/freeze.js", + "type": "./lib/type/freeze.d.ts" + }, + "./lib/type/index": { + "import": "./lib/__esm/type/index.js", + "require": "./lib/type/index.js", + "type": "./lib/type/index.d.ts" + }, + "./lib/type/omit": { + "import": "./lib/__esm/type/omit.js", + "require": "./lib/type/omit.js", + "type": "./lib/type/omit.d.ts" + }, + "./lib/util/lru": { + "import": "./lib/__esm/util/lru.js", + "require": "./lib/util/lru.js", + "type": "./lib/util/lru.d.ts" + }, + "./lib/util/proxys": { + "import": "./lib/__esm/util/proxys.js", + "require": "./lib/util/proxys.js", + "type": "./lib/util/proxys.d.ts" + }, + "./lib/util/randoms": { + "import": "./lib/__esm/util/randoms.js", + "require": "./lib/util/randoms.js", + "type": "./lib/util/randoms.d.ts" + }, + "./lib/util/with-retry": { + "import": "./lib/__esm/util/with-retry.js", + "require": "./lib/util/with-retry.js", + "type": "./lib/util/with-retry.d.ts" + } + }, "resolutions": { "@types/node": "18", "@types/react": "^18" } -} +} \ No newline at end of file