@@ -4,21 +4,20 @@ import process from 'node:process';
44import { createRequire } from 'node:module' ;
55import { promisify } from 'node:util' ;
66import { tryToCatch } from 'try-to-catch' ;
7- import { createSimport } from 'simport' ;
87import parse from 'yargs-parser' ;
98import exit from '../server/exit.js' ;
109import { createConfig , configPath } from '../server/config.js' ;
1110import * as env from '../server/env.js' ;
1211import prefixer from '../server/prefixer.js' ;
1312import * as validate from '../server/validate.js' ;
13+ import Info from '../package.json' with {
14+ type : 'json' ,
15+ } ;
1416
1517process . on ( 'unhandledRejection' , exit ) ;
16-
1718const require = createRequire ( import . meta. url ) ;
1819
19- const Info = require ( '../package.json' ) ;
2020const isUndefined = ( a ) => typeof a === 'undefined' ;
21- const simport = createSimport ( import . meta. url ) ;
2221
2322const choose = ( a , b ) => {
2423 if ( isUndefined ( a ) )
170169 main ( ) ;
171170
172171async function main ( ) {
173- const { validateArgs} = await simport ( '@putout/cli-validate-args' ) ;
172+ const { validateArgs} = await import ( '@putout/cli-validate-args' ) ;
174173
175174 const error = await validateArgs ( args , [
176175 ...yargsOptions . boolean ,
@@ -251,7 +250,7 @@ async function main() {
251250 if ( args . showConfig )
252251 await showConfig ( ) ;
253252
254- const { distributeImport} = await simport ( '../server/distribute/import.js' ) ;
253+ const { distributeImport} = await import ( '../server/distribute/import.js' ) ;
255254 const importConfig = promisify ( distributeImport ) ;
256255
257256 await start ( options , config ) ;
@@ -273,7 +272,7 @@ function validateRoot(root, config) {
273272}
274273
275274async function getPassword ( password ) {
276- const criton = await simport ( 'criton' ) ;
275+ const { default : criton } = await import ( 'criton' ) ;
277276 return criton ( password , config ( 'algo' ) ) ;
278277}
279278
@@ -282,12 +281,10 @@ function version() {
282281}
283282
284283async function start ( options , config ) {
285- const SERVER = `../server/server.js` ;
286-
287284 if ( ! args . server )
288285 return ;
289286
290- const server = await simport ( SERVER ) ;
287+ const { default : server } = await import ( '../server/server.js' ) ;
291288 server ( options , config ) ;
292289}
293290
@@ -311,13 +308,13 @@ async function readConfig(name) {
311308 if ( ! name )
312309 return ;
313310
314- const tryToCatch = await simport ( 'try-to-catch' ) ;
315- const forEachKey = await simport ( 'for-each-key' ) ;
311+ const { default : forEachKey } = await import ( 'for-each-key' ) ;
316312
317- const [ error , data ] = await tryToCatch ( simport , name ) ;
318-
319- if ( error )
320- return exit ( error . message ) ;
313+ const data = await import ( name , {
314+ with : {
315+ type : 'json' ,
316+ } ,
317+ } ) ;
321318
322319 forEachKey ( config , data ) ;
323320}
@@ -329,8 +326,8 @@ async function help() {
329326 } ,
330327 } ) ;
331328
332- const forEachKey = await simport ( 'for-each-key' ) ;
333- const currify = await simport ( 'currify' ) ;
329+ const { default : forEachKey } = await import ( 'for-each-key' ) ;
330+ const { currify} = await import ( 'currify' ) ;
334331
335332 const usage = 'Usage: cloudcmd [options]' ;
336333 const url = Info . homepage ;
@@ -348,17 +345,17 @@ function repl() {
348345}
349346
350347async function checkUpdate ( ) {
351- const load = await simport ( 'package-json' ) ;
352-
348+ const { default : load } = await import ( 'package-json' ) ;
353349 const { version} = await load ( Info . name , 'latest' ) ;
350+
354351 await showUpdateInfo ( version ) ;
355352}
356353
357354async function showUpdateInfo ( version ) {
358355 if ( version === Info . version )
359356 return ;
360357
361- const chalk = await simport ( 'chalk' ) ;
358+ const { default : chalk } = await import ( 'chalk' ) ;
362359
363360 const latestVersion = chalk . green . bold ( `v${ version } ` ) ;
364361 const latest = `update available: ${ latestVersion } ` ;
0 commit comments