-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
I want to have my import paths read with the actual values used by the programmers when consuming my library. Presently, the plugin always reads in my package name from ./package.json, even when I set package: null in my esdoc.json file.
This is the problem:
// Plugin.js
let packagePath = './package.json';
// ...
export function onHandleConfig(ev) {
if (ev.data.config.package) packagePath = ev.data.config.package;
}
// ...
export function onHandleTag(ev) {
let packageName = '';
try {
const packageJSON = fs.readFileSync(packagePath).toString();
const packageObj = JSON.parse(packageJSON);
packageName = packageObj.name;
if(packageObj.main) mainPath = packageObj.main;
} catch (e) {
// ignore
}
// ...
if (importPath === mainPath) {
tag.importPath = packageName;
} else if (packageName) { // <==== always true despite my setting `package: null`
tag.importPath = `${packageName}/${importPath}`;
} else {
tag.importPath = importPath;
}
}I can get my desired behavior by changing onHandleConfig to this:
export function onHandleConfig(ev) {
packagePath = ev.data.config.package;
}Then, package: null in esdoc.json will nullify the default and cause the final else clause above to actually get hit. Then, in the plugin configuration, I can simply do this:
{
"name": "esdoc-importpath-plugin",
"option": {
"replaces": [{ "from": "^APP_NAME/js/", "to": "" }]
}
}If there's another way of accomplishing this without setting package: null, I'm all ears, but I really want my import statements in my documentation to read like
import { func } from 'lib/funcs';and not
import { func } from 'APP_NAME/js/lib/funcs';Metadata
Metadata
Assignees
Labels
No labels