@infly/libs 2.2.9 → 2.2.11

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,56 +1,56 @@
1
1
  /**
2
2
  * Webpack require.context 适配器。
3
- * 自动导出目录下所有文件
4
- * @param {Function} requireContext - require.context 返回的函数
5
- * @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
6
- *
7
- * @example
8
- * // 在 components/Dialog/index.js 中使用
3
+ * 自动导出目录下所有文件
4
+ * @param {Function} requireContext - require.context 返回的函数
5
+ * @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
6
+ *
7
+ * @example
8
+ * // 在 components/Dialog/index.js 中使用
9
9
  * import { autoExportFiles } from '@infly/libs/adapters/webpack/auto-export';
10
- * const components = autoExportFiles(require.context('./', false, /\.vue$/));
11
- * Object.keys(components).forEach(name => {
12
- * module.exports[name] = components[name];
13
- * });
14
- *
15
- * // 或者直接一行
16
- * Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
17
- */
18
- function autoExportFiles(requireContext) {
19
- if (!requireContext || typeof requireContext !== 'function') {
20
- console.error('autoExportFiles: requireContext 必须是 require.context 返回的函数');
21
- return {};
22
- }
23
-
24
- const exports = {};
25
-
26
- requireContext.keys().forEach(fileName => {
27
- // 跳过 index 文件自身
28
- if (fileName.includes('index')) return;
29
-
30
- const componentConfig = requireContext(fileName);
31
- const componentName = fileName
32
- .replace(/^\.\//, '') // 移除 './'
33
- .replace(/\.\w+$/, ''); // 移除扩展名
34
-
35
- exports[componentName] = componentConfig.default || componentConfig;
36
- });
37
-
38
- return exports;
39
- }
40
-
41
- /**
42
- * 简化版:直接挂载到 module.exports
43
- * @param {Function} requireContext - require.context 返回的函数
44
- * @param {Object} targetExports - 目标导出对象(通常是 module.exports)
45
- *
46
- * @example
47
- * // 在 components/Dialog/index.js 中使用
10
+ * const components = autoExportFiles(require.context('./', false, /\.vue$/));
11
+ * Object.keys(components).forEach(name => {
12
+ * module.exports[name] = components[name];
13
+ * });
14
+ *
15
+ * // 或者直接一行
16
+ * Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
17
+ */
18
+ function autoExportFiles(requireContext) {
19
+ if (!requireContext || typeof requireContext !== 'function') {
20
+ console.error('autoExportFiles: requireContext 必须是 require.context 返回的函数');
21
+ return {};
22
+ }
23
+
24
+ const exports = {};
25
+
26
+ requireContext.keys().forEach(fileName => {
27
+ // 跳过 index 文件自身
28
+ if (fileName.includes('index')) return;
29
+
30
+ const componentConfig = requireContext(fileName);
31
+ const componentName = fileName
32
+ .replace(/^\.\//, '') // 移除 './'
33
+ .replace(/\.\w+$/, ''); // 移除扩展名
34
+
35
+ exports[componentName] = componentConfig.default || componentConfig;
36
+ });
37
+
38
+ return exports;
39
+ }
40
+
41
+ /**
42
+ * 简化版:直接挂载到 module.exports
43
+ * @param {Function} requireContext - require.context 返回的函数
44
+ * @param {Object} targetExports - 目标导出对象(通常是 module.exports)
45
+ *
46
+ * @example
47
+ * // 在 components/Dialog/index.js 中使用
48
48
  * import { autoExportToModule } from '@infly/libs/adapters/webpack/auto-export';
49
- * autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
50
- */
51
- function autoExportToModule(requireContext, targetExports) {
52
- const files = autoExportFiles(requireContext);
53
- Object.assign(targetExports, files);
54
- }
55
-
56
- export { autoExportFiles, autoExportToModule };
49
+ * autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
50
+ */
51
+ function autoExportToModule(requireContext, targetExports) {
52
+ const files = autoExportFiles(requireContext);
53
+ Object.assign(targetExports, files);
54
+ }
55
+
56
+ export { autoExportFiles, autoExportToModule };
@@ -36,7 +36,7 @@ const {
36
36
  pullSingleDirFromBranch
37
37
  } = require("../../script/git-automation");
38
38
  const { resolveSiblingAppDeps } = require("../build-utils/deps");
39
- const { resolveGitWorktreeRoot } = require("../../script/git-automation/git-utils");
39
+ const { findOuterWorkspaceRoot, resolveGitWorktreeRoot } = require("../../script/git-automation/git-utils");
40
40
 
41
41
  const scriptEvent = process.env.npm_lifecycle_event;
42
42
  const isBuilZipScript = process.env.npm_lifecycle_event;
@@ -50,6 +50,8 @@ const projectRoot = process.cwd();
50
50
  // 构建配置可以位于主仓中的子目录(例如合并后的 level/)。配置、产物仍以
51
51
  // projectRoot 为基准,只有 Git 检查与分支更新定位到实际工作树根目录。
52
52
  const projectGitRoot = resolveGitWorktreeRoot(projectRoot);
53
+ const isEmbeddedProject = projectGitRoot !== projectRoot;
54
+ const workspaceRoot = isEmbeddedProject ? findOuterWorkspaceRoot(projectGitRoot) : "";
53
55
 
54
56
  // 依赖包的配置
55
57
  const originConfigPath = currentProjectFileResolve("template-version-config.json"); // 模板项目文件
@@ -817,14 +819,17 @@ async function beforeBuild() {
817
819
  return;
818
820
  }
819
821
 
820
- const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, projectName);
822
+ const sourceRepoName = isEmbeddedProject ? path.basename(projectGitRoot) : projectName;
823
+ const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
821
824
 
822
825
  if (currentProjectStatus.hasUncommitted) {
823
826
  console.log(global.logColor.error, `\n❌ 当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
824
827
  process.exit(1);
825
828
  }
826
829
 
827
- const currentProjectUpdateResult = pullSingleDirFromBranch(projectGitRoot, projectName, targetBranch);
830
+ const currentProjectUpdateResult = pullSingleDirFromBranch(
831
+ projectGitRoot, sourceRepoName, targetBranch, isEmbeddedProject ? projectName : ""
832
+ );
828
833
 
829
834
  if (!currentProjectUpdateResult.success) {
830
835
  console.log(global.logColor.error, `\n❌ 当前项目切换到 ${targetBranch} 分支失败,请检查`);
@@ -843,7 +848,7 @@ async function beforeBuild() {
843
848
  }
844
849
 
845
850
  if (process.env.INFLY_SKIP_PACKAGES_UPDATE !== "1") {
846
- await checkAndUpdatePackages(undefined, "master");
851
+ await checkAndUpdatePackages(undefined, "master", isEmbeddedProject ? projectName : "", workspaceRoot);
847
852
  }
848
853
 
849
854
  // 5. 检查并更新兄弟 app 依赖(通过 build config 中的 alias 推断,无需硬编码 app 名称)
@@ -1,57 +1,57 @@
1
- const { spawn } = require("child_process");
2
-
3
- function run(command, args, options = {}) {
4
- return new Promise((resolve, reject) => {
5
- const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
6
- // Avoid DEP0190: when shell=true, pass command+args as single string
7
- const [cmd, cmdArgs] = useShell
8
- ? [[command, ...args].join(" "), []]
9
- : [command, args];
10
- const child = spawn(cmd, cmdArgs, {
11
- cwd: options.cwd || process.cwd(),
12
- env: {
13
- ...process.env,
14
- ...(options.env || {})
15
- },
16
- stdio: options.stdio || "inherit",
17
- shell: useShell
18
- });
19
-
20
- child.on("close", (code) => {
21
- if (code === 0) {
22
- resolve();
23
- } else {
24
- reject(new Error(`${command} ${args.join(" ")} failed with exit code ${code}`));
25
- }
26
- });
27
-
28
- child.on("error", reject);
29
- });
30
- }
31
-
32
- function spawnBackground(command, args, options = {}) {
33
- const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
34
- const [cmd, cmdArgs] = useShell
35
- ? [[command, ...args].join(" "), []]
36
- : [command, args];
37
- const child = spawn(cmd, cmdArgs, {
38
- cwd: options.cwd || process.cwd(),
39
- env: {
40
- ...process.env,
41
- ...(options.env || {})
42
- },
43
- stdio: options.stdio || "inherit",
44
- shell: useShell
45
- });
46
-
47
- child.on("error", (error) => {
48
- console.error(error.message);
49
- });
50
-
51
- return child;
52
- }
53
-
54
- module.exports = {
55
- run,
56
- spawnBackground
57
- };
1
+ const { spawn } = require("child_process");
2
+
3
+ function run(command, args, options = {}) {
4
+ return new Promise((resolve, reject) => {
5
+ const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
6
+ // Avoid DEP0190: when shell=true, pass command+args as single string
7
+ const [cmd, cmdArgs] = useShell
8
+ ? [[command, ...args].join(" "), []]
9
+ : [command, args];
10
+ const child = spawn(cmd, cmdArgs, {
11
+ cwd: options.cwd || process.cwd(),
12
+ env: {
13
+ ...process.env,
14
+ ...(options.env || {})
15
+ },
16
+ stdio: options.stdio || "inherit",
17
+ shell: useShell
18
+ });
19
+
20
+ child.on("close", (code) => {
21
+ if (code === 0) {
22
+ resolve();
23
+ } else {
24
+ reject(new Error(`${command} ${args.join(" ")} failed with exit code ${code}`));
25
+ }
26
+ });
27
+
28
+ child.on("error", reject);
29
+ });
30
+ }
31
+
32
+ function spawnBackground(command, args, options = {}) {
33
+ const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
34
+ const [cmd, cmdArgs] = useShell
35
+ ? [[command, ...args].join(" "), []]
36
+ : [command, args];
37
+ const child = spawn(cmd, cmdArgs, {
38
+ cwd: options.cwd || process.cwd(),
39
+ env: {
40
+ ...process.env,
41
+ ...(options.env || {})
42
+ },
43
+ stdio: options.stdio || "inherit",
44
+ shell: useShell
45
+ });
46
+
47
+ child.on("error", (error) => {
48
+ console.error(error.message);
49
+ });
50
+
51
+ return child;
52
+ }
53
+
54
+ module.exports = {
55
+ run,
56
+ spawnBackground
57
+ };
@@ -1,20 +1,20 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- /**
5
- * 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
6
- *
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ /**
5
+ * 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
6
+ *
7
7
  * 规则:如果 vue.config.js / vite.config.* / next.config.* 的 alias 中存在指向 ../ 的路径,
8
- * 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
9
- *
10
- * 示例(vue.config.js):
11
- * alias: {
12
- * "@example-admin": projectResolve("../example-admin/src")
13
- * }
14
- *
15
- * @param {string} appDir - 当前 app 目录的绝对路径
16
- * @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
17
- */
8
+ * 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
9
+ *
10
+ * 示例(vue.config.js):
11
+ * alias: {
12
+ * "@example-admin": projectResolve("../example-admin/src")
13
+ * }
14
+ *
15
+ * @param {string} appDir - 当前 app 目录的绝对路径
16
+ * @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
17
+ */
18
18
  function resolveSiblingAppDeps(appDir) {
19
19
  const siblings = [];
20
20
  const configFiles = [
@@ -51,13 +51,13 @@ function resolveSiblingAppDeps(appDir) {
51
51
  addSibling(match[2]);
52
52
  }
53
53
  }
54
-
55
- for (const configFile of configFiles) {
56
- const configPath = path.join(appDir, configFile);
57
- if (!fs.existsSync(configPath)) continue;
58
-
59
- const content = fs.readFileSync(configPath, "utf8");
60
-
54
+
55
+ for (const configFile of configFiles) {
56
+ const configPath = path.join(appDir, configFile);
57
+ if (!fs.existsSync(configPath)) continue;
58
+
59
+ const content = fs.readFileSync(configPath, "utf8");
60
+
61
61
  // 匹配 alias 中指向 ../ 兄弟目录的值,兼容以下写法:
62
62
  // "@foo": projectResolve("../foo/src")
63
63
  // "@foo": resolve("../foo/src")
@@ -77,8 +77,8 @@ function resolveSiblingAppDeps(appDir) {
77
77
 
78
78
  [...objectAliasPatterns, ...arrayAliasPatterns].forEach((pattern) => collectMatches(content, pattern));
79
79
  }
80
-
81
- return siblings;
82
- }
83
-
84
- module.exports = { resolveSiblingAppDeps };
80
+
81
+ return siblings;
82
+ }
83
+
84
+ module.exports = { resolveSiblingAppDeps };