@@ -6,11 +6,7 @@ import {
66 promptSelect ,
77} from "@std/cli/unstable-prompt-select" ;
88import { fromFileUrl , join , resolve } from "@std/path" ;
9- import {
10- applyEdits as applyJSONCEdits ,
11- modify as modifyJSONC ,
12- parse as parseJSONC ,
13- } from "jsonc-parser" ;
9+ import { parse as parseJSONC } from "@david/jsonc-morph" ;
1410import { resolve_config } from "./lib/rs_lib.js" ;
1511import { ValidationError } from "@cliffy/command" ;
1612import { createFlow } from "./deploy/create/flow.ts" ;
@@ -250,7 +246,7 @@ async function readConfig(
250246 ) ;
251247
252248 if ( config . path ) {
253- const path = fromFileUrl ( config . config ) ;
249+ const path = fromFileUrl ( config . path ) ;
254250 const content = await Deno . readTextFile ( path ) ;
255251 return { config : { path, content } , files : config . files } ;
256252 }
@@ -263,14 +259,12 @@ function getAppFromConfig(
263259) : { org : undefined | string ; app : undefined | string ; files : string [ ] } {
264260 if ( configContent . config ) {
265261 const config = parseJSONC ( configContent . config . content ) ;
266- if (
267- typeof config === "object" && config !== null && "deploy" in config &&
268- typeof config . deploy === "object" && config . deploy !== null &&
269- ! Array . isArray ( config . deploy )
270- ) {
262+ const deployObj = config . asObject ( ) ?. getIfObject ( "deploy" ) ;
263+
264+ if ( deployObj ) {
271265 return {
272- org : config . deploy . org ,
273- app : config . deploy . app ,
266+ org : deployObj . get ( " org" ) ?. value ( ) ?. asString ( ) ,
267+ app : deployObj . get ( " app" ) ?. value ( ) ?. asString ( ) ,
274268 files : configContent . files ,
275269 } ;
276270 }
@@ -299,19 +293,17 @@ async function writeConfig(
299293 newConfig . app = app ;
300294 }
301295
302- const edits = modifyJSONC ( content , [ "deploy" ] , newConfig , {
303- formattingOptions : {
304- insertSpaces : true ,
305- tabSize : 2 ,
306- } ,
307- } ) ;
308- const out = applyJSONCEdits ( content , edits ) ;
296+ const config = parseJSONC ( content ) ;
297+ const deployObj = config . asObjectOrForce ( ) . getIfObjectOrForce ( "deploy" ) ;
298+ deployObj . replaceWith ( newConfig ) ;
299+ deployObj . ensureMultiline ( ) ;
300+
309301 await Deno . writeTextFile (
310302 configContent . config ?. path ?? join ( Deno . cwd ( ) , "deno.jsonc" ) ,
311- out ,
303+ config . toString ( ) + "\n" ,
312304 ) ;
313305
314- if ( ! configContent ) {
306+ if ( ! configContent . config ) {
315307 console . log (
316308 `Created configuration file at '${ join ( Deno . cwd ( ) , "deno.jsonc" ) } '` ,
317309 ) ;
0 commit comments