@base44-preview/vite-plugin 1.0.52-pr.150.911b6c2 → 1.0.52-pr.150.bd79020

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/README.md CHANGED
@@ -155,7 +155,9 @@ app's own files:
155
155
  bundle file carries a `sourceMappingURL` comment, so browsers never fetch them.
156
156
  - **No source text.** `sourcemapExcludeSources` is set on every output (under
157
157
  `build.rollupOptions.output` before Vite 8, `build.rolldownOptions.output` on
158
- Vite 8), so a map holds file names and positions only.
158
+ Vite 8), so a map holds file names and positions only. Vite bundles web
159
+ workers separately, so any emitted `.map` that still has `sourcesContent`
160
+ (a worker's) has it removed after bundling. Vite emits no CSS maps in builds.
159
161
  - **The app's choice wins.** If `build.sourcemap` is already set, by the app's
160
162
  config or by another plugin, to any value including `false`, source maps are
161
163
  left exactly as configured.
@@ -12,12 +12,17 @@ import type { BuildEnvironmentOptions, Plugin } from "vite";
12
12
  * environment changes, so an SSR or Worker build keeps its own config.
13
13
  * - The app's choice wins: a `build.sourcemap` already set, `false` included,
14
14
  * leaves source maps exactly as configured.
15
+ *
16
+ * `sourcemapExcludeSources` covers the bundle's own chunks. Vite bundles web
17
+ * workers separately with only some of those output options, so after bundling
18
+ * any `.map` that still holds source text has it removed.
15
19
  */
16
- type RollupOutput = Record<string, unknown>;
20
+ type BundlerOutputOptions = Record<string, unknown>;
21
+ type BundlerOptions = {
22
+ output?: BundlerOutputOptions | BundlerOutputOptions[] | undefined;
23
+ } & Record<string, unknown>;
17
24
  type BuildOptions = BuildEnvironmentOptions & {
18
- rolldownOptions?: {
19
- output?: RollupOutput | RollupOutput[];
20
- } & Record<string, unknown>;
25
+ rolldownOptions?: BundlerOptions;
21
26
  };
22
27
  export interface HiddenSourceMapsOptions {
23
28
  /** Whether bundler options live under `rolldownOptions`. Defaults to the installed Vite's. */
@@ -34,6 +39,8 @@ export interface HiddenSourceMapsOptions {
34
39
  export declare function withHiddenSourceMaps(build: BuildOptions | undefined, { rolldown }: {
35
40
  rolldown: boolean;
36
41
  }): BuildOptions | null;
42
+ /** A source map's JSON without its source text, or `null` if it has none or is not a map. */
43
+ export declare function withoutSourcesContent(map: string): string | null;
37
44
  export declare function hiddenSourceMapsPlugin({ rolldown, environments, }?: HiddenSourceMapsOptions): Plugin;
38
45
  export {};
39
46
  //# sourceMappingURL=hidden-source-maps-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hidden-source-maps-plugin.d.ts","sourceRoot":"","sources":["../src/hidden-source-maps-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG5D;;;;;;;;;;;;;GAaG;AAEH,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,KAAK,YAAY,GAAG,uBAAuB,GAAG;IAE5C,eAAe,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxF,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAOD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAClC,YAAY,GAAG,IAAI,CAmBrB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,QAAyB,EACzB,YAA6B,GAC9B,GAAE,uBAA4B,GAAG,MAAM,CAgCvC"}
1
+ {"version":3,"file":"hidden-source-maps-plugin.d.ts","sourceRoot":"","sources":["../src/hidden-source-maps-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG5D;;;;;;;;;;;;;;;;;GAiBG;AAEH,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpD,KAAK,cAAc,GAAG;IAAE,MAAM,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,GAAG,SAAS,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACvH,KAAK,YAAY,GAAG,uBAAuB,GAAG;IAE5C,eAAe,CAAC,EAAE,cAAc,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAOD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,GAAG,SAAS,EAC/B,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAClC,YAAY,GAAG,IAAI,CAmCrB;AAED,6FAA6F;AAC7F,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAShE;AAED,wBAAgB,sBAAsB,CAAC,EACrC,QAAyB,EACzB,YAA6B,GAC9B,GAAE,uBAA4B,GAAG,MAAM,CAyDvC"}
@@ -12,23 +12,52 @@ const excludeSources = (output) => ({
12
12
  export function withHiddenSourceMaps(build, { rolldown }) {
13
13
  if (build?.sourcemap !== undefined)
14
14
  return null;
15
- // Vite 8 aliases `rollupOptions` to `rolldownOptions` with a getter. Read
16
- // either, write only the one this Vite reads, and drop the other so the two
17
- // never disagree.
18
- const { rollupOptions, rolldownOptions, ...rest } = (build ?? {});
19
- const bundlerOptions = (rolldown ? rolldownOptions ?? rollupOptions : rollupOptions) ?? {};
20
- const { output } = bundlerOptions;
21
- return {
22
- ...rest,
15
+ const key = rolldown ? "rolldownOptions" : "rollupOptions";
16
+ // Vite 8 reads `rolldownOptions`, and aliases `rollupOptions` to it.
17
+ const current = ((rolldown ? build?.rolldownOptions ?? build?.rollupOptions : build?.rollupOptions) ?? {});
18
+ const { output } = current;
19
+ const next = {
20
+ ...build,
23
21
  sourcemap: "hidden",
24
- [rolldown ? "rolldownOptions" : "rollupOptions"]: {
25
- ...bundlerOptions,
22
+ [key]: {
23
+ ...current,
26
24
  // An app may build several outputs; each one leaves its sources out.
27
25
  output: Array.isArray(output) ? output.map(excludeSources) : excludeSources(output),
28
26
  },
29
27
  };
28
+ if (rolldown) {
29
+ // Spreading copied the alias as a plain, stale value. Put back the alias
30
+ // Vite 8 itself sets up, so later readers of `rollupOptions` see the same
31
+ // object Vite reads.
32
+ delete next.rollupOptions;
33
+ Object.defineProperty(next, "rollupOptions", {
34
+ get: () => next.rolldownOptions,
35
+ set: (value) => {
36
+ next.rolldownOptions = value;
37
+ },
38
+ configurable: true,
39
+ enumerable: true,
40
+ });
41
+ }
42
+ return next;
43
+ }
44
+ /** A source map's JSON without its source text, or `null` if it has none or is not a map. */
45
+ export function withoutSourcesContent(map) {
46
+ try {
47
+ const parsed = JSON.parse(map);
48
+ if (!parsed || typeof parsed !== "object" || !("sourcesContent" in parsed))
49
+ return null;
50
+ delete parsed.sourcesContent;
51
+ return JSON.stringify(parsed);
52
+ }
53
+ catch {
54
+ return null;
55
+ }
30
56
  }
31
57
  export function hiddenSourceMapsPlugin({ rolldown = isVite8OrLater, environments = isVite6OrLater, } = {}) {
58
+ // The builds this plugin gave hidden maps: environment names on Vite 6+, or
59
+ // the one browser build (`true`) on Vite 5.
60
+ const changed = new Set();
32
61
  return {
33
62
  name: "base44-hidden-source-maps",
34
63
  apply: "build",
@@ -37,6 +66,7 @@ export function hiddenSourceMapsPlugin({ rolldown = isVite8OrLater, environments
37
66
  config: {
38
67
  order: "post",
39
68
  handler(config, env) {
69
+ changed.clear();
40
70
  // Vite 6+ is handled per environment below: the top-level build
41
71
  // options feed the SSR environment too.
42
72
  if (environments)
@@ -45,8 +75,10 @@ export function hiddenSourceMapsPlugin({ rolldown = isVite8OrLater, environments
45
75
  if (config.build?.ssr || env.isSsrBuild)
46
76
  return;
47
77
  const build = withHiddenSourceMaps(config.build, { rolldown });
48
- if (build)
78
+ if (build) {
49
79
  config.build = build;
80
+ changed.add(true);
81
+ }
50
82
  },
51
83
  },
52
84
  configEnvironment: {
@@ -61,8 +93,25 @@ export function hiddenSourceMapsPlugin({ rolldown = isVite8OrLater, environments
61
93
  // Assigned rather than returned: Vite merges a returned config into the
62
94
  // existing one, which would append to an `output` array instead of
63
95
  // updating each entry.
64
- if (build)
96
+ if (build) {
65
97
  config.build = build;
98
+ changed.add(name);
99
+ }
100
+ },
101
+ },
102
+ generateBundle: {
103
+ order: "post",
104
+ handler(_options, bundle) {
105
+ const name = this.environment?.name;
106
+ if (!changed.has(environments ? name ?? "client" : true))
107
+ return;
108
+ for (const file of Object.values(bundle)) {
109
+ if (file.type !== "asset" || !file.fileName.endsWith(".map"))
110
+ continue;
111
+ const stripped = withoutSourcesContent(typeof file.source === "string" ? file.source : new TextDecoder().decode(file.source));
112
+ if (stripped !== null)
113
+ file.source = stripped;
114
+ }
66
115
  },
67
116
  },
68
117
  };
@@ -1 +1 @@
1
- {"version":3,"file":"hidden-source-maps-plugin.js","sourceRoot":"","sources":["../src/hidden-source-maps-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA8B5D,MAAM,cAAc,GAAG,CAAC,MAAgC,EAAgB,EAAE,CAAC,CAAC;IAC1E,GAAG,MAAM;IACT,uBAAuB,EAAE,IAAI;CAC9B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAA+B,EAC/B,EAAE,QAAQ,EAAyB;IAEnC,IAAI,KAAK,EAAE,SAAS,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;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xE,mEAAmE;gBACnE,uBAAuB;gBACvB,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;oBACrB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;SACF;QACD,cAAc,EAAE;YACd,KAAK,EAAE,MAAM;YACb,OAAO,CAAC,QAAQ,EAAE,MAAM;gBACtB,MAAM,IAAI,GAAI,IAA4C,CAAC,WAAW,EAAE,IAAI,CAAC;gBAC7E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;oBAAE,OAAO;gBACjE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;oBACzC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;wBAAE,SAAS;oBACvE,MAAM,QAAQ,GAAG,qBAAqB,CACpC,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CACtF,CAAC;oBACF,IAAI,QAAQ,KAAK,IAAI;wBAAE,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;gBAChD,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/vite-plugin",
3
- "version": "1.0.52-pr.150.911b6c2",
3
+ "version": "1.0.52-pr.150.bd79020",
4
4
  "description": "The Vite plugin for base44 based applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,12 +14,17 @@ import { isVite6OrLater, isVite8OrLater } from "./utils.js";
14
14
  * environment changes, so an SSR or Worker build keeps its own config.
15
15
  * - The app's choice wins: a `build.sourcemap` already set, `false` included,
16
16
  * leaves source maps exactly as configured.
17
+ *
18
+ * `sourcemapExcludeSources` covers the bundle's own chunks. Vite bundles web
19
+ * workers separately with only some of those output options, so after bundling
20
+ * any `.map` that still holds source text has it removed.
17
21
  */
18
22
 
19
- type RollupOutput = Record<string, unknown>;
23
+ type BundlerOutputOptions = Record<string, unknown>;
24
+ type BundlerOptions = { output?: BundlerOutputOptions | BundlerOutputOptions[] | undefined } & Record<string, unknown>;
20
25
  type BuildOptions = BuildEnvironmentOptions & {
21
26
  // Vite 8's spelling. Vite 7's types do not know it.
22
- rolldownOptions?: { output?: RollupOutput | RollupOutput[] } & Record<string, unknown>;
27
+ rolldownOptions?: BundlerOptions;
23
28
  };
24
29
 
25
30
  export interface HiddenSourceMapsOptions {
@@ -29,7 +34,7 @@ export interface HiddenSourceMapsOptions {
29
34
  environments?: boolean;
30
35
  }
31
36
 
32
- const excludeSources = (output: RollupOutput | undefined): RollupOutput => ({
37
+ const excludeSources = (output: BundlerOutputOptions | undefined): BundlerOutputOptions => ({
33
38
  ...output,
34
39
  sourcemapExcludeSources: true,
35
40
  });
@@ -46,28 +51,60 @@ export function withHiddenSourceMaps(
46
51
  ): BuildOptions | null {
47
52
  if (build?.sourcemap !== undefined) return null;
48
53
 
49
- // Vite 8 aliases `rollupOptions` to `rolldownOptions` with a getter. Read
50
- // either, write only the one this Vite reads, and drop the other so the two
51
- // never disagree.
52
- const { rollupOptions, rolldownOptions, ...rest } = (build ?? {}) as BuildOptions;
53
- const bundlerOptions = (rolldown ? rolldownOptions ?? rollupOptions : rollupOptions) ?? {};
54
- const { output } = bundlerOptions as { output?: RollupOutput | RollupOutput[] };
54
+ const key = rolldown ? "rolldownOptions" : "rollupOptions";
55
+ // Vite 8 reads `rolldownOptions`, and aliases `rollupOptions` to it.
56
+ const current = (
57
+ (rolldown ? build?.rolldownOptions ?? build?.rollupOptions : build?.rollupOptions) ?? {}
58
+ ) as BundlerOptions;
59
+ const { output } = current;
55
60
 
56
- return {
57
- ...rest,
61
+ const next = {
62
+ ...build,
58
63
  sourcemap: "hidden",
59
- [rolldown ? "rolldownOptions" : "rollupOptions"]: {
60
- ...bundlerOptions,
64
+ [key]: {
65
+ ...current,
61
66
  // An app may build several outputs; each one leaves its sources out.
62
67
  output: Array.isArray(output) ? output.map(excludeSources) : excludeSources(output),
63
68
  },
64
69
  } as BuildOptions;
70
+
71
+ if (rolldown) {
72
+ // Spreading copied the alias as a plain, stale value. Put back the alias
73
+ // Vite 8 itself sets up, so later readers of `rollupOptions` see the same
74
+ // object Vite reads.
75
+ delete next.rollupOptions;
76
+ Object.defineProperty(next, "rollupOptions", {
77
+ get: () => next.rolldownOptions,
78
+ set: (value) => {
79
+ next.rolldownOptions = value;
80
+ },
81
+ configurable: true,
82
+ enumerable: true,
83
+ });
84
+ }
85
+ return next;
86
+ }
87
+
88
+ /** A source map's JSON without its source text, or `null` if it has none or is not a map. */
89
+ export function withoutSourcesContent(map: string): string | null {
90
+ try {
91
+ const parsed = JSON.parse(map);
92
+ if (!parsed || typeof parsed !== "object" || !("sourcesContent" in parsed)) return null;
93
+ delete parsed.sourcesContent;
94
+ return JSON.stringify(parsed);
95
+ } catch {
96
+ return null;
97
+ }
65
98
  }
66
99
 
67
100
  export function hiddenSourceMapsPlugin({
68
101
  rolldown = isVite8OrLater,
69
102
  environments = isVite6OrLater,
70
103
  }: HiddenSourceMapsOptions = {}): Plugin {
104
+ // The builds this plugin gave hidden maps: environment names on Vite 6+, or
105
+ // the one browser build (`true`) on Vite 5.
106
+ const changed = new Set<string | true>();
107
+
71
108
  return {
72
109
  name: "base44-hidden-source-maps",
73
110
  apply: "build",
@@ -76,13 +113,17 @@ export function hiddenSourceMapsPlugin({
76
113
  config: {
77
114
  order: "post",
78
115
  handler(config, env) {
116
+ changed.clear();
79
117
  // Vite 6+ is handled per environment below: the top-level build
80
118
  // options feed the SSR environment too.
81
119
  if (environments) return;
82
120
  // Vite 5 runs an SSR build as its own `vite build --ssr`.
83
121
  if (config.build?.ssr || env.isSsrBuild) return;
84
122
  const build = withHiddenSourceMaps(config.build, { rolldown });
85
- if (build) config.build = build;
123
+ if (build) {
124
+ config.build = build;
125
+ changed.add(true);
126
+ }
86
127
  },
87
128
  },
88
129
  configEnvironment: {
@@ -95,7 +136,24 @@ export function hiddenSourceMapsPlugin({
95
136
  // Assigned rather than returned: Vite merges a returned config into the
96
137
  // existing one, which would append to an `output` array instead of
97
138
  // updating each entry.
98
- if (build) config.build = build;
139
+ if (build) {
140
+ config.build = build;
141
+ changed.add(name);
142
+ }
143
+ },
144
+ },
145
+ generateBundle: {
146
+ order: "post",
147
+ handler(_options, bundle) {
148
+ const name = (this as { environment?: { name?: string } }).environment?.name;
149
+ if (!changed.has(environments ? name ?? "client" : true)) return;
150
+ for (const file of Object.values(bundle)) {
151
+ if (file.type !== "asset" || !file.fileName.endsWith(".map")) continue;
152
+ const stripped = withoutSourcesContent(
153
+ typeof file.source === "string" ? file.source : new TextDecoder().decode(file.source)
154
+ );
155
+ if (stripped !== null) file.source = stripped;
156
+ }
99
157
  },
100
158
  },
101
159
  };