Skip to content

Commit

Permalink
chore(repo): add unparse back as other package deep import it
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jun 10, 2022
1 parent 1e90413 commit 3b3888a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/nx/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,45 @@ function longRunningTask(task: Task) {
!!task.overrides['watch'] || t === 'serve' || t === 'dev' || t === 'start'
);
}

// TODO: vsavkin remove when nx-cloud doesn't depend on it
export function unparse(options: Object): string[] {
const unparsed = [];
for (const key of Object.keys(options)) {
const value = options[key];
unparseOption(key, value, unparsed);
}

return unparsed;
}

function unparseOption(key: string, value: any, unparsed: string[]) {
if (value === true) {
unparsed.push(`--${key}`);
} else if (value === false) {
unparsed.push(`--no-${key}`);
} else if (Array.isArray(value)) {
value.forEach((item) => unparseOption(key, item, unparsed));
} else if (Object.prototype.toString.call(value) === '[object Object]') {
const flattened = flatten<any, any>(value, { safe: true });
for (const flattenedKey in flattened) {
unparseOption(
`${key}.${flattenedKey}`,
flattened[flattenedKey],
unparsed
);
}
} else if (
typeof value === 'string' &&
stringShouldBeWrappedIntoQuotes(value)
) {
const sanitized = value.replace(/"/g, String.raw`\"`);
unparsed.push(`--${key}="${sanitized}"`);
} else if (value != null) {
unparsed.push(`--${key}=${value}`);
}
}

function stringShouldBeWrappedIntoQuotes(str: string) {
return str.includes(' ') || str.includes('{') || str.includes('"');
}

1 comment on commit 3b3888a

@vercel
Copy link

@vercel vercel bot commented on 3b3888a Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.