Skip to content

Commit

Permalink
Merge pull request #1 from rollup-umd/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kopax authored Mar 4, 2019
2 parents 1ad763f + 6e64f6d commit 6e17b88
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 53 deletions.
21 changes: 21 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Create at the root of your project `.ncurc.js`:

```js static
const { createConfig } = require('$PACKAGE_NAME');
module.exports = createConfig();
```

Add to `.npmignore`:

```diff
+ .ncurc.js
```

Run the upgrade within a project:

```bash
# test
$ npx ncu
# write change
$ npx ncu -a
```
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```bash
$ npm install @yeutech/rollup-umd --save
$ npm install @yeutech/rollup-umd --save-dev
```
72 changes: 57 additions & 15 deletions docs/js/jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ Create npm check updates configuration

Read [https://www.npmjs.com/package/npm-check-updates][1] if you don't know what it is.

Usually, you run updates as follow
Usually, you run updates as follow:

For testing:

```bash
$ npx ncu
```

Writing to `package.json`:

```bash
$ npx npm-check-updates -a
// or install globally
$ npm install -g npm-check-updates
// then run it from global
$ ncu -a
$ npx ncu -a
```

By default, it will try to read it's configuration from `.ncurc.js`, this is where we hook this configuration:
Expand All @@ -25,20 +29,60 @@ module.exports = createConfig();

This configuration will allow you to use:

- **local extension**: Use a new file within a rollup-umd project that will be used to inject ncu configuration per project/
- **dependency extension**: Use a dependency extension within a rollup-umd project to manage ncu configuration across a set of projects.
- **Local extension**: In your `package.json` we read `ncurc` within a rollup-umd project to inject ncu configuration per project
- **Dependency extension**: Use a dependency extension within a rollup-umd project to manage ncu configuration across a set of projects.

## Local extension

Simply add `npmrc` in your `package.json`:

```diff
+ "ncurc": {
+ "reject": [
+ "react-styleguidist"
+ ]
+ }
```

This will for example add `react-styleguidist` to the ignored package when doing `npx ncu -a` in your project.

## Dependency extension

This is a dependency listed in your `package.json`.

To create a dependency extension, all you need is to publish a npm package with:
To create a dependency extension, all you need is to publish a npm package with the following requirements:

- The ncu configuration as default exports, it will be merge with ours.
- Set in the `name` and add in `keywords` of your dependency the string: `ncu`.
- A `ncurc` key containing the configuration in the `package.json` (as the previous example)

**Or** if it only serve a ncu configuration:

- The ncu configuration as default exports **AND** `ncu` in your package name, it will be merge with ours.

```js static
export default {
reject: ['react-styleguidist'],
};
```

These a required **keywords** that **MUST** be set in your `package.json` in order to be detected by the auto configuration:

- The `keywords` of your dependency must have: `ncu`.
- The `keywords` of your dependency must have this package name: `$PACKAGE_NAME`

```diff
"keywords": [
+ "ncu",
+ "$PACKAGE_NAME",
],
```

Dependency extension will be read by `createConfig` and logging will appear for each detection.

### Parameters

- `config` **[object][2]** configuration (optional, default `{}`)
- `config` **[object][2]** local ncu configuration, if you want something (optional, default `{}`)
- `options` **[object][2]** options of create config (optional, default `{}`)
- `options.disableAutoConfig` **[boolean][3]** Disable auto configuration from extensions modules (optional, default `false`)
- `options.extensionFile` **[string][4]** Location of the local extension file (optional, default `.ncurrc.ext.json`)

Returns **[object][2]** npm check updates configuration object

Expand All @@ -47,5 +91,3 @@ Returns **[object][2]** npm check updates configuration object
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup-umd/ncu",
"version": "1.0.1",
"version": "0.0.0-development",
"description": "npm-check-updates rollup-umd preconfiguration",
"main": "lib/index.js",
"jsnext:main": "dist/@rollup-umd/ncu.esm.js",
Expand Down
119 changes: 83 additions & 36 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@ function autoconfig(opts, pkg, thisPkg, base) {
const autoconf = { reject: [] };
if (!opts.disableAutoConf) {
// get them dynamically, it must include documentation in the name, and be in devDependencies or dependencies
const found = false;
[pkg.dependencies || {}, pkg.devDependencies || {}].forEach((o) => {
Object.keys(o).forEach((dep) => {
if (dep.includes('ncu') && !dep.includes(thisPkg.name)) {
const { keywords } = require(join(base, 'node_modules', dep, 'package.json')); // eslint-disable-line
if (keywords && keywords.indexOf(thisPkg.name) !== -1) {
if (!dep.includes(thisPkg.name)) {
const { keywords, ncurc } = require(join(base, 'node_modules', dep, 'package.json')); // eslint-disable-line
let ncu = ncurc;
if (!ncu && dep.includes('ncu') && keywords && keywords.indexOf(thisPkg.name) !== -1) {
if (existsSync(join(base, 'node_modules', dep))) {
try {
const { reject: autoconfReject, autoconfRest } = require(join(base, 'node_modules', dep)); // eslint-disable-line global-require
autoconf.reject = [...new Set(
...(autoconf.reject || []),
...(autoconfReject || []),
)];
Object.assign(autoconf, autoconfRest);
ncu = require(join(base, 'node_modules', dep)); // eslint-disable-line global-require
} catch (e) {
console.log(`[Warning]: ${dep} cannot require ncu configuration`);
console.log(`[Warning]: ${dep} cannot find ncu configuration`); // eslint-disable-line no-console
}
}
}
if (ncu) {
console.log(`Auto configuration with ${dep}`); // eslint-disable-line no-console
const { reject: autoconfReject, autoconfRest } = ncu || {}; // eslint-disable-line global-require
autoconf.reject = [...new Set([
...(autoconf.reject || []),
...(autoconfReject || []),
])];

Object.assign(autoconf, autoconfRest);
}
}
});
if (found) {
console.log(`Auto configuration with ${found}`); // eslint-disable-line no-console
}
});
}
return autoconf;
}

const defaultOptions = {
disableAutoConf: false,
extensionFile: '.ncurc.ext.json',
};

/**
Expand All @@ -46,14 +47,18 @@ const defaultOptions = {
*
* Read https://www.npmjs.com/package/npm-check-updates if you don't know what it is.
*
* Usually, you run updates as follow
* Usually, you run updates as follow:
*
* For testing:
*
* ```bash
* $ npx ncu
* ```
*
* Writing to `package.json`:
*
* ```bash
* $ npx npm-check-updates -a
* // or install globally
* $ npm install -g npm-check-updates
* // then run it from global
* $ ncu -a
* $ npx ncu -a
* ```
*
* By default, it will try to read it's configuration from `.ncurc.js`, this is where we hook this configuration:
Expand All @@ -65,19 +70,58 @@ const defaultOptions = {
*
* This configuration will allow you to use:
*
* - **local extension**: Use a new file within a rollup-umd project that will be used to inject ncu configuration per project/
* - **dependency extension**: Use a dependency extension within a rollup-umd project to manage ncu configuration across a set of projects.
* - **Local extension**: In your `package.json` we read `ncurc` within a rollup-umd project to inject ncu configuration per project
* - **Dependency extension**: Use a dependency extension within a rollup-umd project to manage ncu configuration across a set of projects.
*
* ## Local extension
*
* Simply add `npmrc` in your `package.json`:
*
* ```diff
* + "ncurc": {
* + "reject": [
* + "react-styleguidist"
* + ]
* + }
* ```
*
* This will for example add `react-styleguidist` to the ignored package when doing `npx ncu -a` in your project.
*
* ## Dependency extension
*
* To create a dependency extension, all you need is to publish a npm package with:
* This is a dependency listed in your `package.json`.
*
* - The ncu configuration as default exports, it will be merge with ours.
* - Set in the `name` and add in `keywords` of your dependency the string: `ncu`.
* To create a dependency extension, all you need is to publish a npm package with the following requirements:
*
* @param {object} [config={}] - ncu configuration
* - A `ncurc` key containing the configuration in the `package.json` (as the previous example)
*
* **Or** if it only serve a ncu configuration:
*
* - The ncu configuration as default exports **AND** `ncu` in your package name, it will be merge with ours.
*
* ```js static
* export default {
* reject: ['react-styleguidist'],
* };
* ```
*
* These a required **keywords** that **MUST** be set in your `package.json` in order to be detected by the auto configuration:
*
* - The `keywords` of your dependency must have: `ncu`.
* - The `keywords` of your dependency must have this package name: `$PACKAGE_NAME`
*
* ```diff
* "keywords": [
* + "ncu",
* + "$PACKAGE_NAME",
* ],
* ```
*
* Dependency extension will be read by `createConfig` and logging will appear for each detection.
*
* @param {object} [config={}] - local ncu configuration, if you want something
* @param {object} [options={}] - options of create config
* @param {boolean} [options.disableAutoConfig=false] - Disable auto configuration from extensions modules
* @param {string} [options.extensionFile=.ncurrc.ext.json] - Location of the local extension file
* @return {object} npm check updates configuration object
*/
export function createConfig(config = {}, options = {}) {
Expand All @@ -92,8 +136,8 @@ export function createConfig(config = {}, options = {}) {
const base = existsSync(join(cwd, 'package.json')) ? join(cwd) : join(__dirname, '..');
const pkg = require(join(base, 'package.json')); // eslint-disable-line global-require

// allow config from extension file
const { reject: userExtReject, ...restUserExtConfig } = existsSync(join(base, opts.extensionFile)) ? require(join(base, opts.extensionFile)) : {}; // eslint-disable-line global-require
// allow config from extension in package.json
const { reject: userExtReject, ...restUserExtConfig } = pkg.ncurc || {}; // eslint-disable-line global-require

// just for generating it's own documentation, we need it.
const thisPkgPath = join(__dirname, '../package.json');
Expand All @@ -102,13 +146,16 @@ export function createConfig(config = {}, options = {}) {
// allow config from extension module
const { reject: autoConfigReject, ...restAutoConfig } = autoconfig(opts, pkg, thisPkg, base);

const reject = [...new Set([
...(userReject || []),
...(userExtReject || []),
...(autoConfigReject || []),
])];

console.log(`Rejected: ${reject.join(', ')} will be ignored by npm-check-updates.`); // eslint-disable-line no-console
return {
upgrade: true,
reject: [...new Set([
...(userReject || []),
...(userExtReject || []),
...(autoConfigReject || []),
])],
// upgrade: true, // stop due to https://github.com/tjunnone/npm-check-updates/issues/481#issuecomment-469081174
reject,
...Object.assign(
{},
restUserConfig,
Expand Down

0 comments on commit 6e17b88

Please sign in to comment.