tmcw / dx-spec

Issue (and spec) repository for the development of a spec that would succeed JSDoc.
27 stars 0 forks source link

Modules #6

Open tmcw opened 6 years ago

tmcw commented 6 years ago

JSDoc has its own idea of modules, which I've discussed before - essentially

I should, though, try to figure out whether:

jamiebuilds commented 6 years ago

It makes most sense to me to limit the spec to what JS provides for modules (not including commonjs). I don't see a lot of value in doing anything else.

As for membership of objects, I think this is why JS needs a namespaces concept like seen in TypeScript.

autra commented 6 years ago

It makes most sense to me to limit the spec to what JS provides for modules

+1

Actual modules, like things you install with npm and include with require or import

I'd just say "like things you include with import". Because for the example of npm, a package is not one module. It's as many modules as there are files (you don't need to use the entrypoint defined in the package.json, you can import individual files if you want).

So, as a lib dev, I'd expect a dx compliant engine to find and document all the reachable modules from the entrypoints I invoked it with (entrypoints could be a single file, or actually a directory to recursively scan if I expect someone would want to import some of my package js files individually).

Optionally, it could discover my entrypoints from package.json and document its structure (with links to individual modules), but I'm pretty sure it should not be in the spec, as it is tied to an implementation detail of npm.

So if I give a dx compliant doc engine this entryPoint:

// Main.js

export * as myfoo  from 'Core/reticulation/foo'; // all named export, but not the default
export { helloMethod } from 'Core/greetings/world';
export Bar from 'module1/bar'; // default export

I'd expect the toc to be something like:

My Lib

Core

  • reticulation/foo as myfoo
    • namedExport1
    • namedExport2
    • basically all the export stuff in foo.js
  • greetings/world
    • helloMethod

module1

  • bar
    • default as Bar

Nesting levels is up to individual engines. I'd like it to be configurable, so reticulation could start a new subsection if needed or so I could have a flat structure. That being said, I think the spec should require to have the full path somehow (instead of just the "leaf" name), because as a user, I need to know how to import foo for instance (would be import something from 'my-lib/Core/reticulation/foo'). Not sure if this is clear :-)

Last but not least, the engine should detect the type of the exports and document them in individual file pages. So that:

function helloWorld() {}
export helloWorld;

or

export function helloWorld() {}

or maybe even

var helloWorld = function() {}

would yield the same doc, because essentially they are the same from the importing side POV. dx engines should know that it is a function in this trivial case (inference might not be always possible). Not sure if this should be a MUST or a SHOULD though :-)

WDYT of this?