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 27, 2025
1 parent 2a26d08 commit fe2b116
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')).getMachineId;
break;
case 'linux':
getMachineIdImpl = (await import('./getMachineId-linux')).getMachineId;
break;
case 'freebsd':
getMachineIdImpl = (await import('./getMachineId-bsd')).getMachineId;
break;
case 'win32':
getMachineIdImpl = (await import('./getMachineId-win')).getMachineId;
break;
default:
getMachineIdImpl = (await import('./getMachineId-unsupported')).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 fe2b116

Please sign in to comment.