首页 > 其他分享 >[Typescript] TS Monorepo setup

[Typescript] TS Monorepo setup

时间:2022-08-19 19:14:55浏览次数:83  
标签:Typescript package setup TS json api file folder lerna

Yarn workspace

Add following lines to the package.json file

  "workspaces": [
    "packages/*"
  ]

And create folder call packages in the root folder.

Something need to know about:

Any package under packages folder can be located by yarn, you only need to do yarn in root folder, it will find all the package under packages and install dependencies only once

 

Install Workspace dependencies

For example:

yarn add -WD eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser rimraf lerna

-Wflag mean that we want to installl as worksapce dependency.

It is one place for all packages, to prevent we install the same package for multi different package sparately.

 

Run one CLI command for all packages by Lerna

https://lerna.js.org/

yarn add -WD lerna

Create a lerna.json file in root folder

{
  "packages": ["packages/*"],
  "npmClient": "yarn",
  "version": "0.0.1",
  "useWorkspaces": true,
  "nohoist": ["parcel-bundler"]
}

The version here affect all the packages in workscape. So if we want to update all package to the same version, can update "version" just here.

Or we can put:

"version": "independent",

 

Commands:

lerna link

for example in @shlack/utilspackage you add @shlack/typesas dependcy:

{
  "name": "@shlack/utils",
  ...
  "dependencies": {
    "date-fns": "^2.29.1",
    "jest": "^28.1.3",
    "react": "^18.2.0",
    "@shlack/types": "^0.0.1"
  },
}

After you ran lerna linkinside @shlack/utilsfolder, you will see, @shlack/typeshas been locally linked to utils node_modules folder. This allow us to link different version of @shlack/typesinto utils which normal npm linkcannot do.

lerna run *: run the package json script

lerna run clean: cleanup all the linked packages include node_modules all in one go.

lerna run build: it will run the lowest depnedcy first.

lerna bootstrap:similar to yarn install

lerna run test --concurrency 2 --stream: run all tests in each package concurrently and stream the output

lerna run dev --scope '@shlack/ui': just run yarn dev in @shlack/ui project

Scripty

https://github.com/testdouble/scripty#readme

1. In root project, we need to modify package json to tell where to find scripty folder for worksapce

  "scripty": {
    "path": "./scripts/workspace"
  },

2. For example sub-packages, we need to modify package.json to tell where to find scripty folder for package

  "scripty": {
    "path": "../../scripts/packages"
  },

3. The scripts folder looks like this:

// packages
// build.sh
#!/usr/bin/env bash
echo "┏━━━ 

标签:Typescript,package,setup,TS,json,api,file,folder,lerna
From: https://www.cnblogs.com/Answer1215/p/16581382.html

相关文章

  • 1024 [USACO 2007 Mar G]Ranking the Cows 计算总共确定的关系数目 floyd本质+传递闭
    链接:https://ac.nowcoder.com/acm/contest/26077/1024来源:牛客网题目描述EachofFarmerJohn'sNcows(1≤N≤1,000)producesmilkata......
  • No module named 'setuptools_rust' 安装oss2报错
    今天在测试机器上安装oss2报错了:Nomodulenamed'setuptools_rust'经过查询后记录一下OSS2介绍官方文档:https://help.aliyun.com/document_detail/32027.html一句......
  • TSS结构赋值
    在进程切换过程中,需要一个结构体,在保护模式中,称为TSS.。在MenuetOS32系统中,加载应用,也就是进程时,用了如下的方式:;TSSmoveax,cr3......
  • 【Python】使用requests_html解析HTML页面
    1、官网https://pypi.org/project/requests-html/ 2、githubhttps://github.com/kennethreitz/requests-html 3、安装pipinstallrequests-html  4、使用......
  • echarts 数据的各种格式
    数据集数据集(dataset)是专门用来管理数据的组件。虽然每个系列都可以在series.data中设置数据,但是从ECharts4支持数据集开始,更推荐使用数据集来管理数据。因为这样......
  • IO流知识:FilelnputStream单个字节读取文件
    1packageIO;23importjava.io.FileInputStream;4importjava.io.FileNotFoundException;5importjava.io.IOException;6/*7需求:读取"E:\\javaIo\\da......
  • 使用pip 安装requirements.txt中所需要的包
    使用pip安装requirements.txt中所需要的包pipinstall-rrequirements.txt使用 pipfreeze 会输出所有在本地已安装的包(但不包括 pip、wheel、setuptools 等自......
  • vue3+ts项目中基本使用
    import{ref,reactive}from 'vue'  // 引入refreactive   //  ref定义响应式数据中基础数据类型  reactive定义 响应式数据中复杂数据类型  ......
  • ECharts 中的样式简介
    ECharts中的样式简介本文主要是大略概述,用哪些方法,可以在ApacheEChartsTM中设置样式,改变图形元素或者文字的颜色、明暗、大小等。为了让表述更通俗易懂,我们在这里用......
  • echarts 图表容器及大小
    图表容器及大小在快速上手中,我们介绍了初始化ECharts的接口echarts.init。API文档中详细介绍了参数的具体含义,建议理解后再阅读本文。下面,我们就常见的几种使用场景,......