MCPcopy Create free account
hub / github.com/adobe/react-spectrum / fix

Function fix

packages/dev/eslint-plugin-rsp-rules/rules/imports.js:85–111  ·  view source on GitHub ↗
(fixer)

Source from the content-addressed store, hash-verified

83 node,
84 message: `Missing dependency on ${pkgName}.`,
85 fix(fixer) {
86 // Attempt to find a package in the monorepo. If the dep is for an external library,
87 // then we cannot auto fix it because we don't know the version to add.
88 let depPath = __dirname + '/../packages/' + pkgName + '/package.json';
89 if (!fs.existsSync(depPath)) {
90 return;
91 }
92
93 let depPkg = JSON.parse(fs.readFileSync(depPath, 'utf8'));
94 let pkgVersion = substrings.some(v => depPkg.version.includes(v))
95 ? depPkg.version
96 : `^${depPkg.version}`;
97
98 if (pkgName === '@react-spectrum/provider') {
99 pkg.peerDependencies = insertObject(pkg.peerDependencies, pkgName, pkgVersion);
100 } else {
101 pkg.dependencies = insertObject(pkg.dependencies, pkgName, pkgVersion);
102 }
103
104 fs.writeFileSync(pkgPath, JSON.stringify(pkg, false, 2) + '\n');
105
106 // Fake fix so eslint doesn't show the error.
107 return {
108 range: [0, 0],
109 text: ''
110 };
111 }
112 });
113 }
114 };

Callers

nothing calls this directly

Calls 2

insertObjectFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected