binary-collections 2.0.5 → 2.0.7

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.
Files changed (126) hide show
  1. package/bin/bash-dummy +7 -2
  2. package/bin/clean-nodemodule +7 -2
  3. package/bin/clean-nodemodules +7 -2
  4. package/bin/dev +7 -2
  5. package/bin/empty +7 -2
  6. package/bin/git-diff.cmd +4 -0
  7. package/bin/git-fix-encoding +7 -2
  8. package/bin/git-fix-encoding.cmd +0 -0
  9. package/bin/git-reduce-size +7 -2
  10. package/bin/kill-process +7 -2
  11. package/bin/nodekill +7 -2
  12. package/bin/nodekill.cmd +0 -0
  13. package/bin/nodekill.ps1 +0 -0
  14. package/bin/prod +7 -2
  15. package/bin/rmfind +7 -2
  16. package/bin/rmpath +7 -2
  17. package/bin/rmx +9 -3
  18. package/bin/submodule +13 -2
  19. package/bin/submodule-install +7 -2
  20. package/bin/submodule-remove +7 -2
  21. package/lib/chunk-3LOB2P54.mjs +202 -0
  22. package/lib/chunk-4LEXWIIF.mjs +173 -0
  23. package/lib/chunk-BSD5CIRU.mjs +52 -0
  24. package/lib/chunk-FB6YIQYR.mjs +42 -0
  25. package/lib/chunk-JL32QDSH.mjs +20 -0
  26. package/lib/chunk-OKYLF2MU.mjs +53 -0
  27. package/lib/chunk-VXZQNLPU.mjs +23 -0
  28. package/lib/del-gradle.cjs +72 -0
  29. package/lib/del-gradle.d.mts +2 -0
  30. package/lib/del-gradle.d.ts +1 -0
  31. package/lib/del-gradle.js +15 -0
  32. package/lib/del-gradle.mjs +28 -0
  33. package/lib/del-node-modules.cjs +72 -0
  34. package/lib/del-node-modules.d.mts +2 -0
  35. package/lib/del-node-modules.d.ts +1 -0
  36. package/lib/del-node-modules.js +11 -15
  37. package/lib/del-node-modules.mjs +28 -0
  38. package/lib/del-ps.cjs +93 -0
  39. package/lib/del-ps.d.mts +2 -0
  40. package/lib/del-ps.d.ts +1 -0
  41. package/lib/del-ps.js +31 -0
  42. package/lib/del-ps.mjs +43 -0
  43. package/lib/del-yarn-caches.cjs +65 -0
  44. package/lib/del-yarn-caches.d.mts +2 -0
  45. package/lib/del-yarn-caches.d.ts +1 -0
  46. package/lib/del-yarn-caches.js +6 -9
  47. package/lib/del-yarn-caches.mjs +21 -0
  48. package/lib/find-node-modules-cli.cjs +59 -0
  49. package/lib/find-node-modules-cli.d.mts +1 -0
  50. package/lib/find-node-modules-cli.d.ts +2 -0
  51. package/lib/find-node-modules-cli.js +3 -0
  52. package/lib/find-node-modules-cli.mjs +14 -0
  53. package/lib/find-node-modules.cjs +34 -0
  54. package/lib/find-node-modules.d.mts +10 -0
  55. package/lib/find-node-modules.d.ts +9 -0
  56. package/lib/find-node-modules.js +41 -13
  57. package/lib/find-node-modules.mjs +7 -0
  58. package/lib/git-diff.cjs +74 -0
  59. package/lib/git-diff.d.cts +2 -0
  60. package/lib/git-diff.d.mts +87 -0
  61. package/lib/git-diff.d.ts +87 -0
  62. package/lib/git-diff.mjs +83 -0
  63. package/lib/git-purge.cjs +91 -0
  64. package/lib/git-purge.d.mts +2 -0
  65. package/lib/git-purge.d.ts +1 -0
  66. package/lib/git-purge.js +59 -0
  67. package/lib/git-purge.mjs +47 -0
  68. package/lib/index.cjs +92 -0
  69. package/lib/index.d.mts +1 -0
  70. package/lib/index.d.ts +2 -0
  71. package/lib/index.js +8 -0
  72. package/lib/index.mjs +18 -0
  73. package/lib/npm-run-series.cjs +61 -0
  74. package/lib/npm-run-series.d.mts +1 -0
  75. package/lib/npm-run-series.d.ts +2 -0
  76. package/lib/npm-run-series.js +80 -39
  77. package/lib/npm-run-series.mjs +47 -0
  78. package/lib/package-resolutions.cjs +28 -0
  79. package/lib/package-resolutions.d.mts +25 -0
  80. package/lib/package-resolutions.d.ts +25 -0
  81. package/lib/package-resolutions.mjs +31 -0
  82. package/lib/ps/connected-domain.cjs +156 -0
  83. package/lib/ps/connected-domain.d.mts +3 -0
  84. package/lib/ps/connected-domain.d.ts +2 -0
  85. package/lib/ps/connected-domain.js +202 -0
  86. package/lib/ps/connected-domain.mjs +7 -0
  87. package/lib/ps/index.cjs +555 -0
  88. package/lib/ps/index.d.cjs +17 -0
  89. package/lib/ps/index.d.d.mts +26 -0
  90. package/lib/ps/index.d.d.ts +26 -0
  91. package/lib/ps/index.d.mjs +8 -0
  92. package/lib/ps/index.d.mts +26 -0
  93. package/lib/ps/index.d.ts +2 -0
  94. package/lib/ps/index.js +250 -0
  95. package/lib/ps/index.mjs +203 -0
  96. package/lib/ps/isWin.cjs +3 -0
  97. package/lib/ps/isWin.d.mts +3 -0
  98. package/lib/ps/isWin.d.ts +2 -0
  99. package/lib/ps/isWin.js +2 -0
  100. package/lib/ps/isWin.mjs +7 -0
  101. package/lib/ps/table-parser.cjs +359 -0
  102. package/lib/ps/table-parser.d.mts +3 -0
  103. package/lib/ps/table-parser.d.ts +1 -0
  104. package/lib/ps/table-parser.js +268 -0
  105. package/lib/ps/table-parser.mjs +8 -0
  106. package/lib/submodule-install.cjs +118 -0
  107. package/lib/submodule-install.d.cts +2 -0
  108. package/lib/submodule-install.d.mts +141 -0
  109. package/lib/submodule-install.d.ts +141 -0
  110. package/lib/submodule-install.mjs +116 -0
  111. package/lib/utils.cjs +35 -0
  112. package/lib/utils.d.mts +20 -0
  113. package/lib/utils.d.ts +16 -0
  114. package/lib/utils.js +42 -28
  115. package/lib/utils.mjs +7 -0
  116. package/lib/yarn-reinstall.cjs +42 -0
  117. package/lib/yarn-reinstall.d.cts +1 -0
  118. package/lib/yarn-reinstall.d.mts +45 -0
  119. package/lib/yarn-reinstall.d.ts +45 -0
  120. package/lib/yarn-reinstall.mjs +50 -0
  121. package/package.json +80 -38
  122. package/readme.md +188 -40
  123. package/src/ps/index.js +285 -0
  124. package/test/package.json +19 -0
  125. package/index.js +0 -1
  126. package/lib/package-resolutions.json +0 -22
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const { spawnSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ // Path to .env file
7
+ const envPath = path.resolve(__dirname, ".env");
8
+ // Check if .env exists and read it
9
+ if (fs.existsSync(envPath)) {
10
+ const envContent = fs.readFileSync(envPath, "utf8");
11
+ // Split into lines and process each
12
+ envContent.split("\n").forEach((line) => {
13
+ const trimmedLine = line.trim();
14
+ // Ignore empty lines and comments
15
+ if (!trimmedLine || trimmedLine.startsWith("#"))
16
+ return;
17
+ // Extract key and value
18
+ const [key, ...vals] = trimmedLine.split("=");
19
+ if (!key)
20
+ return;
21
+ const value = vals
22
+ .join("=")
23
+ .trim()
24
+ .replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
25
+ process.env[key.trim()] = value;
26
+ });
27
+ }
28
+ // Parse CLI args
29
+ const args = process.argv.slice(2);
30
+ let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
31
+ let REPO_PATH = ROOT;
32
+ for (let i = 0; i < args.length; i++) {
33
+ if (args[i] === "-cwd" && args[i + 1]) {
34
+ ROOT = path.resolve(args[++i]);
35
+ }
36
+ else if (args[i].startsWith("--cwd=")) {
37
+ ROOT = path.resolve(args[i].split("=")[1]);
38
+ }
39
+ }
40
+ console.log(`Installing submodules at ${ROOT}`);
41
+ // Get submodule paths
42
+ const submoduleList = runGit([
43
+ "-C",
44
+ REPO_PATH,
45
+ "config",
46
+ "-f",
47
+ ".gitmodules",
48
+ "--get-regexp",
49
+ "^submodule\\..*\\.path$"
50
+ ])
51
+ .split("\n")
52
+ .filter(Boolean);
53
+ for (const line of submoduleList) {
54
+ const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
55
+ const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
56
+ if (fs.existsSync(RELATIVE_MODULE_PATH)) {
57
+ console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
58
+ fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
59
+ }
60
+ const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
61
+ const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
62
+ let BRANCH = "master";
63
+ try {
64
+ BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
65
+ }
66
+ catch (_a) {
67
+ // silently ignore if branch is not set
68
+ }
69
+ const addResult = runGit(["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH], true);
70
+ if (addResult.status !== 0) {
71
+ console.warn(`Cannot add submodule ${MODULE_PATH}`);
72
+ continue;
73
+ }
74
+ const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
75
+ if (process.env.ACCESS_TOKEN) {
76
+ let URL_WITH_TOKEN = "";
77
+ let repoInfo;
78
+ if (URL.includes("github.com")) {
79
+ repoInfo = URL.replace("https://github.com/", "");
80
+ URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
81
+ }
82
+ else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
83
+ repoInfo = URL.replace("https://gitlab.com/", "");
84
+ URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
85
+ }
86
+ else {
87
+ // For other Git providers, try a generic approach
88
+ const urlObj = new URL(URL);
89
+ repoInfo = urlObj.pathname.substring(1); // Remove leading slash
90
+ URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
91
+ }
92
+ if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
93
+ console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
94
+ runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
95
+ }
96
+ }
97
+ runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
98
+ runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
99
+ if (fs.existsSync(GIT_MODULES)) {
100
+ console.log(`${MODULE_PATH} has submodules`);
101
+ const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
102
+ if (result.status !== 0) {
103
+ console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
104
+ process.exit(result.status);
105
+ }
106
+ }
107
+ }
108
+ runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
109
+ // ----------- Helper Functions -----------
110
+ function runGit(args, returnResult = false) {
111
+ const result = spawnSync("git", args, { encoding: "utf-8" });
112
+ if (returnResult)
113
+ return result;
114
+ if (result.status !== 0) {
115
+ throw new Error(result.stderr || `git ${args.join(" ")} failed`);
116
+ }
117
+ return result.stdout || "";
118
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require("child_process");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ // Path to .env file
7
+ const envPath = path.resolve(__dirname, ".env");
8
+
9
+ // Check if .env exists and read it
10
+ if (fs.existsSync(envPath)) {
11
+ const envContent = fs.readFileSync(envPath, "utf8");
12
+
13
+ // Split into lines and process each
14
+ envContent.split("\n").forEach((line) => {
15
+ const trimmedLine = line.trim();
16
+
17
+ // Ignore empty lines and comments
18
+ if (!trimmedLine || trimmedLine.startsWith("#")) return;
19
+
20
+ // Extract key and value
21
+ const [key, ...vals] = trimmedLine.split("=");
22
+ if (!key) return;
23
+
24
+ const value = vals
25
+ .join("=")
26
+ .trim()
27
+ .replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
28
+ process.env[key.trim()] = value;
29
+ });
30
+ }
31
+
32
+ // Parse CLI args
33
+ const args = process.argv.slice(2);
34
+ let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
35
+ let REPO_PATH = ROOT;
36
+
37
+ for (let i = 0; i < args.length; i++) {
38
+ if (args[i] === "-cwd" && args[i + 1]) {
39
+ ROOT = path.resolve(args[++i]);
40
+ } else if (args[i].startsWith("--cwd=")) {
41
+ ROOT = path.resolve(args[i].split("=")[1]);
42
+ }
43
+ }
44
+
45
+ console.log(`Installing submodules at ${ROOT}`);
46
+
47
+ // Get submodule paths
48
+ const submoduleList = runGit([
49
+ "-C",
50
+ REPO_PATH,
51
+ "config",
52
+ "-f",
53
+ ".gitmodules",
54
+ "--get-regexp",
55
+ "^submodule\\..*\\.path$"
56
+ ])
57
+ .split("\n")
58
+ .filter(Boolean);
59
+
60
+ for (const line of submoduleList) {
61
+ const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
62
+ const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
63
+
64
+ if (fs.existsSync(RELATIVE_MODULE_PATH)) {
65
+ console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
66
+ fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
67
+ }
68
+
69
+ const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
70
+ const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
71
+
72
+ let BRANCH = "master";
73
+ try {
74
+ BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
75
+ } catch {
76
+ // silently ignore if branch is not set
77
+ }
78
+
79
+ const addResult = runGit(
80
+ ["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
81
+ true
82
+ );
83
+
84
+ if (addResult.status !== 0) {
85
+ console.warn(`Cannot add submodule ${MODULE_PATH}`);
86
+ continue;
87
+ }
88
+
89
+ const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
90
+
91
+ if (process.env.ACCESS_TOKEN) {
92
+ let URL_WITH_TOKEN = "";
93
+ let repoInfo;
94
+
95
+ if (URL.includes("github.com")) {
96
+ repoInfo = URL.replace("https://github.com/", "");
97
+ URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
98
+ } else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
99
+ repoInfo = URL.replace("https://gitlab.com/", "");
100
+ URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
101
+ } else {
102
+ // For other Git providers, try a generic approach
103
+ const urlObj = new URL(URL);
104
+ repoInfo = urlObj.pathname.substring(1); // Remove leading slash
105
+ URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
106
+ }
107
+
108
+ if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
109
+ console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
110
+ runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
111
+ }
112
+ }
113
+
114
+ runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
115
+ runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
116
+
117
+ if (fs.existsSync(GIT_MODULES)) {
118
+ console.log(`${MODULE_PATH} has submodules`);
119
+ const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
120
+ if (result.status !== 0) {
121
+ console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
122
+ process.exit(result.status);
123
+ }
124
+ }
125
+ }
126
+
127
+ runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
128
+
129
+ // ----------- Helper Functions -----------
130
+
131
+ function runGit(args, returnResult = false) {
132
+ const result = spawnSync("git", args, { encoding: "utf-8" });
133
+
134
+ if (returnResult) return result;
135
+
136
+ if (result.status !== 0) {
137
+ throw new Error(result.stderr || `git ${args.join(" ")} failed`);
138
+ }
139
+
140
+ return result.stdout || "";
141
+ }
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require("child_process");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ // Path to .env file
7
+ const envPath = path.resolve(__dirname, ".env");
8
+
9
+ // Check if .env exists and read it
10
+ if (fs.existsSync(envPath)) {
11
+ const envContent = fs.readFileSync(envPath, "utf8");
12
+
13
+ // Split into lines and process each
14
+ envContent.split("\n").forEach((line) => {
15
+ const trimmedLine = line.trim();
16
+
17
+ // Ignore empty lines and comments
18
+ if (!trimmedLine || trimmedLine.startsWith("#")) return;
19
+
20
+ // Extract key and value
21
+ const [key, ...vals] = trimmedLine.split("=");
22
+ if (!key) return;
23
+
24
+ const value = vals
25
+ .join("=")
26
+ .trim()
27
+ .replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
28
+ process.env[key.trim()] = value;
29
+ });
30
+ }
31
+
32
+ // Parse CLI args
33
+ const args = process.argv.slice(2);
34
+ let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
35
+ let REPO_PATH = ROOT;
36
+
37
+ for (let i = 0; i < args.length; i++) {
38
+ if (args[i] === "-cwd" && args[i + 1]) {
39
+ ROOT = path.resolve(args[++i]);
40
+ } else if (args[i].startsWith("--cwd=")) {
41
+ ROOT = path.resolve(args[i].split("=")[1]);
42
+ }
43
+ }
44
+
45
+ console.log(`Installing submodules at ${ROOT}`);
46
+
47
+ // Get submodule paths
48
+ const submoduleList = runGit([
49
+ "-C",
50
+ REPO_PATH,
51
+ "config",
52
+ "-f",
53
+ ".gitmodules",
54
+ "--get-regexp",
55
+ "^submodule\\..*\\.path$"
56
+ ])
57
+ .split("\n")
58
+ .filter(Boolean);
59
+
60
+ for (const line of submoduleList) {
61
+ const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
62
+ const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
63
+
64
+ if (fs.existsSync(RELATIVE_MODULE_PATH)) {
65
+ console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
66
+ fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
67
+ }
68
+
69
+ const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
70
+ const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
71
+
72
+ let BRANCH = "master";
73
+ try {
74
+ BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
75
+ } catch {
76
+ // silently ignore if branch is not set
77
+ }
78
+
79
+ const addResult = runGit(
80
+ ["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
81
+ true
82
+ );
83
+
84
+ if (addResult.status !== 0) {
85
+ console.warn(`Cannot add submodule ${MODULE_PATH}`);
86
+ continue;
87
+ }
88
+
89
+ const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
90
+
91
+ if (process.env.ACCESS_TOKEN) {
92
+ let URL_WITH_TOKEN = "";
93
+ let repoInfo;
94
+
95
+ if (URL.includes("github.com")) {
96
+ repoInfo = URL.replace("https://github.com/", "");
97
+ URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
98
+ } else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
99
+ repoInfo = URL.replace("https://gitlab.com/", "");
100
+ URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
101
+ } else {
102
+ // For other Git providers, try a generic approach
103
+ const urlObj = new URL(URL);
104
+ repoInfo = urlObj.pathname.substring(1); // Remove leading slash
105
+ URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
106
+ }
107
+
108
+ if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
109
+ console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
110
+ runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
111
+ }
112
+ }
113
+
114
+ runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
115
+ runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
116
+
117
+ if (fs.existsSync(GIT_MODULES)) {
118
+ console.log(`${MODULE_PATH} has submodules`);
119
+ const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
120
+ if (result.status !== 0) {
121
+ console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
122
+ process.exit(result.status);
123
+ }
124
+ }
125
+ }
126
+
127
+ runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
128
+
129
+ // ----------- Helper Functions -----------
130
+
131
+ function runGit(args, returnResult = false) {
132
+ const result = spawnSync("git", args, { encoding: "utf-8" });
133
+
134
+ if (returnResult) return result;
135
+
136
+ if (result.status !== 0) {
137
+ throw new Error(result.stderr || `git ${args.join(" ")} failed`);
138
+ }
139
+
140
+ return result.stdout || "";
141
+ }
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
3
+ import {
4
+ __dirname,
5
+ __filename,
6
+ init_esm_shims
7
+ } from "./chunk-VXZQNLPU.mjs";
8
+ import {
9
+ __commonJS,
10
+ __require
11
+ } from "./chunk-FB6YIQYR.mjs";
12
+
13
+ // src/submodule-install.cjs
14
+ var require_submodule_install = __commonJS({
15
+ "src/submodule-install.cjs"() {
16
+ init_esm_shims();
17
+ var { spawnSync } = __require("child_process");
18
+ var fs = __require("fs");
19
+ var path = __require("path");
20
+ var envPath = path.resolve(__dirname, ".env");
21
+ if (fs.existsSync(envPath)) {
22
+ const envContent = fs.readFileSync(envPath, "utf8");
23
+ envContent.split("\n").forEach((line) => {
24
+ const trimmedLine = line.trim();
25
+ if (!trimmedLine || trimmedLine.startsWith("#")) return;
26
+ const [key, ...vals] = trimmedLine.split("=");
27
+ if (!key) return;
28
+ const value = vals.join("=").trim().replace(/^['"]|['"]$/g, "");
29
+ process.env[key.trim()] = value;
30
+ });
31
+ }
32
+ var args = process.argv.slice(2);
33
+ var ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
34
+ var REPO_PATH = ROOT;
35
+ for (let i = 0; i < args.length; i++) {
36
+ if (args[i] === "-cwd" && args[i + 1]) {
37
+ ROOT = path.resolve(args[++i]);
38
+ } else if (args[i].startsWith("--cwd=")) {
39
+ ROOT = path.resolve(args[i].split("=")[1]);
40
+ }
41
+ }
42
+ console.log(`Installing submodules at ${ROOT}`);
43
+ var submoduleList = runGit([
44
+ "-C",
45
+ REPO_PATH,
46
+ "config",
47
+ "-f",
48
+ ".gitmodules",
49
+ "--get-regexp",
50
+ "^submodule\\..*\\.path$"
51
+ ]).split("\n").filter(Boolean);
52
+ for (const line of submoduleList) {
53
+ const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
54
+ const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
55
+ if (fs.existsSync(RELATIVE_MODULE_PATH)) {
56
+ console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
57
+ fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
58
+ }
59
+ const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
60
+ const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
61
+ let BRANCH = "master";
62
+ try {
63
+ BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
64
+ } catch {
65
+ }
66
+ const addResult = runGit(
67
+ ["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
68
+ true
69
+ );
70
+ if (addResult.status !== 0) {
71
+ console.warn(`Cannot add submodule ${MODULE_PATH}`);
72
+ continue;
73
+ }
74
+ const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
75
+ if (process.env.ACCESS_TOKEN) {
76
+ let URL_WITH_TOKEN = "";
77
+ let repoInfo;
78
+ if (URL.includes("github.com")) {
79
+ repoInfo = URL.replace("https://github.com/", "");
80
+ URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
81
+ } else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
82
+ repoInfo = URL.replace("https://gitlab.com/", "");
83
+ URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
84
+ } else {
85
+ const urlObj = new URL(URL);
86
+ repoInfo = urlObj.pathname.substring(1);
87
+ URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
88
+ }
89
+ if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
90
+ console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
91
+ runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
92
+ }
93
+ }
94
+ runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
95
+ runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
96
+ if (fs.existsSync(GIT_MODULES)) {
97
+ console.log(`${MODULE_PATH} has submodules`);
98
+ const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
99
+ if (result.status !== 0) {
100
+ console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
101
+ process.exit(result.status);
102
+ }
103
+ }
104
+ }
105
+ runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
106
+ function runGit(args2, returnResult = false) {
107
+ const result = spawnSync("git", args2, { encoding: "utf-8" });
108
+ if (returnResult) return result;
109
+ if (result.status !== 0) {
110
+ throw new Error(result.stderr || `git ${args2.join(" ")} failed`);
111
+ }
112
+ return result.stdout || "";
113
+ }
114
+ }
115
+ });
116
+ export default require_submodule_install();
package/lib/utils.cjs ADDED
@@ -0,0 +1,35 @@
1
+ // src/utils.js
2
+ var { fs, path } = require("sbg-utility");
3
+ var argv = require("minimist")(process.argv.slice(2));
4
+ function getArgs() {
5
+ return argv;
6
+ }
7
+ function del(fullPath) {
8
+ if (fs.statSync(fullPath).isDirectory()) {
9
+ const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
10
+ for (let i = 0; i < subdir.length; i++) {
11
+ del(subdir[i]);
12
+ }
13
+ } else {
14
+ try {
15
+ fs.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
16
+ console.log("deleted", fullPath);
17
+ } catch (_) {
18
+ console.log("failed delete", fullPath);
19
+ }
20
+ }
21
+ }
22
+ function delStream(globStream) {
23
+ globStream.stream().on("data", (result) => {
24
+ const fullPath = path.resolve(process.cwd(), result);
25
+ if (fs.statSync(fullPath).isDirectory()) {
26
+ const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
27
+ for (let i = 0; i < subdir.length; i++) {
28
+ del(subdir[i]);
29
+ }
30
+ }
31
+ del(fullPath);
32
+ });
33
+ }
34
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
35
+ module.exports = { del, delStream, getArgs, delay };
@@ -0,0 +1,20 @@
1
+ import * as minimist from 'minimist';
2
+
3
+ /**
4
+ * delete file recursive
5
+ * @param {string} fullPath
6
+ */
7
+ declare function del(fullPath: string): void;
8
+ /**
9
+ * glob stream handler
10
+ * @param {glob.Glob} globStream
11
+ */
12
+ declare function delStream(globStream: glob.Glob): void;
13
+ declare function getArgs(): minimist.ParsedArgs;
14
+ /**
15
+ * async delayed
16
+ * @param {number} ms
17
+ */
18
+ declare function delay(ms: number): Promise<any>;
19
+
20
+ export { del, delStream, delay, getArgs };
package/lib/utils.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * delete file recursive
3
+ * @param {string} fullPath
4
+ */
5
+ export function del(fullPath: string): void;
6
+ /**
7
+ * glob stream handler
8
+ * @param {glob.Glob} globStream
9
+ */
10
+ export function delStream(globStream: glob.Glob): void;
11
+ export function getArgs(): import("minimist").ParsedArgs;
12
+ /**
13
+ * async delayed
14
+ * @param {number} ms
15
+ */
16
+ export function delay(ms: number): Promise<any>;
package/lib/utils.js CHANGED
@@ -1,36 +1,50 @@
1
- const { fs, path } = require('sbg-utility');
2
-
1
+ const { fs, path } = require("sbg-utility");
2
+ const argv = require("minimist")(process.argv.slice(2));
3
+ function getArgs() {
4
+ return argv;
5
+ }
3
6
  /**
4
- * glob stream handler
5
- * @param {glob.Glob} globStream
7
+ * delete file recursive
8
+ * @param {string} fullPath
6
9
  */
7
- function delStream(globStream) {
8
- globStream.stream().on('data', (result) => {
9
- const fullPath = path.resolve(process.cwd(), result);
10
- console.log('deleting', fullPath);
10
+ function del(fullPath) {
11
11
  if (fs.statSync(fullPath).isDirectory()) {
12
- // delete all files each package directory
13
- const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
14
- for (let i = 0; i < subdir.length; i++) {
15
- const dir = subdir[i];
16
- del(dir);
17
- }
12
+ // delete all files each package directory
13
+ const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
14
+ for (let i = 0; i < subdir.length; i++) {
15
+ del(subdir[i]);
16
+ }
17
+ }
18
+ else {
19
+ try {
20
+ fs.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7000 });
21
+ console.log("deleted", fullPath);
22
+ }
23
+ catch (_) {
24
+ console.log("failed delete", fullPath);
25
+ }
18
26
  }
19
- del(fullPath);
20
- });
21
27
  }
22
-
23
28
  /**
24
- * delete file recursive
25
- * @param {string} fullPath
29
+ * glob stream handler
30
+ * @param {glob.Glob} globStream
26
31
  */
27
- function del(fullPath) {
28
- try {
29
- fs.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7000 });
30
- console.log('deleted', fullPath);
31
- } catch (_) {
32
- console.log('failed delete', fullPath);
33
- }
32
+ function delStream(globStream) {
33
+ globStream.stream().on("data", (result) => {
34
+ const fullPath = path.resolve(process.cwd(), result);
35
+ if (fs.statSync(fullPath).isDirectory()) {
36
+ // delete all files each package directory
37
+ const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
38
+ for (let i = 0; i < subdir.length; i++) {
39
+ del(subdir[i]);
40
+ }
41
+ }
42
+ del(fullPath);
43
+ });
34
44
  }
35
-
36
- module.exports = { del, delStream };
45
+ /**
46
+ * async delayed
47
+ * @param {number} ms
48
+ */
49
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
50
+ module.exports = { del, delStream, getArgs, delay };
package/lib/utils.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_utils
4
+ } from "./chunk-OKYLF2MU.mjs";
5
+ import "./chunk-VXZQNLPU.mjs";
6
+ import "./chunk-FB6YIQYR.mjs";
7
+ export default require_utils();