File tree 5 files changed +47
-9
lines changed
5 files changed +47
-9
lines changed Original file line number Diff line number Diff line change 44
44
},
45
45
"devDependencies" : {
46
46
"@sanity/check" : " ^0.108.0" ,
47
+ "@sanity/plugin-loader" : " ^0.108.0" ,
47
48
"chai" : " ^3.5.0" ,
48
49
"chai-as-promised" : " ^6.0.0" ,
49
50
"eslint" : " ^3.19.0" ,
Original file line number Diff line number Diff line change @@ -2,7 +2,30 @@ import sanityClient from '@sanity/client'
2
2
import config from 'config:sanity'
3
3
import configureClient from 'part:@sanity/base/configure-client?'
4
4
5
+ const deprecationMessage = `[deprecation] The Sanity client is now exposed in CommonJS format.
6
+
7
+ For instance, change:
8
+ \`const client = require('part:@sanity/base/client').default\`
9
+
10
+ To the following:
11
+ \`const client = require('part:@sanity/base/client')\`
12
+ `
13
+
5
14
const apiConfig = { ...config . api , withCredentials : true }
6
15
const client = sanityClient ( apiConfig )
7
16
8
- export default configureClient ? configureClient ( sanityClient ( apiConfig ) ) : client
17
+ const configuredClient = configureClient
18
+ ? configureClient ( sanityClient ( apiConfig ) )
19
+ : client
20
+
21
+ // Warn when people use `.default`
22
+ Object . defineProperty ( configuredClient , 'default' , {
23
+ get ( ) {
24
+ // eslint-disable-next-line no-console
25
+ console . warn ( deprecationMessage )
26
+ return configuredClient
27
+ }
28
+ } )
29
+
30
+ // Expose as CJS to allow Node scripts to consume it without `.default`
31
+ module . exports = configuredClient
Original file line number Diff line number Diff line change
1
+ import { describe , it } from 'mocha'
2
+ import { expect } from 'chai'
3
+ import client from '../src/client'
4
+
5
+ describe ( 'client' , ( ) => {
6
+ it ( 'should be exposed in CommonJS format' , done => {
7
+ expect ( client . fetch ) . to . be . a ( 'function' )
8
+ done ( )
9
+ } )
10
+
11
+ it ( 'should still expose client on .default, but give warning' , done => {
12
+ expect ( client . default . fetch ) . to . be . a ( 'function' )
13
+ done ( )
14
+ } )
15
+ } )
Original file line number Diff line number Diff line change 1
1
import chai from 'chai'
2
2
import chaiAsPromised from 'chai-as-promised'
3
+ import pluginLoader from '@sanity/plugin-loader'
4
+
5
+ pluginLoader ( {
6
+ overrides : {
7
+ 'config:sanity' : [ { api : { projectId : 'abc123' , dataset : 'hei' } } ]
8
+ }
9
+ } )
3
10
4
11
chai . should ( )
5
12
chai . use ( chaiAsPromised )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments