From 8d0c7c7a06dffc8c8c13fa594515f73b5cd37883 Mon Sep 17 00:00:00 2001 From: sugoidogo Date: Tue, 20 Jan 2026 00:54:08 -0800 Subject: [PATCH] initial release --- .gitea/workflows/publish.yaml | 17 +++++++++++++++++ .gitignore | 3 +++ LICENSE | 21 +++++++++++++++++++++ README.md | 21 +++++++++++++++++++++ package-lock.json | 27 +++++++++++++++++++++++++++ package.json | 13 +++++++++++++ src/main.ts | 12 ++++++++++++ tsconfig.json | 6 ++++++ 8 files changed, 120 insertions(+) create mode 100644 .gitea/workflows/publish.yaml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/main.ts create mode 100644 tsconfig.json diff --git a/.gitea/workflows/publish.yaml b/.gitea/workflows/publish.yaml new file mode 100644 index 0000000..2095ffe --- /dev/null +++ b/.gitea/workflows/publish.yaml @@ -0,0 +1,17 @@ +on: + push: + tags: + - "*" + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - run: npm ci + - run: npm version from-git --allow-same-version --no-git-tag-version + - run: npm config set registry https://gitea.sugoidogo.com/api/packages/sugoidogo/npm/ + - run: npm config set -- '//gitea.sugoidogo.com/api/packages/sugoidogo/npm/:_authToken' "$PACKAGES_KEY" + env: + PACKAGES_KEY: ${{ secrets.PACKAGES_KEY }} + - run: npm publish diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c58c7db --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +*.tgz \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9e841e7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE diff --git a/README.md b/README.md new file mode 100644 index 0000000..c55ce72 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Node Web Globals + +These types are copied (literally) from the web-globals folder of `@types/node` to provide types that are compatible with both web and node for developing libraries that are compatible with both web and node. + +# Usage + +To prevent tsc from importing the default `Dom` library, add the `compilerOptions` key `lib` with value `ESNext` (or whatever version you're targeting, such as `ES2022`). + +
tsconfig.json + +```json +{ + "compilerOptions":{ + "module":"esnext", + "moduleResolution":"node", + "lib":["ESNext"] + } +} +``` + +
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..62123e4 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "node-web-globals", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "@types/node": "^25.0.9" + } + }, + "node_modules/@types/node": { + "version": "25.0.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.9.tgz", + "integrity": "sha512-/rpCXHlCWeqClNBwUhDcusJxXYDjZTyE8v5oTO7WbL8eij2nKhUeU89/6xgjU7N4/Vh3He0BtyhJdQbDyhiXAw==", + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..263f223 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name":"@sugoidogo/node-web-globals", + "version": "0.0.0", + "type": "module", + "files": ["dist/"], + "types": "dist/index.d.ts", + "scripts": { + "prepack": "node src/main.ts" + }, + "devDependencies": { + "@types/node": "^25.0.9" + } +} diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..4b7bf08 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,12 @@ +import * as fs from 'node:fs' + +fs.cpSync('node_modules/@types/node/web-globals','dist',{recursive:true}) +fs.cpSync('node_modules/@types/node/LICENSE', 'LICENSE') +const node_types_index = fs.readFileSync('node_modules/@types/node/index.d.ts').toString() +let globals_types_index = '' +for (const line of node_types_index.split('\n')) { + if (line.includes('path="web-globals/')) { + globals_types_index+=line.replace('path="web-globals/','path="')+'\n' + } +} +fs.writeFileSync('dist/index.d.ts',globals_types_index) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..77c3bcc --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "node" + } +} \ No newline at end of file