Skip to content

Commit

Permalink
fix: tweak module exporting (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Sep 27, 2023
1 parent 1c87e31 commit da0eec5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 43 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
19 changes: 1 addition & 18 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
},
})
},
},
})
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"email": "[email protected]"
},
"license": "MIT",
"funding": "https://github.com/sponsors/kazupon",
"bugs": {
"url": "https://github.com/intlify/utils/issues"
},
Expand All @@ -21,43 +22,43 @@
"url": "git+https://github.com/intlify/utils.git"
},
"homepage": "https://github.com/intlify/utils#readme",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 18"
},
"type": "module",
"sideEffects": false,
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"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",
Expand Down
2 changes: 0 additions & 2 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ declare namespace NodeJS {
LANGUAGE?: string
}
}

declare let __TEST__: boolean
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './shared.ts'
export * from './web.ts'

0 comments on commit da0eec5

Please sign in to comment.