@@ -2,8 +2,7 @@ const fs = require('node:fs');
22const { transformForLint } = require ( './transforms' ) ;
33const { replaceRange } = require ( './transforms' ) ;
44
5- let patchTs , replaceExtensions , syncMtsGtsSourceFiles , typescriptParser , isPatched ;
6- let globalAllowGjs = true ;
5+ let patchTs , replaceExtensions , syncMtsGtsSourceFiles , typescriptParser , isPatched , allowGjs ;
76
87try {
98 const parserPath = require . resolve ( '@typescript-eslint/parser' ) ;
1211 const ts = require ( tsPath ) ;
1312 typescriptParser = require ( '@typescript-eslint/parser' ) ;
1413 patchTs = function patchTs ( options = { } ) {
15- if ( isPatched ) return ;
14+ if ( isPatched ) return { allowGjs } ;
1615 isPatched = true ;
17- globalAllowGjs = options . allowGjs !== undefined ? options . allowGjs : true ;
16+ allowGjs = options . allowGjs !== undefined ? options . allowGjs : true ;
1817 const sys = { ...ts . sys } ;
1918 const newSys = {
2019 ...ts . sys ,
@@ -23,16 +22,14 @@ try {
2322 const gtsVirtuals = results
2423 . filter ( ( x ) => x . endsWith ( '.gts' ) )
2524 . map ( ( f ) => f . replace ( / \. g t s $ / , '.mts' ) ) ;
26- const gjsVirtuals = globalAllowGjs
25+ const gjsVirtuals = allowGjs
2726 ? results . filter ( ( x ) => x . endsWith ( '.gjs' ) ) . map ( ( f ) => f . replace ( / \. g j s $ / , '.mjs' ) )
2827 : [ ] ;
2928 return results . concat ( gtsVirtuals , gjsVirtuals ) ;
3029 } ,
3130 fileExists ( fileName ) {
3231 const gtsExists = fs . existsSync ( fileName . replace ( / \. m ? t s $ / , '.gts' ) ) ;
33- const gjsExists = globalAllowGjs
34- ? fs . existsSync ( fileName . replace ( / \. m ? j s $ / , '.gjs' ) )
35- : false ;
32+ const gjsExists = allowGjs ? fs . existsSync ( fileName . replace ( / \. m ? j s $ / , '.gjs' ) ) : false ;
3633 return gtsExists || gjsExists || fs . existsSync ( fileName ) ;
3734 } ,
3835 readFile ( fname ) {
@@ -47,12 +44,12 @@ try {
4744 } catch {
4845 if ( fileName . match ( / \. m ? t s $ / ) ) {
4946 fileName = fileName . replace ( / \. m ? t s $ / , '.gts' ) ;
50- } else if ( globalAllowGjs && fileName . match ( / \. m ? j s $ / ) ) {
47+ } else if ( allowGjs && fileName . match ( / \. m ? j s $ / ) ) {
5148 fileName = fileName . replace ( / \. m ? j s $ / , '.gjs' ) ;
5249 }
5350 content = fs . readFileSync ( fileName ) . toString ( ) ;
5451 }
55- if ( fileName . endsWith ( '.gts' ) || ( globalAllowGjs && fileName . endsWith ( '.gjs' ) ) ) {
52+ if ( fileName . endsWith ( '.gts' ) || ( allowGjs && fileName . endsWith ( '.gjs' ) ) ) {
5653 try {
5754 content = transformForLint ( content ) . output ;
5855 } catch ( e ) {
6360 if (
6461 ( ! fileName . endsWith ( '.d.ts' ) && fileName . endsWith ( '.ts' ) ) ||
6562 fileName . endsWith ( '.gts' ) ||
66- ( globalAllowGjs && fileName . endsWith ( '.gjs' ) )
63+ ( allowGjs && fileName . endsWith ( '.gjs' ) )
6764 ) {
6865 try {
6966 content = replaceExtensions ( content ) ;
7673 } ,
7774 } ;
7875 ts . setSys ( newSys ) ;
76+ return { allowGjs } ;
7977 } ;
8078
8179 replaceExtensions = function replaceExtensions ( code ) {
0 commit comments