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

Remove non-used traductions #220

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
24 changes: 22 additions & 2 deletions rollup/rollup.language-packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as rollup from 'rollup'
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions'
import { dataToEsm } from '@rollup/pluginutils'
import { PackageJson } from 'type-fest'
import glob from 'fast-glob'
import * as fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'
Expand All @@ -15,11 +16,27 @@ const EXTENSIONS = ['', '.ts', '.js']

const BASE_DIR = path.resolve(__dirname, '..')
const LOC_PATH = path.resolve(BASE_DIR, 'vscode-loc')
const DIST_DIR = path.resolve(BASE_DIR, 'dist')
const NODE_MODULES_DIR = path.resolve(BASE_DIR, 'node_modules')
const MONACO_EDITOR_DIR = path.resolve(NODE_MODULES_DIR, './monaco-editor')
const MONACO_EDITOR_ESM_DIR = path.resolve(MONACO_EDITOR_DIR, './esm')

const locExtensions = fs.readdirSync(LOC_PATH, { withFileTypes: true })
.filter(f => f.isDirectory() && fs.existsSync(path.resolve(LOC_PATH, f.name, 'package.json')))
.map(f => f.name)

const vscodeModules = (await glob('**/vscode/src/**/*.js', {
cwd: DIST_DIR,
onlyFiles: true
})).map(fileName => /vscode\/src\/(.*).js$/.exec(fileName)![1]!)

const monacoModules = (await glob('**/*.js', {
cwd: MONACO_EDITOR_ESM_DIR,
onlyFiles: true
})).map(fileName => fileName.slice(0, -3))

const usedModules = new Set<string>([...vscodeModules, ...monacoModules])

export default rollup.defineConfig([
...locExtensions.map(name => (<rollup.RollupOptions>{
input: {
Expand Down Expand Up @@ -83,9 +100,12 @@ ${Object.entries(translationAssets).map(([id, assetRef]) => ` '${id}': new URL(
transform (code, id) {
if (!id.endsWith('.json')) return null

const parsed = JSON.parse(code)
const parsed = JSON.parse(code).contents
// remove keys that we don't use
const filtered = Object.fromEntries(Object.entries(parsed).filter(([key]) => usedModules.has(key)))

return {
code: dataToEsm(parsed.contents, {
code: dataToEsm(filtered, {
preferConst: true
}),
map: { mappings: '' }
Expand Down