Skip to content

Commit b1f65c1

Browse files
committed
fix: handle preserveEntrySignatures correctly
1 parent 2f6b160 commit b1f65c1

File tree

10 files changed

+305
-18
lines changed

10 files changed

+305
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {defineConfig} from '@sanity/pkg-utils'
2+
3+
export default defineConfig({
4+
tsconfig: 'tsconfig.dist.json',
5+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "next-sanity-repro",
3+
"version": "0.0.0-development",
4+
"private": true,
5+
"license": "MIT",
6+
"sideEffects": false,
7+
"type": "module",
8+
"exports": {
9+
".": {
10+
"source": "./src/index.ts",
11+
"default": "./dist/index.js"
12+
},
13+
"./hooks": {
14+
"source": "./src/hooks/index.ts",
15+
"default": "./dist/hooks.js"
16+
},
17+
"./package.json": "./package.json"
18+
},
19+
"main": "./dist/index.cjs",
20+
"types": "./dist/index.d.ts",
21+
"files": [
22+
"dist"
23+
],
24+
"scripts": {
25+
"build": "pkg build --strict --check --clean",
26+
"clean": "rimraf dist",
27+
"typecheck": "tsc"
28+
},
29+
"browserslist": "extends @sanity/browserslist-config",
30+
"dependencies": {
31+
"@sanity/client": "catalog:",
32+
"@sanity/next-loader": "latest",
33+
"@sanity/visual-editing": "latest"
34+
}
35+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from '@sanity/next-loader/hooks'
2+
export {useOptimistic} from '@sanity/visual-editing/react'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {createClient, unstable__adapter, unstable__environment} from '@sanity/client'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["./tsconfig.settings", "@sanity/pkg-utils/tsconfig/isolated-declarations.json"],
3+
"include": ["./src"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.settings",
3+
"include": ["./package.config.ts", "./src"]
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@sanity/pkg-utils/tsconfig/strictest.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"outDir": "dist"
6+
}
7+
}

pnpm-lock.yaml

Lines changed: 197 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/__snapshots__/cli.test.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,27 @@ export {
247247
"
248248
`;
249249

250+
exports[`should build \`next-sanity-repro\` package > ./dist/hooks.js 1`] = `
251+
"export * from "@sanity/next-loader/hooks";
252+
import { useOptimistic } from "@sanity/visual-editing/react";
253+
export {
254+
useOptimistic
255+
};
256+
//# sourceMappingURL=hooks.js.map
257+
"
258+
`;
259+
260+
exports[`should build \`next-sanity-repro\` package > ./dist/index.js 1`] = `
261+
"import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
262+
export {
263+
createClient,
264+
unstable__adapter,
265+
unstable__environment
266+
};
267+
//# sourceMappingURL=index.js.map
268+
"
269+
`;
270+
250271
exports[`should build \`react-18\` package > ./dist/index.d.ts 1`] = `
251272
"import {ForwardRefExoticComponent, HTMLProps, RefAttributes} from 'react'
252273

test/cli.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,35 @@ test.skipIf(isWindows)('should build `sanity-plugin-with-vanilla-extract` packag
576576
await project.remove()
577577
})
578578

579+
test.skipIf(isWindows)('should build `next-sanity-repro` package', async () => {
580+
const project = await spawnProject('next-sanity-repro')
581+
582+
await project.install()
583+
584+
await project.run('build')
585+
586+
const [distHooksJs, distIndexJs] = await Promise.all([
587+
project.readFile('dist/hooks.js'),
588+
project.readFile('dist/index.js'),
589+
])
590+
591+
// The dist/index.js should import from `@sanity/client`
592+
expect(distIndexJs).toContain(`from "@sanity/client"`)
593+
594+
// The dist/hooks.js should import from `@sanity/next-loader/hooks` and `@sanity/visual-editing/react`
595+
expect(distHooksJs).toContain(`from "@sanity/next-loader/hooks"`)
596+
expect(distHooksJs).toContain(`from "@sanity/visual-editing/react"`)
597+
598+
// The dist/index.js should not contain any references to imports from /hooks
599+
expect(distIndexJs).not.toContain(`import "@sanity/next-loader/hooks"`)
600+
expect(distIndexJs).not.toContain(`import "@sanity/visual-editing/react"`)
601+
602+
expect(distHooksJs).toMatchSnapshot('./dist/hooks.js')
603+
expect(distIndexJs).toMatchSnapshot('./dist/index.js')
604+
605+
await project.remove()
606+
})
607+
579608
describe.skip('runtime: next.js', () => {
580609
test('import `dist/*.browser.js` from package', async () => {
581610
const exportsDummy = await spawnProject('dummy-module')

0 commit comments

Comments
 (0)