MCPcopy
hub / github.com/meteor/meteor / resolve

Method resolve

tools/isobuild/resolver.ts:138–248  ·  view source on GitHub ↗
(
    id: string,
    absParentPath: string,
    _seenDirPaths?: Set<string>,
  )

Source from the content-addressed store, hash-verified

136 // null, relative to an absolute parent path. The _seenDirPaths
137 // parameter is for internal use only and should be ommitted.
138 public resolve(
139 id: string,
140 absParentPath: string,
141 _seenDirPaths?: Set<string>,
142 ): Resolution {
143 let resolved =
144 this.resolveAbsolute(id, absParentPath) ||
145 this.resolveRelative(id, absParentPath) ||
146 this.resolveNodeModule(id, absParentPath);
147
148 if (resolved === "missing") {
149 // The _resolveNodeModule method can return "missing" to indicate
150 // that the ImportScanner should look elsewhere for this module,
151 // such as in the app node_modules directory.
152 return resolved;
153 }
154
155 let packageJsonMap = null;
156
157 while (resolved && resolved.stat && resolved.stat.isDirectory()) {
158 let dirPath = resolved.path;
159 _seenDirPaths = _seenDirPaths || new Set;
160
161 // If the "main" field of a package.json file resolves to a
162 // directory we've already considered, then we should not attempt to
163 // read the same package.json file again.
164 if (! _seenDirPaths.has(dirPath)) {
165 _seenDirPaths.add(dirPath);
166
167 const found = this.getPkgJsonSubsetForDir(dirPath);
168 const foundPkgJsonMain = found && this.mainFields.some(name => {
169 const value = found.pkg[name];
170 if (isString(value)) {
171 // The "main" field of package.json does not have to begin with ./
172 // to be considered relative, so first we try simply appending it
173 // to the directory path before falling back to a full resolve,
174 // which might return a package from a node_modules directory.
175 resolved = this.joinAndStat(dirPath, value) ||
176 this.resolve(value, found.path, _seenDirPaths);
177 return resolved && typeof resolved === "object";
178 }
179 return false;
180 });
181
182 if (foundPkgJsonMain && found) {
183 if (! resolved.packageJsonMap) {
184 resolved.packageJsonMap = Object.create(null);
185 }
186
187 resolved.packageJsonMap![found.path] = found.pkg;
188
189 // The resolution above may have returned a directory, so we
190 // merge resolved.packageJsonMap into packageJsonMap so that we
191 // don't forget the package.json we just resolved, then continue
192 // the loop to make sure we fully resolve the "main" module
193 // identifier to a non-directory. Technically this could
194 // involve even more package.json files, but in practice the
195 // "main" property will almost always name a directory

Callers 15

project-context.jsFile · 0.45
_getEntryModuleMethod · 0.45
resolveMatchMethod · 0.45
attemptFunction · 0.45
coalescingWrapperFunction · 0.45
run-mongo.jsFile · 0.45
profile-require.jsFile · 0.45
dev-bundle.jsFile · 0.45
getDevBundleDirFunction · 0.45
getDevBundleForReleaseFunction · 0.45
addWindowsVariablesFunction · 0.45

Calls 11

resolveAbsoluteMethod · 0.95
resolveRelativeMethod · 0.95
resolveNodeModuleMethod · 0.95
joinAndStatMethod · 0.95
convertToOSPathFunction · 0.90
isStringFunction · 0.85
addMethod · 0.80
isObjectFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected