@ethisyscore/vite-plugin 1.120.0 → 1.122.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
@@ -599,6 +599,30 @@ interface PlatformReactBuildSummary {
599
599
  * Runs in `renderChunk`, before the host-verified digest is computed.
600
600
  */
601
601
  declare function rewriteAliasedExternalImports(): Plugin;
602
+ /**
603
+ * Fail the BUILD when a bundle emits an externalised specifier in a form the host's
604
+ * loader cannot rewrite.
605
+ *
606
+ * The host fetches a bundle as text, finds its imports with `es-module-lexer`, and
607
+ * rewrites each import of a REGISTERED specifier into a read from its module registry.
608
+ * That rewriter deliberately handles only a closed set of forms. It SKIPS:
609
+ *
610
+ * - dynamic `import("spec")` (`record.d !== -1`)
611
+ * - import attributes (`with { … }`) (`record.a !== -1`)
612
+ * - anything no `IMPORT_FORMS` regex matches, notably `export … from "spec"`
613
+ *
614
+ * and a skipped statement is left VERBATIM. A bare specifier that survives into a Blob
615
+ * URL module is unresolvable, so the surface dies at mount, before any plugin code runs
616
+ * — with no build-time signal and a stack trace that points at the host, not the plugin
617
+ * that caused it.
618
+ *
619
+ * Today no plugin in the estate emits either form, so this guard is quiet. It exists so
620
+ * that the day someone writes `const { DataGrid } = await import("@mui/x-data-grid")` or
621
+ * re-exports a host package from a barrel, they get a build error naming the file instead
622
+ * of a blank surface in production. The check is on EMITTED syntax rather than source,
623
+ * because whether a source-level re-export survives bundling depends on the entry shape.
624
+ */
625
+ declare function assertHostResolvableExternals(external: readonly string[]): Plugin;
602
626
  /**
603
627
  * Synthesise one isolated PlatformReact entry per surface straight from its
604
628
  * manifest declaration: `definePluginPage(Page, { …views })`, importing ONLY
@@ -1132,4 +1156,4 @@ interface EthisysPluginOptions {
1132
1156
  */
1133
1157
  declare function ethisysManifestPlugin(options?: EthisysPluginOptions): Plugin;
1134
1158
 
1135
- export { type BuildPlatformReactPagesOptions, CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, type ComputePlatformReactPagesInput, type ComputePlatformReactPagesResult, type ContractAManifest, type ContractAPluginOptions, type ContractBManifest, type ContractBPluginOptions, EHX_PLUGIN_CSS_SCOPE, EHX_PLUGIN_ROOT_SCOPE, EHX_PLUGIN_SCOPE_ROOTS, EHX_SCOPED_CSS_LAYERS, type EthisysPluginOptions, type GeneratePlatformReactManifestConfig, type GeneratePlatformReactManifestResult, type IframeBuildContext, type IframeBuildOutputItem, type IframeBuildResult, type IframeSandboxBuildSummary, type IframeSandboxPluginOptions, type IframeViteBuild, type ManifestReactiveRuleRef, type ManifestResourceRef, PLATFORM_REACT_DEDUPE, PLATFORM_REACT_EXTERNALS, type ParsePlatformReactPagesOptions, type PlatformReactAlias, type PlatformReactBuildContext, type PlatformReactBuildSummary, type PlatformReactManifest, type PlatformReactManifestMeta, type PlatformReactManifestPaths, type PlatformReactPageDeclaration, type PlatformReactPageEntry, type PlatformReactPageInput, type PlatformReactPageOverride, type PlatformReactPageSource, type PlatformReactPluginOptions, type PlatformReactViteBuild, type ResolvedPlatformReactPage, type RouteMetaEntry, type ScopePluginCssOptions, type ValidationFailure, type ValidationResult, type ViteBuildFn, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
1159
+ export { type BuildPlatformReactPagesOptions, CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, type ComputePlatformReactPagesInput, type ComputePlatformReactPagesResult, type ContractAManifest, type ContractAPluginOptions, type ContractBManifest, type ContractBPluginOptions, EHX_PLUGIN_CSS_SCOPE, EHX_PLUGIN_ROOT_SCOPE, EHX_PLUGIN_SCOPE_ROOTS, EHX_SCOPED_CSS_LAYERS, type EthisysPluginOptions, type GeneratePlatformReactManifestConfig, type GeneratePlatformReactManifestResult, type IframeBuildContext, type IframeBuildOutputItem, type IframeBuildResult, type IframeSandboxBuildSummary, type IframeSandboxPluginOptions, type IframeViteBuild, type ManifestReactiveRuleRef, type ManifestResourceRef, PLATFORM_REACT_DEDUPE, PLATFORM_REACT_EXTERNALS, type ParsePlatformReactPagesOptions, type PlatformReactAlias, type PlatformReactBuildContext, type PlatformReactBuildSummary, type PlatformReactManifest, type PlatformReactManifestMeta, type PlatformReactManifestPaths, type PlatformReactPageDeclaration, type PlatformReactPageEntry, type PlatformReactPageInput, type PlatformReactPageOverride, type PlatformReactPageSource, type PlatformReactPluginOptions, type PlatformReactViteBuild, type ResolvedPlatformReactPage, type RouteMetaEntry, type ScopePluginCssOptions, type ValidationFailure, type ValidationResult, type ViteBuildFn, assertHostResolvableExternals, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
package/dist/index.d.ts CHANGED
@@ -599,6 +599,30 @@ interface PlatformReactBuildSummary {
599
599
  * Runs in `renderChunk`, before the host-verified digest is computed.
600
600
  */
601
601
  declare function rewriteAliasedExternalImports(): Plugin;
602
+ /**
603
+ * Fail the BUILD when a bundle emits an externalised specifier in a form the host's
604
+ * loader cannot rewrite.
605
+ *
606
+ * The host fetches a bundle as text, finds its imports with `es-module-lexer`, and
607
+ * rewrites each import of a REGISTERED specifier into a read from its module registry.
608
+ * That rewriter deliberately handles only a closed set of forms. It SKIPS:
609
+ *
610
+ * - dynamic `import("spec")` (`record.d !== -1`)
611
+ * - import attributes (`with { … }`) (`record.a !== -1`)
612
+ * - anything no `IMPORT_FORMS` regex matches, notably `export … from "spec"`
613
+ *
614
+ * and a skipped statement is left VERBATIM. A bare specifier that survives into a Blob
615
+ * URL module is unresolvable, so the surface dies at mount, before any plugin code runs
616
+ * — with no build-time signal and a stack trace that points at the host, not the plugin
617
+ * that caused it.
618
+ *
619
+ * Today no plugin in the estate emits either form, so this guard is quiet. It exists so
620
+ * that the day someone writes `const { DataGrid } = await import("@mui/x-data-grid")` or
621
+ * re-exports a host package from a barrel, they get a build error naming the file instead
622
+ * of a blank surface in production. The check is on EMITTED syntax rather than source,
623
+ * because whether a source-level re-export survives bundling depends on the entry shape.
624
+ */
625
+ declare function assertHostResolvableExternals(external: readonly string[]): Plugin;
602
626
  /**
603
627
  * Synthesise one isolated PlatformReact entry per surface straight from its
604
628
  * manifest declaration: `definePluginPage(Page, { …views })`, importing ONLY
@@ -1132,4 +1156,4 @@ interface EthisysPluginOptions {
1132
1156
  */
1133
1157
  declare function ethisysManifestPlugin(options?: EthisysPluginOptions): Plugin;
1134
1158
 
1135
- export { type BuildPlatformReactPagesOptions, CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, type ComputePlatformReactPagesInput, type ComputePlatformReactPagesResult, type ContractAManifest, type ContractAPluginOptions, type ContractBManifest, type ContractBPluginOptions, EHX_PLUGIN_CSS_SCOPE, EHX_PLUGIN_ROOT_SCOPE, EHX_PLUGIN_SCOPE_ROOTS, EHX_SCOPED_CSS_LAYERS, type EthisysPluginOptions, type GeneratePlatformReactManifestConfig, type GeneratePlatformReactManifestResult, type IframeBuildContext, type IframeBuildOutputItem, type IframeBuildResult, type IframeSandboxBuildSummary, type IframeSandboxPluginOptions, type IframeViteBuild, type ManifestReactiveRuleRef, type ManifestResourceRef, PLATFORM_REACT_DEDUPE, PLATFORM_REACT_EXTERNALS, type ParsePlatformReactPagesOptions, type PlatformReactAlias, type PlatformReactBuildContext, type PlatformReactBuildSummary, type PlatformReactManifest, type PlatformReactManifestMeta, type PlatformReactManifestPaths, type PlatformReactPageDeclaration, type PlatformReactPageEntry, type PlatformReactPageInput, type PlatformReactPageOverride, type PlatformReactPageSource, type PlatformReactPluginOptions, type PlatformReactViteBuild, type ResolvedPlatformReactPage, type RouteMetaEntry, type ScopePluginCssOptions, type ValidationFailure, type ValidationResult, type ViteBuildFn, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
1159
+ export { type BuildPlatformReactPagesOptions, CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, type ComputePlatformReactPagesInput, type ComputePlatformReactPagesResult, type ContractAManifest, type ContractAPluginOptions, type ContractBManifest, type ContractBPluginOptions, EHX_PLUGIN_CSS_SCOPE, EHX_PLUGIN_ROOT_SCOPE, EHX_PLUGIN_SCOPE_ROOTS, EHX_SCOPED_CSS_LAYERS, type EthisysPluginOptions, type GeneratePlatformReactManifestConfig, type GeneratePlatformReactManifestResult, type IframeBuildContext, type IframeBuildOutputItem, type IframeBuildResult, type IframeSandboxBuildSummary, type IframeSandboxPluginOptions, type IframeViteBuild, type ManifestReactiveRuleRef, type ManifestResourceRef, PLATFORM_REACT_DEDUPE, PLATFORM_REACT_EXTERNALS, type ParsePlatformReactPagesOptions, type PlatformReactAlias, type PlatformReactBuildContext, type PlatformReactBuildSummary, type PlatformReactManifest, type PlatformReactManifestMeta, type PlatformReactManifestPaths, type PlatformReactPageDeclaration, type PlatformReactPageEntry, type PlatformReactPageInput, type PlatformReactPageOverride, type PlatformReactPageSource, type PlatformReactPluginOptions, type PlatformReactViteBuild, type ResolvedPlatformReactPage, type RouteMetaEntry, type ScopePluginCssOptions, type ValidationFailure, type ValidationResult, type ViteBuildFn, assertHostResolvableExternals, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
package/dist/index.js CHANGED
@@ -936,6 +936,36 @@ var PLATFORM_REACT_EXTERNALS = [
936
936
  "react-dom",
937
937
  "@mui/material",
938
938
  "@mui/icons-material",
939
+ // MUI X. Every plugin previously shipped its own copy on top of the host's.
940
+ //
941
+ // EXACT STRINGS, and that is load-bearing rather than stylistic. Rolldown matches
942
+ // a string `external` by equality, verified by building an entry that imports both
943
+ // `date-fns` and `date-fns/addDays` against `external: ["date-fns"]`: the bare
944
+ // import stayed external, the subpath was bundled. So a prefix or regex matcher
945
+ // here would externalise `@mui/x-data-grid/style.css` and
946
+ // `@mui/x-date-pickers/AdapterDayjs` too, which the host does NOT register, and an
947
+ // external the host does not serve is an unresolvable bare import that kills the
948
+ // bundle before any plugin code runs. `startsWith("@mui/x-charts")` additionally
949
+ // swallows `@mui/x-charts-pro`. Add specifiers one at a time; never widen the match.
950
+ //
951
+ // THE CONSUMER-SIDE GATE: exact matching makes this safe but PARTIAL. A plugin that
952
+ // imports the package root AND a subpath of the same package gets TWO module
953
+ // instances, host-served and bundled, and React context does not cross that seam.
954
+ // The concrete break is `LocalizationProvider` from "@mui/x-date-pickers" (host)
955
+ // with `DatePicker` from "@mui/x-date-pickers/DatePicker" (bundled): the picker
956
+ // cannot see the provider's context and MUI throws "Can not find the date and time
957
+ // pickers localization context". Every root-exported symbol must therefore be
958
+ // imported from the ROOT once its package is externalised.
959
+ //
960
+ // `@mui/x-date-pickers/AdapterDayjs` is the deliberate exception and stays a
961
+ // sub-path import, because the root does not re-export it. That is safe here and it
962
+ // was checked rather than assumed: `LocalizationProvider` validates the adapter with
963
+ // `if (!dateAdapter.isMUIAdapter)`, a duck-typed flag, so a bundled adapter instance
964
+ // handed to the host's provider passes. Contrast `instanceof`, which would not.
965
+ "@mui/x-data-grid",
966
+ "@mui/x-charts",
967
+ "@mui/x-charts-pro",
968
+ "@mui/x-date-pickers",
939
969
  "@emotion/react",
940
970
  "@emotion/styled",
941
971
  "date-fns",
@@ -1027,6 +1057,34 @@ function rewriteAliasedExternalImports() {
1027
1057
  }
1028
1058
  };
1029
1059
  }
1060
+ function assertHostResolvableExternals(external) {
1061
+ return {
1062
+ name: "assert-host-resolvable-externals",
1063
+ renderChunk(code, chunk) {
1064
+ const offences = [];
1065
+ for (const spec of external) {
1066
+ const q = escapeRegExp(spec);
1067
+ const reExport = new RegExp(`\\bexport\\s[^;]{0,200}?from\\s*["']${q}["']`);
1068
+ const dynamic = new RegExp(`\\bimport\\s*\\(\\s*["']${q}["']\\s*\\)`);
1069
+ if (reExport.test(code)) {
1070
+ offences.push(`re-export of "${spec}" (export \u2026 from)`);
1071
+ }
1072
+ if (dynamic.test(code)) {
1073
+ offences.push(`dynamic import of "${spec}"`);
1074
+ }
1075
+ }
1076
+ if (offences.length > 0) {
1077
+ throw new Error(
1078
+ `[build-pages] ${chunk.fileName ?? "bundle"} emits host-provided specifiers in a form the host loader cannot rewrite, so the surface would fail to load at mount:
1079
+ ` + offences.map((o) => ` - ${o}`).join("\n") + `
1080
+
1081
+ Use a STATIC top-level import of the package root instead. A dynamic import of a host-provided package is never needed: the host already loads its namespaces on demand, per bundle. For a re-export, import the symbols and export them explicitly.`
1082
+ );
1083
+ }
1084
+ return null;
1085
+ }
1086
+ };
1087
+ }
1030
1088
  function virtualPageEntry(page, config) {
1031
1089
  const VIRTUAL_ID = `\0virtual:surface/${page.id}`;
1032
1090
  const views = page.views ?? {};
@@ -1115,7 +1173,9 @@ function makeDefaultBuild(viteBuild) {
1115
1173
  ctx.surfacePlugin,
1116
1174
  ...ctx.plugins,
1117
1175
  scopePluginCssPlugin(),
1118
- rewriteAliasedExternalImports()
1176
+ rewriteAliasedExternalImports(),
1177
+ // Last, so it sees exactly the bytes the host will fetch.
1178
+ assertHostResolvableExternals(ctx.external)
1119
1179
  ],
1120
1180
  resolve: {
1121
1181
  dedupe: [...ctx.dedupe],
@@ -1346,7 +1406,11 @@ function assertHostOriginRelativePath2(value, label) {
1346
1406
  }
1347
1407
  }
1348
1408
  function ethisysPlatformReactPlugin(options = {}) {
1349
- return [ethisysPlatformReactPagesPlugin(options), scopePluginCssPlugin()];
1409
+ return [
1410
+ ethisysPlatformReactPagesPlugin(options),
1411
+ scopePluginCssPlugin(),
1412
+ assertHostResolvableExternals([...PLATFORM_REACT_EXTERNALS, "@ethisyscore/host-ui-externals"])
1413
+ ];
1350
1414
  }
1351
1415
  function ethisysPlatformReactPagesPlugin(options = {}) {
1352
1416
  const explicitRoot = options.root;
@@ -2283,6 +2347,6 @@ function ethisysManifestPlugin(options = {}) {
2283
2347
  * comment-free.
2284
2348
  */
2285
2349
 
2286
- 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 };
2350
+ 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, assertHostResolvableExternals, buildIframeSandboxPages, buildPlatformReactPages, computePlatformReactPages, ethisysContractAPlugin, ethisysContractBPlugin, ethisysIframeSandboxPlugin, ethisysManifestPlugin, ethisysPlatformReactPagesPlugin, ethisysPlatformReactPlugin, findUnscopedSelectors, formatUnscopedSelectorError, generatePlatformReactManifest, isScopableCssId, parseExportedNames, parsePlatformReactPages, rewriteAliasedExternalImports, scopePluginCss, scopePluginCssPlugin, validateDeclarativeResource, validateReactiveRule, virtualPageEntry };
2287
2351
  //# sourceMappingURL=index.js.map
2288
2352
  //# sourceMappingURL=index.js.map