Skip to content

Commit

Permalink
chore: preserve links to master version of API from README.md (#3197)
Browse files Browse the repository at this point in the history
One of our checks makes sure all links from README.md to API.md
point to the last-released version of the API.

This sometimes doesn't work: when we refer to a section
in api.md that is just added, we should be able to reference
the "master" version of the api.md

This patch:
- teaches the doclint check to keep links to tip-of-tree version
  of api.md in README.md intact.
- starts refering to tip-of-tree version of api.md in `puppeter-core` section
  • Loading branch information
aslushnikov committed Sep 5, 2018
1 parent 3364659 commit 7db4f0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -51,7 +51,7 @@ npm i puppeteer-core

`puppeteer-core` is intended to be a lightweight version of puppeteer for launching an existing browser installation or for connecting to a remote one.

See [puppeteer vs puppeteer-core](https://github.com/GoogleChrome/puppeteer/blob/v1.7.0/docs/api.md#puppeteer-vs-puppeteer-core).
See [puppeteer vs puppeteer-core](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteer-vs-puppeteer-core).

### Usage

Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/preprocessor/index.js
Expand Up @@ -18,7 +18,7 @@ const Message = require('../Message');

module.exports.ensureReleasedAPILinks = function(sources, version) {
// Release version is everything that doesn't include "-".
const apiLinkRegex = /https:\/\/github.com\/GoogleChrome\/puppeteer\/blob\/[^/]*\/docs\/api.md/ig;
const apiLinkRegex = /https:\/\/github.com\/GoogleChrome\/puppeteer\/blob\/v[^/]*\/docs\/api.md/ig;
const lastReleasedAPI = `https://github.com/GoogleChrome/puppeteer/blob/v${version.split('-')[0]}/docs/api.md`;

const messages = [];
Expand Down
14 changes: 12 additions & 2 deletions utils/doclint/preprocessor/test.js
Expand Up @@ -28,7 +28,7 @@ const {expect} = new Matchers();
describe('ensureReleasedAPILinks', function() {
it('should work with non-release version', function() {
const source = new Source('doc.md', `
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.1.0/docs/api.md#class-page)
`);
const messages = ensureReleasedAPILinks([source], '1.3.0-post');
expect(messages.length).toBe(1);
Expand All @@ -40,7 +40,7 @@ describe('ensureReleasedAPILinks', function() {
});
it('should work with release version', function() {
const source = new Source('doc.md', `
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.1.0/docs/api.md#class-page)
`);
const messages = ensureReleasedAPILinks([source], '1.3.0');
expect(messages.length).toBe(1);
Expand All @@ -50,6 +50,16 @@ describe('ensureReleasedAPILinks', function() {
[API](https://github.com/GoogleChrome/puppeteer/blob/v1.3.0/docs/api.md#class-page)
`);
});
it('should keep master links intact', function() {
const source = new Source('doc.md', `
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
`);
const messages = ensureReleasedAPILinks([source], '1.3.0');
expect(messages.length).toBe(0);
expect(source.text()).toBe(`
[API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page)
`);
});
});

describe('runCommands', function() {
Expand Down

0 comments on commit 7db4f0f

Please sign in to comment.