-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: script esm * doc: add no-experience-esm flag * chore: add changeset file
- Loading branch information
1 parent
62ab7d6
commit f591344
Showing
24 changed files
with
490 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'farmup': patch | ||
--- | ||
|
||
upgrade @farmfe/core version and add exec script without output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import EventEmitter from 'node:events'; | ||
import net from 'node:net'; | ||
|
||
export class IpcClient<S, R> { | ||
private client!: net.Socket; | ||
|
||
events = new EventEmitter(); | ||
|
||
start(socketPath: string) { | ||
const client = net.createConnection(socketPath); | ||
|
||
client.on('data', (data) => { | ||
this.events.emit('data', data); | ||
}); | ||
|
||
this.client = client; | ||
} | ||
|
||
send(data: S) { | ||
this.client.write(JSON.stringify(data)); | ||
} | ||
|
||
onMessage(callback: (data: R) => void) { | ||
this.events.on('data', (data) => { | ||
callback(JSON.parse(data.toString())); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum ServiceStatus { | ||
WaitShakeHand = 1, | ||
Ready = 2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import tmp from 'tmp'; | ||
import net from 'node:net'; | ||
import { Service } from './service'; | ||
import EventEmitter from 'node:events'; | ||
import path from 'node:path'; | ||
|
||
interface TempFileResult { | ||
path: string; | ||
cleanupCallback: () => void; | ||
} | ||
|
||
function createTempFile(): Promise<TempFileResult> { | ||
return new Promise((resolve) => { | ||
tmp.dir({}, (_err, name, cleanupCallback) => { | ||
resolve({ | ||
path: path.join(name, `socket-${Date.now()}`), | ||
cleanupCallback, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
export class IpcServer<S, R> { | ||
private sockets = new Set<Service<S, R>>(); | ||
private events = new EventEmitter(); | ||
private _server!: net.Server; | ||
socket_path!: string; | ||
|
||
async start() { | ||
const tempFile = await createTempFile(); | ||
this.socket_path = tempFile.path; | ||
|
||
const server = net.createServer((socket) => { | ||
const service = new Service<S, R>(socket); | ||
socket.on('close', () => { | ||
this.sockets.delete(service); | ||
}); | ||
this.sockets.add(service); | ||
this.events.emit('connection', service); | ||
}); | ||
|
||
server.listen(tempFile); | ||
|
||
this._server = server; | ||
} | ||
|
||
onConnection(callback: (socket: Service<S, R>) => void) { | ||
const handler = (socket: Service<S, R>) => { | ||
callback(socket); | ||
|
||
socket.onClose(() => { | ||
this.events.off('connection', handler); | ||
}); | ||
}; | ||
this.events.on('connection', handler); | ||
} | ||
|
||
close() { | ||
this._server.close(); | ||
this.sockets.clear(); | ||
} | ||
|
||
send(data: S) { | ||
for (const socket of this.sockets) { | ||
socket.send(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Socket } from 'node:net'; | ||
|
||
export class Service<S, R> { | ||
// private status = ServiceStatus.WaitShakeHand; | ||
|
||
constructor(private _socket: Socket) {} | ||
|
||
send(data: S) { | ||
if (this._socket.closed) { | ||
return; | ||
} | ||
this._socket.write(JSON.stringify(data)); | ||
} | ||
|
||
onMessage(callback: (data: R) => void) { | ||
const handler = (data: Buffer) => { | ||
callback(JSON.parse(data.toString())); | ||
}; | ||
|
||
this._socket.on('data', handler); | ||
|
||
return () => { | ||
this._socket.off('data', handler); | ||
}; | ||
} | ||
|
||
close() { | ||
this._socket.end(); | ||
} | ||
|
||
onClose(callback: () => void) { | ||
this._socket.on('close', callback); | ||
} | ||
|
||
get isClose() { | ||
return this._socket.closed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.