Skip to content

Commit d8150d7

Browse files
committed
Another variant of dependencies management / installation procedure
1 parent f2aac8e commit d8150d7

File tree

4 files changed

+3097
-1076
lines changed

4 files changed

+3097
-1076
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ Install this package as
99
$ npm install --save topcoder-react-utils
1010
```
1111

12-
You are done if you will use only components and utilities provided by this
13-
package. If you are to use configurations, to build or test your code, you must
14-
also install the peer dependencies:
12+
You are done if you only use components and utilities provided by this
13+
package. If you are to use configurations to build or test your code, you
14+
also need to install all development dependencies into your own package:
1515
```
16-
$ npm install -g install-peerdeps
17-
$ install-peerdeps -od topcoder-react-utils
16+
$ adopt-dev-deps topcoder-react-utils
1817
```
1918

20-
Peer dependencies will be also stored as dev dependencies into `package.json` of
21-
your project, thus future invokations of `npm install` will automatically
22-
install them, and you won't need to use `install-peerdeps` as long as you don't
23-
update `topcoder-react-utils` version.
19+
Installed dev dependencies will be stored into your `package.json`, thus
20+
further invokations of `npm install` will automatically install them. You
21+
only need to call `adopt-dev-deps` again if you update
22+
`topcoder-react-utils` to a newer version.
2423

2524
### Configurations
2625
- [**Babel Configurations**](docs/babel-config.md) — Standard configurations

bin/adopt-dev-deps

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
/* Installs dev dependencies of this, or the specified package into another
4+
* package. */
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
const { spawnSync } = require('child_process');
9+
10+
/* Locates and loads the "package.json" file of the donor package, from which we
11+
* want to adopt dev dependencies. */
12+
const src = process.argv[2] || '..';
13+
14+
let url = path.dirname(require.resolve(src));
15+
for (;;) {
16+
const files = fs.readdirSync(url);
17+
if (files.includes('package.json')) {
18+
url = path.resolve(url, 'package.json');
19+
break;
20+
}
21+
const up = path.resolve(url, '..');
22+
if (url === up) throw new Error(`Cannot find the package ${src}`);
23+
url = up;
24+
}
25+
26+
const packageInfo = JSON.parse(fs.readFileSync(url));
27+
28+
/* Gets the list of dev dependencies from the packageInfo. */
29+
let deps = Object.entries(packageInfo.devDependencies || {});
30+
deps = deps.map(x => `${x[0]}@${x[1]}`);
31+
32+
/* And installs them as dev deps into the current working directory. */
33+
spawnSync('npm', ['install', '--save-dev'].concat(deps), {
34+
stdio: 'inherit',
35+
});

0 commit comments

Comments
 (0)