MCPcopy
hub / github.com/microsoft/vscode / importAMDNodeModule

Function importAMDNodeModule

src/vs/amdX.ts:205–229  ·  view source on GitHub ↗
(nodeModuleName: string, pathInsideNodeModule: string, isBuilt?: boolean)

Source from the content-addressed store, hash-verified

203 * e.g. pass in `vscode-textmate/release/main.js`
204 */
205export async function importAMDNodeModule<T>(nodeModuleName: string, pathInsideNodeModule: string, isBuilt?: boolean): Promise<T> {
206 if (isBuilt === undefined) {
207 const product = globalThis._VSCODE_PRODUCT_JSON as unknown as IProductConfiguration;
208 isBuilt = Boolean((product ?? globalThis.vscode?.context?.configuration()?.product)?.commit);
209 }
210
211 const nodeModulePath = pathInsideNodeModule ? `${nodeModuleName}/${pathInsideNodeModule}` : nodeModuleName;
212 if (cache.has(nodeModulePath)) {
213 return cache.get(nodeModulePath)!;
214 }
215 let scriptSrc: string;
216 if (/^\w[\w\d+.-]*:\/\//.test(nodeModulePath)) {
217 // looks like a URL
218 // bit of a special case for: src/vs/workbench/services/languageDetection/browser/languageDetectionWebWorker.ts
219 scriptSrc = nodeModulePath;
220 } else {
221 const useASAR = (canASAR && isBuilt && !platform.isWeb);
222 const actualNodeModulesPath = (useASAR ? nodeModulesAsarPath : nodeModulesPath);
223 const resourcePath: AppResourcePath = `${actualNodeModulesPath}/${nodeModulePath}`;
224 scriptSrc = FileAccess.asBrowserUri(resourcePath).toString(true);
225 }
226 const result = AMDModuleImporter.INSTANCE.load<T>(scriptSrc);
227 cache.set(nodeModulePath, result);
228 return result;
229}
230
231export function resolveAmdNodeModulePath(nodeModuleName: string, pathInsideNodeModule: string): string {
232 const product = globalThis._VSCODE_PRODUCT_JSON as unknown as IProductConfiguration;

Callers 3

getRegexpModelMethod · 0.85
getModelOperationsMethod · 0.85
vsdaMethod · 0.85

Calls 9

BooleanEnum · 0.85
configurationMethod · 0.65
hasMethod · 0.65
getMethod · 0.65
toStringMethod · 0.65
loadMethod · 0.65
setMethod · 0.65
testMethod · 0.45
asBrowserUriMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…