vscode-nls
Advanced tools
Comparing version 2.0.2 to 3.0.0-next.1
@@ -16,3 +16,17 @@ export interface Options { | ||
} | ||
export declare enum ExtensionKind { | ||
prePackaged = "prePackaged", | ||
marketPlace = "marketPlace", | ||
} | ||
export interface LocalizeInfo { | ||
key: string; | ||
comment: string[]; | ||
} | ||
export declare namespace LocalizeInfo { | ||
function is(value: any): value is LocalizeInfo; | ||
} | ||
export declare type KeyInfo = string | LocalizeInfo; | ||
export declare function loadMessageBundle(file?: string): LocalizeFunc; | ||
export declare function config(opt?: Options | string): LoadFunc; | ||
export declare function config(opt?: Options): LoadFunc; | ||
export declare function config(opt?: string): LoadFunc; | ||
export declare function config(opt: string, kind: ExtensionKind, root: string, outDir: string): LoadFunc; |
105
lib/main.js
@@ -6,7 +6,17 @@ /* -------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
var ExtensionKind; | ||
(function (ExtensionKind) { | ||
ExtensionKind["prePackaged"] = "prePackaged"; | ||
ExtensionKind["marketPlace"] = "marketPlace"; | ||
})(ExtensionKind = exports.ExtensionKind || (exports.ExtensionKind = {})); | ||
var _options = { locale: undefined, cacheLanguageResolution: true }; | ||
var _isPseudo = false; | ||
var _resolvedLanguage = null; | ||
var _extensionKind = undefined; | ||
var _root = undefined; | ||
var _outDir = undefined; | ||
var _resolvedLanguage = undefined; | ||
var _resolvedCacheLocation = undefined; | ||
var toString = Object.prototype.toString; | ||
@@ -25,2 +35,13 @@ function isDefined(value) { | ||
} | ||
function supportsLanguagePack() { | ||
if (_extensionKind === ExtensionKind.prePackaged) { | ||
return _options._resolvedLanguagePackExtensionLocation !== undefined && _root !== undefined && _outDir !== undefined; | ||
} | ||
else if (_extensionKind === ExtensionKind.marketPlace) { | ||
return _options._cacheRoot !== undefined && _root !== undefined && _outDir !== undefined; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
function format(message, args) { | ||
@@ -113,2 +134,30 @@ var result; | ||
} | ||
var LocalizeInfo; | ||
(function (LocalizeInfo) { | ||
function is(value) { | ||
var candidate = value; | ||
return candidate && isDefined(candidate.key) && isDefined(candidate.comment); | ||
} | ||
LocalizeInfo.is = is; | ||
})(LocalizeInfo = exports.LocalizeInfo || (exports.LocalizeInfo = {})); | ||
function mkdir(directory) { | ||
try { | ||
fs.mkdirSync(directory); | ||
} | ||
catch (err) { | ||
if (err.code === 'EEXIST') { | ||
return; | ||
} | ||
else if (err.code === 'ENOENT') { | ||
var parent = path.dirname(directory); | ||
if (parent !== directory) { | ||
mkdir(parent); | ||
fs.mkdir(directory); | ||
} | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
function loadMessageBundle(file) { | ||
@@ -119,3 +168,46 @@ if (!file) { | ||
else { | ||
var resolvedFile = resolveLanguage(file); | ||
var resolvedFile = void 0; | ||
// We have a language pack test locale | ||
if (_options.locale === 'lptest' && supportsLanguagePack()) { | ||
if (_resolvedCacheLocation === undefined) { | ||
try { | ||
var packageJson = require(path.join(_root, 'package.json')); | ||
var extensionName = packageJson.name; | ||
if (extensionName) { | ||
var cacheLocation = path.join(_options._resolvedLanguagePackExtensionLocation, extensionName); | ||
if (fs.existsSync(cacheLocation)) { | ||
_resolvedCacheLocation = cacheLocation; | ||
} | ||
else { | ||
mkdir(cacheLocation); | ||
var metaData = require(path.join(_root, _outDir, 'nls.metadata.json')); | ||
for (var file_1 in metaData.content) { | ||
var entry = metaData.content[file_1]; | ||
var cacheFilePath = path.join(cacheLocation, _outDir, file_1 + '.json'); | ||
mkdir(path.dirname(cacheFilePath)); | ||
var content = []; | ||
for (var message in entry.messages) { | ||
content.push('\uFF3B' + message.replace(/[aouei]/g, '$&$&') + '\uFF3D'); | ||
} | ||
fs.writeFileSync(cacheFilePath, content, 'utf8'); | ||
} | ||
_resolvedCacheLocation = cacheLocation; | ||
} | ||
} | ||
} | ||
catch (err) { | ||
_resolvedCacheLocation = null; | ||
// Fall through; | ||
} | ||
} | ||
if (isString(_resolvedCacheLocation)) { | ||
resolvedFile = path.join(_resolvedCacheLocation, file.substr(_root.length + 1)); | ||
} | ||
} | ||
else { | ||
resolvedFile = resolveLanguage(file); | ||
} | ||
if (!resolvedFile) { | ||
return localize; | ||
} | ||
try { | ||
@@ -143,3 +235,3 @@ var json = require(resolvedFile); | ||
exports.loadMessageBundle = loadMessageBundle; | ||
function config(opt) { | ||
function config(opt, kind, root, outDir) { | ||
var options; | ||
@@ -157,6 +249,11 @@ if (isString(opt)) { | ||
} | ||
if (kind && root && path.isAbsolute(root)) { | ||
_extensionKind = kind; | ||
_root = root; | ||
_outDir = outDir; | ||
} | ||
if (options) { | ||
if (isString(options.locale)) { | ||
_options.locale = options.locale.toLowerCase(); | ||
_resolvedLanguage = null; | ||
_resolvedLanguage = undefined; | ||
} | ||
@@ -163,0 +260,0 @@ if (isBoolean(options.cacheLanguageResolution)) { |
{ | ||
"name": "vscode-nls", | ||
"version": "2.0.2", | ||
"version": "3.0.0-next.1", | ||
"description": "NPM module to externalize and localize VSCode extensions", | ||
@@ -28,2 +28,2 @@ "author": "Microsoft Corporation", | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16332
292
2
4