From ac32b03ee6b9e5e7732af5ce4b695b68bc12cd32 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 27 Sep 2023 17:05:10 +0900 Subject: [PATCH] fix: tweak module exporting --- README.md | 26 ++++++++++++++------------ build.config.ts | 19 +------------------ package.json | 23 ++++++++++++----------- src/env.d.ts | 2 -- src/index.ts | 1 + 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index a3a65b0..9c53fb9 100644 --- a/README.md +++ b/README.md @@ -132,13 +132,9 @@ You can do `import { ... } from '@intlify/utils'` the above utilities - `getNavigatorLanguages` - `getNavigatorLanguage` -You can do `import { ... } from '@intlify/utils/{ENV}'` the above utilities. - -The namespace `{ENV}` is one of the following: +You can do `import { ... } from '@intlify/utils'` the above utilities -- `node`: Node.js -- `web`: JS environments (such as Deno, Bun, and Browser) supporting Web APIs - (`navigator.language(s)`) +> ⚠NOTE: for Node.js You need to do `import { ... } from '@intlify/utils/node'` ### HTTP @@ -149,15 +145,21 @@ The namespace `{ENV}` is one of the following: - `getCookieLocale` - `setCookieLocale` -You can do `import { ... } from '@intlify/utils/{ENV}'` the above utilities. +The about utilies functions accpet Web APIs such as +[Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and +[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) that is +supported by JS environments (such as Deno, Bun, and Browser) + +#### Specialized environments + +If you will use Node.js and H3, You can do +`import { ... } from '@intlify/utils/{ENV}'` the above utilities. The namespace `{ENV}` is one of the following: -- `node`: Node.js -- `web`: JS environments (such as Deno, Bun, and Browser) supporting Web APIs - such as [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) - and [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) -- `h3`: HTTP framework [h3](https://github.com/unjs/h3) +- `node`: accpet `IncomingMessage` and `Outgoing` by Node.js + [http](https://nodejs.org/api/http.html) module +- `h3`: accept `H3Event` by HTTP framework [h3](https://github.com/unjs/h3) ## 🙌 Contributing guidelines diff --git a/build.config.ts b/build.config.ts index ddee8e5..5c44a48 100644 --- a/build.config.ts +++ b/build.config.ts @@ -3,7 +3,7 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ declaration: true, replace: { - 'import.meta.vitest': undefined, + 'import.meta.vitest': 'false', }, rollup: { emitCJS: true, @@ -19,23 +19,6 @@ export default defineBuildConfig({ { input: './src/node.ts', }, - { - input: './src/web.ts', - }, ], externals: ['h3'], - hooks: { - 'rollup:options': (_ctx, options) => { - // deno-lint-ignore no-explicit-any - ;(options.plugins as any).push({ - name: 'workaround-strip-in-source-test', - transform(code: string, _id: string) { - return { - code: code.replace(/import.meta.vitest/g, 'false'), - map: null, - } - }, - }) - }, - }, }) diff --git a/package.json b/package.json index a69429b..0481ab9 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "email": "kawakazu80@gmail.com" }, "license": "MIT", + "funding": "https://github.com/sponsors/kazupon", "bugs": { "url": "https://github.com/intlify/utils/issues" }, @@ -21,9 +22,6 @@ "url": "git+https://github.com/intlify/utils.git" }, "homepage": "https://github.com/intlify/utils#readme", - "files": [ - "dist" - ], "publishConfig": { "access": "public" }, @@ -31,6 +29,7 @@ "node": ">= 18" }, "type": "module", + "sideEffects": false, "main": "dist/index.cjs", "module": "dist/index.mjs", "types": "dist/index.d.ts", @@ -38,26 +37,28 @@ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", - "require": "./dist/index.cjs" + "require": "./dist/index.cjs", + "browser": "./dist/index.mjs", + "default": "./dist/index.mjs" }, "./h3": { "types": "./dist/h3.d.ts", "import": "./dist/h3.mjs", - "require": "./dist/h3.cjs" + "require": "./dist/h3.cjs", + "default": "./dist/h3.mjs" }, "./node": { "types": "./dist/node.d.ts", "import": "./dist/node.mjs", - "require": "./dist/node.cjs" - }, - "./web": { - "types": "./dist/web.d.ts", - "import": "./dist/web.mjs", - "require": "./dist/web.cjs" + "require": "./dist/node.cjs", + "default": "./dist/node.mjs" }, "./dist/*": "./dist/*", "./package.json": "./package.json" }, + "files": [ + "dist" + ], "scripts": { "prepare": "git config --local core.hooksPath .githooks", "changelog": "gh-changelogen --repo=intlify/utils", diff --git a/src/env.d.ts b/src/env.d.ts index d16960f..c8f7bad 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -6,5 +6,3 @@ declare namespace NodeJS { LANGUAGE?: string } } - -declare let __TEST__: boolean diff --git a/src/index.ts b/src/index.ts index 34e93b5..bd768da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,2 @@ export * from './shared.ts' +export * from './web.ts'