-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
141 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { spawn } from 'child_process'; | ||
import { relative } from 'path'; | ||
import { isESM } from 'vs/base/common/amd'; | ||
import { FileAccess } from 'vs/base/common/network'; | ||
import { StopWatch } from 'vs/base/common/stopwatch'; | ||
import { IEnvironmentService } from 'vs/platform/environment/common/environment'; | ||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; | ||
import { ILogService } from 'vs/platform/log/common/log'; | ||
|
||
export const ICSSDevelopmentService = createDecorator<ICSSDevelopmentService>('ICSSDevelopmentService'); | ||
|
||
export interface ICSSDevelopmentService { | ||
_serviceBrand: undefined; | ||
isEnabled: boolean; | ||
getCssModules(): Promise<string[]>; | ||
} | ||
|
||
export class CSSDevelopmentService implements ICSSDevelopmentService { | ||
|
||
declare _serviceBrand: undefined; | ||
|
||
private _cssModules?: Promise<string[]>; | ||
|
||
constructor( | ||
@IEnvironmentService private readonly envService: IEnvironmentService, | ||
@ILogService private readonly logService: ILogService | ||
) { } | ||
|
||
get isEnabled(): boolean { | ||
return !this.envService.isBuilt && isESM; | ||
} | ||
|
||
getCssModules(): Promise<string[]> { | ||
this._cssModules ??= this.computeCssModules(); | ||
return this._cssModules; | ||
} | ||
|
||
private async computeCssModules(): Promise<string[]> { | ||
if (!this.isEnabled) { | ||
return []; | ||
} | ||
|
||
const rg = await import('@vscode/ripgrep'); | ||
return await new Promise<string[]>((resolve) => { | ||
|
||
const sw = StopWatch.create(); | ||
|
||
const chunks: string[][] = []; | ||
const decoder = new TextDecoder(); | ||
const basePath = FileAccess.asFileUri('').fsPath; | ||
const process = spawn(rg.rgPath, ['-g', '**/*.css', '--files', '--no-ignore', basePath], {}); | ||
|
||
process.stdout.on('data', data => { | ||
const chunk = decoder.decode(data, { stream: true }); | ||
chunks.push(chunk.split('\n').filter(Boolean)); | ||
}); | ||
process.on('error', err => { | ||
this.logService.error('[CSS_DEV] FAILED to compute CSS data', err); | ||
resolve([]); | ||
}); | ||
process.on('close', () => { | ||
const result = chunks.flat().map(path => relative(basePath, path).replace(/\\/g, '/')).filter(Boolean).sort(); | ||
resolve(result); | ||
this.logService.info(`[CSS_DEV] DONE, ${result.length} css modules (${Math.round(sw.elapsed())}ms)`); | ||
}); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.