vibe-design-system 2.5.27 → 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,41 +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
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const blockMatch = content.match(/const withProviders\s*=[\s\S]+?;\s*\n/);
|
|
162
|
-
if (blockMatch) {
|
|
163
|
-
const block = blockMatch[0].trim();
|
|
164
|
-
content = content.replace(blockMatch[0], "").replace(/\n{3,}/g, "\n\n");
|
|
165
|
-
content = content.replace(/(\s*)(const preview\s*[^=]*=\s*\{)/, block + "\n\n$1$2");
|
|
166
|
-
}
|
|
167
|
-
} else if (!content.includes("withProviders")) {
|
|
168
|
-
if (!content.includes("import React")) {
|
|
169
|
-
const firstImport = content.match(/^import\s+/m);
|
|
170
|
-
const insertAt = firstImport ? content.indexOf(firstImport[0]) : 0;
|
|
171
|
-
content = content.slice(0, insertAt) + "import React from \"react\";\n" + content.slice(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);
|
|
172
158
|
}
|
|
173
|
-
|
|
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);
|
|
174
165
|
if (content.includes("decorators:")) {
|
|
175
|
-
|
|
166
|
+
if (!content.includes("decorators: [withProviders")) {
|
|
167
|
+
content = content.replace(/decorators:\s*\[/, "decorators: [withProviders, ");
|
|
168
|
+
}
|
|
176
169
|
} else {
|
|
177
170
|
content = content.replace(/(const preview\s*[^=]*=\s*\{\s*)/, "$1\n decorators: [withProviders],\n ");
|
|
178
171
|
}
|
|
179
172
|
}
|
|
180
173
|
fs.writeFileSync(previewPath, content, "utf-8");
|
|
181
|
-
console.log("[VDS] Storybook preview: " +
|
|
174
|
+
console.log("[VDS] Storybook preview: " + uniqueProviders.map((p) => p.name).join(", "));
|
|
182
175
|
}
|
|
183
176
|
|
|
184
177
|
if (hooksWithoutProvider.size > 0) {
|