-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[plugin] remove raw package.json model from metadata
It accumulates to a lot of data with many plugins and can block the connection leading to slow start up time and unresponsive UI. Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
- Loading branch information
Showing
17 changed files
with
167 additions
and
106 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
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
71 changes: 71 additions & 0 deletions
71
packages/plugin-ext/src/hosted/node/plugin-manifest-loader.ts
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,71 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
// tslint:disable:no-any | ||
|
||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
|
||
const NLS_REGEX = /^%([\w\d.-]+)%$/i; | ||
|
||
export async function loadManifest(pluginPath: string): Promise<any> { | ||
const [manifest, translations] = await Promise.all([ | ||
fs.readJson(path.join(pluginPath, 'package.json')), | ||
loadTranslations(pluginPath) | ||
]); | ||
return manifest && translations && Object.keys(translations).length ? | ||
localize(manifest, translations) : | ||
manifest; | ||
} | ||
|
||
async function loadTranslations(pluginPath: string): Promise<any> { | ||
try { | ||
return await fs.readJson(path.join(pluginPath, 'package.nls.json')); | ||
} catch (e) { | ||
if (e.code !== 'ENOENT') { | ||
throw e; | ||
} | ||
return {}; | ||
} | ||
} | ||
|
||
function localize(value: any, translations: { | ||
[key: string]: string | ||
}): any { | ||
if (typeof value === 'string') { | ||
const match = NLS_REGEX.exec(value); | ||
return match && translations[match[1]] || value; | ||
} | ||
if (Array.isArray(value)) { | ||
const result = []; | ||
for (const item of value) { | ||
result.push(localize(item, translations)); | ||
} | ||
return result; | ||
} | ||
if (value === null) { | ||
return value; | ||
} | ||
if (typeof value === 'object') { | ||
const result: { [key: string]: any } = {}; | ||
// tslint:disable-next-line:forin | ||
for (const propertyName in value) { | ||
result[propertyName] = localize(value[propertyName], translations); | ||
} | ||
return result; | ||
} | ||
return value; | ||
} |
Oops, something went wrong.