@wix/zero-config-implementation 1.35.0 → 1.37.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/README.md +13 -7
- package/dist/index.d.ts +3 -1
- package/dist/index.js +14017 -17003
- package/package.json +2 -2
- package/src/component-renderer.ts +10 -0
- package/src/index.ts +17 -3
- package/src/module-loader.ts +12 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"registry": "https://registry.npmjs.org/",
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.37.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": "
|
|
87
|
+
"falconPackageHash": "ee9a93321f74030e3fae1f44881ad07be78e67c051afcb5ea562b546"
|
|
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
|
|
|
@@ -39,7 +39,7 @@ export interface ExtractComponentManifestOptions extends RunExtractorsOptions {
|
|
|
39
39
|
onError?: (error: ExtractionError) => void
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function
|
|
42
|
+
export function extractComponentManifestResult(
|
|
43
43
|
componentPath: string,
|
|
44
44
|
compiledEntryPath: string,
|
|
45
45
|
options?: ExtractComponentManifestOptions,
|
|
@@ -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 }))
|
|
@@ -129,6 +129,20 @@ export function extractComponentManifest(
|
|
|
129
129
|
})
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
export async function extractComponentManifest(
|
|
133
|
+
componentPath: string,
|
|
134
|
+
compiledEntryPath: string,
|
|
135
|
+
options?: ExtractComponentManifestOptions,
|
|
136
|
+
): Promise<ManifestResult> {
|
|
137
|
+
const extractionResult = await extractComponentManifestResult(componentPath, compiledEntryPath, options)
|
|
138
|
+
return extractionResult.match(
|
|
139
|
+
(manifestResult) => manifestResult,
|
|
140
|
+
(error) => {
|
|
141
|
+
throw error
|
|
142
|
+
},
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
132
146
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
133
147
|
// Public API Exports
|
|
134
148
|
//
|
package/src/module-loader.ts
CHANGED
|
@@ -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
|
+
}
|