adminforth 1.1.104 → 1.1.105

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.
@@ -91,7 +91,7 @@ class CodeInjector {
91
91
  }
92
92
  prepareSources(_a) {
93
93
  return __awaiter(this, arguments, void 0, function* ({ filesUpdated, verbose = false }) {
94
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
94
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
95
95
  // check SPA_TMP_PATH exists and create if not
96
96
  try {
97
97
  yield fs.promises.access(CodeInjector.SPA_TMP_PATH, fs.constants.F_OK);
@@ -245,7 +245,7 @@ class CodeInjector {
245
245
  // icons are collectionName:iconName. Get list of all unique collection names:
246
246
  const collections = new Set(icons.map((icon) => icon.split(':')[0]));
247
247
  // package names @iconify-prerendered/vue-<collection name>
248
- const packageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
248
+ const iconPackageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
249
249
  // for each icon generate import statement
250
250
  const iconImports = uniqueIcons.map((icon) => {
251
251
  const [collection, iconName] = icon.split(':');
@@ -358,47 +358,67 @@ class CodeInjector {
358
358
  const spaPackageLock = JSON.parse(yield fs.promises.readFile(spaPackageLockPath, 'utf-8'));
359
359
  const spaLockHash = hashify(spaPackageLock);
360
360
  /* customPackageLock */
361
- const usersPackagePath = path.join('./package.json');
362
- const usersPackage = JSON.parse(yield fs.promises.readFile(usersPackagePath, 'utf-8'));
363
- const usersLockPath = path.join('./package-lock.json');
364
- const usersLock = JSON.parse(yield fs.promises.readFile(usersLockPath, 'utf-8'));
365
- const usersLockHash = hashify(usersLock);
366
- const packagesNamesHash = hashify(packageNames);
367
- const fullHash = `${spaLockHash}::${packagesNamesHash}::${usersLockHash}`;
368
- const hashPath = path.join(CodeInjector.SPA_TMP_PATH, 'node_modules', '.adminforth_hash');
369
- try {
370
- const existingHash = yield fs.promises.readFile(hashPath, 'utf-8');
371
- if (existingHash === fullHash) {
372
- console.log('Hashes match, skipping npm ci/install');
373
- return;
361
+ let usersLockHash = '';
362
+ let usersLock = null;
363
+ if ((_m = this.adminforth.config.customization) === null || _m === void 0 ? void 0 : _m.customComponentsDir) {
364
+ const usersPackagePath = path.join(this.adminforth.config.customization.customComponentsDir, 'package.json');
365
+ let usersPackage = null;
366
+ try {
367
+ usersPackage = JSON.parse(yield fs.promises.readFile(usersPackagePath, 'utf-8'));
374
368
  }
375
- else {
369
+ catch (e) {
370
+ // user package.json does not exist, user does not have custom components
371
+ }
372
+ if (usersPackage) {
373
+ const usersLockPath = path.join(this.adminforth.config.customization.customComponentsDir, 'package-lock.json');
374
+ try {
375
+ usersLock = JSON.parse(yield fs.promises.readFile(usersLockPath, 'utf-8'));
376
+ }
377
+ catch (e) {
378
+ throw new Error(`Custom package-lock.json does not exist in ${this.adminforth.config.customization.customComponentsDir}, but package.json does.
379
+ We can't determine version of packages without package-lock.json. Please run npm install in ${this.adminforth.config.customization.customComponentsDir}`);
380
+ }
381
+ usersLockHash = hashify(usersLock);
382
+ }
383
+ const iconPackagesNamesHash = hashify(iconPackageNames);
384
+ const fullHash = `${spaLockHash}::${iconPackagesNamesHash}::${usersLockHash}`;
385
+ const hashPath = path.join(CodeInjector.SPA_TMP_PATH, 'node_modules', '.adminforth_hash');
386
+ try {
387
+ const existingHash = yield fs.promises.readFile(hashPath, 'utf-8');
388
+ if (existingHash === fullHash) {
389
+ console.log('Hashes match, skipping npm ci/install');
390
+ return;
391
+ }
392
+ else {
393
+ if (verbose) {
394
+ console.log(`Hashes do not match: existing ${existingHash} new ${fullHash}, proceeding with npm ci/install`);
395
+ }
396
+ }
397
+ }
398
+ catch (e) {
399
+ // ignore
376
400
  if (verbose) {
377
- console.log(`Hashes do not match: existing ${existingHash} new ${fullHash}, proceeding with npm ci/install`);
401
+ console.log('Hash file does not exist, proceeding with npm ci/install');
378
402
  }
379
403
  }
380
- }
381
- catch (e) {
382
- // ignore
383
- if (verbose) {
384
- console.log('Hash file does not exist, proceeding with npm ci/install');
404
+ yield this.runNpmShell({ command: 'ci', verbose, cwd: CodeInjector.SPA_TMP_PATH });
405
+ let customPackgeNames = [];
406
+ if (usersPackage && usersLock) {
407
+ customPackgeNames = [
408
+ ...Object.keys(usersPackage.dependencies),
409
+ ...Object.keys(usersPackage.devDependencies || [])
410
+ ].reduce((acc, packageName) => {
411
+ const version = usersLock.packages[`node_modules/${packageName}`].version;
412
+ acc.push(`${packageName}@${version}`);
413
+ return acc;
414
+ }, []);
385
415
  }
416
+ if (iconPackageNames.length) {
417
+ const npmInstallCommand = `install ${[...iconPackageNames, ...customPackgeNames].join(' ')}`;
418
+ yield this.runNpmShell({ command: npmInstallCommand, cwd: CodeInjector.SPA_TMP_PATH });
419
+ }
420
+ yield fs.promises.writeFile(hashPath, fullHash);
386
421
  }
387
- yield this.runNpmShell({ command: 'ci', verbose, cwd: CodeInjector.SPA_TMP_PATH });
388
- // get packages with version from customPackage
389
- const IGNORE_PACKAGES = ['tsx', 'typescript', 'express', 'nodemon', 'adminforth'];
390
- const customPackgeNames = [...Object.keys(usersPackage.dependencies), ...Object.keys(usersPackage.devDependencies || [])]
391
- .filter((packageName) => !IGNORE_PACKAGES.includes(packageName))
392
- .reduce((acc, packageName) => {
393
- const version = usersLock.packages[`node_modules/${packageName}`].version;
394
- acc.push(`${packageName}@${version}`);
395
- return acc;
396
- }, []);
397
- if (packageNames.length) {
398
- const npmInstallCommand = `install ${[...packageNames, ...customPackgeNames].join(' ')}`;
399
- yield this.runNpmShell({ command: npmInstallCommand, cwd: CodeInjector.SPA_TMP_PATH });
400
- }
401
- yield fs.promises.writeFile(hashPath, fullHash);
402
422
  });
403
423
  }
404
424
  watchForReprepare(_a) {
@@ -271,7 +271,7 @@ class CodeInjector implements ICodeInjector {
271
271
  const collections = new Set(icons.map((icon) => icon.split(':')[0]));
272
272
 
273
273
  // package names @iconify-prerendered/vue-<collection name>
274
- const packageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
274
+ const iconPackageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
275
275
 
276
276
  // for each icon generate import statement
277
277
  const iconImports = uniqueIcons.map((icon) => {
@@ -411,16 +411,30 @@ class CodeInjector implements ICodeInjector {
411
411
  const spaLockHash = hashify(spaPackageLock);
412
412
 
413
413
  /* customPackageLock */
414
- const usersPackagePath = path.join('./package.json');
415
- const usersPackage = JSON.parse(await fs.promises.readFile(usersPackagePath, 'utf-8'));
416
-
417
- const usersLockPath = path.join('./package-lock.json');
418
- const usersLock = JSON.parse(await fs.promises.readFile(usersLockPath, 'utf-8'));
419
- const usersLockHash = hashify(usersLock);
414
+ let usersLockHash = '';
415
+ let usersLock = null;
416
+ if (this.adminforth.config.customization?.customComponentsDir) {
417
+ const usersPackagePath = path.join(this.adminforth.config.customization.customComponentsDir, 'package.json');
418
+ let usersPackage = null;
419
+ try {
420
+ usersPackage = JSON.parse(await fs.promises.readFile(usersPackagePath, 'utf-8'));
421
+ } catch (e) {
422
+ // user package.json does not exist, user does not have custom components
423
+ }
424
+ if (usersPackage) {
425
+ const usersLockPath = path.join(this.adminforth.config.customization.customComponentsDir, 'package-lock.json');
426
+ try {
427
+ usersLock = JSON.parse(await fs.promises.readFile(usersLockPath, 'utf-8'));
428
+ } catch (e) {
429
+ throw new Error(`Custom package-lock.json does not exist in ${this.adminforth.config.customization.customComponentsDir}, but package.json does.
430
+ We can't determine version of packages without package-lock.json. Please run npm install in ${this.adminforth.config.customization.customComponentsDir}`);
431
+ }
432
+ usersLockHash = hashify(usersLock);
433
+ }
420
434
 
421
- const packagesNamesHash = hashify(packageNames);
435
+ const iconPackagesNamesHash = hashify(iconPackageNames);
422
436
 
423
- const fullHash = `${spaLockHash}::${packagesNamesHash}::${usersLockHash}`;
437
+ const fullHash = `${spaLockHash}::${iconPackagesNamesHash}::${usersLockHash}`;
424
438
  const hashPath = path.join(CodeInjector.SPA_TMP_PATH, 'node_modules', '.adminforth_hash');
425
439
 
426
440
  try {
@@ -442,25 +456,29 @@ class CodeInjector implements ICodeInjector {
442
456
 
443
457
  await this.runNpmShell({command: 'ci', verbose, cwd: CodeInjector.SPA_TMP_PATH});
444
458
 
445
- // get packages with version from customPackage
446
- const IGNORE_PACKAGES = ['tsx', 'typescript', 'express', 'nodemon', 'adminforth'];
447
- const customPackgeNames = [...Object.keys(usersPackage.dependencies), ...Object.keys(usersPackage.devDependencies || [])]
448
- .filter((packageName) => !IGNORE_PACKAGES.includes(packageName))
449
- .reduce(
450
- (acc, packageName) => {
451
- const version = usersLock.packages[`node_modules/${packageName}`].version;
452
- acc.push(`${packageName}@${version}`);
453
- return acc;
454
- }, []);
455
-
456
- if (packageNames.length) {
457
- const npmInstallCommand = `install ${[...packageNames, ...customPackgeNames].join(' ')}`;
459
+ let customPackgeNames = [];
460
+ if (usersPackage && usersLock) {
461
+ customPackgeNames = [
462
+ ...Object.keys(usersPackage.dependencies),
463
+ ...Object.keys(usersPackage.devDependencies || [])
464
+ ].reduce(
465
+ (acc, packageName) => {
466
+ const version = usersLock.packages[`node_modules/${packageName}`].version;
467
+ acc.push(`${packageName}@${version}`);
468
+ return acc;
469
+ }, []
470
+ );
471
+ }
472
+
473
+ if (iconPackageNames.length) {
474
+ const npmInstallCommand = `install ${[...iconPackageNames, ...customPackgeNames].join(' ')}`;
458
475
  await this.runNpmShell({command: npmInstallCommand, cwd: CodeInjector.SPA_TMP_PATH});
459
476
  }
460
477
 
461
478
  await fs.promises.writeFile(hashPath, fullHash);
462
479
 
463
480
  }
481
+ }
464
482
 
465
483
  async watchForReprepare({ verbose }) {
466
484
  const spaPath = path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.1.104",
3
+ "version": "1.1.105",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",