@sit-onyx/storybook-utils 1.0.1 → 1.0.2-dev-20251016092305
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 +3 -3
- package/src/preview.spec.ts +24 -0
- package/src/preview.ts +4 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/storybook-utils",
|
|
3
3
|
"description": "Storybook utilities for Vue",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2-dev-20251016092305",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"deepmerge-ts": "^7.1.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"storybook": "^9.1.
|
|
41
|
+
"storybook": "^9.1.10",
|
|
42
42
|
"vue": "3.5.22",
|
|
43
|
-
"vue-component-type-helpers": "^3.1.
|
|
43
|
+
"vue-component-type-helpers": "^3.1.1",
|
|
44
44
|
"@sit-onyx/icons": "^1.1.0",
|
|
45
45
|
"@sit-onyx/shared": "^0.1.0"
|
|
46
46
|
},
|
package/src/preview.spec.ts
CHANGED
|
@@ -30,4 +30,28 @@ import { flagDE } from "@sit-onyx/flags";
|
|
|
30
30
|
<OnyxComp>Test</OnyxComp>
|
|
31
31
|
</template>`);
|
|
32
32
|
});
|
|
33
|
+
|
|
34
|
+
test("should not add imports twice", async () => {
|
|
35
|
+
// ACT
|
|
36
|
+
let sourceCode = await sourceCodeTransformer(`<template>
|
|
37
|
+
<OnyxTest />
|
|
38
|
+
</template>`);
|
|
39
|
+
|
|
40
|
+
// ASSERT
|
|
41
|
+
const expectedCode = `<script lang="ts" setup>
|
|
42
|
+
import { OnyxTest } from "sit-onyx";
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<OnyxTest />
|
|
47
|
+
</template>`;
|
|
48
|
+
|
|
49
|
+
expect(sourceCode).toBe(expectedCode);
|
|
50
|
+
|
|
51
|
+
// ACT (call transformer twice)
|
|
52
|
+
sourceCode = await sourceCodeTransformer(sourceCode);
|
|
53
|
+
|
|
54
|
+
// ASSERT
|
|
55
|
+
expect(sourceCode).toBe(expectedCode);
|
|
56
|
+
});
|
|
33
57
|
});
|
package/src/preview.ts
CHANGED
|
@@ -195,13 +195,12 @@ export const sourceCodeTransformer = async (originalSourceCode: string): Promise
|
|
|
195
195
|
// generate the source code for the additional imports and add them to the top of the code snippet
|
|
196
196
|
if (additionalImports.size > 0) {
|
|
197
197
|
const additionalImportsCode = Array.from(additionalImports.entries()).reduce(
|
|
198
|
-
(
|
|
198
|
+
(importsCode, [packageName, imports]) => {
|
|
199
199
|
if (imports.size) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
200
|
+
const newImport = `import { ${Array.from(imports.values()).sort().join(", ")} } from "${packageName}";`;
|
|
201
|
+
if (!code.includes(newImport)) importsCode.push(newImport);
|
|
203
202
|
}
|
|
204
|
-
return
|
|
203
|
+
return importsCode;
|
|
205
204
|
},
|
|
206
205
|
[] as string[],
|
|
207
206
|
);
|