@neovici/cfg 2.8.3 → 2.9.0
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/check-duplicate-components.mjs +22 -10
- package/package.json +1 -1
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
/**
|
|
4
|
-
* Check for duplicate
|
|
4
|
+
* Check for duplicate singleton packages in package-lock.json
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Some packages must only exist as a single copy in the dependency tree:
|
|
7
|
+
* - @neovici/cosmoz-* web components register globally via customElements.define()
|
|
8
|
+
* - @pionjs/pion manages component lifecycle and scheduler state
|
|
9
|
+
* - lit-html and lit maintain internal template caches and reactive internals
|
|
10
|
+
* - i18next maintains a singleton translation context
|
|
11
|
+
*
|
|
12
|
+
* Having multiple versions of these packages causes runtime conflicts and errors.
|
|
9
13
|
*/
|
|
10
14
|
|
|
11
15
|
import { readFileSync, existsSync } from 'fs';
|
|
12
16
|
import { join } from 'path';
|
|
13
17
|
|
|
14
18
|
const LOCKFILE = 'package-lock.json',
|
|
15
|
-
|
|
19
|
+
PACKAGE_PATTERNS = [
|
|
20
|
+
/^@neovici\/cosmoz-/u,
|
|
21
|
+
/^@pionjs\/pion$/u,
|
|
22
|
+
/^lit-html$/u,
|
|
23
|
+
/^lit$/u,
|
|
24
|
+
/^i18next$/u,
|
|
25
|
+
],
|
|
16
26
|
PACKAGE_NAME_PATTERN = /node_modules\/(@[^/]+\/[^/]+|[^/]+)$/u;
|
|
17
27
|
|
|
18
28
|
const readLockfile = (lockfilePath) => {
|
|
@@ -43,7 +53,9 @@ const collectComponentVersions = (packages) => {
|
|
|
43
53
|
if (!path.startsWith('node_modules/')) continue;
|
|
44
54
|
|
|
45
55
|
const packageName = extractPackageName(path);
|
|
46
|
-
if (!packageName || !
|
|
56
|
+
if (!packageName || !PACKAGE_PATTERNS.some((p) => p.test(packageName))) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
47
59
|
|
|
48
60
|
const { version } = info;
|
|
49
61
|
if (!version) continue;
|
|
@@ -66,8 +78,8 @@ const findDuplicates = (componentVersions) =>
|
|
|
66
78
|
.map(([packageName, instances]) => ({ packageName, instances }));
|
|
67
79
|
|
|
68
80
|
const printDuplicates = (duplicates) => {
|
|
69
|
-
console.error('ERROR: Duplicate
|
|
70
|
-
console.error('
|
|
81
|
+
console.error('ERROR: Duplicate singleton packages detected!\n');
|
|
82
|
+
console.error('These packages must exist as a single copy. Having multiple');
|
|
71
83
|
console.error('versions will cause runtime conflicts and errors.\n');
|
|
72
84
|
|
|
73
85
|
for (const { packageName, instances } of duplicates) {
|
|
@@ -79,7 +91,7 @@ const printDuplicates = (duplicates) => {
|
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
console.error('Fix: Update your dependencies to ensure all packages use');
|
|
82
|
-
console.error('compatible version ranges
|
|
94
|
+
console.error('compatible version ranges, or add overrides to package.json.\n');
|
|
83
95
|
console.error('Run `npm ls <package-name>` to see the dependency tree');
|
|
84
96
|
console.error('and identify which packages need updating.');
|
|
85
97
|
};
|
|
@@ -91,7 +103,7 @@ const main = () => {
|
|
|
91
103
|
duplicates = findDuplicates(componentVersions);
|
|
92
104
|
|
|
93
105
|
if (duplicates.length === 0) {
|
|
94
|
-
console.log('✓ No duplicate
|
|
106
|
+
console.log('✓ No duplicate singleton packages found');
|
|
95
107
|
process.exit(0);
|
|
96
108
|
}
|
|
97
109
|
|