Skip to content

Commit 33b23ee

Browse files
author
DavertMik
committed
lazy load
1 parent 8a07aa5 commit 33b23ee

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

codeceptjs.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
import codeceptjs from 'codeceptjs'
1+
// CodeceptJS handle, looked up from the in-process registry the framework sets
2+
// on globalThis. Avoids a top-level `import 'codeceptjs'`, which fails to
3+
// resolve inside the codeceptjs repo's own CI (the project IS the codeceptjs
4+
// package). Each named export is a Proxy that forwards property access to the
5+
// live framework module at call time, so hooks register against the same
6+
// singletons the runner is using.
27

3-
if (!codeceptjs?.config?.addHook) {
4-
throw new Error('CodeceptJS >= 4.0.0 is required to use config hooks. For older versions, install @codeceptjs/configure@^1.')
8+
function lazy(name) {
9+
return new Proxy({}, {
10+
get(_, key) {
11+
const cjs = globalThis.codeceptjs
12+
if (!cjs) {
13+
throw new Error('CodeceptJS host not available — call configure functions from inside a codecept.conf.js / codecept run, or make sure CodeceptJS >= 4.0 is loaded first.')
14+
}
15+
const target = cjs[name]
16+
if (!target) {
17+
throw new Error(`CodeceptJS does not expose ${name} on the host registry.`)
18+
}
19+
const v = target[key]
20+
return typeof v === 'function' ? v.bind(target) : v
21+
},
22+
})
523
}
624

25+
const codeceptjs = new Proxy({}, {
26+
get(_, key) {
27+
const cjs = globalThis.codeceptjs
28+
if (!cjs) throw new Error('CodeceptJS host not available — call configure functions from inside a codecept.conf.js / codecept run.')
29+
return cjs[key]
30+
},
31+
})
32+
733
export default codeceptjs
8-
export const config = codeceptjs.config
9-
export const container = codeceptjs.container
10-
export const event = codeceptjs.event
11-
export const output = codeceptjs.output
34+
export const config = lazy('config')
35+
export const container = lazy('container')
36+
export const event = lazy('event')
37+
export const output = lazy('output')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codeceptjs/configure",
3-
"version": "4.0.0-beta.3",
3+
"version": "4.0.0-beta.4",
44
"description": "Set of CodeceptJS config hooks to simplify configuration (ESM, CodeceptJS 4.x)",
55
"type": "module",
66
"main": "index.js",

0 commit comments

Comments
 (0)