scripts/verify-pkg-main.js
function verifyPath(packageJson, jsonPath, packagePropertyKey) {
  const isAtRoot = packagePropertyKey === 'module';
  const packageJsonPropPath = path.join(path.dirname(jsonPath), packageJson[packagePropertyKey]);
  let isInvalid = false;
  if (!isAtRoot && packageJsonPropPath.indexOf('dist') === -1) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property does not reference a file under dist`);
  } else if (isAtRoot && packageJsonPropPath.indexOf('dist') !== -1) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property should not reference a file under dist`);
  }
  if (!fs.existsSync(packageJsonPropPath)) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property points to nonexistent ${packageJsonPropPath}`);
  }

  if (isInvalid) {
    // Multiple checks could have failed, but only increment the counter once for one package.

    switch (packagePropertyKey) {
    case 'main':
      invalidMains++;
      break;
    case 'module':
      invalidModules++;
      break;
    case 'types':
      invalidTypes++;
      break;
    }
  }
}
function verifyPath(packageJson, jsonPath, packagePropertyKey) {
  const isAtRoot = packagePropertyKey === 'module';
  const packageJsonPropPath = path.join(path.dirname(jsonPath), packageJson[packagePropertyKey]);
  let isInvalid = false;
  if (!isAtRoot && packageJsonPropPath.indexOf('dist') === -1) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property does not reference a file under dist`);
  } else if (isAtRoot && packageJsonPropPath.indexOf('dist') !== -1) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property should not reference a file under dist`);
  }
  if (!fs.existsSync(packageJsonPropPath)) {
    isInvalid = true;
    logError(`${jsonPath} ${packagePropertyKey} property points to nonexistent ${packageJsonPropPath}`);
  }

  if (isInvalid) {
    // Multiple checks could have failed, but only increment the counter once for one package.

    switch (packagePropertyKey) {
    case 'main':
      invalidMains++;
      break;
    case 'module':
      invalidModules++;
      break;
    case 'types':
      invalidTypes++;
      break;
    }
  }
}
function verifyPath ( packageJson , jsonPath , packagePropertyKey ) { const isAtRoot = packagePropertyKey === 'module' ; const packageJsonPropPath = path . join ( path . dirname ( jsonPath ) , packageJson [ packagePropertyKey ] ) ; let isInvalid = false ; if ( ! isAtRoot && packageJsonPropPath . indexOf ( 'dist' ) === - 1 ) { isInvalid = true ; logError ( ` ${ jsonPath } ${ packagePropertyKey } ` ) ; } else if ( isAtRoot && packageJsonPropPath . indexOf ( 'dist' ) !== - 1 ) { isInvalid = true ; logError ( ` ${ jsonPath } ${ packagePropertyKey } ` ) ; } if ( ! fs . existsSync ( packageJsonPropPath ) ) { isInvalid = true ; logError ( ` ${ jsonPath } ${ packagePropertyKey } ${ packageJsonPropPath } ` ) ; } if ( isInvalid ) { // Multiple checks could have failed, but only increment the counter once for one package. switch ( packagePropertyKey ) { case 'main' : invalidMains ++ ; break ; case 'module' : invalidModules ++ ; break ; case 'types' : invalidTypes ++ ; break ; } } }
Verifies that a file exists at the `packagePropertyKey`. If it does not
this function will log an error to the console.
@param {object} packageJson package.json in JSON format
@param {string} jsonPath filepath (relative to the root directory) to a component's package.json
@param {string} packagePropertyKey property key of package.json
Verifies that a file exists at the packagePropertyKey . If it does not this function will log an error to the console .