npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mose-ml-cli

v1.0.0

Published

``` lerna init ```

Downloads

2

Readme

lerna 使用

初始化 lerna 管理包的项目

lerna init
  • 会创建 packages 目录
  • git 管理
  • 创建 lerna.json

直接创建自定义的包

  • lerna create @mose-ml-cli/core packages => 在 packages 目录下,创建 group 组名为 mose-ml-cli 的名称为 core 的包

安装依赖

  • 会为 packages 下的每个包安装 axios
lerna add axios #
lerna notice cli v4.0.0
lerna info Adding axios in 2 packages
lerna info Bootstrapping 2 packages
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 2 packages

清除 packages 中包的所有依赖项

  • 删除每个 packages 下的包中的依赖 lerna clean, 就把 node_modules 目录删除了,但是没有删除每个包中 package.json 中的依赖列表, 如果不需要依赖,手工删除即可
"dependencies": {
    "axios": "^0.21.1"
}

针对某个特定的包安装特定的依赖

  • 比如 core 这个包, 安装 axios
lerna add axios packages/core
  • 如下报错是因为, core 目录下的 package.json 中的 dependencies 已经存在了 axios,需要手工删除,

  • 测试这个时发现,其他的包的依赖也必须删除,即 utils/package.json 中的 dependencies 中对应的依赖包也必须删除

bogon:mose-ml-cli sanfeng$ lerna add axios packages/core
info cli using local version of lerna
lerna notice cli v4.0.0
lerna WARN No packages found where axios can be added.
  • 针对某个包安装依赖
lerna add mocha packages/core -D

lerna bootstrap

  • 如果 packages 中每个包中的 package.json 中有依赖,如果之前 lerna clean 了(即删除了 node_modules,但是没有清空 dependencies),会自动安装依赖的库(如 axios)

lerna link

  • 自动创建 packages 中所有包之间相互依赖的软连接,如果没有依赖是没有效果的
  • 按照管理, 修改 utils/lib 下的文件名 从 utils.js => index.js
    • 修改 package.json 的 main 入口文件
        "main": "lib/utils.js",
  • 手动在 core 的 package.json 中增加依赖
    "dependencies": {
        "@mose-ml-cli/utils": "^1.0.0"
    }

lerna add 安装的依赖是已经发布的包 > lerna link 是连接项目中使用的包,对于已经上线的包通过 add 安装后就不需要使用 link 安装了。

cd \@mose-ml-cli/
bogon:@mose-ml-cli sanfeng$ ls -l
total 0
lrwxr-xr-x  1 sanfeng  staff  14  7  3 22:08 utils -> ../../../utils

lerna exec

**--scope: 指定哪个包的范围, **

@mose-ml-cli/core 是某个包中package.json中name属性

lerna exec --scope @mose-ml-cli/core -- rm -rf node_modules

lerna run 执行npm中script中的命令

lerna run test  # 执行所有包的npm test的命令
lerna run test @mose-ml-cli/core  # 执行指定包的

package.json中的配置

"scripts": {
    "test": "echo \"Error: run tests from core\""
},

lerna发布上线

  1. lerna version
  • 每次发布上线,都希望package.json中的version都需要增加一位 1.0.1
 通过使用lerna version 增加版本号
 需要将代码提交
λ lerna version
lerna notice cli v4.0.0
lerna info current version 1.0.0
lerna info Assuming all packages changed
? Select a new version (currently 1.0.0) (Use arrow keys)
> Patch (1.0.1)
  Minor (1.1.0)
  Major (2.0.0)
  Prepatch (1.0.1-alpha.0)
  Preminor (1.1.0-alpha.0)
  Premajor (2.0.0-alpha.0)
  Custom Prerelease
  Custom Version

因为1.0.0还没有创建,暂时先不创建1.0.1这个版本

  1. lerna changed

和上个版本相比有哪些版本发生了变更

lerna changed
lerna notice cli v4.0.0
lerna info Assuming all packages changed
@mose-ml-cli/core
@mose-ml-cli/utils
lerna success found 2 packages ready to publish
  1. lerna diff
λ lerna diff
lerna notice cli v4.0.0
diff --git a/packages/core/package.json b/packages/core/package.json
index ca9808b..01b2e6d 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -17,7 +17,7 @@
     "registry": "https://registry.npm.taobao.org"
   },
   "scripts": {
-    "test": "echo \"Error: run tests from root\" && exit 1"
+    "test": "echo \"Error: run tests from core\""
   },
   "dependencies": {
     "@mose-ml-cli/utils": "^1.0.0",
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 1e1d488..fc61628 100644