-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathserver.ts
40 lines (33 loc) · 1.05 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import './lib/env'
import { createConnection } from 'vscode-languageserver/node'
// @ts-ignore
import preflight from 'tailwindcss/lib/css/preflight.css'
import { TW } from './tw'
import { interceptLogs } from './util/logs'
// @ts-ignore
// new Function(…) is used to work around issues with esbuild
global.__preflight = preflight
new Function(
'require',
'__dirname',
`
let oldReadFileSync = require('fs').readFileSync
require('fs').readFileSync = function (filename, ...args) {
if (filename === require('path').join(__dirname, 'css/preflight.css')) {
return global.__preflight
}
return oldReadFileSync(filename, ...args)
}
`,
)(require, __dirname)
const connection =
process.argv.length <= 2 ? createConnection(process.stdin, process.stdout) : createConnection()
interceptLogs(console, connection)
process.on('unhandledRejection', (e: any) => {
console.error(`Unhandled rejection`, e)
})
const tw = new TW(connection)
console.log('Setting up server…')
tw.setup()
console.log('Listening for messages…')
tw.listen()