@songtonyli/dsh-cli 0.1.58 → 0.1.60

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.
Files changed (139) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +1 -0
  4. package/node_modules/@deepseek-ai/dsh-api-session-controller/lib/client.js +1 -0
  5. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +1 -1
  6. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  7. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  8. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +59 -4
  9. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +73 -0
  10. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +166 -0
  11. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +166 -0
  12. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +227 -0
  13. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +704 -0
  14. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/package.json +62 -0
  15. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.i18n.yaml +2 -2
  16. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.md +1 -1
  17. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.zh.md +1 -1
  18. package/node_modules/@deepseek-ai/dsh-sandbox-policy/lib/index.js +23 -0
  19. package/node_modules/@deepseek-ai/dsh-session/lib/index.js +1 -0
  20. package/node_modules/@deepseek-ai/dsh-session/lib/types/known-event-types.js +1 -0
  21. package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/worker.cjs +1 -0
  22. package/node_modules/@deepseek-ai/dsh-system-prompt/lib/index.js +1 -0
  23. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +22 -0
  24. package/node_modules/@deepseek-ai/dsh-tool-fs/README.i18n.yaml +2 -2
  25. package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
  26. package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
  27. package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +24 -0
  28. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.i18n.yaml +4 -4
  29. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.md +2 -2
  30. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.zh.md +2 -2
  31. package/node_modules/@deepseek-ai/dsh-tool-fs-search/lib/index.js +28 -3
  32. package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +7 -2
  33. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.i18n.yaml +2 -2
  34. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.md +1 -1
  35. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.zh.md +1 -1
  36. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/lib/index.js +14 -6
  37. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +8 -8
  38. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +13 -7
  39. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +13 -7
  40. package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +20 -0
  41. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +2403 -2033
  42. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +1 -0
  43. package/node_modules/@deepseek-ai/libreoffice-kit/README.md +20 -5
  44. package/node_modules/@deepseek-ai/libreoffice-kit/README.zh.md +21 -6
  45. package/node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js +499 -253
  46. package/node_modules/@deepseek-ai/libreoffice-kit/lib/font-snapshot-worker.js +37 -26
  47. package/node_modules/@deepseek-ai/libreoffice-kit/lib/index.js +498 -252
  48. package/node_modules/@deepseek-ai/libreoffice-kit/lib/worker.js +39 -13
  49. package/node_modules/@deepseek-ai/libreoffice-kit/package.json +5 -3
  50. package/node_modules/@earendil-works/pi-ai/README.md +4 -3
  51. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +117 -18
  52. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  53. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +19 -8
  54. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +1 -0
  55. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -0
  56. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +1 -0
  57. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -0
  58. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +5 -0
  59. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +24 -2
  60. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  61. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  62. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  63. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  64. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  65. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  66. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  67. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  68. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  69. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  70. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  71. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -1
  72. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +3 -2
  73. package/node_modules/@earendil-works/pi-ai/package.json +6 -2
  74. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  75. package/node_modules/@shikijs/core/dist/index.mjs +15 -12
  76. package/node_modules/@shikijs/core/package.json +4 -4
  77. package/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs +2 -4
  78. package/node_modules/@shikijs/engine-javascript/dist/engine-raw.mjs +2 -4
  79. package/node_modules/@shikijs/engine-javascript/dist/index.mjs +1 -1
  80. package/node_modules/@shikijs/engine-javascript/dist/string-TLTPtCPs.mjs +115 -0
  81. package/node_modules/@shikijs/engine-javascript/package.json +3 -3
  82. package/node_modules/@shikijs/engine-oniguruma/package.json +3 -3
  83. package/node_modules/@shikijs/langs/dist/ada.mjs +1 -1
  84. package/node_modules/@shikijs/langs/dist/ahk.mjs +1 -1
  85. package/node_modules/@shikijs/langs/dist/beancount.mjs +1 -1
  86. package/node_modules/@shikijs/langs/dist/coq.mjs +1 -1
  87. package/node_modules/@shikijs/langs/dist/csharp.mjs +1 -1
  88. package/node_modules/@shikijs/langs/dist/css.mjs +1 -1
  89. package/node_modules/@shikijs/langs/dist/dart.mjs +1 -1
  90. package/node_modules/@shikijs/langs/dist/dotenv.mjs +1 -1
  91. package/node_modules/@shikijs/langs/dist/emacs-lisp.mjs +1 -1
  92. package/node_modules/@shikijs/langs/dist/gn.mjs +1 -1
  93. package/node_modules/@shikijs/langs/dist/handlebars.mjs +1 -1
  94. package/node_modules/@shikijs/langs/dist/julia.mjs +1 -1
  95. package/node_modules/@shikijs/langs/dist/latex.mjs +1 -1
  96. package/node_modules/@shikijs/langs/dist/luau.mjs +1 -1
  97. package/node_modules/@shikijs/langs/dist/marko.mjs +1 -1
  98. package/node_modules/@shikijs/langs/dist/moonbit.mjs +1 -1
  99. package/node_modules/@shikijs/langs/dist/nextflow-groovy.mjs +1 -1
  100. package/node_modules/@shikijs/langs/dist/nextflow.mjs +1 -1
  101. package/node_modules/@shikijs/langs/dist/nushell.mjs +1 -1
  102. package/node_modules/@shikijs/langs/dist/php.mjs +1 -1
  103. package/node_modules/@shikijs/langs/dist/powershell.mjs +1 -1
  104. package/node_modules/@shikijs/langs/dist/ruby.mjs +1 -1
  105. package/node_modules/@shikijs/langs/dist/rust.mjs +1 -1
  106. package/node_modules/@shikijs/langs/dist/sql.mjs +1 -1
  107. package/node_modules/@shikijs/langs/dist/svelte.mjs +1 -1
  108. package/node_modules/@shikijs/langs/dist/twig.mjs +3 -3
  109. package/node_modules/@shikijs/langs/dist/typespec.mjs +1 -1
  110. package/node_modules/@shikijs/langs/package.json +3 -3
  111. package/node_modules/@shikijs/primitive/dist/index.mjs +2 -1
  112. package/node_modules/@shikijs/primitive/package.json +3 -3
  113. package/node_modules/@shikijs/themes/dist/monokai.mjs +1 -1
  114. package/node_modules/@shikijs/themes/dist/one-dark-pro.mjs +1 -1
  115. package/node_modules/@shikijs/themes/dist/red.mjs +1 -1
  116. package/node_modules/@shikijs/themes/dist/solarized-dark.mjs +1 -1
  117. package/node_modules/@shikijs/themes/dist/solarized-light.mjs +1 -1
  118. package/node_modules/@shikijs/themes/package.json +3 -3
  119. package/node_modules/@shikijs/types/package.json +1 -1
  120. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +33 -11
  121. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
  122. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/exceptions.js +33 -11
  123. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +3 -0
  124. package/node_modules/@smithy/core/package.json +1 -1
  125. package/node_modules/node-addon-native-custom-loader/lib/index.js +23 -10
  126. package/node_modules/node-addon-native-custom-loader/package.json +6 -1
  127. package/node_modules/node-addon-require-builtin/package.json +7 -2
  128. package/node_modules/powershell-utils/index.js +40 -19
  129. package/node_modules/powershell-utils/package.json +1 -1
  130. package/node_modules/powershell-utils/readme.md +69 -13
  131. package/node_modules/shiki/package.json +10 -10
  132. package/node_modules/wsl-utils/index.js +18 -37
  133. package/node_modules/wsl-utils/package.json +2 -2
  134. package/package.json +33 -29
  135. package/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs +0 -77
  136. package/node_modules/open/node_modules/powershell-utils/index.js +0 -79
  137. package/node_modules/open/node_modules/powershell-utils/license +0 -9
  138. package/node_modules/open/node_modules/powershell-utils/package.json +0 -47
  139. package/node_modules/open/node_modules/powershell-utils/readme.md +0 -209
@@ -1,4 +1,5 @@
1
1
  export class ServiceException extends Error {
2
+ static shapeId = "smithy.ts.sdk.synthetic.nonamespace.client#ServiceException";
2
3
  $fault;
3
4
  $response;
4
5
  $retryable;
@@ -30,22 +31,43 @@ export class ServiceException extends Error {
30
31
  if (this.prototype.isPrototypeOf(instance)) {
31
32
  return true;
32
33
  }
33
- const targetName = this.name;
34
- if (!targetName || !candidate.name) {
35
- return false;
34
+ const targetId = Object.prototype.hasOwnProperty.call(this, "shapeId")
35
+ ? this.shapeId
36
+ : undefined;
37
+ let candidateHasShapeId = false;
38
+ if (targetId) {
39
+ let proto = Object.getPrototypeOf(candidate);
40
+ while (proto && proto !== Object.prototype) {
41
+ const ctor = proto.constructor;
42
+ const candidateId = ctor !== ServiceException && Object.prototype.hasOwnProperty.call(ctor, "shapeId")
43
+ ? ctor?.shapeId
44
+ : undefined;
45
+ if (candidateId) {
46
+ candidateHasShapeId = true;
47
+ if (candidateId === targetId) {
48
+ return true;
49
+ }
50
+ }
51
+ proto = Object.getPrototypeOf(proto);
52
+ }
36
53
  }
37
- if (candidate.name === targetName) {
38
- return true;
54
+ if (targetId && candidateHasShapeId) {
55
+ return false;
39
56
  }
40
- let proto = Object.getPrototypeOf(candidate);
41
- while (proto && proto !== Object.prototype) {
42
- const ctorName = proto.constructor?.name;
43
- if (ctorName && ctorName !== "Error" && ctorName === targetName) {
57
+ const targetName = this.name;
58
+ if (targetName && targetName.length >= 6) {
59
+ if (candidate.name === targetName) {
44
60
  return true;
45
61
  }
46
- proto = Object.getPrototypeOf(proto);
62
+ let proto = Object.getPrototypeOf(candidate);
63
+ while (proto && proto !== Object.prototype) {
64
+ const ctorName = proto.constructor?.name;
65
+ if (ctorName && ctorName !== "Error" && ctorName === targetName) {
66
+ return true;
67
+ }
68
+ proto = Object.getPrototypeOf(proto);
69
+ }
47
70
  }
48
- return false;
49
71
  }
50
72
  return false;
51
73
  }
@@ -58,6 +58,9 @@ export class TypeRegistry {
58
58
  const $error = es;
59
59
  const ns = $error[1];
60
60
  const qualifiedName = ns + "#" + $error[2];
61
+ if (!ctor.hasOwnProperty?.("shapeId")) {
62
+ ctor.shapeId = qualifiedName;
63
+ }
61
64
  for (const r of [this, TypeRegistry.for(ns)]) {
62
65
  if (!r.schemas.has(qualifiedName) && !r.exceptions.has($error)) {
63
66
  r.schemas.set(qualifiedName, $error);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.35.0",
3
+ "version": "3.35.1",
4
4
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/core",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -348,7 +348,15 @@ function prebuildCandidateBinaries(prebuilds, backendPreference) {
348
348
  }
349
349
  return [nodeAbiBinary, napiBinary].filter((binary) => Boolean(binary));
350
350
  }
351
- function validateLoadedBinding(binding, bindingPath) {
351
+ function productForPackage(packageName) {
352
+ for (const product of ['require-builtin', 'internal-loader']) {
353
+ const prefix = `node-addon-${product}`;
354
+ if (packageName === prefix || packageName.startsWith(`${prefix}-`))
355
+ return product;
356
+ }
357
+ throw new Error(`unknown native product package: ${packageName}`);
358
+ }
359
+ function validateLoadedBinding(binding, bindingPath, product) {
352
360
  if (!binding) {
353
361
  throw new Error(`native binding did not export an object: ${bindingPath}`);
354
362
  }
@@ -366,10 +374,14 @@ function validateLoadedBinding(binding, bindingPath) {
366
374
  throw new Error(`native binding info is not an object: ${bindingPath}`);
367
375
  }
368
376
  if (typeof info.mode !== 'string' ||
377
+ typeof info.product !== 'string' ||
369
378
  typeof info.backend !== 'string' ||
370
379
  typeof info.abi !== 'string') {
371
380
  throw new Error(`native binding info has invalid fields: ${bindingPath}`);
372
381
  }
382
+ if (info.product !== product) {
383
+ throw new Error(`native binding product mismatch for ${bindingPath}: expected ${product}, got ${info.product}`);
384
+ }
373
385
  const backend = info.backend;
374
386
  if (backend !== BACKEND_NAPI && backend !== BACKEND_NODEABI) {
375
387
  throw new Error(`native binding has unsupported backend ${backend}: ${bindingPath}`);
@@ -385,8 +397,8 @@ function validateLoadedBinding(binding, bindingPath) {
385
397
  });
386
398
  return binding;
387
399
  }
388
- function validatePrebuiltBinding(binding, binary, bindingPath) {
389
- validateLoadedBinding(binding, bindingPath);
400
+ function validatePrebuiltBinding(binding, binary, bindingPath, product) {
401
+ validateLoadedBinding(binding, bindingPath, product);
390
402
  const info = binding.nativeBindingInfo;
391
403
  if (!info || info.backend !== binary.backend || info.abi !== binary.abi) {
392
404
  const actualBackend = info && info.backend;
@@ -421,7 +433,7 @@ function loadPrebuild(packageDir, options = {}) {
421
433
  let loadPath = bindingPath;
422
434
  try {
423
435
  loadPath = materializedNativeBinaryPath(bindingPath, packageName);
424
- return validatePrebuiltBinding(require(loadPath), binary, loadPath);
436
+ return validatePrebuiltBinding(require(loadPath), binary, loadPath, productForPackage(packageName));
425
437
  }
426
438
  catch (error) {
427
439
  attempts.push({
@@ -437,23 +449,23 @@ function loadPrebuild(packageDir, options = {}) {
437
449
  error.attempts = attempts;
438
450
  throw error;
439
451
  }
440
- function tryRequirePackage(candidate) {
452
+ function tryRequirePackage(candidate, product) {
441
453
  try {
442
454
  const binding = require(candidate.request);
443
455
  const bindingPath = binding.bindingPath || require.resolve(candidate.request);
444
- validateLoadedBinding(binding, bindingPath);
456
+ validateLoadedBinding(binding, bindingPath, product);
445
457
  return { binding, path: bindingPath, error: null };
446
458
  }
447
459
  catch (error) {
448
460
  return { binding: null, path: null, error };
449
461
  }
450
462
  }
451
- function tryRequireLocal(packageDir, binary) {
463
+ function tryRequireLocal(packageDir, binary, product) {
452
464
  const file = node_path_1.default.join(packageDir, 'build', binary.backend, `${binary.abi}-${platformPackageSuffix()}`, BINARY_NAME);
453
465
  try {
454
466
  const loadPath = materializedNativeBinaryPath(file, 'node-addon-native-custom-loader-local');
455
467
  const binding = require(loadPath);
456
- validateLoadedBinding(binding, loadPath);
468
+ validateLoadedBinding(binding, loadPath, product);
457
469
  Object.defineProperty(binding, 'bindingPath', {
458
470
  value: loadPath,
459
471
  enumerable: false,
@@ -496,11 +508,12 @@ function optionalPackageCandidates(packageDir, packagePrefix) {
496
508
  function loadEntry(options) {
497
509
  const packageDir = options.packageDir;
498
510
  const packagePrefix = options.packagePrefix;
511
+ const product = productForPackage(packagePrefix);
499
512
  const backendPreference = normalizeBackend(options.backend || process.env.NARB_BACKEND);
500
513
  const attempts = [];
501
514
  if (process.env.NARB_DISABLE_OPTIONAL_PACKAGE !== '1') {
502
515
  for (const candidate of optionalPackageCandidates(packageDir, packagePrefix)) {
503
- const result = tryRequirePackage(candidate);
516
+ const result = tryRequirePackage(candidate, product);
504
517
  if (result.binding && result.path) {
505
518
  return {
506
519
  binding: result.binding,
@@ -520,7 +533,7 @@ function loadEntry(options) {
520
533
  throw noUsableBindingError(packagePrefix, backendPreference, attempts);
521
534
  }
522
535
  for (const binary of entryCandidateBinaries(backendPreference)) {
523
- const result = tryRequireLocal(packageDir, binary);
536
+ const result = tryRequireLocal(packageDir, binary, product);
524
537
  if (result.binding) {
525
538
  return {
526
539
  binding: result.binding,
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "node-addon-native-custom-loader",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/deepseek-ai/dsh-node-addon-require-builtin.git",
7
+ "directory": "packages/loader"
8
+ },
4
9
  "type": "commonjs",
5
10
  "description": "Shared native binary loader for the node-addon-require-builtin and node-addon-internal-loader package families.",
6
11
  "main": "lib/index.js",
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "node-addon-require-builtin",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/deepseek-ai/dsh-node-addon-require-builtin.git",
7
+ "directory": "packages/require-builtin/entry"
8
+ },
4
9
  "type": "commonjs",
5
10
  "description": "Node-API addon with runtime probing for internal access (unrestricted require-builtin variant).",
6
11
  "main": "lib/index.js",
@@ -26,6 +31,6 @@
26
31
  },
27
32
  "license": "MIT",
28
33
  "dependencies": {
29
- "node-addon-native-custom-loader": "0.1.6"
34
+ "node-addon-native-custom-loader": "0.1.7"
30
35
  }
31
36
  }
@@ -24,35 +24,56 @@ export const canAccessPowerShell = async () => {
24
24
  return canAccessCache;
25
25
  };
26
26
 
27
+ const argumentsPrefix = [
28
+ '-NoProfile',
29
+ '-NonInteractive',
30
+ '-ExecutionPolicy',
31
+ 'Bypass',
32
+ '-EncodedCommand',
33
+ ];
34
+
35
+ const encodeCommand = command => Buffer.from(command, 'utf16le').toString('base64');
36
+
37
+ /*
38
+ PowerShell's tokenizer treats the typographic single quotes U+2018, U+2019, U+201A, and U+201B as string delimiters, exactly like the ASCII one, and it does not require the closing quote to match the opening quote. Escaping only the ASCII quote would let any of the others terminate the string and inject a statement. Doubling works for all of them.
39
+ */
40
+ const escapeArgument = value => `'${String(value).replaceAll(/['‘’‚‛]/g, match => match + match)}'`;
41
+
42
+ const createArguments = command => [...argumentsPrefix, encodeCommand(command)];
43
+
44
+ const createExecFileOptions = options => ({
45
+ encoding: 'utf8',
46
+ ...options,
47
+ shell: false,
48
+ });
49
+
27
50
  export const executePowerShell = async (command, options = {}) => {
28
51
  const {
29
52
  powerShellPath: psPath,
30
53
  ...execFileOptions
31
54
  } = options;
32
55
 
33
- const encodedCommand = executePowerShell.encodeCommand(command);
34
-
35
56
  return execFile(
36
57
  psPath ?? powerShellPath(),
37
- [
38
- ...executePowerShell.argumentsPrefix,
39
- encodedCommand,
40
- ],
41
- {
42
- encoding: 'utf8',
43
- ...execFileOptions,
44
- },
58
+ createArguments(command),
59
+ createExecFileOptions(execFileOptions),
45
60
  );
46
61
  };
47
62
 
48
- executePowerShell.argumentsPrefix = [
49
- '-NoProfile',
50
- '-NonInteractive',
51
- '-ExecutionPolicy',
52
- 'Bypass',
53
- '-EncodedCommand',
54
- ];
63
+ executePowerShell.argumentsPrefix = argumentsPrefix;
64
+ executePowerShell.encodeCommand = encodeCommand;
65
+ executePowerShell.escapeArgument = escapeArgument;
66
+ executePowerShell.createArguments = createArguments;
55
67
 
56
- executePowerShell.encodeCommand = command => Buffer.from(command, 'utf16le').toString('base64');
68
+ export const executePowerShellSync = (command, options = {}) => {
69
+ const {
70
+ powerShellPath: psPath,
71
+ ...execFileOptions
72
+ } = options;
57
73
 
58
- executePowerShell.escapeArgument = value => `'${String(value).replaceAll('\'', '\'\'')}'`;
74
+ return childProcess.execFileSync(
75
+ psPath ?? powerShellPath(),
76
+ createArguments(command),
77
+ createExecFileOptions(execFileOptions),
78
+ );
79
+ };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powershell-utils",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Utilities for executing PowerShell commands",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/powershell-utils",
@@ -13,11 +13,9 @@ npm install powershell-utils
13
13
  ```js
14
14
  import {executePowerShell, powerShellPath} from 'powershell-utils';
15
15
 
16
- // Execute a PowerShell command
17
16
  const {stdout} = await executePowerShell('Get-Process');
18
17
  console.log(stdout);
19
18
 
20
- // Get PowerShell path
21
19
  console.log(powerShellPath());
22
20
  //=> 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
23
21
  ```
@@ -64,7 +62,6 @@ Execute a PowerShell command.
64
62
  ```js
65
63
  import {executePowerShell} from 'powershell-utils';
66
64
 
67
- // Execute a PowerShell command
68
65
  const {stdout} = await executePowerShell('Get-Process');
69
66
  console.log(stdout);
70
67
  ```
@@ -79,7 +76,7 @@ The PowerShell command to execute.
79
76
 
80
77
  Type: `object`
81
78
 
82
- The below option and also all options in Node.js [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) are supported.
79
+ The below option and all options except `shell` in Node.js [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) are supported. PowerShell is always executed directly to prevent shell injection.
83
80
 
84
81
  ##### powerShellPath
85
82
 
@@ -99,16 +96,9 @@ Character encoding for stdout and stderr.
99
96
 
100
97
  Type: `string[]`
101
98
 
102
- Standard PowerShell arguments that prefix the encoded command.
99
+ Standard PowerShell arguments that prefix the encoded command: `['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand']`
103
100
 
104
- Use these when manually building PowerShell execution arguments for `spawn()`, `execFile()`, etc.
105
-
106
- ```js
107
- import {executePowerShell} from 'powershell-utils';
108
-
109
- const arguments_ = [...executePowerShell.argumentsPrefix, encodedCommand];
110
- childProcess.spawn(powerShellPath(), arguments_);
111
- ```
101
+ Exposed for debugging or for advanced use cases where you need to customize the arguments. For most cases, use `createArguments()` instead.
112
102
 
113
103
  ### executePowerShell.encodeCommand(command)
114
104
 
@@ -136,6 +126,11 @@ Returns: `string`
136
126
 
137
127
  Escape a string argument for use in PowerShell single-quoted strings.
138
128
 
129
+ > [!IMPORTANT]
130
+ > This makes a value safe as a PowerShell string literal, not as an argument to a native program. PowerShell removes the outer quotes before passing a value onwards, and the receiving process then re-splits it under its own command-line rules, where spaces and double quotes are delimiters. For example, `Start-Process -ArgumentList` receives `'a b'` as two arguments rather than one.
131
+ >
132
+ > Escaping also does not make an untrusted value safe to use as the program that `Start-Process` runs. Validate such values against an allowlist.
133
+
139
134
  #### value
140
135
 
141
136
  Type: `unknown`
@@ -151,3 +146,64 @@ const escaped = executePowerShell.escapeArgument("it's a test");
151
146
  // Use in command building
152
147
  const command = `Start-Process ${executePowerShell.escapeArgument(appName)}`;
153
148
  ```
149
+
150
+ ### executePowerShell.createArguments(command)
151
+
152
+ Returns: `string[]`
153
+
154
+ Create the full arguments array for PowerShell execution.
155
+
156
+ Combines `argumentsPrefix` with the encoded command. Useful when using `spawn()`, `execFile()`, or other process execution methods.
157
+
158
+ #### command
159
+
160
+ Type: `string`
161
+
162
+ The PowerShell command.
163
+
164
+ ```js
165
+ import {spawn} from 'node:child_process';
166
+ import {powerShellPath, executePowerShell} from 'powershell-utils';
167
+
168
+ const args = executePowerShell.createArguments('Get-Process');
169
+ spawn(powerShellPath(), args);
170
+ ```
171
+
172
+ ### executePowerShellSync(command, options?)
173
+
174
+ Returns: `string`
175
+
176
+ Execute a PowerShell command synchronously.
177
+
178
+ ```js
179
+ import {executePowerShellSync} from 'powershell-utils';
180
+
181
+ const stdout = executePowerShellSync('Get-Process');
182
+ console.log(stdout);
183
+ ```
184
+
185
+ #### command
186
+
187
+ Type: `string`
188
+
189
+ The PowerShell command to execute.
190
+
191
+ #### options
192
+
193
+ Type: `object`
194
+
195
+ The below option and all options except `shell` in Node.js [`child_process.execFileSync()`](https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options) are supported. PowerShell is always executed directly to prevent shell injection.
196
+
197
+ ##### powerShellPath
198
+
199
+ Type: `string`\
200
+ Default: `powerShellPath()`
201
+
202
+ Path to PowerShell executable.
203
+
204
+ ##### encoding
205
+
206
+ Type: `string`\
207
+ Default: `'utf8'`
208
+
209
+ Character encoding for the output.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shiki",
3
3
  "type": "module",
4
- "version": "4.4.3",
4
+ "version": "4.5.0",
5
5
  "description": "A beautiful Syntax Highlighter.",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -49,19 +49,19 @@
49
49
  "node": ">=20"
50
50
  },
51
51
  "dependencies": {
52
+ "@shikijs/core": "4.5.0",
53
+ "@shikijs/engine-javascript": "4.5.0",
54
+ "@shikijs/engine-oniguruma": "4.5.0",
55
+ "@shikijs/langs": "4.5.0",
56
+ "@shikijs/themes": "4.5.0",
57
+ "@shikijs/types": "4.5.0",
52
58
  "@shikijs/vscode-textmate": "^10.0.2",
53
- "@types/hast": "^3.0.5",
54
- "@shikijs/core": "4.4.3",
55
- "@shikijs/engine-javascript": "4.4.3",
56
- "@shikijs/engine-oniguruma": "4.4.3",
57
- "@shikijs/langs": "4.4.3",
58
- "@shikijs/themes": "4.4.3",
59
- "@shikijs/types": "4.4.3"
59
+ "@types/hast": "^3.0.5"
60
60
  },
61
61
  "devDependencies": {
62
62
  "rollup-plugin-copy": "^3.5.0",
63
- "tm-grammars": "^1.32.3",
64
- "tm-themes": "^1.12.3",
63
+ "tm-grammars": "^1.32.22",
64
+ "tm-themes": "^1.12.12",
65
65
  "vscode-oniguruma": "1.7.0"
66
66
  }
67
67
  }
@@ -87,37 +87,25 @@ export const wslDefaultBrowser = async () => {
87
87
 
88
88
  const isUrl = path => /^[a-z]+:\/\//i.test(path);
89
89
 
90
- export const convertWslPathToWindows = async paths => {
91
- const isBatch = Array.isArray(paths);
92
- const pathArray = isBatch ? paths : [paths];
93
-
94
- // Find indices of non-URL paths that need conversion
95
- const indicesToConvert = [];
96
- const pathsToConvert = [];
97
-
98
- for (const [index, path] of pathArray.entries()) {
99
- if (!isUrl(path)) {
100
- indicesToConvert.push(index);
101
- pathsToConvert.push(path);
102
- }
103
- }
104
-
105
- // Start with original paths (URLs stay as-is)
106
- const results = [...pathArray];
107
-
108
- if (pathsToConvert.length > 0) {
109
- try {
110
- const {stdout} = await execFile('wslpath', ['-aw', ...pathsToConvert], {encoding: 'utf8'});
111
- const convertedPaths = stdout.split(/\r?\n/).filter(Boolean);
90
+ // `wslpath` only accepts a single path, so each path needs its own call.
91
+ const convertPath = async (flag, path) => {
92
+ // `--` stops `wslpath` from reading a leading `-` as an option. Only pass it when needed, as it is only confirmed for WSL 2.5 and later.
93
+ const wslpathArguments = path.startsWith('-') ? [flag, '--', path] : [flag, path];
112
94
 
113
- for (const [index, originalIndex] of indicesToConvert.entries()) {
114
- results[originalIndex] = convertedPaths[index] ?? pathArray[originalIndex];
115
- }
116
- } catch {
117
- // If wslpath fails, keep original paths
118
- }
95
+ try {
96
+ const {stdout} = await execFile('wslpath', wslpathArguments, {encoding: 'utf8'});
97
+ return stdout.replace(/\r?\n$/, '') || path;
98
+ } catch {
99
+ // If wslpath fails, keep original path
100
+ return path;
119
101
  }
102
+ };
120
103
 
104
+ export const convertWslPathToWindows = async paths => {
105
+ const isBatch = Array.isArray(paths);
106
+ const pathArray = isBatch ? paths : [paths];
107
+ // URLs stay as-is
108
+ const results = await Promise.all(pathArray.map(path => isUrl(path) ? path : convertPath('-aw', path)));
121
109
  return isBatch ? results : results[0];
122
110
  };
123
111
 
@@ -131,15 +119,8 @@ export const isPathOnWindowsFilesystem = async path => {
131
119
  export const convertWindowsPathToWsl = async paths => {
132
120
  const isBatch = Array.isArray(paths);
133
121
  const pathArray = isBatch ? paths : [paths];
134
-
135
- try {
136
- const {stdout} = await execFile('wslpath', ['-u', ...pathArray], {encoding: 'utf8'});
137
- const convertedPaths = stdout.split(/\r?\n/).filter(Boolean);
138
- const results = pathArray.map((original, index) => convertedPaths[index] ?? original);
139
- return isBatch ? results : results[0];
140
- } catch {
141
- return isBatch ? pathArray : pathArray[0];
142
- }
122
+ const results = await Promise.all(pathArray.map(path => convertPath('-u', path)));
123
+ return isBatch ? results : results[0];
143
124
  };
144
125
 
145
126
  export {default as isWsl} from 'is-wsl';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wsl-utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Utilities for working with Windows Subsystem for Linux (WSL)",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/wsl-utils",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "is-wsl": "^3.1.0",
38
- "powershell-utils": "^0.1.0"
38
+ "powershell-utils": "^0.2.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "ava": "^6.4.1",