@sit-onyx/storybook-utils 1.0.1-dev-20250930120837 → 1.0.2-dev-20251016073921

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sit-onyx/storybook-utils",
3
3
  "description": "Storybook utilities for Vue",
4
- "version": "1.0.1-dev-20250930120837",
4
+ "version": "1.0.2-dev-20251016073921",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
@@ -32,16 +32,16 @@
32
32
  "storybook": ">= 9.0.0",
33
33
  "vue-component-type-helpers": ">= 2",
34
34
  "@sit-onyx/flags": "^1.0.0",
35
- "@sit-onyx/icons": "^1.1.0-dev-20250930120837"
35
+ "@sit-onyx/icons": "^1.1.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "deepmerge-ts": "^7.1.5"
39
39
  },
40
40
  "devDependencies": {
41
- "storybook": "^9.1.8",
41
+ "storybook": "^9.1.10",
42
42
  "vue": "3.5.22",
43
- "vue-component-type-helpers": "^3.1.0",
44
- "@sit-onyx/icons": "^1.1.0-dev-20250930120837",
43
+ "vue-component-type-helpers": "^3.1.1",
44
+ "@sit-onyx/icons": "^1.1.0",
45
45
  "@sit-onyx/shared": "^0.1.0"
46
46
  },
47
47
  "scripts": {
@@ -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
- (code, [packageName, imports]) => {
198
+ (importsCode, [packageName, imports]) => {
199
199
  if (imports.size) {
200
- code.push(
201
- `import { ${Array.from(imports.values()).sort().join(", ")} } from "${packageName}";`,
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 code;
203
+ return importsCode;
205
204
  },
206
205
  [] as string[],
207
206
  );