-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: add npm init <create-pkg-name> command #20303
Conversation
npm init <create-pkg-name>.
lib/init.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The promise returned by npx is a vanilla promise (not a bluebird one) so lacks the nodeify helper.
The promise then(cb) of npx is executed before the npm init command finishes which causes the process to exit. There is a PR open on npx (zkat/npx#172) to return a promise so the cb will be executed after npx runs its command.
lib/init.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
βοΈ That regexp is the key yarn/npm interoperable bit.
|
Any guidance on unit tests would be appreciated. |
lib/init.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π In addition to following yarn's rules,
name expansion also supports transforming @scope into @scope/create.
|
@jdalton as far as unit tests go, I would mock |
Cool! |
|
The |
2e76172 to
fe31e66
Compare
|
Added tests! |
lib/init.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated. You should document this feature in doc/cli/npm-init.md as well.
package.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed -- I've updated libnpx
|
Added docs and removed the |
|
Thank you π |
| 'rb': 'rebuild', | ||
| 'list': 'ls', | ||
| 'ln': 'link', | ||
| 'create': 'init', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this alias π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks goes to @zkat π
The
npm init <create-pkg-name>command willnpm init(e.g.
npm init esmwill translate theesmarg tocreate-esm)npx create-esmvialibnpxRelated to zkat/npx#167.
Update:
Okay!
Basic functionality exists in the PR now (thanks to @zkat for getting me unstuck).
At the moment I defer to
npxfor parsing args and handling installs, which means it follows its rules on fresh installing packages and all that.npxdoes all the heavy lifting here so this tie-in is pretty minimal.I based
npxinvocation onbin/npx-cli.js. The first arg beyondnpm init __is used as the initer to resolve. Additional arguments are forwarded to the initer.I used
argspassed toinit()as the initial feature gate because it was provided info. Theargsarray lacks extra flags though. So, for saynpm init esm -ytheargsarray toinit()is['esm']. This is whyprocess.argvis used to forward additional args.Erroring is handled by
npx. So for invalid packages the result looks likeUpdate:
Added
createas an alias ofinitand addedinnitas an affordance ofinit.