MCPcopy Index your code
hub / github.com/rollup/plugins / resolveLikeNode

Function resolveLikeNode

packages/node-resolve/src/index.js:107–272  ·  view source on GitHub ↗
(context, importee, importer, custom)

Source from the content-addressed store, hash-verified

105 let preserveSymlinks;
106
107 const resolveLikeNode = async (context, importee, importer, custom) => {
108 // strip query params from import
109 const [importPath, params] = importee.split('?');
110 const importSuffix = `${params ? `?${params}` : ''}`;
111 importee = importPath;
112
113 const baseDir = !importer || dedupe(importee) ? rootDir : dirname(importer);
114
115 // https://github.com/defunctzombie/package-browser-field-spec
116 const browser = browserMapCache.get(importer);
117 if (useBrowserOverrides && browser) {
118 const resolvedImportee = resolve(baseDir, importee);
119 if (browser[importee] === false || browser[resolvedImportee] === false) {
120 return { id: ES6_BROWSER_EMPTY };
121 }
122 const browserImportee =
123 (importee[0] !== '.' && browser[importee]) ||
124 browser[resolvedImportee] ||
125 browser[`${resolvedImportee}.js`] ||
126 browser[`${resolvedImportee}.json`];
127 if (browserImportee) {
128 importee = browserImportee;
129 }
130 }
131
132 const parts = importee.split(/[/\\]/);
133 let id = parts.shift();
134 let isRelativeImport = false;
135
136 if (id[0] === '@' && parts.length > 0) {
137 // scoped packages
138 id += `/${parts.shift()}`;
139 } else if (id[0] === '.') {
140 // an import relative to the parent dir of the importer
141 id = resolve(baseDir, importee);
142 isRelativeImport = true;
143 }
144
145 // if it's not a relative import, and it's not requested, reject it.
146 if (!isRelativeImport && !resolveOnly(id)) {
147 if (normalizeInput(rollupOptions.input).includes(importee)) {
148 return null;
149 }
150 return false;
151 }
152
153 const importSpecifierList = [importee];
154
155 if (importer === undefined && importee[0] && !importee[0].match(/^\.?\.?\//)) {
156 // For module graph roots (i.e. when importer is undefined), we
157 // need to handle 'path fragments` like `foo/bar` that are commonly
158 // found in rollup config files. If importee doesn't look like a
159 // relative or absolute path, we make it relative and attempt to
160 // resolve it.
161 importSpecifierList.push(`./${importee}`);
162 }
163
164 // TypeScript files may import '.mjs' or '.cjs' to refer to either '.mts' or '.cts'.

Callers 1

handlerFunction · 0.85

Calls 6

normalizeInputFunction · 0.90
fileExistsFunction · 0.90
resolveImportSpecifiersFunction · 0.85
hasModuleSideEffectsFunction · 0.85
getMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected