GeezerVison is showing github.com — tools: make apilinks building more robust · nodejs/node@027ca95
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Makefile +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -647,16 +647,16 @@ out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets | 647 | 647 |
| 648 | 648 | run-npm-ci = $(PWD)/$(NPM) ci | 649 | 649 |
| | 650 | +LINK_DATA = out/doc/apilinks.json | 650 | 651 | gen-api = tools/doc/generate.js --node-version=$(FULLVERSION) \ | 651 | | - --apilinks=out/apilinks.json $< --output-directory=out/doc/api | 652 | | -gen-apilink = tools/doc/apilinks.js $(wildcard lib/*.js) > $@ | | 652 | + --apilinks=$(LINK_DATA) $< --output-directory=out/doc/api | | 653 | +gen-apilink = tools/doc/apilinks.js $(LINK_DATA) $(wildcard lib/*.js) | 653 | 654 |
| 654 | | -out/apilinks.json: $(wildcard lib/*.js) tools/doc/apilinks.js | | 655 | +$(LINK_DATA): $(wildcard lib/*.js) tools/doc/apilinks.js | 655 | 656 | $(call available-node, $(gen-apilink)) | 656 | 657 |
| 657 | 658 | out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.js \ | 658 | | - tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | \ | 659 | | - out/apilinks.json | | 659 | + tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | $(LINK_DATA) | 660 | 660 | $(call available-node, $(gen-api)) | 661 | 661 |
| 662 | 662 | out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \ | |
Collapse file Copy file name to clipboardExpand all lines: test/doctool/test-apilinks.js +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 | const fixtures = require('../common/fixtures'); | | 5 | +const tmpdir = require('../common/tmpdir'); | 5 | 6 | const fs = require('fs'); | 6 | 7 | const assert = require('assert'); | 7 | 8 | const path = require('path'); | 8 | 9 | const { execFileSync } = require('child_process'); | 9 | 10 |
| 10 | 11 | const script = path.join(__dirname, '..', '..', 'tools', 'doc', 'apilinks.js'); | 11 | | - | 12 | 12 | const apilinks = fixtures.path('apilinks'); | | 13 | + | | 14 | +tmpdir.refresh(); | | 15 | + | 13 | 16 | fs.readdirSync(apilinks).forEach((fixture) => { | 14 | 17 | if (!fixture.endsWith('.js')) return; | 15 | | - const file = path.join(apilinks, fixture); | 16 | | - | 17 | | - const expectedContent = fs.readFileSync(file + 'on', 'utf8'); | | 18 | + const input = path.join(apilinks, fixture); | 18 | 19 |
| 19 | | - const output = execFileSync( | | 20 | + const expectedContent = fs.readFileSync(`${input}on`, 'utf8'); | | 21 | + const outputPath = path.join(tmpdir.path, `${fixture}on`); | | 22 | + execFileSync( | 20 | 23 | process.execPath, | 21 | | - [script, file], | | 24 | + [script, outputPath, input], | 22 | 25 | { encoding: 'utf-8' } | 23 | 26 | ); | 24 | 27 |
| 25 | 28 | const expectedLinks = JSON.parse(expectedContent); | 26 | | - const actualLinks = JSON.parse(output); | | 29 | + const actualLinks = JSON.parse(fs.readFileSync(outputPath)); | 27 | 30 |
| 28 | 31 | for (const [k, v] of Object.entries(expectedLinks)) { | 29 | 32 | assert.ok(k in actualLinks, `link not found: ${k}`); | |
Collapse file Copy file name to clipboardExpand all lines: tools/doc/apilinks.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,9 @@ const tag = execSync(`git describe --contains ${hash}`).split('\n')[0] || hash; | 47 | 47 |
| 48 | 48 | // Extract definitions from each file specified. | 49 | 49 | const definition = {}; | 50 | | -process.argv.slice(2).forEach((file) => { | | 50 | +const output = process.argv[2]; | | 51 | +const inputs = process.argv.slice(3); | | 52 | +inputs.forEach((file) => { | 51 | 53 | const basename = path.basename(file, '.js'); | 52 | 54 |
| 53 | 55 | // Parse source. | @@ -206,4 +208,4 @@ process.argv.slice(2).forEach((file) => { | 206 | 208 | } | 207 | 209 | }); | 208 | 210 |
| 209 | | -console.log(JSON.stringify(definition, null, 2)); | | 211 | +fs.writeFileSync(output, JSON.stringify(definition, null, 2), 'utf8'); |
Collapse file Copy file name to clipboardExpand all lines: tools/doc/generate.js +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,9 +49,12 @@ args.forEach(function(arg) { | 49 | 49 | } else if (arg.startsWith('--output-directory=')) { | 50 | 50 | outputDir = arg.replace(/^--output-directory=/, ''); | 51 | 51 | } else if (arg.startsWith('--apilinks=')) { | 52 | | - apilinks = JSON.parse( | 53 | | - fs.readFileSync(arg.replace(/^--apilinks=/, ''), 'utf8') | 54 | | - ); | | 52 | + const linkFile = arg.replace(/^--apilinks=/, ''); | | 53 | + const data = fs.readFileSync(linkFile, 'utf8'); | | 54 | + if (!data.trim()) { | | 55 | + throw new Error(`${linkFile} is empty`); | | 56 | + } | | 57 | + apilinks = JSON.parse(data); | 55 | 58 | } | 56 | 59 | }); | 57 | 60 |
| |
|