Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/cssDev/node/cssDevService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { spawn } from 'child_process';
7
import { relative } from '../../../base/common/path.js';
8
import { FileAccess } from '../../../base/common/network.js';
9
import { StopWatch } from '../../../base/common/stopwatch.js';
10
import { IEnvironmentService } from '../../environment/common/environment.js';
11
import { createDecorator } from '../../instantiation/common/instantiation.js';
12
import { ILogService } from '../../log/common/log.js';
13
14
export const ICSSDevelopmentService = createDecorator<ICSSDevelopmentService>('ICSSDevelopmentService');
15
16
export interface ICSSDevelopmentService {
17
_serviceBrand: undefined;
18
isEnabled: boolean;
19
getCssModules(): Promise<string[]>;
20
}
21
22
export class CSSDevelopmentService implements ICSSDevelopmentService {
23
24
declare _serviceBrand: undefined;
25
26
private _cssModules?: Promise<string[]>;
27
28
constructor(
29
@IEnvironmentService private readonly envService: IEnvironmentService,
30
@ILogService private readonly logService: ILogService
31
) { }
32
33
get isEnabled(): boolean {
34
return !this.envService.isBuilt;
35
}
36
37
getCssModules(): Promise<string[]> {
38
this._cssModules ??= this.computeCssModules();
39
return this._cssModules;
40
}
41
42
private async computeCssModules(): Promise<string[]> {
43
if (!this.isEnabled) {
44
return [];
45
}
46
47
const rg = await import('@vscode/ripgrep');
48
return await new Promise<string[]>((resolve) => {
49
50
const sw = StopWatch.create();
51
52
const chunks: Buffer[] = [];
53
const basePath = FileAccess.asFileUri('').fsPath;
54
const process = spawn(rg.rgPath, ['-g', '**/*.css', '--files', '--no-ignore', basePath], {});
55
56
process.stdout.on('data', data => {
57
chunks.push(data);
58
});
59
process.on('error', err => {
60
this.logService.error('[CSS_DEV] FAILED to compute CSS data', err);
61
resolve([]);
62
});
63
process.on('close', () => {
64
const data = Buffer.concat(chunks).toString('utf8');
65
const result = data.split('\n').filter(Boolean).map(path => relative(basePath, path).replace(/\\/g, '/')).filter(Boolean).sort();
66
if (result.some(path => path.indexOf('vs/') !== 0)) {
67
this.logService.error(`[CSS_DEV] Detected invalid paths in css modules, raw output: ${data}`);
68
}
69
resolve(result);
70
this.logService.info(`[CSS_DEV] DONE, ${result.length} css modules (${Math.round(sw.elapsed())}ms)`);
71
});
72
});
73
}
74
}
75
76