Skip to content

Commit 1719306

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent 96c7fc1 commit 1719306

File tree

5 files changed

+740
-3
lines changed

5 files changed

+740
-3
lines changed

runok.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = {
3737
async defTypings() {
3838
console.log('Generate TypeScript definitions using TypeScript compiler')
3939
// Generate type definitions using TypeScript compiler (replaces tsd-jsdoc)
40-
// The script generates .d.ts files from JSDoc comments in JavaScript files
40+
// First generate promise-based helper types, then regular types
41+
await npx('node typings/generate-dts.mjs tsconfig.typings.json --promise-based')
4142
await npx('node typings/generate-dts.mjs tsconfig.typings.json')
4243
},
4344

typings/generate-dts.mjs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ function cleanupDeclaration(filePath) {
4848
return
4949
}
5050

51-
// Simple cleanup - just ensure proper formatting
52-
// Don't wrap in namespace here, we'll create a consolidated types.d.ts instead
51+
// Remove problematic export statements that cause module format errors
52+
content = content.replace(/^export\s*=\s*.+;?\s*$/gm, '')
53+
54+
// Remove empty lines at the start
55+
content = content.replace(/^\s*\n/gm, '')
5356

5457
writeFileSync(filePath, content)
5558
}
@@ -188,6 +191,71 @@ function main() {
188191
cleanupDeclaration(file)
189192
}
190193

194+
// Step 3: Create consolidated types.d.ts file in CodeceptJS namespace
195+
console.log('\nCreating consolidated types file...')
196+
const outputFilename = isPromiseBased ? 'promiseBasedTypes.d.ts' : 'types.d.ts'
197+
const outputPath = join(typingsDir, outputFilename)
198+
199+
const consolidated = []
200+
consolidated.push('// Auto-generated TypeScript definitions')
201+
consolidated.push('// Generated from JSDoc comments using TypeScript compiler')
202+
consolidated.push('')
203+
consolidated.push('declare namespace CodeceptJS {')
204+
205+
// Collect all class, interface, and type definitions from helper and lib files
206+
const helperFiles = dtsFiles.filter(f => f.includes('/docs/build/'))
207+
const libFiles = dtsFiles.filter(
208+
f =>
209+
f.includes('/lib/') &&
210+
!f.includes('/lib/command/') &&
211+
!f.includes('/lib/listener/') &&
212+
!f.includes('/lib/assert/') &&
213+
!f.includes('/lib/data/') &&
214+
!f.includes('/lib/plugin/') &&
215+
!f.includes('/lib/template/') &&
216+
!f.includes('/lib/utils/'),
217+
)
218+
219+
// For promise-based types, only include helpers. For regular types, include both.
220+
const allFiles = isPromiseBased ? helperFiles : [...libFiles, ...helperFiles]
221+
222+
for (const file of allFiles) {
223+
if (!existsSync(file)) continue
224+
225+
let content = readFileSync(file, 'utf-8')
226+
227+
// Remove all import statements
228+
content = content.replace(/^import .+$/gm, '')
229+
230+
// Remove export default and export = statements
231+
content = content.replace(/^export default .+$/gm, '')
232+
content = content.replace(/^export = .+$/gm, '')
233+
content = content.replace(/^export \{\};?$/gm, '')
234+
235+
// Remove export keywords but keep declarations
236+
content = content.replace(/^export (declare )?/gm, '')
237+
content = content.replace(/^declare /gm, '')
238+
239+
// Keep CodeceptJS. prefix - it's needed for cross-references within the namespace
240+
241+
// Split into lines and indent
242+
const lines = content.split('\n')
243+
for (const line of lines) {
244+
if (line.trim()) {
245+
consolidated.push(' ' + line)
246+
} else if (consolidated[consolidated.length - 1] !== '') {
247+
// Only add empty line if previous line wasn't empty
248+
consolidated.push('')
249+
}
250+
}
251+
}
252+
253+
consolidated.push('}')
254+
consolidated.push('')
255+
256+
writeFileSync(outputPath, consolidated.join('\n'))
257+
console.log(`Created ${outputFilename} with ${allFiles.length} type definitions (${helperFiles.length} helpers, ${libFiles.length} lib)`)
258+
191259
console.log('\nType definitions generated successfully!')
192260
console.log('Generated .d.ts files are in typings/ directory (excluded from git)')
193261
}

typings/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Project: https://github.com/codeception/codeceptjs/
22
// TypeScript definitions generated from JSDoc comments
3+
/// <reference path="./types.d.ts" />
4+
/// <reference path="./promiseBasedTypes.d.ts" />
35
/// <reference types="webdriverio" />
46
/// <reference path="./Mocha.d.ts" />
57
/// <reference types="joi" />

0 commit comments

Comments
 (0)