@wix/zero-config-implementation 1.78.0 → 1.80.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.
Files changed (37) hide show
  1. package/README.md +4 -0
  2. package/dist/{index--6I20lGB.js → index-B8oF7hWg.js} +15405 -15073
  3. package/dist/{index-DAAmOM1c.js → index-CGnbp9jn.js} +1 -1
  4. package/dist/index.js +1 -1
  5. package/package.json +3 -3
  6. package/src/converters/to-editor-component.ts +2 -2
  7. package/src/extensions/context-providers/context.test.ts +181 -0
  8. package/src/extensions/context-providers/context.ts +83 -0
  9. package/src/extensions/context-providers/mock-provider.test.ts +44 -0
  10. package/src/extensions/context-providers/mock-provider.ts +210 -0
  11. package/src/extensions/context-providers/types.ts +22 -0
  12. package/src/{ref-elements → extensions/ref-elements}/context.test.ts +4 -4
  13. package/src/extensions/ref-elements/context.ts +168 -0
  14. package/src/{ref-elements → extensions/ref-elements}/eligible-paths.ts +1 -1
  15. package/src/extensions/shared/ast-scanner.ts +85 -0
  16. package/src/extensions/shared/catalog-loader.ts +64 -0
  17. package/src/{ref-elements → extensions/shared}/module-resolution.test.ts +2 -2
  18. package/src/index.ts +108 -67
  19. package/src/information-extractors/css/parse.test.ts +58 -0
  20. package/src/information-extractors/css/parse.ts +54 -7
  21. package/src/information-extractors/css/sass-adapter.test.ts +137 -0
  22. package/src/information-extractors/css/sass-adapter.ts +59 -1
  23. package/src/information-extractors/react/extractors/prop-tracker.test.ts +2 -2
  24. package/src/information-extractors/react/extractors/prop-tracker.ts +3 -3
  25. package/src/information-extractors/react/utils/mock-generator.test.ts +107 -3
  26. package/src/information-extractors/react/utils/mock-generator.ts +104 -1
  27. package/src/manifest-pipeline.ts +4 -1
  28. package/src/module-loader.test.ts +1 -1
  29. package/src/module-loader.ts +1 -1
  30. package/src/react-runtime-loader.ts +28 -2
  31. package/src/ref-elements/context.ts +0 -280
  32. /package/src/{ref-elements → extensions/ref-elements}/component-tag.ts +0 -0
  33. /package/src/{ref-elements → extensions/ref-elements}/path-utils.test.ts +0 -0
  34. /package/src/{ref-elements → extensions/ref-elements}/path-utils.ts +0 -0
  35. /package/src/{ref-elements → extensions/ref-elements}/types.ts +0 -0
  36. /package/src/{ref-elements → extensions/shared}/module-resolution.ts +0 -0
  37. /package/src/{ref-elements/module-specifier.ts → extensions/shared/package-specifier.ts} +0 -0
@@ -1,280 +0,0 @@
1
- import ts from 'typescript'
2
- import type { ComponentInfo } from '../information-extractors/ts/types'
3
- import { extractEligibleRefElementPaths } from './eligible-paths'
4
- import { resolveModuleUrlFromEntryPath } from './module-resolution'
5
- import { extractBasePackageName, extractModuleLeafExportName } from './module-specifier'
6
- import type { RefElementContext, RefElementModule } from './types'
7
-
8
- interface RawRefElementExtensionEntry {
9
- options?: {
10
- type?: string
11
- resources?: {
12
- client?: {
13
- moduleSpecifier?: string
14
- }
15
- }
16
- }
17
- type?: string
18
- resources?: {
19
- client?: {
20
- moduleSpecifier?: string
21
- }
22
- }
23
- }
24
-
25
- interface NormalizedRefElementCatalogEntry {
26
- moduleSpecifier: string
27
- refComponentType: string
28
- }
29
-
30
- export async function buildRefElementContext(
31
- program: ts.Program,
32
- sourceFilePath: string,
33
- componentInfo: ComponentInfo,
34
- compiledEntryPath: string,
35
- ): Promise<RefElementContext> {
36
- const importedModuleSpecifiers = collectImportedRefElementModuleSpecifiers(program, sourceFilePath)
37
-
38
- return {
39
- eligiblePaths: extractEligibleRefElementPaths(componentInfo),
40
- runtimeModules: await resolveRuntimeModules(importedModuleSpecifiers, compiledEntryPath),
41
- }
42
- }
43
-
44
- async function resolveRuntimeModules(
45
- importedModuleSpecifiers: string[],
46
- compiledEntryPath: string,
47
- ): Promise<RefElementModule[]> {
48
- if (importedModuleSpecifiers.length === 0) {
49
- return []
50
- }
51
-
52
- const importedModuleSpecifierSet = new Set(importedModuleSpecifiers)
53
- const importedPackageNames = [
54
- ...new Set(importedModuleSpecifiers.filter(isPackageModuleSpecifier).map(extractBasePackageName)),
55
- ]
56
- const catalogEntries = (
57
- await Promise.all(importedPackageNames.map((packageName) => loadCatalogEntries(packageName, compiledEntryPath)))
58
- ).flat()
59
-
60
- const runtimeModulesBySpecifier = new Map<string, Set<string>>()
61
-
62
- for (const catalogEntry of catalogEntries) {
63
- if (!importedModuleSpecifierSet.has(catalogEntry.moduleSpecifier)) {
64
- continue
65
- }
66
-
67
- const refComponentTypes = runtimeModulesBySpecifier.get(catalogEntry.moduleSpecifier) ?? new Set<string>()
68
- refComponentTypes.add(catalogEntry.refComponentType)
69
- runtimeModulesBySpecifier.set(catalogEntry.moduleSpecifier, refComponentTypes)
70
- }
71
-
72
- const runtimeModules: RefElementModule[] = []
73
-
74
- for (const [moduleSpecifier, refComponentTypes] of runtimeModulesBySpecifier.entries()) {
75
- if (refComponentTypes.size !== 1) {
76
- continue
77
- }
78
-
79
- const refComponentType = [...refComponentTypes][0]
80
- if (!refComponentType) {
81
- continue
82
- }
83
-
84
- const resolvedModuleUrl = resolveModuleUrlFromEntryPath(compiledEntryPath, moduleSpecifier)
85
- if (!resolvedModuleUrl) {
86
- continue
87
- }
88
-
89
- runtimeModules.push({
90
- exportNames: buildRefElementExportNames(moduleSpecifier),
91
- moduleSpecifier,
92
- resolvedModuleUrl,
93
- refComponentType,
94
- })
95
- }
96
-
97
- return runtimeModules
98
- }
99
-
100
- function isPackageModuleSpecifier(moduleSpecifier: string): boolean {
101
- return !moduleSpecifier.startsWith('.') && !moduleSpecifier.startsWith('/') && !moduleSpecifier.startsWith('file:')
102
- }
103
-
104
- function collectImportedRefElementModuleSpecifiers(program: ts.Program, sourceFilePath: string): string[] {
105
- const entrySourceFile = findSourceFile(program, sourceFilePath)
106
- if (!entrySourceFile) {
107
- return []
108
- }
109
-
110
- const importedModuleSpecifiers = new Set<string>()
111
- const visitedSourceFiles = new Set<string>()
112
-
113
- function visitSourceFile(sourceFile: ts.SourceFile): void {
114
- if (visitedSourceFiles.has(sourceFile.fileName)) {
115
- return
116
- }
117
-
118
- visitedSourceFiles.add(sourceFile.fileName)
119
-
120
- for (const statement of sourceFile.statements) {
121
- const moduleSpecifier = readReferencedModuleSpecifier(statement)
122
- if (!moduleSpecifier) {
123
- continue
124
- }
125
-
126
- if (referencesRefElementModule(statement, moduleSpecifier)) {
127
- importedModuleSpecifiers.add(moduleSpecifier)
128
- }
129
-
130
- const importedSourceFile = resolveImportedSourceFile(program, sourceFile.fileName, moduleSpecifier)
131
- if (importedSourceFile) {
132
- visitSourceFile(importedSourceFile)
133
- }
134
- }
135
- }
136
-
137
- visitSourceFile(entrySourceFile)
138
- return [...importedModuleSpecifiers]
139
- }
140
-
141
- async function loadCatalogEntries(
142
- packageName: string,
143
- compiledEntryPath: string,
144
- ): Promise<NormalizedRefElementCatalogEntry[]> {
145
- const resolvedExtensionsUrl = resolveModuleUrlFromEntryPath(compiledEntryPath, `${packageName}/extensions`)
146
- if (!resolvedExtensionsUrl) {
147
- return []
148
- }
149
-
150
- const extensionModule = (await import(resolvedExtensionsUrl)) as Record<string, unknown>
151
-
152
- return extractRawExtensionEntries(extensionModule)
153
- .map(normalizeExtensionEntry)
154
- .flatMap((catalogEntry) => (catalogEntry ? [catalogEntry] : []))
155
- }
156
-
157
- function referencesRefElementModule(statement: ts.Statement, moduleSpecifier: string): boolean {
158
- const moduleLeafExportName = extractModuleLeafExportName(moduleSpecifier)
159
- if (!moduleLeafExportName) {
160
- return false
161
- }
162
-
163
- if (ts.isImportDeclaration(statement)) {
164
- return importsRefElementModule(statement, moduleLeafExportName)
165
- }
166
-
167
- if (ts.isExportDeclaration(statement)) {
168
- return reExportsRefElementModule(statement, moduleLeafExportName)
169
- }
170
-
171
- return false
172
- }
173
-
174
- function importsRefElementModule(importDeclaration: ts.ImportDeclaration, moduleLeafExportName: string): boolean {
175
- const importClause = importDeclaration.importClause
176
- if (!importClause) {
177
- return false
178
- }
179
-
180
- if (importClause.name) {
181
- return true
182
- }
183
-
184
- if (!importClause.namedBindings || !ts.isNamedImports(importClause.namedBindings)) {
185
- return false
186
- }
187
-
188
- return importClause.namedBindings.elements.some((importSpecifier) => {
189
- const importedName = importSpecifier.propertyName?.text ?? importSpecifier.name.text
190
- return importedName === moduleLeafExportName
191
- })
192
- }
193
-
194
- function reExportsRefElementModule(exportDeclaration: ts.ExportDeclaration, moduleLeafExportName: string): boolean {
195
- if (!exportDeclaration.exportClause || !ts.isNamedExports(exportDeclaration.exportClause)) {
196
- return false
197
- }
198
-
199
- return exportDeclaration.exportClause.elements.some((exportSpecifier) => {
200
- const exportedSourceName = exportSpecifier.propertyName?.text ?? exportSpecifier.name.text
201
- return exportedSourceName === 'default' || exportedSourceName === moduleLeafExportName
202
- })
203
- }
204
-
205
- function extractRawExtensionEntries(extensionModule: Record<string, unknown>): RawRefElementExtensionEntry[] {
206
- const defaultExport = extensionModule.default
207
- const extensionEntries = Array.isArray(defaultExport)
208
- ? defaultExport
209
- : ((defaultExport as { extensions?: unknown[] } | undefined)?.extensions ?? extensionModule.extensions)
210
-
211
- return Array.isArray(extensionEntries) ? (extensionEntries as RawRefElementExtensionEntry[]) : []
212
- }
213
-
214
- function normalizeExtensionEntry(rawEntry: RawRefElementExtensionEntry): NormalizedRefElementCatalogEntry | undefined {
215
- const normalizedEntry = rawEntry.options ?? rawEntry
216
- const moduleSpecifier = normalizedEntry.resources?.client?.moduleSpecifier
217
- const refComponentType = normalizedEntry.type
218
-
219
- if (!moduleSpecifier || !refComponentType) {
220
- return undefined
221
- }
222
-
223
- return {
224
- moduleSpecifier,
225
- refComponentType,
226
- }
227
- }
228
-
229
- function buildRefElementExportNames(moduleSpecifier: string): string[] {
230
- const exportNames = new Set<string>(['default'])
231
- if (extractBasePackageName(moduleSpecifier) === moduleSpecifier) {
232
- return [...exportNames]
233
- }
234
-
235
- const moduleLeafName = extractModuleLeafExportName(moduleSpecifier)
236
- if (moduleLeafName) {
237
- exportNames.add(moduleLeafName)
238
- }
239
-
240
- return [...exportNames]
241
- }
242
-
243
- function findSourceFile(program: ts.Program, sourceFilePath: string): ts.SourceFile | undefined {
244
- return (
245
- program.getSourceFile(sourceFilePath) ??
246
- program.getSourceFiles().find((sourceFile) => sourceFile.fileName === sourceFilePath)
247
- )
248
- }
249
-
250
- function resolveImportedSourceFile(
251
- program: ts.Program,
252
- importingFilePath: string,
253
- moduleSpecifier: string,
254
- ): ts.SourceFile | undefined {
255
- const resolvedModule = ts.resolveModuleName(moduleSpecifier, importingFilePath, program.getCompilerOptions(), ts.sys)
256
- const resolvedFileName = resolvedModule.resolvedModule?.resolvedFileName
257
-
258
- if (!resolvedFileName) {
259
- return undefined
260
- }
261
-
262
- const resolvedSourceFile = findSourceFile(program, resolvedFileName)
263
- if (!resolvedSourceFile || resolvedSourceFile.isDeclarationFile) {
264
- return undefined
265
- }
266
-
267
- return resolvedSourceFile
268
- }
269
-
270
- function readReferencedModuleSpecifier(statement: ts.Statement): string | undefined {
271
- if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
272
- return statement.moduleSpecifier.text
273
- }
274
-
275
- if (ts.isExportDeclaration(statement) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
276
- return statement.moduleSpecifier.text
277
- }
278
-
279
- return undefined
280
- }