Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with allowing absolute paths for imports in core #236653

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 17 additions & 13 deletions src/bootstrap-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
globalThis._VSCODE_FILE_ROOT = baseUrl.toString();

// Dev only: CSS import map tricks
setupCSSImportMaps<T>(configuration, baseUrl);
setupDevImportMaps<T>(configuration, baseUrl);

// ESM Import
try {
Expand Down Expand Up @@ -181,13 +181,18 @@
return uri.replace(/#/g, '%23');
}

function setupCSSImportMaps<T extends ISandboxConfiguration>(configuration: T, baseUrl: URL) {
function setupDevImportMaps<T extends ISandboxConfiguration>(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<string, string> } = {
imports: {
'#vs/': baseUrl.href + '/vs/'
}
};

if (Array.isArray(configuration.cssModules) && configuration.cssModules.length > 0) {
performance.mark('code/willAddCssLoader');
Expand All @@ -202,25 +207,24 @@
style.textContent += `@import url(${url});\n`;
};

const importMap: { imports: Record<string, string> } = { 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 };
Expand Down
2 changes: 1 addition & 1 deletion src/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"vs/*": [
"#vs/*": [
"./vs/*"
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/codecs/baseToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/log/common/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 6 in src/vs/platform/log/common/log.ts

View workflow job for this annotation

GitHub Actions / Monaco Editor checks

Cannot find module '#vs/nls.js' or its corresponding type declarations.
import { toErrorMessage } from '../../../base/common/errorMessage.js';
import { Emitter, Event } from '../../../base/common/event.js';
import { hash } from '../../../base/common/hash.js';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/policy/node/nativePolicyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Loading