Skip to content

Commit

Permalink
refactor(CLI): Convert isLocallyInstalled to export result directly
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jan 27, 2022
1 parent 3dc8395 commit ad0bbb0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/cli/handle-error.js
Expand Up @@ -14,7 +14,7 @@ const { logWarning } = require('../classes/Error');
const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
const tokenizeException = require('../utils/tokenize-exception');
const logDeprecation = require('../utils/logDeprecation');
const resolveIsLocallyInstalled = require('./is-locally-installed');
const isThisLocallyInstalled = require('./is-locally-installed');
const isTelemetryDisabled = require('../utils/telemetry/areDisabled');
const { storeLocally: storeTelemetryLocally, send: sendTelemetry } = require('../utils/telemetry');
const generateTelemetryPayload = require('../utils/telemetry/generatePayload');
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = async (exception, options = {}) => {

// If provided serverless instance is a local fallback, and we're not in context of it
// Pass error handling to this local fallback implementation
if (isInvokedByGlobalInstallation && !resolveIsLocallyInstalled()) {
if (isInvokedByGlobalInstallation && !isThisLocallyInstalled) {
const localErrorHandlerData = (() => {
try {
return {
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports = async (exception, options = {}) => {
const installationModePostfix = (() => {
if (isStandaloneExecutable) return ' (standalone)';
if (isLocallyInstalled != null) return isLocallyInstalled ? ' (local)' : '';
return resolveIsLocallyInstalled() ? ' (local)' : '';
return isThisLocallyInstalled ? ' (local)' : '';
})();

const detailsTextTokens = [
Expand Down
7 changes: 1 addition & 6 deletions lib/cli/is-locally-installed.js
Expand Up @@ -3,9 +3,4 @@
const path = require('path');
const localServerlessPath = require('./local-serverless-path');

const serverlessPath = path.resolve(__dirname, '../..');

// This method should be kept as sync. The reason for it is the fact that
// telemetry generation and persistence needs to be run in sync manner
// and it depends on this function, either directly or indirectly.
module.exports = () => serverlessPath === localServerlessPath;
module.exports = localServerlessPath === path.resolve(__dirname, '../../');
11 changes: 6 additions & 5 deletions lib/cli/local-serverless-path.js
@@ -1,11 +1,12 @@
'use strict';

// This module should be dependencies free (as it's used at local fallback triage) and
// kept async (as telemetry payload generation depends on it)
try {
const path = require('path');
const { createRequire } = require('module');
// This module should be dependencies free (as it's used at local fallback triage)
// and kept async (as telemetry payload generation depends on it)

const path = require('path');
const { createRequire } = require('module');

try {
module.exports = path.resolve(
path.dirname(
createRequire(path.resolve(process.cwd(), 'require-resolver')).resolve('serverless')
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/telemetry/generatePayload.js
Expand Up @@ -12,7 +12,7 @@ const { getConfigurationValidationResult } = require('../../classes/ConfigSchema
const { triggeredDeprecations } = require('../logDeprecation');
const isNpmGlobal = require('../npmPackage/isGlobal');
const localServerlessPath = require('../../cli/local-serverless-path');
const resolveIsLocallyInstalled = require('../../cli/is-locally-installed');
const isThisLocallyInstalled = require('../../cli/is-locally-installed');
const getRequire = require('../../utils/get-require');
const ci = require('ci-info');
const AWS = require('aws-sdk');
Expand Down Expand Up @@ -187,11 +187,11 @@ module.exports = ({
return serverless.isLocallyInstalled;
}

return resolveIsLocallyInstalled();
return isThisLocallyInstalled;
})();

const usedVersions = (() => {
if (!isLocallyInstalled || resolveIsLocallyInstalled()) {
if (!isLocallyInstalled || isThisLocallyInstalled) {
return {
'serverless': require('../../../package').version,
'@serverless/dashboard-plugin': require('@serverless/dashboard-plugin/package').version,
Expand Down

0 comments on commit ad0bbb0

Please sign in to comment.