From 670d50a96b554e758509a70c78ee3a30834b7c78 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 19 Dec 2024 15:00:42 -0800 Subject: [PATCH] Experiment with allowing absolute paths for imports in core For #236644 Only works for dev right now --- package.json | 3 ++ src/bootstrap-window.ts | 30 +++++++++++-------- src/tsconfig.base.json | 2 +- src/vs/editor/common/codecs/baseToken.ts | 2 +- src/vs/platform/log/common/log.ts | 2 +- .../policy/node/nativePolicyService.ts | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 3316ae225ea89..276501ba99476 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "main": "./out/main.js", "type": "module", "private": true, + "imports": { + "#vs/*.js": "./out/vs/*.js" + }, "scripts": { "test": "echo Please run any of the test scripts from the scripts folder.", "test-browser": "npx playwright install && node test/unit/browser/index.js", diff --git a/src/bootstrap-window.ts b/src/bootstrap-window.ts index 3c1270026039a..909759a8c1887 100644 --- a/src/bootstrap-window.ts +++ b/src/bootstrap-window.ts @@ -32,7 +32,7 @@ globalThis._VSCODE_FILE_ROOT = baseUrl.toString(); // Dev only: CSS import map tricks - setupCSSImportMaps(configuration, baseUrl); + setupDevImportMaps(configuration, baseUrl); // ESM Import try { @@ -181,13 +181,18 @@ return uri.replace(/#/g, '%23'); } - function setupCSSImportMaps(configuration: T, baseUrl: URL) { + function setupDevImportMaps(configuration: T, baseUrl: URL) { // DEV --------------------------------------------------------------------------------------- // DEV: This is for development and enables loading CSS via import-statements via import-maps. // DEV: For each CSS modules that we have we defined an entry in the import map that maps to // DEV: a blob URL that loads the CSS via a dynamic @import-rule. // DEV --------------------------------------------------------------------------------------- + const importMap: { imports: Record } = { + imports: { + '#vs/': baseUrl.href + '/vs/' + } + }; if (Array.isArray(configuration.cssModules) && configuration.cssModules.length > 0) { performance.mark('code/willAddCssLoader'); @@ -202,25 +207,24 @@ style.textContent += `@import url(${url});\n`; }; - const importMap: { imports: Record } = { imports: {} }; for (const cssModule of configuration.cssModules) { const cssUrl = new URL(cssModule, baseUrl).href; const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\n`; const blob = new Blob([jsSrc], { type: 'application/javascript' }); importMap.imports[cssUrl] = URL.createObjectURL(blob); } + } - const ttp = window.trustedTypes?.createPolicy('vscode-bootstrapImportMap', { createScript(value) { return value; }, }); - const importMapSrc = JSON.stringify(importMap, undefined, 2); - const importMapScript = document.createElement('script'); - importMapScript.type = 'importmap'; - importMapScript.setAttribute('nonce', '0c6a828f1297'); - // @ts-ignore - importMapScript.textContent = ttp?.createScript(importMapSrc) ?? importMapSrc; - document.head.appendChild(importMapScript); + const ttp = window.trustedTypes?.createPolicy('vscode-bootstrapImportMap', { createScript(value) { return value; }, }); + const importMapSrc = JSON.stringify(importMap, undefined, 2); + const importMapScript = document.createElement('script'); + importMapScript.type = 'importmap'; + importMapScript.setAttribute('nonce', '0c6a828f1297'); + // @ts-ignore + importMapScript.textContent = ttp?.createScript(importMapSrc) ?? importMapSrc; + document.head.appendChild(importMapScript); - performance.mark('code/didAddCssLoader'); - } + performance.mark('code/didAddCssLoader'); } (globalThis as any).MonacoBootstrapWindow = { load }; diff --git a/src/tsconfig.base.json b/src/tsconfig.base.json index 9c7aacd4f11b0..86fcf3942d3fd 100644 --- a/src/tsconfig.base.json +++ b/src/tsconfig.base.json @@ -13,7 +13,7 @@ "forceConsistentCasingInFileNames": true, "baseUrl": ".", "paths": { - "vs/*": [ + "#vs/*": [ "./vs/*" ] }, diff --git a/src/vs/editor/common/codecs/baseToken.ts b/src/vs/editor/common/codecs/baseToken.ts index 9ebe3ad8abc3c..56230cf9a8da3 100644 --- a/src/vs/editor/common/codecs/baseToken.ts +++ b/src/vs/editor/common/codecs/baseToken.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IRange, Range } from '../../../editor/common/core/range.js'; +import { IRange, Range } from '#vs/editor/common/core/range.js'; /** * Base class for all tokens with a `range` that diff --git a/src/vs/platform/log/common/log.ts b/src/vs/platform/log/common/log.ts index 7ce341461a488..e1636b4d290fd 100644 --- a/src/vs/platform/log/common/log.ts +++ b/src/vs/platform/log/common/log.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as nls from '../../../nls.js'; +import * as nls from '#vs/nls.js'; import { toErrorMessage } from '../../../base/common/errorMessage.js'; import { Emitter, Event } from '../../../base/common/event.js'; import { hash } from '../../../base/common/hash.js'; diff --git a/src/vs/platform/policy/node/nativePolicyService.ts b/src/vs/platform/policy/node/nativePolicyService.ts index 67f7892e72f2c..230c3a6da7c3a 100644 --- a/src/vs/platform/policy/node/nativePolicyService.ts +++ b/src/vs/platform/policy/node/nativePolicyService.ts @@ -8,7 +8,7 @@ import { IStringDictionary } from '../../../base/common/collections.js'; import { Throttler } from '../../../base/common/async.js'; import type { PolicyUpdate, Watcher } from '@vscode/policy-watcher'; import { MutableDisposable } from '../../../base/common/lifecycle.js'; -import { ILogService } from '../../log/common/log.js'; +import { ILogService } from '#vs/platform/log/common/log.js'; export class NativePolicyService extends AbstractPolicyService implements IPolicyService {