amdX.ts ×18

Frontier kind: Code frontier

unlabeled · c_37f2b56b8c08

60 tests · 6264 LOC · 31 files · introduces 0 tests · 90 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges90 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
973 ranges6264 lines · 31 files · Browse complete extent
All tests (intent)
60 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 90 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/amdX.ts 90 introduced LOC · 18 ranges

Open complete file

17 class DefineCall {
18 constructor(
19 > public readonly id: string | null | undefined, amdX.ts
20 > public readonly dependencies: string[] | null | undefined,
21 > public readonly callback: any
22 > ) { }
23 }
24
42
43 private _initialize(): void {
44 > if (this._state === AMDModuleImporterState.Uninitialized) { amdX.ts
45 > if (globalThis.define) {
46 this._state = AMDModuleImporterState.InitializedExternal;
47 return;
48 }
49 > } else { amdX.ts
50 return;
51 }
52 > amdX.ts
53 > this._state = AMDModuleImporterState.InitializedInternal;
54 >
55 > globalThis.define = (id: any, dependencies: any, callback: any) => {
56 > if (typeof id !== 'string') {
57 > callback = dependencies;
58 > dependencies = id;
59 > id = null;
60 > }
61 > if (typeof dependencies !== 'object' || !Array.isArray(dependencies)) {
62 callback = dependencies;
63 dependencies = null;
64 }
65 > // if (!dependencies) { amdX.ts
66 > // dependencies = ['require', 'exports', 'module'];
67 > // }
68 > this._defineCalls.push(new DefineCall(id, dependencies, callback));
69 > };
70 >
71 > globalThis.define.amd = true;
72 >
73 > if (this._isRenderer) {
74 this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? window.trustedTypes?.createPolicy('amdLoader', {
75 createScriptURL(value: any) {
83 }
84 });
85 > } else if (this._isWebWorker) { amdX.ts
86 this._amdPolicy = globalThis._VSCODE_WEB_PACKAGE_TTP ?? globalThis.trustedTypes?.createPolicy('amdLoader', {
87 createScriptURL(value: string) {
90 });
91 }
92 > } amdX.ts
93
94 public async load<T>(scriptSrc: string): Promise<T> {
95 > this._initialize(); amdX.ts
96 >
97 > if (this._state === AMDModuleImporterState.InitializedExternal) {
98 return new Promise<T>(resolve => {
99 const tmpModuleId = generateUuid();
103 });
104 }
105 > amdX.ts
106 > const defineCall = await (this._isWebWorker ? this._workerLoadScript(scriptSrc) : this._isRenderer ? this._rendererLoadScript(scriptSrc) : this._nodeJSLoadScript(scriptSrc));
107 > if (!defineCall) {
108 console.warn(`Did not receive a define call from script ${scriptSrc}`);
109 return <T>undefined;
110 }
111 > // TODO@esm require, module amdX.ts
112 > const exports = {};
113 > const dependencyObjs: any[] = [];
114 > const dependencyModules: string[] = [];
115 >
116 > if (Array.isArray(defineCall.dependencies)) {
117 >
118 > for (const mod of defineCall.dependencies) {
119 if (mod === 'exports') {
120 dependencyObjs.push(exports);
123 }
124 }
125 > } amdX.ts
126 >
127 > if (dependencyModules.length > 0) {
128 throw new Error(`Cannot resolve dependencies for script ${scriptSrc}. The dependencies are: ${dependencyModules.join(', ')}`);
129 }
130 > if (typeof defineCall.callback === 'function') { amdX.ts
131 > return defineCall.callback(...dependencyObjs) ?? exports;
132 > } else {
133 return defineCall.callback;
134 }
135 > } amdX.ts
136
137 private _rendererLoadScript(scriptSrc: string): Promise<DefineCall | undefined> {
175
176 private async _nodeJSLoadScript(scriptSrc: string): Promise<DefineCall | undefined> {
177 > try { amdX.ts
178 > // `import('module')` is not remapped (only `fs` is), so it yields the real
179 > // `module` builtin. We use its `createRequire` to obtain `fs`/`vm`: the ESM
180 > // resolution hook maps `import('fs')` to the ASAR-unaware `original-fs`, but
181 > // `scriptSrc` may point inside the `node_modules.asar` archive. The `fs`
182 > // returned by `require` stays ASAR-aware in Electron, so it can read module
183 > // files from within the archive.
184 > const module = (await import(/* webpackIgnore: true */ /* @vite-ignore */ `${'module'}`)).default;
185 > const nodeRequire = module.createRequire(import.meta.url);
186 > const fs = nodeRequire('fs');
187 > const vm = nodeRequire('vm');
188 >
189 > const filePath = URI.parse(scriptSrc).fsPath;
190 > const content = fs.readFileSync(filePath).toString();
191 > const scriptSource = module.wrap(content.replace(/^#!.*/, ''));
192 > const script = new vm.Script(scriptSource);
193 > const compileWrapper = script.runInThisContext();
194 > compileWrapper.apply();
195 > return this._defineCalls.pop();
196 > } catch (error) {
197 throw error;
198 }
199 > } amdX.ts
200 }
201
208 * e.g. pass in `vscode-textmate/release/main.js`
209 */
210 > export async function importAMDNodeModule<T>(nodeModuleName: string, pathInsideNodeModule: string, isBuilt?: boolean): Promise<T> { amdX.ts
211 > if (isBuilt === undefined) {
212 > const product = globalThis._VSCODE_PRODUCT_JSON as unknown as IProductConfiguration;
213 > isBuilt = Boolean((product ?? globalThis.vscode?.context?.configuration()?.product)?.commit);
214 > }
215 >
216 > const nodeModulePath = pathInsideNodeModule ? `${nodeModuleName}/${pathInsideNodeModule}` : nodeModuleName;
217 > if (cache.has(nodeModulePath)) {
218 return cache.get(nodeModulePath)!;
219 }
220 > let scriptSrc: string; amdX.ts
221 > if (/^\w[\w\d+.-]*:\/\//.test(nodeModulePath)) {
222 // looks like a URL
223 // bit of a special case for: src/vs/workbench/services/languageDetection/browser/languageDetectionWebWorker.ts
224 scriptSrc = nodeModulePath;
225 > } else { amdX.ts
226 > const useASAR = (isBuilt && (platform.isElectron || (platform.isWebWorker && platform.hasElectronUserAgent)));
227 > const actualNodeModulesPath = (useASAR ? nodeModulesAsarPath : nodeModulesPath);
228 > const resourcePath: AppResourcePath = `${actualNodeModulesPath}/${nodeModulePath}`;
229 > scriptSrc = FileAccess.asBrowserUri(resourcePath).toString(true);
230 > }
231 > const result = AMDModuleImporter.INSTANCE.load<T>(scriptSrc);
232 > cache.set(nodeModulePath, result);
233 > return result;
234 > }
235
236 export function resolveAmdNodeModulePath(nodeModuleName: string, pathInsideNodeModule: string): string {