@@ -2,17 +2,16 @@ import path from 'path';
22import fs from 'fs' ;
33import type { RuleModule } from '../../src/types.js' ;
44
5- const __dirname = path . dirname ( new URL ( import . meta. url ) . pathname ) ;
5+ const rulesLibRootURL = new URL ( '../../src/rules/' , import . meta. url ) ;
66
77/**
88 * Get the all rules
99 * @returns {Array } The all rules
1010 */
1111async function readRules ( ) {
12- const rulesLibRoot = path . resolve ( __dirname , '../../src/rules' ) ;
1312 const rules : RuleModule [ ] = [ ] ;
1413 for ( const name of iterateTsFiles ( ) ) {
15- const module = await import ( path . join ( rulesLibRoot , name ) ) ;
14+ const module = await import ( new URL ( name , rulesLibRootURL ) . href ) ;
1615 const rule : RuleModule = module && module . default ;
1716 if ( ! rule || typeof rule . create !== 'function' ) {
1817 continue ;
@@ -27,19 +26,18 @@ export const rules = await readRules();
2726
2827/** Iterate ts files */
2928function * iterateTsFiles ( ) {
30- const rulesLibRoot = path . resolve ( __dirname , '../../src/rules' ) ;
31- const files = fs . readdirSync ( rulesLibRoot ) ;
29+ const files = fs . readdirSync ( rulesLibRootURL ) ;
3230
3331 while ( files . length ) {
3432 const file = files . shift ( ) ! ;
3533 if ( file . endsWith ( '.ts' ) ) {
3634 yield file ;
3735 continue ;
3836 }
39- const filePath = path . join ( rulesLibRoot , file ) ;
40- if ( ! fs . statSync ( filePath ) . isDirectory ( ) ) {
37+ const filePathURL = new URL ( file , rulesLibRootURL ) ;
38+ if ( ! fs . statSync ( filePathURL ) . isDirectory ( ) ) {
4139 continue ;
4240 }
43- files . unshift ( ...fs . readdirSync ( filePath ) . map ( ( n ) => path . join ( file , n ) ) ) ;
41+ files . unshift ( ...fs . readdirSync ( filePathURL ) . map ( ( n ) => path . join ( file , n ) ) ) ;
4442 }
4543}
0 commit comments