@4399ywkf/core 5.1.6 → 5.3.1

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.
@@ -1,5 +1,5 @@
1
- import { Q as YwkfPlugin, e as PluginHooks, Y as YwkfConfig, f as PluginConfig, U as RouteItem } from '../schema-Ba1qfYz_.js';
2
- export { y as BuildHooks, C as CodeInjection, V as DefinePlugin, F as GeneratedFile, G as GeneratorContext, J as GeneratorHooks, W as PluginAPI, K as PluginContext, X as PluginLogger, L as RouterHooks, N as RuntimeHooks } from '../schema-Ba1qfYz_.js';
1
+ import { Q as YwkfPlugin, e as PluginHooks, Y as YwkfConfig, f as PluginConfig, U as RouteItem } from '../schema-Ade9gA3U.js';
2
+ export { y as BuildHooks, C as CodeInjection, V as DefinePlugin, F as GeneratedFile, G as GeneratorContext, J as GeneratorHooks, W as PluginAPI, K as PluginContext, X as PluginLogger, L as RouterHooks, N as RuntimeHooks } from '../schema-Ade9gA3U.js';
3
3
  import { Configuration } from '@rspack/core';
4
4
  import { a as AppConfig, P as ProviderConfig } from '../types-ZJhd87ue.js';
5
5
  import 'react';
@@ -1,5 +1,5 @@
1
1
  import { Configuration } from '@rspack/core';
2
- import { Y as YwkfConfig } from '../schema-Ba1qfYz_.js';
2
+ import { Y as YwkfConfig } from '../schema-Ade9gA3U.js';
3
3
  import '../types-ZJhd87ue.js';
4
4
  import 'react';
5
5
  import 'react-router';
@@ -763,7 +763,7 @@ function scaffoldI18nRc(cwd, localesDir, defaultLocale, locales, logger) {
763
763
  const filePath = join3(cwd, ".i18nrc.js");
764
764
  if (existsSync3(filePath)) return;
765
765
  const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `"${l}"`).join(", ");
766
- const content = `const { defineConfig } = require("@lobehub/i18n-cli");
766
+ const content = `const { defineConfig } = require("@4399ywkf/i18n");
767
767
 
768
768
  module.exports = defineConfig({
769
769
  entry: "${localesDir}/${defaultLocale}",
@@ -773,7 +773,7 @@ module.exports = defineConfig({
773
773
  });
774
774
  `;
775
775
  writeFileSync2(filePath, content, "utf-8");
776
- logger.info("\u5DF2\u751F\u6210\u7FFB\u8BD1\u914D\u7F6E: .i18nrc.js\uFF08@lobehub/i18n-cli\uFF09");
776
+ logger.info("\u5DF2\u751F\u6210\u7FFB\u8BD1\u914D\u7F6E: .i18nrc.js\uFF08\u9700\u5B89\u88C5 @4399ywkf/i18n\uFF09");
777
777
  }
778
778
  function scaffoldLocaleJsonDirs(cwd, localesDir, locales, defaultLocale, namespaces, logger) {
779
779
  const baseDir = join3(cwd, localesDir);
@@ -874,7 +874,7 @@ function createMockMiddleware(mockPath, options) {
874
874
  scanMockFiles(mockPath);
875
875
  return async (_req, _res, next) => {
876
876
  if (delay > 0) {
877
- await new Promise((resolve3) => setTimeout(resolve3, delay));
877
+ await new Promise((resolve4) => setTimeout(resolve4, delay));
878
878
  }
879
879
  next();
880
880
  };
@@ -1828,11 +1828,11 @@ var zustandPlugin = createPlugin((options = {}) => ({
1828
1828
  const hooks = {
1829
1829
  modifyRspackConfig(rspackConfig) {
1830
1830
  logger.info("Zustand \u5DF2\u542F\u7528");
1831
- const resolve3 = rspackConfig.resolve || {};
1832
- const alias = resolve3.alias || {};
1831
+ const resolve4 = rspackConfig.resolve || {};
1832
+ const alias = resolve4.alias || {};
1833
1833
  alias["@store"] = storePath;
1834
- resolve3.alias = alias;
1835
- rspackConfig.resolve = resolve3;
1834
+ resolve4.alias = alias;
1835
+ rspackConfig.resolve = resolve4;
1836
1836
  return rspackConfig;
1837
1837
  },
1838
1838
  generateFiles(_ctx) {
@@ -3016,6 +3016,69 @@ var YwkfGeneratorPlugin = class {
3016
3016
  }
3017
3017
  };
3018
3018
 
3019
+ // src/rspack/client-env.ts
3020
+ import { existsSync as existsSync12, readFileSync as readFileSync4 } from "fs";
3021
+ import { resolve as resolve3 } from "path";
3022
+ import dotenv from "dotenv";
3023
+ var FRAMEWORK_ENV_KEYS = [
3024
+ "APP_CNAME",
3025
+ "APP_HOST",
3026
+ "APP_MODE",
3027
+ "APP_NAME",
3028
+ "APP_PORT",
3029
+ "DEBUG",
3030
+ "NODE_ENV",
3031
+ "OUTPUT_PATH",
3032
+ "PUBLIC_PATH",
3033
+ "YWKF_BUILD_ID",
3034
+ "YWKF_PREFIX_CLS"
3035
+ ];
3036
+ var DEFAULT_EXPOSE_PREFIXES = ["YWKF_PUBLIC_", "NEXT_PUBLIC_"];
3037
+ var SECRET_KEY_PATTERN = /TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|PRIVATE|AUTH|ACCESS_KEY|API_KEY|SIGNING_KEY/i;
3038
+ var SECRET_VALUE_PATTERN = /^(sntry[su]_|sk-|ghp_|gho_|ghu_|ghs_|github_pat_|glpat-|xox[abprs]-|AKIA|ya29\.)/;
3039
+ function readEnvFileKeys(filePath) {
3040
+ if (!existsSync12(filePath)) return [];
3041
+ try {
3042
+ return Object.keys(dotenv.parse(readFileSync4(filePath, "utf-8")));
3043
+ } catch {
3044
+ return [];
3045
+ }
3046
+ }
3047
+ function collectClientEnvKeys(options) {
3048
+ const { cwd, env = {}, mode = process.env.APP_MODE || "development" } = options;
3049
+ const keys = new Set(FRAMEWORK_ENV_KEYS);
3050
+ const files = [
3051
+ env.publicEnvFile ?? "config/env/.env.public",
3052
+ ".env.public",
3053
+ ".env",
3054
+ `${env.envDir ?? "config/env"}/.env.${mode}`,
3055
+ `.env.${mode}`
3056
+ ];
3057
+ for (const file of files) {
3058
+ for (const key of readEnvFileKeys(resolve3(cwd, file))) keys.add(key);
3059
+ }
3060
+ for (const key of env.expose ?? []) keys.add(key);
3061
+ return keys;
3062
+ }
3063
+ function buildClientEnv(options) {
3064
+ const { cwd, env = {}, mode, processEnv = process.env } = options;
3065
+ const prefixes = env.exposePrefixes ?? DEFAULT_EXPOSE_PREFIXES;
3066
+ const allowed = collectClientEnvKeys({ cwd, env, mode });
3067
+ const result = {};
3068
+ const dropped = [];
3069
+ for (const [key, value] of Object.entries(processEnv)) {
3070
+ if (value === void 0) continue;
3071
+ const isAllowed = allowed.has(key) || prefixes.some((prefix) => key.startsWith(prefix));
3072
+ if (!isAllowed) continue;
3073
+ if (SECRET_KEY_PATTERN.test(key) || SECRET_VALUE_PATTERN.test(value)) {
3074
+ dropped.push(key);
3075
+ continue;
3076
+ }
3077
+ result[key] = value;
3078
+ }
3079
+ return { env: result, dropped };
3080
+ }
3081
+
3019
3082
  // src/rspack/base.ts
3020
3083
  var require2 = createRequire(import.meta.url);
3021
3084
  var __dirname = dirname(fileURLToPath(import.meta.url));
@@ -3034,6 +3097,12 @@ function createBaseConfig(config, cwd, options = {}) {
3034
3097
  const { resolveApp } = createPathResolver(cwd);
3035
3098
  const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
3036
3099
  const buildId = resolveYwkfBuildId(appName);
3100
+ const { env: clientEnv, dropped: droppedEnvKeys } = buildClientEnv({ cwd, env: config.env });
3101
+ if (droppedEnvKeys.length > 0) {
3102
+ console.warn(
3103
+ `[ywkf] \u4EE5\u4E0B\u73AF\u5883\u53D8\u91CF\u7591\u4F3C\u5BC6\u94A5,\u5DF2\u4ECE\u5BA2\u6237\u7AEF\u4EA7\u7269\u4E2D\u5254\u9664:${droppedEnvKeys.join(", ")}\u3002\u5982\u786E\u4E3A\u516C\u5F00\u914D\u7F6E,\u8BF7\u91CD\u547D\u540D\u6216\u8C03\u6574 env.expose\u3002`
3104
+ );
3105
+ }
3037
3106
  const ywkfOutputDir = resolveApp(".ywkf");
3038
3107
  const defaultAlias = {
3039
3108
  "@": resolveApp("src"),
@@ -3158,7 +3227,10 @@ function createBaseConfig(config, cwd, options = {}) {
3158
3227
  }),
3159
3228
  new rspack2.DefinePlugin({
3160
3229
  "globalThis.__YWKF_BUILD_ID__": JSON.stringify(buildId),
3161
- "process.env": JSON.stringify(process.env)
3230
+ // 只内联白名单内的公开配置。整包 process.env 会把构建机环境(CI 凭据、内网地址)
3231
+ // 写进公网可下载的产物,见 client-env.ts。外层括号不可省:该值以 `{` 开头,
3232
+ // `() => process.env.X` 会被替换成 `() => {…}` 而当成函数块体,导致整条 chunk 语法失败。
3233
+ "process.env": `(${JSON.stringify(clientEnv)})`
3162
3234
  }),
3163
3235
  new rspack2.HtmlRspackPlugin({
3164
3236
  template: resolveApp(html.template ?? "public/index.html"),