Skip to content

Does not honor package config option in esdoc.json #4

@neezer

Description

@neezer

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions