vadimdemedes / pastel

🎨 Next.js-like framework for CLIs made with Ink
https://term.ink/pastel
MIT License
2.2k stars 36 forks source link

Divide into two libraries: CLI and Runtime. (stop installing deps such as "parcel-bundler" alongside the generated CLI app) #48

Closed AeonFr closed 3 years ago

AeonFr commented 3 years ago

I believe that including pastel as a dependency includes unnecessary code to the generated CLI app, such as the parcel-bundler dependency.

Saving parcel with --save-dev doesn't work, because there's some runtime code in this library that's needed for the app to run. But the problem is that the runtime is installed alongside all the dev tooling.

As an example:

This is the package.json of the CLI (relevant parts only):

{
    "name": "@filmin/translations",
    "version": "2.0.4",
    "bin": {
        "filmin-translations-cli": "./build/cli.js"
    },
        "devDependencies": {
                "pastel": "^1.1.1",
        },

And this is the package.json of the consumer (relevant parts only):

{
        "name": "CONSUMER",
    "scripts": {
        "fetch-translations": "filmin-translations-cli <args...>"
    },
        "dependencies": {
                "@filmin/translations": "^2.0.4",
        },

Since pastel is a devDependency, the fetch-translations command fails:

❯ npm run fetch-translations
> filmin-translations-cli fetch <args...>

/Users/francisco/Sites/filminweb/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

Error: Cannot find module 'pastel/boot'
Require stack:
- /Users/francisco/Sites/filminweb/node_modules/@filmin/translations/build/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/francisco/Sites/filminweb/node_modules/@filmin/translations/build/cli.js:5:14)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/francisco/Sites/filminweb/node_modules/@filmin/translations/build/cli.js'
  ]
}

In order to prevent the npm run fetch-translations command to fail, I have to move pastel from devDependencies to dependencies. But doing so also causes "CONSUMER" to load libraries such as parcel-bundler, which I believe are not necessary.

As a proposed solution, we could consider splitting pastel into two separate packages, the "dev cli" and the "runtime" (a.k.a. pastel/boot).

Any thoughts?

AeonFr commented 3 years ago

I realized this is a duplicate of #37 , closing it