wclr / yalc

Work with yarn/npm packages locally like a boss.
MIT License
5.52k stars 146 forks source link

use version 0.0.1 as default #216

Open mathio opened 1 year ago

mathio commented 1 year ago

When no version is provided in package manifest (eg. project is using semantic release) use version 0.0.1 as default

Currently when I run yalc publish in project without version I get an error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (internal/errors.js:322:7)
    at validateString (internal/validators.js:124:11)
    at Object.join (path.js:1148:7)
    at ~/.config/yarn/global/node_modules/yalc/src/copy.js:155:47
    at step (~/.config/yarn/global/node_modules/yalc/src/copy.js:44:23)
    at Object.next (~/.config/yarn/global/node_modules/yalc/src/copy.js:25:53)
    at ~/.config/yarn/global/node_modules/yalc/src/copy.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (~/.config/yarn/global/node_modules/yalc/src/copy.js:15:12)
    at Object.exports.copyPackageToStore (~/.config/yarn/global/node_modules/yalc/src/copy.js:144:58) {
wclr commented 1 year ago

I don't think so (that there should be any default for version), as npm docs say: If you plan to publish your package, the most important things in your package.json are the name and version fields as they will be required.

mathio commented 1 year ago

You are right. However with semantic-release you may omit the version in your package.json because it manages it on its own via git tags (as mentioned in semantic-release FAQ). I use yalc for such package locally. However maybe I could add "version": "0.0.0" to package.json for compatibility 🤔

If you want to enforce version maybe we could update this check:

    if (!pkg.name && pkg.version) {
      console.log(
        'Package manifest',
        packagePath,
        'should contain name and version.'
      )
      return null
    }

To this:

    if (!pkg.name || !pkg.version) {   // <-- check if name or version is missing
      console.log(
        'Package manifest',
        packagePath,
        'should contain name and version.'
      )
      return null
    }

Does that make sense?