Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename project from thoughtbelt to Belt #32

Merged
merged 5 commits into from
Feb 2, 2024
Merged

Conversation

stevehanson
Copy link

@stevehanson stevehanson commented Feb 2, 2024

Ticket. This is currently in a private Trello board, will be migrating this project to GitHub as the repo becomes public.

  • Rename repo to "belt"
  • Publish npm package "create-belt-app"
  • Update references to thoughtbelt in the code
  • Test the published package to ensure it works as expected
    • npx create-belt-app MyApp then npx belt <cmd> works
    • npx create-belt-app MyApp --yarn (bundles with yarn), then yarn belt <cmd> works
    • [solution in comment] yarn create belt-app MyApp (bundles with yarn), then yarn belt <cmd> works
      • This currently results in an error when run with yarn 1.22.19 (I believe v1 is now deprecated though...) (output below)
    • [solution in comment] bunx create belt-app MyApp, then bunx belt <cmd> works
      • Results in same error as yarn, even references ~/.config/yarn/global 🤔
❌ yarn create belt-app error
success Installed "[email protected]" with binaries:
      - create-belt-app
      - belt


        👖 Belt 👖

Perform project setup and redundant tasks
    without your pants falling down!


/Users/shanson/.config/yarn/global/node_modules/wrap-ansi/index.js:2
const stringWidth = require('string-width');
                    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/shanson/.config/yarn/global/node_modules/string-width/index.js from /Users/shanson/.config/yarn/global/node_modules/wrap-ansi/index.js not supported.
Instead change the require of /Users/shanson/.config/yarn/global/node_modules/string-width/index.js in /Users/shanson/.config/yarn/global/node_modules/wrap-ansi/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/shanson/.config/yarn/global/node_modules/wrap-ansi/index.js:2:21) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v21.1.0
error Command failed.
Exit code: 1
Command: /Users/shanson/.yarn/bin/create-belt-app
Arguments: NewApp0202-yarn-create
Directory: /Users/shanson/dev

@@ -1,13 +1,13 @@
{
"name": "thoughtbelt",
"name": "create-belt-app",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what causes the package to be renamed. After making this change, I published to npm with:

npm version minor
yarn pub:release

@stevehanson
Copy link
Author

Findings with the yarn issue:

  • Belt has a dependency on string-width v4
  • string-width v5 converted to a pure ESM project
  • wrap-ansi package has require('string-width')
  • We get the ERR_REQUIRE_ESM error because string-width v5 is being imported instead of v4, which is specified in package.json and yarn.lock

I believe the issue is caused because Yarn 1 doesn't handle globals well:

Version Conflict Resolution: Yarn 1 doesn't handle version conflicts between global packages gracefully. If two globally installed packages require different versions of the same dependency, Yarn 1 typically installs the version required by the first package and may ignore the dependency requirements of the second package. This can lead to version conflicts and unexpected behavior.

Also, from modern yarn docs:

Use yarn dlx instead of yarn global
Yarn focuses on project management, and managing system-wide packages was deemed to be outside of our scope. As a result, yarn global got removed and needs to be replaced by yarn dlx to run one off scripts.

Conclusions

  • Yarn 1 is not ideal as a global package manager
  • Two options:
    • Instruct users to only use yarn 3+, with the yarn dlx create-belt-app MyApp command
    • Just instruct users to use npx create-belt-app MyApp --yarn. This already works correctly in initiating a new app with dependencies installed with yarn install

I pushed 3b698b0, which updates the instructions to create new apps using npx and the appropriate --yarn/--bun/etc flag.

@stevehanson stevehanson merged commit 0690c13 into main Feb 2, 2024
2 checks passed
@stevehanson stevehanson deleted the rename-project branch February 2, 2024 21:20
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.

1 participant