j-d-carmichael / boats

Beautiful Open Api Template System
MIT License
57 stars 8 forks source link

Programmatic use not working #87

Closed Papooch closed 2 months ago

Papooch commented 8 months ago

Describe the bug When trying to import boats programmatically, I get the following error:

Error: Cannot find module '<path-to-repo>/node_modules/boats/src/index.js'. Please verify that the package.json has a valid "main" entry

To Reproduce include import boats from 'boats' (or the CJS equivalent) in a source file and run it.

Expected behavior As per the docs

You can also use BOATS programmatically, just require (import if you are using a bundler) the lib into your project.

I would expect this to work and provide some programmatic API.

j-d-carmichael commented 8 months ago

Hi,

Could you show some code of how you're importing?

Thanks, John

p-mcgowan commented 8 months ago

the issue is main in package.json doesn't point to build/src but src, which doesn't exist after an install.

steps to repro

mkdir test
cd test
npm init --yes
npm i boats
node -p 'require("boats")'
p-mcgowan commented 8 months ago

although that won't fix it anyway - it looks like the index exports the default key from 4 files, so it won't work anyway.

You would have to do something like require('boats/build/src/Template').default in order to use those files

j-d-carmichael commented 7 months ago

Dang!

I'm pretty slammed at the moment so not sure i have the time until next month... PR would be very welcomed :)

j-d-carmichael commented 2 months ago

@Papooch I've decided as I don't have time to work on this feature to instead remove programmatic use.

If you would like to expose boats in a programmatic way a PR would be welcomed.

The section of boats to expose would be: https://github.com/j-d-carmichael/boats/blob/main/src/cli.ts#L55 to https://github.com/j-d-carmichael/boats/blob/main/src/cli.ts#L77

Ideally, the cli.ts file would call a new function or class named "boats" and the package.json would both export the types and the said file.

I would imagine something like added to the package json file:

  "main": "build/src/boats.js",
  "typings": "build/src/boats.d.ts",

For now though, there is no longer an export and I will close this PR.