@autter/runtime-cli 1.1.0 → 1.3.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.
@@ -2,12 +2,18 @@ import {
2
2
  BUNDLE_RE,
3
3
  logMapsNotGenerated,
4
4
  processBuildOutput,
5
+ serverUrlPrefix,
5
6
  shouldGenerateMaps
6
- } from "./chunk-DQLLM2NT.js";
7
+ } from "./chunk-Q23FB5X3.js";
7
8
 
8
9
  // src/webpack.ts
9
10
  import { resolve } from "path";
10
11
  var PLUGIN_NAME = "AutterSourceMapsWebpackPlugin";
12
+ var SERVER_TARGET_RE = /^(?:async-)?node|^electron-(?:main|preload)/;
13
+ function isServerTarget(target) {
14
+ const targets = Array.isArray(target) ? target : [target];
15
+ return targets.some((value) => typeof value === "string" && SERVER_TARGET_RE.test(value));
16
+ }
11
17
  var AutterSourceMapsWebpackPlugin = class {
12
18
  constructor(options = {}, internal = {}) {
13
19
  this.options = options;
@@ -18,6 +24,8 @@ var AutterSourceMapsWebpackPlugin = class {
18
24
  apply(compiler) {
19
25
  const mode = compiler.options.mode ?? (process.env.NODE_ENV === "development" ? "development" : void 0);
20
26
  if (mode === "development") return;
27
+ const server = this.internal.server ?? isServerTarget(compiler.options.target);
28
+ if (server && this.options.serverBundles === false) return;
21
29
  let enabledMaps = this.internal.ownMaps ?? false;
22
30
  if (!compiler.options.devtool) {
23
31
  if (shouldGenerateMaps(this.options)) {
@@ -31,7 +39,7 @@ var AutterSourceMapsWebpackPlugin = class {
31
39
  const dir = compilation.outputOptions.path ?? compiler.outputPath;
32
40
  if (!dir) return;
33
41
  const publicPath = compilation.outputOptions.publicPath;
34
- const urlPrefix = typeof publicPath === "string" && publicPath !== "auto" && publicPath !== "" ? publicPath : "/";
42
+ const urlPrefix = server ? serverUrlPrefix(compiler.context ?? process.cwd(), dir) : typeof publicPath === "string" && publicPath !== "auto" && publicPath !== "" ? publicPath : "/";
35
43
  const assets = compilation.getAssets().map((asset) => asset.name);
36
44
  const files = assets.filter((name) => BUNDLE_RE.test(name)).map((name) => resolve(dir, name));
37
45
  const maps = assets.filter((name) => name.endsWith(".map")).map((name) => resolve(dir, name));
@@ -42,7 +50,8 @@ var AutterSourceMapsWebpackPlugin = class {
42
50
  urlPrefix,
43
51
  options: this.options,
44
52
  deleteAfterUpload: enabledMaps,
45
- ownMaps: enabledMaps
53
+ ownMaps: enabledMaps,
54
+ ...server ? { server: true } : {}
46
55
  });
47
56
  });
48
57
  }
@@ -53,6 +62,7 @@ function autterSourceMapsWebpack(options = {}) {
53
62
  var webpack_default = AutterSourceMapsWebpackPlugin;
54
63
 
55
64
  export {
65
+ isServerTarget,
56
66
  AutterSourceMapsWebpackPlugin,
57
67
  autterSourceMapsWebpack,
58
68
  webpack_default