Skip to content

Commit

Permalink
fix: esm suport
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiangmoe committed Jan 26, 2025
1 parent 90afa28 commit 5ed3017
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@
*/
import * as process from 'process';

let getMachineId: () => Promise<string>;
let getMachineIdImpl: () => Promise<string>;
async function getMachineId(): Promise<string> {
if(!getMachineIdImpl) {
switch (process.platform) {
case 'darwin':
getMachineIdImpl = await import('./getMachineId-darwin').then((m) => m.getMachineId);
break;
case 'linux':
getMachineIdImpl = await import('./getMachineId-linux').then((m) => m.getMachineId);
break;
case 'freebsd':
getMachineIdImpl = await import('./getMachineId-bsd').then((m) => m.getMachineId);
break;
case 'win32':
getMachineIdImpl = await import('./getMachineId-win').then((m) => m.getMachineId);
break;
default:
getMachineIdImpl = await import('./getMachineId-unsupported').then((m) => m.getMachineId);
break;
}
}

switch (process.platform) {
case 'darwin':
({ getMachineId } = require('./getMachineId-darwin'));
break;
case 'linux':
({ getMachineId } = require('./getMachineId-linux'));
break;
case 'freebsd':
({ getMachineId } = require('./getMachineId-bsd'));
break;
case 'win32':
({ getMachineId } = require('./getMachineId-win'));
break;
default:
({ getMachineId } = require('./getMachineId-unsupported'));
return getMachineIdImpl();
}

export { getMachineId };

0 comments on commit 5ed3017

Please sign in to comment.