Skip to content

Commit 0fdae0d

Browse files
committed
feat: patch plugin order to always load ts-essential-plugins first
1 parent 9046820 commit 0fdae0d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/extension.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,30 @@ export const activate = async () => {
142142
)
143143
}
144144
}
145+
146+
try {
147+
const tsExtension = vscode.extensions.getExtension('vscode.typescript-language-features')!
148+
const readFileSyncUnpatched = require('fs').readFileSync
149+
150+
const extensionJsPath = require.resolve('./dist/extension.js', {
151+
paths: [tsExtension.extensionPath],
152+
})
153+
154+
require('fs').readFileSync = (...args) => {
155+
if (args[0] === extensionJsPath) {
156+
let text = readFileSyncUnpatched(...args) as string
157+
158+
// sort plugins
159+
text = text.replace(
160+
'"--globalPlugins",i.plugins',
161+
'"--globalPlugins",i.plugins.sort((a,b)=>(b.name==="typescript-essential-plugins"?1:0)-(a.name==="typescript-essential-plugins"?1:0))',
162+
)
163+
164+
return text
165+
}
166+
167+
return readFileSyncUnpatched(...args)
168+
}
169+
} catch (e) {
170+
console.error('Error patching TS extension', e)
171+
}

0 commit comments

Comments
 (0)