reffy 4.0.1 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +5 -4
- package/reffy.js +15 -3
- package/src/cli/study-crawl.js +3 -2
- package/src/lib/fetch.js +6 -0
- package/src/lib/nock-server.js +3 -2
- package/src/lib/specs-crawler.js +8 -2
- package/src/lib/util.js +17 -2
package/README.md
CHANGED
|
@@ -11,14 +11,14 @@ The code also currently includes a set of individual tools to study extracts and
|
|
|
11
11
|
|
|
12
12
|
### Pre-requisites
|
|
13
13
|
|
|
14
|
-
To install Reffy, you need [Node.js](https://nodejs.org/en/).
|
|
14
|
+
To install Reffy, you need [Node.js](https://nodejs.org/en/) 14 or greater.
|
|
15
15
|
|
|
16
16
|
### Installation
|
|
17
17
|
|
|
18
18
|
Reffy is available as an NPM package. To install the package globally, run:
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install -g reffy
|
|
21
|
+
npm install -g reffy
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
This will install Reffy as a command-line interface tool.
|
|
@@ -52,7 +52,7 @@ The crawler can be fully parameterized to crawl a specific list of specs and run
|
|
|
52
52
|
```
|
|
53
53
|
- To retrieve the list of specs that the HTML spec references, run (noting that crawling the HTML spec takes some time due to it being a multipage spec):
|
|
54
54
|
```bash
|
|
55
|
-
reffy --spec html --module refs
|
|
55
|
+
reffy --spec html --module refs
|
|
56
56
|
```
|
|
57
57
|
- To extract the list of CSS properties defined in CSS Flexible Box Layout Module Level 1, run:
|
|
58
58
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reffy",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "W3C/WHATWG spec dependencies exploration companion. Features a short set of tools to study spec references as well as WebIDL term definitions and references found in W3C specifications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,20 +32,21 @@
|
|
|
32
32
|
"bin": "./reffy.js",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"abortcontroller-polyfill": "1.7.3",
|
|
35
|
-
"browser-specs": "2.
|
|
35
|
+
"browser-specs": "2.15.1",
|
|
36
36
|
"commander": "8.2.0",
|
|
37
37
|
"fetch-filecache-for-crawling": "4.0.2",
|
|
38
38
|
"node-pandoc": "0.3.0",
|
|
39
39
|
"puppeteer": "10.4.0",
|
|
40
|
+
"semver": "^7.3.5",
|
|
40
41
|
"webidl2": "24.1.2"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"chai": "4.3.4",
|
|
44
45
|
"mocha": "9.1.2",
|
|
45
46
|
"nock": "13.1.3",
|
|
46
|
-
"respec": "26.
|
|
47
|
+
"respec": "26.14.0",
|
|
47
48
|
"respec-hljs": "2.1.1",
|
|
48
|
-
"rollup": "2.
|
|
49
|
+
"rollup": "2.58.0"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"all": "node src/cli/crawl-and-study.js run ed all && node src/cli/crawl-and-study.js run tr all",
|
package/reffy.js
CHANGED
|
@@ -22,11 +22,19 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const commander = require('commander');
|
|
25
|
-
const
|
|
25
|
+
const satisfies = require('semver/functions/satisfies');
|
|
26
26
|
const specs = require('browser-specs');
|
|
27
|
+
const { version, engines } = require('./package.json');
|
|
27
28
|
const { requireFromWorkingDirectory } = require('./src/lib/util');
|
|
28
29
|
const { crawlSpecs } = require('./src/lib/specs-crawler');
|
|
29
30
|
|
|
31
|
+
// Warn if version of Node.js does not satisfy requirements
|
|
32
|
+
if (engines && engines.node && !satisfies(process.version, engines.node)) {
|
|
33
|
+
console.warn(`
|
|
34
|
+
[WARNING] Node.js ${process.version} detected but Reffy needs Node.js ${engines.node}.
|
|
35
|
+
Please consider upgrading Node.js if the program crashes!`);
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
|
|
31
39
|
function parseModuleOption(input) {
|
|
32
40
|
const parts = input.split(':');
|
|
@@ -55,6 +63,7 @@ function parseSpecOption(input) {
|
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
|
|
58
67
|
const program = new commander.Command();
|
|
59
68
|
program
|
|
60
69
|
.version(version)
|
|
@@ -137,7 +146,7 @@ Usage notes for some of the options:
|
|
|
137
146
|
-m, --module <modules...>
|
|
138
147
|
If processing modules are not specified, the crawler runs all core processing
|
|
139
148
|
modules defined in:
|
|
140
|
-
https://github.com/w3c/reffy/
|
|
149
|
+
https://github.com/w3c/reffy/blob/main/src/browserlib/reffy.json
|
|
141
150
|
|
|
142
151
|
Modules must be specified using a relative path to an ".mjs" file that defines
|
|
143
152
|
the processing logic to run on the spec's page in a browser context. For
|
|
@@ -202,7 +211,10 @@ Usage notes for some of the options:
|
|
|
202
211
|
|
|
203
212
|
Valid spec values may be a shortname, a URL, or a relative path to a file that
|
|
204
213
|
contains a list of spec URLs and/or shortnames. All shortnames must exist in
|
|
205
|
-
browser-specs.
|
|
214
|
+
browser-specs. Shortname may be the shortname of the spec series, in which
|
|
215
|
+
case the spec identified as the current specification in the series is used.
|
|
216
|
+
For instance, as of September 2021, "pointerlock" will map to "pointerlock-2"
|
|
217
|
+
because Pointer Lock 2.0 is the current level in the series.
|
|
206
218
|
|
|
207
219
|
Use "all" to include all specs in browser-specs in the crawl. For instance, to
|
|
208
220
|
crawl all specs plus one custom spec that does not exist in browser-specs:
|
package/src/cli/study-crawl.js
CHANGED
|
@@ -119,8 +119,9 @@ function studyCrawlResults(results, options = {}) {
|
|
|
119
119
|
isLatestLevelThatPasses(spec, results, s =>
|
|
120
120
|
s.idl && s.idl.idlNames && s.idl.idlNames[name])));
|
|
121
121
|
|
|
122
|
-
//
|
|
123
|
-
var WebIDLSpec = results.find(spec =>
|
|
122
|
+
// WebIDL-1 only kept for historical reasons to process old crawl results
|
|
123
|
+
var WebIDLSpec = results.find(spec =>
|
|
124
|
+
spec.shortname === 'webidl' || spec.shortname === 'WebIDL-1') || {};
|
|
124
125
|
|
|
125
126
|
var sortedResults = results.sort(byTitle);
|
|
126
127
|
|
package/src/lib/fetch.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @module finder
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
const os = require('os');
|
|
8
9
|
const path = require('path');
|
|
9
10
|
const baseFetch = require('fetch-filecache-for-crawling');
|
|
10
11
|
|
|
@@ -43,6 +44,11 @@ async function fetch(url, options) {
|
|
|
43
44
|
options.refresh = 'once';
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
// Use cache folder in tmp folder by default
|
|
48
|
+
if (!options.cacheFolder) {
|
|
49
|
+
options.cacheFolder = path.resolve(os.tmpdir(), 'reffy-cache');
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
return baseFetch(url, options);
|
|
47
53
|
}
|
|
48
54
|
|
package/src/lib/nock-server.js
CHANGED
|
@@ -36,7 +36,8 @@ const mockSpecs = {
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"/mediacapture-output/": `<script>respecConfig = { shortName: 'test' };</script><script src='https://www.w3.org/Tools/respec/respec-w3c'></script><div id=abstract></div><pre class='idl'>[Exposed=Window] interface Foo { attribute DOMString bar; };</pre>`,
|
|
39
|
-
"/accelerometer/": `<html><h2>Normative references</h2><dl><dt>FOO</dt><dd><a href='https://www.w3.org/TR/Foo'>Foo</a></dd></dl
|
|
39
|
+
"/accelerometer/": `<html><h2>Normative references</h2><dl><dt>FOO</dt><dd><a href='https://www.w3.org/TR/Foo'>Foo</a></dd></dl>`,
|
|
40
|
+
"/pointerlock/": `<html><h1>Pointer Lock 2.0`
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
nock.disableNetConnect();
|
|
@@ -68,7 +69,7 @@ nock("https://respec.org")
|
|
|
68
69
|
|
|
69
70
|
nock("https://api.specref.org")
|
|
70
71
|
.persist()
|
|
71
|
-
.get("/bibrefs?refs=webidl,html").reply(200, {webidl:{href:"https://
|
|
72
|
+
.get("/bibrefs?refs=webidl,html").reply(200, {webidl:{href:"https://webidl.spec.whatwg.org/"}}, {"Access-Control-Allow-Origin": "*"})
|
|
72
73
|
.get("/bibrefs?refs=HTML").reply(200, {HTML:{href:"https://html.spec.whatwg.org/multipage/"}}, {"Access-Control-Allow-Origin": "*"});
|
|
73
74
|
|
|
74
75
|
nock("https://www.w3.org")
|
package/src/lib/specs-crawler.js
CHANGED
|
@@ -482,7 +482,12 @@ function crawlSpecs(options) {
|
|
|
482
482
|
if (typeof spec !== 'string') {
|
|
483
483
|
return spec;
|
|
484
484
|
}
|
|
485
|
-
|
|
485
|
+
let match = specs.find(s => s.url === spec || s.shortname === spec);
|
|
486
|
+
if (!match) {
|
|
487
|
+
match = specs.find(s => s.series &&
|
|
488
|
+
s.series.shortname === spec &&
|
|
489
|
+
s.series.currentSpecification === s.shortname);
|
|
490
|
+
}
|
|
486
491
|
if (match) {
|
|
487
492
|
return match;
|
|
488
493
|
}
|
|
@@ -496,7 +501,8 @@ function crawlSpecs(options) {
|
|
|
496
501
|
url = (new URL(spec, `file://${process.cwd()}/`)).href;
|
|
497
502
|
}
|
|
498
503
|
else {
|
|
499
|
-
|
|
504
|
+
const msg = `Spec ID "${spec}" can neither be interpreted as a URL, a valid shortname or a relative path to an HTML file`;
|
|
505
|
+
throw new Error(msg);
|
|
500
506
|
}
|
|
501
507
|
}
|
|
502
508
|
return {
|
package/src/lib/util.js
CHANGED
|
@@ -14,6 +14,21 @@ const specEquivalents = require('../specs/spec-equivalents.json');
|
|
|
14
14
|
const reffyModules = require('../browserlib/reffy.json');
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Maximum depth difference supported between Reffy's install path and custom
|
|
19
|
+
* modules that may be provided on the command-line
|
|
20
|
+
*
|
|
21
|
+
* TODO: Find a way to get right of that, there should be no limit
|
|
22
|
+
*/
|
|
23
|
+
const maxPathDepth = 20;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns a range array from 0 to the number provided (not included)
|
|
28
|
+
*/
|
|
29
|
+
const range = n => Array.from(Array(n).keys());
|
|
30
|
+
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
* Shortcut that returns a property extractor iterator
|
|
19
34
|
*/
|
|
@@ -356,7 +371,7 @@ async function processSpecification(spec, processFunction, args, options) {
|
|
|
356
371
|
let depth = requestPath.lastIndexOf('__/') / 3;
|
|
357
372
|
const filename = requestPath.substring(requestPath.lastIndexOf('__/') + 3);
|
|
358
373
|
let filePath = path.resolve(__dirname, '..', 'browserlib');
|
|
359
|
-
while (depth <
|
|
374
|
+
while (depth < maxPathDepth - 1) {
|
|
360
375
|
filePath = path.resolve(filePath, '..');
|
|
361
376
|
depth += 1;
|
|
362
377
|
}
|
|
@@ -547,7 +562,7 @@ async function processSpecification(spec, processFunction, args, options) {
|
|
|
547
562
|
// "../../node_modules/[...]" and may import other scripts that are
|
|
548
563
|
// higher in the folder tree.
|
|
549
564
|
await page.addScriptTag({
|
|
550
|
-
url:
|
|
565
|
+
url: `reffy/scripts/${range(maxPathDepth).map(n => '__').join('/')}/reffy.mjs`,
|
|
551
566
|
type: 'module'
|
|
552
567
|
});
|
|
553
568
|
|