1212 */
1313
1414import { createRequire } from 'node:module'
15- import { readdirSync , statSync } from 'node:fs'
15+ import { readdirSync } from 'node:fs'
1616import path from 'node:path'
1717import { fileURLToPath } from 'node:url'
1818import { pathToFileURL } from 'node:url'
@@ -21,12 +21,10 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
2121const externalDir = path . resolve ( __dirname , '..' , '..' , 'dist' , 'external' )
2222const require = createRequire ( import . meta. url )
2323
24- // Normalize path for cross-platform (converts backslashes to forward slashes)
25- const normalizePath = p => p . split ( path . sep ) . join ( '/' )
26-
2724// Import CommonJS modules using require
2825const { isQuiet } = require ( '#socketsecurity/lib/argv/flags' )
2926const { getDefaultLogger } = require ( '#socketsecurity/lib/logger' )
27+ const { normalizePath } = require ( '#socketsecurity/lib/path' )
3028const { pluralize } = require ( '#socketsecurity/lib/words' )
3129
3230const logger = getDefaultLogger ( )
@@ -88,7 +86,8 @@ async function checkModuleExports(filePath) {
8886
8987 // Validate CJS export structure
9088 const cjsType = typeof cjsModule
91- const cjsKeys = cjsType === 'object' && cjsModule !== null ? Object . keys ( cjsModule ) : [ ]
89+ const cjsKeys =
90+ cjsType === 'object' && cjsModule !== null ? Object . keys ( cjsModule ) : [ ]
9291
9392 // Check for problematic CJS patterns
9493 if ( cjsType === 'object' && cjsModule !== null ) {
@@ -101,7 +100,9 @@ async function checkModuleExports(filePath) {
101100
102101 // Empty object is suspicious
103102 if ( cjsKeys . length === 0 ) {
104- issues . push ( 'CJS: Module exports empty object - may indicate bundling issue' )
103+ issues . push (
104+ 'CJS: Module exports empty object - may indicate bundling issue' ,
105+ )
105106 }
106107
107108 // Check if .default shadows the main export
@@ -112,7 +113,9 @@ async function checkModuleExports(filePath) {
112113 // If there are other exports, this might be intentional (like @inquirer modules)
113114 // We'll check ESM compatibility below
114115 if ( nonDefaultKeys . length === 0 ) {
115- issues . push ( 'CJS: Module has .default but no other exports - may be wrapped' )
116+ issues . push (
117+ 'CJS: Module has .default but no other exports - may be wrapped' ,
118+ )
116119 }
117120 }
118121 }
@@ -150,7 +153,9 @@ async function checkModuleExports(filePath) {
150153 if ( 'default' in cjsModule && cjsModule . default !== cjsModule ) {
151154 // ESM should have the default export
152155 if ( esmDefault === undefined ) {
153- issues . push ( 'ESM: Missing default export, but CJS has .default property' )
156+ issues . push (
157+ 'ESM: Missing default export, but CJS has .default property' ,
158+ )
154159 }
155160
156161 // Named exports should be accessible in ESM's default import
@@ -170,7 +175,9 @@ async function checkModuleExports(filePath) {
170175 const esmDefaultKeys = Object . keys ( esmDefault )
171176 for ( const key of cjsKeys ) {
172177 if ( ! esmDefaultKeys . includes ( key ) ) {
173- issues . push ( `ESM: Named export '${ key } ' missing from default object` )
178+ issues . push (
179+ `ESM: Named export '${ key } ' missing from default object` ,
180+ )
174181 }
175182 }
176183 }
@@ -278,7 +285,9 @@ async function main() {
278285 // Summary statistics
279286 const totalCjsKeys = successes . reduce ( ( sum , r ) => sum + r . cjsKeys , 0 )
280287 const modulesWithDefault = successes . filter ( r => r . hasEsmDefault ) . length
281- const functionExports = successes . filter ( r => r . cjsType === 'function' ) . length
288+ const functionExports = successes . filter (
289+ r => r . cjsType === 'function' ,
290+ ) . length
282291 const objectExports = successes . filter ( r => r . cjsType === 'object' ) . length
283292
284293 logger . success (
0 commit comments