MCPcopy
hub / github.com/webpack/webpack / getManagedItem

Function getManagedItem

lib/FileSystemInfo.js:1128–1187  ·  view source on GitHub ↗
(managedPath, path)

Source from the content-addressed store, hash-verified

1126 * ) === '/Users/user/my-project/node_modules/package'
1127 */
1128const getManagedItem = (managedPath, path) => {
1129 let i = managedPath.length;
1130 let slashes = 1;
1131 let startingPosition = true;
1132 loop: while (i < path.length) {
1133 switch (path.charCodeAt(i)) {
1134 case 47: // slash
1135 case 92: // backslash
1136 if (--slashes === 0) break loop;
1137 startingPosition = true;
1138 break;
1139 case 46: // .
1140 // hidden files are disallowed as managed items
1141 // it's probably .yarn-integrity or .cache
1142 if (startingPosition) return null;
1143 break;
1144 case 64: // @
1145 if (!startingPosition) return null;
1146 slashes++;
1147 break;
1148 default:
1149 startingPosition = false;
1150 break;
1151 }
1152 i++;
1153 }
1154 if (i === path.length) slashes--;
1155 // return null when path is incomplete
1156 if (slashes !== 0) return null;
1157 // if (path.slice(i + 1, i + 13) === "node_modules")
1158 if (
1159 path.length >= i + 13 &&
1160 path.charCodeAt(i + 1) === 110 &&
1161 path.charCodeAt(i + 2) === 111 &&
1162 path.charCodeAt(i + 3) === 100 &&
1163 path.charCodeAt(i + 4) === 101 &&
1164 path.charCodeAt(i + 5) === 95 &&
1165 path.charCodeAt(i + 6) === 109 &&
1166 path.charCodeAt(i + 7) === 111 &&
1167 path.charCodeAt(i + 8) === 100 &&
1168 path.charCodeAt(i + 9) === 117 &&
1169 path.charCodeAt(i + 10) === 108 &&
1170 path.charCodeAt(i + 11) === 101 &&
1171 path.charCodeAt(i + 12) === 115
1172 ) {
1173 // if this is the end of the path
1174 if (path.length === i + 13) {
1175 // return the node_modules directory
1176 // it's special
1177 return path;
1178 }
1179 const c = path.charCodeAt(i + 13);
1180 // if next symbol is slash or backslash
1181 if (c === 47 || c === 92) {
1182 // Managed subpath
1183 return getManagedItem(path.slice(0, i + 14), path);
1184 }
1185 }

Callers 2

checkManagedMethod · 0.85
_readContextMethod · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected