@@ -37,10 +37,10 @@ module.exports = {
3737 async defTypings ( ) {
3838 console . log ( 'Generate TypeScript definition' )
3939 // Generate definitions for promised-based helper methods
40- await npx ( 'jsdoc -c typings/jsdocPromiseBased.conf.js ' )
40+ await npx ( 'jsdoc -c typings/jsdocPromiseBased.conf.json ' )
4141 fs . renameSync ( 'typings/types.d.ts' , 'typings/promiseBasedTypes.d.ts' )
4242 // Generate all other regular definitions
43- await npx ( 'jsdoc -c typings/jsdoc.conf.js ' )
43+ await npx ( 'jsdoc -c typings/jsdoc.conf.json ' )
4444 } ,
4545
4646 async docsPlugins ( ) {
@@ -176,6 +176,31 @@ Our community prepared some valuable recipes for setting up CI systems with Code
176176 cfg . replace ( / L o c a t o r O r S t r i n g / g, 'string | object' )
177177 cfg . replace ( / C o d e c e p t J S .S t r i n g O r S e c r e t / g, 'string | object' )
178178 }
179+ // Convert ESM imports to require() for JSDoc compatibility
180+ cfg . replace ( / ^ i m p o r t \s + ( [ ^ ' " ` \s { ] + ) \s + f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, "const $1 = require('$2')" )
181+ cfg . replace ( / ^ i m p o r t \s * \{ \s * ( [ ^ } ] + ) \s * \} \s * f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, ( match , imports , path ) => {
182+ // Handle destructuring imports with aliases - convert to simple require and assign
183+ if ( imports . includes ( ' as ' ) ) {
184+ const parts = imports . split ( ',' ) . map ( i => i . trim ( ) )
185+ const assignments = parts . map ( part => {
186+ if ( part . includes ( ' as ' ) ) {
187+ const [ original , alias ] = part . split ( ' as ' ) . map ( s => s . trim ( ) )
188+ return `const ${ alias } = require('${ path } ').${ original } `
189+ } else {
190+ return `const ${ part } = require('${ path } ').${ part } `
191+ }
192+ } )
193+ return assignments . join ( ';\n' )
194+ }
195+ return `const { ${ imports } } = require('${ path } ')`
196+ } )
197+ cfg . replace ( / ^ i m p o r t \s + \* \s + a s \s + ( [ ^ ' " ` ] + ) \s + f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, "const $1 = require('$2')" )
198+
199+ // Convert ESM exports to module.exports for JSDoc compatibility
200+ cfg . replace ( / ^ e x p o r t \s * \{ \s * ( [ ^ } ] + ) \s + a s \s + d e f a u l t \s * \} / gm, 'module.exports = $1' )
201+ cfg . replace ( / ^ e x p o r t \s + d e f a u l t \s + ( .+ ) / gm, 'module.exports = $1' )
202+ cfg . replace ( / ^ e x p o r t \s * \{ \s * ( [ ^ } ] + ) \s * \} / gm, 'module.exports = { $1 }' )
203+ cfg . replace ( / ^ e x p o r t \s + ( c l a s s | f u n c t i o n | c o n s t | l e t | v a r ) \s + ( [ ^ \s = ] + ) / gm, '$1 $2' )
179204 } )
180205 }
181206 } ,
@@ -215,6 +240,32 @@ Our community prepared some valuable recipes for setting up CI systems with Code
215240 cfg . replace ( / C o d e c e p t J S .L o c a t o r O r S t r i n g / g, 'string | object' )
216241 cfg . replace ( / L o c a t o r O r S t r i n g / g, 'string | object' )
217242 cfg . replace ( / C o d e c e p t J S .S t r i n g O r S e c r e t / g, 'string | object' )
243+
244+ // Convert ESM imports to require() for JSDoc compatibility
245+ cfg . replace ( / ^ i m p o r t \s + ( [ ^ ' " ` \s { ] + ) \s + f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, "const $1 = require('$2')" )
246+ cfg . replace ( / ^ i m p o r t \s * \{ \s * ( [ ^ } ] + ) \s * \} \s * f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, ( match , imports , path ) => {
247+ // Handle destructuring imports with aliases - convert to simple require and assign
248+ if ( imports . includes ( ' as ' ) ) {
249+ const parts = imports . split ( ',' ) . map ( i => i . trim ( ) )
250+ const assignments = parts . map ( part => {
251+ if ( part . includes ( ' as ' ) ) {
252+ const [ original , alias ] = part . split ( ' as ' ) . map ( s => s . trim ( ) )
253+ return `const ${ alias } = require('${ path } ').${ original } `
254+ } else {
255+ return `const ${ part } = require('${ path } ').${ part } `
256+ }
257+ } )
258+ return assignments . join ( ';\n' )
259+ }
260+ return `const { ${ imports } } = require('${ path } ')`
261+ } )
262+ cfg . replace ( / ^ i m p o r t \s + \* \s + a s \s + ( [ ^ ' " ` ] + ) \s + f r o m \s + [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / gm, "const $1 = require('$2')" )
263+
264+ // Convert ESM exports to module.exports for JSDoc compatibility
265+ cfg . replace ( / ^ e x p o r t \s * \{ \s * ( [ ^ } ] + ) \s + a s \s + d e f a u l t \s * \} / gm, 'module.exports = $1' )
266+ cfg . replace ( / ^ e x p o r t \s + d e f a u l t \s + ( .+ ) / gm, 'module.exports = $1' )
267+ cfg . replace ( / ^ e x p o r t \s * \{ \s * ( [ ^ } ] + ) \s * \} / gm, 'module.exports = { $1 }' )
268+ cfg . replace ( / ^ e x p o r t \s + ( c l a s s | f u n c t i o n | c o n s t | l e t | v a r ) \s + ( [ ^ \s = ] + ) / gm, '$1 $2' )
218269 } )
219270
220271 await npx ( `documentation build docs/build/${ file } -o docs/helpers/${ name } .md ${ documentjsCliArgs } ` )
0 commit comments