Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,25 @@ describe('expandPackageList', () => {
`${process.cwd()}/sandbox/${projectName}/packages/package_b`,
]);
});

it('ignores packages with "!" prefix in package directory', () => {
silentExec('./tests/bootstrap-examples/simple-monorepo.sh');

expect(
expandPackageList(
['.', 'packages/*', '!packages/package_a'],
'sandbox/simple-monorepo'
)
).toEqual([
`${process.cwd()}/sandbox/simple-monorepo`,
`${process.cwd()}/sandbox/simple-monorepo/packages/package_b`,
]);

expect(
expandPackageList(
['.', 'packages/*', '!packages/package_a', '!packages/package_b'],
'sandbox/simple-monorepo'
)
).toEqual([`${process.cwd()}/sandbox/simple-monorepo`]);
});
});
12 changes: 10 additions & 2 deletions packages/shipjs-lib/src/lib/util/expandPackageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
const flatten = (arr) => arr.reduce((acc, item) => acc.concat(item), []);

export default function expandPackageList(list, dir = '.') {
return flatten(
list.map((item) => {
const exclusions = list
.filter((item) => item.startsWith('!'))
.map((item) => resolve(dir, item.slice(1)));

Check failure on line 15 in packages/shipjs-lib/src/lib/util/expandPackageList.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/shipjs-lib/src/lib/util/expandPackageList.js#L15

Detected possible user input going into a `path.join` or `path.resolve` function.

const inclusions = list.filter((item) => !item.startsWith('!'));

const expandedInclusions = flatten(
inclusions.map((item) => {
const partIndex = item
.split(sep)
.findIndex((part) => part.startsWith('@(') && part.endsWith(')'));
Expand All @@ -37,4 +43,6 @@
}
})
).filter(hasPackageJson);

return expandedInclusions.filter((pkg) => !exclusions.includes(pkg));
}
12 changes: 10 additions & 2 deletions website/guide/useful-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ Ship.js currently supports monorepo project(Independent versioning is not suppor
module.exports = {
monorepo: {
mainVersionFile: 'package.json', // or `lerna.json`, or whatever a json file you can read the latest `version` from.
packagesToBump: ['packages/*', 'examples/*'],
packagesToPublish: ['packages/*'],
packagesToBump: ['packages/*', 'examples/*', '!example/a'],
packagesToPublish: ['packages/*', '!examples/a'],
},
};
```

Patterns supported in `packagesToBump` / `packagesToPublish`:
- Plain paths (e.g. `.` or `packages/package_a`)
- Trailing `/*` to include immediate subdirectories (e.g. `packages/*`)
- `@(a|b)` style alternation (e.g. `packages/@(package_a|package_b)`)
- Start with `!` to skip a path: `!packages/package_a`

Ship.js only lists folders that have a `package.json`. Any paths that start with `!` are removed after the patterns are handled.

With the config above, `prepare` command will

1. Read the current version from `package.json` file at the project root directory.
Expand Down