@spaceflow/core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -5678,9 +5678,9 @@ const SWAGGER_API_MODEL_PROPERTIES_ARRAY = "swagger/apiModelPropertiesArray";
|
|
|
5678
5678
|
}
|
|
5679
5679
|
|
|
5680
5680
|
;// CONCATENATED MODULE: ./src/locales/zh-cn/translation.json
|
|
5681
|
-
var translation_namespaceObject = JSON.parse('{"common.executionFailed":"执行失败: {{error}}","common.stackTrace":"\\n堆栈信息:\\n{{stack}}","common.options.dryRun":"仅打印将要执行的操作,不实际执行","common.options.verbose":"显示详细日志 (-v: 基本日志, -vv: 详细日志)","common.options.verboseDebug":"显示详细日志 (-v: 基本日志, -vv: 详细日志, -vvv: 调试日志)","common.options.ci":"是否在 CI 环境中运行","config.parseWarning":"警告: 无法解析配置文件 {{path}}","config.validationFailed":"Spaceflow 配置验证失败:\\n{{errors}}","extensionLoader.loadFailed":"⚠️ 加载 Extension {{name}} 失败: {{error}}"}')
|
|
5681
|
+
var translation_namespaceObject = JSON.parse('{"common.executionFailed":"执行失败: {{error}}","common.stackTrace":"\\n堆栈信息:\\n{{stack}}","common.options.dryRun":"仅打印将要执行的操作,不实际执行","common.options.verbose":"显示详细日志 (-v: 基本日志, -vv: 详细日志)","common.options.verboseDebug":"显示详细日志 (-v: 基本日志, -vv: 详细日志, -vvv: 调试日志)","common.options.ci":"是否在 CI 环境中运行","config.parseWarning":"警告: 无法解析配置文件 {{path}}","config.validationFailed":"Spaceflow 配置验证失败:\\n{{errors}}","extensionLoader.loadFailed":"⚠️ 加载 Extension {{name}} 失败: {{error}}","extensionLoader.autoInstalling":"📦 自动安装缺失的扩展: {{packages}}","extensionLoader.autoInstallFailed":"⚠️ 自动安装扩展失败,请手动执行 spaceflow install"}')
|
|
5682
5682
|
;// CONCATENATED MODULE: ./src/locales/en/translation.json
|
|
5683
|
-
var en_translation_namespaceObject = JSON.parse('{"common.executionFailed":"Execution failed: {{error}}","common.stackTrace":"\\nStack trace:\\n{{stack}}","common.options.dryRun":"Only print actions without executing","common.options.verbose":"Show verbose logs (-v: basic, -vv: detailed)","common.options.verboseDebug":"Show verbose logs (-v: basic, -vv: detailed, -vvv: debug)","common.options.ci":"Run in CI environment","config.parseWarning":"Warning: unable to parse config file {{path}}","config.validationFailed":"Spaceflow config validation failed:\\n{{errors}}","extensionLoader.loadFailed":"⚠️ Failed to load Extension {{name}}: {{error}}"}')
|
|
5683
|
+
var en_translation_namespaceObject = JSON.parse('{"common.executionFailed":"Execution failed: {{error}}","common.stackTrace":"\\nStack trace:\\n{{stack}}","common.options.dryRun":"Only print actions without executing","common.options.verbose":"Show verbose logs (-v: basic, -vv: detailed)","common.options.verboseDebug":"Show verbose logs (-v: basic, -vv: detailed, -vvv: debug)","common.options.ci":"Run in CI environment","config.parseWarning":"Warning: unable to parse config file {{path}}","config.validationFailed":"Spaceflow config validation failed:\\n{{errors}}","extensionLoader.loadFailed":"⚠️ Failed to load Extension {{name}}: {{error}}","extensionLoader.autoInstalling":"📦 Auto-installing missing extensions: {{packages}}","extensionLoader.autoInstallFailed":"⚠️ Auto-install failed, please run spaceflow install manually"}')
|
|
5684
5684
|
;// CONCATENATED MODULE: ./src/shared/i18n/i18n.ts
|
|
5685
5685
|
|
|
5686
5686
|
// 兼容 CJS/ESM 混合环境
|
|
@@ -5689,16 +5689,30 @@ const i18next = __rspack_external_i18next["default"] || __rspack_external_i18nex
|
|
|
5689
5689
|
|
|
5690
5690
|
|
|
5691
5691
|
/** 默认命名空间 */ const DEFAULT_NS = "translation";
|
|
5692
|
-
/**
|
|
5692
|
+
/** globalThis 上的 key,确保多份 core 实例共享同一个 i18n 状态 */ const GLOBAL_I18N_KEY = "__spaceflow_i18n__";
|
|
5693
|
+
/**
|
|
5694
|
+
* 获取全局 i18n 状态(单例)
|
|
5695
|
+
* 无论有几份 @spaceflow/core 实例,都共享同一个 i18next 实例
|
|
5696
|
+
*/ function getGlobalState() {
|
|
5697
|
+
const g = globalThis;
|
|
5698
|
+
if (!g[GLOBAL_I18N_KEY]) {
|
|
5699
|
+
g[GLOBAL_I18N_KEY] = {
|
|
5700
|
+
instance: i18next,
|
|
5701
|
+
initialized: false
|
|
5702
|
+
};
|
|
5703
|
+
}
|
|
5704
|
+
return g[GLOBAL_I18N_KEY];
|
|
5705
|
+
}
|
|
5693
5706
|
/**
|
|
5694
5707
|
* 初始化 i18n
|
|
5695
5708
|
* 当提供 resources 且无后端加载器时,i18next.init() 同步完成
|
|
5696
5709
|
* @param lang 指定语言,不传则自动检测
|
|
5697
5710
|
*/ function initI18n(lang) {
|
|
5698
|
-
|
|
5711
|
+
const state = getGlobalState();
|
|
5712
|
+
if (state.initialized) return;
|
|
5699
5713
|
const lng = lang || detectLocale();
|
|
5700
5714
|
// i18next v25+ 移除了 initSync,但提供内联 resources 时 init() 同步完成
|
|
5701
|
-
void
|
|
5715
|
+
void state.instance.init({
|
|
5702
5716
|
lng,
|
|
5703
5717
|
fallbackLng: "zh-CN",
|
|
5704
5718
|
defaultNS: DEFAULT_NS,
|
|
@@ -5723,42 +5737,45 @@ const i18next = __rspack_external_i18next["default"] || __rspack_external_i18nex
|
|
|
5723
5737
|
// i18next v25.8+ 会在 init 时输出 locize.com 推广日志
|
|
5724
5738
|
showSupportNotice: false
|
|
5725
5739
|
});
|
|
5726
|
-
initialized = true;
|
|
5740
|
+
state.initialized = true;
|
|
5727
5741
|
}
|
|
5728
5742
|
/**
|
|
5729
5743
|
* 重置 i18n 状态(仅用于测试)
|
|
5730
5744
|
*/ function resetI18n() {
|
|
5731
|
-
|
|
5745
|
+
const state = getGlobalState();
|
|
5746
|
+
state.initialized = false;
|
|
5732
5747
|
}
|
|
5733
5748
|
/**
|
|
5734
5749
|
* 翻译函数
|
|
5735
|
-
*
|
|
5750
|
+
* 通过 globalThis 共享 i18next 实例,确保多份 core 实例下翻译一致
|
|
5736
5751
|
* @param key 翻译 key
|
|
5737
5752
|
* @param options 插值参数
|
|
5738
5753
|
*/ function i18n_t(key, options) {
|
|
5739
|
-
|
|
5754
|
+
const state = getGlobalState();
|
|
5755
|
+
if (!state.initialized) {
|
|
5740
5756
|
initI18n();
|
|
5741
5757
|
}
|
|
5742
|
-
return
|
|
5758
|
+
return state.instance.t(key, options);
|
|
5743
5759
|
}
|
|
5744
5760
|
/**
|
|
5745
5761
|
* 为外部 Extension 注册语言资源
|
|
5746
5762
|
* @param ns 命名空间(通常为 Extension name)
|
|
5747
5763
|
* @param resources 语言资源,key 为语言代码,值为翻译对象
|
|
5748
5764
|
*/ function addLocaleResources(ns, resources) {
|
|
5749
|
-
|
|
5765
|
+
const state = getGlobalState();
|
|
5766
|
+
if (!state.initialized) {
|
|
5750
5767
|
initI18n();
|
|
5751
5768
|
}
|
|
5752
5769
|
for (const [lng, translations] of Object.entries(resources)){
|
|
5753
|
-
|
|
5770
|
+
state.instance.addResourceBundle(lng, ns, translations, true, true);
|
|
5754
5771
|
}
|
|
5755
|
-
if (!
|
|
5756
|
-
|
|
5772
|
+
if (!state.instance.options.ns) {
|
|
5773
|
+
state.instance.options.ns = [
|
|
5757
5774
|
DEFAULT_NS,
|
|
5758
5775
|
ns
|
|
5759
5776
|
];
|
|
5760
|
-
} else if (Array.isArray(
|
|
5761
|
-
|
|
5777
|
+
} else if (Array.isArray(state.instance.options.ns) && !state.instance.options.ns.includes(ns)) {
|
|
5778
|
+
state.instance.options.ns.push(ns);
|
|
5762
5779
|
}
|
|
5763
5780
|
}
|
|
5764
5781
|
|
|
@@ -6068,7 +6085,6 @@ var external_zod_ = __webpack_require__(971);
|
|
|
6068
6085
|
}
|
|
6069
6086
|
// 写入文件
|
|
6070
6087
|
external_fs_.writeFileSync(outputPath, JSON.stringify(fullSchema, null, 2), "utf-8");
|
|
6071
|
-
console.log(`✅ JSON Schema 已生成: ${outputPath}`);
|
|
6072
6088
|
// 自动添加到 .gitignore
|
|
6073
6089
|
this.addToGitignore(dir, external_path_.basename(outputPath));
|
|
6074
6090
|
}
|