@unpackjs/core 1.5.3 → 1.6.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.
Files changed (238) hide show
  1. package/bin/openChrome.applescript +94 -0
  2. package/compiled/chokidar/index.d.ts +327 -0
  3. package/compiled/chokidar/index.js +1773 -0
  4. package/compiled/chokidar/license +21 -0
  5. package/compiled/chokidar/package.json +1 -0
  6. package/compiled/commander/index.d.ts +971 -0
  7. package/compiled/commander/index.js +2190 -0
  8. package/compiled/commander/license +22 -0
  9. package/compiled/commander/package.json +1 -0
  10. package/compiled/css-loader/api.js +85 -0
  11. package/compiled/css-loader/getUrl.js +26 -0
  12. package/compiled/css-loader/index.d.ts +1 -0
  13. package/compiled/css-loader/index.js +8004 -0
  14. package/compiled/css-loader/license +20 -0
  15. package/compiled/css-loader/noSourceMaps.js +5 -0
  16. package/compiled/css-loader/package.json +1 -0
  17. package/compiled/css-loader/sourceMaps.js +16 -0
  18. package/compiled/fast-glob/index.d.ts +237 -0
  19. package/compiled/fast-glob/index.js +5726 -0
  20. package/compiled/fast-glob/license +21 -0
  21. package/compiled/fast-glob/package.json +1 -0
  22. package/compiled/less-loader/index.d.ts +1 -0
  23. package/compiled/less-loader/index.js +340 -0
  24. package/compiled/less-loader/license +20 -0
  25. package/compiled/less-loader/package.json +1 -0
  26. package/compiled/line-diff/index.d.ts +1 -0
  27. package/compiled/line-diff/index.js +160 -0
  28. package/compiled/line-diff/license +21 -0
  29. package/compiled/line-diff/package.json +1 -0
  30. package/compiled/log-update/index.d.ts +1 -0
  31. package/compiled/log-update/index.js +1970 -0
  32. package/compiled/log-update/package.json +1 -0
  33. package/compiled/portfinder/index.d.ts +64 -0
  34. package/compiled/portfinder/index.js +3401 -0
  35. package/compiled/portfinder/license +22 -0
  36. package/compiled/portfinder/package.json +1 -0
  37. package/compiled/postcss-loader/index.d.ts +1 -0
  38. package/compiled/postcss-loader/index.js +94945 -0
  39. package/compiled/postcss-loader/license +20 -0
  40. package/compiled/postcss-loader/package.json +1 -0
  41. package/compiled/sass-loader/index.d.ts +961 -0
  42. package/compiled/sass-loader/index.js +5610 -0
  43. package/compiled/sass-loader/index1.js +65 -0
  44. package/compiled/sass-loader/license +20 -0
  45. package/compiled/sass-loader/package.json +1 -0
  46. package/compiled/sass-loader/sass.node.js +12 -0
  47. package/compiled/semver/index.d.ts +1 -0
  48. package/compiled/semver/index.js +1940 -0
  49. package/compiled/semver/license +15 -0
  50. package/compiled/semver/package.json +1 -0
  51. package/compiled/style-loader/index.d.ts +1 -0
  52. package/compiled/style-loader/index.js +370 -0
  53. package/compiled/style-loader/license +20 -0
  54. package/compiled/style-loader/package.json +1 -0
  55. package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
  56. package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
  57. package/compiled/style-loader/runtime/insertBySelector.js +34 -0
  58. package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
  59. package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
  60. package/compiled/style-loader/runtime/isOldIE.js +17 -0
  61. package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
  62. package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
  63. package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
  64. package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
  65. package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
  66. package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
  67. package/compiled/webpack-bundle-analyzer/index.d.ts +1 -0
  68. package/compiled/webpack-bundle-analyzer/index.js +13276 -0
  69. package/compiled/webpack-bundle-analyzer/license +20 -0
  70. package/compiled/webpack-bundle-analyzer/package.json +1 -0
  71. package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
  72. package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
  73. package/compiled/webpack-merge/index.d.ts +31 -0
  74. package/compiled/webpack-merge/index.js +1200 -0
  75. package/compiled/webpack-merge/license +20 -0
  76. package/compiled/webpack-merge/package.json +1 -0
  77. package/dist/bundleRequire.cjs +200 -0
  78. package/dist/bundleRequire.d.ts +5 -0
  79. package/dist/bundleRequire.d.ts.map +1 -0
  80. package/dist/bundleRequire.js +173 -0
  81. package/dist/bundler-config/chunkSplit.cjs +151 -0
  82. package/dist/bundler-config/chunkSplit.d.ts +6 -0
  83. package/dist/bundler-config/chunkSplit.d.ts.map +1 -0
  84. package/dist/bundler-config/chunkSplit.js +127 -0
  85. package/dist/bundler-config/css.cjs +168 -0
  86. package/dist/bundler-config/css.d.ts +6 -0
  87. package/dist/bundler-config/css.d.ts.map +1 -0
  88. package/dist/bundler-config/css.js +158 -0
  89. package/dist/bundler-config/experimentCss.cjs +167 -0
  90. package/dist/bundler-config/experimentCss.d.ts +6 -0
  91. package/dist/bundler-config/experimentCss.d.ts.map +1 -0
  92. package/dist/bundler-config/experimentCss.js +157 -0
  93. package/dist/bundler-config/helper.cjs +81 -0
  94. package/dist/bundler-config/helper.d.ts +8 -0
  95. package/dist/bundler-config/helper.d.ts.map +1 -0
  96. package/dist/bundler-config/helper.js +56 -0
  97. package/dist/bundler-config/index.cjs +206 -0
  98. package/dist/bundler-config/index.d.ts +3 -0
  99. package/dist/bundler-config/index.d.ts.map +1 -0
  100. package/dist/bundler-config/index.js +190 -0
  101. package/dist/colors.cjs +60 -0
  102. package/dist/colors.d.ts +6 -0
  103. package/dist/colors.d.ts.map +1 -0
  104. package/dist/colors.js +40 -0
  105. package/dist/{config/index.cjs → config.cjs} +28 -21
  106. package/dist/{config/index.d.ts → config.d.ts} +4 -3
  107. package/dist/config.d.ts.map +1 -0
  108. package/dist/{config/index.js → config.js} +22 -23
  109. package/dist/constants.cjs +86 -0
  110. package/dist/constants.d.ts +25 -0
  111. package/dist/constants.d.ts.map +1 -0
  112. package/dist/constants.js +61 -0
  113. package/dist/createService.cjs +65 -0
  114. package/dist/createService.d.ts +8 -0
  115. package/dist/createService.d.ts.map +1 -0
  116. package/dist/createService.js +41 -0
  117. package/dist/index.cjs +27 -48
  118. package/dist/index.d.ts +7 -7
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +8 -51
  121. package/dist/lightningcss/cache.cjs +36 -0
  122. package/dist/lightningcss/cache.d.ts +2 -0
  123. package/dist/lightningcss/cache.d.ts.map +1 -0
  124. package/dist/lightningcss/cache.js +22 -0
  125. package/dist/lightningcss/index.cjs +21 -0
  126. package/dist/lightningcss/index.d.ts +2 -0
  127. package/dist/lightningcss/index.d.ts.map +1 -0
  128. package/dist/lightningcss/index.js +10 -0
  129. package/dist/lightningcss/loader.cjs +56 -0
  130. package/dist/lightningcss/loader.d.ts +5 -0
  131. package/dist/lightningcss/loader.d.ts.map +1 -0
  132. package/dist/lightningcss/loader.js +36 -0
  133. package/dist/lightningcss/minimizer.cjs +114 -0
  134. package/dist/lightningcss/minimizer.d.ts +11 -0
  135. package/dist/lightningcss/minimizer.d.ts.map +1 -0
  136. package/dist/lightningcss/minimizer.js +90 -0
  137. package/dist/logger.cjs +103 -0
  138. package/dist/logger.d.ts +3 -0
  139. package/dist/logger.d.ts.map +1 -0
  140. package/dist/logger.js +79 -0
  141. package/dist/openBrowser.cjs +85 -0
  142. package/dist/openBrowser.d.ts +2 -0
  143. package/dist/openBrowser.d.ts.map +1 -0
  144. package/dist/openBrowser.js +61 -0
  145. package/dist/plugin-progress/rspack.cjs +74 -0
  146. package/dist/plugin-progress/rspack.d.ts +9 -0
  147. package/dist/plugin-progress/rspack.d.ts.map +1 -0
  148. package/dist/plugin-progress/rspack.js +50 -0
  149. package/dist/plugin-progress/webpack.cjs +84 -0
  150. package/dist/plugin-progress/webpack.d.ts +9 -0
  151. package/dist/plugin-progress/webpack.d.ts.map +1 -0
  152. package/dist/plugin-progress/webpack.js +60 -0
  153. package/dist/plugin.cjs +33 -0
  154. package/dist/plugin.d.ts +3 -0
  155. package/dist/plugin.d.ts.map +1 -0
  156. package/dist/plugin.js +19 -0
  157. package/dist/progressBar.cjs +70 -0
  158. package/dist/progressBar.d.ts +14 -0
  159. package/dist/progressBar.d.ts.map +1 -0
  160. package/dist/progressBar.js +46 -0
  161. package/dist/reporter.cjs +133 -0
  162. package/dist/reporter.d.ts +8 -0
  163. package/dist/reporter.d.ts.map +1 -0
  164. package/dist/reporter.js +109 -0
  165. package/dist/run/build.cjs +77 -0
  166. package/dist/run/build.d.ts +3 -0
  167. package/dist/run/build.d.ts.map +1 -0
  168. package/dist/run/build.js +53 -0
  169. package/dist/run/dev.cjs +107 -0
  170. package/dist/run/dev.d.ts +3 -0
  171. package/dist/run/dev.d.ts.map +1 -0
  172. package/dist/run/dev.js +83 -0
  173. package/dist/run/index.cjs +23 -0
  174. package/dist/run/index.d.ts +3 -0
  175. package/dist/run/index.d.ts.map +1 -0
  176. package/dist/run/index.js +11 -0
  177. package/dist/thread-loader/WorkerError.cjs +41 -0
  178. package/dist/thread-loader/WorkerError.js +31 -0
  179. package/dist/thread-loader/WorkerPool.cjs +407 -0
  180. package/dist/thread-loader/WorkerPool.js +387 -0
  181. package/dist/thread-loader/index.cjs +100 -0
  182. package/dist/thread-loader/index.js +85 -0
  183. package/dist/thread-loader/readBuffer.cjs +55 -0
  184. package/dist/thread-loader/readBuffer.js +45 -0
  185. package/dist/thread-loader/serializer.cjs +46 -0
  186. package/dist/thread-loader/serializer.js +31 -0
  187. package/dist/thread-loader/utils.cjs +84 -0
  188. package/dist/thread-loader/utils.js +60 -0
  189. package/dist/thread-loader/worker.cjs +377 -0
  190. package/dist/thread-loader/worker.js +382 -0
  191. package/dist/thread-loader/workerPools.cjs +57 -0
  192. package/dist/thread-loader/workerPools.js +33 -0
  193. package/dist/typed-css-modules/index.cjs +21 -0
  194. package/dist/typed-css-modules/index.d.ts +2 -0
  195. package/dist/typed-css-modules/index.d.ts.map +1 -0
  196. package/dist/typed-css-modules/index.js +10 -0
  197. package/dist/typed-css-modules/loader.cjs +195 -0
  198. package/dist/typed-css-modules/loader.d.ts +10 -0
  199. package/dist/typed-css-modules/loader.d.ts.map +1 -0
  200. package/dist/typed-css-modules/loader.js +170 -0
  201. package/dist/typed-css-modules/plugin.cjs +96 -0
  202. package/dist/typed-css-modules/plugin.d.ts +16 -0
  203. package/dist/typed-css-modules/plugin.d.ts.map +1 -0
  204. package/dist/typed-css-modules/plugin.js +72 -0
  205. package/dist/typed-css-modules/utils.cjs +45 -0
  206. package/dist/typed-css-modules/utils.d.ts +6 -0
  207. package/dist/typed-css-modules/utils.d.ts.map +1 -0
  208. package/dist/typed-css-modules/utils.js +31 -0
  209. package/dist/types/chunkSplit.cjs +15 -0
  210. package/dist/types/chunkSplit.d.ts +35 -0
  211. package/dist/types/chunkSplit.d.ts.map +1 -0
  212. package/dist/types/chunkSplit.js +9 -0
  213. package/dist/types/config.cjs +15 -0
  214. package/dist/types/config.d.ts +176 -0
  215. package/dist/types/config.d.ts.map +1 -0
  216. package/dist/types/config.js +9 -0
  217. package/dist/types/index.cjs +29 -0
  218. package/dist/types/index.d.ts +16 -0
  219. package/dist/types/index.d.ts.map +1 -0
  220. package/dist/types/index.js +14 -0
  221. package/dist/types/lightningcss.cjs +15 -0
  222. package/dist/types/lightningcss.d.ts +11 -0
  223. package/dist/types/lightningcss.d.ts.map +1 -0
  224. package/dist/types/lightningcss.js +9 -0
  225. package/dist/types/logger.cjs +35 -0
  226. package/dist/types/logger.d.ts +16 -0
  227. package/dist/types/logger.d.ts.map +1 -0
  228. package/dist/types/logger.js +21 -0
  229. package/dist/types/plugin.cjs +15 -0
  230. package/dist/types/plugin.d.ts +18 -0
  231. package/dist/types/plugin.d.ts.map +1 -0
  232. package/dist/types/plugin.js +9 -0
  233. package/dist/utils.cjs +293 -0
  234. package/dist/utils.d.ts +39 -0
  235. package/dist/utils.d.ts.map +1 -0
  236. package/dist/utils.js +242 -0
  237. package/package.json +95 -6
  238. package/dist/config/index.d.ts.map +0 -1
package/dist/utils.cjs ADDED
@@ -0,0 +1,293 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var utils_exports = {};
29
+ __export(utils_exports, {
30
+ debounce: () => debounce,
31
+ getAddressUrls: () => getAddressUrls,
32
+ getCompiledPkgPath: () => getCompiledPkgPath,
33
+ getNodeEnv: () => getNodeEnv,
34
+ getPort: () => getPort,
35
+ getTime: () => getTime,
36
+ getUserDepPath: () => getUserDepPath,
37
+ getValidPath: () => getValidPath,
38
+ getValueByPath: () => getValueByPath,
39
+ isBoolean: () => isBoolean,
40
+ isDev: () => isDev,
41
+ isDevServer: () => isDevServer,
42
+ isFunction: () => isFunction,
43
+ isObject: () => isObject,
44
+ isPlainObject: () => isPlainObject,
45
+ isProd: () => isProd,
46
+ isRegExp: () => isRegExp,
47
+ isString: () => isString,
48
+ isTs: () => isTs,
49
+ isUndefined: () => isUndefined,
50
+ isWatch: () => isWatch,
51
+ isWin: () => isWin,
52
+ prettyTime: () => prettyTime,
53
+ setDevServer: () => setDevServer,
54
+ setNodeEnv: () => setNodeEnv,
55
+ setValueByPath: () => setValueByPath,
56
+ trackPerformance: () => trackPerformance,
57
+ uniqueId: () => uniqueId
58
+ });
59
+ module.exports = __toCommonJS(utils_exports);
60
+ var import_colors = __toESM(require("./colors.cjs"));
61
+ var import_node_fs = __toESM(require("node:fs"));
62
+ var import_node_net = __toESM(require("node:net"));
63
+ var import_node_os = __toESM(require("node:os"));
64
+ var import_node_path = __toESM(require("node:path"));
65
+ var import_constants = require("./constants.cjs");
66
+ var import_logger = require("./logger.cjs");
67
+ const glob = require("../compiled/fast-glob/index.js");
68
+ const portfinder = require("../compiled/portfinder/index.js");
69
+ const getNodeEnv = () => process.env.NODE_ENV;
70
+ const setNodeEnv = (env) => {
71
+ process.env.NODE_ENV = env;
72
+ };
73
+ const setDevServer = (isDevServer2) => {
74
+ process.env.DEV_SERVER = isDevServer2 ? "true" : "false";
75
+ };
76
+ const isDev = () => getNodeEnv() === "development";
77
+ const isDevServer = () => process.env.DEV_SERVER === "true";
78
+ const isWatch = () => isDev() && !isDevServer();
79
+ const isProd = () => getNodeEnv() === "production";
80
+ const isWin = () => process.platform === "win32";
81
+ const isString = (str) => typeof str === "string";
82
+ const isBoolean = (bool) => typeof bool === "boolean";
83
+ const isUndefined = (obj) => typeof obj === "undefined";
84
+ const isFunction = (func) => typeof func === "function";
85
+ const isObject = (obj) => obj !== null && typeof obj === "object";
86
+ const isPlainObject = (obj) => isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
87
+ const isRegExp = (obj) => Object.prototype.toString.call(obj) === "[object RegExp]";
88
+ const prettyTime = (seconds) => {
89
+ const toFixed = (num, len) => {
90
+ const factor = 10 ** len;
91
+ return Math.floor(num * factor) / factor;
92
+ };
93
+ if (seconds < 0.1) {
94
+ return `${toFixed(seconds * 1e3, 0)}ms`;
95
+ }
96
+ if (seconds < 60) {
97
+ return `${toFixed(seconds, 1)}s`;
98
+ }
99
+ return `${toFixed(seconds / 60, 2)}m`;
100
+ };
101
+ const getValueByPath = (target, pathArray, defaultValue) => {
102
+ let current = target;
103
+ for (let i = 0; i < pathArray.length - 1; i++) {
104
+ const currKey = pathArray[i];
105
+ if (!current[currKey] || typeof current[currKey] !== "object") {
106
+ current[currKey] = typeof pathArray[i + 1] === "string" ? {} : [];
107
+ }
108
+ current = current[currKey];
109
+ }
110
+ const lastKey = pathArray.at(-1);
111
+ if (current[lastKey] === void 0) {
112
+ current[lastKey] = defaultValue;
113
+ }
114
+ return current[lastKey];
115
+ };
116
+ const setValueByPath = (target, pathArray, value) => {
117
+ let current = target;
118
+ for (let i = 0; i < pathArray.length - 1; i++) {
119
+ const currKey = pathArray[i];
120
+ if (!current[currKey] || typeof current[currKey] !== "object") {
121
+ current[currKey] = typeof pathArray[i + 1] === "string" ? {} : [];
122
+ }
123
+ current = current[currKey];
124
+ }
125
+ current[pathArray.at(-1)] = value;
126
+ };
127
+ const getPort = (startPort) => {
128
+ return new Promise((resolve) => {
129
+ portfinder.getPort(
130
+ {
131
+ port: startPort
132
+ },
133
+ (_, port) => {
134
+ resolve(port);
135
+ }
136
+ );
137
+ });
138
+ };
139
+ const getCompiledPkgPath = (packageName) => import_node_path.default.join(__dirname, "../compiled", packageName);
140
+ const getUserDepPath = (root, deps) => {
141
+ const paths = glob.sync(deps, {
142
+ cwd: import_node_path.default.resolve(root, "node_modules"),
143
+ absolute: true,
144
+ onlyDirectories: true,
145
+ deep: 1
146
+ });
147
+ return paths?.[0];
148
+ };
149
+ const uniqueId = (length) => {
150
+ const generateId = () => Date.now().toString(36);
151
+ const ids = Array.from({ length }, generateId);
152
+ return ids.join("").slice(0, length);
153
+ };
154
+ function getTime() {
155
+ const now = /* @__PURE__ */ new Date();
156
+ const hours = String(now.getHours()).padStart(2, "0");
157
+ const minutes = String(now.getMinutes()).padStart(2, "0");
158
+ const seconds = String(now.getSeconds()).padStart(2, "0");
159
+ return `${hours}:${minutes}:${seconds}`;
160
+ }
161
+ const debounce = (fn, delay) => {
162
+ let timer = null;
163
+ return (...args) => {
164
+ clearTimeout(timer);
165
+ timer = setTimeout(() => {
166
+ fn(...args);
167
+ }, delay);
168
+ };
169
+ };
170
+ const getValidPath = (filePath) => {
171
+ const absPath = import_node_path.default.isAbsolute(filePath) ? filePath : import_node_path.default.resolve(process.cwd(), filePath);
172
+ if (import_node_fs.default.existsSync(absPath)) {
173
+ return absPath;
174
+ }
175
+ return void 0;
176
+ };
177
+ const isTs = () => {
178
+ const tsconfigPath = import_node_path.default.resolve(process.cwd(), "tsconfig.json");
179
+ return import_node_fs.default.existsSync(tsconfigPath);
180
+ };
181
+ const getIpv4Interfaces = () => {
182
+ const interfaces = import_node_os.default.networkInterfaces();
183
+ const ipv4Interfaces = /* @__PURE__ */ new Map();
184
+ for (const key of Object.keys(interfaces)) {
185
+ for (const detail of interfaces[key]) {
186
+ const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
187
+ if (detail.family === familyV4Value && !ipv4Interfaces.has(detail.address)) {
188
+ ipv4Interfaces.set(detail.address, detail);
189
+ }
190
+ }
191
+ }
192
+ return Array.from(ipv4Interfaces.values());
193
+ };
194
+ const isLoopbackHost = (host) => {
195
+ const loopbackHosts = ["localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001"];
196
+ return loopbackHosts.includes(host);
197
+ };
198
+ const getHostInUrl = (host) => {
199
+ if (import_node_net.default.isIPv6(host)) {
200
+ return host === "::" ? "[::1]" : `[${host}]`;
201
+ }
202
+ return host;
203
+ };
204
+ const concatUrl = ({
205
+ host,
206
+ port,
207
+ protocol
208
+ }) => `${protocol}://${host}:${port}/`;
209
+ const LOCAL_LABEL = "Local: ";
210
+ const NETWORK_LABEL = "Network: ";
211
+ const getAddressUrls = ({
212
+ protocol = "http",
213
+ port,
214
+ host
215
+ }) => {
216
+ if (host && host !== import_constants.DEFAULT_DEV_HOST) {
217
+ return [
218
+ {
219
+ label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
220
+ url: concatUrl({
221
+ port,
222
+ host: getHostInUrl(host),
223
+ protocol
224
+ })
225
+ }
226
+ ];
227
+ }
228
+ const ipv4Interfaces = getIpv4Interfaces();
229
+ const addressUrls = [];
230
+ let hasLocalUrl = false;
231
+ for (const detail of ipv4Interfaces) {
232
+ if (isLoopbackHost(detail.address) || detail.internal) {
233
+ if (hasLocalUrl) {
234
+ continue;
235
+ }
236
+ addressUrls.push({
237
+ label: LOCAL_LABEL,
238
+ url: concatUrl({ host: "localhost", port, protocol })
239
+ });
240
+ hasLocalUrl = true;
241
+ } else {
242
+ addressUrls.push({
243
+ label: NETWORK_LABEL,
244
+ url: concatUrl({ host: detail.address, port, protocol })
245
+ });
246
+ }
247
+ }
248
+ return addressUrls;
249
+ };
250
+ const trackPerformance = (msg) => {
251
+ const k = "__unpack_last_track_time";
252
+ if (!global[k]) {
253
+ global[k] = performance.now();
254
+ return;
255
+ }
256
+ if (msg) {
257
+ import_logger.logger.wait(
258
+ `${msg} ${import_colors.default.dim("for")} ${import_colors.default.bold(import_colors.default.yellow(`${Math.ceil(performance.now() - global[k])}ms`))}`
259
+ );
260
+ }
261
+ global[k] = performance.now();
262
+ };
263
+ // Annotate the CommonJS export names for ESM import in node:
264
+ 0 && (module.exports = {
265
+ debounce,
266
+ getAddressUrls,
267
+ getCompiledPkgPath,
268
+ getNodeEnv,
269
+ getPort,
270
+ getTime,
271
+ getUserDepPath,
272
+ getValidPath,
273
+ getValueByPath,
274
+ isBoolean,
275
+ isDev,
276
+ isDevServer,
277
+ isFunction,
278
+ isObject,
279
+ isPlainObject,
280
+ isProd,
281
+ isRegExp,
282
+ isString,
283
+ isTs,
284
+ isUndefined,
285
+ isWatch,
286
+ isWin,
287
+ prettyTime,
288
+ setDevServer,
289
+ setNodeEnv,
290
+ setValueByPath,
291
+ trackPerformance,
292
+ uniqueId
293
+ });
@@ -0,0 +1,39 @@
1
+ import type { CompiledPkgName, NodeEnv } from './types/index';
2
+ export declare const getNodeEnv: () => NodeEnv;
3
+ export declare const setNodeEnv: (env: NodeEnv) => void;
4
+ export declare const setDevServer: (isDevServer: boolean) => void;
5
+ export declare const isDev: () => boolean;
6
+ export declare const isDevServer: () => boolean;
7
+ export declare const isWatch: () => boolean;
8
+ export declare const isProd: () => boolean;
9
+ export declare const isWin: () => boolean;
10
+ export declare const isString: (str: unknown) => str is string;
11
+ export declare const isBoolean: (bool: unknown) => bool is boolean;
12
+ export declare const isUndefined: (obj: unknown) => obj is undefined;
13
+ export declare const isFunction: (func: unknown) => func is (...args: any[]) => any;
14
+ export declare const isObject: (obj: unknown) => obj is Record<string, any>;
15
+ export declare const isPlainObject: (obj: unknown) => obj is Record<string, any>;
16
+ export declare const isRegExp: (obj: any) => obj is RegExp;
17
+ export declare const prettyTime: (seconds: number) => string;
18
+ export declare const getValueByPath: (target: any, pathArray: (string | number)[], defaultValue: any) => any;
19
+ export declare const setValueByPath: (target: any, pathArray: (string | number)[], value: any) => void;
20
+ export declare const getPort: (startPort: number) => Promise<number>;
21
+ export declare const getCompiledPkgPath: (packageName: CompiledPkgName) => string;
22
+ export declare const getUserDepPath: (root: string, deps: string | string[]) => string | undefined;
23
+ export declare const uniqueId: (length: number) => string;
24
+ export declare function getTime(): string;
25
+ export declare const debounce: (fn: any, delay: any) => (...args: any[]) => void;
26
+ export declare const getValidPath: (filePath: string) => string;
27
+ export declare const isTs: () => boolean;
28
+ type AddressUrl = {
29
+ label: string;
30
+ url: string;
31
+ };
32
+ export declare const getAddressUrls: ({ protocol, port, host, }: {
33
+ protocol?: string;
34
+ port: number;
35
+ host?: string;
36
+ }) => AddressUrl[];
37
+ export declare const trackPerformance: (msg?: string) => void;
38
+ export {};
39
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE7D,eAAO,MAAM,UAAU,QAAiC,OAAO,CAAA;AAE/D,eAAO,MAAM,UAAU,QAAS,OAAO,SAEtC,CAAA;AAED,eAAO,MAAM,YAAY,gBAAiB,OAAO,SAEhD,CAAA;AAED,eAAO,MAAM,KAAK,QAAO,OAAyC,CAAA;AAElE,eAAO,MAAM,WAAW,QAAO,OAA4C,CAAA;AAE3E,eAAO,MAAM,OAAO,QAAO,OAAoC,CAAA;AAE/D,eAAO,MAAM,MAAM,QAAO,OAAwC,CAAA;AAElE,eAAO,MAAM,KAAK,QAAO,OAAuC,CAAA;AAEhE,eAAO,MAAM,QAAQ,QAAS,OAAO,KAAG,GAAG,IAAI,MAAiC,CAAA;AAEhF,eAAO,MAAM,SAAS,SAAU,OAAO,KAAG,IAAI,IAAI,OAAoC,CAAA;AAEtF,eAAO,MAAM,WAAW,QAAS,OAAO,KAAG,GAAG,IAAI,SAAuC,CAAA;AAEzF,eAAO,MAAM,UAAU,SAAU,OAAO,KAAG,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAC3C,CAAA;AAE5B,eAAO,MAAM,QAAQ,QAAS,OAAO,KAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CACxB,CAAA;AAEzC,eAAO,MAAM,aAAa,QAAS,OAAO,KAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CACM,CAAA;AAE5E,eAAO,MAAM,QAAQ,QAAS,GAAG,KAAG,GAAG,IAAI,MACgB,CAAA;AAE3D,eAAO,MAAM,UAAU,YAAa,MAAM,WAYzC,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,gBAAgB,GAAG,QAc5F,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,SAAS,GAAG,SAUrF,CAAA;AAED,eAAO,MAAM,OAAO,cAAe,MAAM,KAAG,OAAO,CAAC,MAAM,CAWzD,CAAA;AAED,eAAO,MAAM,kBAAkB,gBAAiB,eAAe,WACb,CAAA;AAElD,eAAO,MAAM,cAAc,SAAU,MAAM,QAAQ,MAAM,GAAG,MAAM,EAAE,KAAG,MAAM,GAAG,SAQ/E,CAAA;AAED,eAAO,MAAM,QAAQ,WAAY,MAAM,WAItC,CAAA;AAED,wBAAgB,OAAO,WAMtB;AAED,eAAO,MAAM,QAAQ,mDAQpB,CAAA;AAED,eAAO,MAAM,YAAY,aAAc,MAAM,WAM5C,CAAA;AAED,eAAO,MAAM,IAAI,eAGhB,CAAA;AA6CD,KAAK,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAEhD,eAAO,MAAM,cAAc,8BAIxB;IACD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,KAAG,UAAU,EAuCb,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,MAAM,SAY5C,CAAA"}
package/dist/utils.js ADDED
@@ -0,0 +1,242 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ const glob = require("../compiled/fast-glob/index.js");
11
+ import colors from "./colors.js";
12
+ const portfinder = require("../compiled/portfinder/index.js");
13
+ import fs from "node:fs";
14
+ import net from "node:net";
15
+ import os from "node:os";
16
+ import path2 from "node:path";
17
+ import { DEFAULT_DEV_HOST } from "./constants.js";
18
+ import { logger } from "./logger.js";
19
+ const getNodeEnv = () => process.env.NODE_ENV;
20
+ const setNodeEnv = (env) => {
21
+ process.env.NODE_ENV = env;
22
+ };
23
+ const setDevServer = (isDevServer2) => {
24
+ process.env.DEV_SERVER = isDevServer2 ? "true" : "false";
25
+ };
26
+ const isDev = () => getNodeEnv() === "development";
27
+ const isDevServer = () => process.env.DEV_SERVER === "true";
28
+ const isWatch = () => isDev() && !isDevServer();
29
+ const isProd = () => getNodeEnv() === "production";
30
+ const isWin = () => process.platform === "win32";
31
+ const isString = (str) => typeof str === "string";
32
+ const isBoolean = (bool) => typeof bool === "boolean";
33
+ const isUndefined = (obj) => typeof obj === "undefined";
34
+ const isFunction = (func) => typeof func === "function";
35
+ const isObject = (obj) => obj !== null && typeof obj === "object";
36
+ const isPlainObject = (obj) => isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
37
+ const isRegExp = (obj) => Object.prototype.toString.call(obj) === "[object RegExp]";
38
+ const prettyTime = (seconds) => {
39
+ const toFixed = (num, len) => {
40
+ const factor = 10 ** len;
41
+ return Math.floor(num * factor) / factor;
42
+ };
43
+ if (seconds < 0.1) {
44
+ return `${toFixed(seconds * 1e3, 0)}ms`;
45
+ }
46
+ if (seconds < 60) {
47
+ return `${toFixed(seconds, 1)}s`;
48
+ }
49
+ return `${toFixed(seconds / 60, 2)}m`;
50
+ };
51
+ const getValueByPath = (target, pathArray, defaultValue) => {
52
+ let current = target;
53
+ for (let i = 0; i < pathArray.length - 1; i++) {
54
+ const currKey = pathArray[i];
55
+ if (!current[currKey] || typeof current[currKey] !== "object") {
56
+ current[currKey] = typeof pathArray[i + 1] === "string" ? {} : [];
57
+ }
58
+ current = current[currKey];
59
+ }
60
+ const lastKey = pathArray.at(-1);
61
+ if (current[lastKey] === void 0) {
62
+ current[lastKey] = defaultValue;
63
+ }
64
+ return current[lastKey];
65
+ };
66
+ const setValueByPath = (target, pathArray, value) => {
67
+ let current = target;
68
+ for (let i = 0; i < pathArray.length - 1; i++) {
69
+ const currKey = pathArray[i];
70
+ if (!current[currKey] || typeof current[currKey] !== "object") {
71
+ current[currKey] = typeof pathArray[i + 1] === "string" ? {} : [];
72
+ }
73
+ current = current[currKey];
74
+ }
75
+ current[pathArray.at(-1)] = value;
76
+ };
77
+ const getPort = (startPort) => {
78
+ return new Promise((resolve) => {
79
+ portfinder.getPort(
80
+ {
81
+ port: startPort
82
+ },
83
+ (_, port) => {
84
+ resolve(port);
85
+ }
86
+ );
87
+ });
88
+ };
89
+ const getCompiledPkgPath = (packageName) => path2.join(__dirname, "../compiled", packageName);
90
+ const getUserDepPath = (root, deps) => {
91
+ const paths = glob.sync(deps, {
92
+ cwd: path2.resolve(root, "node_modules"),
93
+ absolute: true,
94
+ onlyDirectories: true,
95
+ deep: 1
96
+ });
97
+ return paths?.[0];
98
+ };
99
+ const uniqueId = (length) => {
100
+ const generateId = () => Date.now().toString(36);
101
+ const ids = Array.from({ length }, generateId);
102
+ return ids.join("").slice(0, length);
103
+ };
104
+ function getTime() {
105
+ const now = /* @__PURE__ */ new Date();
106
+ const hours = String(now.getHours()).padStart(2, "0");
107
+ const minutes = String(now.getMinutes()).padStart(2, "0");
108
+ const seconds = String(now.getSeconds()).padStart(2, "0");
109
+ return `${hours}:${minutes}:${seconds}`;
110
+ }
111
+ const debounce = (fn, delay) => {
112
+ let timer = null;
113
+ return (...args) => {
114
+ clearTimeout(timer);
115
+ timer = setTimeout(() => {
116
+ fn(...args);
117
+ }, delay);
118
+ };
119
+ };
120
+ const getValidPath = (filePath) => {
121
+ const absPath = path2.isAbsolute(filePath) ? filePath : path2.resolve(process.cwd(), filePath);
122
+ if (fs.existsSync(absPath)) {
123
+ return absPath;
124
+ }
125
+ return void 0;
126
+ };
127
+ const isTs = () => {
128
+ const tsconfigPath = path2.resolve(process.cwd(), "tsconfig.json");
129
+ return fs.existsSync(tsconfigPath);
130
+ };
131
+ const getIpv4Interfaces = () => {
132
+ const interfaces = os.networkInterfaces();
133
+ const ipv4Interfaces = /* @__PURE__ */ new Map();
134
+ for (const key of Object.keys(interfaces)) {
135
+ for (const detail of interfaces[key]) {
136
+ const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
137
+ if (detail.family === familyV4Value && !ipv4Interfaces.has(detail.address)) {
138
+ ipv4Interfaces.set(detail.address, detail);
139
+ }
140
+ }
141
+ }
142
+ return Array.from(ipv4Interfaces.values());
143
+ };
144
+ const isLoopbackHost = (host) => {
145
+ const loopbackHosts = ["localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001"];
146
+ return loopbackHosts.includes(host);
147
+ };
148
+ const getHostInUrl = (host) => {
149
+ if (net.isIPv6(host)) {
150
+ return host === "::" ? "[::1]" : `[${host}]`;
151
+ }
152
+ return host;
153
+ };
154
+ const concatUrl = ({
155
+ host,
156
+ port,
157
+ protocol
158
+ }) => `${protocol}://${host}:${port}/`;
159
+ const LOCAL_LABEL = "Local: ";
160
+ const NETWORK_LABEL = "Network: ";
161
+ const getAddressUrls = ({
162
+ protocol = "http",
163
+ port,
164
+ host
165
+ }) => {
166
+ if (host && host !== DEFAULT_DEV_HOST) {
167
+ return [
168
+ {
169
+ label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
170
+ url: concatUrl({
171
+ port,
172
+ host: getHostInUrl(host),
173
+ protocol
174
+ })
175
+ }
176
+ ];
177
+ }
178
+ const ipv4Interfaces = getIpv4Interfaces();
179
+ const addressUrls = [];
180
+ let hasLocalUrl = false;
181
+ for (const detail of ipv4Interfaces) {
182
+ if (isLoopbackHost(detail.address) || detail.internal) {
183
+ if (hasLocalUrl) {
184
+ continue;
185
+ }
186
+ addressUrls.push({
187
+ label: LOCAL_LABEL,
188
+ url: concatUrl({ host: "localhost", port, protocol })
189
+ });
190
+ hasLocalUrl = true;
191
+ } else {
192
+ addressUrls.push({
193
+ label: NETWORK_LABEL,
194
+ url: concatUrl({ host: detail.address, port, protocol })
195
+ });
196
+ }
197
+ }
198
+ return addressUrls;
199
+ };
200
+ const trackPerformance = (msg) => {
201
+ const k = "__unpack_last_track_time";
202
+ if (!global[k]) {
203
+ global[k] = performance.now();
204
+ return;
205
+ }
206
+ if (msg) {
207
+ logger.wait(
208
+ `${msg} ${colors.dim("for")} ${colors.bold(colors.yellow(`${Math.ceil(performance.now() - global[k])}ms`))}`
209
+ );
210
+ }
211
+ global[k] = performance.now();
212
+ };
213
+ export {
214
+ debounce,
215
+ getAddressUrls,
216
+ getCompiledPkgPath,
217
+ getNodeEnv,
218
+ getPort,
219
+ getTime,
220
+ getUserDepPath,
221
+ getValidPath,
222
+ getValueByPath,
223
+ isBoolean,
224
+ isDev,
225
+ isDevServer,
226
+ isFunction,
227
+ isObject,
228
+ isPlainObject,
229
+ isProd,
230
+ isRegExp,
231
+ isString,
232
+ isTs,
233
+ isUndefined,
234
+ isWatch,
235
+ isWin,
236
+ prettyTime,
237
+ setDevServer,
238
+ setNodeEnv,
239
+ setValueByPath,
240
+ trackPerformance,
241
+ uniqueId
242
+ };