@wix/zero-config-implementation 1.35.0 → 1.36.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "registry": "https://registry.npmjs.org/",
5
5
  "access": "public"
6
6
  },
7
- "version": "1.35.0",
7
+ "version": "1.36.0",
8
8
  "description": "Core library for extracting component manifests from JS and CSS files",
9
9
  "type": "module",
10
10
  "main": "dist/index.js",
@@ -84,5 +84,5 @@
84
84
  ]
85
85
  }
86
86
  },
87
- "falconPackageHash": "c6e9f573fcd1e0e0ae8582c94dd30bad934661b0c2396401d835a923"
87
+ "falconPackageHash": "783628b17db7e1730658c51eaaddf8d5abc8372807221c09c6828115"
88
88
  }
@@ -138,6 +138,8 @@ export function renderWithExtractors(
138
138
  ): string {
139
139
  let nextId = 0
140
140
  const getNextId = () => `t${++nextId}`
141
+ const globalScopeWithReact = globalThis as typeof globalThis & { React?: typeof React }
142
+ const hasExistingGlobalReact = Object.prototype.hasOwnProperty.call(globalScopeWithReact, 'React')
141
143
 
142
144
  // Store originals
143
145
  const originalCreateElement = React.createElement
@@ -165,6 +167,11 @@ export function renderWithExtractors(
165
167
  const interceptedJsxDEV = createInterceptor(originalJsxDEV as ElementCreator, listeners, getNextId, store)
166
168
 
167
169
  try {
170
+ // Provide a scoped global React binding only when absent, for classic bundles
171
+ // that reference `React.createElement` without a runtime React import.
172
+ if (!hasExistingGlobalReact) {
173
+ globalScopeWithReact.React = React
174
+ }
168
175
  // @ts-expect-error Monkey-patch createElement
169
176
  React.createElement = interceptedCreateElement
170
177
  // Use the interceptor API for jsx-runtime (includes jsxDEV for dev mode)
@@ -188,5 +195,8 @@ export function renderWithExtractors(
188
195
  cjsRuntime.jsx = origCjsJsx
189
196
  cjsRuntime.jsxs = origCjsJsxs
190
197
  cjsDevRuntime.jsxDEV = origCjsJsxDEV
198
+ if (!hasExistingGlobalReact) {
199
+ Reflect.deleteProperty(globalScopeWithReact, 'React')
200
+ }
191
201
  }
192
202
  }
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ import type { ExtractionError } from './extraction-types'
8
8
  import type { RunExtractorsOptions } from './information-extractors/react'
9
9
  import { extractCssImports, extractDefaultComponentInfo } from './information-extractors/ts'
10
10
  import { processComponent } from './manifest-pipeline'
11
- import { findComponent, loadModule } from './module-loader'
11
+ import { findComponent, findDefaultComponent, loadModule } from './module-loader'
12
12
  import type { LoadModuleFailure } from './module-loader'
13
13
  import { compileTsFile } from './ts-compiler'
14
14
 
@@ -77,7 +77,7 @@ export function extractComponentManifest(
77
77
  // so componentName is known when reporting failures
78
78
  return loadModule(compiledEntryPath)
79
79
  .map((moduleExports) => ({
80
- loadComponent: (name: string) => findComponent(moduleExports, name),
80
+ loadComponent: (name: string) => findComponent(moduleExports, name) ?? findDefaultComponent(moduleExports),
81
81
  failure: null as LoadModuleFailure | null,
82
82
  }))
83
83
  .orElse((failure) => okAsync({ loadComponent: () => null as ComponentType<unknown> | null, failure }))
@@ -79,3 +79,15 @@ export function findComponent(moduleExports: Record<string, unknown>, name: stri
79
79
 
80
80
  return null
81
81
  }
82
+
83
+ /**
84
+ * Finds the default-exported React component from a module.
85
+ * Returns null when the default export is missing or is not component-like.
86
+ */
87
+ export function findDefaultComponent(moduleExports: Record<string, unknown>): ComponentType<unknown> | null {
88
+ const defaultExport = moduleExports.default
89
+ if (isComponent(defaultExport)) {
90
+ return defaultExport as ComponentType<unknown>
91
+ }
92
+ return null
93
+ }