Skip to content

Commit

Permalink
refactor: migrate curl parse to args-tokenizer (#4628)
Browse files Browse the repository at this point in the history
Created new package https://github.com/TrySound/args-tokenizer for curl
parser. Might be useful in combination with tinyexec.
  • Loading branch information
TrySound authored Dec 21, 2024
1 parent 7ec6c73 commit e877b1f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
3 changes: 0 additions & 3 deletions @types/arrgv.d.ts

This file was deleted.

12 changes: 2 additions & 10 deletions apps/builder/app/builder/features/settings-panel/curl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ResourceRequest } from "@webstudio-is/sdk";
import arrgv from "arrgv";
import { tokenizeArgs } from "args-tokenizer";
import { parse as parseArgs } from "ultraflag";

/*
Expand Down Expand Up @@ -30,15 +30,7 @@ export type CurlRequest = Pick<
>;

export const parseCurl = (curl: string): undefined | CurlRequest => {
// remove backslash followed by newline
// https://github.com/astur/arrgv/issues/3
curl = curl.replaceAll(/\\(?=\s)/g, "");
let argv;
try {
argv = arrgv(curl);
} catch {
return;
}
const argv = tokenizeArgs(curl);
if (argv.length === 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@webstudio-is/sdk-components-react-radix": "workspace:*",
"@webstudio-is/template": "workspace:*",
"@webstudio-is/trpc-interface": "workspace:*",
"arrgv": "^1.0.2",
"args-tokenizer": "^0.1.0",
"bcp-47": "^2.1.0",
"change-case": "^5.4.4",
"colord": "^2.9.3",
Expand Down
17 changes: 8 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e877b1f

Please sign in to comment.