yarn-berry-deduplicate 2.0.0 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS.md +30 -0
- package/CHANGELOG.md +211 -22
- package/CODE_OF_CONDUCT.md +35 -18
- package/LICENSE.md +160 -0
- package/README.md +113 -66
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +95 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +162 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -24
- package/.eslintrc.js +0 -17
- package/.prettierrc.js +0 -10
- package/AUTHORS +0 -22
- package/LICENSE.txt +0 -202
- package/cli.js +0 -87
- package/index.js +0 -225
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yarn-berry-deduplicate",
|
|
3
|
-
"version": "
|
|
4
|
-
"bin": "./cli.js",
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "6.0.2",
|
|
4
|
+
"bin": "./dist/cli.js",
|
|
5
|
+
"description": "Deduplication tool for yarn.lock files",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"yarn",
|
|
8
8
|
"yarn.lock",
|
|
@@ -13,41 +13,67 @@
|
|
|
13
13
|
"deduplicate"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"clean": "yarn tsc --build --clean",
|
|
17
|
+
"test": "yarn build && jest",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"typecheck": "yarn tsc --build tsconfig.json --force && yarn tsc --build tests/tsconfig.json --force",
|
|
20
|
+
"validate": "yarn test && yarn lint && yarn typecheck",
|
|
21
|
+
"prepack": "yarn build",
|
|
22
|
+
"build": "yarn clean && yarn tsc --build",
|
|
23
|
+
"release": "release-it"
|
|
18
24
|
},
|
|
19
25
|
"homepage": "https://github.com/christophehurpeau/yarn-deduplicate#readme",
|
|
20
26
|
"bugs": "https://github.com/christophehurpeau/yarn-deduplicate/issues",
|
|
21
27
|
"license": "Apache-2.0",
|
|
22
|
-
"author": "Sergio Cinos <
|
|
23
|
-
"main": "index.js",
|
|
28
|
+
"author": "Sergio Cinos <sergio.cinos@gmail.com>",
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"AUTHORS.md",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"CODE_OF_CONDUCT.md",
|
|
35
|
+
"LICENSE.txt",
|
|
36
|
+
"README.md",
|
|
37
|
+
"dist/*",
|
|
38
|
+
"!dist/tsconfig.tsbuildinfo"
|
|
39
|
+
],
|
|
24
40
|
"repository": {
|
|
25
41
|
"type": "git",
|
|
26
42
|
"url": "git@github.com:christophehurpeau/yarn-deduplicate.git"
|
|
27
43
|
},
|
|
28
44
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
30
|
-
"yarn": "^1.0.0"
|
|
45
|
+
"node": ">=v14"
|
|
31
46
|
},
|
|
32
47
|
"dependencies": {
|
|
33
|
-
"@yarnpkg/
|
|
34
|
-
"
|
|
35
|
-
"
|
|
48
|
+
"@yarnpkg/core": "^4.0.0-rc.37",
|
|
49
|
+
"@yarnpkg/parsers": "^3.0.0-rc.37",
|
|
50
|
+
"commander": "^9.4.1",
|
|
51
|
+
"semver": "^7.3.8",
|
|
52
|
+
"tslib": "^2.4.1"
|
|
36
53
|
},
|
|
37
54
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
55
|
+
"@babel/core": "^7.20.5",
|
|
56
|
+
"@babel/preset-env": "^7.20.2",
|
|
57
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
58
|
+
"@release-it/keep-a-changelog": "^3.1.0",
|
|
59
|
+
"@tsconfig/node12": "^1.0.11",
|
|
60
|
+
"@types/jest": "^29.2.4",
|
|
61
|
+
"@types/semver": "^7.3.13",
|
|
62
|
+
"eslint": "^8.29.0",
|
|
63
|
+
"eslint-config-prettier": "^8.5.0",
|
|
64
|
+
"eslint-plugin-jest": "^27.1.6",
|
|
65
|
+
"eslint-plugin-md": "^1.0.19",
|
|
66
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
67
|
+
"jest": "^29.3.1",
|
|
68
|
+
"outdent": "^0.8.0",
|
|
69
|
+
"prettier": "^2.8.1",
|
|
70
|
+
"release-it": "^15.5.1",
|
|
71
|
+
"typescript": "^4.9.4"
|
|
45
72
|
},
|
|
46
73
|
"jest": {
|
|
47
|
-
"
|
|
48
|
-
"<rootDir>/
|
|
49
|
-
"<rootDir>/.history",
|
|
50
|
-
"<rootDir>/.vscode"
|
|
74
|
+
"testMatch": [
|
|
75
|
+
"<rootDir>/tests/*.ts"
|
|
51
76
|
]
|
|
52
|
-
}
|
|
77
|
+
},
|
|
78
|
+
"packageManager": "yarn@3.3.0"
|
|
53
79
|
}
|
package/.eslintrc.js
DELETED
package/.prettierrc.js
DELETED
package/AUTHORS
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Ally Beaton <ally.beaton@lendi.com.au>
|
|
2
|
-
Alon Bukai <alonzorz@gmail.com>
|
|
3
|
-
amark <amark@palantir.com>
|
|
4
|
-
bjorn <bjorn@binovi.se>
|
|
5
|
-
Björn Lundgren <bjorn.erik.lundgren@gmail.com>
|
|
6
|
-
bluelovers <codelovers@users.sourceforge.net>
|
|
7
|
-
Felipe Matos Santana <felipems@yahoo.com.br>
|
|
8
|
-
FUJI Goro <g.psy.va@gmail.com>
|
|
9
|
-
Hawken Rives <hawkrives@gmail.com>
|
|
10
|
-
Jacob Blomgren <blomgren@protonmail.com>
|
|
11
|
-
Joge <joge@application-studios.com>
|
|
12
|
-
Lukas Eipert <git@leipert.io>
|
|
13
|
-
Luke Batchelor <lbatchelor@atlassian.com>
|
|
14
|
-
Maciej Rzymski <mrzymski@atlassian.com>
|
|
15
|
-
Matt Mulder <muldmatt@gmail.com>
|
|
16
|
-
Mike Greiling <mike@pixelcog.com>
|
|
17
|
-
Richard Atkins <richatkins@atlassian.com>
|
|
18
|
-
Sergio Cinos <sergio.cinos@gmail.com>
|
|
19
|
-
Simon Knox <psimyn@users.noreply.github.com>
|
|
20
|
-
Su-Shing Chen <Shingyx@users.noreply.github.com>
|
|
21
|
-
Xianming Zhong <chinesedfan@qq.com>
|
|
22
|
-
Yann Pringault <yann.pringault@gmail.com>
|
package/LICENSE.txt
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
-
|
|
181
|
-
To apply the Apache License to your work, attach the following
|
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
-
replaced with your own identifying information. (Don't include
|
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
-
comment syntax for the file format. We also recommend that a
|
|
186
|
-
file or class name and description of purpose be included on the
|
|
187
|
-
same "printed page" as the copyright notice for easier
|
|
188
|
-
identification within third-party archives.
|
|
189
|
-
|
|
190
|
-
Copyright [yyyy] [name of copyright owner]
|
|
191
|
-
|
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
-
you may not use this file except in compliance with the License.
|
|
194
|
-
You may obtain a copy of the License at
|
|
195
|
-
|
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
|
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
-
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
package/cli.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const commander = require('commander');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
|
|
6
|
-
const { fixDuplicates, listDuplicates } = require('./index');
|
|
7
|
-
const version = require('./package.json').version;
|
|
8
|
-
|
|
9
|
-
commander
|
|
10
|
-
.version(version)
|
|
11
|
-
.usage('[options] [yarn.lock path (default: yarn.lock)]')
|
|
12
|
-
.option(
|
|
13
|
-
'-s, --strategy <strategy>',
|
|
14
|
-
'deduplication strategy. Valid values: fewer, highest. Default is "highest"',
|
|
15
|
-
'highest'
|
|
16
|
-
)
|
|
17
|
-
.option('-l, --list', 'do not change yarn.lock, just output the diagnosis')
|
|
18
|
-
.option('-f, --fail', 'if there are duplicates in yarn.lock, exit 1 for failure')
|
|
19
|
-
.option(
|
|
20
|
-
'--packages <packages>',
|
|
21
|
-
'a comma separated list of packages to deduplicate. Defaults to all packages.',
|
|
22
|
-
val => val.split(',').map(v => v.trim())
|
|
23
|
-
)
|
|
24
|
-
.option('--exclude <exclude>', 'a comma separated list of packages not to deduplicate.', val =>
|
|
25
|
-
val.split(',').map(v => v.trim())
|
|
26
|
-
)
|
|
27
|
-
.option('--print', 'instead of saving the deduplicated yarn.lock, print the result in stdout');
|
|
28
|
-
|
|
29
|
-
commander.parse(process.argv);
|
|
30
|
-
|
|
31
|
-
if (commander.strategy !== 'highest' && commander.strategy !== 'fewer') {
|
|
32
|
-
console.error(`Invalid strategy ${commander.strategy}`);
|
|
33
|
-
commander.help();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const file = commander.args.length ? commander.args[0] : 'yarn.lock';
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const yarnLock = fs.readFileSync(file, 'utf8');
|
|
40
|
-
const useMostCommon = commander.strategy === 'fewer';
|
|
41
|
-
|
|
42
|
-
if (commander.list) {
|
|
43
|
-
const duplicates = listDuplicates(yarnLock, {
|
|
44
|
-
useMostCommon,
|
|
45
|
-
includePackages: commander.packages,
|
|
46
|
-
excludePackages: commander.exclude,
|
|
47
|
-
});
|
|
48
|
-
duplicates.forEach(logLine => console.log(logLine));
|
|
49
|
-
if (commander.fail && duplicates.length > 0) {
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
// https://github.com/yarnpkg/berry/blob/06443a7c050713f90f33d9a224cc37f7312cd28b/packages/yarnpkg-core/sources/Project.ts#L1510-L1515
|
|
54
|
-
const header = `${[
|
|
55
|
-
`# This file is generated by running "yarn install" inside your project.\n`,
|
|
56
|
-
`# Manual changes might be lost - proceed with caution!\n`,
|
|
57
|
-
].join(``)}\n`;
|
|
58
|
-
|
|
59
|
-
let dedupedYarnLock =
|
|
60
|
-
header +
|
|
61
|
-
fixDuplicates(yarnLock, {
|
|
62
|
-
useMostCommon,
|
|
63
|
-
includePackages: commander.packages,
|
|
64
|
-
excludePackages: commander.exclude,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (commander.print) {
|
|
68
|
-
console.log(dedupedYarnLock);
|
|
69
|
-
} else {
|
|
70
|
-
const eolMatch = yarnLock.match(/(\r?\n)/);
|
|
71
|
-
if (eolMatch && eolMatch[0] === '\r\n') {
|
|
72
|
-
dedupedYarnLock = dedupedYarnLock.replace(/\n/g, '\r\n');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return fs.writeFileSync(file, dedupedYarnLock);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (commander.fail && yarnLock !== dedupedYarnLock) {
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
process.exit(0);
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.error(e);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
package/index.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
// const lockfile = require('@yarnpkg/lockfile');
|
|
2
|
-
const yarnParsers = require('@yarnpkg/parsers');
|
|
3
|
-
const semver = require('semver');
|
|
4
|
-
|
|
5
|
-
const parseYarnLock = file => yarnParsers.parseSyml(file);
|
|
6
|
-
|
|
7
|
-
const extractPackages = (json, includePackages = [], excludePackages = []) => {
|
|
8
|
-
const packages = {};
|
|
9
|
-
const re = /^(.*)@(?:([^:]*):)?([^@]*?)$/;
|
|
10
|
-
|
|
11
|
-
Object.keys(json).forEach(key => {
|
|
12
|
-
if (key === '__metadata') return;
|
|
13
|
-
const pkg = json[key];
|
|
14
|
-
|
|
15
|
-
// ignore non hard links
|
|
16
|
-
if (pkg.linkType !== 'hard') return;
|
|
17
|
-
|
|
18
|
-
let packageName,
|
|
19
|
-
requestedSources = new Set(),
|
|
20
|
-
requestedVersions = [];
|
|
21
|
-
|
|
22
|
-
key.split(', ').forEach(part => {
|
|
23
|
-
const match = part.match(re);
|
|
24
|
-
|
|
25
|
-
let requestedVersion, requestedSource;
|
|
26
|
-
|
|
27
|
-
// TODO: make this ignore other urls like:
|
|
28
|
-
// git...
|
|
29
|
-
// user/repo
|
|
30
|
-
// tag
|
|
31
|
-
// path/path/path
|
|
32
|
-
if (match) {
|
|
33
|
-
[, packageName, requestedSource, requestedVersion] = match;
|
|
34
|
-
} else {
|
|
35
|
-
console.log(part);
|
|
36
|
-
// If there is no match, it means there is no version specified. According to the doc
|
|
37
|
-
// this means "*" (https://docs.npmjs.com/files/package.json#dependencies)
|
|
38
|
-
packageName = part;
|
|
39
|
-
requestedSource = 'npm';
|
|
40
|
-
requestedVersion = '*';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// If there is a list of package names, only process those.
|
|
44
|
-
if (includePackages.length > 0 && !includePackages.includes(packageName)) return;
|
|
45
|
-
|
|
46
|
-
if (excludePackages.length > 0 && excludePackages.includes(packageName)) return;
|
|
47
|
-
|
|
48
|
-
requestedSources.add(requestedSource);
|
|
49
|
-
requestedVersions.push(requestedVersion);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// ignore non npm sources
|
|
53
|
-
if (requestedSources.size !== 1 || !requestedSources.has('npm')) return;
|
|
54
|
-
|
|
55
|
-
packages[packageName] = packages[packageName] || [];
|
|
56
|
-
packages[packageName].push({
|
|
57
|
-
key,
|
|
58
|
-
pkg,
|
|
59
|
-
name: packageName,
|
|
60
|
-
requestedVersions,
|
|
61
|
-
installedVersion: pkg.version,
|
|
62
|
-
satisfiedBy: new Set(),
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
return packages;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const computePackageInstances = (packages, name, useMostCommon) => {
|
|
69
|
-
// Instances of this package in the tree
|
|
70
|
-
const packageInstances = packages[name];
|
|
71
|
-
|
|
72
|
-
// Extract the list of unique versions for this package
|
|
73
|
-
const versions = packageInstances.reduce((versions, packageInstance) => {
|
|
74
|
-
if (packageInstance.installedVersion in versions) return versions;
|
|
75
|
-
versions[packageInstance.installedVersion] = {
|
|
76
|
-
pkg: packageInstance.pkg,
|
|
77
|
-
satisfies: new Set(),
|
|
78
|
-
};
|
|
79
|
-
return versions;
|
|
80
|
-
}, {});
|
|
81
|
-
|
|
82
|
-
// Link each package instance with all the versions it could satisfy.
|
|
83
|
-
Object.keys(versions).forEach(version => {
|
|
84
|
-
const satisfies = versions[version].satisfies;
|
|
85
|
-
packageInstances.forEach(packageInstance => {
|
|
86
|
-
// We can assume that the installed version always satisfied the requested version.
|
|
87
|
-
packageInstance.satisfiedBy.add(packageInstance.installedVersion);
|
|
88
|
-
// In some cases the requested version is invalid form a semver point of view (for
|
|
89
|
-
// example `sinon@next`). Just ignore those cases, they won't get deduped.
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
packageInstance.requestedVersions.some(
|
|
93
|
-
requestedVersion =>
|
|
94
|
-
semver.validRange(requestedVersion) &&
|
|
95
|
-
semver.satisfies(version, requestedVersion)
|
|
96
|
-
)
|
|
97
|
-
) {
|
|
98
|
-
satisfies.add(packageInstance);
|
|
99
|
-
packageInstance.satisfiedBy.add(version);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// Sort the list of satisfied versions
|
|
105
|
-
packageInstances.forEach(packageInstance => {
|
|
106
|
-
// Save all versions for future reference
|
|
107
|
-
packageInstance.versions = versions;
|
|
108
|
-
|
|
109
|
-
// Compute the versions that actually satisfy this instance
|
|
110
|
-
const candidateVersions = Array.from(packageInstance.satisfiedBy);
|
|
111
|
-
candidateVersions.sort((versionA, versionB) => {
|
|
112
|
-
if (useMostCommon) {
|
|
113
|
-
// Sort verions based on how many packages it satisfies. In case of a tie, put the
|
|
114
|
-
// highest version first.
|
|
115
|
-
if (versions[versionB].satisfies.size > versions[versionA].satisfies.size) return 1;
|
|
116
|
-
if (versions[versionB].satisfies.size < versions[versionA].satisfies.size)
|
|
117
|
-
return -1;
|
|
118
|
-
}
|
|
119
|
-
return semver.rcompare(versionA, versionB);
|
|
120
|
-
});
|
|
121
|
-
packageInstance.satisfiedBy = candidateVersions;
|
|
122
|
-
|
|
123
|
-
// The best package is always the first one in the list thanks to the sorting above.
|
|
124
|
-
packageInstance.bestVersion = candidateVersions[0];
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return packageInstances;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const getDuplicatedPackages = (packages, { useMostCommon }) => {
|
|
131
|
-
return Object.keys(packages)
|
|
132
|
-
.reduce(
|
|
133
|
-
(acc, name) => acc.concat(computePackageInstances(packages, name, useMostCommon)),
|
|
134
|
-
[]
|
|
135
|
-
)
|
|
136
|
-
.filter(({ bestVersion, installedVersion }) => bestVersion !== installedVersion);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
module.exports.listDuplicates = (
|
|
140
|
-
yarnLock,
|
|
141
|
-
{ includePackages = [], excludePackages = [], useMostCommon = false } = {}
|
|
142
|
-
) => {
|
|
143
|
-
const json = parseYarnLock(yarnLock);
|
|
144
|
-
const packages = extractPackages(json, includePackages, excludePackages);
|
|
145
|
-
const result = [];
|
|
146
|
-
|
|
147
|
-
getDuplicatedPackages(packages, { useMostCommon }).forEach(
|
|
148
|
-
({ bestVersion, name, installedVersion, requestedVersions }) => {
|
|
149
|
-
result.push(
|
|
150
|
-
`Package "${name}" wants ${requestedVersions.join(
|
|
151
|
-
','
|
|
152
|
-
)} and could get ${bestVersion}, but got ${installedVersion}`
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return result;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
module.exports.fixDuplicates = (
|
|
161
|
-
yarnLock,
|
|
162
|
-
{ includePackages = [], excludePackages = [], useMostCommon = false } = {}
|
|
163
|
-
) => {
|
|
164
|
-
const json = parseYarnLock(yarnLock);
|
|
165
|
-
const packages = extractPackages(json, includePackages, excludePackages);
|
|
166
|
-
const changesToPackages = new Map();
|
|
167
|
-
|
|
168
|
-
getDuplicatedPackages(packages, { useMostCommon }).forEach(
|
|
169
|
-
({ name, bestVersion, installedVersion }) => {
|
|
170
|
-
if (!changesToPackages.has(name)) {
|
|
171
|
-
changesToPackages.set(name, []);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
changesToPackages.get(name).push({ bestVersion, installedVersion });
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
changesToPackages.forEach((changes, name) => {
|
|
179
|
-
const entries = new Map(
|
|
180
|
-
packages[name].map(({ installedVersion, key, pkg }) => [
|
|
181
|
-
installedVersion,
|
|
182
|
-
{ key, pkg, deleted: false, changed: false },
|
|
183
|
-
])
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
changes.forEach(({ bestVersion, installedVersion }) => {
|
|
187
|
-
const entry = entries.get(bestVersion);
|
|
188
|
-
|
|
189
|
-
const installedVersionEntry = entries.get(installedVersion);
|
|
190
|
-
if (
|
|
191
|
-
installedVersionEntry.changed &&
|
|
192
|
-
installedVersionEntry.newKey.startsWith(installedVersionEntry.key)
|
|
193
|
-
) {
|
|
194
|
-
installedVersionEntry.newKey = installedVersionEntry.newKey.slice(
|
|
195
|
-
installedVersionEntry.key.length + ', '.length
|
|
196
|
-
);
|
|
197
|
-
} else {
|
|
198
|
-
installedVersionEntry.deleted = true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (entry.deleted) throw new Error('Unsupported');
|
|
202
|
-
entry.newKey = (entry.newKey || entry.key) + ', ' + entries.get(installedVersion).key;
|
|
203
|
-
entry.changed = true;
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
entries.forEach(({ key, newKey, pkg, deleted, changed }) => {
|
|
207
|
-
if (deleted || changed) {
|
|
208
|
-
delete json[key];
|
|
209
|
-
|
|
210
|
-
if (changed) {
|
|
211
|
-
const newKeyRequested = newKey.split(', ');
|
|
212
|
-
newKeyRequested.sort((versionA, versionB) => {
|
|
213
|
-
return semver.compare(
|
|
214
|
-
semver.minVersion(versionA.split(':', 2)[1]),
|
|
215
|
-
semver.minVersion(versionB.split(':', 2)[1])
|
|
216
|
-
);
|
|
217
|
-
});
|
|
218
|
-
json[newKeyRequested.join(', ')] = pkg;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
return yarnParsers.stringifySyml(json);
|
|
225
|
-
};
|