@autter/runtime-cli 1.0.0 → 1.2.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.
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AutterSourceMapsOptions } from './build-BXFh_jbP.cjs';
1
+ import { A as AutterSourceMapsOptions } from './build-BqjqqeLg.cjs';
2
2
 
3
3
  type SourcemapSetting = boolean | "inline" | "hidden";
4
4
  /** The parts of Vite's / Rollup's types this plugin touches (structural, so
@@ -41,7 +41,8 @@ interface AutterSourceMapsPlugin {
41
41
  /**
42
42
  * Vite and Rollup plugin: turns on hidden source maps, gives every emitted
43
43
  * chunk a debug id after the bundle is written, and uploads the maps when
44
- * AUTTER_RUNTIME_KEY (or `key`) is set.
44
+ * AUTTER_RUNTIME_KEY (or `key`) is set. Maps it turned on are deleted after
45
+ * the upload step whatever its outcome; without a key it turns none on.
45
46
  *
46
47
  * ```ts
47
48
  * // vite.config.ts
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AutterSourceMapsOptions } from './build-BXFh_jbP.js';
1
+ import { A as AutterSourceMapsOptions } from './build-BqjqqeLg.js';
2
2
 
3
3
  type SourcemapSetting = boolean | "inline" | "hidden";
4
4
  /** The parts of Vite's / Rollup's types this plugin touches (structural, so
@@ -41,7 +41,8 @@ interface AutterSourceMapsPlugin {
41
41
  /**
42
42
  * Vite and Rollup plugin: turns on hidden source maps, gives every emitted
43
43
  * chunk a debug id after the bundle is written, and uploads the maps when
44
- * AUTTER_RUNTIME_KEY (or `key`) is set.
44
+ * AUTTER_RUNTIME_KEY (or `key`) is set. Maps it turned on are deleted after
45
+ * the upload step whatever its outcome; without a key it turns none on.
45
46
  *
46
47
  * ```ts
47
48
  * // vite.config.ts
package/dist/vite.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import {
2
- processBuildOutput
3
- } from "./chunk-SIRFO2QU.js";
2
+ logMapsNotGenerated,
3
+ processBuildOutput,
4
+ removeSourceMaps,
5
+ shouldGenerateMaps
6
+ } from "./chunk-KIQRQY3X.js";
4
7
 
5
8
  // src/vite.ts
6
9
  import { dirname, resolve } from "path";
@@ -16,7 +19,11 @@ function autterSourceMaps(options = {}) {
16
19
  config(config) {
17
20
  isVite = true;
18
21
  const current = config.build?.sourcemap;
19
- if (current === void 0 || current === false) {
22
+ if ((current === void 0 || current === false) && !config.build?.ssr) {
23
+ if (!shouldGenerateMaps(options)) {
24
+ logMapsNotGenerated(options);
25
+ return void 0;
26
+ }
20
27
  enabledMaps = true;
21
28
  return { build: { sourcemap: "hidden" } };
22
29
  }
@@ -31,21 +38,40 @@ function autterSourceMaps(options = {}) {
31
38
  },
32
39
  outputOptions(output) {
33
40
  if (isVite || output.sourcemap !== void 0 && output.sourcemap !== false) return null;
41
+ if (!shouldGenerateMaps(options)) {
42
+ logMapsNotGenerated(options);
43
+ return null;
44
+ }
34
45
  enabledMaps = true;
35
46
  return { ...output, sourcemap: "hidden" };
36
47
  },
37
48
  async writeBundle(output, bundle) {
38
- const environment = this?.environment;
39
- if (ssr || environment?.config?.consumer === "server") return;
40
49
  const dir = output.dir ?? (output.file ? dirname(output.file) : void 0);
41
50
  if (!dir) return;
51
+ const maps = Object.values(bundle).filter((file) => file.fileName.endsWith(".map")).map((file) => resolve(dir, file.fileName));
52
+ const environment = this?.environment;
53
+ if (ssr || environment?.config?.consumer === "server") {
54
+ if (enabledMaps && options.deleteAfterUpload !== false) {
55
+ try {
56
+ const removed = await removeSourceMaps(maps);
57
+ if (removed.length && !options.silent) {
58
+ console.log(`[autter-runtime] removed ${removed.length} source map(s) this plugin generated for a server bundle (not uploaded)`);
59
+ }
60
+ } catch (err) {
61
+ if (!options.silent) console.warn(`[autter-runtime] could not delete server source maps: ${err instanceof Error ? err.message : String(err)}`);
62
+ }
63
+ }
64
+ return;
65
+ }
42
66
  const files = Object.values(bundle).filter((file) => file.type === "chunk").map((file) => resolve(dir, file.fileName));
43
67
  await processBuildOutput({
44
68
  dir,
45
69
  files,
70
+ maps,
46
71
  urlPrefix: base,
47
72
  options,
48
- deleteAfterUpload: enabledMaps
73
+ deleteAfterUpload: enabledMaps,
74
+ ownMaps: enabledMaps
49
75
  });
50
76
  }
51
77
  };