@oclif/test 4.0.1 → 4.0.3

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 (2) hide show
  1. package/lib/index.js +16 -1
  2. package/package.json +5 -5
package/lib/index.js CHANGED
@@ -27,6 +27,21 @@ function findRoot() {
27
27
  function makeLoadOptions(loadOpts) {
28
28
  return loadOpts ?? { root: findRoot() };
29
29
  }
30
+ /**
31
+ * Split a string into an array of strings, preserving quoted substrings
32
+ *
33
+ * @example
34
+ * splitString('foo bar --name "foo"') // ['foo bar', '--name', 'foo']
35
+ * splitString('foo bar --name "foo bar"') // ['foo bar', '--name', 'foo bar']
36
+ * splitString('foo bar --name="foo bar"') // ['foo bar', '--name=foo bar']
37
+ * splitString('foo bar --name=foo bar') // ['foo bar', '--name=foo', 'bar']
38
+ *
39
+ * @param str input string
40
+ * @returns array of strings with quotes removed
41
+ */
42
+ function splitString(str) {
43
+ return (str.match(/(?:[^\s"]+|"[^"]*")+/g) ?? []).map((s) => s.replaceAll(/^"|"$|(?<==)"/g, ''));
44
+ }
30
45
  /**
31
46
  * Capture the stderr and stdout output of a function
32
47
  * @param fn async function to run
@@ -108,7 +123,7 @@ exports.captureOutput = captureOutput;
108
123
  */
109
124
  async function runCommand(args, loadOpts, captureOpts) {
110
125
  const loadOptions = makeLoadOptions(loadOpts);
111
- const argsArray = (Array.isArray(args) ? args : [args]).join(' ').split(' ');
126
+ const argsArray = splitString((Array.isArray(args) ? args : [args]).join(' '));
112
127
  const [id, ...rest] = argsArray;
113
128
  const finalArgs = id === '.' ? rest : argsArray;
114
129
  debug('loadOpts: %O', loadOptions);
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@oclif/test",
3
3
  "description": "test helpers for oclif components",
4
- "version": "4.0.1",
4
+ "version": "4.0.3",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/test/issues",
7
7
  "dependencies": {
8
8
  "ansis": "^3.2.0",
9
- "debug": "^4.3.4"
9
+ "debug": "^4.3.5"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "@oclif/core": ">= 3.0.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@commitlint/config-conventional": "^18.6.3",
16
- "@oclif/core": "^4.0.0-beta.6",
16
+ "@oclif/core": "^4.0.0-beta.13",
17
17
  "@oclif/prettier-config": "^0.2.1",
18
18
  "@types/chai": "^4.3.16",
19
19
  "@types/debug": "^4.1.12",
@@ -26,11 +26,11 @@
26
26
  "eslint-config-oclif-typescript": "^3.1.7",
27
27
  "eslint-config-prettier": "^9.1.0",
28
28
  "husky": "^9.0.3",
29
- "lint-staged": "^15.2.2",
29
+ "lint-staged": "^15.2.5",
30
30
  "mocha": "^10",
31
31
  "prettier": "^3.2.5",
32
32
  "shx": "^0.3.3",
33
- "tsx": "^4.10.2",
33
+ "tsx": "^4.11.0",
34
34
  "typescript": "^5.4.5"
35
35
  },
36
36
  "engines": {