Skip to content

Commit d8dc14b

Browse files
authored
fix: remove use of unctx to avoid issues with conflicting versions (#566)
1 parent 953b11e commit d8dc14b

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

build.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default defineBuildConfig({
2222
'hash-sum',
2323
'hookable',
2424
'pathe',
25-
'unctx',
2625
'webpack',
2726
'vuex',
2827
],

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@
6969
"hash-sum": "^2.0.0",
7070
"lodash.mergewith": "^4.6.2",
7171
"mlly": "^1.0.0",
72-
"pathe": "^1.0.0",
73-
"unctx": "^2.0.0"
72+
"pathe": "^1.0.0"
7473
},
7574
"devDependencies": {
7675
"@nuxt/module-builder": "0.2.1",

src/kit-shim.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import hash from 'hash-sum'
77
import { basename, parse, normalize, resolve } from 'pathe'
88
import { resolveAlias as _resolveAlias } from 'pathe/utils'
99
import type { Hookable } from 'hookable'
10-
import { getContext } from 'unctx'
1110
import type { WebpackPluginInstance, Configuration as WebpackConfig } from 'webpack'
1211
import type { NuxtOptions } from '@nuxt/types'
1312

@@ -58,7 +57,7 @@ export interface NuxtModule<T extends ModuleOptions = ModuleOptions> {
5857
}
5958

6059
/** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
61-
export const nuxtCtx = getContext<Nuxt>('nuxt')
60+
let nuxtCtx: Nuxt | null = null
6261

6362
// TODO: Use use/tryUse from unctx. https://github.com/unjs/unctx/issues/6
6463

@@ -73,7 +72,7 @@ export const nuxtCtx = getContext<Nuxt>('nuxt')
7372
* ```
7473
*/
7574
export function useNuxt (): Nuxt {
76-
const instance = nuxtCtx.tryUse()
75+
const instance = nuxtCtx
7776
if (!instance) {
7877
throw new Error('Nuxt instance is unavailable!')
7978
}
@@ -94,7 +93,7 @@ export function useNuxt (): Nuxt {
9493
* ```
9594
*/
9695
export function tryUseNuxt (): Nuxt | null {
97-
return nuxtCtx.tryUse()
96+
return nuxtCtx
9897
}
9998

10099
// -- Nuxt 2 compatibility shims --
@@ -111,9 +110,9 @@ function nuxt2Shims (nuxt: Nuxt) {
111110
nuxt.hooks = nuxt
112111

113112
// Allow using useNuxt()
114-
if (!nuxtCtx.tryUse()) {
115-
nuxtCtx.set(nuxt)
116-
nuxt.hook('close', () => nuxtCtx.unset())
113+
if (!nuxtCtx) {
114+
nuxtCtx = nuxt
115+
nuxt.hook('close', () => { nuxtCtx = null })
117116
}
118117
}
119118

yarn.lock

+1-33
Original file line numberDiff line numberDiff line change
@@ -6089,13 +6089,6 @@ estree-walker@^2.0.2:
60896089
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
60906090
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==
60916091

6092-
estree-walker@^3.0.3:
6093-
version "3.0.3"
6094-
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-3.0.3.tgz#67c3e549ec402a487b4fc193d1953a524752340d"
6095-
integrity sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==
6096-
dependencies:
6097-
"@types/estree" "^1.0.0"
6098-
60996092
esutils@^2.0.2:
61006093
version "2.0.3"
61016094
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
@@ -12928,16 +12921,6 @@ unbuild@^1.0.1:
1292812921
typescript "^4.9.5"
1292912922
untyped "^1.2.2"
1293012923

12931-
unctx@^2.0.0:
12932-
version "2.1.2"
12933-
resolved "https://registry.yarnpkg.com/unctx/-/unctx-2.1.2.tgz#12d34c540ef4fbaffb2a3b38a0697e42b152d478"
12934-
integrity sha512-KK18aLRKe3OlbPyHbXAkIWSU3xK8GInomXfA7fzDMGFXQ1crX1UWrCzKesVXeUyHIayHUrnTvf87IPCKMyeKTg==
12935-
dependencies:
12936-
acorn "^8.8.2"
12937-
estree-walker "^3.0.3"
12938-
magic-string "^0.27.0"
12939-
unplugin "^1.0.1"
12940-
1294112924
unfetch@^5.0.0:
1294212925
version "5.0.0"
1294312926
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-5.0.0.tgz#8a5b6e5779ebe4dde0049f7d7a81d4a1af99d142"
@@ -13017,16 +13000,6 @@ unpipe@1.0.0, unpipe@~1.0.0:
1301713000
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
1301813001
integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==
1301913002

13020-
unplugin@^1.0.1:
13021-
version "1.3.1"
13022-
resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.3.1.tgz#7af993ba8695d17d61b0845718380caf6af5109f"
13023-
integrity sha512-h4uUTIvFBQRxUKS2Wjys6ivoeofGhxzTe2sRWlooyjHXVttcVfV/JiavNd3d4+jty0SVV0dxGw9AkY9MwiaCEw==
13024-
dependencies:
13025-
acorn "^8.8.2"
13026-
chokidar "^3.5.3"
13027-
webpack-sources "^3.2.3"
13028-
webpack-virtual-modules "^0.5.0"
13029-
1303013003
unset-value@^1.0.0:
1303113004
version "1.0.0"
1303213005
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
@@ -13433,16 +13406,11 @@ webpack-sources@^1.0.1, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-
1343313406
source-list-map "^2.0.0"
1343413407
source-map "~0.6.1"
1343513408

13436-
"webpack-sources@^2.0.0 || ^3.0.0", webpack-sources@^3.2.3:
13409+
"webpack-sources@^2.0.0 || ^3.0.0":
1343713410
version "3.2.3"
1343813411
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
1343913412
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
1344013413

13441-
webpack-virtual-modules@^0.5.0:
13442-
version "0.5.0"
13443-
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c"
13444-
integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==
13445-
1344613414
webpack@^4.46.0:
1344713415
version "4.46.0"
1344813416
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542"

0 commit comments

Comments
 (0)