From 49d1b26dc30058dfb08e8199d3828e865d2ac5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 2 Dec 2023 19:33:15 +0100 Subject: [PATCH 01/31] playground with typescripts sandbox - `pnpm play` will run the playground locally - it will be published on github pages automatically too --- .github/workflows/playground.yml | 45 +++ README.md | 10 +- package.json | 4 +- playground/index.html | 9 + playground/index.js | 57 ++++ playground/serve.json | 9 + pnpm-lock.yaml | 568 +++++++++++++++++++++++++++++++ 7 files changed, 698 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/playground.yml create mode 100644 playground/index.html create mode 100644 playground/index.js create mode 100644 playground/serve.json diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml new file mode 100644 index 0000000..7997fc8 --- /dev/null +++ b/.github/workflows/playground.yml @@ -0,0 +1,45 @@ +name: Build Playground + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + playground: + # Allow one concurrent deployment + concurrency: + group: 'pages' + cancel-in-progress: true + + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + with: + run_install: true + + - run: pnpm dist/ + - run: cp playground/index.html dist/ + + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: ./dist + + - uses: actions/deploy-pages@v1 + id: deployment diff --git a/README.md b/README.md index 99a97c9..76f20f9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,12 @@ Typescript API to access the IrcLog CouchDB database. Mostly typed wrappers over ## Quick start for users ``` -TBD +echo "@irclogs:registry=https://npm.pkg.github.com" >> .npmrc +npm install @irclogs/api +# or +yarn add @irclogs/api +# or +pnpm add @irclogs/api ``` ## Quick start for developers @@ -14,7 +19,7 @@ TBD TBD ``` pnpm install -pnpm dev +pnpm play ``` ## References @@ -27,6 +32,5 @@ pnpm dev - naming: class name? - documentation -- playground publish to gh-pages (https://www.typescriptlang.org/dev/sandbox/) - package publish check auto-versioning schema - validation on responses and typing (use zod) diff --git a/package.json b/package.json index db33db2..f51ffaa 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,16 @@ "/dist" ], "scripts": { - "dist": "tsc", + "dist": "rm -rf dist/ && tsc", "compile": "tsc --noEmit --pretty", "prettier": "prettier src/", "prettier:fix": "prettier src/ --write", + "play": "pnpm dist && serve -c playground/serve.json", "test": "echo Warning: no test specified for now!" }, "devDependencies": { "prettier": "^3.1.0", + "serve": "^14.2.1", "typescript": "^5.3.2" }, "prettier": { diff --git a/playground/index.html b/playground/index.html new file mode 100644 index 0000000..1306b8d --- /dev/null +++ b/playground/index.html @@ -0,0 +1,9 @@ + + + + + +
Loading...
+
+ + diff --git a/playground/index.js b/playground/index.js new file mode 100644 index 0000000..e75270f --- /dev/null +++ b/playground/index.js @@ -0,0 +1,57 @@ +// First set up the VSCode loader in a script tag +const getLoaderScript = document.createElement('script') +getLoaderScript.src = 'https://www.typescriptlang.org/js/vs.loader.js' +getLoaderScript.async = true +getLoaderScript.onload = () => { + // Now the loader is ready, tell require where it can get the version of monaco, and the sandbox + // This version uses the latest version of the sandbox, which is used on the TypeScript website + + // For the monaco version you can use unpkg or the TypeSCript web infra CDN + // You can see the available releases for TypeScript here: + // https://typescript.azureedge.net/indexes/releases.json + // + require.config({ + paths: { + vs: 'https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs', + // vs: 'https://unpkg.com/@typescript-deploys/monaco-editor@4.0.5/min/vs', + sandbox: 'https://www.typescriptlang.org/js/sandbox', + }, + // This is something you need for monaco to work + ignoreDuplicateModules: ['vs/editor/editor.main'], + }) + + // Grab a copy of monaco, TypeScript and the sandbox + require(['vs/editor/editor.main', 'vs/language/typescript/tsWorker', 'sandbox/index'], ( + main, + _tsWorker, + sandboxFactory + ) => { + const initialCode = `import {CouchdDB} from "???"; + +const db = new CouchdDB("https://db.softver.org.mk/irclog/"); +let res = db.fetchChannelList(); +console.log(res); +` + const isOK = main && window.ts && sandboxFactory + if (isOK) { + document.getElementById('loader').parentNode.removeChild(document.getElementById('loader')) + } else { + console.error('Could not get all the dependencies of sandbox set up!') + console.error('main', !!main, 'ts', !!window.ts, 'sandbox', !!sandbox) + return + } + + // Create a sandbox and embed it into the div #monaco-editor-embed + const sandboxConfig = { + text: initialCode, + compilerOptions: {}, + domID: 'monaco-editor-embed', + } + + const sandbox = sandboxFactory.createTypeScriptSandbox(sandboxConfig, main, window.ts) + sandbox.editor.focus() + window.sandbox = sandbox; + }) +} + +document.body.appendChild(getLoaderScript) diff --git a/playground/serve.json b/playground/serve.json new file mode 100644 index 0000000..a67d81b --- /dev/null +++ b/playground/serve.json @@ -0,0 +1,9 @@ +{ + "rewrites": [ + { "source": "", "destination": "playground/index.html" }, + { "source": "index.html", "destination": "playground/index.html" }, + { "source": "index.js", "destination": "playground/index.js" }, + { "source": "dist/**", "destination": "dist/*" } + ], + "cleanUrls": false +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fcf8d08..d859758 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,20 +8,588 @@ devDependencies: prettier: specifier: ^3.1.0 version: 3.1.0 + serve: + specifier: ^14.2.1 + version: 14.2.1 typescript: specifier: ^5.3.2 version: 5.3.2 packages: + /@zeit/schemas@2.29.0: + resolution: {integrity: sha512-g5QiLIfbg3pLuYUJPlisNKY+epQJTcMDsOnVNkscrDP1oi7vmJnzOANYJI/1pZcVJ6umUkBv3aFtlg1UvUHGzA==} + dev: true + + /accepts@1.3.8: + resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==} + engines: {node: '>= 0.6'} + dependencies: + mime-types: 2.1.35 + negotiator: 0.6.3 + dev: true + + /ajv@8.11.0: + resolution: {integrity: sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==} + dependencies: + fast-deep-equal: 3.1.3 + json-schema-traverse: 1.0.0 + require-from-string: 2.0.2 + uri-js: 4.4.1 + dev: true + + /ansi-align@3.0.1: + resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} + dependencies: + string-width: 4.2.3 + dev: true + + /ansi-regex@5.0.1: + resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} + engines: {node: '>=8'} + dev: true + + /ansi-regex@6.0.1: + resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} + engines: {node: '>=12'} + dev: true + + /ansi-styles@4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + dependencies: + color-convert: 2.0.1 + dev: true + + /ansi-styles@6.2.1: + resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} + engines: {node: '>=12'} + dev: true + + /arch@2.2.0: + resolution: {integrity: sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==} + dev: true + + /arg@5.0.2: + resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==} + dev: true + + /balanced-match@1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + dev: true + + /boxen@7.0.0: + resolution: {integrity: sha512-j//dBVuyacJbvW+tvZ9HuH03fZ46QcaKvvhZickZqtB271DxJ7SNRSNxrV/dZX0085m7hISRZWbzWlJvx/rHSg==} + engines: {node: '>=14.16'} + dependencies: + ansi-align: 3.0.1 + camelcase: 7.0.1 + chalk: 5.0.1 + cli-boxes: 3.0.0 + string-width: 5.1.2 + type-fest: 2.19.0 + widest-line: 4.0.1 + wrap-ansi: 8.1.0 + dev: true + + /brace-expansion@1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + dev: true + + /bytes@3.0.0: + resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} + engines: {node: '>= 0.8'} + dev: true + + /camelcase@7.0.1: + resolution: {integrity: sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==} + engines: {node: '>=14.16'} + dev: true + + /chalk-template@0.4.0: + resolution: {integrity: sha512-/ghrgmhfY8RaSdeo43hNXxpoHAtxdbskUHjPpfqUWGttFgycUhYPGx3YZBCnUCvOa7Doivn1IZec3DEGFoMgLg==} + engines: {node: '>=12'} + dependencies: + chalk: 4.1.2 + dev: true + + /chalk@4.1.2: + resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + supports-color: 7.2.0 + dev: true + + /chalk@5.0.1: + resolution: {integrity: sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: true + + /cli-boxes@3.0.0: + resolution: {integrity: sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==} + engines: {node: '>=10'} + dev: true + + /clipboardy@3.0.0: + resolution: {integrity: sha512-Su+uU5sr1jkUy1sGRpLKjKrvEOVXgSgiSInwa/qeID6aJ07yh+5NWc3h2QfjHjBnfX4LhtFcuAWKUsJ3r+fjbg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + arch: 2.2.0 + execa: 5.1.1 + is-wsl: 2.2.0 + dev: true + + /color-convert@2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + dependencies: + color-name: 1.1.4 + dev: true + + /color-name@1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + dev: true + + /compressible@2.0.18: + resolution: {integrity: sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==} + engines: {node: '>= 0.6'} + dependencies: + mime-db: 1.52.0 + dev: true + + /compression@1.7.4: + resolution: {integrity: sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==} + engines: {node: '>= 0.8.0'} + dependencies: + accepts: 1.3.8 + bytes: 3.0.0 + compressible: 2.0.18 + debug: 2.6.9 + on-headers: 1.0.2 + safe-buffer: 5.1.2 + vary: 1.1.2 + transitivePeerDependencies: + - supports-color + dev: true + + /concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + dev: true + + /content-disposition@0.5.2: + resolution: {integrity: sha512-kRGRZw3bLlFISDBgwTSA1TMBFN6J6GWDeubmDE3AF+3+yXL8hTWv8r5rkLbqYXY4RjPk/EzHnClI3zQf1cFmHA==} + engines: {node: '>= 0.6'} + dev: true + + /cross-spawn@7.0.3: + resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} + engines: {node: '>= 8'} + dependencies: + path-key: 3.1.1 + shebang-command: 2.0.0 + which: 2.0.2 + dev: true + + /debug@2.6.9: + resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.0.0 + dev: true + + /deep-extend@0.6.0: + resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} + engines: {node: '>=4.0.0'} + dev: true + + /eastasianwidth@0.2.0: + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} + dev: true + + /emoji-regex@8.0.0: + resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + dev: true + + /emoji-regex@9.2.2: + resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} + dev: true + + /execa@5.1.1: + resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} + engines: {node: '>=10'} + dependencies: + cross-spawn: 7.0.3 + get-stream: 6.0.1 + human-signals: 2.1.0 + is-stream: 2.0.1 + merge-stream: 2.0.0 + npm-run-path: 4.0.1 + onetime: 5.1.2 + signal-exit: 3.0.7 + strip-final-newline: 2.0.0 + dev: true + + /fast-deep-equal@3.1.3: + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + dev: true + + /fast-url-parser@1.1.3: + resolution: {integrity: sha512-5jOCVXADYNuRkKFzNJ0dCCewsZiYo0dz8QNYljkOpFC6r2U4OBmKtvm/Tsuh4w1YYdDqDb31a8TVhBJ2OJKdqQ==} + dependencies: + punycode: 1.4.1 + dev: true + + /get-stream@6.0.1: + resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} + engines: {node: '>=10'} + dev: true + + /has-flag@4.0.0: + resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} + engines: {node: '>=8'} + dev: true + + /human-signals@2.1.0: + resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} + engines: {node: '>=10.17.0'} + dev: true + + /ini@1.3.8: + resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} + dev: true + + /is-docker@2.2.1: + resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} + engines: {node: '>=8'} + hasBin: true + dev: true + + /is-fullwidth-code-point@3.0.0: + resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + engines: {node: '>=8'} + dev: true + + /is-port-reachable@4.0.0: + resolution: {integrity: sha512-9UoipoxYmSk6Xy7QFgRv2HDyaysmgSG75TFQs6S+3pDM7ZhKTF/bskZV+0UlABHzKjNVhPjYCLfeZUEg1wXxig==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: true + + /is-stream@2.0.1: + resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} + engines: {node: '>=8'} + dev: true + + /is-wsl@2.2.0: + resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} + engines: {node: '>=8'} + dependencies: + is-docker: 2.2.1 + dev: true + + /isexe@2.0.0: + resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + dev: true + + /json-schema-traverse@1.0.0: + resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} + dev: true + + /merge-stream@2.0.0: + resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} + dev: true + + /mime-db@1.33.0: + resolution: {integrity: sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==} + engines: {node: '>= 0.6'} + dev: true + + /mime-db@1.52.0: + resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} + engines: {node: '>= 0.6'} + dev: true + + /mime-types@2.1.18: + resolution: {integrity: sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==} + engines: {node: '>= 0.6'} + dependencies: + mime-db: 1.33.0 + dev: true + + /mime-types@2.1.35: + resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} + engines: {node: '>= 0.6'} + dependencies: + mime-db: 1.52.0 + dev: true + + /mimic-fn@2.1.0: + resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} + engines: {node: '>=6'} + dev: true + + /minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + dependencies: + brace-expansion: 1.1.11 + dev: true + + /minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + dev: true + + /ms@2.0.0: + resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} + dev: true + + /negotiator@0.6.3: + resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} + engines: {node: '>= 0.6'} + dev: true + + /npm-run-path@4.0.1: + resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} + engines: {node: '>=8'} + dependencies: + path-key: 3.1.1 + dev: true + + /on-headers@1.0.2: + resolution: {integrity: sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==} + engines: {node: '>= 0.8'} + dev: true + + /onetime@5.1.2: + resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} + engines: {node: '>=6'} + dependencies: + mimic-fn: 2.1.0 + dev: true + + /path-is-inside@1.0.2: + resolution: {integrity: sha512-DUWJr3+ULp4zXmol/SZkFf3JGsS9/SIv+Y3Rt93/UjPpDpklB5f1er4O3POIbUuUJ3FXgqte2Q7SrU6zAqwk8w==} + dev: true + + /path-key@3.1.1: + resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} + engines: {node: '>=8'} + dev: true + + /path-to-regexp@2.2.1: + resolution: {integrity: sha512-gu9bD6Ta5bwGrrU8muHzVOBFFREpp2iRkVfhBJahwJ6p6Xw20SjT0MxLnwkjOibQmGSYhiUnf2FLe7k+jcFmGQ==} + dev: true + /prettier@3.1.0: resolution: {integrity: sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==} engines: {node: '>=14'} hasBin: true dev: true + /punycode@1.4.1: + resolution: {integrity: sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==} + dev: true + + /punycode@2.3.1: + resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} + engines: {node: '>=6'} + dev: true + + /range-parser@1.2.0: + resolution: {integrity: sha512-kA5WQoNVo4t9lNx2kQNFCxKeBl5IbbSNBl1M/tLkw9WCn+hxNBAW5Qh8gdhs63CJnhjJ2zQWFoqPJP2sK1AV5A==} + engines: {node: '>= 0.6'} + dev: true + + /rc@1.2.8: + resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} + hasBin: true + dependencies: + deep-extend: 0.6.0 + ini: 1.3.8 + minimist: 1.2.8 + strip-json-comments: 2.0.1 + dev: true + + /registry-auth-token@3.3.2: + resolution: {integrity: sha512-JL39c60XlzCVgNrO+qq68FoNb56w/m7JYvGR2jT5iR1xBrUA3Mfx5Twk5rqTThPmQKMWydGmq8oFtDlxfrmxnQ==} + dependencies: + rc: 1.2.8 + safe-buffer: 5.2.1 + dev: true + + /registry-url@3.1.0: + resolution: {integrity: sha512-ZbgR5aZEdf4UKZVBPYIgaglBmSF2Hi94s2PcIHhRGFjKYu+chjJdYfHn4rt3hB6eCKLJ8giVIIfgMa1ehDfZKA==} + engines: {node: '>=0.10.0'} + dependencies: + rc: 1.2.8 + dev: true + + /require-from-string@2.0.2: + resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} + engines: {node: '>=0.10.0'} + dev: true + + /safe-buffer@5.1.2: + resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==} + dev: true + + /safe-buffer@5.2.1: + resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: true + + /serve-handler@6.1.5: + resolution: {integrity: sha512-ijPFle6Hwe8zfmBxJdE+5fta53fdIY0lHISJvuikXB3VYFafRjMRpOffSPvCYsbKyBA7pvy9oYr/BT1O3EArlg==} + dependencies: + bytes: 3.0.0 + content-disposition: 0.5.2 + fast-url-parser: 1.1.3 + mime-types: 2.1.18 + minimatch: 3.1.2 + path-is-inside: 1.0.2 + path-to-regexp: 2.2.1 + range-parser: 1.2.0 + dev: true + + /serve@14.2.1: + resolution: {integrity: sha512-48er5fzHh7GCShLnNyPBRPEjs2I6QBozeGr02gaacROiyS/8ARADlj595j39iZXAqBbJHH/ivJJyPRWY9sQWZA==} + engines: {node: '>= 14'} + hasBin: true + dependencies: + '@zeit/schemas': 2.29.0 + ajv: 8.11.0 + arg: 5.0.2 + boxen: 7.0.0 + chalk: 5.0.1 + chalk-template: 0.4.0 + clipboardy: 3.0.0 + compression: 1.7.4 + is-port-reachable: 4.0.0 + serve-handler: 6.1.5 + update-check: 1.5.4 + transitivePeerDependencies: + - supports-color + dev: true + + /shebang-command@2.0.0: + resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} + engines: {node: '>=8'} + dependencies: + shebang-regex: 3.0.0 + dev: true + + /shebang-regex@3.0.0: + resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} + engines: {node: '>=8'} + dev: true + + /signal-exit@3.0.7: + resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + dev: true + + /string-width@4.2.3: + resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} + engines: {node: '>=8'} + dependencies: + emoji-regex: 8.0.0 + is-fullwidth-code-point: 3.0.0 + strip-ansi: 6.0.1 + dev: true + + /string-width@5.1.2: + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} + engines: {node: '>=12'} + dependencies: + eastasianwidth: 0.2.0 + emoji-regex: 9.2.2 + strip-ansi: 7.1.0 + dev: true + + /strip-ansi@6.0.1: + resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} + engines: {node: '>=8'} + dependencies: + ansi-regex: 5.0.1 + dev: true + + /strip-ansi@7.1.0: + resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} + engines: {node: '>=12'} + dependencies: + ansi-regex: 6.0.1 + dev: true + + /strip-final-newline@2.0.0: + resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} + engines: {node: '>=6'} + dev: true + + /strip-json-comments@2.0.1: + resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} + engines: {node: '>=0.10.0'} + dev: true + + /supports-color@7.2.0: + resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} + engines: {node: '>=8'} + dependencies: + has-flag: 4.0.0 + dev: true + + /type-fest@2.19.0: + resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} + engines: {node: '>=12.20'} + dev: true + /typescript@5.3.2: resolution: {integrity: sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==} engines: {node: '>=14.17'} hasBin: true dev: true + + /update-check@1.5.4: + resolution: {integrity: sha512-5YHsflzHP4t1G+8WGPlvKbJEbAJGCgw+Em+dGR1KmBUbr1J36SJBqlHLjR7oob7sco5hWHGQVcr9B2poIVDDTQ==} + dependencies: + registry-auth-token: 3.3.2 + registry-url: 3.1.0 + dev: true + + /uri-js@4.4.1: + resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + dependencies: + punycode: 2.3.1 + dev: true + + /vary@1.1.2: + resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} + engines: {node: '>= 0.8'} + dev: true + + /which@2.0.2: + resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} + engines: {node: '>= 8'} + hasBin: true + dependencies: + isexe: 2.0.0 + dev: true + + /widest-line@4.0.1: + resolution: {integrity: sha512-o0cyEG0e8GPzT4iGHphIOh0cJOV8fivsXxddQasHPHfoZf1ZexrfeA21w2NaEN1RHE+fXlfISmOE8R9N3u3Qig==} + engines: {node: '>=12'} + dependencies: + string-width: 5.1.2 + dev: true + + /wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + dependencies: + ansi-styles: 6.2.1 + string-width: 5.1.2 + strip-ansi: 7.1.0 + dev: true From 0d9d468a3d8ddb64da5e99d00cb478f2b418d8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Wed, 27 Dec 2023 03:20:13 +0100 Subject: [PATCH 02/31] compile to a single amd file for playground --- README.md | 2 +- package.json | 3 ++- playground/serve.json | 9 --------- 3 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 playground/serve.json diff --git a/README.md b/README.md index 76f20f9..a084162 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ pnpm add @irclogs/api TBD ``` pnpm install -pnpm play +pnpm run "/^play:.*/" ``` ## References diff --git a/package.json b/package.json index f51ffaa..10cf5ec 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "compile": "tsc --noEmit --pretty", "prettier": "prettier src/", "prettier:fix": "prettier src/ --write", - "play": "pnpm dist && serve -c playground/serve.json", + "play:watch": "tsc --outFile playground/dist/index.js --module amd --watch", + "play:serve": "serve playground/", "test": "echo Warning: no test specified for now!" }, "devDependencies": { diff --git a/playground/serve.json b/playground/serve.json deleted file mode 100644 index a67d81b..0000000 --- a/playground/serve.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "rewrites": [ - { "source": "", "destination": "playground/index.html" }, - { "source": "index.html", "destination": "playground/index.html" }, - { "source": "index.js", "destination": "playground/index.js" }, - { "source": "dist/**", "destination": "dist/*" } - ], - "cleanUrls": false -} From 24f099e6faabdab2c5e4c3267d9b3663e5b09d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Thu, 28 Dec 2023 20:17:55 +0100 Subject: [PATCH 03/31] add esbuild and make the playground run with it --- README.md | 2 +- package.json | 8 +- pnpm-lock.yaml | 257 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 254 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a084162..76f20f9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ pnpm add @irclogs/api TBD ``` pnpm install -pnpm run "/^play:.*/" +pnpm play ``` ## References diff --git a/package.json b/package.json index 10cf5ec..0c3eb71 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,14 @@ "compile": "tsc --noEmit --pretty", "prettier": "prettier src/", "prettier:fix": "prettier src/ --write", - "play:watch": "tsc --outFile playground/dist/index.js --module amd --watch", - "play:serve": "serve playground/", + "play": "esbuild src/index.ts --bundle --outdir=playground/dist --watch --servedir=playground", "test": "echo Warning: no test specified for now!" }, "devDependencies": { - "prettier": "^3.1.0", + "esbuild": "^0.19.10", + "prettier": "^3.1.1", "serve": "^14.2.1", - "typescript": "^5.3.2" + "typescript": "^5.3.3" }, "prettier": { "printWidth": 120, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d859758..70b0c31 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,18 +5,228 @@ settings: excludeLinksFromLockfile: false devDependencies: + esbuild: + specifier: ^0.19.10 + version: 0.19.10 prettier: - specifier: ^3.1.0 - version: 3.1.0 + specifier: ^3.1.1 + version: 3.1.1 serve: specifier: ^14.2.1 version: 14.2.1 typescript: - specifier: ^5.3.2 - version: 5.3.2 + specifier: ^5.3.3 + version: 5.3.3 packages: + /@esbuild/aix-ppc64@0.19.10: + resolution: {integrity: sha512-Q+mk96KJ+FZ30h9fsJl+67IjNJm3x2eX+GBWGmocAKgzp27cowCOOqSdscX80s0SpdFXZnIv/+1xD1EctFx96Q==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-arm64@0.19.10: + resolution: {integrity: sha512-1X4CClKhDgC3by7k8aOWZeBXQX8dHT5QAMCAQDArCLaYfkppoARvh0fit3X2Qs+MXDngKcHv6XXyQCpY0hkK1Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-arm@0.19.10: + resolution: {integrity: sha512-7W0bK7qfkw1fc2viBfrtAEkDKHatYfHzr/jKAHNr9BvkYDXPcC6bodtm8AyLJNNuqClLNaeTLuwURt4PRT9d7w==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-x64@0.19.10: + resolution: {integrity: sha512-O/nO/g+/7NlitUxETkUv/IvADKuZXyH4BHf/g/7laqKC4i/7whLpB0gvpPc2zpF0q9Q6FXS3TS75QHac9MvVWw==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/darwin-arm64@0.19.10: + resolution: {integrity: sha512-YSRRs2zOpwypck+6GL3wGXx2gNP7DXzetmo5pHXLrY/VIMsS59yKfjPizQ4lLt5vEI80M41gjm2BxrGZ5U+VMA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@esbuild/darwin-x64@0.19.10: + resolution: {integrity: sha512-alfGtT+IEICKtNE54hbvPg13xGBe4GkVxyGWtzr+yHO7HIiRJppPDhOKq3zstTcVf8msXb/t4eavW3jCDpMSmA==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@esbuild/freebsd-arm64@0.19.10: + resolution: {integrity: sha512-dMtk1wc7FSH8CCkE854GyGuNKCewlh+7heYP/sclpOG6Cectzk14qdUIY5CrKDbkA/OczXq9WesqnPl09mj5dg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/freebsd-x64@0.19.10: + resolution: {integrity: sha512-G5UPPspryHu1T3uX8WiOEUa6q6OlQh6gNl4CO4Iw5PS+Kg5bVggVFehzXBJY6X6RSOMS8iXDv2330VzaObm4Ag==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-arm64@0.19.10: + resolution: {integrity: sha512-QxaouHWZ+2KWEj7cGJmvTIHVALfhpGxo3WLmlYfJ+dA5fJB6lDEIg+oe/0//FuyVHuS3l79/wyBxbHr0NgtxJQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-arm@0.19.10: + resolution: {integrity: sha512-j6gUW5aAaPgD416Hk9FHxn27On28H4eVI9rJ4az7oCGTFW48+LcgNDBN+9f8rKZz7EEowo889CPKyeaD0iw9Kg==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-ia32@0.19.10: + resolution: {integrity: sha512-4ub1YwXxYjj9h1UIZs2hYbnTZBtenPw5NfXCRgEkGb0b6OJ2gpkMvDqRDYIDRjRdWSe/TBiZltm3Y3Q8SN1xNg==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-loong64@0.19.10: + resolution: {integrity: sha512-lo3I9k+mbEKoxtoIbM0yC/MZ1i2wM0cIeOejlVdZ3D86LAcFXFRdeuZmh91QJvUTW51bOK5W2BznGNIl4+mDaA==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-mips64el@0.19.10: + resolution: {integrity: sha512-J4gH3zhHNbdZN0Bcr1QUGVNkHTdpijgx5VMxeetSk6ntdt+vR1DqGmHxQYHRmNb77tP6GVvD+K0NyO4xjd7y4A==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-ppc64@0.19.10: + resolution: {integrity: sha512-tgT/7u+QhV6ge8wFMzaklOY7KqiyitgT1AUHMApau32ZlvTB/+efeCtMk4eXS+uEymYK249JsoiklZN64xt6oQ==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-riscv64@0.19.10: + resolution: {integrity: sha512-0f/spw0PfBMZBNqtKe5FLzBDGo0SKZKvMl5PHYQr3+eiSscfJ96XEknCe+JoOayybWUFQbcJTrk946i3j9uYZA==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-s390x@0.19.10: + resolution: {integrity: sha512-pZFe0OeskMHzHa9U38g+z8Yx5FNCLFtUnJtQMpwhS+r4S566aK2ci3t4NCP4tjt6d5j5uo4h7tExZMjeKoehAA==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-x64@0.19.10: + resolution: {integrity: sha512-SpYNEqg/6pZYoc+1zLCjVOYvxfZVZj6w0KROZ3Fje/QrM3nfvT2llI+wmKSrWuX6wmZeTapbarvuNNK/qepSgA==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/netbsd-x64@0.19.10: + resolution: {integrity: sha512-ACbZ0vXy9zksNArWlk2c38NdKg25+L9pr/mVaj9SUq6lHZu/35nx2xnQVRGLrC1KKQqJKRIB0q8GspiHI3J80Q==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/openbsd-x64@0.19.10: + resolution: {integrity: sha512-PxcgvjdSjtgPMiPQrM3pwSaG4kGphP+bLSb+cihuP0LYdZv1epbAIecHVl5sD3npkfYBZ0ZnOjR878I7MdJDFg==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/sunos-x64@0.19.10: + resolution: {integrity: sha512-ZkIOtrRL8SEJjr+VHjmW0znkPs+oJXhlJbNwfI37rvgeMtk3sxOQevXPXjmAPZPigVTncvFqLMd+uV0IBSEzqA==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-arm64@0.19.10: + resolution: {integrity: sha512-+Sa4oTDbpBfGpl3Hn3XiUe4f8TU2JF7aX8cOfqFYMMjXp6ma6NJDztl5FDG8Ezx0OjwGikIHw+iA54YLDNNVfw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-ia32@0.19.10: + resolution: {integrity: sha512-EOGVLK1oWMBXgfttJdPHDTiivYSjX6jDNaATeNOaCOFEVcfMjtbx7WVQwPSE1eIfCp/CaSF2nSrDtzc4I9f8TQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-x64@0.19.10: + resolution: {integrity: sha512-whqLG6Sc70AbU73fFYvuYzaE4MNMBIlR1Y/IrUeOXFrWHxBEjjbZaQ3IXIQS8wJdAzue2GwYZCjOrgrU1oUHoA==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@zeit/schemas@2.29.0: resolution: {integrity: sha512-g5QiLIfbg3pLuYUJPlisNKY+epQJTcMDsOnVNkscrDP1oi7vmJnzOANYJI/1pZcVJ6umUkBv3aFtlg1UvUHGzA==} dev: true @@ -222,6 +432,37 @@ packages: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: true + /esbuild@0.19.10: + resolution: {integrity: sha512-S1Y27QGt/snkNYrRcswgRFqZjaTG5a5xM3EQo97uNBnH505pdzSNe/HLBq1v0RO7iK/ngdbhJB6mDAp0OK+iUA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/aix-ppc64': 0.19.10 + '@esbuild/android-arm': 0.19.10 + '@esbuild/android-arm64': 0.19.10 + '@esbuild/android-x64': 0.19.10 + '@esbuild/darwin-arm64': 0.19.10 + '@esbuild/darwin-x64': 0.19.10 + '@esbuild/freebsd-arm64': 0.19.10 + '@esbuild/freebsd-x64': 0.19.10 + '@esbuild/linux-arm': 0.19.10 + '@esbuild/linux-arm64': 0.19.10 + '@esbuild/linux-ia32': 0.19.10 + '@esbuild/linux-loong64': 0.19.10 + '@esbuild/linux-mips64el': 0.19.10 + '@esbuild/linux-ppc64': 0.19.10 + '@esbuild/linux-riscv64': 0.19.10 + '@esbuild/linux-s390x': 0.19.10 + '@esbuild/linux-x64': 0.19.10 + '@esbuild/netbsd-x64': 0.19.10 + '@esbuild/openbsd-x64': 0.19.10 + '@esbuild/sunos-x64': 0.19.10 + '@esbuild/win32-arm64': 0.19.10 + '@esbuild/win32-ia32': 0.19.10 + '@esbuild/win32-x64': 0.19.10 + dev: true + /execa@5.1.1: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} @@ -386,8 +627,8 @@ packages: resolution: {integrity: sha512-gu9bD6Ta5bwGrrU8muHzVOBFFREpp2iRkVfhBJahwJ6p6Xw20SjT0MxLnwkjOibQmGSYhiUnf2FLe7k+jcFmGQ==} dev: true - /prettier@3.1.0: - resolution: {integrity: sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==} + /prettier@3.1.1: + resolution: {integrity: sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==} engines: {node: '>=14'} hasBin: true dev: true @@ -546,8 +787,8 @@ packages: engines: {node: '>=12.20'} dev: true - /typescript@5.3.2: - resolution: {integrity: sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==} + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} engines: {node: '>=14.17'} hasBin: true dev: true From c9267c8a8eef323ab7b98c50b13af4abe5d3afcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Thu, 28 Dec 2023 20:20:48 +0100 Subject: [PATCH 04/31] use monaco-editor directly the `https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs` one hasn't been updated more than 2 years. --- .github/workflows/playground.yml | 8 +- .gitignore | 2 + playground/README.md | 22 +++++ playground/example.ts | 8 ++ playground/favicon.ico | Bin 0 -> 1406 bytes playground/index.html | 42 +++++++- playground/index.js | 158 ++++++++++++++++++++----------- 7 files changed, 176 insertions(+), 64 deletions(-) create mode 100644 playground/README.md create mode 100644 playground/example.ts create mode 100644 playground/favicon.ico diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml index 7997fc8..74fadaa 100644 --- a/.github/workflows/playground.yml +++ b/.github/workflows/playground.yml @@ -2,7 +2,7 @@ name: Build Playground on: push: - branches: [main] + branches: [playground] workflow_dispatch: jobs: @@ -33,13 +33,13 @@ jobs: with: run_install: true - - run: pnpm dist/ - - run: cp playground/index.html dist/ + - run: esbuild src/index.ts --bundle --outdir=playground/dist + - run: pnpm tsc --emitDeclarationOnly src/index.ts --declaration --target esnext --declarationDir playground/types - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: - path: ./dist + path: ./playground - uses: actions/deploy-pages@v1 id: deployment diff --git a/.gitignore b/.gitignore index cdd7ad1..c05eb81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ dist/ +playground/types/ +playground/dist/ .tsbuildinfo diff --git a/playground/README.md b/playground/README.md new file mode 100644 index 0000000..8787289 --- /dev/null +++ b/playground/README.md @@ -0,0 +1,22 @@ +# TODO + +* load types in monaco-editor +* transpile to javascript (LSP?) +* load library in browser +* execute transpiled code +* redirect console.log to #console-output +* live-reload locally +- load other npm packages + +# Api Playground + +The api playground loads up monaco-editor and the types and code of the api libraries. Running it on localhost:8000 or +github … + + +# NOTES +``` +esbuild src/index.ts --bundle --outdir=playground/dist --watch --servedir=playground + +pnpm tsc --emitDeclarationOnly src/index.ts --declaration --target esnext --declarationDir playground/types +``` diff --git a/playground/example.ts b/playground/example.ts new file mode 100644 index 0000000..1583396 --- /dev/null +++ b/playground/example.ts @@ -0,0 +1,8 @@ +import {CouchDB} from "irclog-api"; + +type T = "a" | "B"; +let a: T = "a"; + +const db = new CouchDB("https://db.softver.org.mk", "irclog"); +let res = await db.fetchChannelList(); +console.log(res); diff --git a/playground/favicon.ico b/playground/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..6848441be374fc0a908926cea0be3bdfa815414d GIT binary patch literal 1406 zcmZQzU<5(|0R}M0U}azs1F|%L7$l?s#Ec9aKoZP=&`9k6|NkSzMp>gFFd71*Aut*O HM27$XOB)0R literal 0 HcmV?d00001 diff --git a/playground/index.html b/playground/index.html index 1306b8d..eee6eeb 100644 --- a/playground/index.html +++ b/playground/index.html @@ -1,9 +1,41 @@ - + - + + + Playground + + + + -
Loading...
-
- + +
+
+ +

+    
+ diff --git a/playground/index.js b/playground/index.js index e75270f..3a0e075 100644 --- a/playground/index.js +++ b/playground/index.js @@ -1,57 +1,105 @@ -// First set up the VSCode loader in a script tag -const getLoaderScript = document.createElement('script') -getLoaderScript.src = 'https://www.typescriptlang.org/js/vs.loader.js' -getLoaderScript.async = true -getLoaderScript.onload = () => { - // Now the loader is ready, tell require where it can get the version of monaco, and the sandbox - // This version uses the latest version of the sandbox, which is used on the TypeScript website - - // For the monaco version you can use unpkg or the TypeSCript web infra CDN - // You can see the available releases for TypeScript here: - // https://typescript.azureedge.net/indexes/releases.json - // - require.config({ - paths: { - vs: 'https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs', - // vs: 'https://unpkg.com/@typescript-deploys/monaco-editor@4.0.5/min/vs', - sandbox: 'https://www.typescriptlang.org/js/sandbox', - }, - // This is something you need for monaco to work - ignoreDuplicateModules: ['vs/editor/editor.main'], - }) - - // Grab a copy of monaco, TypeScript and the sandbox - require(['vs/editor/editor.main', 'vs/language/typescript/tsWorker', 'sandbox/index'], ( - main, - _tsWorker, - sandboxFactory - ) => { - const initialCode = `import {CouchdDB} from "???"; - -const db = new CouchdDB("https://db.softver.org.mk/irclog/"); -let res = db.fetchChannelList(); -console.log(res); -` - const isOK = main && window.ts && sandboxFactory - if (isOK) { - document.getElementById('loader').parentNode.removeChild(document.getElementById('loader')) - } else { - console.error('Could not get all the dependencies of sandbox set up!') - console.error('main', !!main, 'ts', !!window.ts, 'sandbox', !!sandbox) - return - } - - // Create a sandbox and embed it into the div #monaco-editor-embed - const sandboxConfig = { - text: initialCode, - compilerOptions: {}, - domID: 'monaco-editor-embed', - } - - const sandbox = sandboxFactory.createTypeScriptSandbox(sandboxConfig, main, window.ts) - sandbox.editor.focus() - window.sandbox = sandbox; - }) +/** + * Runs after monaco-editor library is loaded. + * Prepare model. + * Create editor. + * Configure the typescript language server. + */ +async function init() { + const example = await fetch('./example.ts'); + const exampleContent = await example.text(); + const uri = monaco.Uri.parse('http://localhost:3000/example.ts'); + const model = monaco.editor.createModel(exampleContent, 'typescript', uri); + + const editor = monaco.editor.create(document.getElementById('monaco-editor'), { + model: model, + theme: 'vs-light', + automaticLayout: true, + }); + editor.focus(); + + monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ + target: monaco.languages.typescript.ScriptTarget.ESNext, + module: monaco.languages.typescript.ModuleKind.ESNext, + allowNonTsExtensions: true, + }); + + document.getElementById('run-code').addEventListener('click', () => runCode(editor)); } -document.body.appendChild(getLoaderScript) +/** + * Run button handler + * + * @param {MonacoEditor} editor + */ +function runCode(editor) { + const code = editor.getValue(); + const outputElement = document.querySelector('#console-output'); + + try { + const result = ts.transpileModule(code, { + compilerOptions: { target: 'es2022', module: 'es2022', }, + reportDiagnostics: true, + }); + const transpiledCode = result.outputText + .replace(/^[:space:]*import.*from.*irclog-api.*/, `import {CouchDB} from "./dist/index.js"`) + + createModule(transpiledCode, '#console-output'); + + outputElement.innerText = 'Code executed successfully'; + } catch (error) { + outputElement.innerText += `Error: ${error.message}\n`; + } + outputElement.scrollTo({top: outputElement.scrollHeight}); +} + +/** + * Poor mans sandbox/eval implementation. + * + * Create a From 58973003fb980ccaaf95a3be79b1f79ee625d877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 17:30:06 +0100 Subject: [PATCH 09/31] debounced autosave on keyDown and ctrl-s saves --- playground/index.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/playground/index.js b/playground/index.js index 3a0e075..a83bb91 100644 --- a/playground/index.js +++ b/playground/index.js @@ -5,10 +5,13 @@ * Configure the typescript language server. */ async function init() { - const example = await fetch('./example.ts'); - const exampleContent = await example.text(); + let exampleCode = localStorage.getItem("example.ts"); + if (!exampleCode) { + const req = await fetch('./example.ts'); + exampleCode = await req.text(); + } const uri = monaco.Uri.parse('http://localhost:3000/example.ts'); - const model = monaco.editor.createModel(exampleContent, 'typescript', uri); + const model = monaco.editor.createModel(exampleCode, 'typescript', uri); const editor = monaco.editor.create(document.getElementById('monaco-editor'), { model: model, @@ -23,9 +26,23 @@ async function init() { allowNonTsExtensions: true, }); + const debouncedSave = debounce(() => save(editor), 1000); + editor.onKeyDown((ev) => { + if (ev.keyCode === 49 /** KeyCode.KeyS */ && ev.ctrlKey) { + ev.preventDefault(); + save(editor); + } else { + debouncedSave() + } + }); + document.getElementById('run-code').addEventListener('click', () => runCode(editor)); } +function save(editor) { + localStorage.setItem("example.ts", editor.getModel().getValue()); +} + /** * Run button handler * @@ -103,3 +120,18 @@ require(['vs/editor/editor.main'], function () { if (window.location.hostname == 'localhost') { new EventSource('/esbuild').addEventListener('change', () => location.reload()); } + +/** + * poor-mans debounce + * + * @param {()=>void} callback + * @param {number} delay + * @returns ()=>void + */ +function debounce(callback, delay) { + let timer; + return function () { + if (timer) clearTimeout(timer); + timer = setTimeout(callback, delay); + } +} From 8fe7f671a2a8652723bdb0ec6ea858d0d0b2fd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 17:31:10 +0100 Subject: [PATCH 10/31] autoformat --- playground/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/playground/index.js b/playground/index.js index a83bb91..735dbe4 100644 --- a/playground/index.js +++ b/playground/index.js @@ -58,7 +58,7 @@ function runCode(editor) { reportDiagnostics: true, }); const transpiledCode = result.outputText - .replace(/^[:space:]*import.*from.*irclog-api.*/, `import {CouchDB} from "./dist/index.js"`) + .replace(/^[:space:]*import.*from.*irclog-api.*/, `import {CouchDB} from "./dist/index.js"`) createModule(transpiledCode, '#console-output'); @@ -66,7 +66,7 @@ function runCode(editor) { } catch (error) { outputElement.innerText += `Error: ${error.message}\n`; } - outputElement.scrollTo({top: outputElement.scrollHeight}); + outputElement.scrollTo({ top: outputElement.scrollHeight }); } /** @@ -102,10 +102,10 @@ function createModule(code, consoleSelector) { // Load the Monaco Editor require.config({ - paths: { - vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs', - // 'irclog-api': './dist/index.js', - } + paths: { + vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs', + // 'irclog-api': './dist/index.js', + } }); require(['vs/editor/editor.main'], function () { From b7ae12fb5337969d5ff522cb8d541f5f7bfabab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 17:31:50 +0100 Subject: [PATCH 11/31] global window.monacoEditor for debugging around --- playground/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/playground/index.js b/playground/index.js index 735dbe4..529ba18 100644 --- a/playground/index.js +++ b/playground/index.js @@ -19,6 +19,8 @@ async function init() { automaticLayout: true, }); editor.focus(); + // make it global for debugging + window.monacoEditor = editor; monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ target: monaco.languages.typescript.ScriptTarget.ESNext, From d0ae4d929f7e17755fe512964f6fdd0a30573b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 17:32:13 +0100 Subject: [PATCH 12/31] side-by-side layout --- playground/index.html | 97 +++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/playground/index.html b/playground/index.html index 27df3ef..946a54e 100644 --- a/playground/index.html +++ b/playground/index.html @@ -1,42 +1,69 @@ - - - - Playground - - - - - - - -
-
- + } + + + + +
+
+
+
+
+

     
- +
+ + From 4f5b4575f9028c487bc694bd523a1b87a0f63e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 17:34:32 +0100 Subject: [PATCH 13/31] configure typescriptDefaults first thing in init() --- playground/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/playground/index.js b/playground/index.js index 529ba18..aed9160 100644 --- a/playground/index.js +++ b/playground/index.js @@ -5,6 +5,12 @@ * Configure the typescript language server. */ async function init() { + monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ + target: monaco.languages.typescript.ScriptTarget.ESNext, + module: monaco.languages.typescript.ModuleKind.ESNext, + allowNonTsExtensions: true, + }); + let exampleCode = localStorage.getItem("example.ts"); if (!exampleCode) { const req = await fetch('./example.ts'); @@ -22,12 +28,6 @@ async function init() { // make it global for debugging window.monacoEditor = editor; - monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ - target: monaco.languages.typescript.ScriptTarget.ESNext, - module: monaco.languages.typescript.ModuleKind.ESNext, - allowNonTsExtensions: true, - }); - const debouncedSave = debounce(() => save(editor), 1000); editor.onKeyDown((ev) => { if (ev.keyCode === 49 /** KeyCode.KeyS */ && ev.ctrlKey) { From dc1705ed49e7980ad557e6099f05b0a2c4937228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 20:04:31 +0100 Subject: [PATCH 14/31] load types in the monaco editor now it knows the type of CouchDB had to change the uri of the model so it looks for files in the virtual file:/// path --- playground/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/playground/index.js b/playground/index.js index aed9160..7733eb8 100644 --- a/playground/index.js +++ b/playground/index.js @@ -11,12 +11,19 @@ async function init() { allowNonTsExtensions: true, }); + // FIXME: auto-detect all types + for (const lib of ["index.d.ts", "couch-api.d.ts", "types.d.ts", "post-query.d.ts"]) { + const req = await fetch(`./types/${lib}`); + const content = await req.text(); + monaco.languages.typescript.typescriptDefaults.addExtraLib(content, `file:///node_modules/@types/irclog-api/${lib}`); + } + let exampleCode = localStorage.getItem("example.ts"); if (!exampleCode) { const req = await fetch('./example.ts'); exampleCode = await req.text(); } - const uri = monaco.Uri.parse('http://localhost:3000/example.ts'); + const uri = monaco.Uri.parse('file:///example.ts'); const model = monaco.editor.createModel(exampleCode, 'typescript', uri); const editor = monaco.editor.create(document.getElementById('monaco-editor'), { From fd1c3d6015db582a6c6a5936004d9ce72440234b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 20:20:58 +0100 Subject: [PATCH 15/31] increase autosave delay to 5s --- playground/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/index.js b/playground/index.js index 7733eb8..55b78a8 100644 --- a/playground/index.js +++ b/playground/index.js @@ -35,7 +35,7 @@ async function init() { // make it global for debugging window.monacoEditor = editor; - const debouncedSave = debounce(() => save(editor), 1000); + const debouncedSave = debounce(() => save(editor), 5000); editor.onKeyDown((ev) => { if (ev.keyCode === 49 /** KeyCode.KeyS */ && ev.ctrlKey) { ev.preventDefault(); From 82d4f8220d5bfe0384a53e32a9cdd78fb433cfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 20:34:54 +0100 Subject: [PATCH 16/31] download in parallel (Promise.all) --- playground/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/playground/index.js b/playground/index.js index 55b78a8..ceab5cc 100644 --- a/playground/index.js +++ b/playground/index.js @@ -12,11 +12,15 @@ async function init() { }); // FIXME: auto-detect all types - for (const lib of ["index.d.ts", "couch-api.d.ts", "types.d.ts", "post-query.d.ts"]) { - const req = await fetch(`./types/${lib}`); + const types = ["index.d.ts", "couch-api.d.ts", "types.d.ts", "post-query.d.ts"]; + (await Promise.all(types.map(async (dts) => { + const req = await fetch(`./types/${dts}`); const content = await req.text(); - monaco.languages.typescript.typescriptDefaults.addExtraLib(content, `file:///node_modules/@types/irclog-api/${lib}`); - } + return [content, `file:///node_modules/@types/irclog-api/${dts}`] + }))) + .forEach(([content, path]) => { + monaco.languages.typescript.typescriptDefaults.addExtraLib(content, path); + }); let exampleCode = localStorage.getItem("example.ts"); if (!exampleCode) { From c8421055d29c6c1cc661e19622744e3631c2331a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sat, 30 Dec 2023 20:49:11 +0100 Subject: [PATCH 17/31] get javascript from the typescript worker --- playground/index.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/playground/index.js b/playground/index.js index ceab5cc..372d731 100644 --- a/playground/index.js +++ b/playground/index.js @@ -59,26 +59,16 @@ function save(editor) { /** * Run button handler * - * @param {MonacoEditor} editor */ -function runCode(editor) { - const code = editor.getValue(); - const outputElement = document.querySelector('#console-output'); - - try { - const result = ts.transpileModule(code, { - compilerOptions: { target: 'es2022', module: 'es2022', }, - reportDiagnostics: true, - }); - const transpiledCode = result.outputText - .replace(/^[:space:]*import.*from.*irclog-api.*/, `import {CouchDB} from "./dist/index.js"`) +async function runCode() { - createModule(transpiledCode, '#console-output'); + const worker = await monaco.languages.typescript.getTypeScriptWorker(); + const client = await worker(); + const output = await client.getEmitOutput("file:///example.ts"); + const js = output.outputFiles[0].text; - outputElement.innerText = 'Code executed successfully'; - } catch (error) { - outputElement.innerText += `Error: ${error.message}\n`; - } + const outputElement = document.querySelector('#console-output'); + outputElement.innerText = js; outputElement.scrollTo({ top: outputElement.scrollHeight }); } From e93575a0d74f070d1e99bff959f2569b4a528da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sun, 31 Dec 2023 15:59:07 +0100 Subject: [PATCH 18/31] browser importmap: point "irclog-api" -> "./dist/index.js" https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap --- playground/index.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/playground/index.html b/playground/index.html index 946a54e..3bc6ec3 100644 --- a/playground/index.html +++ b/playground/index.html @@ -6,9 +6,16 @@ Playground - + + @@ -67,7 +68,7 @@
-
+

     
diff --git a/playground/playground.js b/playground/playground.js index c4fc347..478176a 100644 --- a/playground/playground.js +++ b/playground/playground.js @@ -50,6 +50,7 @@ async function init() { }); document.getElementById('run-code').addEventListener('click', () => runCode(editor)); + document.getElementById('clear-log').addEventListener('click', () => document.querySelector('#console-output').innerText = ''); } function save(editor) { From 05b74ff648aa4fc04eb78dff4489b8333a94737c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Mon, 1 Jan 2024 02:36:56 +0100 Subject: [PATCH 25/31] add dts-bundle to create a single "bundled" index.d.ts file --- package.json | 3 +- pnpm-lock.yaml | 131 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index df8ee1a..a2070b6 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,11 @@ "prettier:fix": "prettier src/ --write", "play": "esbuild src/index.ts --bundle --outdir=playground/dist --watch --servedir=playground --format=esm", "playground:dist": "esbuild src/index.ts --bundle --outdir=playground/dist --format=esm", - "playground:types": "tsc --emitDeclarationOnly src/index.ts --declaration --target esnext --declarationDir playground/types", + "playground:types": "dts-bundle --name @irclogs/api --baseDir ./dist/ --main dist/index.d.ts --out $PWD/playground/dist/index.d.ts", "test": "echo Warning: no test specified for now!" }, "devDependencies": { + "dts-bundle": "^0.7.3", "esbuild": "^0.19.10", "prettier": "^3.1.1", "typescript": "^5.3.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 51f4288..cf14759 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false devDependencies: + dts-bundle: + specifier: ^0.7.3 + version: 0.7.3 esbuild: specifier: ^0.19.10 version: 0.19.10 @@ -224,6 +227,72 @@ packages: dev: true optional: true + /@types/detect-indent@0.1.30: + resolution: {integrity: sha512-AUmj9JHuHTD94slY1WR1VulFxRGC6D1pcNCN0MCulKFyiihvV/28lLS8oRHgfmc2Cxq954J8Vmosa8qzm7PLGQ==} + dev: true + + /@types/glob@5.0.30: + resolution: {integrity: sha512-ZM05wDByI+WA153sfirJyEHoYYoIuZ7lA2dB/Gl8ymmpMTR78fNRtDMqa7Z6SdH4fZdLWZNRE6mZpx3XqBOrHw==} + dependencies: + '@types/minimatch': 5.1.2 + '@types/node': 8.0.0 + dev: true + + /@types/minimatch@5.1.2: + resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} + dev: true + + /@types/mkdirp@0.3.29: + resolution: {integrity: sha512-QRLQpFsIQGO2k8pupga9abfei85GKotAtQ+F6xuQmSGomUt6C52TyMiTFpP8kUwuPKr00gNtu3itLlC6gvI/NA==} + dev: true + + /@types/node@8.0.0: + resolution: {integrity: sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A==} + dev: true + + /balanced-match@1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + dev: true + + /brace-expansion@1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + dev: true + + /commander@2.20.3: + resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} + dev: true + + /concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + dev: true + + /detect-indent@0.2.0: + resolution: {integrity: sha512-C6jyrDu/eGH4KT0ZxAzijiH+ts5YLy7DqGFoDuHGxZjMOdjzRltp3jByySnpFBVIy4Em0ZkLN8tIV6mcREdw5A==} + engines: {node: '>=0.10.0'} + hasBin: true + dependencies: + get-stdin: 0.1.0 + minimist: 0.1.0 + dev: true + + /dts-bundle@0.7.3: + resolution: {integrity: sha512-EEAEuPRk8QyKhoN90NHTh+spSQujkkvOnKWUfuzpmC/fgryiWopL1SegSktx0UsoPfNidIGVDN7/AXpBDBv0WQ==} + engines: {node: '>= 0.10.0'} + hasBin: true + dependencies: + '@types/detect-indent': 0.1.30 + '@types/glob': 5.0.30 + '@types/mkdirp': 0.3.29 + '@types/node': 8.0.0 + commander: 2.20.3 + detect-indent: 0.2.0 + glob: 6.0.4 + mkdirp: 0.5.6 + dev: true + /esbuild@0.19.10: resolution: {integrity: sha512-S1Y27QGt/snkNYrRcswgRFqZjaTG5a5xM3EQo97uNBnH505pdzSNe/HLBq1v0RO7iK/ngdbhJB6mDAp0OK+iUA==} engines: {node: '>=12'} @@ -255,6 +324,64 @@ packages: '@esbuild/win32-x64': 0.19.10 dev: true + /get-stdin@0.1.0: + resolution: {integrity: sha512-/WBu3IaQZxE3bs3BhBmR10ipDY4pjN+U4EZgXULa1eqKA0B/Lka/MVoAqhTVYBkkRlCrEGDOU9itrzIgm9Ksng==} + engines: {node: '>=0.10.0'} + dev: true + + /glob@6.0.4: + resolution: {integrity: sha512-MKZeRNyYZAVVVG1oZeLaWie1uweH40m9AZwIwxyPbTSX4hHrVYSzLg0Ro5Z5R7XKkIX+Cc6oD1rqeDJnwsB8/A==} + dependencies: + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 3.1.2 + once: 1.4.0 + path-is-absolute: 1.0.1 + dev: true + + /inflight@1.0.6: + resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + dependencies: + once: 1.4.0 + wrappy: 1.0.2 + dev: true + + /inherits@2.0.4: + resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: true + + /minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + dependencies: + brace-expansion: 1.1.11 + dev: true + + /minimist@0.1.0: + resolution: {integrity: sha512-wR5Ipl99t0mTGwLjQJnBjrP/O7zBbLZqvA3aw32DmLx+nXHfWctUjzDjnDx09pX1Po86WFQazF9xUzfMea3Cnw==} + dev: true + + /minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + dev: true + + /mkdirp@0.5.6: + resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} + hasBin: true + dependencies: + minimist: 1.2.8 + dev: true + + /once@1.4.0: + resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + dependencies: + wrappy: 1.0.2 + dev: true + + /path-is-absolute@1.0.1: + resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} + engines: {node: '>=0.10.0'} + dev: true + /prettier@3.1.1: resolution: {integrity: sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==} engines: {node: '>=14'} @@ -266,3 +393,7 @@ packages: engines: {node: '>=14.17'} hasBin: true dev: true + + /wrappy@1.0.2: + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + dev: true From c29c2f168605d1160d6a87751fd049b672df0d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Mon, 1 Jan 2024 02:37:35 +0100 Subject: [PATCH 26/31] load a single bundled index.d.ts file instead of the separate files generated with `tsc`. also use `@irclogs/api` as the module name everywhere, as is the package name --- playground/example.ts | 2 +- playground/index.html | 2 +- playground/playground.js | 20 +++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/playground/example.ts b/playground/example.ts index 495fc4e..a3d4556 100644 --- a/playground/example.ts +++ b/playground/example.ts @@ -1,4 +1,4 @@ -import {CouchDB} from "irclog-api"; +import {CouchDB} from "@irclogs/api"; type T = "a" | "B"; let a: T = "a"; diff --git a/playground/index.html b/playground/index.html index a3c0600..ddd1052 100644 --- a/playground/index.html +++ b/playground/index.html @@ -11,7 +11,7 @@ diff --git a/playground/playground.js b/playground/playground.js index 478176a..9f8899f 100644 --- a/playground/playground.js +++ b/playground/playground.js @@ -11,18 +11,12 @@ async function init() { allowNonTsExtensions: true, }); - // FIXME: auto-detect all types - const types = ["index.d.ts", "couch-api.d.ts", "types.d.ts", "post-query.d.ts"]; - (await Promise.all(types.map(async (dts) => { - const req = await fetch(`./types/${dts}`); - const content = await req.text(); - return [content, `file:///node_modules/@types/irclog-api/${dts}`] - }))) - .forEach(([content, path]) => { - monaco.languages.typescript.typescriptDefaults.addExtraLib(content, path); - }); + const req = await fetch('./dist/index.d.ts'); + const content = await req.text(); + const path = 'file:///node_modules/@types/@irclogs/api/index.d.ts'; + monaco.languages.typescript.typescriptDefaults.addExtraLib(content, path); - let exampleCode = localStorage.getItem("example.ts"); + let exampleCode = localStorage.getItem("file:///example.ts"); if (!exampleCode) { const req = await fetch('./example.ts'); exampleCode = await req.text(); @@ -54,7 +48,7 @@ async function init() { } function save(editor) { - localStorage.setItem("example.ts", editor.getModel().getValue()); + localStorage.setItem("file:///example.ts", editor.getModel().getValue()); } /** @@ -62,6 +56,7 @@ function save(editor) { * */ async function runCode() { + // I have no idea how this works const worker = await monaco.languages.typescript.getTypeScriptWorker(); const client = await worker(); const output = await client.getEmitOutput("file:///example.ts"); @@ -108,7 +103,6 @@ function createModule(code, consoleSelector) { require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs', - // 'irclog-api': './dist/index.js', } }); From db801ca26f62cbf9e1c15496529c61d123cf010c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Mon, 1 Jan 2024 02:57:48 +0100 Subject: [PATCH 27/31] load the vs.loader from cdnjs too, it's newer too --- playground/index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/playground/index.html b/playground/index.html index ddd1052..bfce623 100644 --- a/playground/index.html +++ b/playground/index.html @@ -6,7 +6,12 @@ Playground - +