@dropi/ui 0.1.35 → 0.1.36

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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/scripts/setup.js +65 -44
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropi/ui",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Dropi Design System — Web Components for Angular, React and Vue",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -33,7 +33,8 @@
33
33
  "import": "./hydrate/index.mjs",
34
34
  "require": "./hydrate/index.js",
35
35
  "types": "./hydrate/index.d.ts"
36
- }
36
+ },
37
+ "./package.json": "./package.json"
37
38
  },
38
39
  "files": [
39
40
  "dist/",
package/scripts/setup.js CHANGED
@@ -368,60 +368,81 @@ dropi-icon:not(.hydrated) {
368
368
  // Resolver ruta real de @dropi/ui (compatible con npm, Yarn Berry, monorepos)
369
369
  let dropiUiRoot;
370
370
  try {
371
- // Intento 1: require.resolve desde projectRoot
372
- dropiUiRoot = path.dirname(require.resolve('@dropi/ui/package.json', { paths: [projectRoot] }));
373
- } catch (e1) {
374
- try {
375
- // Intento 2: ejecutar node en contexto del proyecto (útil en Yarn Berry PnP)
376
- const resolved = execSync(
377
- `node -e "console.log(require.resolve('@dropi/ui/package.json'))"`,
378
- { cwd: projectRoot, encoding: 'utf8' }
379
- ).trim();
380
- dropiUiRoot = path.dirname(resolved);
381
- } catch (e2) {
382
- // Intento 3: buscar en árbol de directorios (monorepos con hoisting)
383
- let dir = projectRoot;
384
- while (dir !== path.dirname(dir)) {
385
- const candidate = path.join(dir, 'node_modules', '@dropi', 'ui');
386
- if (fs.existsSync(path.join(candidate, 'package.json'))) {
387
- dropiUiRoot = candidate;
388
- break;
389
- }
390
- dir = path.dirname(dir);
371
+ // Intento 1: resolver desde la exportación principal y subir al root del paquete
372
+ // (evita ERR_PACKAGE_PATH_NOT_EXPORTED que ocurre al resolver './package.json')
373
+ const mainFile = require.resolve('@dropi/ui', { paths: [projectRoot] });
374
+ let dir = path.dirname(mainFile);
375
+ while (dir !== path.dirname(dir)) {
376
+ const pkgPath = path.join(dir, 'package.json');
377
+ if (fs.existsSync(pkgPath)) {
378
+ try {
379
+ if (JSON.parse(fs.readFileSync(pkgPath, 'utf8')).name === '@dropi/ui') {
380
+ dropiUiRoot = dir;
381
+ break;
382
+ }
383
+ } catch (_) {}
391
384
  }
392
- // Fallback convencional
393
- if (!dropiUiRoot) dropiUiRoot = path.join(projectRoot, 'node_modules', '@dropi', 'ui');
385
+ dir = path.dirname(dir);
386
+ }
387
+ } catch (e1) {}
388
+
389
+ if (!dropiUiRoot) {
390
+ // Intento 2: buscar en árbol de directorios (monorepos con hoisting)
391
+ let dir = projectRoot;
392
+ while (dir !== path.dirname(dir)) {
393
+ const candidate = path.join(dir, 'node_modules', '@dropi', 'ui');
394
+ if (fs.existsSync(path.join(candidate, 'package.json'))) {
395
+ dropiUiRoot = candidate;
396
+ break;
397
+ }
398
+ dir = path.dirname(dir);
394
399
  }
395
400
  }
396
401
 
402
+ // Fallback convencional
403
+ if (!dropiUiRoot) dropiUiRoot = path.join(projectRoot, 'node_modules', '@dropi', 'ui');
404
+
397
405
  const setupAsset = (srcRelativePath, destRelativePath) => {
398
406
  const src = path.join(dropiUiRoot, srcRelativePath);
399
407
  const dest = path.join(projectRoot, publicDir, destRelativePath);
400
408
  const destDir = path.dirname(dest);
401
409
 
402
- if (fs.existsSync(src)) {
403
- if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
404
- try {
405
- if (fs.existsSync(dest)) {
406
- if (fs.lstatSync(dest).isSymbolicLink() || fs.existsSync(dest)) fs.unlinkSync(dest);
407
- }
408
- fs.symlinkSync(src, dest, fs.lstatSync(src).isDirectory() ? 'dir' : 'file');
409
- log(`Assets configurados: ${destRelativePath} (Symlink ✅)`, 'ok');
410
- } catch (e) {
411
- // Fallback a copia recursiva
412
- try {
413
- if (fs.lstatSync(src).isDirectory()) {
414
- fs.cpSync ? fs.cpSync(src, dest, { recursive: true }) : execSync(`cp -R "${src}" "${dest}"`);
415
- } else {
416
- fs.copyFileSync(src, dest);
417
- }
418
- log(`Assets copiados: ${destRelativePath} (Copia ✅)`, 'ok');
419
- } catch (copyErr) {
420
- log(`Assets no encontrados: ${destRelativePath}. Cópialos manualmente desde node_modules/@dropi/ui/${srcRelativePath}`, 'warn');
421
- }
410
+ if (!fs.existsSync(src)) {
411
+ log(`Assets no encontrados: ${srcRelativePath}. Verifica que @dropi/ui esté instalado.`, 'warn');
412
+ return;
413
+ }
414
+
415
+ if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
416
+
417
+ // Limpiar dest con lstatSync — detecta symlinks rotos que existsSync ignora
418
+ try {
419
+ const stat = fs.lstatSync(dest);
420
+ if (stat.isDirectory() && !stat.isSymbolicLink()) {
421
+ fs.rmSync(dest, { recursive: true, force: true });
422
+ } else {
423
+ fs.unlinkSync(dest); // funciona para symlinks, broken symlinks y archivos
422
424
  }
423
- } else {
424
- log(`Assets no encontrados en node_modules: ${srcRelativePath}. Verifica que @dropi/ui esté instalado correctamente.`, 'warn');
425
+ } catch (_) {
426
+ // dest no existe, todo bien
427
+ }
428
+
429
+ // Intentar symlink primero
430
+ try {
431
+ fs.symlinkSync(src, dest, fs.lstatSync(src).isDirectory() ? 'dir' : 'file');
432
+ log(`Assets configurados: ${destRelativePath} (Symlink ✅)`, 'ok');
433
+ return;
434
+ } catch (_) {}
435
+
436
+ // Fallback: copia directa
437
+ try {
438
+ if (fs.lstatSync(src).isDirectory()) {
439
+ fs.cpSync ? fs.cpSync(src, dest, { recursive: true }) : execSync(`cp -R "${src}" "${dest}"`);
440
+ } else {
441
+ fs.copyFileSync(src, dest);
442
+ }
443
+ log(`Assets copiados: ${destRelativePath} (Copia ✅)`, 'ok');
444
+ } catch (copyErr) {
445
+ log(`Error al copiar ${destRelativePath}: ${copyErr.message}`, 'warn');
425
446
  }
426
447
  };
427
448