Skip to content

Commit 6dfaab3

Browse files
committed
fixes
1 parent f24fad5 commit 6dfaab3

6 files changed

Lines changed: 38 additions & 42 deletions

File tree

config.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import {
66
promptSelect,
77
} from "@std/cli/unstable-prompt-select";
88
import { 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";
1410
import { resolve_config } from "./lib/rs_lib.js";
1511
import { ValidationError } from "@cliffy/command";
1612
import { 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
);

deno.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"exports": "./main.ts",
1717
"imports": {
1818
"@cliffy/command": "jsr:@cliffy/command@^1.0.0",
19+
"@david/jsonc-morph": "jsr:@david/jsonc-morph@^0.3.1",
1920
"@deno/sandbox": "jsr:@deno/sandbox@^0.10.0",
2021
"@std/assert": "jsr:@std/assert@^1.0.16",
2122
"@std/async": "jsr:@std/async@^1.1.0",
@@ -24,15 +25,13 @@
2425
"@std/encoding": "jsr:@std/encoding@^1.0.10",
2526
"@std/fmt": "jsr:@std/fmt@^1.0.8",
2627
"@std/fs": "jsr:@std/fs@^1.0.19",
27-
"@std/jsonc": "jsr:@std/jsonc@^1.0.2",
2828
"@std/path": "jsr:@std/path@^1.1.2",
2929
"@std/semver": "jsr:@std/semver@^1.0.8",
3030
"@std/tar": "jsr:@std/tar@^0.1.9",
3131
"@trpc/client": "npm:@trpc/client@^11.0.2",
3232
"@trpc/server": "npm:@trpc/server@^11.0.2",
3333
"@types/prompts": "npm:@types/prompts@2.4.9",
3434
"event-source-polyfill": "npm:event-source-polyfill@^1.0.31",
35-
"jsonc-parser": "npm:jsonc-parser@^3.3.1",
3635
"open": "npm:open@^10.1.0",
3736
"superjson": "npm:superjson@^2.2.2",
3837
"@deno/framework-detect": "jsr:@deno/framework-detect@^0.3",

deno.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/mod.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,17 @@ deploy your local directory to the specified application.`)
228228
rootPath,
229229
);
230230

231-
await publish(
232-
options,
233-
config,
234-
rootPath,
235-
org,
236-
app,
237-
options.prod ?? created,
238-
options.wait ?? true,
239-
);
231+
if (!created) {
232+
await publish(
233+
options,
234+
config,
235+
rootPath,
236+
org,
237+
app,
238+
options.prod ?? false,
239+
options.wait ?? true,
240+
);
241+
}
240242
},
241243
(rootPath) => rootPath,
242244
),

dev_env.sh

100644100755
File mode changed.

rs_lib/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn inner_resolve_config(
5959
.append(exclude.into_path_or_patterns().into_iter());
6060
}
6161

62-
let files = collect_files(&real_sys, config.files, allow_node_modules);
62+
let files = collect_files(&real_sys, root_path, config.files, allow_node_modules);
6363

6464
return Ok(ConfigLookup {
6565
path: Some(deno_json.specifier.to_string()),
@@ -77,7 +77,7 @@ fn inner_resolve_config(
7777
.append(exclude.into_path_or_patterns().into_iter());
7878
}
7979

80-
let files = collect_files(&real_sys, files_config, allow_node_modules);
80+
let files = collect_files(&real_sys, root_path, files_config, allow_node_modules);
8181
return Ok(ConfigLookup {
8282
path: Some(deno_json.specifier.to_string()),
8383
files,
@@ -87,16 +87,19 @@ fn inner_resolve_config(
8787

8888
Ok(ConfigLookup {
8989
path: None,
90-
files: collect_files(&real_sys, FilePatterns::new_with_base(root_path), allow_node_modules),
90+
files: collect_files(&real_sys, root_path.clone(), FilePatterns::new_with_base(root_path), allow_node_modules),
9191
})
9292
}
9393

9494
fn collect_files(
9595
real_sys: &sys_traits::impls::RealSys,
96+
root_path: PathBuf,
9697
files: FilePatterns,
9798
allow_node_modules: bool,
9899
) -> Vec<String> {
99-
let mut collector = FileCollector::new(|_| true)
100+
let mut collector = FileCollector::new(|entry| {
101+
entry.path.starts_with(&root_path)
102+
})
100103
.ignore_git_folder()
101104
.use_gitignore();
102105

0 commit comments

Comments
 (0)