Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support multiple commands in the same line #118

Merged
merged 5 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/content/registry/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,20 @@ describe('npm', () => {

expect(packagePosition).toStrictEqual(expectedPackages);
});

it('should break into commands', () => {
// https://stackoverflow.com/a/65043610/839513
baruchiro marked this conversation as resolved.
Show resolved Hide resolved
const {
command,
positions,
} = cli`npm uninstall -g create-react-app && npm i -g ${'npm@latest'} && npm cache clean -f && npx ${'create-react-app@latest'} my-app --use-npm`;
const expectedPackages = positions.map(({ index, value }) =>
packageResult({ name: value.split('@')[0], startIndex: index, endIndex: index + value.length })
);

const packagePosition = parseCommand(command);

expect(packagePosition).toStrictEqual(expectedPackages);
});
});
});
15 changes: 15 additions & 0 deletions src/content/registry/python.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ describe(parseCommand.name, () => {

expect(packagePosition).toStrictEqual(expectedPackages);
});

it('should break into commands', () => {
// https://stackoverflow.com/a/65043610/839513
const {
command,
positions,
} = cli`pip uninstall -y requests-temp && pip install ${'scipy'} && pip check --no-color && pip hash -V && pip install ${'numpy'}`;
const expectedPackages = positions.map(({ index, value }) =>
packageResult({ name: value.split('@')[0], startIndex: index, endIndex: index + value.length })
);

const packagePosition = parseCommand(command);

expect(packagePosition).toStrictEqual(expectedPackages);
});
});
3 changes: 2 additions & 1 deletion src/content/registry/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const createParseCommand =
const packages = [];
let counterIndex = 0;

const lines = command.split('\n');
const lines = command.split(/\n|\s*&&\s*/);

while (lines.length > 0) {
const line = lines.shift();

Expand Down
295 changes: 295 additions & 0 deletions tests/real-examples/real-examples-results.yaml

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

4 changes: 4 additions & 0 deletions tests/real-examples/real-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ links:
comment: with semver ~
post: answer
registry: npm
https://stackoverflow.com/a/65043610/839513:
comment: multiple commands in the same line
post: answer
registry: npm

https://stackoverflow.com/questions/2817869:
comment: high scored
Expand Down
Loading