@starko-one/sdk 0.0.0-stage → 0.1.0-beta.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 (108) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/LICENSE +17 -0
  3. package/NOTICE +58 -0
  4. package/README.md +81 -2
  5. package/dist/api-B5IHeINe.d.ts +558 -0
  6. package/dist/api-DR4HazCu.d.cts +558 -0
  7. package/dist/browser/index.cjs +168 -0
  8. package/dist/browser/index.d.cts +131 -0
  9. package/dist/browser/index.d.ts +131 -0
  10. package/dist/browser/index.js +7 -0
  11. package/dist/build/rollup.cjs +22 -0
  12. package/dist/build/rollup.d.cts +34 -0
  13. package/dist/build/rollup.d.ts +34 -0
  14. package/dist/build/rollup.js +3 -0
  15. package/dist/build/vite.cjs +51 -0
  16. package/dist/build/vite.d.cts +23 -0
  17. package/dist/build/vite.d.ts +23 -0
  18. package/dist/build/vite.js +46 -0
  19. package/dist/build/webpack.cjs +18 -0
  20. package/dist/build/webpack.d.cts +39 -0
  21. package/dist/build/webpack.d.ts +39 -0
  22. package/dist/build/webpack.js +3 -0
  23. package/dist/chunk-7HYGODU6.cjs +583 -0
  24. package/dist/chunk-A5M4NOVT.js +413 -0
  25. package/dist/chunk-A7MYYWMP.cjs +15 -0
  26. package/dist/chunk-BAQA47FM.js +1113 -0
  27. package/dist/chunk-CM7HM6CC.js +563 -0
  28. package/dist/chunk-DFYNIWUN.js +608 -0
  29. package/dist/chunk-DMVVCGKO.cjs +96 -0
  30. package/dist/chunk-FARGXYJ4.cjs +56 -0
  31. package/dist/chunk-G3MYIAX2.js +1226 -0
  32. package/dist/chunk-G4NAVZQ4.js +249 -0
  33. package/dist/chunk-GH7RYPKS.js +96 -0
  34. package/dist/chunk-HADYYQNL.cjs +134 -0
  35. package/dist/chunk-HOQPAB4X.js +178 -0
  36. package/dist/chunk-J5RU73SW.js +214 -0
  37. package/dist/chunk-JNAJ3YZB.cjs +223 -0
  38. package/dist/chunk-KN7H22EQ.cjs +659 -0
  39. package/dist/chunk-LDQ4I7FZ.cjs +1151 -0
  40. package/dist/chunk-NPGESRVQ.js +1212 -0
  41. package/dist/chunk-OPWM5V7A.cjs +258 -0
  42. package/dist/chunk-PYYWPIFL.cjs +1230 -0
  43. package/dist/chunk-R7JLZ4WO.cjs +115 -0
  44. package/dist/chunk-SC6VQSES.js +213 -0
  45. package/dist/chunk-TPSJGLR3.cjs +220 -0
  46. package/dist/chunk-UKBY6HPC.js +131 -0
  47. package/dist/chunk-VRSEHRBX.cjs +185 -0
  48. package/dist/chunk-X74AONZA.js +90 -0
  49. package/dist/chunk-XW3I5CJN.js +12 -0
  50. package/dist/chunk-XW56FKKJ.js +53 -0
  51. package/dist/chunk-Z3G5SW7R.cjs +1251 -0
  52. package/dist/chunk-ZVMAN7OO.cjs +431 -0
  53. package/dist/cli/index.cjs +1487 -0
  54. package/dist/common-ARWXbeS3.d.ts +36 -0
  55. package/dist/common-CwIFh2hK.d.cts +36 -0
  56. package/dist/dedupe-eHBIfUUD.d.cts +13 -0
  57. package/dist/dedupe-fw8aNtt4.d.ts +13 -0
  58. package/dist/handler-DTZ4Rzcf.d.ts +82 -0
  59. package/dist/handler-_00lctTI.d.cts +82 -0
  60. package/dist/index.cjs +277 -0
  61. package/dist/index.d.cts +187 -0
  62. package/dist/index.d.ts +187 -0
  63. package/dist/index.js +4 -0
  64. package/dist/next/client.cjs +113 -0
  65. package/dist/next/client.d.cts +26 -0
  66. package/dist/next/client.d.ts +26 -0
  67. package/dist/next/client.js +41 -0
  68. package/dist/next/config.cjs +275 -0
  69. package/dist/next/config.d.cts +193 -0
  70. package/dist/next/config.d.ts +193 -0
  71. package/dist/next/config.js +261 -0
  72. package/dist/next/index.cjs +148 -0
  73. package/dist/next/index.d.cts +32 -0
  74. package/dist/next/index.d.ts +32 -0
  75. package/dist/next/index.js +59 -0
  76. package/dist/node/index.cjs +257 -0
  77. package/dist/node/index.d.cts +145 -0
  78. package/dist/node/index.d.ts +145 -0
  79. package/dist/node/index.js +83 -0
  80. package/dist/options-0BhybO54.d.cts +47 -0
  81. package/dist/options-0BhybO54.d.ts +47 -0
  82. package/dist/react/index.cjs +107 -0
  83. package/dist/react/index.d.cts +84 -0
  84. package/dist/react/index.d.ts +84 -0
  85. package/dist/react/index.js +103 -0
  86. package/dist/scope-Bvh45bOf.d.cts +404 -0
  87. package/dist/scope-Bvh45bOf.d.ts +404 -0
  88. package/dist/server-edge-BPOGA3GH.cjs +51 -0
  89. package/dist/server-edge-GYKAJREU.js +48 -0
  90. package/dist/server-node-HYK2OB2J.js +24 -0
  91. package/dist/server-node-J2DBAHDV.cjs +27 -0
  92. package/dist/session-C_WzbEN2.d.cts +4 -0
  93. package/dist/session-C_WzbEN2.d.ts +4 -0
  94. package/dist/session-propagation-B7REA7uy.d.cts +30 -0
  95. package/dist/session-propagation-BnJjKJbR.d.ts +30 -0
  96. package/dist/starko.min.js +6 -0
  97. package/docs/browser.md +381 -0
  98. package/docs/configuration.md +269 -0
  99. package/docs/nextjs.md +312 -0
  100. package/docs/node.md +376 -0
  101. package/docs/other-backends.md +232 -0
  102. package/docs/privacy.md +112 -0
  103. package/docs/react.md +187 -0
  104. package/docs/source-maps.md +332 -0
  105. package/docs/troubleshooting.md +171 -0
  106. package/docs/widget.md +84 -0
  107. package/docs/wire-format.md +367 -0
  108. package/package.json +98 -4
@@ -0,0 +1,214 @@
1
+ import { resolveConnection, createLogger, createFileFilter, NO_API_KEY_MESSAGE, runUpload, errorMessage, shouldDeleteSourcemaps, findDebugId, hasStarkoRegistration, planInjection, resolveReleaseInfo, findSourceMappingUrl, stripSourceMappingUrl, stripCssSourceMappingUrl, injectDebugId, localMapReference } from './chunk-G3MYIAX2.js';
2
+ import path from 'path';
3
+ import MagicString from 'magic-string';
4
+
5
+ function isRolldown(context) {
6
+ return Boolean(context.meta?.rolldownVersion);
7
+ }
8
+ function assetText(asset) {
9
+ return typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString("utf8");
10
+ }
11
+ var SWITCHED_ON = /* @__PURE__ */ Symbol.for("starko.sdk.rollup.sourcemapSwitchedOn");
12
+ function markSwitchedOn(user) {
13
+ const transform = function(relativeSourcePath, sourcemapPath) {
14
+ return typeof user === "function" ? user.call(this, relativeSourcePath, sourcemapPath) : relativeSourcePath;
15
+ };
16
+ Object.defineProperty(transform, SWITCHED_ON, { value: true });
17
+ return transform;
18
+ }
19
+ function switchedOn(output) {
20
+ try {
21
+ const t = output.sourcemapPathTransform;
22
+ return typeof t === "function" && t[SWITCHED_ON] === true;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ function removeMapAssets(bundle) {
28
+ const removed = /* @__PURE__ */ new Set();
29
+ for (const [fileName, file] of Object.entries(bundle)) {
30
+ if (file.type === "asset" && fileName.endsWith(".map")) {
31
+ delete bundle[fileName];
32
+ removed.add(fileName);
33
+ }
34
+ }
35
+ if (removed.size === 0) return 0;
36
+ const pointsAtRemoved = (fileName, url) => {
37
+ const local = localMapReference(url);
38
+ if (local === void 0) return false;
39
+ return removed.has(path.posix.normalize(path.posix.join(path.posix.dirname(fileName), local)));
40
+ };
41
+ for (const file of Object.values(bundle)) {
42
+ if (file.type === "chunk") {
43
+ const ref = findSourceMappingUrl(file.code);
44
+ if (ref && pointsAtRemoved(file.fileName, ref.url)) file.code = stripSourceMappingUrl(file.code, ref);
45
+ } else if (file.fileName.endsWith(".css")) {
46
+ const css = assetText(file);
47
+ const stripped = stripCssSourceMappingUrl(css, (url) => pointsAtRemoved(file.fileName, url));
48
+ if (stripped !== css) file.source = stripped;
49
+ }
50
+ }
51
+ return removed.size;
52
+ }
53
+ function createStarkoRollupPlugin(options = {}, internals = {}) {
54
+ const connection = resolveConnection(options);
55
+ const logger = createLogger({ silent: options.silent, secrets: [connection.apiKey] });
56
+ const filter = createFileFilter(options);
57
+ let enabled = false;
58
+ let release;
59
+ let releaseResolved = false;
60
+ let warnedNoKey = false;
61
+ const resolveEnabled = (context) => {
62
+ const wanted = internals.isEnabled ? internals.isEnabled(context) : options.enabled ?? (!context.meta.watchMode && process.env.NODE_ENV !== "development");
63
+ if (wanted && !connection.apiKey) {
64
+ if (!warnedNoKey) logger.warn(NO_API_KEY_MESSAGE);
65
+ warnedNoKey = true;
66
+ return false;
67
+ }
68
+ return wanted;
69
+ };
70
+ const ownerOf = (output) => internals.sourcemapOwner ? internals.sourcemapOwner() : switchedOn(output) ? "starko" : "user";
71
+ const getRelease = () => {
72
+ if (!releaseResolved) {
73
+ release = resolveReleaseInfo(options.release);
74
+ releaseResolved = true;
75
+ }
76
+ return release;
77
+ };
78
+ const prepareChunks = (bundle, rolldown) => {
79
+ const entries = [];
80
+ for (const chunk of Object.values(bundle)) {
81
+ if (chunk.type !== "chunk" || !filter(chunk.fileName)) continue;
82
+ try {
83
+ const entry = prepareChunk(bundle, chunk, rolldown);
84
+ if (entry) entries.push(entry);
85
+ } catch (error) {
86
+ logger.warn(`could not process ${chunk.fileName}: ${errorMessage(error)}`);
87
+ }
88
+ }
89
+ return entries;
90
+ };
91
+ const prepareChunk = (bundle, chunk, rolldown) => {
92
+ const mapFileName = chunk.sourcemapFileName ?? `${chunk.fileName}.map`;
93
+ const mapAsset = bundle[mapFileName];
94
+ if (!mapAsset || mapAsset.type !== "asset") return void 0;
95
+ let map;
96
+ try {
97
+ map = JSON.parse(assetText(mapAsset));
98
+ } catch {
99
+ logger.warn(`could not read ${mapFileName}; ${chunk.fileName} is not processed`);
100
+ return void 0;
101
+ }
102
+ let chunkId = findDebugId(chunk.code);
103
+ if (rolldown && (!chunkId || !hasStarkoRegistration(chunk.code, chunkId))) {
104
+ const out = injectDebugId(chunk.code, map, { release: getRelease()?.version });
105
+ chunk.code = out.code;
106
+ map = out.map;
107
+ chunkId = out.debugId;
108
+ if (chunk.map) Object.assign(chunk.map, { mappings: map.mappings });
109
+ }
110
+ if (!chunkId) return void 0;
111
+ if (map.debugId !== chunkId) map = { ...map, debugId: chunkId };
112
+ const text = JSON.stringify(map);
113
+ mapAsset.source = text;
114
+ if (chunk.map) chunk.map.debugId = chunkId;
115
+ return { chunkId, map: text, fileName: chunk.fileName };
116
+ };
117
+ return {
118
+ name: internals.name ?? "starko-rollup-plugin",
119
+ buildStart() {
120
+ enabled = resolveEnabled(this);
121
+ releaseResolved = false;
122
+ },
123
+ outputOptions: {
124
+ order: "post",
125
+ handler(output) {
126
+ enabled = resolveEnabled(this);
127
+ if (!enabled) return null;
128
+ const next = { ...output };
129
+ if (!next.sourcemap) {
130
+ next.sourcemap = "hidden";
131
+ next.sourcemapPathTransform = markSwitchedOn(next.sourcemapPathTransform);
132
+ }
133
+ if (next.sourcemap === "inline") {
134
+ logger.warn("inline source maps are not uploaded; use `sourcemap: true` or `'hidden'`");
135
+ }
136
+ if (next.sourcemapDebugIds) {
137
+ next.sourcemapDebugIds = false;
138
+ logger.info("output.sourcemapDebugIds is turned off: the Starko plugin writes the debug ids");
139
+ }
140
+ return next;
141
+ }
142
+ },
143
+ // Rollup: inject after every other renderChunk hook (minifiers included),
144
+ // before file hashes and generateBundle, so the written files are final.
145
+ // Rollup composes the returned map with the chunk's map.
146
+ renderChunk: {
147
+ order: "post",
148
+ handler(code, chunk, output) {
149
+ if (!enabled || isRolldown(this) || !output.sourcemap || output.sourcemap === "inline") return null;
150
+ if (!filter(chunk.fileName)) return null;
151
+ try {
152
+ const existing = findDebugId(code);
153
+ if (existing && hasStarkoRegistration(code, existing)) return null;
154
+ const plan = planInjection(code, { release: getRelease()?.version, debugId: existing });
155
+ const s = new MagicString(code);
156
+ s.appendLeft(plan.snippet.offset, plan.snippet.text);
157
+ if (!existing) s.appendLeft(plan.comment.offset, plan.comment.text);
158
+ return { code: s.toString(), map: s.generateMap({ hires: "boundary" }) };
159
+ } catch (error) {
160
+ logger.warn(`could not inject ${chunk.fileName}: ${errorMessage(error)}`);
161
+ return null;
162
+ }
163
+ }
164
+ },
165
+ // Last generateBundle hook: every map gets its `debugId`, the maps are
166
+ // uploaded from memory, and then, whatever happened, the maps that must
167
+ // not ship are removed from the bundle so they are never written.
168
+ generateBundle: {
169
+ order: "post",
170
+ async handler(output, bundle) {
171
+ if (!enabled || !output.sourcemap || output.sourcemap === "inline") return;
172
+ const owner = ownerOf(output);
173
+ let failure;
174
+ try {
175
+ const entries = prepareChunks(bundle, isRolldown(this));
176
+ if (entries.length > 0) {
177
+ const outcome = await runUpload(entries, {
178
+ apiKey: connection.apiKey,
179
+ host: connection.host,
180
+ release: getRelease(),
181
+ dryRun: options.dryRun,
182
+ uploadTimeoutMs: options.uploadTimeoutMs,
183
+ logger
184
+ });
185
+ if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
186
+ }
187
+ } catch (error) {
188
+ failure = errorMessage(error);
189
+ logger.error(`source maps: ${failure}`);
190
+ } finally {
191
+ if (shouldDeleteSourcemaps(owner, options)) {
192
+ try {
193
+ const removed = removeMapAssets(bundle);
194
+ if (removed > 0) {
195
+ logger.info(
196
+ owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
197
+ );
198
+ }
199
+ } catch (error) {
200
+ logger.error(`could not remove the source maps from the output: ${errorMessage(error)}`);
201
+ }
202
+ }
203
+ }
204
+ if (failure && options.failOnError) this.error(`[starko] ${failure}`);
205
+ }
206
+ }
207
+ };
208
+ }
209
+ function starkoRollupPlugin(options = {}) {
210
+ return createStarkoRollupPlugin(options);
211
+ }
212
+ var rollup_default = starkoRollupPlugin;
213
+
214
+ export { createStarkoRollupPlugin, rollup_default, starkoRollupPlugin };
@@ -0,0 +1,223 @@
1
+ 'use strict';
2
+
3
+ var chunkZ3G5SW7R_cjs = require('./chunk-Z3G5SW7R.cjs');
4
+ var path = require('path');
5
+ var MagicString = require('magic-string');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var path__default = /*#__PURE__*/_interopDefault(path);
10
+ var MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
11
+
12
+ function isRolldown(context) {
13
+ return Boolean(context.meta?.rolldownVersion);
14
+ }
15
+ function assetText(asset) {
16
+ return typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString("utf8");
17
+ }
18
+ var SWITCHED_ON = /* @__PURE__ */ Symbol.for("starko.sdk.rollup.sourcemapSwitchedOn");
19
+ function markSwitchedOn(user) {
20
+ const transform = function(relativeSourcePath, sourcemapPath) {
21
+ return typeof user === "function" ? user.call(this, relativeSourcePath, sourcemapPath) : relativeSourcePath;
22
+ };
23
+ Object.defineProperty(transform, SWITCHED_ON, { value: true });
24
+ return transform;
25
+ }
26
+ function switchedOn(output) {
27
+ try {
28
+ const t = output.sourcemapPathTransform;
29
+ return typeof t === "function" && t[SWITCHED_ON] === true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+ function removeMapAssets(bundle) {
35
+ const removed = /* @__PURE__ */ new Set();
36
+ for (const [fileName, file] of Object.entries(bundle)) {
37
+ if (file.type === "asset" && fileName.endsWith(".map")) {
38
+ delete bundle[fileName];
39
+ removed.add(fileName);
40
+ }
41
+ }
42
+ if (removed.size === 0) return 0;
43
+ const pointsAtRemoved = (fileName, url) => {
44
+ const local = chunkZ3G5SW7R_cjs.localMapReference(url);
45
+ if (local === void 0) return false;
46
+ return removed.has(path__default.default.posix.normalize(path__default.default.posix.join(path__default.default.posix.dirname(fileName), local)));
47
+ };
48
+ for (const file of Object.values(bundle)) {
49
+ if (file.type === "chunk") {
50
+ const ref = chunkZ3G5SW7R_cjs.findSourceMappingUrl(file.code);
51
+ if (ref && pointsAtRemoved(file.fileName, ref.url)) file.code = chunkZ3G5SW7R_cjs.stripSourceMappingUrl(file.code, ref);
52
+ } else if (file.fileName.endsWith(".css")) {
53
+ const css = assetText(file);
54
+ const stripped = chunkZ3G5SW7R_cjs.stripCssSourceMappingUrl(css, (url) => pointsAtRemoved(file.fileName, url));
55
+ if (stripped !== css) file.source = stripped;
56
+ }
57
+ }
58
+ return removed.size;
59
+ }
60
+ function createStarkoRollupPlugin(options = {}, internals = {}) {
61
+ const connection = chunkZ3G5SW7R_cjs.resolveConnection(options);
62
+ const logger = chunkZ3G5SW7R_cjs.createLogger({ silent: options.silent, secrets: [connection.apiKey] });
63
+ const filter = chunkZ3G5SW7R_cjs.createFileFilter(options);
64
+ let enabled = false;
65
+ let release;
66
+ let releaseResolved = false;
67
+ let warnedNoKey = false;
68
+ const resolveEnabled = (context) => {
69
+ const wanted = internals.isEnabled ? internals.isEnabled(context) : options.enabled ?? (!context.meta.watchMode && process.env.NODE_ENV !== "development");
70
+ if (wanted && !connection.apiKey) {
71
+ if (!warnedNoKey) logger.warn(chunkZ3G5SW7R_cjs.NO_API_KEY_MESSAGE);
72
+ warnedNoKey = true;
73
+ return false;
74
+ }
75
+ return wanted;
76
+ };
77
+ const ownerOf = (output) => internals.sourcemapOwner ? internals.sourcemapOwner() : switchedOn(output) ? "starko" : "user";
78
+ const getRelease = () => {
79
+ if (!releaseResolved) {
80
+ release = chunkZ3G5SW7R_cjs.resolveReleaseInfo(options.release);
81
+ releaseResolved = true;
82
+ }
83
+ return release;
84
+ };
85
+ const prepareChunks = (bundle, rolldown) => {
86
+ const entries = [];
87
+ for (const chunk of Object.values(bundle)) {
88
+ if (chunk.type !== "chunk" || !filter(chunk.fileName)) continue;
89
+ try {
90
+ const entry = prepareChunk(bundle, chunk, rolldown);
91
+ if (entry) entries.push(entry);
92
+ } catch (error) {
93
+ logger.warn(`could not process ${chunk.fileName}: ${chunkZ3G5SW7R_cjs.errorMessage(error)}`);
94
+ }
95
+ }
96
+ return entries;
97
+ };
98
+ const prepareChunk = (bundle, chunk, rolldown) => {
99
+ const mapFileName = chunk.sourcemapFileName ?? `${chunk.fileName}.map`;
100
+ const mapAsset = bundle[mapFileName];
101
+ if (!mapAsset || mapAsset.type !== "asset") return void 0;
102
+ let map;
103
+ try {
104
+ map = JSON.parse(assetText(mapAsset));
105
+ } catch {
106
+ logger.warn(`could not read ${mapFileName}; ${chunk.fileName} is not processed`);
107
+ return void 0;
108
+ }
109
+ let chunkId = chunkZ3G5SW7R_cjs.findDebugId(chunk.code);
110
+ if (rolldown && (!chunkId || !chunkZ3G5SW7R_cjs.hasStarkoRegistration(chunk.code, chunkId))) {
111
+ const out = chunkZ3G5SW7R_cjs.injectDebugId(chunk.code, map, { release: getRelease()?.version });
112
+ chunk.code = out.code;
113
+ map = out.map;
114
+ chunkId = out.debugId;
115
+ if (chunk.map) Object.assign(chunk.map, { mappings: map.mappings });
116
+ }
117
+ if (!chunkId) return void 0;
118
+ if (map.debugId !== chunkId) map = { ...map, debugId: chunkId };
119
+ const text = JSON.stringify(map);
120
+ mapAsset.source = text;
121
+ if (chunk.map) chunk.map.debugId = chunkId;
122
+ return { chunkId, map: text, fileName: chunk.fileName };
123
+ };
124
+ return {
125
+ name: internals.name ?? "starko-rollup-plugin",
126
+ buildStart() {
127
+ enabled = resolveEnabled(this);
128
+ releaseResolved = false;
129
+ },
130
+ outputOptions: {
131
+ order: "post",
132
+ handler(output) {
133
+ enabled = resolveEnabled(this);
134
+ if (!enabled) return null;
135
+ const next = { ...output };
136
+ if (!next.sourcemap) {
137
+ next.sourcemap = "hidden";
138
+ next.sourcemapPathTransform = markSwitchedOn(next.sourcemapPathTransform);
139
+ }
140
+ if (next.sourcemap === "inline") {
141
+ logger.warn("inline source maps are not uploaded; use `sourcemap: true` or `'hidden'`");
142
+ }
143
+ if (next.sourcemapDebugIds) {
144
+ next.sourcemapDebugIds = false;
145
+ logger.info("output.sourcemapDebugIds is turned off: the Starko plugin writes the debug ids");
146
+ }
147
+ return next;
148
+ }
149
+ },
150
+ // Rollup: inject after every other renderChunk hook (minifiers included),
151
+ // before file hashes and generateBundle, so the written files are final.
152
+ // Rollup composes the returned map with the chunk's map.
153
+ renderChunk: {
154
+ order: "post",
155
+ handler(code, chunk, output) {
156
+ if (!enabled || isRolldown(this) || !output.sourcemap || output.sourcemap === "inline") return null;
157
+ if (!filter(chunk.fileName)) return null;
158
+ try {
159
+ const existing = chunkZ3G5SW7R_cjs.findDebugId(code);
160
+ if (existing && chunkZ3G5SW7R_cjs.hasStarkoRegistration(code, existing)) return null;
161
+ const plan = chunkZ3G5SW7R_cjs.planInjection(code, { release: getRelease()?.version, debugId: existing });
162
+ const s = new MagicString__default.default(code);
163
+ s.appendLeft(plan.snippet.offset, plan.snippet.text);
164
+ if (!existing) s.appendLeft(plan.comment.offset, plan.comment.text);
165
+ return { code: s.toString(), map: s.generateMap({ hires: "boundary" }) };
166
+ } catch (error) {
167
+ logger.warn(`could not inject ${chunk.fileName}: ${chunkZ3G5SW7R_cjs.errorMessage(error)}`);
168
+ return null;
169
+ }
170
+ }
171
+ },
172
+ // Last generateBundle hook: every map gets its `debugId`, the maps are
173
+ // uploaded from memory, and then, whatever happened, the maps that must
174
+ // not ship are removed from the bundle so they are never written.
175
+ generateBundle: {
176
+ order: "post",
177
+ async handler(output, bundle) {
178
+ if (!enabled || !output.sourcemap || output.sourcemap === "inline") return;
179
+ const owner = ownerOf(output);
180
+ let failure;
181
+ try {
182
+ const entries = prepareChunks(bundle, isRolldown(this));
183
+ if (entries.length > 0) {
184
+ const outcome = await chunkZ3G5SW7R_cjs.runUpload(entries, {
185
+ apiKey: connection.apiKey,
186
+ host: connection.host,
187
+ release: getRelease(),
188
+ dryRun: options.dryRun,
189
+ uploadTimeoutMs: options.uploadTimeoutMs,
190
+ logger
191
+ });
192
+ if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
193
+ }
194
+ } catch (error) {
195
+ failure = chunkZ3G5SW7R_cjs.errorMessage(error);
196
+ logger.error(`source maps: ${failure}`);
197
+ } finally {
198
+ if (chunkZ3G5SW7R_cjs.shouldDeleteSourcemaps(owner, options)) {
199
+ try {
200
+ const removed = removeMapAssets(bundle);
201
+ if (removed > 0) {
202
+ logger.info(
203
+ owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
204
+ );
205
+ }
206
+ } catch (error) {
207
+ logger.error(`could not remove the source maps from the output: ${chunkZ3G5SW7R_cjs.errorMessage(error)}`);
208
+ }
209
+ }
210
+ }
211
+ if (failure && options.failOnError) this.error(`[starko] ${failure}`);
212
+ }
213
+ }
214
+ };
215
+ }
216
+ function starkoRollupPlugin(options = {}) {
217
+ return createStarkoRollupPlugin(options);
218
+ }
219
+ var rollup_default = starkoRollupPlugin;
220
+
221
+ exports.createStarkoRollupPlugin = createStarkoRollupPlugin;
222
+ exports.rollup_default = rollup_default;
223
+ exports.starkoRollupPlugin = starkoRollupPlugin;