mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-04 01:44:44 -06:00
Adopts @vscode/rollup-plugin-esm-url (#290012)
* Adopts @vscode/rollup-plugin-esm-url * Exports EditorWorkerService.workerDescriptor
This commit is contained in:
parent
564100cbce
commit
55134be2df
11
build/vite/package-lock.json
generated
11
build/vite/package-lock.json
generated
@ -8,6 +8,7 @@
|
||||
"name": "@vscode/sample-source",
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"@vscode/rollup-plugin-esm-url": "^1.0.1-0",
|
||||
"vite": "^7.1.11"
|
||||
}
|
||||
},
|
||||
@ -754,6 +755,16 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@vscode/rollup-plugin-esm-url": {
|
||||
"version": "1.0.1-0",
|
||||
"resolved": "https://registry.npmjs.org/@vscode/rollup-plugin-esm-url/-/rollup-plugin-esm-url-1.0.1-0.tgz",
|
||||
"integrity": "sha512-5k9c2ZK6xTTa2MGa0uD+f/a1cZV8SCQm9ZhorQDyBRvobIzOTg57LjOl3di9Z6zawPh7nDgbWp6g+GnSSpdCrg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"rollup": "^3.0.0 || ^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.9",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz",
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vscode/rollup-plugin-esm-url": "^1.0.1-0",
|
||||
"vite": "^7.1.11"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,63 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @type {() => import('rollup').Plugin}
|
||||
*/
|
||||
export function urlToEsmPlugin() {
|
||||
return {
|
||||
name: 'import-meta-url',
|
||||
async transform(code, id) {
|
||||
if (this.environment?.mode === 'dev') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for `new URL(..., import.meta.url)` patterns.
|
||||
const regex = /new\s+URL\s*\(\s*(['"`])(.*?)\1\s*,\s*import\.meta\.url\s*\)?/g;
|
||||
|
||||
let match;
|
||||
let modified = false;
|
||||
let result = code;
|
||||
let offset = 0;
|
||||
|
||||
while ((match = regex.exec(code)) !== null) {
|
||||
let path = match[2];
|
||||
|
||||
if (!path.startsWith('.') && !path.startsWith('/')) {
|
||||
path = `./${path}`;
|
||||
}
|
||||
const resolved = await this.resolve(path, id);
|
||||
|
||||
if (!resolved) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add the file as an entry point
|
||||
const refId = this.emitFile({
|
||||
type: 'chunk',
|
||||
id: resolved.id,
|
||||
});
|
||||
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
|
||||
const replacement = `import.meta.ROLLUP_FILE_URL_OBJ_${refId}`;
|
||||
|
||||
result = result.slice(0, start + offset) + replacement + result.slice(end + offset);
|
||||
offset += replacement.length - (end - start);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!modified) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
code: result,
|
||||
map: null
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import { createLogger, defineConfig, Plugin } from 'vite';
|
||||
import path, { join } from 'path';
|
||||
import { urlToEsmPlugin } from './rollup-url-to-module-plugin/index.mjs';
|
||||
import { rollupEsmUrlPlugin } from '@vscode/rollup-plugin-esm-url';
|
||||
import { statSync } from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
@ -164,7 +164,7 @@ logger.warn = (msg, options) => {
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
urlToEsmPlugin(),
|
||||
rollupEsmUrlPlugin({}),
|
||||
injectBuiltinExtensionsPlugin(),
|
||||
createHotClassSupport()
|
||||
],
|
||||
@ -177,6 +177,14 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
root: '../..', // To support /out/... paths
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
//index: path.resolve(__dirname, 'index.html'),
|
||||
workbench: path.resolve(__dirname, 'workbench-vite.html'),
|
||||
}
|
||||
}
|
||||
},
|
||||
server: {
|
||||
cors: true,
|
||||
port: 5199,
|
||||
|
||||
@ -58,6 +58,12 @@ export class EditorWorkerService extends Disposable implements IEditorWorkerServ
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
public static readonly workerDescriptor = new WebWorkerDescriptor({
|
||||
esmModuleLocation: () => FileAccess.asBrowserUri('vs/editor/common/services/editorWebWorkerMain.js'),
|
||||
esmModuleLocationBundler: () => new URL('../../common/services/editorWebWorkerMain.ts?esm', import.meta.url),
|
||||
label: 'editorWorkerService'
|
||||
});
|
||||
|
||||
private readonly _modelService: IModelService;
|
||||
private readonly _workerManager: WorkerManager;
|
||||
private readonly _logService: ILogService;
|
||||
@ -73,13 +79,7 @@ export class EditorWorkerService extends Disposable implements IEditorWorkerServ
|
||||
super();
|
||||
this._modelService = modelService;
|
||||
|
||||
const workerDescriptor = new WebWorkerDescriptor({
|
||||
esmModuleLocation: () => FileAccess.asBrowserUri('vs/editor/common/services/editorWebWorkerMain.js'),
|
||||
esmModuleLocationBundler: () => new URL('../../common/services/editorWebWorkerMain.ts?esm', import.meta.url),
|
||||
label: 'editorWorkerService'
|
||||
});
|
||||
|
||||
this._workerManager = this._register(new WorkerManager(workerDescriptor, this._modelService, this._webWorkerService));
|
||||
this._workerManager = this._register(new WorkerManager(EditorWorkerService.workerDescriptor, this._modelService, this._webWorkerService));
|
||||
this._logService = logService;
|
||||
|
||||
// register default link-provider and default completions-provider
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user