-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: Include links to source code in documentation #22405
Conversation
This is a first "proof of concept" step towards implementing #22393. It scans The basic idea is that A few things to note from just this first step:
|
It should be possible for releases (docs are built at the same time). Probably for nightlies too. |
Indeed, the commit hash is known and fixed by the time the docs are rendered. Since what we store in git are doc "sources", and only render them as part of the release process. They are even tagged so we can construct a URI apriori (https://github.com/nodejs/node/blob/v10.9.0/lib/console.js#L32). |
It certainly can be made to work for releases and nightlies. What should be done for builds done by developers on their own machines? |
reminder to self. find a way to put that into the binary as well |
Note that this use case would include people who are verifying their changes before pushing them. |
I think it would be worthwhile for this code to land at this point in order to (1) debug the build processes, (2) get wider review of the appearance and usability of the output produced, (3) get feedback on the developer experience. Known issues:
Most of all, landing this would enable mutliple people to contribute to completing this effort. |
Test failure is unrelated:
|
Flaky test: #21038 |
@refack Thanks! Thoughts? |
/CC @nodejs/website @nodejs/website-redesign let's get some feedback from the website folk. |
tools/doc/apilinks.js
Outdated
const repo = (child_process.execSync('git remote get-url origin').toString() | ||
.match(/(\w+\/\w+)\.git\r?\n?$/) || ['', 'nodejs/node'])[1]; | ||
let hash = child_process.execSync('git log -1 --pretty=%H').toString().trim(); | ||
const repo = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should get this from the environment with a default of https://github.com/nodejs/node/blob/
, similar to
Lines 606 to 609 in 36468ca
# Google Analytics ID used for tracking API docs page views, empty | |
# DOCS_ANALYTICS means no tracking scripts will be included in the | |
# generated .html files | |
DOCS_ANALYTICS ?= |
For example on my PC I don't have an origin
remote, I have upstream
instead. On the CI use use the ssh
protocol so: remote.origin.url=git@github.com:nodejs/node.git
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with an environment variable, and I'm fine with a default to nodejs/node
when all else fails, and I'm fine with looking at upstream
if origin
is not found... that being said, I continue to assert that enabling a developer to validate their own work before creating a pull request is an important use case.
It looks like git rev-parse --abbrev-ref --symbolic-full-name @{u}
will show the correct remote associated with the current branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that being said, I continue to assert that enabling a developer to validate their own work before creating a pull request is an important use case.
Sure, but I'm willing to assume the most common case, then allow for the developer to manually override it. Case in point our form to start a CI job. It has defaults, and allows the submitter to override them. IMHO trying to deduce configuration on end user's machine is just a world of hurt.
It looks like git
rev-parse --abbrev-ref --symbolic-full-name @{u}
will show the correct remote associated with the current branch.
The trick is that we need to read files in this non checked out ref. Maybe we can stream them out, and only those who are diff from the current HEAD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain world of hurt?
I found an alternate set of github commands that does the job, perhaps more clearly:
LOCAL_BRANCH=`git name-rev --name-only HEAD`
TRACKING_REMOTE=`git config branch.$LOCAL_BRANCH.remote`
REMOTE_URL=`git config remote.$TRACKING_REMOTE.url`
This (plus fallback to nodejs/node when any of the above commands fail) should work for the common case (CI, release). It should also work when a developer is working on branch in their own private fork.
Why the insistence on inconveniencing the developer?
Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16668/ |
an endless wormhole of edge cases. For example as I mentioned in our CI (which also does the release)
so the only url is
or
On top of that we want to maintain a tarball build that work on code not in a git workspace.
I don't want to inconvenience the developer. I just don't want to over optimize this and end up with a bunch of unmaintainable code. Thinking about this some more IMHO the main thing a dev would want to verify is that the docs detected the correct file/line-number, so maybe having an intermediary step that also generate an |
The current code contains the following line:
By looking only at the end of the URL, this code effortlessly handles both git and https urls. And defaults to Net: for all the cases you have described, the code (particularly when I apply the changes mentioned above) will "just work". And if anything goes wrong, it falls back to |
I'm just voicing my 2c. I won't block this in any way, as I tend to yield to the author on personal style or cost/benefit decisions. How about generating an |
Cool, thanks! At the moment, it is blocked by lack of reviews. The documentation team seems to be a bit inactive. I'll wait a day or so, and then start asking for RSLGTM reviews.
Can you point me at the documentation for such? It sounds like a great idea, as the data sources are "dirty" and the more users we can find for the the filtered data results, the more likely that data will be maintained and accurate. |
I will try to review at weekend but do not wait for me if the PR will have enough approvals. The most part of this PR is out of my sure competence anyway) |
tools/doc/apilinks.js
Outdated
|
||
// parse source | ||
const source = fs.readFileSync(file, 'utf8'); | ||
const ast = acorn.parse(source, { ecmaVersion: 10 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding locations: true
will annotate the nodes with line & column location. So no need for lineends
.
e.g:
> const acorn = require('internal/deps/acorn/dist/acorn');
> const source = fs.readFileSync(file, 'utf8');
> const ast = acorn.parse('lib/buffer.js', { ecmaVersion: 10, locations: true })
> console.log(ast.body[2].loc)
SourceLocation {
start: Position { line: 42, column: 0 },
end: Position { line: 42, column: 21 } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or const acorn = require('../../deps/acorn');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That gets me:
SyntaxError: Unexpected token (127:12)
at Parser.pp$4.raise (/Users/rubys/git/node/deps/acorn/dist/acorn.js:2649:13)
at Parser.pp.unexpected (/Users/rubys/git/node/deps/acorn/dist/acorn.js:637:8)
at Parser.pp.expect (/Users/rubys/git/node/deps/acorn/dist/acorn.js:631:26)
at Parser.pp$1.parseTryStatement (/Users/rubys/git/node/deps/acorn/dist/acorn.js:983:10)
at Parser.pp$1.parseStatement (/Users/rubys/git/node/deps/acorn/dist/acorn.js:768:32)
at Parser.pp$1.parseBlock (/Users/rubys/git/node/deps/acorn/dist/acorn.js:1077:23)
at Parser.pp$1.parseStatement (/Users/rubys/git/node/deps/acorn/dist/acorn.js:775:34)
at Parser.pp$1.parseIfStatement (/Users/rubys/git/node/deps/acorn/dist/acorn.js:902:26)
at Parser.pp$1.parseStatement (/Users/rubys/git/node/deps/acorn/dist/acorn.js:764:31)
at Parser.pp$1.parseBlock (/Users/rubys/git/node/deps/acorn/dist/acorn.js:1077:23)
make[1]: *** [out/apilinks.json] Error 1
This is while parsing lib/assert.js
dep/acorn is at version 5.2.1, and needs to be at 5.6.0 or later to support this relatively new JavaScript feature.
How did you get past this?
Imported from the tarball published on npm (https://registry.npmjs.org/acorn/-/acorn-5.7.2.tgz). Update to emcaScript version 10 in order to get support for binding-less catch statements. Also needed to parse node.js lib API in #22405. PR-URL: #22488 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Parse source code using acorn; extracting exports. When producing documentation, match exports to headers. When a match is found, add a [src] link. This first commit handles simple exported classes and functions, and does so without requiring any changes to the source code or markdown. Subsequent commits will attempt to match more headers, and some of these changes are likely to require changes to the source code and/or markdown. PR-URL: #22405 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Imported from the tarball published on npm (https://registry.npmjs.org/acorn/-/acorn-5.7.2.tgz). Update to emcaScript version 10 in order to get support for binding-less catch statements. Also needed to parse node.js lib API in #22405. PR-URL: #22488 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Parse source code using acorn; extracting exports. When producing documentation, match exports to headers. When a match is found, add a [src] link. This first commit handles simple exported classes and functions, and does so without requiring any changes to the source code or markdown. Subsequent commits will attempt to match more headers, and some of these changes are likely to require changes to the source code and/or markdown. PR-URL: #22405 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
first proof of concept
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes