From 68d6a6b84cb3d327ffbfb19619b131990aa39bc5 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 4 Nov 2020 19:56:24 +0100 Subject: [PATCH] Add all symbols to the legacy build --- config/jsdoc/info/api-plugin.js | 11 ----------- config/jsdoc/info/conf.json | 1 - config/jsdoc/info/publish.js | 22 +++++++++++----------- tasks/generate-index.js | 27 +++++++++++++-------------- 4 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 config/jsdoc/info/api-plugin.js diff --git a/config/jsdoc/info/api-plugin.js b/config/jsdoc/info/api-plugin.js deleted file mode 100644 index 2a3dd96610..0000000000 --- a/config/jsdoc/info/api-plugin.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Handle the api annotation. - * @param {Object} dictionary The tag dictionary. - */ -exports.defineTags = function (dictionary) { - dictionary.defineTag('api', { - onTagged: function (doclet, tag) { - doclet.api = true; - }, - }); -}; diff --git a/config/jsdoc/info/conf.json b/config/jsdoc/info/conf.json index be9422ef95..969ae716c0 100644 --- a/config/jsdoc/info/conf.json +++ b/config/jsdoc/info/conf.json @@ -11,7 +11,6 @@ }, "plugins": [ "jsdoc-plugin-typescript", - "config/jsdoc/info/api-plugin", "config/jsdoc/info/define-plugin", "config/jsdoc/info/virtual-plugin" ], diff --git a/config/jsdoc/info/publish.js b/config/jsdoc/info/publish.js index f57c4dec57..fe2c8f1316 100644 --- a/config/jsdoc/info/publish.js +++ b/config/jsdoc/info/publish.js @@ -27,19 +27,20 @@ exports.publish = function (data, opts) { {define: {isObject: true}}, function () { if (this.kind == 'class') { - if (!('extends' in this) || typeof this.api == 'boolean') { - classes[this.longname] = this; - return true; - } + classes[this.longname] = this; + return true; } return ( - typeof this.api == 'boolean' || - (this.meta && /[\\\/]externs$/.test(this.meta.path)) + this.meta && + this.meta.path && + this.longname.indexOf('') !== 0 && + this.longname !== 'module:ol' ); }, ], {kind: {'!is': 'file'}}, - {kind: {'!is': 'event'}} + {kind: {'!is': 'event'}}, + {kind: {'!is': 'module'}} ).get(); // get symbols data, filter out those that are members of private classes @@ -77,7 +78,7 @@ exports.publish = function (data, opts) { path: path.join(doc.meta.path, doc.meta.filename), default: doc.define.default, }); - } else if (doc.kind == 'typedef' || doc.isEnum === true) { + } else if (doc.type && (doc.kind == 'typedef' || doc.isEnum === true)) { typedefs.push({ name: doc.longname, types: getTypes(doc.type.names), @@ -136,7 +137,7 @@ exports.publish = function (data, opts) { }); } - const target = isExterns ? externs : doc.api ? symbols : base; + const target = isExterns ? externs : symbols; const existingSymbol = symbolsByName[symbol.name]; if (existingSymbol) { const idx = target.indexOf(existingSymbol); @@ -145,10 +146,9 @@ exports.publish = function (data, opts) { target.push(symbol); symbolsByName[symbol.name] = symbol; - if (doc.api && symbol.extends) { + if (symbol.extends) { while ( symbol.extends in classes && - !classes[symbol.extends].api && classes[symbol.extends].augments ) { symbol.extends = classes[symbol.extends].augments[0]; diff --git a/tasks/generate-index.js b/tasks/generate-index.js index ae22ee1376..2b8ab72fe1 100644 --- a/tasks/generate-index.js +++ b/tasks/generate-index.js @@ -20,7 +20,7 @@ async function getSymbols() { function getImport(symbol, member) { const defaultExport = symbol.name.split('~'); const namedExport = symbol.name.split('.'); - if (defaultExport.length > 1) { + if (defaultExport.length > 1 && defaultExport[0].indexOf('.') === -1) { const from = defaultExport[0].replace(/^module\:/, './'); const importName = from.replace(/[.\/]+/g, '$'); return `import ${importName} from '${from}';`; @@ -53,8 +53,11 @@ function formatSymbolExport(symbol, namespaces, imports) { namespaces[line] = (line in namespaces ? namespaces[line] : true) && i < ii - 1; } - line += ` = ${importName};`; - imports[getImport(symbol, nsParts.pop())] = true; + line += ` = ${importName} || {};`; + const imp = getImport(symbol, nsParts.pop()); + if (imp) { + imports[imp] = true; + } return line; } @@ -68,18 +71,15 @@ function formatSymbolExport(symbol, namespaces, imports) { function generateExports(symbols) { const namespaces = {}; const imports = []; - let blocks = []; + const blocks = []; symbols.forEach(function (symbol) { const name = symbol.name; if (name.indexOf('#') == -1) { const imp = getImport(symbol); if (imp) { - imports[getImport(symbol)] = true; - } - const block = formatSymbolExport(symbol, namespaces, imports); - if (block !== blocks[blocks.length - 1]) { - blocks.push(block); + imports[imp] = true; } + blocks.push(formatSymbolExport(symbol, namespaces, imports)); } }); const nsdefs = []; @@ -89,11 +89,10 @@ function generateExports(symbols) { nsdefs.push(`${ns[i]} = {};`); } } - blocks = Object.keys(imports) - .concat('\nvar ol = {};\n', nsdefs.sort()) - .concat(blocks.sort()); - blocks.push('', 'export default ol;'); - return blocks.join('\n'); + const defs = ['\nvar ol = {};'].concat(nsdefs, [...new Set(blocks)]); + const lines = Object.keys(imports).concat(defs.sort()); + lines.push('', 'export default ol;'); + return lines.join('\n'); } /**