@unpackjs/core 3.8.2 → 3.9.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 (33) hide show
  1. package/compiled/css-loader/index.js +20 -20
  2. package/compiled/less-loader/index.js +8 -8
  3. package/compiled/postcss-loader/index.js +11 -11
  4. package/compiled/sass-loader/index.js +8 -8
  5. package/dist/index.js +134 -142
  6. package/dist/rslib-runtime.js +1 -1
  7. package/dist/transformLoader.js +3 -7
  8. package/dist/typedCssModulesLoader.js +3 -72
  9. package/dist-types/bundler-config/css.d.ts.map +1 -1
  10. package/dist-types/bundler-config/detectCircular.d.ts.map +1 -1
  11. package/dist-types/bundler-config/experimentCss.d.ts.map +1 -1
  12. package/dist-types/bundler-config/html.d.ts.map +1 -1
  13. package/dist-types/bundler-config/index.d.ts.map +1 -1
  14. package/dist-types/bundler-config/loaders/transformLoader.d.ts +1 -1
  15. package/dist-types/bundler-config/loaders/transformLoader.d.ts.map +1 -1
  16. package/dist-types/bundler-config/loaders/typedCssModulesLoader.d.ts +2 -4
  17. package/dist-types/bundler-config/loaders/typedCssModulesLoader.d.ts.map +1 -1
  18. package/dist-types/bundler-config/plugins/progress/helpers.d.ts.map +1 -1
  19. package/dist-types/constants.d.ts +4 -4
  20. package/dist-types/constants.d.ts.map +1 -1
  21. package/dist-types/createUnpack.d.ts.map +1 -1
  22. package/dist-types/plugins/autoCssModules.d.ts +3 -0
  23. package/dist-types/plugins/autoCssModules.d.ts.map +1 -0
  24. package/dist-types/plugins/browserLogs.d.ts.map +1 -1
  25. package/dist-types/plugins/prebundle.d.ts.map +1 -1
  26. package/dist-types/run/dev.d.ts.map +1 -1
  27. package/dist-types/types/config.d.ts +1 -14
  28. package/dist-types/types/config.d.ts.map +1 -1
  29. package/dist-types/types/plugin.d.ts +4 -1
  30. package/dist-types/types/plugin.d.ts.map +1 -1
  31. package/dist-types/utils.d.ts +4 -8
  32. package/dist-types/utils.d.ts.map +1 -1
  33. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  let lastTrackTime, lastFileInfo, logger;
2
- import __rslib_shim_module__ from 'module';
2
+ import __rslib_shim_module__ from "node:module";
3
3
  let require = __rslib_shim_module__.createRequire(import.meta.url);
4
4
  import { fileURLToPath as __rspack_fileURLToPath, pathToFileURL } from "node:url";
5
5
  import node_path, { dirname as __rspack_dirname, join, sep } from "node:path";
@@ -9,7 +9,6 @@ import { __webpack_require__ } from "./rslib-runtime.js";
9
9
  import { rspack } from "@rspack/core";
10
10
  import node_readline from "node:readline";
11
11
  import node_fs from "node:fs";
12
- import node_net from "node:net";
13
12
  import node_os, { platform } from "node:os";
14
13
  import portfinder from "portfinder";
15
14
  import { format, promisify } from "node:util";
@@ -106,7 +105,7 @@ let restartCleaners = [], addRestartCleaner = (...cleaners)=>{
106
105
  unpackStartTime = time;
107
106
  };
108
107
  var LogColor, logger_LogColor = ((LogColor = {}).error = "red", LogColor.warn = "yellow", LogColor.info = "cyan", LogColor.ready = "green", LogColor.event = "magenta", LogColor.wait = "blue", LogColor);
109
- let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULES_REGEX = /\.module\.\w+$/i, DEV_DEFAULT_FILENAME = {
108
+ let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULES_EXPORTS_CONVENTION = 'camel-case', DEV_DEFAULT_FILENAME = {
110
109
  js: 'js/[name].js',
111
110
  jsAsync: 'js/async/[name].js',
112
111
  css: 'css/[name].css',
@@ -116,7 +115,7 @@ let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULE
116
115
  jsAsync: 'js/async/[name].[contenthash:8].js',
117
116
  css: 'css/[name].[contenthash:8].css',
118
117
  cssAsync: 'css/async/[name].[contenthash:8].css'
119
- }, EXPORT_LOCALS_CONVENTION = 'camel-case-only', NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, DEFAULT_DEV_HOST = '0.0.0.0', TEMPLATE_CONTENT = ({ title = '', headTag = '', mountId = '' })=>`<!DOCTYPE html>
118
+ }, NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, ALL_INTERFACES_IPV4 = '0.0.0.0', LOCALHOST = 'localhost', TEMPLATE_CONTENT = ({ title = '', headTag = '', mountId = '' })=>`<!DOCTYPE html>
120
119
  <html>
121
120
  <head>
122
121
  <meta charset="UTF-8">
@@ -191,17 +190,17 @@ let debounce = (fn, delay)=>{
191
190
  }
192
191
  return Array.from(ipv4Interfaces.values());
193
192
  }, isLoopbackHost = (host)=>[
194
- 'localhost',
193
+ LOCALHOST,
195
194
  '127.0.0.1',
196
195
  '::1',
197
196
  '0000:0000:0000:0000:0000:0000:0000:0001'
198
- ].includes(host), concatUrl = ({ host, port, protocol, base })=>`${protocol}://${host}:${port}${normalizePublicPath(base)}`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getAddressUrls = ({ protocol = 'http', port, host, base })=>{
199
- if (host && host !== DEFAULT_DEV_HOST) return [
197
+ ].includes(host), concatUrl = ({ host, port, protocol, base })=>`${protocol}://${host}:${port}${normalizePublicPath(base)}`, LOCAL_LABEL = 'Local: ', getAddressUrls = ({ protocol = 'http', port, host, base })=>{
198
+ if (!host) return [
200
199
  {
201
- label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
200
+ label: LOCAL_LABEL,
202
201
  url: concatUrl({
202
+ host: LOCALHOST,
203
203
  port,
204
- host: node_net.isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host,
205
204
  protocol,
206
205
  base
207
206
  })
@@ -213,14 +212,14 @@ let debounce = (fn, delay)=>{
213
212
  addressUrls.push({
214
213
  label: LOCAL_LABEL,
215
214
  url: concatUrl({
216
- host: 'localhost',
215
+ host: LOCALHOST,
217
216
  port,
218
217
  protocol,
219
218
  base
220
219
  })
221
220
  }), hasLocalUrl = !0;
222
221
  } else addressUrls.push({
223
- label: NETWORK_LABEL,
222
+ label: 'Network: ',
224
223
  url: concatUrl({
225
224
  host: detail.address,
226
225
  port,
@@ -247,12 +246,7 @@ function isNodeVersionAtLeast(major, minor) {
247
246
  let [currMajor, currMinor] = process.versions.node.split('.').map(Number);
248
247
  return currMajor > major || currMajor === major && currMinor >= minor;
249
248
  }
250
- let isCSSModules = ({ resourcePath, modules })=>{
251
- if (!1 === modules) return !1;
252
- isPlainObject(modules) || (modules = {});
253
- let auto = modules.auto;
254
- return !1 !== auto && (isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath));
255
- }, esVersionToBrowserslist = (esVersion)=>{
249
+ let esVersionToBrowserslist = (esVersion)=>{
256
250
  let browsers = {
257
251
  es2022: [
258
252
  'chrome >= 94',
@@ -322,16 +316,13 @@ let pathToExportIdentifier = (path)=>{
322
316
  function printServerUrls({ port, host, base }) {
323
317
  let addressUrls = getAddressUrls({
324
318
  port,
325
- base
319
+ base,
320
+ host
326
321
  }), colorPrefix = colors.brand('➜');
327
- addressUrls.forEach((addr, index)=>{
322
+ addressUrls.forEach((addr)=>{
328
323
  let url;
329
- if (!host && 0 !== index) {
330
- 1 === index && console.log(` ${colors.dim(colorPrefix)} ${colors.bold(colors.dim('Network:'))} ${colors.dim('use')} ${colors.bold('--host')} ${colors.dim('to expose')}`);
331
- return;
332
- }
333
324
  console.log(` ${colorPrefix} ${colors.bold(addr.label)}${(url = addr.url, colors.cyan(url.replace(/:(\d+)\//, (_, port)=>`:${colors.bold(port)}/`)))}`);
334
- });
325
+ }), host || console.log(` ${colors.dim(colorPrefix)} ${colors.bold(colors.dim('Network:'))} ${colors.dim('use')} ${colors.bold('--host')} ${colors.dim('to expose')}`);
335
326
  }
336
327
  function getHtmlTemplateOrContent(rawTemplate, root) {
337
328
  let template, templateContent;
@@ -537,7 +528,7 @@ let removeDir = (dir)=>{
537
528
  recursive: !0,
538
529
  force: !0
539
530
  });
540
- }, BROWSER_LOGS_ENDPOINT = '/__browser_logs__', browserLogs_SCRIPT_REGEX = /\.(js|jsx|mjs|cjs|ts|tsx|mts|cts|vue|svelte)$/, gzip = promisify(node_zlib.gzip), numberFormatter = new Intl.NumberFormat('en', {
531
+ }, STYLE_IMPORT_RE = /import\s+([\s\S]+?)\s+from\s+(['"])(.*?\.(?:css|less|scss|sass))\2/g, BROWSER_LOGS_ENDPOINT = '/__browser_logs__', browserLogs_SCRIPT_REGEX = /\.(js|jsx|mjs|cjs|ts|tsx|mts|cts|vue|svelte)$/, gzip = promisify(node_zlib.gzip), numberFormatter = new Intl.NumberFormat('en', {
541
532
  maximumFractionDigits: 2,
542
533
  minimumFractionDigits: 2
543
534
  }), displaySize = (bytes)=>`${numberFormatter.format(bytes / 1000)} kB`;
@@ -729,26 +720,23 @@ let getOutputFilename = ({ type, hash, async })=>{
729
720
  };
730
721
  var css_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
731
722
  async function applyHtmlConfig({ config, unpackConfig }) {
732
- if (!unpackConfig.mpa) {
733
- let htmlConfig = unpackConfig.html || {}, { template, templateContent } = getHtmlTemplateOrContent(htmlConfig.template, unpackConfig.root), templateParameters = {
734
- mountId: htmlConfig.mountId,
735
- title: isFunction(htmlConfig.title) ? htmlConfig.title({
736
- entryName: 'index'
737
- }) : htmlConfig.title || '',
738
- headTag: htmlConfig.headTag || '',
739
- ...htmlConfig.templateParameters
740
- };
741
- config.plugins.push(new rspack.HtmlRspackPlugin({
742
- template,
743
- templateContent,
744
- templateParameters,
745
- minify: !1,
746
- chunks: [
747
- 'main'
748
- ]
749
- }));
750
- }
751
- return config;
723
+ let htmlConfig = unpackConfig.html || {}, { template, templateContent } = getHtmlTemplateOrContent(htmlConfig.template, unpackConfig.root), templateParameters = {
724
+ mountId: htmlConfig.mountId,
725
+ title: isFunction(htmlConfig.title) ? htmlConfig.title({
726
+ entryName: 'index'
727
+ }) : htmlConfig.title || '',
728
+ headTag: htmlConfig.headTag || '',
729
+ ...htmlConfig.templateParameters
730
+ };
731
+ return config.plugins.push(new rspack.HtmlRspackPlugin({
732
+ template,
733
+ templateContent,
734
+ templateParameters,
735
+ minify: !1,
736
+ chunks: [
737
+ 'main'
738
+ ]
739
+ })), config;
752
740
  }
753
741
  let { RawSource: RawSource, SourceMapSource: SourceMapSource } = rspack.sources, isJsFile = /\.[cm]?js(\?.*)?$/i, jsMinify_PLUGIN_NAME = 'JsMinifyPlugin';
754
742
  class JsMinifyPlugin {
@@ -761,7 +749,7 @@ class JsMinifyPlugin {
761
749
  apply(compiler) {
762
750
  let meta = JSON.stringify({
763
751
  name: jsMinify_PLUGIN_NAME,
764
- version: "3.8.2",
752
+ version: "3.9.0",
765
753
  options: this.minifyOptions
766
754
  });
767
755
  compiler.hooks.compilation.tap(jsMinify_PLUGIN_NAME, (compilation)=>{
@@ -871,7 +859,7 @@ async function compileDone(compiler, stats) {
871
859
  (packageName = '.pnpm' === pathParts[0] && pathParts.length >= 4 ? pathParts[3].startsWith('@') ? `${pathParts[3]}/${pathParts[4]}` : pathParts[3] : pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0]) && (nodeModulesStats[packageName] = (nodeModulesStats[packageName] || 0) + 1);
872
860
  }
873
861
  }), nodeModulesStats)).sort((a, b)=>a[1] - b[1]).forEach(([packageName, count])=>{
874
- logger_logger.debug(`${colors.cyan(packageName)}: ${colors.yellow(count)} modules`);
862
+ count > 10 && logger_logger.debug(`${colors.cyan(packageName)}: ${colors.yellow(count)} modules`);
875
863
  });
876
864
  }
877
865
  isDebug() || logger_logger.clear(), console.log(colors.dim(getTime()), colors.cyan(`[${getCurrentUnpackConfig()._context.callerName}]`), colors.brand(utils_isDevServer() ? 'hmr update' : 'build'), `${colors.dim(fileInfo)}${sameCount > 1 ? ` ${colors.yellow(`(x${sameCount})`)}` : ''}`, isDebug() ? colors.dim(`| ${prettyTime(getCompileTime(stats))} (${stats.compilation.modules.size} modules)`) : '');
@@ -1150,23 +1138,24 @@ async function getBundlerConfig(originalUnpackConfig) {
1150
1138
  performance: {
1151
1139
  hints: !1
1152
1140
  }
1153
- }, transformPlugins = getNormalizedPluginsByHook('transform');
1154
- return transformPlugins.length && config.module.rules.push({
1155
- test: SCRIPT_REGEX,
1156
- enforce: 'pre',
1157
- exclude: /node_modules/,
1158
- use: [
1159
- {
1160
- loader: node_path.resolve(bundler_config_dirname, './transformLoader.js'),
1161
- options: {
1162
- plugins: transformPlugins
1141
+ };
1142
+ for (let plugin of getNormalizedPluginsByHook('transform')){
1143
+ let { filter, handler } = plugin.transform;
1144
+ config.module.rules.push({
1145
+ exclude: NODE_MODULES_REGEX,
1146
+ ...filter,
1147
+ enforce: 'pre',
1148
+ use: [
1149
+ {
1150
+ loader: node_path.resolve(bundler_config_dirname, './transformLoader.js'),
1151
+ options: {
1152
+ handler
1153
+ }
1163
1154
  }
1164
- }
1165
- ]
1166
- }), config = await applyHtmlConfig({
1167
- config,
1168
- unpackConfig
1169
- }), config = (({ config, unpackConfig })=>{
1155
+ ]
1156
+ });
1157
+ }
1158
+ return config = (({ config, unpackConfig })=>{
1170
1159
  let { chunkSplit } = unpackConfig.performance || {};
1171
1160
  if (chunkSplit?.strategy) {
1172
1161
  let forceSplittingGroups = {};
@@ -1208,8 +1197,8 @@ async function getBundlerConfig(originalUnpackConfig) {
1208
1197
  'experiments',
1209
1198
  'css'
1210
1199
  ], !0);
1211
- let sourceMap = unpackConfig.css?.sourceMap, modules = unpackConfig.css?.modules;
1212
- isPlainObject(modules) || !1 === modules || (modules = {}), !1 !== modules && !1 !== modules.auto && (set(config, [
1200
+ let sourceMap = unpackConfig.css?.sourceMap;
1201
+ set(config, [
1213
1202
  'module',
1214
1203
  'parser',
1215
1204
  'css/module'
@@ -1220,18 +1209,14 @@ async function getBundlerConfig(originalUnpackConfig) {
1220
1209
  'generator',
1221
1210
  'css/module'
1222
1211
  ], {
1223
- localIdentName: modules.localIdentName || CSS_MODULES_LOCAL_IDENT_NAME,
1224
- exportsConvention: EXPORT_LOCALS_CONVENTION
1225
- }));
1226
- let withCssModules = ({ use })=>{
1227
- if (!1 === modules) return !1;
1228
- let auto = modules.auto;
1229
- return !1 !== auto && {
1230
- test: (resourcePath)=>resourcePath.includes('node_modules') ? CSS_MODULES_REGEX.test(resourcePath) : isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath),
1212
+ localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1213
+ exportsConvention: CSS_MODULES_EXPORTS_CONVENTION
1214
+ });
1215
+ let withCssModules = ({ use })=>({
1216
+ resourceQuery: /[?&]module(?:[=&]|$)/,
1231
1217
  use,
1232
1218
  type: 'css/module'
1233
- };
1234
- }, getLessLoader = ()=>({
1219
+ }), getLessLoader = ()=>({
1235
1220
  loader: getCompiledPkgPath('less-loader'),
1236
1221
  options: {
1237
1222
  lessOptions: mergeConfig({
@@ -1318,9 +1303,7 @@ async function getBundlerConfig(originalUnpackConfig) {
1318
1303
  config,
1319
1304
  unpackConfig
1320
1305
  }) : function({ config, unpackConfig }) {
1321
- let sourceMap = unpackConfig.css?.sourceMap, modules = unpackConfig.css?.modules;
1322
- isPlainObject(modules) || !1 === modules || (modules = {});
1323
- let getCommonRules = ({ importLoaders })=>[
1306
+ let sourceMap = unpackConfig.css?.sourceMap, getCommonRules = ({ importLoaders })=>[
1324
1307
  utils_isDevServer() ? {
1325
1308
  loader: getCompiledPkgPath('style-loader')
1326
1309
  } : {
@@ -1330,23 +1313,16 @@ async function getBundlerConfig(originalUnpackConfig) {
1330
1313
  }
1331
1314
  },
1332
1315
  isDev() && {
1333
- loader: node_path.resolve(css_dirname, './typedCssModulesLoader.js'),
1334
- options: {
1335
- modules
1336
- }
1316
+ loader: node_path.resolve(css_dirname, './typedCssModulesLoader.js')
1337
1317
  },
1338
1318
  {
1339
1319
  loader: getCompiledPkgPath('css-loader'),
1340
1320
  options: {
1341
1321
  importLoaders,
1342
1322
  modules: {
1343
- auto: (()=>{
1344
- if (!1 === modules) return !1;
1345
- let auto = modules.auto;
1346
- return !1 !== auto && ((resourcePath)=>resourcePath.includes('node_modules') ? CSS_MODULES_REGEX.test(resourcePath) : isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath));
1347
- })(),
1348
- localIdentName: !1 !== modules && (modules.localIdentName || CSS_MODULES_LOCAL_IDENT_NAME),
1349
- exportLocalsConvention: EXPORT_LOCALS_CONVENTION,
1323
+ auto: (_, resourceQuery)=>resourceQuery?.includes('module'),
1324
+ localIdentName: CSS_MODULES_LOCAL_IDENT_NAME,
1325
+ exportLocalsConvention: CSS_MODULES_EXPORTS_CONVENTION,
1350
1326
  namedExport: !1
1351
1327
  },
1352
1328
  sourceMap
@@ -1430,7 +1406,10 @@ async function getBundlerConfig(originalUnpackConfig) {
1430
1406
  unpackConfig
1431
1407
  }),
1432
1408
  unpackConfig
1433
- }), unpackConfig.performance?.cache && (config = await applyCacheConfig({
1409
+ }), unpackConfig.mpa || (config = await applyHtmlConfig({
1410
+ config,
1411
+ unpackConfig
1412
+ })), unpackConfig.performance?.cache && (config = await applyCacheConfig({
1434
1413
  config,
1435
1414
  unpackConfig,
1436
1415
  envFilePaths
@@ -1442,39 +1421,31 @@ async function getBundlerConfig(originalUnpackConfig) {
1442
1421
  unpackConfig
1443
1422
  })), unpackConfig.detectCircular && (config = function({ config, unpackConfig }) {
1444
1423
  let circularCount = 0, circularDependencyPlugin = new rspack.CircularDependencyRspackPlugin({
1445
- exclude: /node_modules/,
1424
+ exclude: NODE_MODULES_REGEX,
1446
1425
  onStart () {
1447
1426
  circularCount = 0;
1448
1427
  },
1449
1428
  onDetected (_, modules) {
1450
- circularCount++, console.log(''), logger_logger.warn('circular dependency detected:');
1451
- let uniquePaths = modules.map((module)=>{
1429
+ var paths;
1430
+ let arrow, lastIndex;
1431
+ circularCount++, logger_logger.warn('circular dependency detected:'), paths = modules.map((module)=>{
1452
1432
  let filePath = module.replace(/^.*!/, ''), relativePath = node_path.relative(unpackConfig.root, filePath);
1453
1433
  return relativePath.startsWith('..') ? filePath : relativePath;
1454
- }).slice(0, -1);
1455
- if (2 + uniquePaths.join(' → ').length > (process.stdout.columns || 80)) {
1456
- let arrow, lastIndex;
1457
- console.log(''), arrow = '↳ ', lastIndex = uniquePaths.length - 1, uniquePaths.forEach((p, i)=>{
1458
- switch(i){
1459
- case 0:
1460
- console.log(` ${p}`);
1461
- break;
1462
- case lastIndex:
1463
- console.log(` ${arrow}${p} ${colors.dim('(cycle introduced)')}`);
1464
- break;
1465
- default:
1466
- console.log(` ${arrow}${p}`);
1467
- }
1468
- }), console.log(` ${arrow}${uniquePaths[0]}`), console.log('');
1469
- } else {
1470
- let line1, downArrowPos, lineLength;
1471
- line1 = ' ', downArrowPos = 0, uniquePaths.forEach((p, i)=>{
1472
- line1 += p, i < uniquePaths.length - 1 ? line1 += ' → ' : downArrowPos = line1.length - 1;
1473
- }), lineLength = downArrowPos - 2, console.log(''), console.log(line1), console.log(' ' + ' '.repeat(0) + '↑' + ' '.repeat(downArrowPos - 2 - 1) + '↓'), console.log(' ' + ' '.repeat(0) + '└' + '─'.repeat(lineLength - 1) + '┘'), console.log('');
1474
- }
1434
+ }).slice(0, -1), console.log(''), arrow = colors.dim('↳ '), lastIndex = paths.length - 1, paths.forEach((p, i)=>{
1435
+ switch(i){
1436
+ case 0:
1437
+ console.log(` ${p}`);
1438
+ break;
1439
+ case lastIndex:
1440
+ console.log(` ${arrow}${p} ${colors.yellow(colors.dim('(cycle introduced)'))}`);
1441
+ break;
1442
+ default:
1443
+ console.log(` ${arrow}${p}`);
1444
+ }
1445
+ }), console.log(` ${arrow}${paths[0]}`), console.log('');
1475
1446
  },
1476
1447
  onEnd () {
1477
- circularCount > 0 && console.log(`Found ${circularCount} circular ${1 === circularCount ? 'dependency' : 'dependencies'}`);
1448
+ circularCount > 0 && console.log('Found', colors.yellow(colors.bold(`${circularCount} circular ${1 === circularCount ? 'dependency' : 'dependencies'}`)));
1478
1449
  }
1479
1450
  });
1480
1451
  return config.plugins?.push(circularDependencyPlugin), config;
@@ -1593,7 +1564,8 @@ async function unpackDev(unpackConfig) {
1593
1564
  devMiddleware: {
1594
1565
  publicPath: devPublicPath,
1595
1566
  writeToDisk: unpackConfig.dev?.writeToDisk
1596
- }
1567
+ },
1568
+ host: unpackConfig.server?.host ? ALL_INTERFACES_IPV4 : LOCALHOST
1597
1569
  }, pluginMiddlewares = [];
1598
1570
  await applyPluginsByHook('setupMiddlewares', async (impl)=>{
1599
1571
  pluginMiddlewares = await impl(pluginMiddlewares);
@@ -1609,9 +1581,9 @@ async function unpackDev(unpackConfig) {
1609
1581
  ...middlewares
1610
1582
  ]);
1611
1583
  let server = new RspackDevServer(devServerOptions, compiler);
1612
- await server.start(), logger_logger.greet(` ${colors.brand(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v3.8.2${unpackConfig.performance?.cache ? ' ϟ' : ''}`)} ${colors.dim('ready in')} ${colors.bold(Math.ceil(performance.now() - getUnpackStartTime()))} ${colors.dim('ms')}\n`), printServerUrls({
1584
+ await server.start(), logger_logger.greet(` ${colors.brand(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v3.9.0${unpackConfig.performance?.cache ? ' ϟ' : ''}`)} ${colors.dim('ready in')} ${colors.bold(Math.ceil(performance.now() - getUnpackStartTime()))} ${colors.dim('ms')}\n`), printServerUrls({
1613
1585
  port,
1614
- host: unpackConfig.server?.host,
1586
+ host: unpackConfig.server.host,
1615
1587
  base: unpackConfig.base
1616
1588
  }), addRestartCleaner(()=>server.stop(), ()=>new Promise((resolve)=>compiler.close(()=>resolve())));
1617
1589
  let open = unpackConfig.server?.open, url = isString(open) ? open : `http://localhost:${port}${devPublicPath}`;
@@ -1623,7 +1595,7 @@ async function unpackDev(unpackConfig) {
1623
1595
  function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'unpack' }) {
1624
1596
  let _context = {
1625
1597
  callerName,
1626
- version: "3.8.2",
1598
+ version: "3.9.0",
1627
1599
  cachePath: 'node_modules/.unpack'
1628
1600
  }, resolveConfig = (mode)=>{
1629
1601
  let rootPath, outputPath, basePath, cachedTraceMap, fs, isValidMethodName, parseFrame, formatOriginalLocation, formatFullStack, resolveErrorLocationAndStack, shouldTransformDeepImport, preJsAssets, jsAssets, cssAssets, bundledDepsCachePath, deepImportPkgPattern, deepImportRegex, root;
@@ -1639,13 +1611,13 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1639
1611
  target: 'es2023'
1640
1612
  },
1641
1613
  server: {
1642
- port: 3000
1614
+ port: 3000,
1615
+ host: !1
1643
1616
  },
1644
1617
  html: {
1645
1618
  mountId: 'root'
1646
1619
  },
1647
1620
  css: {
1648
- modules: !0,
1649
1621
  transformer: 'postcss',
1650
1622
  sourceMap: !1
1651
1623
  },
@@ -1661,6 +1633,15 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1661
1633
  'PUBLIC_'
1662
1634
  ],
1663
1635
  plugins: [
1636
+ {
1637
+ name: 'unpack:auto-css-modules',
1638
+ transform: {
1639
+ filter: {
1640
+ test: JSX_REGEX
1641
+ },
1642
+ handler: (code)=>code.replace(STYLE_IMPORT_RE, (full, importClause, quote, spec)=>'string' == typeof importClause && /^\s*type\b/.test(importClause) || spec.includes('?') || spec.includes('#') ? full : `import ${importClause} from ${quote}${spec}?module${quote}`)
1643
+ }
1644
+ },
1664
1645
  (rootPath = '', outputPath = '', basePath = '/', cachedTraceMap = new Map(), fs = null, isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.test(methodName), parseFrame = async (frame)=>{
1665
1646
  let { file, column, lineNumber } = frame;
1666
1647
  if (!file || null == lineNumber || null == column) return;
@@ -1731,7 +1712,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1731
1712
  /(^|[\\/])src[\\/]/.test(locationText) && srcLines.push(line);
1732
1713
  }
1733
1714
  }
1734
- return srcLines.length > 0 ? srcLines.join('') : allLines.join('');
1715
+ return srcLines.length > 0 ? srcLines[0] : allLines.join('');
1735
1716
  }, resolveErrorLocationAndStack = async (item)=>{
1736
1717
  let locationFromMsg = item.message ? ((message)=>{
1737
1718
  let match = message.match(/((?:[A-Za-z]:)?\/[^\s:]+):(\d+):(\d+)/);
@@ -1864,12 +1845,11 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1864
1845
  }
1865
1846
  switch(item.type){
1866
1847
  case 'string':
1867
- return ((message)=>{
1868
- let trimmed = message.trim();
1869
- if (!trimmed) return !0;
1870
- let normalizedFirstLine = (trimmed.split('\n', 1)[0]?.trim() || '').replace(/`/g, '');
1871
- return /^at\s+/.test(normalizedFirstLine);
1872
- })(item.message) ? '' : item.message;
1848
+ let trimmed;
1849
+ return (trimmed = item.message.trim()) ? trimmed.split(/\r?\n/g).filter((line)=>{
1850
+ let normalized = line.trim().replace(/`/g, '');
1851
+ return !!normalized && !/^at\s+/.test(normalized);
1852
+ }).join('\n').trim() : '';
1873
1853
  case 'null':
1874
1854
  return null;
1875
1855
  case 'undefined':
@@ -1905,12 +1885,12 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1905
1885
  format(cleanedTemplate, ...rest)
1906
1886
  ];
1907
1887
  })(formattedArgs), prefix = colors.dim(`[browser ${time}]`);
1908
- switch(level){
1888
+ switch(console.log(''), level){
1909
1889
  case 'error':
1910
- logger_logger.error(`${prefix} ${outputArgs.join(' ')}`);
1890
+ logger_logger.error(`${prefix} ${format(...outputArgs)}`);
1911
1891
  break;
1912
1892
  case 'warn':
1913
- logger_logger.warn(`${prefix} ${outputArgs.join(' ')}`);
1893
+ logger_logger.warn(`${prefix} ${format(...outputArgs)}`);
1914
1894
  break;
1915
1895
  case 'debug':
1916
1896
  logger_logger.info(prefix, ...outputArgs);
@@ -1932,7 +1912,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
1932
1912
  apply: (config, { command })=>'dev' === command && !!config.dev?.prebundle,
1933
1913
  config: async (config, context)=>{
1934
1914
  var externals;
1935
- let existExternals, cacheDir, root = config.root;
1915
+ let existExternals, root = config.root;
1936
1916
  bundledDepsCachePath = node_path.resolve(root, context.cachePath, 'umd');
1937
1917
  let count = {
1938
1918
  total: 0,
@@ -2123,9 +2103,16 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2123
2103
  });
2124
2104
  });
2125
2105
  }))(depInfo)));
2126
- cacheDir = node_path.dirname(failedDepsJsonPath), node_fs.existsSync(cacheDir) || node_fs.mkdirSync(cacheDir, {
2127
- recursive: !0
2128
- }), node_fs.writeFileSync(failedDepsJsonPath, JSON.stringify(failedCache, null, 2), 'utf-8');
2106
+ ((cache)=>{
2107
+ if (0 === Object.keys(cache).length) {
2108
+ node_fs.existsSync(failedDepsJsonPath) && node_fs.unlinkSync(failedDepsJsonPath);
2109
+ return;
2110
+ }
2111
+ let cacheDir = node_path.dirname(failedDepsJsonPath);
2112
+ node_fs.existsSync(cacheDir) || node_fs.mkdirSync(cacheDir, {
2113
+ recursive: !0
2114
+ }), node_fs.writeFileSync(failedDepsJsonPath, JSON.stringify(cache, null, 2), 'utf-8');
2115
+ })(failedCache);
2129
2116
  let externals1 = {};
2130
2117
  bundledDeps.filter(Boolean).forEach((dep)=>{
2131
2118
  dep && (externals1[dep.name] = getExternalValue(dep.name), dep.assets.forEach((absPath)=>{
@@ -2154,10 +2141,15 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2154
2141
  ...existingExternals
2155
2142
  ], config;
2156
2143
  },
2157
- transform: (code, id)=>shouldTransformDeepImport && JSX_REGEX.test(id) && code.includes('import') && SPECIAL_NO_ENTRY_DEPS.some((pkg)=>code.includes(pkg)) ? code.replace(deepImportRegex, (_, localName, importPath, pkgName)=>{
2158
- let exportName = pathToExportIdentifier(importPath.slice(pkgName.length + 1));
2159
- return `import { ${exportName} as ${localName} } from '${pkgName}'`;
2160
- }) : null,
2144
+ transform: {
2145
+ filter: {
2146
+ test: JSX_REGEX
2147
+ },
2148
+ handler: (code)=>shouldTransformDeepImport && SPECIAL_NO_ENTRY_DEPS.some((pkg)=>code.includes(pkg)) ? code.replace(deepImportRegex, (_, localName, importPath, pkgName)=>{
2149
+ let exportName = pathToExportIdentifier(importPath.slice(pkgName.length + 1));
2150
+ return `import { ${exportName} as ${localName} } from '${pkgName}'`;
2151
+ }) : null
2152
+ },
2161
2153
  transformHtml: (html)=>injectToHead(html, preJsAssets.sort((a, b)=>a.order - b.order).map((item)=>item.path).map((item)=>`<script defer src="${item}"></script>`).join('')),
2162
2154
  setupMiddlewares: (middlewares)=>[
2163
2155
  (req, res, next)=>{
@@ -2273,7 +2265,7 @@ function createUnpack({ cwd = process.cwd(), config: userConfig, callerName = 'u
2273
2265
  let mode = watch ? 'development' : 'production';
2274
2266
  setNodeEnv(mode);
2275
2267
  let config = resolveConfig(mode);
2276
- console.log(colors.brand(`${callerName} v3.8.2${config.performance?.cache ? ' ϟ' : ''}`), colors.cyan(`building for ${mode}...`)), await unpackBuild(config);
2268
+ console.log(colors.brand(`${callerName} v3.9.0${config.performance?.cache ? ' ϟ' : ''}`), colors.cyan(`building for ${mode}...`)), await unpackBuild(config);
2277
2269
  },
2278
2270
  dev: async ()=>{
2279
2271
  setUnpackStartTime(performance.now());
@@ -2301,5 +2293,5 @@ async function createChokidar(pathOrGlobs, root = process.cwd(), options) {
2301
2293
  ...options
2302
2294
  });
2303
2295
  }
2304
- var src_CSS_NAMED_EXPORT = !1;
2305
- export { CSS_MODULES_LOCAL_IDENT_NAME, CSS_MODULES_REGEX, DEFAULT_DEV_HOST, DEV_DEFAULT_FILENAME, EXPORT_LOCALS_CONVENTION, JSX_REGEX, JS_REGEX, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, SCRIPT_REGEX, TEMPLATE_CONTENT, addRestartCleaner, cleanUpBeforeRestart, clearLine, colors, convertBasicAnsiColors, createChokidar, createUnpack, debounce, defineConfig, esVersionToBrowserslist, findExists, getAddressUrls, getCompiledPkgPath, getCurrentUnpackConfig, getHtmlTemplateOrContent, getIpv4Interfaces, getNodeEnv, getOrSetDefault, getPathInJs, getPort, getTime, getUnpackStartTime, getUserDepPath, getUserDepVersion, injectToHead, isBoolean, isCSSModules, isDebug, isDev, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isRegExp, isString, isUndefined, isWatch, isWin, launchEditor, loadConfig, logUpdate, logger_LogColor as LogColor, logger_logger as logger, mergeConfig, normalizePublicPath, openBrowser, pLimit, pathExists, pathToExportIdentifier, prettyTime, printServerUrls, removeDir, resolveConfigPath, rspack, set, setCurrentUnpackConfig, setDevServer, setNodeEnv, setUnpackStartTime, setupCliShortcuts, src_CSS_NAMED_EXPORT as CSS_NAMED_EXPORT, trackPerformance, utils_isDevServer as isDevServer, utils_isProd as isProd };
2296
+ var src_CSS_MODULES_NAMED_EXPORT = !1;
2297
+ export { ALL_INTERFACES_IPV4, CSS_MODULES_EXPORTS_CONVENTION, CSS_MODULES_LOCAL_IDENT_NAME, DEV_DEFAULT_FILENAME, JSX_REGEX, JS_REGEX, LOCALHOST, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, SCRIPT_REGEX, TEMPLATE_CONTENT, addRestartCleaner, cleanUpBeforeRestart, clearLine, colors, convertBasicAnsiColors, createChokidar, createUnpack, debounce, defineConfig, esVersionToBrowserslist, findExists, getAddressUrls, getCompiledPkgPath, getCurrentUnpackConfig, getHtmlTemplateOrContent, getIpv4Interfaces, getNodeEnv, getOrSetDefault, getPathInJs, getPort, getTime, getUnpackStartTime, getUserDepPath, getUserDepVersion, injectToHead, isBoolean, isDebug, isDev, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isRegExp, isString, isUndefined, isWatch, isWin, launchEditor, loadConfig, logUpdate, logger_LogColor as LogColor, logger_logger as logger, mergeConfig, normalizePublicPath, openBrowser, pLimit, pathExists, pathToExportIdentifier, prettyTime, printServerUrls, removeDir, resolveConfigPath, rspack, set, setCurrentUnpackConfig, setDevServer, setNodeEnv, setUnpackStartTime, setupCliShortcuts, src_CSS_MODULES_NAMED_EXPORT as CSS_MODULES_NAMED_EXPORT, trackPerformance, utils_isDevServer as isDevServer, utils_isProd as isProd };
@@ -1,4 +1,4 @@
1
- import 'module';
1
+ import "node:module";
2
2
  import.meta.url;
3
3
  var __webpack_modules__ = {}, __webpack_module_cache__ = {};
4
4
  function __webpack_require__(moduleId) {
@@ -1,11 +1,7 @@
1
1
  export default function(content) {
2
- let callback = this.async(), { plugins } = this.getOptions(), id = this.resourcePath;
2
+ let callback = this.async(), { handler } = this.getOptions(), id = this.resourcePath;
3
3
  (async ()=>{
4
- let code = content;
5
- for (let plugin of plugins){
6
- let result = await plugin.transform(code, id);
7
- 'string' == typeof result && (code = result);
8
- }
9
- return code;
4
+ let result = await handler(content, id);
5
+ return 'string' == typeof result ? result : content;
10
6
  })().then((code)=>callback(null, code)).catch((error)=>callback(error));
11
7
  };