Skip to content

Commit 1b1fa13

Browse files
committed
typemap as json
1 parent f75eaa3 commit 1b1fa13

File tree

5 files changed

+133
-203
lines changed

5 files changed

+133
-203
lines changed

bin/commands/generate.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export default {
120120
prompt: {
121121
message: 'Path to doc/api/type_map.json',
122122
type: 'text',
123+
initialValue: import.meta.resolve(
124+
'../../src/utils/parser/typeMap.json'
125+
),
123126
},
124127
},
125128
},
@@ -131,10 +134,7 @@ export default {
131134
async action(opts) {
132135
const docs = await loadAndParse(opts.input, opts.ignore);
133136
const releases = await parseChangelog(opts.changelog);
134-
135-
const typeMap = opts.typeMap
136-
? JSON.parse(await loadFromURL(opts.typeMap))
137-
: undefined;
137+
const typeMap = JSON.parse(await loadFromURL(opts.typeMap));
138138

139139
const index = opts.index && (await parseIndex(opts.index));
140140

src/utils/parser.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const loadFromURL = async url => {
1212

1313
if (!parsedUrl || parsedUrl.protocol === 'file:') {
1414
// Load from file system
15-
return readFile(url, 'utf-8');
15+
return readFile(parsedUrl, 'utf-8');
1616
} else {
1717
// Load from network
1818
const response = await fetch(parsedUrl);

src/utils/parser/constants.mjs

Lines changed: 0 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -101,199 +101,6 @@ export const DOC_TYPES_MAPPING_GLOBALS = {
101101
'WebAssembly.Instance': 'WebAssembly/Instance',
102102
};
103103

104-
// This is a mapping for types within the Markdown content and their respective
105-
// Node.js types within the Node.js API docs (refers to a different API doc page)
106-
// Note: These hashes are generated with the GitHub Slugger
107-
export const DOC_TYPES_MAPPING_NODE_MODULES = {
108-
AbortController: 'globals.html#class-abortcontroller',
109-
AbortSignal: 'globals.html#class-abortsignal',
110-
111-
Algorithm: 'webcrypto.html#class-algorithm',
112-
AlgorithmIdentifier: 'webcrypto.html#class-algorithmidentifier',
113-
AsyncHook: 'async_hooks.html#async_hookscreatehookcallbacks',
114-
AsyncLocalStorage: 'async_context.html#class-asynclocalstorage',
115-
AsyncResource: 'async_hooks.html#class-asyncresource',
116-
117-
AesCbcParams: 'webcrypto.html#class-aescbcparams',
118-
AesCtrParams: 'webcrypto.html#class-aesctrparams',
119-
AesGcmParams: 'webcrypto.html#class-aesgcmparams',
120-
AesKeyAlgorithm: 'webcrypto.html#class-aeskeyalgorithm',
121-
AesKeyGenParams: 'webcrypto.html#class-aeskeygenparams',
122-
AesDerivedKeyParams: 'webcrypto.html#class-aesderivedkeyparams',
123-
124-
Blob: 'buffer.html#class-blob',
125-
BroadcastChannel:
126-
'worker_threads.html#class-broadcastchannel-extends-eventtarget',
127-
Buffer: 'buffer.html#class-buffer',
128-
129-
ByteLengthQueuingStrategy: 'webstreams.html#class-bytelengthqueuingstrategy',
130-
131-
Channel: 'diagnostics_channel.html#class-channel',
132-
ChildProcess: 'child_process.html#class-childprocess',
133-
Cipher: 'crypto.html#class-cipher',
134-
Cipheriv: 'crypto.html#class-cipheriv',
135-
Decipheriv: 'crypto.html#class-decipheriv',
136-
ClientHttp2Session: 'http2.html#class-clienthttp2session',
137-
ClientHttp2Stream: 'http2.html#class-clienthttp2stream',
138-
139-
CountQueuingStrategy: 'webstreams.html#class-countqueuingstrategy',
140-
141-
Crypto: 'webcrypto.html#class-crypto',
142-
CryptoKey: 'webcrypto.html#class-cryptokey',
143-
CryptoKeyPair: 'webcrypto.html#class-cryptokeypair',
144-
145-
CustomEvent: 'events.html#class-customevent',
146-
147-
Decipher: 'crypto.html#class-decipher',
148-
DiffieHellman: 'crypto.html#class-diffiehellman',
149-
DiffieHellmanGroup: 'crypto.html#class-diffiehellmangroup',
150-
Domain: 'domain.html#class-domain',
151-
152-
Duplex: 'stream.html#class-streamduplex',
153-
154-
ECDH: 'crypto.html#class-ecdh',
155-
EcdhKeyDeriveParams: 'webcrypto.html#class-ecdhkeyderiveparams',
156-
EcdsaParams: 'webcrypto.html#class-ecdsaparams',
157-
EcKeyAlgorithm: 'webcrypto.html#class-eckeyalgorithm',
158-
EcKeyGenParams: 'webcrypto.html#class-eckeygenparams',
159-
EcKeyImportParams: 'webcrypto.html#class-eckeyimportparams',
160-
Ed448Params: 'webcrypto.html#class-ed448params',
161-
162-
Event: 'events.html#class-event',
163-
EventEmitter: 'events.html#class-eventemitter',
164-
EventListener: 'events.html#event-listener',
165-
EventTarget: 'events.html#class-eventtarget',
166-
167-
File: 'buffer.html#class-file',
168-
FileHandle: 'fs.html#class-filehandle',
169-
170-
Handle: 'net.html#serverlistenhandle-backlog-callback',
171-
Hash: 'crypto.html#class-hash',
172-
Histogram: 'perf_hooks.html#class-histogram',
173-
HkdfParams: 'webcrypto.html#class-hkdfparams',
174-
Hmac: 'crypto.html#class-hmac',
175-
HmacImportParams: 'webcrypto.html#class-hmacimportparams',
176-
HmacKeyAlgorithm: 'webcrypto.html#class-hmackeyalgorithm',
177-
HmacKeyGenParams: 'webcrypto.html#class-hmackeygenparams',
178-
179-
Http2SecureServer: 'http2.html#class-http2secureserver',
180-
Http2Server: 'http2.html#class-http2server',
181-
Http2Session: 'http2.html#class-http2session',
182-
Http2Stream: 'http2.html#class-http2stream',
183-
184-
Immediate: 'timers.html#class-immediate',
185-
186-
IntervalHistogram:
187-
'perf_hooks.html#class-intervalhistogram-extends-histogram',
188-
189-
LockManager: 'worker_threads.html#class-lockmanager',
190-
191-
KeyAlgorithm: 'webcrypto.html#class-keyalgorithm',
192-
KeyObject: 'crypto.html#class-keyobject',
193-
194-
MIMEParams: 'util.html#class-utilmimeparams',
195-
MessagePort: 'worker_threads.html#class-messageport',
196-
197-
MockModuleContext: 'test.html#class-mockmodulecontext',
198-
199-
NodeEventTarget: 'events.html#class-nodeeventtarget',
200-
201-
Pbkdf2Params: 'webcrypto.html#class-pbkdf2params',
202-
PerformanceEntry: 'perf_hooks.html#class-performanceentry',
203-
PerformanceNodeTiming: 'perf_hooks.html#class-performancenodetiming',
204-
PerformanceObserver: 'perf_hooks.html#class-performanceobserver',
205-
PerformanceObserverEntryList:
206-
'perf_hooks.html#class-performanceobserverentrylist',
207-
208-
Readable: 'stream.html#class-streamreadable',
209-
ReadableByteStreamController:
210-
'webstreams.html#class-readablebytestreamcontroller',
211-
ReadableStream: 'webstreams.html#class-readablestream',
212-
ReadableStreamBYOBReader: 'webstreams.html#class-readablestreambyobreader',
213-
ReadableStreamBYOBRequest: 'webstreams.html#class-readablestreambyobrequest',
214-
ReadableStreamDefaultController:
215-
'webstreams.html#class-readablestreamdefaultcontroller',
216-
ReadableStreamDefaultReader:
217-
'webstreams.html#class-readablestreamdefaultreader',
218-
219-
ModuleRequest: 'vm.html#type-modulerequest',
220-
221-
DatabaseSync: 'sqlite.html#class-databasesync',
222-
223-
RecordableHistogram:
224-
'perf_hooks.html#class-recordablehistogram-extends-histogram',
225-
226-
RsaHashedKeyAlgorithm: 'webcrypto.html#class-rsahashedkeyalgorithm',
227-
RsaHashedImportParams: 'webcrypto.html#class-rsahashedimportparams',
228-
RsaHashedKeyGenParams: 'webcrypto.html#class-rsahashedkeygenparams',
229-
RsaOaepParams: 'webcrypto.html#class-rsaoaepparams',
230-
RsaPssParams: 'webcrypto.html#class-rsapssparams',
231-
232-
ServerHttp2Session: 'http2.html#class-serverhttp2session',
233-
ServerHttp2Stream: 'http2.html#class-serverhttp2stream',
234-
235-
Sign: 'crypto.html#class-sign',
236-
237-
Disposable:
238-
'https://tc39.es/proposal-explicit-resource-management/#sec-disposable-interface',
239-
240-
Session: 'sqlite.html#class-session',
241-
StatementSync: 'sqlite.html#class-statementsync',
242-
243-
Stream: 'stream.html#stream',
244-
245-
SubtleCrypto: 'webcrypto.html#class-subtlecrypto',
246-
247-
TestsStream: 'test.html#class-testsstream',
248-
249-
TextDecoderStream: 'webstreams.html#class-textdecoderstream',
250-
TextEncoderStream: 'webstreams.html#class-textencoderstream',
251-
252-
Timeout: 'timers.html#class-timeout',
253-
Timer: 'timers.html#timers',
254-
255-
Tracing: 'tracing.html#tracing-object',
256-
TracingChannel: 'diagnostics_channel.html#class-tracingchannel',
257-
258-
Transform: 'stream.html#class-streamtransform',
259-
TransformStream: 'webstreams.html#class-transformstream',
260-
TransformStreamDefaultController:
261-
'webstreams.html#class-transformstreamdefaultcontroller',
262-
263-
URL: 'url.html#the-whatwg-url-api',
264-
URLSearchParams: 'url.html#class-urlsearchparams',
265-
266-
Verify: 'crypto.html#class-verify',
267-
268-
Writable: 'stream.html#class-streamwritable',
269-
WritableStream: 'webstreams.html#class-writablestream',
270-
WritableStreamDefaultController:
271-
'webstreams.html#class-writablestreamdefaultcontroller',
272-
WritableStreamDefaultWriter:
273-
'webstreams.html#class-writablestreamdefaultwriter',
274-
275-
Worker: 'worker_threads.html#class-worker',
276-
277-
X509Certificate: 'crypto.html#class-x509certificate',
278-
279-
'brotli options': 'zlib.html#class-brotlioptions',
280-
281-
'import.meta': 'esm.html#importmeta',
282-
283-
'os.constants.dlopen': 'os.html#dlopen-constants',
284-
285-
'readlinePromises.Interface': 'readline.html#class-readlinepromisesinterface',
286-
287-
require: 'modules.html#requireid',
288-
module: 'modules.html#the-module-object',
289-
290-
'zlib options': 'zlib.html#class-options',
291-
'zstd options': 'zlib.html#class-zstdoptions',
292-
293-
'HTTP/2 Headers Object': 'http2.html#headers-object',
294-
'HTTP/2 Settings Object': 'http2.html#settings-object',
295-
};
296-
297104
// This is a mapping for miscellaneous types within the Markdown content and their respective
298105
// external reference on appropriate 3rd-party vendors/documentation sites.
299106
export const DOC_TYPES_MAPPING_OTHER = {

src/utils/parser/index.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
DOC_MDN_BASE_URL_JS_GLOBALS,
88
DOC_MDN_BASE_URL_JS_PRIMITIVES,
99
DOC_TYPES_MAPPING_GLOBALS,
10-
DOC_TYPES_MAPPING_NODE_MODULES,
1110
DOC_TYPES_MAPPING_OTHER,
1211
DOC_TYPES_MAPPING_PRIMITIVES,
1312
DOC_MAN_BASE_URL,
@@ -69,10 +68,7 @@ export const transformUnixManualToLink = (
6968
* @param {Record<string, string>} record The mapping of types to links
7069
* @returns {string} The Markdown link as a string (formatted in Markdown)
7170
*/
72-
export const transformTypeToReferenceLink = (
73-
type,
74-
record = DOC_TYPES_MAPPING_NODE_MODULES
75-
) => {
71+
export const transformTypeToReferenceLink = (type, record) => {
7672
// Removes the wrapping tags that wrap the type references such as `<>` and `{}`
7773
const typeInput = type.replace(/[{}<>]/g, '');
7874

src/utils/parser/typeMap.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"AbortController": "globals.html#class-abortcontroller",
3+
"AbortSignal": "globals.html#class-abortsignal",
4+
"Algorithm": "webcrypto.html#class-algorithm",
5+
"AlgorithmIdentifier": "webcrypto.html#class-algorithmidentifier",
6+
"AsyncHook": "async_hooks.html#async_hookscreatehookcallbacks",
7+
"AsyncLocalStorage": "async_context.html#class-asynclocalstorage",
8+
"AsyncResource": "async_hooks.html#class-asyncresource",
9+
"AesCbcParams": "webcrypto.html#class-aescbcparams",
10+
"AesCtrParams": "webcrypto.html#class-aesctrparams",
11+
"AesGcmParams": "webcrypto.html#class-aesgcmparams",
12+
"AesKeyAlgorithm": "webcrypto.html#class-aeskeyalgorithm",
13+
"AesKeyGenParams": "webcrypto.html#class-aeskeygenparams",
14+
"AesDerivedKeyParams": "webcrypto.html#class-aesderivedkeyparams",
15+
"Blob": "buffer.html#class-blob",
16+
"BroadcastChannel": "worker_threads.html#class-broadcastchannel-extends-eventtarget",
17+
"Buffer": "buffer.html#class-buffer",
18+
"ByteLengthQueuingStrategy": "webstreams.html#class-bytelengthqueuingstrategy",
19+
"Channel": "diagnostics_channel.html#class-channel",
20+
"ChildProcess": "child_process.html#class-childprocess",
21+
"Cipher": "crypto.html#class-cipher",
22+
"Cipheriv": "crypto.html#class-cipheriv",
23+
"Decipheriv": "crypto.html#class-decipheriv",
24+
"ClientHttp2Session": "http2.html#class-clienthttp2session",
25+
"ClientHttp2Stream": "http2.html#class-clienthttp2stream",
26+
"CountQueuingStrategy": "webstreams.html#class-countqueuingstrategy",
27+
"Crypto": "webcrypto.html#class-crypto",
28+
"CryptoKey": "webcrypto.html#class-cryptokey",
29+
"CryptoKeyPair": "webcrypto.html#class-cryptokeypair",
30+
"CustomEvent": "events.html#class-customevent",
31+
"Decipher": "crypto.html#class-decipher",
32+
"DiffieHellman": "crypto.html#class-diffiehellman",
33+
"DiffieHellmanGroup": "crypto.html#class-diffiehellmangroup",
34+
"Domain": "domain.html#class-domain",
35+
"Duplex": "stream.html#class-streamduplex",
36+
"ECDH": "crypto.html#class-ecdh",
37+
"EcdhKeyDeriveParams": "webcrypto.html#class-ecdhkeyderiveparams",
38+
"EcdsaParams": "webcrypto.html#class-ecdsaparams",
39+
"EcKeyAlgorithm": "webcrypto.html#class-eckeyalgorithm",
40+
"EcKeyGenParams": "webcrypto.html#class-eckeygenparams",
41+
"EcKeyImportParams": "webcrypto.html#class-eckeyimportparams",
42+
"Ed448Params": "webcrypto.html#class-ed448params",
43+
"Event": "events.html#class-event",
44+
"EventEmitter": "events.html#class-eventemitter",
45+
"EventListener": "events.html#event-listener",
46+
"EventTarget": "events.html#class-eventtarget",
47+
"File": "buffer.html#class-file",
48+
"FileHandle": "fs.html#class-filehandle",
49+
"Handle": "net.html#serverlistenhandle-backlog-callback",
50+
"Hash": "crypto.html#class-hash",
51+
"Histogram": "perf_hooks.html#class-histogram",
52+
"HkdfParams": "webcrypto.html#class-hkdfparams",
53+
"Hmac": "crypto.html#class-hmac",
54+
"HmacImportParams": "webcrypto.html#class-hmacimportparams",
55+
"HmacKeyAlgorithm": "webcrypto.html#class-hmackeyalgorithm",
56+
"HmacKeyGenParams": "webcrypto.html#class-hmackeygenparams",
57+
"Http2SecureServer": "http2.html#class-http2secureserver",
58+
"Http2Server": "http2.html#class-http2server",
59+
"Http2Session": "http2.html#class-http2session",
60+
"Http2Stream": "http2.html#class-http2stream",
61+
"Immediate": "timers.html#class-immediate",
62+
"IntervalHistogram": "perf_hooks.html#class-intervalhistogram-extends-histogram",
63+
"LockManager": "worker_threads.html#class-lockmanager",
64+
"KeyAlgorithm": "webcrypto.html#class-keyalgorithm",
65+
"KeyObject": "crypto.html#class-keyobject",
66+
"MIMEParams": "util.html#class-utilmimeparams",
67+
"MessagePort": "worker_threads.html#class-messageport",
68+
"MockModuleContext": "test.html#class-mockmodulecontext",
69+
"NodeEventTarget": "events.html#class-nodeeventtarget",
70+
"Pbkdf2Params": "webcrypto.html#class-pbkdf2params",
71+
"PerformanceEntry": "perf_hooks.html#class-performanceentry",
72+
"PerformanceNodeTiming": "perf_hooks.html#class-performancenodetiming",
73+
"PerformanceObserver": "perf_hooks.html#class-performanceobserver",
74+
"PerformanceObserverEntryList": "perf_hooks.html#class-performanceobserverentrylist",
75+
"Readable": "stream.html#class-streamreadable",
76+
"ReadableByteStreamController": "webstreams.html#class-readablebytestreamcontroller",
77+
"ReadableStream": "webstreams.html#class-readablestream",
78+
"ReadableStreamBYOBReader": "webstreams.html#class-readablestreambyobreader",
79+
"ReadableStreamBYOBRequest": "webstreams.html#class-readablestreambyobrequest",
80+
"ReadableStreamDefaultController": "webstreams.html#class-readablestreamdefaultcontroller",
81+
"ReadableStreamDefaultReader": "webstreams.html#class-readablestreamdefaultreader",
82+
"ModuleRequest": "vm.html#type-modulerequest",
83+
"DatabaseSync": "sqlite.html#class-databasesync",
84+
"RecordableHistogram": "perf_hooks.html#class-recordablehistogram-extends-histogram",
85+
"RsaHashedKeyAlgorithm": "webcrypto.html#class-rsahashedkeyalgorithm",
86+
"RsaHashedImportParams": "webcrypto.html#class-rsahashedimportparams",
87+
"RsaHashedKeyGenParams": "webcrypto.html#class-rsahashedkeygenparams",
88+
"RsaOaepParams": "webcrypto.html#class-rsaoaepparams",
89+
"RsaPssParams": "webcrypto.html#class-rsapssparams",
90+
"ServerHttp2Session": "http2.html#class-serverhttp2session",
91+
"ServerHttp2Stream": "http2.html#class-serverhttp2stream",
92+
"Sign": "crypto.html#class-sign",
93+
"Disposable": "https://tc39.es/proposal-explicit-resource-management/#sec-disposable-interface",
94+
"Session": "sqlite.html#class-session",
95+
"StatementSync": "sqlite.html#class-statementsync",
96+
"Stream": "stream.html#stream",
97+
"SubtleCrypto": "webcrypto.html#class-subtlecrypto",
98+
"TestsStream": "test.html#class-testsstream",
99+
"TextDecoderStream": "webstreams.html#class-textdecoderstream",
100+
"TextEncoderStream": "webstreams.html#class-textencoderstream",
101+
"Timeout": "timers.html#class-timeout",
102+
"Timer": "timers.html#timers",
103+
"Tracing": "tracing.html#tracing-object",
104+
"TracingChannel": "diagnostics_channel.html#class-tracingchannel",
105+
"Transform": "stream.html#class-streamtransform",
106+
"TransformStream": "webstreams.html#class-transformstream",
107+
"TransformStreamDefaultController": "webstreams.html#class-transformstreamdefaultcontroller",
108+
"URL": "url.html#the-whatwg-url-api",
109+
"URLSearchParams": "url.html#class-urlsearchparams",
110+
"Verify": "crypto.html#class-verify",
111+
"Writable": "stream.html#class-streamwritable",
112+
"WritableStream": "webstreams.html#class-writablestream",
113+
"WritableStreamDefaultController": "webstreams.html#class-writablestreamdefaultcontroller",
114+
"WritableStreamDefaultWriter": "webstreams.html#class-writablestreamdefaultwriter",
115+
"Worker": "worker_threads.html#class-worker",
116+
"X509Certificate": "crypto.html#class-x509certificate",
117+
"brotli options": "zlib.html#class-brotlioptions",
118+
"import.meta": "esm.html#importmeta",
119+
"os.constants.dlopen": "os.html#dlopen-constants",
120+
"readlinePromises.Interface": "readline.html#class-readlinepromisesinterface",
121+
"require": "modules.html#requireid",
122+
"module": "modules.html#the-module-object",
123+
"zlib options": "zlib.html#class-options",
124+
"zstd options": "zlib.html#class-zstdoptions",
125+
"HTTP/2 Headers Object": "http2.html#headers-object",
126+
"HTTP/2 Settings Object": "http2.html#settings-object"
127+
}

0 commit comments

Comments
 (0)