@rivinia/toast 0.5.0 → 0.5.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivinia/toast",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Headless toast queue for Angular: signals, pause-on-hover timers, actions.",
5
5
  "keywords": [
6
6
  "angular",
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "license": "MIT",
13
13
  "peerDependencies": {
14
+ "@angular-devkit/schematics": "^22.0.0",
14
15
  "@angular/core": "^22.0.0"
15
16
  },
16
17
  "sideEffects": false,
@@ -39,7 +39,7 @@ function ngAdd(options) {
39
39
  parts.push(`maxVisible: ${options.maxVisible}`);
40
40
  const provideCall = `provideRiviniaToast(${parts.length > 0 ? `{ ${parts.join(', ')} }` : ''})`;
41
41
  let changed = false;
42
- if (!content.includes(PROVIDE_IMPORT)) {
42
+ if (!importsValue(content, '@rivinia/toast', 'provideRiviniaToast')) {
43
43
  content = insertAfterLastImport(content, PROVIDE_IMPORT);
44
44
  changed = true;
45
45
  }
@@ -104,3 +104,33 @@ function insertProvider(content, call) {
104
104
  const at = match.index + match[0].length;
105
105
  return `${content.slice(0, at)}\n ${call},${content.slice(at)}`;
106
106
  }
107
+ /**
108
+ * Whether the file already binds `symbol` as a VALUE imported from `module`.
109
+ *
110
+ * A plain `content.includes(IMPORT_LINE)` recognises only ONE shape of the
111
+ * import — `import { symbol } from 'module';`. An app that imports the
112
+ * symbol beside others (`import { other, symbol } from 'module';`) would be
113
+ * given a SECOND import of the same symbol, and its build would then fail
114
+ * with "Duplicate identifier" (TS2300).
115
+ *
116
+ * An aliased or a type-only import does not bind the name we need, so it
117
+ * does not count as present.
118
+ */
119
+ function importsValue(content, module, symbol) {
120
+ const pattern = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g;
121
+ for (const match of content.matchAll(pattern)) {
122
+ if (match[2] !== module)
123
+ continue;
124
+ if (/^\s*import\s+type\s/.test(match[0]))
125
+ continue; // a type-only import
126
+ for (const entry of match[1].split(',')) {
127
+ const raw = entry.trim();
128
+ if (!raw || /^type\s/.test(raw))
129
+ continue; // a type-only specifier
130
+ const local = raw.split(/\s+as\s+/).pop().trim();
131
+ if (local === symbol)
132
+ return true;
133
+ }
134
+ }
135
+ return false;
136
+ }