Skip to content

Conversation

@mathio
Copy link

@mathio mathio commented Mar 15, 2023

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) {

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

wclr commented Mar 22, 2023

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
Copy link
Author

mathio commented Mar 23, 2023

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?

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

Successfully merging this pull request may close these issues.

2 participants