@ethisyscore/vite-plugin 1.104.0 → 1.106.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/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin, InlineConfig } from 'vite';
1
+ import { Plugin, ESBuildOptions, InlineConfig } from 'vite';
2
2
 
3
3
  /**
4
4
  * Reference from the plugin manifest to an SDUI resource JSON file.
@@ -440,8 +440,18 @@ interface PlatformReactBuildContext {
440
440
  alias: PlatformReactAlias[];
441
441
  plugins: Plugin[];
442
442
  target: string;
443
- minify: boolean;
444
- sourcemap: boolean;
443
+ minify: boolean | "esbuild" | "terser";
444
+ sourcemap: boolean | "inline" | "hidden";
445
+ /**
446
+ * Optional so an existing consumer constructing this context keeps compiling.
447
+ * This type is exported through the `PlatformReactViteBuild` seam, so a
448
+ * required field here is a breaking change for anyone who builds one by hand.
449
+ * The orchestrator always sets them; the defaults below only cover that case.
450
+ */
451
+ sourcemapExcludeSources?: boolean;
452
+ esbuild?: ESBuildOptions | false;
453
+ cssMinify?: boolean | "esbuild" | "lightningcss";
454
+ reportCompressedSize?: boolean;
445
455
  }
446
456
  /** Low-level Vite `build` function. Defaults to a dynamic `import("vite")`. */
447
457
  type ViteBuildFn = (config: InlineConfig) => Promise<unknown>;
@@ -474,12 +484,63 @@ interface BuildPlatformReactPagesOptions {
474
484
  srcDir?: string;
475
485
  /** Alias prefix manifest `src/…` paths are rewritten to. Default `@` (→ `@/…`). */
476
486
  aliasPrefix?: string;
477
- /** Rollup build target. Default `es2022`. */
487
+ /**
488
+ * Rollup build target. Default `esnext`.
489
+ *
490
+ * Only worth it alongside minification. Measured across 50 finance surfaces,
491
+ * `esnext` on unminified output cost 10% MORE gzipped than `es2022`, because
492
+ * it skips the esbuild pass that also normalises emitted code. Lower the
493
+ * target too if minification is ever turned off.
494
+ */
478
495
  target?: string;
479
- /** Minify output. Default `false` (digest stability + debuggability). */
480
- minify?: boolean;
481
- /** Emit sourcemaps. Default `true`. */
482
- sourcemap?: boolean;
496
+ /**
497
+ * Minify output. Default `true`, worth roughly 31% of gzipped transfer.
498
+ *
499
+ * DEPLOYMENT ORDER: a minified bundle only mounts on a host whose module
500
+ * registry walks the import prologue. The earlier rewriter was line-anchored
501
+ * and matched an import only when it sat on its own line; a minifier puts the
502
+ * whole prologue on line one, where nothing matched, so `react` and
503
+ * `@mui/material` reached the browser as unresolvable bare specifiers and the
504
+ * surface threw at mount. A plugin built with this default must therefore not
505
+ * be promoted ahead of that host change.
506
+ */
507
+ minify?: boolean | "esbuild" | "terser";
508
+ /**
509
+ * Sourcemap mode. Default `"hidden"`: the map is emitted but no
510
+ * `sourceMappingURL` comment is written into the bundle, so a browser never
511
+ * fetches it and cannot 404 on a map stripped before deploy.
512
+ */
513
+ sourcemap?: boolean | "inline" | "hidden";
514
+ /**
515
+ * Omit `sourcesContent` from emitted maps. Default `true`. The map keeps the
516
+ * `mappings` needed to rewrite a stack trace, but carries no source bodies —
517
+ * which both shrinks it by roughly 80% and removes the source-in-map leak path.
518
+ */
519
+ sourcemapExcludeSources?: boolean;
520
+ /**
521
+ * esbuild options applied while minifying. The default drops `console` and
522
+ * `debugger` calls, so diagnostic logging a developer left in a page never
523
+ * reaches a packaged bundle. Pass `false` to keep them — a plugin that
524
+ * reports failures through `console.error` must move to the runtime logger
525
+ * before relying on the default.
526
+ *
527
+ * `false` means "apply no esbuild options". It does NOT disable esbuild: Vite
528
+ * would read that as removing the transform plugin, taking TS and JSX handling
529
+ * with it.
530
+ */
531
+ esbuild?: ESBuildOptions | false;
532
+ /**
533
+ * Minify CSS before it is inlined into the bundle. Default `true`, which lets
534
+ * Vite pick its own minifier. Naming `"esbuild"` would force Vite 8 to import
535
+ * an optional peer that need not be installed.
536
+ */
537
+ cssMinify?: boolean | "esbuild" | "lightningcss";
538
+ /**
539
+ * Print the post-build gzip-size table. Default `false`: the numbers are
540
+ * informational, and producing them compresses every chunk a second time —
541
+ * once per sub-build, so the cost scales with surface count.
542
+ */
543
+ reportCompressedSize?: boolean;
483
544
  /** Wipe `outDir` before building. Default `true`. */
484
545
  clean?: boolean;
485
546
  /** Progress logger. Default `console`. */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin, InlineConfig } from 'vite';
1
+ import { Plugin, ESBuildOptions, InlineConfig } from 'vite';
2
2
 
3
3
  /**
4
4
  * Reference from the plugin manifest to an SDUI resource JSON file.
@@ -440,8 +440,18 @@ interface PlatformReactBuildContext {
440
440
  alias: PlatformReactAlias[];
441
441
  plugins: Plugin[];
442
442
  target: string;
443
- minify: boolean;
444
- sourcemap: boolean;
443
+ minify: boolean | "esbuild" | "terser";
444
+ sourcemap: boolean | "inline" | "hidden";
445
+ /**
446
+ * Optional so an existing consumer constructing this context keeps compiling.
447
+ * This type is exported through the `PlatformReactViteBuild` seam, so a
448
+ * required field here is a breaking change for anyone who builds one by hand.
449
+ * The orchestrator always sets them; the defaults below only cover that case.
450
+ */
451
+ sourcemapExcludeSources?: boolean;
452
+ esbuild?: ESBuildOptions | false;
453
+ cssMinify?: boolean | "esbuild" | "lightningcss";
454
+ reportCompressedSize?: boolean;
445
455
  }
446
456
  /** Low-level Vite `build` function. Defaults to a dynamic `import("vite")`. */
447
457
  type ViteBuildFn = (config: InlineConfig) => Promise<unknown>;
@@ -474,12 +484,63 @@ interface BuildPlatformReactPagesOptions {
474
484
  srcDir?: string;
475
485
  /** Alias prefix manifest `src/…` paths are rewritten to. Default `@` (→ `@/…`). */
476
486
  aliasPrefix?: string;
477
- /** Rollup build target. Default `es2022`. */
487
+ /**
488
+ * Rollup build target. Default `esnext`.
489
+ *
490
+ * Only worth it alongside minification. Measured across 50 finance surfaces,
491
+ * `esnext` on unminified output cost 10% MORE gzipped than `es2022`, because
492
+ * it skips the esbuild pass that also normalises emitted code. Lower the
493
+ * target too if minification is ever turned off.
494
+ */
478
495
  target?: string;
479
- /** Minify output. Default `false` (digest stability + debuggability). */
480
- minify?: boolean;
481
- /** Emit sourcemaps. Default `true`. */
482
- sourcemap?: boolean;
496
+ /**
497
+ * Minify output. Default `true`, worth roughly 31% of gzipped transfer.
498
+ *
499
+ * DEPLOYMENT ORDER: a minified bundle only mounts on a host whose module
500
+ * registry walks the import prologue. The earlier rewriter was line-anchored
501
+ * and matched an import only when it sat on its own line; a minifier puts the
502
+ * whole prologue on line one, where nothing matched, so `react` and
503
+ * `@mui/material` reached the browser as unresolvable bare specifiers and the
504
+ * surface threw at mount. A plugin built with this default must therefore not
505
+ * be promoted ahead of that host change.
506
+ */
507
+ minify?: boolean | "esbuild" | "terser";
508
+ /**
509
+ * Sourcemap mode. Default `"hidden"`: the map is emitted but no
510
+ * `sourceMappingURL` comment is written into the bundle, so a browser never
511
+ * fetches it and cannot 404 on a map stripped before deploy.
512
+ */
513
+ sourcemap?: boolean | "inline" | "hidden";
514
+ /**
515
+ * Omit `sourcesContent` from emitted maps. Default `true`. The map keeps the
516
+ * `mappings` needed to rewrite a stack trace, but carries no source bodies —
517
+ * which both shrinks it by roughly 80% and removes the source-in-map leak path.
518
+ */
519
+ sourcemapExcludeSources?: boolean;
520
+ /**
521
+ * esbuild options applied while minifying. The default drops `console` and
522
+ * `debugger` calls, so diagnostic logging a developer left in a page never
523
+ * reaches a packaged bundle. Pass `false` to keep them — a plugin that
524
+ * reports failures through `console.error` must move to the runtime logger
525
+ * before relying on the default.
526
+ *
527
+ * `false` means "apply no esbuild options". It does NOT disable esbuild: Vite
528
+ * would read that as removing the transform plugin, taking TS and JSX handling
529
+ * with it.
530
+ */
531
+ esbuild?: ESBuildOptions | false;
532
+ /**
533
+ * Minify CSS before it is inlined into the bundle. Default `true`, which lets
534
+ * Vite pick its own minifier. Naming `"esbuild"` would force Vite 8 to import
535
+ * an optional peer that need not be installed.
536
+ */
537
+ cssMinify?: boolean | "esbuild" | "lightningcss";
538
+ /**
539
+ * Print the post-build gzip-size table. Default `false`: the numbers are
540
+ * informational, and producing them compresses every chunk a second time —
541
+ * once per sub-build, so the cost scales with surface count.
542
+ */
543
+ reportCompressedSize?: boolean;
483
544
  /** Wipe `outDir` before building. Default `true`. */
484
545
  clean?: boolean;
485
546
  /** Progress logger. Default `console`. */
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { readFileSync, existsSync, rmSync, mkdirSync, readdirSync, writeFileSync
2
2
  import { isAbsolute, resolve, basename, relative, sep, dirname, normalize } from 'path';
3
3
  import { KNOWN_PRIMITIVES, KNOWN_OPERATORS, KNOWN_RULE_KINDS, SduiNode, ReactiveRule, IframeSandboxPageDeclaration, AssetDigest } from '@ethisyscore/protocol';
4
4
  import { createHash } from 'crypto';
5
+ import { createRequire } from 'module';
5
6
 
6
7
  // src/index.ts
7
8
  var KNOWN_PRIMITIVE_SET = new Set(KNOWN_PRIMITIVES);
@@ -953,6 +954,19 @@ var DEFAULT_SRC_DIR = "src";
953
954
  var DEFAULT_ALIAS_PREFIX = "@";
954
955
  var SUMMARY_FILENAME = "platform-react-pages.json";
955
956
  var DIGEST_MAP_FILENAME = "platform-react-digest-map.json";
957
+ var DEFAULT_ESBUILD = {
958
+ // `pure`, not `drop: ["console"]`. A blanket drop removes `console.error` and
959
+ // `console.warn` too, and the SDK reports real failures through them from code
960
+ // bundled into every surface: a production URL-resolution failure in
961
+ // `plugin-ui/src/platform-react/surfaceUrl.ts`, and host-version skew in
962
+ // `useOrgFormatSync` and `useReportingCurrencySync`. Those would have failed
963
+ // silently in packaged bundles. Marking the noisy methods side-effect-free
964
+ // lets tree shaking remove them while diagnostics survive.
965
+ pure: ["console.log", "console.debug", "console.trace"],
966
+ drop: ["debugger"],
967
+ legalComments: "eof",
968
+ treeShaking: true
969
+ };
956
970
  function rewriteAliasedExternalImports() {
957
971
  return {
958
972
  name: "rewrite-aliased-external-imports",
@@ -1044,6 +1058,14 @@ function readManifest(options, root) {
1044
1058
  );
1045
1059
  }
1046
1060
  }
1061
+ function esbuildIsAvailable(root) {
1062
+ try {
1063
+ createRequire(resolve(root, "package.json")).resolve("esbuild");
1064
+ return true;
1065
+ } catch {
1066
+ return false;
1067
+ }
1068
+ }
1047
1069
  function makeDefaultBuild(viteBuild) {
1048
1070
  return async (ctx) => {
1049
1071
  const build = viteBuild ?? (await import('vite')).build;
@@ -1064,12 +1086,27 @@ function makeDefaultBuild(viteBuild) {
1064
1086
  dedupe: [...ctx.dedupe],
1065
1087
  alias: ctx.alias
1066
1088
  },
1089
+ // Top-level, not under `build` — Vite feeds this to esbuild during
1090
+ // minification, which is where `drop` removes console/debugger calls.
1091
+ //
1092
+ // `false` is never forwarded. Vite reads `esbuild: false` as "drop the
1093
+ // esbuild transform plugin entirely", not as "apply no options", so a
1094
+ // plugin opting out of console-stripping would also lose TS/JSX
1095
+ // transformation for any file its own plugins do not handle. An empty
1096
+ // options object keeps the transform and applies nothing.
1097
+ //
1098
+ // Omitted entirely where esbuild cannot be resolved: naming it would make
1099
+ // Vite 8 import an optional peer that is not installed. Minification still
1100
+ // happens there through oxc; only the esbuild-specific options are lost.
1101
+ ...esbuildIsAvailable(ctx.root) ? { esbuild: ctx.esbuild === false ? {} : ctx.esbuild ?? DEFAULT_ESBUILD } : {},
1067
1102
  build: {
1068
1103
  target: ctx.target,
1069
1104
  outDir: ctx.outDir,
1070
1105
  emptyOutDir: false,
1071
1106
  assetsDir: "",
1072
1107
  minify: ctx.minify,
1108
+ cssMinify: ctx.cssMinify ?? true,
1109
+ reportCompressedSize: ctx.reportCompressedSize ?? false,
1073
1110
  sourcemap: ctx.sourcemap,
1074
1111
  rollupOptions: {
1075
1112
  input: { [ctx.pageId]: ctx.entryId },
@@ -1078,6 +1115,7 @@ function makeDefaultBuild(viteBuild) {
1078
1115
  output: {
1079
1116
  format: "es",
1080
1117
  inlineDynamicImports: true,
1118
+ sourcemapExcludeSources: ctx.sourcemapExcludeSources ?? true,
1081
1119
  entryFileNames: `${ctx.outputPrefix}/[name].js`,
1082
1120
  chunkFileNames: `${ctx.outputPrefix}/[name]-[hash].js`,
1083
1121
  assetFileNames: `${ctx.outputPrefix}/[name][extname]`
@@ -1174,9 +1212,13 @@ async function buildPlatformReactPages(options = {}) {
1174
1212
  dedupe,
1175
1213
  alias,
1176
1214
  plugins,
1177
- target: options.target ?? "es2022",
1178
- minify: options.minify ?? false,
1179
- sourcemap: options.sourcemap ?? true
1215
+ target: options.target ?? "esnext",
1216
+ minify: options.minify ?? true,
1217
+ sourcemap: options.sourcemap ?? "hidden",
1218
+ sourcemapExcludeSources: options.sourcemapExcludeSources ?? true,
1219
+ esbuild: options.esbuild ?? DEFAULT_ESBUILD,
1220
+ cssMinify: options.cssMinify ?? true,
1221
+ reportCompressedSize: options.reportCompressedSize ?? false
1180
1222
  });
1181
1223
  }
1182
1224
  if (overlay) {
@@ -1196,9 +1238,13 @@ async function buildPlatformReactPages(options = {}) {
1196
1238
  dedupe,
1197
1239
  alias,
1198
1240
  plugins,
1199
- target: options.target ?? "es2022",
1200
- minify: options.minify ?? false,
1201
- sourcemap: options.sourcemap ?? true
1241
+ target: options.target ?? "esnext",
1242
+ minify: options.minify ?? true,
1243
+ sourcemap: options.sourcemap ?? "hidden",
1244
+ sourcemapExcludeSources: options.sourcemapExcludeSources ?? true,
1245
+ esbuild: options.esbuild ?? DEFAULT_ESBUILD,
1246
+ cssMinify: options.cssMinify ?? true,
1247
+ reportCompressedSize: options.reportCompressedSize ?? false
1202
1248
  });
1203
1249
  }
1204
1250
  const summaryPages = pages.map((p) => ({
@@ -2192,6 +2238,15 @@ function ethisysManifestPlugin(options = {}) {
2192
2238
  }
2193
2239
  };
2194
2240
  }
2241
+ /**
2242
+ * esbuild options applied while minifying.
2243
+ *
2244
+ * `legalComments: "eof"`, not `"none"`: this builder bundles every non-external
2245
+ * dependency into each surface, so stripping `/*!` and `@preserve` banners would
2246
+ * distribute third-party code without the attribution its licence requires.
2247
+ * Collecting them at end of file keeps the notices while leaving the code itself
2248
+ * comment-free.
2249
+ */
2195
2250
 
2196
2251
  export { CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, EHX_PLUGIN_CSS_SCOPE, EHX_PLUGIN_ROOT_SCOPE, EHX_PLUGIN_SCOPE_ROOTS, EHX_SCOPED_CSS_LAYERS, PLATFORM_REACT_DEDUPE, PLATFORM_REACT_EXTERNALS, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
2197
2252
  //# sourceMappingURL=index.js.map