refactor: replace yarn with pnpm (#3571)

* refactor: replace yarn with pnpm

* chore: install pnpm

* chore: disable cache

* ignore pnpm-lock.yaml

* resolve deps

* setup pnpm
This commit is contained in:
三咲智子 2021-09-23 08:12:37 +08:00 committed by GitHub
parent 53a519457e
commit f9e192535f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 12224 additions and 15235 deletions

View File

@ -2,3 +2,4 @@ node_modules
dist
packages/*/es
packages/*/lib
pnpm-lock.yaml

View File

@ -17,30 +17,32 @@ jobs:
with:
node-version: '16'
- name: Install dependencies
run: yarn bootstrap
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Init docs
run: cd docs && yarn
- name: Install dependencies
run: pnpm bootstrap
- name: Fetch Crowdin token for pulling languages
run: yarn docs:crowdin
run: pnpm docs:crowdin
env:
CROWDIN_TOKEN: ${{secrets.CROWDIN_TOKEN}}
- name: Pull Crowdin translations
run: cd docs && yarn crowdin download
run: cd docs && pnpx crowdin download
- name: Generate common locale
run: yarn docs:gen-locale
run: pnpm docs:gen-locale
- name: Build website
run: yarn docs:build
run: pnpm docs:build
env:
DOC_ENV: production
# - name: Build Indices
# run: yarn build:indices
# run: pnpm build:indices
# env:
# ALGOLIA_KEY: ${{secrets.ALGOLIA_KEY}}

View File

@ -18,20 +18,22 @@ jobs:
node-version: '16'
registry-url: https://registry.npmjs.com/
- name: Install dependencies
run: yarn bootstrap
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Init docs
run: cd docs && yarn
- name: Install dependencies
run: pnpm bootstrap
- name: Generate common locale
run: yarn docs:gen-locale
run: pnpm docs:gen-locale
- name: Build Element Plus
run: sh scripts/build.sh
- name: Build website
run: yarn docs:build
run: pnpm docs:build
env:
DOC_ENV: preview

View File

@ -13,12 +13,16 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Install dependencies
run: yarn bootstrap
run: pnpm bootstrap
- name: Lint
run: yarn lint
run: pnpm lint
- name: Test
run: yarn test
run: pnpm test
publish:
needs: test
@ -29,12 +33,16 @@ jobs:
with:
node-version: '14'
registry-url: https://registry.npmjs.com/
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Get version
run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get git head
run: echo "GIT_HEAD=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Gen npmrc
run: echo "//registry.npmjs.com/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > ./.npmrc
run: echo "//registry.npmjs.com/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" >> ./.npmrc
- name: Build&publish
run: sh ./scripts/publish.sh
env:

View File

@ -19,31 +19,33 @@ jobs:
with:
node-version: '16'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Install dependencies
run: yarn bootstrap
run: pnpm bootstrap
- name: Compile Element Plus
run: sh scripts/build.sh
- name: Init docs
run: cd docs && yarn
- name: Init Crowdin token
run: yarn docs:crowdin
run: pnpm docs:crowdin
env:
CROWDIN_TOKEN: ${{secrets.CROWDIN_TOKEN}}
- name: Upload source files
run: cd docs && yarn crowdin upload sources
run: cd docs && pnpx crowdin upload sources
- name: Pull Crowdin translations
run: cd docs && yarn crowdin download
run: cd docs && pnpx crowdin download
- name: Generate common locale
run: yarn docs:gen-locale
run: pnpm docs:gen-locale
- name: Build website
run: yarn docs:build
run: pnpm docs:build
env:
DOC_ENV: staging

View File

@ -16,14 +16,18 @@ jobs:
node-name: 'Latest'
steps:
- uses: actions/checkout@v2
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 6.15.1
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: 'pnpm'
- name: Install dependencies
run: yarn bootstrap
run: pnpm bootstrap
- name: Lint
run: yarn lint
run: pnpm lint
- name: Test
run: yarn test
run: pnpm test

5
.gitignore vendored
View File

@ -3,10 +3,7 @@
# Package Manager
node_modules
lerna-debug.json
lerna-debug.log
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# System
.DS_Store

1
.npmrc
View File

@ -0,0 +1 @@
shamefully-hoist = true

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
v16

View File

@ -3,3 +3,4 @@ node_modules
packages/*/es
packages/*/lib
coverage
pnpm-lock.yaml

View File

@ -5,12 +5,12 @@ Here are the problems that are easy to encounter in development.
## If you encounter dependency related issues
```bash
yarn bootstrap
pnpm bootstrap
```
## Test suite failed to run (jest)
Can not run `yarn test xxx`
Can not run `pnpm test xxx`
```bash
rm -rf dist

View File

@ -77,17 +77,17 @@ You can find the breaking change list here: [Breaking Change List](https://githu
With command
```bash
$ yarn bootstrap
$ pnpm bootstrap
```
the project will install all dependencies and run `lerna bootstrap` to initialize the project
the project will install all dependencies
## Website preview
With command
```bash
$ yarn docs:dev
$ pnpm docs:dev
```
the project will launch website for you to preview all existing component
@ -97,7 +97,7 @@ the project will launch website for you to preview all existing component
1. With command
```shell
$ yarn dev
$ pnpm dev
```
will start the local development environment
@ -132,7 +132,7 @@ Modify `play.vue` file per your needs to get things work.
With command
```bash
$ yarn gen component-name
$ pnpm gen component-name
```
Note the `component-name` must be in `kebab-case`, combining words by replacing each space with a dash.
@ -142,7 +142,7 @@ Note the `component-name` must be in `kebab-case`, combining words by replacing
With command
```bash
yarn cz
pnpm cz
```
Example

View File

@ -63,6 +63,7 @@ function pathsRewriter(id: string) {
async function buildComponents() {
const componentPaths = await getComponents()
const external = await getExternals({ full: false })
const builds = componentPaths.map(
async ({ path: p, name: componentName }) => {
@ -72,7 +73,7 @@ async function buildComponents() {
const rollupConfig = {
input: entry,
plugins,
external: getExternals({ full: false }),
external,
}
const bundle = await rollup.rollup(rollupConfig)

View File

@ -30,7 +30,7 @@ import { getExternals } from './utils'
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
external: getExternals({ full: true }),
external: await getExternals({ full: true }),
}
console.log(chalk.cyan('Start generating full bundle'))

View File

@ -45,6 +45,7 @@ const genVueTypes = async (
'tests',
'css',
'.DS_Store',
'node_modules',
]
const filePaths = globSync('**/*', {
cwd: root,

View File

@ -1,67 +0,0 @@
import path from 'path'
import vue from 'rollup-plugin-vue'
import css from 'rollup-plugin-css-only'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import esbuild from 'rollup-plugin-esbuild'
import { getPackagesSync } from '@lerna/project'
import pkg from '../package.json'
const noElPrefixFile = /(utils|directives|hooks|locale)/
const getOutFile = (name, dir = 'lib') => {
const compName = name.split('@element-plus/')[1]
if (noElPrefixFile.test(name)) {
return `${dir}/${compName}/index.js`
}
return `${dir}/el-${compName}/index.js`
}
const deps = Object.keys(pkg.dependencies)
const inputs = getPackagesSync()
.map((pkg) => pkg.name)
.filter((name) => name.includes('@element-plus') && !name.includes('utils'))
export default inputs.map((name: string) => ({
input: path.resolve(
__dirname,
`../packages/${name.split('@element-plus/')[1]}/index.ts`
),
output: [
{
format: 'es',
file: getOutFile(name, 'es'),
paths(id: string) {
if (/^@element-plus/.test(id)) {
if (noElPrefixFile.test(id)) return id.replace('@element-plus', '..')
return id.replace('@element-plus/', '../el-')
}
},
},
{
format: 'cjs',
file: getOutFile(name, 'lib'),
exports: 'named',
paths(id: string) {
if (/^@element-plus/.test(id)) {
if (noElPrefixFile.test(id)) return id.replace('@element-plus', '..')
return id.replace('@element-plus/', '../el-')
}
},
},
],
plugins: [
css(),
vue({
target: 'browser',
// css: false,
}),
nodeResolve(),
esbuild(),
],
external(id: string) {
return (
/^vue/.test(id) ||
/^@element-plus/.test(id) ||
deps.some((k) => new RegExp(`^${k}`).test(id))
)
},
}))

View File

@ -1,9 +1,9 @@
import path from 'path'
import os from 'os'
import { getPackagesSync } from '@lerna/project'
import getWorkspacePackages from '@pnpm/find-workspace-packages'
import chalk from 'chalk'
import { compRoot } from './paths'
import { compRoot, projRoot } from './paths'
export const getDeps = (pkgPath: string): string[] => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
@ -15,20 +15,25 @@ export const getDeps = (pkgPath: string): string[] => {
export const getCpuCount = () => os.cpus().length
export const getPkgs = (): { name: string }[] => getPackagesSync()
export const getPkgs = () => getWorkspacePackages(projRoot)
export const getExternals = (options: { full: boolean }) => (id: string) => {
const packages: string[] = ['vue']
if (!options.full) {
const compPkg = path.resolve(compRoot, './package.json')
const monoPackages = getPkgs().map((pkg) => pkg.name)
const depPackages = getDeps(compPkg)
packages.push('@vue', ...monoPackages, ...depPackages)
export const getExternals = async (options: { full: boolean }) => {
const monoPackages = (await getPkgs())
.map((pkg) => pkg.manifest.name)
.filter((name): name is string => !!name)
return (id: string) => {
const packages: string[] = ['vue']
if (!options.full) {
const compPkg = path.resolve(compRoot, './package.json')
const depPackages = getDeps(compPkg)
packages.push('@vue', ...monoPackages, ...depPackages)
}
return [...new Set(packages)].some(
(pkg) => id === pkg || id.startsWith(`${pkg}/`)
)
}
return [...new Set(packages)].some(
(pkg) => id === pkg || id.startsWith(`${pkg}/`)
)
}
export function yellow(str: string) {

View File

@ -1,23 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const { createRequire } = require('module')
const {
default: getWorkspacePackages,
} = require('@pnpm/find-workspace-packages')
function getPackages(context) {
return Promise.resolve()
.then(() => {
const ctx = context || {}
const cwd = ctx.cwd || process.cwd()
const Project = createRequire(path.resolve(cwd, 'noop.js'))(
'@lerna/project'
)
const project = new Project(cwd)
return project.getPackages()
})
.then((packages) => {
return packages
.map((pkg) => pkg.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name))
})
async function getPackages(context) {
const ctx = context || {}
const cwd = ctx.cwd || process.cwd()
const packages = await getWorkspacePackages(cwd)
return packages
.map((pkg) => pkg.manifest.name)
.filter((name) => !!name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name))
}
const scopes = [

View File

@ -8,7 +8,7 @@
},
"dependencies": {
"@vueuse/core": "^6.4.0",
"element-plus": "latest",
"element-plus": "npm:element-plus@latest",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0"
},

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ module.exports = {
},
},
},
testPathIgnorePatterns: ['/node_modules/', 'dist'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.vue$': 'vue-jest',

View File

@ -1,6 +0,0 @@
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}

View File

@ -10,7 +10,7 @@
"gen": "bash ./scripts/gc.sh",
"gen:version": "esno build/gen-version.ts",
"update:version": "esno build/update-version.ts",
"bootstrap": "yarn --frozen-lockfile && npx lerna bootstrap && cd docs && yarn",
"bootstrap": "pnpm i",
"clean:lib": "rimraf lib && rimraf es && rimraf dist",
"build": "sh scripts/build.sh",
"build:helper": "esno build/build-helper.ts",
@ -18,23 +18,23 @@
"build:comps": "rimraf dist/components && esno build/components.ts",
"build:style": "gulp --cwd ./build",
"build:prod": "sh scripts/publish.sh",
"build:directives": "cd packages/directives && yarn clean && yarn build",
"build:hooks": "cd packages/hooks && yarn clean && yarn build",
"build:locale": "cd packages/locale && yarn clean && yarn build",
"build:theme": "cd packages/theme-chalk && yarn clean && yarn build",
"build:utils": "cd packages/utils && yarn clean && yarn build",
"build:tokens": "cd packages/tokens && yarn clean && yarn build",
"build:directives": "cd packages/directives && pnpm clean && pnpm build",
"build:hooks": "cd packages/hooks && pnpm clean && pnpm build",
"build:locale": "cd packages/locale && pnpm clean && pnpm build",
"build:theme": "cd packages/theme-chalk && pnpm clean && pnpm build",
"build:utils": "cd packages/utils && pnpm clean && pnpm build",
"build:tokens": "cd packages/tokens && pnpm clean && pnpm build",
"build:full-bundle": "esno build/full-bundle.ts",
"format": "prettier --write .",
"lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx --max-warnings 0 && prettier --check .",
"lint:fix": "eslint --fix . --ext .vue,.js,.ts,.jsx,.tsx && prettier --write .",
"docs:dev": "sh ./scripts/ifBuild.sh && yarn docs:gen-locale && cd docs && yarn dev",
"docs:build": "cd docs && yarn build",
"docs:serve": "cd docs && yarn serve",
"docs:dev": "sh ./scripts/ifBuild.sh && pnpm docs:gen-locale && cd docs && pnpm dev",
"docs:build": "cd docs && pnpm build",
"docs:serve": "cd docs && pnpm serve",
"docs:gen-locale": "rimraf docs/.vitepress/i18n && esno build/crowdin-generate.ts",
"docs:crowdin": "esno build/crowdin-credentials.ts",
"prepare": "husky install",
"postinstall": "yarn gen:version"
"postinstall": "pnpm gen:version"
},
"config": {
"commitizen": {
@ -57,15 +57,23 @@
"vue": "^3.2.0"
},
"dependencies": {
"@element-plus/components": "workspace:*",
"@element-plus/directives": "workspace:*",
"@element-plus/hooks": "workspace:*",
"@element-plus/icons": "^0.0.11",
"@element-plus/locale": "workspace:*",
"@element-plus/test-utils": "workspace:*",
"@element-plus/theme-chalk": "workspace:*",
"@element-plus/tokens": "workspace:*",
"@element-plus/utils": "workspace:*",
"@popperjs/core": "^2.10.1",
"@vueuse/core": "~6.1.0",
"async-validator": "^3.4.0",
"dayjs": "1.x",
"lodash": "^4.17.21",
"memoize-one": "^5.2.1",
"normalize-wheel": "^1.0.1",
"resize-observer-polyfill": "^1.5.1",
"memoize-one": "^5.2.1"
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
@ -76,6 +84,8 @@
"@babel/preset-typescript": "^7.15.0",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@pnpm/find-workspace-packages": "^3.1.13",
"@pnpm/logger": "^4.0.0",
"@rollup/plugin-alias": "^3.1.5",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
@ -89,6 +99,7 @@
"@vue/babel-plugin-jsx": "^1.0.7",
"@vue/compiler-sfc": "^3.2.8",
"@vue/component-compiler-utils": "^3.2.2",
"@vue/test-utils": "2.0.0-beta.4",
"algoliasearch": "^4.10.5",
"babel-jest": "^26.3.0",
"babel-plugin-lodash": "^3.3.4",
@ -113,7 +124,6 @@
"gulp-typescript": "^6.0.0-alpha.1",
"husky": "^7.0.2",
"jest": "^26.6.3",
"lerna": "^3.22.1",
"lint-staged": "^11.1.2",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",

View File

@ -3,12 +3,7 @@
"version": "0.0.5",
"description": "all components are settled here",
"dependencies": {
"@element-plus/directives": "^0.0.5",
"@element-plus/hooks": "^0.0.5",
"@element-plus/icons": "^0.0.11",
"@element-plus/theme-chalk": "^0.0.5",
"@element-plus/tokens": "^0.0.5",
"@element-plus/utils": "^0.0.5",
"@popperjs/core": "^2.10.1",
"@vueuse/core": "~6.1.0",
"async-validator": "^3.4.0",

View File

@ -15,12 +15,9 @@
"build": "gulp build"
},
"dependencies": {
"@element-plus/utils": "^0.0.5",
"normalize-wheel": "^1.0.1"
},
"devDependencies": {
"@element-plus/test-utils": "^0.0.5",
"@vue/test-utils": "^2.0.0-beta.3",
"chalk": "^4.1.2",
"gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1",

View File

@ -33,7 +33,6 @@
"vue": "^3.2.0"
},
"dependencies": {
"@element-plus/icons": "^0.0.11",
"@popperjs/core": "^2.10.1",
"@vueuse/core": "~6.1.0",
"async-validator": "^3.4.0",
@ -42,9 +41,7 @@
"normalize-wheel": "^1.0.1",
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"@element-plus/test-utils": "^0.0.5"
},
"devDependencies": {},
"vetur": {
"tags": "tags.json",
"attributes": "attributes.json"

View File

@ -16,15 +16,10 @@
"build": "gulp build"
},
"dependencies": {
"@element-plus/directives": "^0.0.5",
"@element-plus/locale": "^0.0.5",
"@element-plus/utils": "^0.0.5",
"@popperjs/core": "^2.10.1",
"@vueuse/core": "~6.1.0"
},
"devDependencies": {
"@element-plus/test-utils": "^0.0.5",
"@vue/test-utils": "^2.0.0-beta.3",
"chalk": "^4.1.2",
"gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1",

View File

@ -16,9 +16,7 @@
"dayjs": "1.x"
},
"devDependencies": {
"@element-plus/test-utils": "^0.0.5",
"@types/gulp": "^4.0.9",
"@vue/test-utils": "^2.0.0-beta.3",
"chalk": "^4.1.2",
"gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1",

View File

@ -5,8 +5,6 @@
"main": "dist/index.js",
"license": "MIT",
"dependencies": {
"@vue/test-utils": "^2.0.0-beta.3",
"lodash": "^4.17.21",
"vue": "^3.2.0"
"lodash": "^4.17.21"
}
}

View File

@ -21,7 +21,6 @@
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"@vue/test-utils": "^2.0.0-beta.3",
"chalk": "^4.1.2",
"gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1",

View File

@ -15,7 +15,6 @@
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"@vue/test-utils": "^2.0.0-beta.3",
"chalk": "^4.1.2",
"gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1",

7
play/package.json Normal file
View File

@ -0,0 +1,7 @@
{
"private": true,
"scripts": {
"dev": "vite"
},
"dependencies": {}
}

View File

@ -1,6 +1,6 @@
import './vite.init'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import './vite.init'
export default defineConfig({
plugins: [vue()],

12070
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

7
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,7 @@
#
packages:
- 'packages/**'
- '!packages/__mocks__'
- docs
- play
- '!**/__tests__/**'

View File

@ -2,30 +2,30 @@
set -e
yarn clean:lib
pnpm clean:lib
# build all packages in case of error
# build components
yarn build:comps
pnpm build:comps
rsync -a dist/types/components/ dist/element-plus/es/components/
rsync -a dist/types/components/ dist/element-plus/lib/components/
# build style
yarn build:style
pnpm build:style
yarn build:theme
yarn build:locale
yarn build:utils
yarn build:hooks
yarn build:directives
yarn build:tokens
yarn build:full-bundle
pnpm build:theme
pnpm build:locale
pnpm build:utils
pnpm build:hooks
pnpm build:directives
pnpm build:tokens
pnpm build:full-bundle
rsync -a dist/entry/types/ dist/element-plus/es/
rsync -a dist/entry/types/ dist/element-plus/lib/
yarn build:helper
pnpm build:helper
echo "copy index.css"
cp dist/element-plus/theme-chalk/index.css dist/element-plus/dist/index.css

View File

@ -7,7 +7,7 @@ FILE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../packages" && pwd)
re="[[:space:]]+"
if [ "$#" -ne 1 ] || [[ $NAME =~ $re ]] || [ "$NAME" == "" ]; then
echo "Usage: yarn gc \${name} with no space"
echo "Usage: pnpm gc \${name} with no space"
exit 1
fi

View File

@ -2,9 +2,8 @@
set -e
yarn bootstrap
yarn update:version
yarn gen:version
pnpm bootstrap
pnpm update:version
sh scripts/build.sh

13526
yarn.lock

File diff suppressed because it is too large Load Diff