@lingui/conf
Advanced tools
Comparing version 3.0.0-5 to 3.0.0-6
225
index.js
@@ -8,51 +8,31 @@ "use strict"; | ||
}); | ||
exports.getConfig = getConfig; | ||
exports.replaceRootDir = replaceRootDir; | ||
exports.getConfig = getConfig; | ||
exports.defaultConfig = void 0; | ||
exports.fallbackLanguageMigration = fallbackLanguageMigration; | ||
exports.catalogMigration = catalogMigration; | ||
exports.configValidation = exports.defaultConfig = void 0; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var path = require("path"); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var fs = require("fs"); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var chalk = require("chalk"); | ||
var _path = _interopRequireDefault(require("path")); | ||
var cosmiconfig = require("cosmiconfig"); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _require = require("jest-validate"), | ||
validate = _require.validate; | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _require2 = require("jest-regex-util"), | ||
replacePathSepForRegex = _require2.replacePathSepForRegex; | ||
var _cosmiconfig = _interopRequireDefault(require("cosmiconfig")); | ||
var NODE_MODULES = replacePathSepForRegex(path.sep + "node_modules" + path.sep); | ||
var _jestValidate = require("jest-validate"); | ||
function replaceRootDir(conf, rootDir) { | ||
var replace = function replace(s) { | ||
return s.replace("<rootDir>", rootDir); | ||
}; | ||
["srcPathDirs", "srcPathIgnorePatterns", "localeDir"].forEach(function (key) { | ||
var value = conf[key]; | ||
if (!value) {} else if (typeof value === "string") { | ||
conf[key] = replace(value); | ||
} else if (value.length) { | ||
conf[key] = value.map(replace); | ||
} | ||
}); | ||
conf.rootDir = rootDir; | ||
return conf; | ||
} | ||
var defaultConfig = { | ||
localeDir: "./locale", | ||
sourceLocale: "", | ||
fallbackLocale: "", | ||
pseudoLocale: "", | ||
srcPathDirs: ["<rootDir>"], | ||
srcPathIgnorePatterns: [NODE_MODULES], | ||
format: "po", | ||
rootDir: ".", | ||
catalogs: [{ | ||
path: _path.default.join("<rootDir>", "locale", "{locale}", "messages"), | ||
include: ["<rootDir>"], | ||
exclude: ["*/node_modules/*"] | ||
}], | ||
compileNamespace: "cjs", | ||
extractBabelOptions: { | ||
@@ -62,5 +42,43 @@ plugins: [], | ||
}, | ||
compileNamespace: "cjs" | ||
fallbackLocale: "", | ||
format: "po", | ||
locales: [], | ||
pseudoLocale: "", | ||
rootDir: ".", | ||
sourceLocale: "" | ||
}; | ||
exports.defaultConfig = defaultConfig; | ||
function configExists(path) { | ||
return path && _fs.default.existsSync(path); | ||
} | ||
function getConfig() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
cwd = _ref.cwd, | ||
configPath = _ref.configPath, | ||
_ref$skipValidation = _ref.skipValidation, | ||
skipValidation = _ref$skipValidation === void 0 ? false : _ref$skipValidation; | ||
var defaultRootDir = cwd || process.cwd(); | ||
var configExplorer = (0, _cosmiconfig.default)("lingui"); | ||
var result = configExists(configPath) ? configExplorer.loadSync(configPath) : configExplorer.searchSync(defaultRootDir); | ||
var userConfig = result ? result.config : {}; | ||
var config = (0, _objectSpread2.default)({}, defaultConfig, { | ||
rootDir: result ? _path.default.dirname(result.filepath) : defaultRootDir | ||
}, userConfig); | ||
if (!skipValidation) { | ||
(0, _jestValidate.validate)(config, configValidation); | ||
return pipe( // List config migrations from oldest to newest | ||
fallbackLanguageMigration, catalogMigration, // Custom validation | ||
validateLocales, // `replaceRootDir` should always be the last | ||
function (config) { | ||
return replaceRootDir(config, config.rootDir); | ||
})(config); | ||
} else { | ||
return replaceRootDir(config, config.rootDir); | ||
} | ||
} | ||
var exampleConfig = (0, _objectSpread2.default)({}, defaultConfig, { | ||
@@ -76,3 +94,12 @@ extractBabelOptions: { | ||
fallbackLanguage: function fallbackLanguage(config) { | ||
return " Option ".concat(chalk.bold("fallbackLanguage"), " was replaced by ").concat(chalk.bold("fallbackLocale"), "\n \n @lingui/cli now treats your current configuration as:\n {\n ").concat(chalk.bold('"fallbackLocale"'), ": ").concat(chalk.bold("\"".concat(config.fallbackLanguage, "\"")), "\n }\n \n Please update your configuration.\n "); | ||
return " Option ".concat(_chalk.default.bold("fallbackLanguage"), " was replaced by ").concat(_chalk.default.bold("fallbackLocale"), "\n \n @lingui/cli now treats your current configuration as:\n {\n ").concat(_chalk.default.bold('"fallbackLocale"'), ": ").concat(_chalk.default.bold("\"".concat(config.fallbackLanguage, "\"")), "\n }\n \n Please update your configuration.\n "); | ||
}, | ||
localeDir: function localeDir(config) { | ||
return " Option ".concat(_chalk.default.bold("localeDir"), " is deprecated. Configure source paths using ").concat(_chalk.default.bold("catalogs"), " instead.\n \n @lingui/cli now treats your current configuration as:\n \n {\n ").concat(_chalk.default.bold('"catalogs"'), ": ").concat(JSON.stringify(catalogMigration(config).catalogs, null, 2), "\n }\n \n Please update your configuration.\n "); | ||
}, | ||
srcPathDirs: function srcPathDirs(config) { | ||
return " Option ".concat(_chalk.default.bold("srcPathDirs"), " is deprecated. Configure source paths using ").concat(_chalk.default.bold("catalogs"), " instead.\n \n @lingui/cli now treats your current configuration as:\n \n {\n ").concat(_chalk.default.bold('"catalogs"'), ": ").concat(JSON.stringify(catalogMigration(config).catalogs, null, 2), "\n }\n \n Please update your configuration.\n "); | ||
}, | ||
srcPathIgnorePatterns: function srcPathIgnorePatterns(config) { | ||
return " Option ".concat(_chalk.default.bold("srcPathIgnorePatterns"), " is deprecated. Configure excluded source paths using ").concat(_chalk.default.bold("catalogs"), " instead.\n \n @lingui/cli now treats your current configuration as:\n \n {\n ").concat(_chalk.default.bold('"catalogs"'), ": ").concat(JSON.stringify(catalogMigration(config).catalogs, null, 2), "\n }\n \n Please update your configuration.\n "); | ||
} | ||
@@ -83,31 +110,105 @@ }; | ||
deprecatedConfig: deprecatedConfig, | ||
comment: "See https://lingui.js.org/ref/conf.html for a list of valid options" | ||
comment: "Documentation: https://lingui.js.org/ref/conf.html" | ||
}; | ||
exports.configValidation = configValidation; | ||
function configFilePathFromArgs() { | ||
var configIndex = process.argv.indexOf("--config"); | ||
function validateLocales(config) { | ||
if (!Array.isArray(config.locales) || !config.locales.length) { | ||
console.error("No locales defined!\n"); | ||
console.error("Add ".concat(_chalk.default.yellow("'locales'"), " to your configuration. See ").concat(_chalk.default.underline("https://lingui.js.org/ref/conf.html#locales"))); | ||
} | ||
if (configIndex >= 0 && process.argv.length > configIndex && fs.existsSync(process.argv[configIndex + 1])) { | ||
return process.argv[configIndex + 1]; | ||
return config; | ||
} | ||
function replaceRootDir(config, rootDir) { | ||
return function replaceDeep(value, rootDir) { | ||
var replace = function replace(s) { | ||
return s.replace("<rootDir>", rootDir); | ||
}; | ||
if (value == null) { | ||
return value; | ||
} else if (typeof value === "string") { | ||
return replace(value); | ||
} else if (Array.isArray(value)) { | ||
return value.map(function (item) { | ||
return replaceDeep(item, rootDir); | ||
}); | ||
} else if ((0, _typeof2.default)(value) === "object") { | ||
Object.keys(value).forEach(function (key) { | ||
var newKey = replaceDeep(key, rootDir); | ||
value[newKey] = replaceDeep(value[key], rootDir); | ||
if (key !== newKey) delete value[key]; | ||
}); | ||
} | ||
return value; | ||
}(config, rootDir); | ||
} | ||
/** | ||
* Replace fallbackLanguage with fallbackLocale | ||
* | ||
* Released in lingui-conf 0.9 | ||
* Remove anytime after 3.x | ||
*/ | ||
function fallbackLanguageMigration(config) { | ||
var fallbackLocale = config.fallbackLocale, | ||
fallbackLanguage = config.fallbackLanguage, | ||
newConfig = (0, _objectWithoutProperties2.default)(config, ["fallbackLocale", "fallbackLanguage"]); | ||
return (0, _objectSpread2.default)({}, newConfig, { | ||
fallbackLocale: fallbackLocale || fallbackLanguage || "" | ||
}); | ||
} | ||
/** | ||
* Replace localeDir, srcPathDirs and srcPathIgnorePatterns with catalogs | ||
* | ||
* Released in @lingui/conf 3.0 | ||
* Remove anytime after 4.x | ||
*/ | ||
function catalogMigration(config) { | ||
var localeDir = config.localeDir, | ||
srcPathDirs = config.srcPathDirs, | ||
srcPathIgnorePatterns = config.srcPathIgnorePatterns, | ||
newConfig = (0, _objectWithoutProperties2.default)(config, ["localeDir", "srcPathDirs", "srcPathIgnorePatterns"]); | ||
if (localeDir || srcPathDirs || srcPathIgnorePatterns) { | ||
// Replace missing values with default ones | ||
if (localeDir === undefined) localeDir = _path.default.join("<rootDir>", "locale", "{locale}", "messages"); | ||
if (srcPathDirs === undefined) srcPathDirs = ["<rootDir>"]; | ||
if (srcPathIgnorePatterns === undefined) srcPathIgnorePatterns = ["*/node_modules/*"]; | ||
var newLocaleDir = localeDir; | ||
if (localeDir.slice(-1) !== _path.default.sep) { | ||
newLocaleDir += "/"; | ||
} | ||
if (!Array.isArray(newConfig.catalogs)) { | ||
newConfig.catalogs = []; | ||
} | ||
newConfig.catalogs.push({ | ||
path: _path.default.join(newLocaleDir, "{locale}", "messages"), | ||
include: srcPathDirs, | ||
exclude: srcPathIgnorePatterns | ||
}); | ||
} | ||
return null; | ||
return newConfig; | ||
} | ||
function getConfig() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { | ||
cwd: null | ||
}, | ||
cwd = _ref.cwd; | ||
var pipe = function pipe() { | ||
for (var _len = arguments.length, functions = new Array(_len), _key = 0; _key < _len; _key++) { | ||
functions[_key] = arguments[_key]; | ||
} | ||
var configExplorer = cosmiconfig("lingui"); | ||
var defaultRootDir = cwd || process.cwd(); | ||
var configPath = configFilePathFromArgs(); | ||
var result = configPath == null ? configExplorer.searchSync(defaultRootDir) : configExplorer.loadSync(configPath); | ||
var config = (0, _objectSpread2.default)({}, defaultConfig, result ? result.config : {}); | ||
validate(config, configValidation); // Use deprecated fallbackLanguage, if defined | ||
config.fallbackLocale = config.fallbackLocale || config.fallbackLanguage || ""; | ||
var rootDir = result ? path.dirname(result.filepath) : defaultRootDir; | ||
return replaceRootDir(config, rootDir); | ||
} | ||
return function (args) { | ||
return functions.reduce(function (arg, fn) { | ||
return fn(arg); | ||
}, args); | ||
}; | ||
}; |
{ | ||
"name": "@lingui/conf", | ||
"version": "3.0.0-5", | ||
"version": "3.0.0-6", | ||
"description": "Get lingui configuration from package.json", | ||
@@ -21,7 +21,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.5", | ||
"chalk": "^2.3.0", | ||
"cosmiconfig": "^5.2.1", | ||
"jest-regex-util": "^24.3.0", | ||
"jest-validate": "^24.8.0", | ||
"pkg-conf": "^3.1.0" | ||
"jest-validate": "^24.8.0" | ||
}, | ||
@@ -28,0 +27,0 @@ "files": [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11245
4
181
1
+ Added@babel/runtime@^7.4.5
+ Added@babel/runtime@7.24.8(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedjest-regex-util@^24.3.0
- Removedpkg-conf@^3.1.0
- Removedfind-up@3.0.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedjest-regex-util@24.9.0(transitive)
- Removedload-json-file@5.3.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpify@4.0.1(transitive)
- Removedpkg-conf@3.1.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedtype-fest@0.3.1(transitive)