Skip to content

Commit

Permalink
feat: @yarn-tool/fix-ws-pkgs-link 修正 node_modules 內的連結
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jul 23, 2021
1 parent f642c0e commit f1af663
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 160 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"@types/level": "^6.0.0",
"@types/lodash": "^4.14.171",
"@types/micromatch": "^4.0.2",
"@types/mocha": "^8.2.3",
"@types/node": "^16.3.3",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.1",
"@types/npm-package-arg": "^6.1.1",
"@types/npm-packlist": "^1.1.2",
"@types/parse-git-config": "^3.0.1",
Expand All @@ -87,7 +87,7 @@
"jest": "^27.0.6",
"jest-console": "^0.1.0",
"mocha": "^9.0.2",
"ts-jest": "^27.0.3"
"ts-jest": "^27.0.4"
},
"peerDependencies": {
"lerna": "^4"
Expand Down
6 changes: 6 additions & 0 deletions packages/@yarn-tool/fix-ws-links/bin/fix-ws-links.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/@yarn-tool/fix-ws-links/bin/fix-ws-links.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

import fixYarnWorkspaceLinks from '../index';
import fixWorkspacesPackageLinks from '@yarn-tool/fix-ws-pkgs-link';

let cwd = process.cwd();

Expand All @@ -9,3 +10,11 @@ fixYarnWorkspaceLinks(cwd, {
verbose: true,
runYarnAfter: process.argv.includes('--runYarnAfter'),
})

let wsp = fixWorkspacesPackageLinks(cwd)

if (wsp.length)
{
console.log(`node_modules links fixed`)
wsp.forEach(r => r.name)
}
1 change: 1 addition & 0 deletions packages/@yarn-tool/fix-ws-links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"tsc:esm": "tsc -p tsconfig.esm.json"
},
"dependencies": {
"@yarn-tool/fix-ws-pkgs-link": "^1.0.0",
"@yarn-tool/node-modules": "^1.0.48",
"cross-spawn-extra": "^2.1.0",
"debug-color2": "^1.2.7",
Expand Down
137 changes: 137 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

/.*/
.idea
node_modules
~ci.list.txt
~ci.log.txt
~ci.errors.txt
*.stackdump
*.bak
*.old
package-lock.json
test/**/*.js
test/**/*.d.ts
test/*.js
test/*.d.ts
test/temp*
test/**/*.map
tests/**/*.js
tests/**/*.d.ts
tests/*.js
tests/*.d.ts
tests/temp*
tests/**/*.map
bin/*.d.ts
bin/**/*.d.ts
/packages/*/bin/*.d.ts
/packages/*/test/**/*.js
/packages/*/test/**/*.d.ts
/packages/*/test/*.js
/packages/*/test/*.d.ts
/packages/*/test/temp*
/packages/*/tests/**/*.js
/packages/*/tests/**/*.d.ts
/packages/*/tests/*.js
/packages/*/tests/*.d.ts
/packages/*/tests/temp*
**/node_modules
*.tgz
/tsconfig.json.tpl
/.eslintrc.json.tpl
!tsconfig.json
!.eslintrc.json
yarn-error.log
*.log
.git
yarn.lock
.env.local
.env.*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.vue.js
*.vue.d.ts
*.vue.js.map
vue.config.d.ts
vue.config.js.map
.nyc_output
coverage
/*.tpl
!.forestry
!.vuepress
!.github
!.gitee
!.gitlab
.git

*.tsbuildinfo
tsconfig.esm.json.tpl

.browserslistrc
.nvmrc

/.eslintignore
/package.d.ts
.nycrc
.mocharc.yml
#jest.config.js
node_modules/.cache
.yarn-integrity
jest.config.d.ts
jest.config.js.map
/report.*.json
*.js.map
/now.json
.nyc_output
.coverage-cache
.reify-cache
*.spec.d.ts
*.spec.js
.nowignore
*/**/.github
!/.github
!npm-shrinkwrap.json
*.stat
.vercel
/test/tsconfig.json.tpl
/tsconfig.json.tpl
86 changes: 86 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/.pnp
.pnp.js
.idea
~ci.list.txt
~ci.log.txt
~ci.errors.txt
*.stackdump
*.bak
*.old
*.log
tsconfig.json
package-lock.json
test
.github
.gitkeep
/.*/
/.*
tests
/~*
__test__
__tests__
node_modules
/node_modules/
**/node_modules/
*.ts
!*.d.ts
/bin/**/*.d.ts
/bin/*.d.ts
*.tgz
/tsconfig.json.tpl
yarn-error.log
.git
yarn.lock
.env.local
.env.*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.vue.js
*.vue.d.ts
*.vue.js.map
.nyc_output
coverage
/*.tpl
webpack.config.js
vue.config.js
/jestconfig.json
/tslint.json
.git
webpack.*.config.js
webpack.*.config.d.ts
webpack.*.config.js.map
webpack.*.config.ts
karma.conf.js
/_config.yml
intellij-style-guide.xml
jest.config.js
*.tsbuildinfo
tsconfig.*.json
tsconfig.esm.json.tpl
/package.d.ts
.mocharc.yml
jest.config.js
jest.config.*
/report.*.json
now.json
/Makefile
*.spec.d.ts
*.spec.js
*.spec.ts
*.spec.tsx
__mocks__
__tests__
__snapshots__
*.snap
npm-shrinkwrap.json
/example/
*.stat
.vercel
tsdx.config.js
12 changes: 12 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# README.md



## install

```bash
yarn add @yarn-tool/fix-ws-pkgs-link
yarn-tool add @yarn-tool/fix-ws-pkgs-link
yt add @yarn-tool/fix-ws-pkgs-link
```

2 changes: 2 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function fixWorkspacesPackageLinks(cwd?: string): import("ws-pkg-list").IListableRow[];
export default fixWorkspacesPackageLinks;
30 changes: 30 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions packages/@yarn-tool/fix-ws-pkgs-link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { wsPkgListable } from 'ws-pkg-list/lib/listable';
import { findRootLazy } from '@yarn-tool/find-root';
import { getModulesDir } from '@yarn-tool/node-modules/lib/util';
import { ensureSymlinkSync, lstatSync, pathExists, pathExistsSync, realpathSync, unlinkSync, renameSync } from 'fs-extra';
import { join } from 'path';
import { fsSameRealpath } from 'path-is-same';
import { isSymbolicLinkSync } from 'fs-stat';

export function fixWorkspacesPackageLinks(cwd?: string)
{
const rootData = findRootLazy({
cwd,
});

const node_modules = getModulesDir(rootData.root);

const listable = wsPkgListable(rootData.root);

return listable.filter((entry) => {

let target = join(node_modules, entry.name);

if (!isSymbolicLinkSync(target) && !fsSameRealpath(target, entry.location))
{
if (pathExistsSync(target))
{
renameSync(target, target + '.old_' + Math.random())
}

ensureSymlinkSync(entry.location, target);

return true
}
})
}

export default fixWorkspacesPackageLinks
Loading

0 comments on commit f1af663

Please sign in to comment.