Skip to content

Commit bec69db

Browse files
authored
fix: docs generation should maintain a stable relative path (emberjs#8598)
1 parent 894bdfe commit bec69db

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

docs-generator/compile-docs.js

+40-2
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,54 @@ function generateOptions() {
2929
return Y.Project.init(config);
3030
}
3131

32+
function rewritePath(filePath) {
33+
if (filePath.startsWith('../packages')) {
34+
return filePath.replace('../packages/', '../');
35+
}
36+
if (filePath.startsWith('../')) {
37+
return filePath.replace('../', '../../');
38+
}
39+
return filePath;
40+
}
41+
3242
async function main() {
3343
const options = generateOptions();
3444

3545
const yuidocCompiler = new Y.YUIDoc(options);
36-
const json = yuidocCompiler.run();
37-
const builder = new Y.DocBuilder(options, json);
46+
const initialJson = yuidocCompiler.run();
47+
48+
const builder = new Y.DocBuilder(options, initialJson);
3849

3950
await new Promise((resolve) => {
4051
builder.compile(resolve);
4152
});
53+
54+
const dataFile = path.join(__dirname, '../packages/-ember-data/dist/docs/data.json');
55+
const json = JSON.parse(fs.readFileSync(dataFile));
56+
57+
const newFiles = {};
58+
Object.keys(json.files).forEach((key) => {
59+
const newKey = rewritePath(key);
60+
newFiles[newKey] = json.files[key];
61+
newFiles[newKey].name = newKey;
62+
});
63+
json.files = newFiles;
64+
65+
Object.keys(json.classes).forEach((key) => {
66+
const val = json.classes[key];
67+
if (val.file) {
68+
val.file = rewritePath(val.file);
69+
}
70+
});
71+
72+
Object.keys(json.modules).forEach((key) => {
73+
const val = json.modules[key];
74+
if (val.file) {
75+
val.file = rewritePath(val.file);
76+
}
77+
});
78+
79+
fs.writeFileSync(dataFile, JSON.stringify(json, null, 2));
4280
}
4381

4482
main();

tests/docs/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
const path = require('path');
3+
const fs = require('fs');
4+
25
const QUnit = require('qunit');
36

47
const { test } = QUnit;
@@ -38,6 +41,7 @@ QUnit.module('Docs coverage', function (hooks) {
3841
const module = docs.modules[moduleName];
3942
if (isOwnModule(module)) {
4043
test(`${moduleName} is configured correctly`, function (assert) {
44+
assert.ok(docs.files[module.file], `${moduleName} has a file in ${linkItem(module)}`);
4145
assert.strictEqual(module.tag, 'main', `${moduleName} is tagged as main in ${linkItem(module)}`);
4246
assert.true(isNonEmptyString(module.description), `${moduleName} has a description in ${linkItem(module)}`);
4347
assert.false(
@@ -56,6 +60,7 @@ QUnit.module('Docs coverage', function (hooks) {
5660
return;
5761
}
5862
test(`Class ${className} is documented correctly at ${linkItem(def)}`, function (assert) {
63+
assert.ok(docs.files[def.file], `${className} has a file`);
5964
assert.true(
6065
def.access === 'public' || def.access === 'private',
6166
`${def.name} must declare either as either @internal @private or @public`
@@ -150,6 +155,16 @@ QUnit.module('Docs coverage', function (hooks) {
150155
);
151156
});
152157
});
158+
159+
QUnit.module('files', function (hooks) {
160+
test(`All files have meaningful paths`, function (assert) {
161+
const root = path.join(__dirname, '../../packages/-ember-data');
162+
Object.keys(docs.files).forEach((fileName) => {
163+
const filePath = path.join(root, fileName);
164+
assert.true(fs.existsSync(filePath), `${fileName} is resolvable as ${filePath}`);
165+
});
166+
});
167+
});
153168
});
154169

155170
function setDifference(setA, setB) {

0 commit comments

Comments
 (0)