@unpackjs/core 3.2.0 → 3.2.2

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
@@ -4,15 +4,15 @@ import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
4
4
  import { dirname as __webpack_dirname__ } from "node:path";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_webpack_bundle_analyzer_index_js_1177eada__ from "../compiled/webpack-bundle-analyzer/index.js";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_webpack_merge_index_js_efd91626__ from "../compiled/webpack-merge/index.js";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
7
8
  import { experiments, rspack } from "@rspack/core";
8
9
  import picocolors from "picocolors";
9
10
  import node_fs from "node:fs";
10
11
  import node_path, { join, sep } from "node:path";
11
- import { pathToFileURL } from "node:url";
12
12
  import { createJiti } from "jiti";
13
13
  import node_readline from "node:readline";
14
14
  import node_net from "node:net";
15
- import node_os, { platform } from "node:os";
15
+ import node_os, { platform as external_node_os_platform } from "node:os";
16
16
  import portfinder from "portfinder";
17
17
  import { expand } from "dotenv-expand";
18
18
  import { TsCheckerRspackPlugin } from "ts-checker-rspack-plugin";
@@ -20,7 +20,7 @@ import node_assert from "node:assert";
20
20
  import { glob, globSync } from "tinyglobby";
21
21
  import typed_css_modules from "typed-css-modules";
22
22
  import { minify } from "oxc-minify";
23
- import { exec, spawn } from "node:child_process";
23
+ import node_child_process, { exec, spawn } from "node:child_process";
24
24
  import { promisify } from "node:util";
25
25
  import node_zlib from "node:zlib";
26
26
  import cors from "cors";
@@ -33,6 +33,9 @@ var LogColor, __webpack_modules__ = {
33
33
  },
34
34
  "compiled/webpack-merge": function(module) {
35
35
  module.exports = __WEBPACK_EXTERNAL_MODULE__compiled_webpack_merge_index_js_efd91626__;
36
+ },
37
+ "node:url": function(module) {
38
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
36
39
  }
37
40
  }, __webpack_module_cache__ = {};
38
41
  function __webpack_require__(moduleId) {
@@ -53,7 +56,7 @@ let colors = {
53
56
  return output;
54
57
  }
55
58
  };
56
- var logger_LogColor = ((LogColor = {}).error = "red", LogColor.warn = "yellow", LogColor.info = "cyan", LogColor.ready = "green", LogColor.event = "magenta", LogColor.wait = "blue", LogColor.debug = "dim", LogColor);
59
+ var external_node_url_ = __webpack_require__("node:url"), logger_LogColor = ((LogColor = {}).error = "red", LogColor.warn = "yellow", LogColor.info = "cyan", LogColor.ready = "green", LogColor.event = "magenta", LogColor.wait = "blue", LogColor.debug = "dim", LogColor);
57
60
  let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULES_REGEX = /\.module\.\w+$/i, DEV_DEFAULT_FILENAME = {
58
61
  js: 'js/[name].js',
59
62
  jsAsync: 'js/async/[name].js',
@@ -217,7 +220,8 @@ let isCSSModules = ({ resourcePath, modules })=>{
217
220
  ],
218
221
  esnext: [
219
222
  'last 2 versions',
220
- 'not dead'
223
+ 'not dead',
224
+ '> 0.5%'
221
225
  ]
222
226
  }[esVersion];
223
227
  if (!browsers) throw Error(`Unsupported ES version: ${esVersion}`);
@@ -275,7 +279,7 @@ async function loadConfig({ cliOptions, command }) {
275
279
  if (isNodeVersionAtLeast(23, 6) || /\.(?:js|mjs|cjs)$/.test(configFilePath)) {
276
280
  logger_logger.debug('loading config file with native loader:', colors.dim(configFilePath));
277
281
  try {
278
- let configFileURL = pathToFileURL(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
282
+ let configFileURL = (0, external_node_url_.pathToFileURL)(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
279
283
  configExport = exportModule.default ? exportModule.default : exportModule;
280
284
  } catch (err) {
281
285
  throw logger_logger.error('failed to load config file with native loader:', colors.dim(configFilePath)), err;
@@ -588,7 +592,7 @@ class JsMinifyPlugin {
588
592
  apply(compiler) {
589
593
  let meta = JSON.stringify({
590
594
  name: jsMinify_PLUGIN_NAME,
591
- version: "3.2.0",
595
+ version: "3.2.2",
592
596
  options: this.minifyOptions
593
597
  });
594
598
  compiler.hooks.compilation.tap(jsMinify_PLUGIN_NAME, (compilation)=>{
@@ -1005,6 +1009,10 @@ async function getBundlerConfig(unpackConfig) {
1005
1009
  test: /\.(woff2?|eot|ttf|otf)$/i,
1006
1010
  type: 'asset'
1007
1011
  },
1012
+ {
1013
+ test: /\.(mp4|m4v|webm|ogv|ogg|mp3|m4a|wav|flac|aac|opus)$/i,
1014
+ type: 'asset/resource'
1015
+ },
1008
1016
  {
1009
1017
  test: /\.wasm$/,
1010
1018
  dependency: 'url',
@@ -1510,7 +1518,7 @@ async function openBrowser(url) {
1510
1518
  try {
1511
1519
  return new Promise((resolve, reject)=>{
1512
1520
  let command, args = [];
1513
- switch(platform()){
1521
+ switch(external_node_os_platform()){
1514
1522
  case 'darwin':
1515
1523
  command = 'open', args = [
1516
1524
  url
@@ -1793,7 +1801,7 @@ async function unpackDev(originalUnpackConfig) {
1793
1801
  (null == (_req_headers_accept = req.headers.accept) ? void 0 : _req_headers_accept.includes('html')) && (req.url = '/index.html'), next();
1794
1802
  }), middlewares.unshift(experiments.lazyCompilationMiddleware(compiler)), middlewares);
1795
1803
  let server = new webpack_dev_server(devServerOptions, compiler);
1796
- await server.start(), logger_logger.greet(` ${colors.green(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v3.2.0`)} ${colors.dim(`ready in ${colors.reset(Math.ceil(performance.now() - global.__unpack_start_time))}ms`)}\n`), getAddressUrls({
1804
+ await server.start(), logger_logger.greet(` ${colors.green(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v3.2.2`)} ${colors.dim(`ready in ${colors.reset(Math.ceil(performance.now() - global.__unpack_start_time))}ms`)}\n`), getAddressUrls({
1797
1805
  port: port
1798
1806
  }).forEach((addr)=>{
1799
1807
  let url;
@@ -1844,7 +1852,7 @@ function createUnpack({ cwd = process.cwd(), config, callerName = 'unpack' }) {
1844
1852
  ]
1845
1853
  }, _context = {
1846
1854
  callerName,
1847
- version: "3.2.0"
1855
+ version: "3.2.2"
1848
1856
  }, { plugins, bundlerConfig, ...rest } = mergeConfig(defaultConfig, config);
1849
1857
  for (let plugin of getNormalizedPluginsByHook('config', plugins))rest = await plugin.config(rest, {
1850
1858
  ..._context,
@@ -1861,13 +1869,611 @@ function createUnpack({ cwd = process.cwd(), config, callerName = 'unpack' }) {
1861
1869
  build: async ({ watch } = {})=>{
1862
1870
  setNodeEnv(watch ? 'development' : 'production');
1863
1871
  let config = await resolveConfig();
1864
- console.log(colors.rainbow(`${callerName} v3.2.0`), colors.green(`building for ${getNodeEnv()}...`)), unpackBuild(config);
1872
+ console.log(colors.rainbow(`${callerName} v3.2.2`), colors.green(`building for ${getNodeEnv()}...`)), unpackBuild(config);
1865
1873
  },
1866
1874
  dev: async ()=>{
1867
1875
  global.__unpack_start_time = performance.now(), setNodeEnv('development'), setDevServer(!0), unpackDev(await resolveConfig());
1868
1876
  }
1869
1877
  };
1870
1878
  }
1879
+ let COMMON_EDITORS_MAP = {
1880
+ darwin: {
1881
+ '/Cursor.app/Contents/MacOS/Cursor': '/Cursor.app/Contents/MacOS/Cursor',
1882
+ '/Comate.app/Contents/MacOS/Electron': '/Comate.app/Contents/MacOS/Electron',
1883
+ '/Windsurf.app/Contents/MacOS/Electron': '/Windsurf.app/Contents/MacOS/Electron',
1884
+ '/Trae.app/Contents/MacOS/Electron': '/Trae.app/Contents/MacOS/Electron',
1885
+ '/Trae CN.app/Contents/MacOS/Electron': '/Trae CN.app/Contents/MacOS/Electron',
1886
+ '/Visual Studio Code.app/Contents/MacOS/Electron': '/Visual Studio Code.app/Contents/MacOS/Electron',
1887
+ '/Visual Studio Code - Insiders.app/Contents/MacOS/Electron': '/Visual Studio Code - Insiders.app/Contents/MacOS/Electron',
1888
+ '/VSCodium.app/Contents/MacOS/Electron': '/VSCodium.app/Contents/MacOS/Electron',
1889
+ '/WebStorm.app/Contents/MacOS/webstorm': '/WebStorm.app/Contents/MacOS/webstorm',
1890
+ '/HBuilderX.app/Contents/MacOS/HBuilderX': '/HBuilderX.app/Contents/MacOS/HBuilderX',
1891
+ '/Atom.app/Contents/MacOS/Atom': 'atom',
1892
+ '/Atom Beta.app/Contents/MacOS/Atom Beta': '/Atom Beta.app/Contents/MacOS/Atom Beta',
1893
+ '/Brackets.app/Contents/MacOS/Brackets': 'brackets',
1894
+ '/Sublime Text.app/Contents/MacOS/Sublime Text': '/Sublime Text.app/Contents/SharedSupport/bin/subl',
1895
+ '/Sublime Text.app/Contents/MacOS/sublime_text': '/Sublime Text.app/Contents/SharedSupport/bin/subl',
1896
+ '/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
1897
+ '/Sublime Text Dev.app/Contents/MacOS/Sublime Text': '/Sublime Text Dev.app/Contents/SharedSupport/bin/subl',
1898
+ '/PhpStorm.app/Contents/MacOS/phpstorm': '/PhpStorm.app/Contents/MacOS/phpstorm',
1899
+ '/PyCharm.app/Contents/MacOS/pycharm': '/PyCharm.app/Contents/MacOS/pycharm',
1900
+ '/PyCharm CE.app/Contents/MacOS/pycharm': '/PyCharm CE.app/Contents/MacOS/pycharm',
1901
+ '/IntelliJ IDEA.app/Contents/MacOS/idea': '/IntelliJ IDEA.app/Contents/MacOS/idea',
1902
+ '/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea': '/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea',
1903
+ '/IntelliJ IDEA Community Edition.app/Contents/MacOS/idea': '/IntelliJ IDEA Community Edition.app/Contents/MacOS/idea',
1904
+ '/Zed.app/Contents/MacOS/zed': 'zed',
1905
+ '/GoLand.app/Contents/MacOS/goland': '/GoLand.app/Contents/MacOS/goland',
1906
+ '/AppCode.app/Contents/MacOS/appcode': '/AppCode.app/Contents/MacOS/appcode',
1907
+ '/CLion.app/Contents/MacOS/clion': '/CLion.app/Contents/MacOS/clion',
1908
+ '/RubyMine.app/Contents/MacOS/rubymine': '/RubyMine.app/Contents/MacOS/rubymine',
1909
+ '/MacVim.app/Contents/MacOS/MacVim': 'mvim',
1910
+ '/Rider.app/Contents/MacOS/rider': '/Rider.app/Contents/MacOS/rider'
1911
+ },
1912
+ linux: {
1913
+ cursor: 'cursor',
1914
+ windsurf: 'windsurf',
1915
+ code: 'code',
1916
+ vscodium: 'vscodium',
1917
+ codium: 'codium',
1918
+ webstorm: 'webstorm',
1919
+ 'webstorm.sh': 'webstorm',
1920
+ hbuilderx: 'hbuilderx',
1921
+ 'hbuilderx.sh': 'hbuilderx',
1922
+ atom: 'atom',
1923
+ Brackets: 'brackets',
1924
+ 'code-insiders': 'code-insiders',
1925
+ emacs: 'emacs',
1926
+ gvim: 'gvim',
1927
+ idea: 'idea',
1928
+ 'idea.sh': 'idea',
1929
+ phpstorm: 'phpstorm',
1930
+ 'phpstorm.sh': 'phpstorm',
1931
+ pycharm: 'pycharm',
1932
+ 'pycharm.sh': 'pycharm',
1933
+ rubymine: 'rubymine',
1934
+ 'rubymine.sh': 'rubymine',
1935
+ sublime_text: 'subl',
1936
+ vim: 'vim',
1937
+ goland: 'goland',
1938
+ 'goland.sh': 'goland',
1939
+ rider: 'rider',
1940
+ 'rider.sh': 'rider'
1941
+ },
1942
+ win32: {
1943
+ 'Cursor.exe': '',
1944
+ 'Windsurf.exe': '',
1945
+ 'Trae.exe': '',
1946
+ 'Trae CN.exe': '',
1947
+ 'comate.exe': '',
1948
+ 'Code.exe': '',
1949
+ 'Code - Insiders.exe': '',
1950
+ 'VSCodium.exe': '',
1951
+ 'webstorm.exe': '',
1952
+ 'webstorm64.exe': '',
1953
+ 'HBuilderX.exe': '',
1954
+ 'HBuilderX64.exe': '',
1955
+ 'HBuilder.exe': '',
1956
+ 'HBuilder64.exe': '',
1957
+ 'Brackets.exe': '',
1958
+ 'atom.exe': '',
1959
+ 'sublime_text.exe': '',
1960
+ 'notepad++.exe': '',
1961
+ 'clion.exe': '',
1962
+ 'clion64.exe': '',
1963
+ 'idea.exe': '',
1964
+ 'idea64.exe': '',
1965
+ 'phpstorm.exe': '',
1966
+ 'phpstorm64.exe': '',
1967
+ 'pycharm.exe': '',
1968
+ 'pycharm64.exe': '',
1969
+ 'rubymine.exe': '',
1970
+ 'rubymine64.exe': '',
1971
+ 'goland.exe': '',
1972
+ 'goland64.exe': '',
1973
+ 'rider.exe': '',
1974
+ 'rider64.exe': ''
1975
+ }
1976
+ }, COMMON_EDITOR_PROCESS_MAP = {
1977
+ darwin: {
1978
+ cursor: [
1979
+ '/Cursor.app/Contents/MacOS/Cursor'
1980
+ ],
1981
+ comate: [
1982
+ '/Comate.app/Contents/MacOS/Electron'
1983
+ ],
1984
+ windsurf: [
1985
+ '/Windsurf.app/Contents/MacOS/Electron'
1986
+ ],
1987
+ trae: [
1988
+ '/Trae.app/Contents/MacOS/Electron',
1989
+ '/Trae CN.app/Contents/MacOS/Electron'
1990
+ ],
1991
+ code: [
1992
+ '/Visual Studio Code.app/Contents/MacOS/Electron'
1993
+ ],
1994
+ 'code-insiders': [
1995
+ '/Visual Studio Code - Insiders.app/Contents/MacOS/Electron'
1996
+ ],
1997
+ webstorm: [
1998
+ '/WebStorm.app/Contents/MacOS/webstorm'
1999
+ ],
2000
+ atom: [
2001
+ '/Atom.app/Contents/MacOS/Atom'
2002
+ ],
2003
+ hbuilder: [
2004
+ '/HBuilderX.app/Contents/MacOS/HBuilderX'
2005
+ ],
2006
+ phpstorm: [
2007
+ '/PhpStorm.app/Contents/MacOS/phpstorm'
2008
+ ],
2009
+ pycharm: [
2010
+ '/PyCharm.app/Contents/MacOS/pycharm'
2011
+ ],
2012
+ idea: [
2013
+ '/IntelliJ IDEA.app/Contents/MacOS/idea'
2014
+ ],
2015
+ codium: [
2016
+ '/VSCodium.app/Contents/MacOS/Electron'
2017
+ ],
2018
+ goland: [
2019
+ '/GoLand.app/Contents/MacOS/goland'
2020
+ ],
2021
+ colin: [
2022
+ '/CLion.app/Contents/MacOS/clion'
2023
+ ],
2024
+ appcode: [
2025
+ '/AppCode.app/Contents/MacOS/appcode'
2026
+ ],
2027
+ 'atom-beta': [
2028
+ '/Atom Beta.app/Contents/MacOS/Atom Beta'
2029
+ ],
2030
+ brackets: [
2031
+ '/Brackets.app/Contents/MacOS/Brackets'
2032
+ ],
2033
+ rider: [
2034
+ '/Rider.app/Contents/MacOS/rider'
2035
+ ],
2036
+ rubymine: [
2037
+ '/RubyMine.app/Contents/MacOS/rubymine'
2038
+ ],
2039
+ sublime: [
2040
+ '/Sublime Text.app/Contents/MacOS/sublime_text'
2041
+ ],
2042
+ zed: [
2043
+ '/Zed.app/Contents/MacOS/zed'
2044
+ ]
2045
+ },
2046
+ linux: {
2047
+ code: [
2048
+ 'code'
2049
+ ],
2050
+ 'code-insiders': [
2051
+ 'code-insiders'
2052
+ ],
2053
+ webstorm: [
2054
+ 'webstorm',
2055
+ 'webstorm.sh'
2056
+ ],
2057
+ cursor: [
2058
+ 'cursor'
2059
+ ],
2060
+ windsurf: [
2061
+ 'windsurf'
2062
+ ],
2063
+ atom: [
2064
+ 'atom'
2065
+ ],
2066
+ hbuilder: [
2067
+ 'hbuilderx',
2068
+ 'hbuilderx.sh'
2069
+ ],
2070
+ phpstorm: [
2071
+ 'phpstorm',
2072
+ 'phpstorm.sh'
2073
+ ],
2074
+ pycharm: [
2075
+ 'pycharm',
2076
+ 'pycharm.sh'
2077
+ ],
2078
+ idea: [
2079
+ 'idea',
2080
+ 'idea.sh'
2081
+ ],
2082
+ codium: [
2083
+ 'vscodium'
2084
+ ],
2085
+ goland: [
2086
+ 'goland'
2087
+ ],
2088
+ brackets: [
2089
+ 'Brackets'
2090
+ ],
2091
+ rider: [
2092
+ 'rider'
2093
+ ],
2094
+ rubymine: [
2095
+ 'rubymine',
2096
+ 'rubymine.sh'
2097
+ ],
2098
+ sublime: [
2099
+ 'sublime_text'
2100
+ ],
2101
+ vim: [
2102
+ 'vim'
2103
+ ],
2104
+ emacs: [
2105
+ 'emacs'
2106
+ ]
2107
+ },
2108
+ win32: {
2109
+ code: [
2110
+ 'Code.exe'
2111
+ ],
2112
+ 'code-insiders': [
2113
+ 'Code - Insiders.exe'
2114
+ ],
2115
+ webstorm: [
2116
+ 'webstorm.exe',
2117
+ 'webstorm64.exe'
2118
+ ],
2119
+ cursor: [
2120
+ 'Cursor.exe'
2121
+ ],
2122
+ windsurf: [
2123
+ 'Windsurf.exe'
2124
+ ],
2125
+ trae: [
2126
+ 'Trae.exe',
2127
+ 'Trae CN.exe'
2128
+ ],
2129
+ comate: [
2130
+ 'comate.exe'
2131
+ ],
2132
+ atom: [
2133
+ 'atom.exe'
2134
+ ],
2135
+ hbuilder: [
2136
+ 'HBuilderX.exe',
2137
+ 'HBuilder.exe',
2138
+ 'HBuilderX64.exe',
2139
+ 'HBuilder64.exe'
2140
+ ],
2141
+ phpstorm: [
2142
+ 'phpstorm.exe',
2143
+ 'phpstorm64.exe'
2144
+ ],
2145
+ pycharm: [
2146
+ 'pycharm.exe',
2147
+ 'pycharm64.exe'
2148
+ ],
2149
+ idea: [
2150
+ 'idea.exe',
2151
+ 'idea64.exe'
2152
+ ],
2153
+ codium: [
2154
+ 'VSCodium.exe'
2155
+ ],
2156
+ goland: [
2157
+ 'goland.exe',
2158
+ 'goland64.exe'
2159
+ ],
2160
+ colin: [
2161
+ 'clion.exe',
2162
+ 'clion64.exe'
2163
+ ],
2164
+ brackets: [
2165
+ 'Brackets.exe'
2166
+ ],
2167
+ rider: [
2168
+ 'rider.exe',
2169
+ 'rider64.exe'
2170
+ ],
2171
+ rubymine: [
2172
+ 'rubymine.exe',
2173
+ 'rubymine64.exe'
2174
+ ],
2175
+ sublime: [
2176
+ 'sublime_text.exe'
2177
+ ],
2178
+ notepad: [
2179
+ 'notepad++.exe'
2180
+ ]
2181
+ }
2182
+ }, FormatFile = '{file}', FormatLine = '{line}', FormatColumn = '{column}', processExecutionMap = {
2183
+ darwin: 'ps ax -o comm=',
2184
+ linux: 'ps -eo comm --sort=comm',
2185
+ win32: 'wmic process where "executablepath is not null" get executablepath'
2186
+ }, compatibleWithChineseCharacter = (isWin32)=>{
2187
+ if (isWin32) try {
2188
+ node_child_process.execSync('chcp 65001');
2189
+ } catch {}
2190
+ }, _childProcess = null, positionRE = /:(\d+)(:(\d+))?$/;
2191
+ function launchEditor(file, options) {
2192
+ let { editor: specifiedEditor, method, onError } = options || {}, parsed = function(file) {
2193
+ let _file = file;
2194
+ _file.startsWith('file://') && (_file = __webpack_require__("node:url").fileURLToPath(_file));
2195
+ let fileName = _file.replace(positionRE, ''), match = _file.match(positionRE);
2196
+ return {
2197
+ fileName,
2198
+ lineNumber: (null == match ? void 0 : match[1]) || 1,
2199
+ columnNumber: (null == match ? void 0 : match[3]) || 1
2200
+ };
2201
+ }(file), { fileName } = parsed, { lineNumber, columnNumber } = parsed;
2202
+ if (!node_fs.existsSync(fileName)) return;
2203
+ let onErrorCallback = (fileName, errorMessage)=>{
2204
+ if (console.log(), console.log(colors.red('Could not open ' + node_path.basename(fileName) + ' in the editor.')), errorMessage) {
2205
+ let displayErrorMessage = errorMessage;
2206
+ '.' !== displayErrorMessage[displayErrorMessage.length - 1] && (displayErrorMessage += '.'), console.log(colors.red('The editor process exited with an error: ' + displayErrorMessage));
2207
+ }
2208
+ console.log(), onError && onError(fileName, errorMessage);
2209
+ }, [editor, ...args] = function(specifiedEditor) {
2210
+ let platform = process.platform;
2211
+ if (specifiedEditor) {
2212
+ var _COMMON_EDITOR_PROCESS_MAP_platform;
2213
+ let editor = null == (_COMMON_EDITOR_PROCESS_MAP_platform = COMMON_EDITOR_PROCESS_MAP[platform]) ? void 0 : _COMMON_EDITOR_PROCESS_MAP_platform[specifiedEditor];
2214
+ if (editor) return editor;
2215
+ }
2216
+ let editorFromPid = function() {
2217
+ let platform = process.platform, editorNames = Object.keys(COMMON_EDITORS_MAP[platform]);
2218
+ try {
2219
+ return function(pid, platform, editorNames) {
2220
+ let depth = 0, currentPid = pid;
2221
+ for(; currentPid && 0 !== currentPid && depth < 50;){
2222
+ let processInfo = function(pid, platform) {
2223
+ switch(platform){
2224
+ case 'darwin':
2225
+ case 'linux':
2226
+ var pid1, pid2 = pid;
2227
+ try {
2228
+ let lines = node_child_process.execSync(`ps -p ${pid2} -o ppid=,comm=`, {
2229
+ encoding: 'utf8'
2230
+ }).trim().split('\n');
2231
+ if (!lines.length) return null;
2232
+ var processLine = lines[0].trim();
2233
+ let match = processLine.match(/^(\d+)\s+(.+)$/);
2234
+ return match ? {
2235
+ command: match[2],
2236
+ parentPid: Number.parseInt(match[1])
2237
+ } : null;
2238
+ } catch {
2239
+ return null;
2240
+ }
2241
+ case 'win32':
2242
+ return pid1 = pid, function(pid) {
2243
+ try {
2244
+ compatibleWithChineseCharacter(!0);
2245
+ let lines = node_child_process.execSync(`wmic process where "ProcessId=${pid}" get ParentProcessId,ExecutablePath /format:csv`, {
2246
+ encoding: 'utf8'
2247
+ }).trim().split('\r\n').filter((line)=>line.trim()).slice(1);
2248
+ if (0 === lines.length) return null;
2249
+ let parts = lines[0].split(',');
2250
+ if (parts.length < 3) return null;
2251
+ return {
2252
+ command: parts[1].trim(),
2253
+ parentPid: Number.parseInt(parts[2].trim())
2254
+ };
2255
+ } catch {
2256
+ return null;
2257
+ }
2258
+ }(pid1) || function(pid) {
2259
+ try {
2260
+ compatibleWithChineseCharacter(!0);
2261
+ let line = node_child_process.execSync(`powershell -NoProfile -Command "Get-CimInstance -Query \"select ParentProcessId,ExecutablePath from win32_process where ProcessId=${pid}\" | ForEach-Object { $_.ExecutablePath + ',' + $_.ParentProcessId }"`, {
2262
+ encoding: 'utf8'
2263
+ }).trim();
2264
+ if (!line) return null;
2265
+ let parts = line.split(',');
2266
+ if (parts.length < 2) return null;
2267
+ return {
2268
+ command: parts[0].trim(),
2269
+ parentPid: Number.parseInt(parts[1].trim())
2270
+ };
2271
+ } catch {
2272
+ return null;
2273
+ }
2274
+ }(pid1);
2275
+ default:
2276
+ return null;
2277
+ }
2278
+ }(currentPid, platform);
2279
+ if (!processInfo) break;
2280
+ let { command, parentPid } = processInfo;
2281
+ if (function(command, editorNames) {
2282
+ return editorNames.some((editorName)=>command.toLowerCase().endsWith(editorName.toLowerCase()));
2283
+ }(command, editorNames)) return command;
2284
+ currentPid = parentPid, depth++;
2285
+ }
2286
+ return null;
2287
+ }(process.pid, platform, editorNames);
2288
+ } catch (error) {
2289
+ return console.error('Error while getting editor by PID:', error), null;
2290
+ }
2291
+ }();
2292
+ if (editorFromPid) return [
2293
+ editorFromPid
2294
+ ];
2295
+ try {
2296
+ let first, isWin32 = 'win32' === process.platform, execution = processExecutionMap[platform], commonEditors = COMMON_EDITORS_MAP[platform];
2297
+ compatibleWithChineseCharacter(isWin32);
2298
+ let output = '';
2299
+ try {
2300
+ output = node_child_process.execSync(execution, {
2301
+ encoding: 'utf-8'
2302
+ });
2303
+ } catch {
2304
+ isWin32 && (output = node_child_process.execSync('powershell -NoProfile -Command "Get-CimInstance -Query \\"select executablepath from win32_process where executablepath is not null\\" | % { $_.ExecutablePath }"', {
2305
+ encoding: 'utf-8'
2306
+ }));
2307
+ }
2308
+ let editorNames = Object.keys(commonEditors), runningProcesses = output.split(isWin32 ? '\r\n' : '\n').map((item)=>item.trim());
2309
+ for(let i = 0; i < editorNames.length; i++){
2310
+ let editorName = editorNames[i], editor = '', runningEditor = '';
2311
+ if (isWin32) {
2312
+ let processPath = runningProcesses.find((_process)=>node_path.basename(_process).toLowerCase() === editorName.toLowerCase());
2313
+ processPath && (runningEditor = node_path.basename(processPath), editor = processPath);
2314
+ } else if ('darwin' === platform) {
2315
+ let runningProcess = runningProcesses.find((_process)=>_process.toLowerCase().endsWith(editorName.toLowerCase()));
2316
+ if (runningProcess) {
2317
+ let prefixPath = runningProcess.replace(editorName, ''), processName = commonEditors[editorName];
2318
+ runningEditor = editorName, editor = processName.includes('/') ? `${prefixPath}${processName}` : processName;
2319
+ }
2320
+ } else -1 !== output.indexOf(editorName) && (runningEditor = editorName, editor = commonEditors[editorName]);
2321
+ if (runningEditor && editor && !first) {
2322
+ first = [
2323
+ editor
2324
+ ];
2325
+ break;
2326
+ }
2327
+ }
2328
+ if (first) return first;
2329
+ } catch {}
2330
+ return process.env.VISUAL ? [
2331
+ process.env.VISUAL
2332
+ ] : process.env.EDITOR ? [
2333
+ process.env.EDITOR
2334
+ ] : [];
2335
+ }(specifiedEditor);
2336
+ if (!editor) return void onErrorCallback(fileName);
2337
+ if ('linux' === process.platform && fileName.startsWith('/mnt/') && /Microsoft/i.test(node_os.release()) && (fileName = node_path.relative('', fileName)), args = args.concat(function({ processName, fileName, lineNumber, columnNumber, workspace, openMethodArgs }) {
2338
+ let format = function({ editorBasename, openMethodArgs, workspace }) {
2339
+ switch(editorBasename){
2340
+ case 'atom':
2341
+ case 'atom beta':
2342
+ case 'subl':
2343
+ case 'sublime':
2344
+ case 'sublime_text':
2345
+ case 'wstorm':
2346
+ case 'charm':
2347
+ case 'zed':
2348
+ return `${FormatFile}:${FormatLine}:${FormatColumn}`;
2349
+ case 'notepad++':
2350
+ return [
2351
+ '-n' + FormatLine,
2352
+ '-c' + FormatColumn,
2353
+ FormatFile
2354
+ ];
2355
+ case 'vim':
2356
+ case 'mvim':
2357
+ return [
2358
+ `+call cursor(${FormatLine}, ${FormatColumn})`,
2359
+ FormatFile
2360
+ ];
2361
+ case 'joe':
2362
+ case 'gvim':
2363
+ return [
2364
+ '+' + FormatLine,
2365
+ FormatFile
2366
+ ];
2367
+ case 'emacs':
2368
+ case 'emacsclient':
2369
+ return [
2370
+ '+' + FormatLine + ':' + FormatColumn,
2371
+ FormatFile
2372
+ ];
2373
+ case 'rmate':
2374
+ case 'mate':
2375
+ case 'mine':
2376
+ return [
2377
+ '--line',
2378
+ FormatLine,
2379
+ FormatFile
2380
+ ];
2381
+ case 'code':
2382
+ case 'code-insiders':
2383
+ case 'code - insiders':
2384
+ case 'codium':
2385
+ case 'cursor':
2386
+ case 'windsurf':
2387
+ case 'trae':
2388
+ case 'comate':
2389
+ case 'vscodium':
2390
+ case 'hbuilderx':
2391
+ case 'hbuilder':
2392
+ return [
2393
+ ...workspace ? [
2394
+ workspace
2395
+ ] : [],
2396
+ '-g',
2397
+ ...openMethodArgs ? [
2398
+ openMethodArgs
2399
+ ] : [],
2400
+ `${FormatFile}:${FormatLine}:${FormatColumn}`
2401
+ ];
2402
+ case 'appcode':
2403
+ case 'clion':
2404
+ case 'clion64':
2405
+ case 'idea':
2406
+ case 'idea64':
2407
+ case 'phpstorm':
2408
+ case 'phpstorm64':
2409
+ case 'pycharm':
2410
+ case 'pycharm64':
2411
+ case 'rubymine':
2412
+ case 'rubymine64':
2413
+ case 'webstorm':
2414
+ case 'webstorm64':
2415
+ case 'goland':
2416
+ case 'goland64':
2417
+ case 'rider':
2418
+ case 'rider64':
2419
+ return [
2420
+ ...workspace ? [
2421
+ workspace
2422
+ ] : [],
2423
+ '--line',
2424
+ FormatLine,
2425
+ FormatFile
2426
+ ];
2427
+ }
2428
+ return '';
2429
+ }({
2430
+ editorBasename: function(processName) {
2431
+ let editorBasename = node_path.basename(processName).replace(/\.(exe|cmd|bat|sh)$/i, ''), platform = process.platform, editorBasenameList = Object.keys(COMMON_EDITOR_PROCESS_MAP[platform]);
2432
+ for(let i = 0; i < editorBasenameList.length; i++)if ((COMMON_EDITOR_PROCESS_MAP[platform][editorBasenameList[i]] || []).some((editorPath)=>processName.endsWith(editorPath))) {
2433
+ editorBasename = editorBasenameList[i];
2434
+ break;
2435
+ }
2436
+ return editorBasename.toLowerCase();
2437
+ }(processName),
2438
+ openMethodArgs,
2439
+ workspace
2440
+ }) || '{file}', formattedPath = `${fileName}:${lineNumber}:${columnNumber}`;
2441
+ if ('string' == typeof format) formattedPath = format.replace(FormatFile, fileName).replace(FormatLine, lineNumber.toString()).replace(FormatColumn, columnNumber.toString());
2442
+ else if (Array.isArray(format)) return format.map((item)=>item.replace(FormatFile, fileName).replace(FormatLine, lineNumber.toString()).replace(FormatColumn, columnNumber.toString()));
2443
+ return [
2444
+ formattedPath
2445
+ ];
2446
+ }({
2447
+ processName: editor,
2448
+ fileName,
2449
+ lineNumber,
2450
+ columnNumber,
2451
+ workspace: null,
2452
+ openMethodArgs: 'reuse' === method ? '-r' : 'new' === method ? '-n' : ''
2453
+ })), _childProcess && function(editor) {
2454
+ switch(editor){
2455
+ case 'vim':
2456
+ case 'emacs':
2457
+ case 'nano':
2458
+ return !0;
2459
+ }
2460
+ return !1;
2461
+ }(editor) && _childProcess.kill('SIGKILL'), 'win32' === process.platform) {
2462
+ let launchCommand = [
2463
+ editor,
2464
+ ...args.map((cmdArgs)=>cmdArgs.replace(/([&|<>,;=^])/g, '^$1'))
2465
+ ].map((str)=>str.includes('^') ? `^"${str}^"` : str.includes(' ') ? `"${str}"` : str).join(' ');
2466
+ _childProcess = node_child_process.exec(launchCommand, {
2467
+ shell: !0
2468
+ });
2469
+ } else _childProcess = node_child_process.spawn(editor, args);
2470
+ _childProcess.on('exit', (errorCode)=>{
2471
+ _childProcess = null, errorCode && onErrorCallback(fileName, '(code ' + errorCode + ')');
2472
+ }), _childProcess.on('error', (error)=>{
2473
+ let { message } = error;
2474
+ onErrorCallback(fileName, message);
2475
+ });
2476
+ }
1871
2477
  let GLOB_REGEX = /[*?{}[\]()!@+|]/;
1872
2478
  async function createChokidar(pathOrGlobs, root = process.cwd(), options) {
1873
2479
  let watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!GLOB_REGEX.test(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
@@ -1881,4 +2487,4 @@ async function createChokidar(pathOrGlobs, root = process.cwd(), options) {
1881
2487
  ...options
1882
2488
  });
1883
2489
  }
1884
- export { CSS_MODULES_LOCAL_IDENT_NAME, CSS_MODULES_REGEX, CSS_NAMED_EXPORT, DEFAULT_DEV_HOST, DEV_DEFAULT_FILENAME, EXPORT_LOCALS_CONVENTION, logger_LogColor as LogColor, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, TEMPLATE_CONTENT, TEMP_DIR, THREAD_OPTIONS, clearLine, colors, createChokidar, createUnpack, debounce, defineConfig, esVersionToBrowserslist, findExists, getAddressUrls, getCompiledPkgPath, getIpv4Interfaces, getNodeEnv, getPathInJs, getPort, getTime, getUserDepPath, getUserDepVersion, getValueByPath, isBoolean, isCI, isCSSModules, isDebug, isDev, utils_isDevServer as isDevServer, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isProd, isRegExp, isString, isUndefined, isWatch, isWin, loadConfig, logUpdate, logger_logger as logger, mergeConfig, pathExists, prettyTime, removeDir, resolveConfigPath, restartCleaners, rspack, setDevServer, setNodeEnv, setValueByPath, trackPerformance };
2490
+ export { CSS_MODULES_LOCAL_IDENT_NAME, CSS_MODULES_REGEX, CSS_NAMED_EXPORT, DEFAULT_DEV_HOST, DEV_DEFAULT_FILENAME, EXPORT_LOCALS_CONVENTION, logger_LogColor as LogColor, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, TEMPLATE_CONTENT, TEMP_DIR, THREAD_OPTIONS, clearLine, colors, createChokidar, createUnpack, debounce, defineConfig, esVersionToBrowserslist, findExists, getAddressUrls, getCompiledPkgPath, getIpv4Interfaces, getNodeEnv, getPathInJs, getPort, getTime, getUserDepPath, getUserDepVersion, getValueByPath, isBoolean, isCI, isCSSModules, isDebug, isDev, utils_isDevServer as isDevServer, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isProd, isRegExp, isString, isUndefined, isWatch, isWin, launchEditor, loadConfig, logUpdate, logger_logger as logger, mergeConfig, pathExists, prettyTime, removeDir, resolveConfigPath, restartCleaners, rspack, setDevServer, setNodeEnv, setValueByPath, trackPerformance };