@npm-questionpro/wick-ui-i18n 2.7.0 → 2.8.0

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": "@npm-questionpro/wick-ui-i18n",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "private": false,
5
5
  "license": "ISC",
6
6
  "description": "Auto-translation AST wrapper for Wick UI",
package/src/telemetry.js CHANGED
@@ -41,6 +41,26 @@ export class TelemetryCollector {
41
41
  }
42
42
  }
43
43
 
44
+ /**
45
+ * Finds the nearest ancestor `node_modules` directory starting at `dir`, walking
46
+ * up towards the filesystem root — same strategy Node's own `require` resolution
47
+ * uses. Needed because in a monorepo, Vite's resolved root is often a subpackage
48
+ * folder while `node_modules` is hoisted several levels above it.
49
+ *
50
+ * @param {string} dir
51
+ * @returns {string|null}
52
+ */
53
+ static findNodeModules(dir) {
54
+ let current = dir
55
+ while (true) {
56
+ const candidate = path.join(current, 'node_modules')
57
+ if (fs.existsSync(candidate)) return candidate
58
+ const parent = path.dirname(current)
59
+ if (parent === current) return null // reached filesystem root
60
+ current = parent
61
+ }
62
+ }
63
+
44
64
  /**
45
65
  * Scan the consumer's node_modules for all @npm-questionpro/wick-ui-* packages
46
66
  * and record their versions. Called once in configResolved when root is known.
@@ -48,13 +68,16 @@ export class TelemetryCollector {
48
68
  * @param {string} root - Vite project root
49
69
  */
50
70
  scanVersions(root) {
51
- const scopeDir = path.join(root, 'node_modules', '@npm-questionpro')
71
+ const nodeModules = TelemetryCollector.findNodeModules(root)
72
+ if (!nodeModules) return // no node_modules found anywhere up the tree — skip silently
73
+
74
+ const scopeDir = path.join(nodeModules, '@npm-questionpro')
52
75
  let entries
53
76
  try {
54
77
  entries = fs.readdirSync(scopeDir)
55
78
  } catch {
56
79
  // @npm-questionpro scope not present — skip silently
57
- return
80
+ entries = []
58
81
  }
59
82
  for (const name of entries) {
60
83
  if (!name.startsWith('wick-ui-')) continue
@@ -67,10 +90,10 @@ export class TelemetryCollector {
67
90
  }
68
91
  }
69
92
 
70
- // Also capture react and react-dom versions from the consumer's node_modules
93
+ // Also capture react and react-dom versions from the same node_modules
71
94
  for (const dep of ['react', 'react-dom']) {
72
95
  try {
73
- const pkg = JSON.parse(fs.readFileSync(path.join(root, 'node_modules', dep, 'package.json'), 'utf8'))
96
+ const pkg = JSON.parse(fs.readFileSync(path.join(nodeModules, dep, 'package.json'), 'utf8'))
74
97
  this.versions[dep] = pkg.version
75
98
  } catch {
76
99
  // not installed — skip
package/src/transform.js CHANGED
@@ -159,6 +159,10 @@ export function transformFile(code, id, processor, {telemetry} = {}) {
159
159
  let hasImport = false
160
160
  let needsUseWtImport = false
161
161
  let hasUseWtImport = false
162
+ // Local names of components actually imported from @npm-questionpro/* — telemetry only
163
+ // counts these, so a same-named Wu* component from an unrelated package (e.g. a legacy
164
+ // internal UI lib) never pollutes the @npm-questionpro/wick-ui-* usage stats.
165
+ const npmQuestionProImports = new Set()
162
166
 
163
167
  traverse(ast, {
164
168
  /**
@@ -179,6 +183,11 @@ export function transformFile(code, id, processor, {telemetry} = {}) {
179
183
  if (s.imported?.name === 'useWt') hasUseWtImport = true
180
184
  }
181
185
  }
186
+ if (path.node.source.value.startsWith('@npm-questionpro/')) {
187
+ for (const s of path.node.specifiers) {
188
+ npmQuestionProImports.add(s.local.name)
189
+ }
190
+ }
182
191
  },
183
192
 
184
193
  /**
@@ -296,6 +305,7 @@ export function transformFile(code, id, processor, {telemetry} = {}) {
296
305
  if (!telemetry) return
297
306
  const name = path.node.name.name
298
307
  if (typeof name !== 'string' || !name.startsWith('Wu')) return
308
+ if (!npmQuestionProImports.has(name)) return
299
309
  const props = path.node.attributes
300
310
  .filter(a => a.type === 'JSXAttribute' && typeof a.name?.name === 'string')
301
311
  .map(a => a.name.name)