5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -149,9 +149,12 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Tests
|
||||
- name: Build the Package
|
||||
run: npm run build-package
|
||||
|
||||
- name: Generate the Legacy Build
|
||||
run: npm run build-legacy
|
||||
|
||||
rendering:
|
||||
name: Rendering
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
]
|
||||
},
|
||||
"plugins": [
|
||||
"config/jsdoc/api/plugins/markdown.cjs",
|
||||
"config/jsdoc/plugins/markdown.cjs",
|
||||
"jsdoc-plugin-typescript",
|
||||
"config/jsdoc/api/plugins/inline-options.cjs",
|
||||
"config/jsdoc/api/plugins/events.cjs",
|
||||
"config/jsdoc/api/plugins/observable.cjs",
|
||||
"config/jsdoc/api/plugins/api.cjs"
|
||||
"config/jsdoc/plugins/inline-options.cjs",
|
||||
"config/jsdoc/plugins/events.cjs",
|
||||
"config/jsdoc/plugins/observable.cjs",
|
||||
"config/jsdoc/plugins/api.cjs",
|
||||
"config/jsdoc/plugins/default-export.cjs"
|
||||
],
|
||||
"typescript": {
|
||||
"moduleRoot": "src"
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
},
|
||||
"plugins": [
|
||||
"jsdoc-plugin-typescript",
|
||||
"config/jsdoc/info/define-plugin.cjs",
|
||||
"config/jsdoc/info/virtual-plugin.cjs"
|
||||
"config/jsdoc/plugins/define-plugin.cjs",
|
||||
"config/jsdoc/plugins/virtual-plugin.cjs",
|
||||
"config/jsdoc/plugins/default-export.cjs"
|
||||
],
|
||||
"typescript": {
|
||||
"moduleRoot": "src"
|
||||
|
||||
@@ -137,6 +137,9 @@ exports.publish = function (data, opts) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (doc.isDefaultExport) {
|
||||
symbol.isDefaultExport = true;
|
||||
}
|
||||
|
||||
const target = isExterns ? externs : symbols;
|
||||
const existingSymbol = symbolsByName[symbol.name];
|
||||
|
||||
@@ -104,26 +104,6 @@ function includeTypes(doclet) {
|
||||
}
|
||||
}
|
||||
|
||||
const defaultExports = {};
|
||||
const path = require('path');
|
||||
const moduleRoot = path.join(process.cwd(), 'src');
|
||||
|
||||
// Tag default exported Identifiers because their name should be the same as the module name.
|
||||
exports.astNodeVisitor = {
|
||||
visitNode: function (node, e, parser, currentSourceName) {
|
||||
if (node.parent && node.parent.type === 'ExportDefaultDeclaration') {
|
||||
const modulePath = path
|
||||
.relative(moduleRoot, currentSourceName)
|
||||
.replace(/\.js$/, '');
|
||||
const exportName =
|
||||
'module:' +
|
||||
modulePath.replace(/\\/g, '/') +
|
||||
(node.name ? '~' + node.name : '');
|
||||
defaultExports[exportName] = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function sortOtherMembers(doclet) {
|
||||
if (doclet.fires) {
|
||||
doclet.fires.sort(function (a, b) {
|
||||
@@ -198,18 +178,4 @@ exports.handlers = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
processingComplete(e) {
|
||||
const byLongname = e.doclets.index.longname;
|
||||
for (const name in defaultExports) {
|
||||
if (!(name in byLongname)) {
|
||||
throw new Error(
|
||||
`missing ${name} in doclet index, did you forget a @module tag?`
|
||||
);
|
||||
}
|
||||
byLongname[name].forEach(function (doclet) {
|
||||
doclet.isDefaultExport = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
35
config/jsdoc/plugins/default-export.cjs
Normal file
35
config/jsdoc/plugins/default-export.cjs
Normal file
@@ -0,0 +1,35 @@
|
||||
const defaultExports = {};
|
||||
const path = require('path');
|
||||
const moduleRoot = path.join(process.cwd(), 'src');
|
||||
|
||||
// Tag default exported Identifiers because their name should be the same as the module name.
|
||||
exports.astNodeVisitor = {
|
||||
visitNode: function (node, e, parser, currentSourceName) {
|
||||
if (node.parent && node.parent.type === 'ExportDefaultDeclaration') {
|
||||
const modulePath = path
|
||||
.relative(moduleRoot, currentSourceName)
|
||||
.replace(/\.js$/, '');
|
||||
const exportName =
|
||||
'module:' +
|
||||
modulePath.replace(/\\/g, '/') +
|
||||
(node.name ? '~' + node.name : '');
|
||||
defaultExports[exportName] = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
exports.handlers = {
|
||||
processingComplete(e) {
|
||||
const byLongname = e.doclets.index.longname;
|
||||
for (const name in defaultExports) {
|
||||
if (!(name in byLongname)) {
|
||||
throw new Error(
|
||||
`missing ${name} in doclet index, did you forget a @module tag?`
|
||||
);
|
||||
}
|
||||
byLongname[name].forEach(function (doclet) {
|
||||
doclet.isDefaultExport = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -21,8 +21,8 @@
|
||||
"serve-examples": "webpack serve --config examples/webpack/config.js --mode development",
|
||||
"build-examples": "webpack --config examples/webpack/config.js --mode production",
|
||||
"build-package": "npm run transpile && npm run copy-css && node tasks/prepare-package.js",
|
||||
"build-index": "npm run build-package && node tasks/generate-index.js",
|
||||
"build-legacy": "shx rm -rf build && npm run build-index && webpack --config config/webpack-config-legacy-build.js && cleancss --source-map src/ol/ol.css -o build/legacy/ol.css",
|
||||
"build-index": "shx rm -f build/index.js && npm run build-package && node tasks/generate-index.js",
|
||||
"build-legacy": "shx rm -rf build/legacy && npm run build-index && webpack --config config/webpack-config-legacy-build.js && cleancss --source-map src/ol/ol.css -o build/legacy/ol.css",
|
||||
"build-site": "npm run build-examples && npm run apidoc && mkdir -p build/site && cp site/index.html build/site && mv build/apidoc build/site/apidoc && mv build/examples build/site/examples",
|
||||
"copy-css": "shx cp src/ol/ol.css build/ol/ol.css",
|
||||
"transpile": "shx rm -rf build/ol && shx mkdir -p build/ol && shx cp -rf src/ol build/ol/src && node tasks/serialize-workers.cjs && tsc --project config/tsconfig-build.json",
|
||||
|
||||
@@ -22,15 +22,20 @@ async function getSymbols() {
|
||||
*/
|
||||
function getImport(symbol, member) {
|
||||
const defaultExport = symbol.name.split('~');
|
||||
const namedExport = symbol.name.split('.');
|
||||
if (defaultExport.length > 1 && defaultExport[0].indexOf('.') === -1) {
|
||||
const from = defaultExport[0].replace(/^module\:/, './') + '.js';
|
||||
if (symbol.isDefaultExport) {
|
||||
const from = defaultExport[0].replace(/^module\:/, './');
|
||||
const importName = from.replace(/[.\/]+/g, '$');
|
||||
return `import ${importName} from '${from}';`;
|
||||
} else if (namedExport.length > 1 && member) {
|
||||
const from = namedExport[0].replace(/^module\:/, './') + '.js';
|
||||
return `import ${importName} from '${from}.js';`;
|
||||
}
|
||||
const namedExport = symbol.name.split('.');
|
||||
if (
|
||||
member &&
|
||||
namedExport.length > 1 &&
|
||||
(defaultExport.length <= 1 || defaultExport[0].indexOf('.') !== -1)
|
||||
) {
|
||||
const from = namedExport[0].replace(/^module\:/, './');
|
||||
const importName = from.replace(/[.\/]+/g, '_');
|
||||
return `import {${member} as ${importName}$${member}} from '${from}';`;
|
||||
return `import {${member} as ${importName}$${member}} from '${from}.js';`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,24 +49,24 @@ function getImport(symbol, member) {
|
||||
function formatSymbolExport(symbol, namespaces, imports) {
|
||||
const name = symbol.name;
|
||||
const parts = name.split('~');
|
||||
const isNamed = parts[0].indexOf('.') !== -1;
|
||||
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
|
||||
const last = nsParts.length - 1;
|
||||
const importName = isNamed
|
||||
? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last]
|
||||
: '$' + nsParts.join('$');
|
||||
let line = nsParts[0];
|
||||
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
|
||||
line += `.${nsParts[i]}`;
|
||||
namespaces[line] =
|
||||
(line in namespaces ? namespaces[line] : true) && i < ii - 1;
|
||||
}
|
||||
line += ` = ${importName} || {};`;
|
||||
const imp = getImport(symbol, nsParts.pop());
|
||||
const imp = getImport(symbol, nsParts[last]);
|
||||
if (imp) {
|
||||
const isNamed = parts[0].indexOf('.') !== -1;
|
||||
const importName = isNamed
|
||||
? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last]
|
||||
: '$' + nsParts.join('$');
|
||||
let line = nsParts[0];
|
||||
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
|
||||
line += `.${nsParts[i]}`;
|
||||
namespaces[line] =
|
||||
(line in namespaces ? namespaces[line] : true) && i < ii - 1;
|
||||
}
|
||||
line += ` = ${importName};`;
|
||||
imports[imp] = true;
|
||||
return line;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +76,7 @@ function formatSymbolExport(symbol, namespaces, imports) {
|
||||
*/
|
||||
function generateExports(symbols) {
|
||||
const namespaces = {};
|
||||
const imports = [];
|
||||
const imports = {};
|
||||
const blocks = [];
|
||||
symbols.forEach(function (symbol) {
|
||||
const name = symbol.name;
|
||||
@@ -80,7 +85,10 @@ function generateExports(symbols) {
|
||||
if (imp) {
|
||||
imports[imp] = true;
|
||||
}
|
||||
blocks.push(formatSymbolExport(symbol, namespaces, imports));
|
||||
const line = formatSymbolExport(symbol, namespaces, imports);
|
||||
if (line) {
|
||||
blocks.push(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
const nsdefs = [];
|
||||
|
||||
Reference in New Issue
Block a user