Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
neezer opened this issue Feb 28, 2016 · 0 comments
Open

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

neezer opened this issue Feb 28, 2016 · 0 comments

Comments

@neezer
Copy link

neezer commented Feb 28, 2016

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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant