shell-dsl 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +24 -13
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/commands/awk/awk.cjs +19 -9
- package/dist/cjs/src/commands/awk/awk.cjs.map +2 -2
- package/dist/cjs/src/commands/break-continue/break-continue.cjs +19 -9
- package/dist/cjs/src/commands/break-continue/break-continue.cjs.map +2 -2
- package/dist/cjs/src/commands/cat/cat.cjs +19 -9
- package/dist/cjs/src/commands/cat/cat.cjs.map +2 -2
- package/dist/cjs/src/commands/cd/cd.cjs +19 -9
- package/dist/cjs/src/commands/cd/cd.cjs.map +2 -2
- package/dist/cjs/src/commands/colon/colon.cjs +19 -9
- package/dist/cjs/src/commands/colon/colon.cjs.map +2 -2
- package/dist/cjs/src/commands/cp/cp.cjs +19 -9
- package/dist/cjs/src/commands/cp/cp.cjs.map +2 -2
- package/dist/cjs/src/commands/cut/cut.cjs +19 -9
- package/dist/cjs/src/commands/cut/cut.cjs.map +2 -2
- package/dist/cjs/src/commands/echo/echo.cjs +19 -9
- package/dist/cjs/src/commands/echo/echo.cjs.map +2 -2
- package/dist/cjs/src/commands/find/find.cjs +19 -9
- package/dist/cjs/src/commands/find/find.cjs.map +2 -2
- package/dist/cjs/src/commands/grep/grep.cjs +19 -9
- package/dist/cjs/src/commands/grep/grep.cjs.map +2 -2
- package/dist/cjs/src/commands/head/head.cjs +19 -9
- package/dist/cjs/src/commands/head/head.cjs.map +2 -2
- package/dist/cjs/src/commands/index.cjs +19 -9
- package/dist/cjs/src/commands/index.cjs.map +2 -2
- package/dist/cjs/src/commands/ls/ls.cjs +19 -9
- package/dist/cjs/src/commands/ls/ls.cjs.map +2 -2
- package/dist/cjs/src/commands/mkdir/mkdir.cjs +19 -9
- package/dist/cjs/src/commands/mkdir/mkdir.cjs.map +2 -2
- package/dist/cjs/src/commands/mv/mv.cjs +19 -9
- package/dist/cjs/src/commands/mv/mv.cjs.map +2 -2
- package/dist/cjs/src/commands/pwd/pwd.cjs +19 -9
- package/dist/cjs/src/commands/pwd/pwd.cjs.map +2 -2
- package/dist/cjs/src/commands/rm/rm.cjs +19 -9
- package/dist/cjs/src/commands/rm/rm.cjs.map +2 -2
- package/dist/cjs/src/commands/sed/sed.cjs +19 -9
- package/dist/cjs/src/commands/sed/sed.cjs.map +2 -2
- package/dist/cjs/src/commands/sort/sort.cjs +19 -9
- package/dist/cjs/src/commands/sort/sort.cjs.map +2 -2
- package/dist/cjs/src/commands/tail/tail.cjs +19 -9
- package/dist/cjs/src/commands/tail/tail.cjs.map +2 -2
- package/dist/cjs/src/commands/tee/tee.cjs +19 -9
- package/dist/cjs/src/commands/tee/tee.cjs.map +2 -2
- package/dist/cjs/src/commands/test/test.cjs +19 -9
- package/dist/cjs/src/commands/test/test.cjs.map +2 -2
- package/dist/cjs/src/commands/touch/touch.cjs +19 -9
- package/dist/cjs/src/commands/touch/touch.cjs.map +2 -2
- package/dist/cjs/src/commands/tr/tr.cjs +19 -9
- package/dist/cjs/src/commands/tr/tr.cjs.map +2 -2
- package/dist/cjs/src/commands/tree/tree.cjs +19 -9
- package/dist/cjs/src/commands/tree/tree.cjs.map +2 -2
- package/dist/cjs/src/commands/true-false/true-false.cjs +19 -9
- package/dist/cjs/src/commands/true-false/true-false.cjs.map +2 -2
- package/dist/cjs/src/commands/uniq/uniq.cjs +19 -9
- package/dist/cjs/src/commands/uniq/uniq.cjs.map +2 -2
- package/dist/cjs/src/commands/wc/wc.cjs +19 -9
- package/dist/cjs/src/commands/wc/wc.cjs.map +2 -2
- package/dist/cjs/src/errors.cjs +19 -9
- package/dist/cjs/src/errors.cjs.map +2 -2
- package/dist/cjs/src/fs/index.cjs +19 -9
- package/dist/cjs/src/fs/index.cjs.map +2 -2
- package/dist/cjs/src/fs/memfs-adapter.cjs +31 -10
- package/dist/cjs/src/fs/memfs-adapter.cjs.map +2 -2
- package/dist/cjs/src/fs/readonly-fs.cjs +19 -9
- package/dist/cjs/src/fs/readonly-fs.cjs.map +2 -2
- package/dist/cjs/src/fs/real-fs.cjs +31 -10
- package/dist/cjs/src/fs/real-fs.cjs.map +2 -2
- package/dist/cjs/src/index.cjs +19 -9
- package/dist/cjs/src/index.cjs.map +2 -2
- package/dist/cjs/src/interpreter/context.cjs +19 -9
- package/dist/cjs/src/interpreter/context.cjs.map +2 -2
- package/dist/cjs/src/interpreter/index.cjs +19 -9
- package/dist/cjs/src/interpreter/index.cjs.map +2 -2
- package/dist/cjs/src/interpreter/interpreter.cjs +19 -9
- package/dist/cjs/src/interpreter/interpreter.cjs.map +2 -2
- package/dist/cjs/src/io/index.cjs +19 -9
- package/dist/cjs/src/io/index.cjs.map +2 -2
- package/dist/cjs/src/io/stdin.cjs +19 -9
- package/dist/cjs/src/io/stdin.cjs.map +2 -2
- package/dist/cjs/src/io/stdout.cjs +19 -9
- package/dist/cjs/src/io/stdout.cjs.map +2 -2
- package/dist/cjs/src/lexer/index.cjs +19 -9
- package/dist/cjs/src/lexer/index.cjs.map +2 -2
- package/dist/cjs/src/lexer/lexer.cjs +19 -9
- package/dist/cjs/src/lexer/lexer.cjs.map +2 -2
- package/dist/cjs/src/lexer/tokens.cjs +19 -9
- package/dist/cjs/src/lexer/tokens.cjs.map +2 -2
- package/dist/cjs/src/parser/ast.cjs +19 -9
- package/dist/cjs/src/parser/ast.cjs.map +2 -2
- package/dist/cjs/src/parser/index.cjs +19 -9
- package/dist/cjs/src/parser/index.cjs.map +2 -2
- package/dist/cjs/src/parser/parser.cjs +19 -9
- package/dist/cjs/src/parser/parser.cjs.map +2 -2
- package/dist/cjs/src/shell-dsl.cjs +19 -9
- package/dist/cjs/src/shell-dsl.cjs.map +2 -2
- package/dist/cjs/src/shell-promise.cjs +19 -9
- package/dist/cjs/src/shell-promise.cjs.map +2 -2
- package/dist/cjs/src/types.cjs +19 -9
- package/dist/cjs/src/types.cjs.map +2 -2
- package/dist/cjs/src/utils/escape.cjs +19 -9
- package/dist/cjs/src/utils/escape.cjs.map +2 -2
- package/dist/cjs/src/utils/expand-escapes.cjs +19 -9
- package/dist/cjs/src/utils/expand-escapes.cjs.map +2 -2
- package/dist/cjs/src/utils/flag-parser.cjs +27 -9
- package/dist/cjs/src/utils/flag-parser.cjs.map +3 -3
- package/dist/cjs/src/utils/index.cjs +19 -9
- package/dist/cjs/src/utils/index.cjs.map +2 -2
- package/dist/cjs/src/utils/match-glob.cjs +19 -9
- package/dist/cjs/src/utils/match-glob.cjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/utils/flag-parser.mjs +9 -1
- package/dist/mjs/src/utils/flag-parser.mjs.map +3 -3
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,44 +2,55 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
5
8
|
var __reExport = (target, mod, secondTarget) => {
|
|
6
|
-
|
|
9
|
+
var keys = __getOwnPropNames(mod);
|
|
10
|
+
for (let key of keys)
|
|
7
11
|
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
8
12
|
__defProp(target, key, {
|
|
9
|
-
get: (
|
|
13
|
+
get: __accessProp.bind(mod, key),
|
|
10
14
|
enumerable: true
|
|
11
15
|
});
|
|
12
16
|
if (secondTarget) {
|
|
13
|
-
for (let key of
|
|
17
|
+
for (let key of keys)
|
|
14
18
|
if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
|
|
15
19
|
__defProp(secondTarget, key, {
|
|
16
|
-
get: (
|
|
20
|
+
get: __accessProp.bind(mod, key),
|
|
17
21
|
enumerable: true
|
|
18
22
|
});
|
|
19
23
|
return secondTarget;
|
|
20
24
|
}
|
|
21
25
|
};
|
|
22
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
23
26
|
var __toCommonJS = (from) => {
|
|
24
|
-
var entry = __moduleCache.get(from), desc;
|
|
27
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
25
28
|
if (entry)
|
|
26
29
|
return entry;
|
|
27
30
|
entry = __defProp({}, "__esModule", { value: true });
|
|
28
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (var key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(entry, key))
|
|
34
|
+
__defProp(entry, key, {
|
|
35
|
+
get: __accessProp.bind(from, key),
|
|
36
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
37
|
+
});
|
|
38
|
+
}
|
|
33
39
|
__moduleCache.set(from, entry);
|
|
34
40
|
return entry;
|
|
35
41
|
};
|
|
42
|
+
var __moduleCache;
|
|
43
|
+
var __returnValue = (v) => v;
|
|
44
|
+
function __exportSetter(name, newValue) {
|
|
45
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
46
|
+
}
|
|
36
47
|
var __export = (target, all) => {
|
|
37
48
|
for (var name in all)
|
|
38
49
|
__defProp(target, name, {
|
|
39
50
|
get: all[name],
|
|
40
51
|
enumerable: true,
|
|
41
52
|
configurable: true,
|
|
42
|
-
set: (
|
|
53
|
+
set: __exportSetter.bind(all, name)
|
|
43
54
|
});
|
|
44
55
|
};
|
|
45
56
|
|
|
@@ -79,4 +90,4 @@ __reExport(exports_shell_dsl, require("./src/index.cjs"), module.exports);
|
|
|
79
90
|
var import_commands = require("./src/commands/index.cjs");
|
|
80
91
|
var import_commands2 = require("./src/commands/index.cjs");
|
|
81
92
|
|
|
82
|
-
//# debugId=
|
|
93
|
+
//# debugId=1205A0385489D10D64756E2164756E21
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// Re-export everything from src\nexport * from \"./src/index.cjs\";\n\n// Re-export built-in commands\nexport { builtinCommands } from \"./src/commands/index.cjs\";\nexport {\n echo,\n cat,\n grep,\n wc,\n head,\n tail,\n sort,\n uniq,\n pwd,\n ls,\n mkdir,\n rm,\n test,\n bracket,\n trueCmd,\n falseCmd,\n touch,\n cp,\n mv,\n tee,\n tree,\n find,\n sed,\n awk,\n breakCmd,\n continueCmd,\n} from \"./src/commands/index.cjs\";\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAGgC,IAAhC;AA4BO,IA3BP;",
|
|
8
|
+
"debugId": "1205A0385489D10D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -322,4 +332,4 @@ var awk = async (ctx) => {
|
|
|
322
332
|
return 0;
|
|
323
333
|
};
|
|
324
334
|
|
|
325
|
-
//# debugId=
|
|
335
|
+
//# debugId=34567F9F5DE564DB64756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\nimport { expandEscapes } from \"../../utils/expand-escapes.cjs\";\n\ninterface AwkRule {\n pattern?: RegExp;\n action: string;\n}\n\ninterface AwkOptions {\n fieldSeparator: RegExp;\n program: AwkRule[];\n}\n\ninterface ParseArgsResult {\n options: AwkOptions;\n files: string[];\n error?: { type: \"unrecognized_option\" | \"missing_value\"; option: string };\n}\n\nfunction parseProgram(programStr: string): AwkRule[] {\n const rules: AwkRule[] = [];\n const trimmed = programStr.trim();\n\n // Simple parser for patterns like: /regex/ {action} or {action}\n // Handle multiple rules separated by whitespace/newlines\n\n let remaining = trimmed;\n\n while (remaining.length > 0) {\n remaining = remaining.trim();\n if (remaining.length === 0) break;\n\n let pattern: RegExp | undefined;\n let action = \"\";\n\n // Check for /pattern/ prefix\n if (remaining.startsWith(\"/\")) {\n const endSlash = remaining.indexOf(\"/\", 1);\n if (endSlash > 1) {\n const patternStr = remaining.slice(1, endSlash);\n try {\n pattern = new RegExp(patternStr);\n } catch {\n // Invalid regex, skip\n }\n remaining = remaining.slice(endSlash + 1).trim();\n }\n }\n\n // Check for {action} block\n if (remaining.startsWith(\"{\")) {\n let braceCount = 1;\n let i = 1;\n while (i < remaining.length && braceCount > 0) {\n if (remaining[i] === \"{\") braceCount++;\n else if (remaining[i] === \"}\") braceCount--;\n i++;\n }\n action = remaining.slice(1, i - 1).trim();\n remaining = remaining.slice(i).trim();\n } else if (pattern) {\n // Pattern without action - default action is print\n action = \"print\";\n } else {\n // No pattern and no action block, might be malformed\n break;\n }\n\n if (action || pattern) {\n rules.push({ pattern, action: action || \"print\" });\n }\n }\n\n return rules;\n}\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction parseArgs(args: string[]): ParseArgsResult {\n const options: AwkOptions = {\n fieldSeparator: /[ \\t]+/,\n program: [],\n };\n const files: string[] = [];\n\n let i = 0;\n let programFound = false;\n\n while (i < args.length) {\n const arg = args[i]!;\n\n // Handle -- to stop flag parsing\n if (arg === \"--\") {\n i++;\n while (i < args.length) {\n const remaining = args[i]!;\n if (!programFound) {\n options.program = parseProgram(remaining);\n programFound = true;\n } else {\n files.push(remaining);\n }\n i++;\n }\n break;\n }\n\n // Long flag handling\n if (arg.startsWith(\"--\")) {\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: arg },\n };\n }\n\n // Short flag handling\n if (arg.startsWith(\"-\") && arg.length > 1) {\n const char = arg[1]!;\n\n if (char === \"F\") {\n // -F takes a field separator argument\n const restOfArg = arg.slice(2);\n let fs: string;\n\n if (restOfArg.length > 0) {\n fs = restOfArg;\n } else if (i + 1 < args.length) {\n fs = args[++i]!;\n } else {\n return {\n options,\n files,\n error: { type: \"missing_value\", option: \"-F\" },\n };\n }\n\n // Expand escape sequences (e.g. \\t → tab)\n fs = expandEscapes(fs);\n\n // For single character separators, match exactly\n // For patterns, use as regex\n if (fs.length === 1) {\n options.fieldSeparator = new RegExp(escapeRegex(fs));\n } else {\n try {\n options.fieldSeparator = new RegExp(fs);\n } catch {\n options.fieldSeparator = new RegExp(escapeRegex(fs));\n }\n }\n i++;\n continue;\n } else {\n // Unknown flag\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: `-${char}` },\n };\n }\n }\n\n // Non-flag argument\n if (!programFound) {\n options.program = parseProgram(arg);\n programFound = true;\n } else {\n files.push(arg);\n }\n i++;\n }\n\n return { options, files };\n}\n\nfunction formatError(error: NonNullable<ParseArgsResult[\"error\"]>): string {\n let message: string;\n if (error.type === \"unrecognized_option\") {\n if (error.option.startsWith(\"--\")) {\n message = `awk: unrecognized option '${error.option}'\\n`;\n } else {\n message = `awk: invalid option -- '${error.option.slice(1)}'\\n`;\n }\n } else {\n message = `awk: option '${error.option}' requires an argument\\n`;\n }\n return message + `usage: awk [-F fs] 'program' [file ...]\\n`;\n}\n\nfunction splitFields(line: string, separator: RegExp): string[] {\n // Split and filter empty strings for whitespace separation\n const parts = line.split(separator);\n // For whitespace separator, filter leading empty string\n if (separator.source === \"[ \\\\t]+\" && parts[0] === \"\") {\n parts.shift();\n }\n return parts;\n}\n\nfunction executeAction(\n action: string,\n fields: string[],\n line: string,\n lineNumber: number\n): string | null {\n // Parse and execute the action\n // Supported: print, print $0, print $1, print $1, $2, etc.\n\n const trimmedAction = action.trim();\n\n if (trimmedAction === \"\" || trimmedAction === \"print\" || trimmedAction === \"print $0\") {\n return line;\n }\n\n // Check for print with field references\n if (trimmedAction.startsWith(\"print\")) {\n const printArgs = trimmedAction.slice(5).trim();\n return evaluatePrintArgs(printArgs, fields, line, lineNumber);\n }\n\n // Just field reference without print (implicit print)\n if (trimmedAction.startsWith(\"$\")) {\n return evaluatePrintArgs(trimmedAction, fields, line, lineNumber);\n }\n\n return null;\n}\n\nfunction evaluatePrintArgs(\n argsStr: string,\n fields: string[],\n line: string,\n lineNumber: number\n): string {\n const results: string[] = [];\n\n // Split by comma for multiple arguments\n const args = argsStr.split(\",\").map((a) => a.trim());\n\n for (const arg of args) {\n const value = evaluateExpression(arg, fields, line, lineNumber);\n results.push(value);\n }\n\n return results.join(\" \");\n}\n\nfunction tokenizeExpression(expr: string): string[] {\n const tokens: string[] = [];\n let i = 0;\n const str = expr.trim();\n\n while (i < str.length) {\n // Skip whitespace\n while (i < str.length && /\\s/.test(str[i]!)) {\n i++;\n }\n if (i >= str.length) break;\n\n // String literal\n if (str[i] === '\"' || str[i] === \"'\") {\n const quote = str[i]!;\n let j = i + 1;\n while (j < str.length && str[j] !== quote) {\n j++;\n }\n tokens.push(str.slice(i, j + 1));\n i = j + 1;\n }\n // Field reference or variable\n else if (str[i] === '$' || /[a-zA-Z]/.test(str[i]!)) {\n let j = i;\n while (j < str.length && /[\\w$]/.test(str[j]!)) {\n j++;\n }\n tokens.push(str.slice(i, j));\n i = j;\n }\n // Other characters\n else {\n tokens.push(str[i]!);\n i++;\n }\n }\n\n return tokens;\n}\n\nfunction evaluateExpression(\n expr: string,\n fields: string[],\n line: string,\n lineNumber: number\n): string {\n const tokens = tokenizeExpression(expr);\n\n if (tokens.length === 0) {\n return \"\";\n }\n\n // Evaluate each token and concatenate\n const parts: string[] = [];\n for (const token of tokens) {\n // String literal\n if ((token.startsWith('\"') && token.endsWith('\"')) ||\n (token.startsWith(\"'\") && token.endsWith(\"'\"))) {\n parts.push(expandEscapes(token.slice(1, -1)));\n }\n // Field reference $0, $1, etc.\n else if (token.match(/^\\$(\\d+)$/)) {\n const fieldNum = parseInt(token.slice(1), 10);\n if (fieldNum === 0) {\n parts.push(line);\n } else {\n parts.push(fields[fieldNum - 1] ?? \"\");\n }\n }\n // Built-in variables\n else if (token === \"NF\") {\n parts.push(String(fields.length));\n }\n else if (token === \"NR\") {\n parts.push(String(lineNumber));\n }\n // Unknown - return as-is\n else {\n parts.push(token);\n }\n }\n\n return parts.join(\"\");\n}\n\nfunction processLine(\n line: string,\n lineNumber: number,\n options: AwkOptions\n): string[] {\n const fields = splitFields(line, options.fieldSeparator);\n const outputs: string[] = [];\n\n for (const rule of options.program) {\n // Check pattern match\n if (rule.pattern && !rule.pattern.test(line)) {\n continue;\n }\n\n const result = executeAction(rule.action, fields, line, lineNumber);\n if (result !== null) {\n outputs.push(result);\n }\n }\n\n return outputs;\n}\n\nexport const awk: Command = async (ctx) => {\n const { options, files, error } = parseArgs(ctx.args);\n\n if (error) {\n await ctx.stderr.writeText(formatError(error));\n return 1;\n }\n\n if (options.program.length === 0) {\n await ctx.stderr.writeText(\"awk: missing program\\n\");\n return 1;\n }\n\n let lineNumber = 0;\n\n const processContent = async (content: string): Promise<void> => {\n const lines = content.split(\"\\n\");\n // Handle trailing newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n\n for (const line of lines) {\n lineNumber++;\n const outputs = processLine(line, lineNumber, options);\n for (const output of outputs) {\n await ctx.stdout.writeText(output + \"\\n\");\n }\n }\n };\n\n if (files.length === 0) {\n // Read from stdin\n const content = await ctx.stdin.text();\n await processContent(content);\n } else {\n // Read from files\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n await processContent(content.toString());\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`awk: ${file}: ${message}\\n`);\n return 1;\n }\n }\n }\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAS;AAAA,QAC5B,MAAM,IAAI,OAAO,UAAU,SAAS;AAAA,CAAI;AAAA,MAC1C;AAAA,IACF;AAAA;AAAA,EAGF,IAAI,MAAM,WAAW,GAAG;AAAA,IAEtB,MAAM,UAAU,MAAM,IAAI,MAAM,KAAK;AAAA,IACrC,MAAM,eAAe,OAAO;AAAA,EAC9B,EAAO;AAAA,IAEL,WAAW,QAAQ,OAAO;AAAA,MACxB,IAAI;AAAA,QACF,MAAM,OAAO,IAAI,GAAG,QAAQ,IAAI,KAAK,IAAI;AAAA,QACzC,MAAM,UAAU,MAAM,IAAI,GAAG,SAAS,IAAI;AAAA,QAC1C,MAAM,eAAe,QAAQ,SAAS,CAAC;AAAA,QACvC,OAAO,KAAK;AAAA,QACZ,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,QAC/D,MAAM,IAAI,OAAO,UAAU,QAAQ,SAAS;AAAA,CAAW;AAAA,QACvD,OAAO;AAAA;AAAA,IAEX;AAAA;AAAA,EAGF,OAAO;AAAA;",
|
|
8
|
+
"debugId": "34567F9F5DE564DB64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -53,4 +63,4 @@ var continueCmd = async (ctx) => {
|
|
|
53
63
|
throw new import_interpreter.ContinueException(levels);
|
|
54
64
|
};
|
|
55
65
|
|
|
56
|
-
//# debugId=
|
|
66
|
+
//# debugId=CE23DE6EFD3E65A664756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\nimport { BreakException, ContinueException } from \"../../interpreter/interpreter.cjs\";\n\nexport const breakCmd: Command = async (ctx) => {\n const levels = ctx.args[0] ? parseInt(ctx.args[0], 10) : 1;\n if (isNaN(levels) || levels < 1) {\n await ctx.stderr.writeText(\"break: invalid level\\n\");\n return 1;\n }\n throw new BreakException(levels);\n};\n\nexport const continueCmd: Command = async (ctx) => {\n const levels = ctx.args[0] ? parseInt(ctx.args[0], 10) : 1;\n if (isNaN(levels) || levels < 1) {\n await ctx.stderr.writeText(\"continue: invalid level\\n\");\n return 1;\n }\n throw new ContinueException(levels);\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACkD,IAAlD;AAEO,IAAM,WAAoB,OAAO,QAAQ;AAAA,EAC9C,MAAM,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,EAAE,IAAI;AAAA,EACzD,IAAI,MAAM,MAAM,KAAK,SAAS,GAAG;AAAA,IAC/B,MAAM,IAAI,OAAO,UAAU;AAAA,CAAwB;AAAA,IACnD,OAAO;AAAA,EACT;AAAA,EACA,MAAM,IAAI,kCAAe,MAAM;AAAA;AAG1B,IAAM,cAAuB,OAAO,QAAQ;AAAA,EACjD,MAAM,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,IAAI,EAAE,IAAI;AAAA,EACzD,IAAI,MAAM,MAAM,KAAK,SAAS,GAAG;AAAA,IAC/B,MAAM,IAAI,OAAO,UAAU;AAAA,CAA2B;AAAA,IACtD,OAAO;AAAA,EACT;AAAA,EACA,MAAM,IAAI,qCAAkB,MAAM;AAAA;",
|
|
8
|
+
"debugId": "CE23DE6EFD3E65A664756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -166,4 +176,4 @@ var cat = async (ctx) => {
|
|
|
166
176
|
return 0;
|
|
167
177
|
};
|
|
168
178
|
|
|
169
|
-
//# debugId=
|
|
179
|
+
//# debugId=431D32F56AC89BDC64756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface CatFlags {\n A: boolean; // show all (equivalent to -vET)\n b: boolean; // number non-blank lines\n E: boolean; // show $ at end of lines\n n: boolean; // number all lines\n T: boolean; // show tabs as ^I\n v: boolean; // show non-printing characters\n}\n\nconst spec = {\n name: \"cat\",\n flags: [\n { short: \"A\", long: \"show-all\" },\n { short: \"b\", long: \"number-nonblank\" },\n { short: \"E\", long: \"show-ends\" },\n { short: \"n\", long: \"number\" },\n { short: \"T\", long: \"show-tabs\" },\n { short: \"v\", long: \"show-nonprinting\" },\n ] as FlagDefinition[],\n usage: \"cat [-AbEnTv] [file ...]\",\n};\n\nconst defaultFlags: CatFlags = {\n A: false,\n b: false,\n E: false,\n n: false,\n T: false,\n v: false,\n};\n\nconst parser = createFlagParser(spec, defaultFlags, (flags, flagDef) => {\n if (flagDef.short) {\n flags[flagDef.short as keyof CatFlags] = true;\n }\n});\n\nfunction showNonPrintingChar(charCode: number): string {\n if (charCode === 9) {\n // Tab - handled separately\n return \"\\t\";\n } else if (charCode === 10) {\n // Newline - pass through\n return \"\\n\";\n } else if (charCode < 32) {\n // Control characters 0-31 (except tab/newline)\n return \"^\" + String.fromCharCode(charCode + 64);\n } else if (charCode === 127) {\n // DEL\n return \"^?\";\n } else if (charCode >= 128 && charCode < 160) {\n // High control characters (M-^@, M-^A, etc.)\n return \"M-^\" + String.fromCharCode(charCode - 128 + 64);\n } else if (charCode >= 160 && charCode < 255) {\n // High printable characters (M-<space>, etc.)\n return \"M-\" + String.fromCharCode(charCode - 128);\n } else if (charCode === 255) {\n // M-^?\n return \"M-^?\";\n }\n return String.fromCharCode(charCode);\n}\n\nfunction processLine(line: string, flags: CatFlags): string {\n let result = \"\";\n\n for (let i = 0; i < line.length; i++) {\n const char = line[i]!;\n const charCode = char.charCodeAt(0);\n\n if (flags.T && charCode === 9) {\n result += \"^I\";\n } else if (flags.v && (charCode < 32 || charCode >= 127) && charCode !== 9 && charCode !== 10) {\n result += showNonPrintingChar(charCode);\n } else {\n result += char;\n }\n }\n\n if (flags.E) {\n result += \"$\";\n }\n\n return result;\n}\n\nfunction formatLineNumber(num: number): string {\n return num.toString().padStart(6, \" \") + \"\\t\";\n}\n\nexport const cat: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const files = result.args;\n const flags: CatFlags = { ...result.flags };\n\n // -A is equivalent to -vET\n if (flags.A) {\n flags.v = true;\n flags.E = true;\n flags.T = true;\n }\n\n const needsProcessing = flags.n || flags.b || flags.E || flags.T || flags.v;\n let lineNumber = 1;\n\n const processContent = async (content: Buffer | Uint8Array) => {\n if (!needsProcessing) {\n await ctx.stdout.write(new Uint8Array(content));\n return;\n }\n\n const text = Buffer.from(content).toString(\"utf-8\");\n const lines = text.split(\"\\n\");\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n const isLastLine = i === lines.length - 1;\n const isEmpty = line === \"\";\n\n // Skip the final empty element from split (no trailing output)\n if (isLastLine && isEmpty) {\n continue;\n }\n\n let output = processLine(line, flags);\n\n // Line numbering\n if (flags.b) {\n // Number non-blank lines only\n if (!isEmpty) {\n output = formatLineNumber(lineNumber++) + output;\n }\n } else if (flags.n) {\n // Number all lines\n output = formatLineNumber(lineNumber++) + output;\n }\n\n await ctx.stdout.writeText(output + \"\\n\");\n }\n };\n\n if (files.length === 0) {\n // Read from stdin\n if (!needsProcessing) {\n for await (const chunk of ctx.stdin.stream()) {\n await ctx.stdout.write(chunk);\n }\n } else {\n const content = await ctx.stdin.buffer();\n await processContent(content);\n }\n } else {\n // Read from files\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n await processContent(new Uint8Array(content));\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`cat: ${file}: ${message}\\n`);\n return 1;\n }\n }\n }\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;A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A,QAC/D,MAAM,IAAI,OAAO,UAAU,QAAQ,SAAS;AAAA,CAAW;AAAA,QACvD,OAAO;AAAA;AAAA,IAEX;AAAA;AAAA,EAEF,OAAO;AAAA;",
|
|
8
|
+
"debugId": "431D32F56AC89BDC64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -63,4 +73,4 @@ var cd = async (ctx) => {
|
|
|
63
73
|
return 0;
|
|
64
74
|
};
|
|
65
75
|
|
|
66
|
-
//# debugId=
|
|
76
|
+
//# debugId=E21D0B48E6C6A12C64756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\n\nexport const cd: Command = async (ctx) => {\n if (ctx.args.length === 0) {\n return 0;\n }\n\n let target = ctx.args[0]!;\n\n if (target === \"-\") {\n const oldpwd = ctx.env.OLDPWD;\n if (!oldpwd) {\n await ctx.stderr.writeText(\"cd: OLDPWD not set\\n\");\n return 1;\n }\n target = oldpwd;\n }\n\n const resolved = ctx.fs.resolve(ctx.cwd, target);\n\n try {\n const stat = await ctx.fs.stat(resolved);\n if (!stat.isDirectory()) {\n await ctx.stderr.writeText(`cd: not a directory: ${target}\\n`);\n return 1;\n }\n } catch {\n await ctx.stderr.writeText(`cd: not a directory: ${target}\\n`);\n return 1;\n }\n\n ctx.setCwd(resolved);\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAM,KAAc,OAAO,QAAQ;AAAA,EACxC,IAAI,IAAI,KAAK,WAAW,GAAG;AAAA,IACzB,OAAO;AAAA,EACT;AAAA,EAEA,IAAI,SAAS,IAAI,KAAK;AAAA,EAEtB,IAAI,WAAW,KAAK;AAAA,IAClB,MAAM,SAAS,IAAI,IAAI;AAAA,IACvB,IAAI,CAAC,QAAQ;AAAA,MACX,MAAM,IAAI,OAAO,UAAU;AAAA,CAAsB;AAAA,MACjD,OAAO;AAAA,IACT;AAAA,IACA,SAAS;AAAA,EACX;AAAA,EAEA,MAAM,WAAW,IAAI,GAAG,QAAQ,IAAI,KAAK,MAAM;AAAA,EAE/C,IAAI;AAAA,IACF,MAAM,OAAO,MAAM,IAAI,GAAG,KAAK,QAAQ;AAAA,IACvC,IAAI,CAAC,KAAK,YAAY,GAAG;AAAA,MACvB,MAAM,IAAI,OAAO,UAAU,wBAAwB;AAAA,CAAU;AAAA,MAC7D,OAAO;AAAA,IACT;AAAA,IACA,MAAM;AAAA,IACN,MAAM,IAAI,OAAO,UAAU,wBAAwB;AAAA,CAAU;AAAA,IAC7D,OAAO;AAAA;AAAA,EAGT,IAAI,OAAO,QAAQ;AAAA,EAEnB,OAAO;AAAA;",
|
|
8
|
+
"debugId": "E21D0B48E6C6A12C64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -36,4 +46,4 @@ var colon = async (_ctx) => {
|
|
|
36
46
|
return 0;
|
|
37
47
|
};
|
|
38
48
|
|
|
39
|
-
//# debugId=
|
|
49
|
+
//# debugId=09D392CABC1F7FF364756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\n\nexport const colon: Command = async (_ctx) => {\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAM,QAAiB,OAAO,SAAS;AAAA,EAC5C,OAAO;AAAA;",
|
|
8
|
+
"debugId": "09D392CABC1F7FF364756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -129,4 +139,4 @@ async function copyDirectory(ctx, src, dest, noClobber) {
|
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
//# debugId=
|
|
142
|
+
//# debugId=CE0187CCE02D936164756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface CpFlags {\n recursive: boolean;\n noClobber: boolean;\n}\n\nconst spec = {\n name: \"cp\",\n flags: [\n { short: \"r\", long: \"recursive\" },\n { short: \"R\" },\n { short: \"n\", long: \"no-clobber\" },\n { short: \"f\", long: \"force\" },\n ] as FlagDefinition[],\n usage: \"cp [-rRnf] source ... dest\",\n};\n\nconst defaults: CpFlags = { recursive: false, noClobber: false };\n\nconst handler = (flags: CpFlags, flag: FlagDefinition) => {\n if (flag.short === \"r\" || flag.short === \"R\") flags.recursive = true;\n if (flag.short === \"n\") flags.noClobber = true;\n // -f is default behavior, so we don't need to do anything\n};\n\nconst parser = createFlagParser(spec, defaults, handler);\n\nexport const cp: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const { recursive, noClobber } = result.flags;\n const paths = result.args;\n\n if (paths.length < 2) {\n await ctx.stderr.writeText(\"cp: missing destination file operand\\n\");\n return 1;\n }\n\n const sources = paths.slice(0, -1);\n const dest = paths[paths.length - 1]!;\n const destPath = ctx.fs.resolve(ctx.cwd, dest);\n\n // Check if destination is a directory\n let destIsDir = false;\n try {\n const stat = await ctx.fs.stat(destPath);\n destIsDir = stat.isDirectory();\n } catch {\n // Destination doesn't exist\n }\n\n // If multiple sources, dest must be a directory\n if (sources.length > 1 && !destIsDir) {\n await ctx.stderr.writeText(`cp: target '${dest}' is not a directory\\n`);\n return 1;\n }\n\n for (const source of sources) {\n const srcPath = ctx.fs.resolve(ctx.cwd, source);\n\n try {\n const srcStat = await ctx.fs.stat(srcPath);\n\n if (srcStat.isDirectory()) {\n if (!recursive) {\n await ctx.stderr.writeText(`cp: -r not specified; omitting directory '${source}'\\n`);\n return 1;\n }\n // Copy directory recursively\n const finalDest = destIsDir\n ? ctx.fs.resolve(destPath, ctx.fs.basename(srcPath))\n : destPath;\n\n await copyDirectory(ctx, srcPath, finalDest, noClobber);\n } else {\n // Copy file\n const finalDest = destIsDir\n ? ctx.fs.resolve(destPath, ctx.fs.basename(srcPath))\n : destPath;\n\n // Check if dest exists and noClobber\n if (noClobber) {\n const exists = await ctx.fs.exists(finalDest);\n if (exists) continue; // Skip silently\n }\n\n const content = await ctx.fs.readFile(srcPath);\n await ctx.fs.writeFile(finalDest, content);\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`cp: cannot stat '${source}': ${message}\\n`);\n return 1;\n }\n }\n\n return 0;\n};\n\nasync function copyDirectory(\n ctx: Parameters<Command>[0],\n src: string,\n dest: string,\n noClobber: boolean\n): Promise<void> {\n // Create destination directory\n await ctx.fs.mkdir(dest, { recursive: true });\n\n // Read source directory contents\n const entries = await ctx.fs.readdir(src);\n\n for (const entry of entries) {\n const srcPath = ctx.fs.resolve(src, entry);\n const destPath = ctx.fs.resolve(dest, entry);\n\n const stat = await ctx.fs.stat(srcPath);\n\n if (stat.isDirectory()) {\n await copyDirectory(ctx, srcPath, destPath, noClobber);\n } else {\n if (noClobber) {\n const exists = await ctx.fs.exists(destPath);\n if (exists) continue;\n }\n const content = await ctx.fs.readFile(srcPath);\n await ctx.fs.writeFile(destPath, content);\n }\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;AAOA,IAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,IACL,EAAE,OAAO,KAAK,MAAM,YAAY;AAAA,IAChC,EAAE,OAAO,IAAI;AAAA,IACb,EAAE,OAAO,KAAK,MAAM,aAAa;AAAA,IACjC,EAAE,OAAO,KAAK,MAAM,QAAQ;AAAA,EAC9B;AAAA,EACA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A,IAEtC,IAAI,KAAK,YAAY,GAAG;AAAA,MACtB,MAAM,cAAc,KAAK,SAAS,UAAU,SAAS;AAAA,IACvD,EAAO;AAAA,MACL,IAAI,WAAW;AAAA,QACb,MAAM,SAAS,MAAM,IAAI,GAAG,OAAO,QAAQ;AAAA,QAC3C,IAAI;AAAA,UAAQ;AAAA,MACd;AAAA,MACA,MAAM,UAAU,MAAM,IAAI,GAAG,SAAS,OAAO;AAAA,MAC7C,MAAM,IAAI,GAAG,UAAU,UAAU,OAAO;AAAA;AAAA,EAE5C;AAAA;",
|
|
8
|
+
"debugId": "CE0187CCE02D936164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -185,4 +195,4 @@ var cut = async (ctx) => {
|
|
|
185
195
|
return 0;
|
|
186
196
|
};
|
|
187
197
|
|
|
188
|
-
//# debugId=
|
|
198
|
+
//# debugId=CE8614538A4CB1BF64756E2164756E21
|