vibe-design-system 2.5.26 → 2.5.28
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
|
@@ -144,31 +144,34 @@ function injectProviderDecorators(projectRoot) {
|
|
|
144
144
|
|
|
145
145
|
if (providersToAdd.length > 0) {
|
|
146
146
|
let content = fs.readFileSync(previewPath, "utf-8");
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const lastImportIdx = content.search(/\nimport\s+.+?;\s*$/m);
|
|
153
|
-
const insertAt = lastImportIdx >= 0 ? content.indexOf("\n", lastImportIdx) + 1 : content.indexOf("\n") + 1;
|
|
154
|
-
content = content.slice(0, insertAt) + importLines + "\n" + content.slice(insertAt);
|
|
147
|
+
const uniqueProviders = [...new Map(providersToAdd.map((p) => [p.name, p])).values()];
|
|
148
|
+
if (!content.includes("import React") && !content.includes("import React from")) {
|
|
149
|
+
const firstImport = content.match(/^import\s+/m);
|
|
150
|
+
const insertAt = firstImport ? content.indexOf(firstImport[0]) : 0;
|
|
151
|
+
content = content.slice(0, insertAt) + "import React from \"react\";\n" + content.slice(insertAt);
|
|
155
152
|
}
|
|
156
|
-
|
|
157
|
-
if (!content.includes(
|
|
158
|
-
const
|
|
159
|
-
const insertAt =
|
|
160
|
-
content = content.slice(0, insertAt) +
|
|
153
|
+
for (const p of uniqueProviders) {
|
|
154
|
+
if (!content.includes(p.name)) {
|
|
155
|
+
const lastImportIdx = content.search(/\nimport\s+.+?;\s*$/m);
|
|
156
|
+
const insertAt = lastImportIdx >= 0 ? content.indexOf("\n", lastImportIdx) + 1 : content.indexOf("\n") + 1;
|
|
157
|
+
content = content.slice(0, insertAt) + `import { ${p.name} } from "${p.importPath}";\n` + content.slice(insertAt);
|
|
161
158
|
}
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
}
|
|
160
|
+
content = content.replace(/const withProviders\s*=\s*\([^)]*\)\s*=>\s*[\s\S]+?;\s*\n?/g, "").replace(/\n{3,}/g, "\n\n");
|
|
161
|
+
const withProvidersCode = buildWithProvidersCode(providersToAdd);
|
|
162
|
+
const insertBefore = content.indexOf("const preview");
|
|
163
|
+
if (insertBefore !== -1) {
|
|
164
|
+
content = content.slice(0, insertBefore) + withProvidersCode + "\n\n" + content.slice(insertBefore);
|
|
164
165
|
if (content.includes("decorators:")) {
|
|
165
|
-
|
|
166
|
+
if (!content.includes("decorators: [withProviders")) {
|
|
167
|
+
content = content.replace(/decorators:\s*\[/, "decorators: [withProviders, ");
|
|
168
|
+
}
|
|
166
169
|
} else {
|
|
167
170
|
content = content.replace(/(const preview\s*[^=]*=\s*\{\s*)/, "$1\n decorators: [withProviders],\n ");
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
fs.writeFileSync(previewPath, content, "utf-8");
|
|
171
|
-
console.log("[VDS] Storybook preview:
|
|
174
|
+
console.log("[VDS] Storybook preview: " + uniqueProviders.map((p) => p.name).join(", "));
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
if (hooksWithoutProvider.size > 0) {
|