Skip to content

Commit

Permalink
feat: Add temporary dedicated server features imports
Browse files Browse the repository at this point in the history
This allows using the serializer and the parsers in server-side code without
depending on React for the cache, as would be the case if importing
from `nuqs/server`.

Closes #804. See also discussion #717.
  • Loading branch information
franky47 committed Dec 12, 2024
1 parent 1635863 commit 6d868dd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/nuqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"files": [
"dist/",
"server.d.ts",
"server/cache.d.ts",
"server/serializer.d.ts",
"server/parsers.d.ts",
"adapters/react.d.ts",
"adapters/next.d.ts",
"adapters/next/app.d.ts",
Expand All @@ -58,6 +61,21 @@
"import": "./dist/server.js",
"require": "./esm-only.cjs"
},
"./server/cache": {
"types": "./dist/server/cache.d.ts",
"import": "./dist/server/cache.js",
"require": "./esm-only.cjs"
},
"./server/serializer": {
"types": "./dist/server/serializer.d.ts",
"import": "./dist/server/serializer.js",
"require": "./esm-only.cjs"
},
"./server/parsers": {
"types": "./dist/server/parsers.d.ts",
"import": "./dist/server/parsers.js",
"require": "./esm-only.cjs"
},
"./adapters/react": {
"types": "./dist/adapters/react.d.ts",
"import": "./dist/adapters/react.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/nuqs/server/cache.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is needed for projects that have `moduleResolution` set to `node`
// in their tsconfig.json to be able to `import {} from 'nuqs/server/cache'`.
// Other module resolutions strategies will look for the `exports` in `package.json`,
// but with `node`, TypeScript will look for a .d.ts file with that name at the
// root of the package.

export * from './dist/server/cache'
7 changes: 7 additions & 0 deletions packages/nuqs/server/parsers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is needed for projects that have `moduleResolution` set to `node`
// in their tsconfig.json to be able to `import {} from 'nuqs/server/parsers'`.
// Other module resolutions strategies will look for the `exports` in `package.json`,
// but with `node`, TypeScript will look for a .d.ts file with that name at the
// root of the package.

export * from './dist/server/parsers'
7 changes: 7 additions & 0 deletions packages/nuqs/server/serializer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is needed for projects that have `moduleResolution` set to `node`
// in their tsconfig.json to be able to `import {} from 'nuqs/server/serializer'`.
// Other module resolutions strategies will look for the `exports` in `package.json`,
// but with `node`, TypeScript will look for a .d.ts file with that name at the
// root of the package.

export * from './dist/server/serializer'
2 changes: 2 additions & 0 deletions packages/nuqs/src/index.server.cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { createSearchParamsCache } from './cache'
export type { HistoryOptions, Nullable, Options, SearchParams } from './defs'
2 changes: 2 additions & 0 deletions packages/nuqs/src/index.server.parsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { HistoryOptions, Nullable, Options, SearchParams } from './defs'
export * from './parsers'
2 changes: 2 additions & 0 deletions packages/nuqs/src/index.server.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { HistoryOptions, Nullable, Options, SearchParams } from './defs'
export { createSerializer } from './serializer'
5 changes: 4 additions & 1 deletion packages/nuqs/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const entrypoints = {
'adapters/testing': 'src/adapters/testing.ts'
},
server: {
server: 'src/index.server.ts'
server: 'src/index.server.ts',
'server/cache': 'src/index.server.cache.ts',
'server/parsers': 'src/index.server.parsers.ts',
'server/serializer': 'src/index.server.serializer.ts'
}
}

Expand Down

0 comments on commit 6d868dd

Please sign in to comment.