Skip to content

Commit

Permalink
fix(core-path): fixed getCliNodeModulePath utility
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 14, 2022
1 parent a3b15e6 commit e1c571a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/utils/setConstants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import { getLocalOrGlobalConfig } from './config'
import { getNodeModulePath } from './utils'
import { getCliNodeModulePath } from './utils'
import { getAbsolutePath } from '@sasjs/utils'

export const contextName = 'sasjs cli compute context'
Expand Down Expand Up @@ -38,13 +38,7 @@ export const setConstants = async () => {
const buildDestinationJobsFolder = path.join(buildDestinationFolder, 'jobs')
const buildDestinationDbFolder = path.join(buildDestinationFolder, 'db')
const buildDestinationDocsFolder = path.join(buildDestinationFolder, 'docs')
const macroCorePath = await getNodeModulePath('@sasjs/core')

if (!macroCorePath) {
process.logger?.warn(
`Couldn't locate @sasjs/core path. Please run 'npm install @sasjs/core@latest' to install it locally or 'npm install -g @sasjs/core@latest' to install it globally.`
)
}
const macroCorePath = await getCliNodeModulePath('@sasjs/core')

const buildDestinationResultsFolder = getAbsolutePath(
buildResultsFolder,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/spec/setConstants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ const verifySasjsConstants = (appFolder?: string) => {
[prefixAppFolder, 'sasjsbuild', 'tests'].join(path.sep)
)

const corePath = path.join('cli', 'node_modules', '@sasjs', 'core')

if (appFolder) {
expect(sasjsConstants.macroCorePath).toEqual(
[prefixAppFolder, 'node_modules', '@sasjs', 'core'].join(path.sep)
path.join(prefixAppFolder, 'node_modules', '@sasjs', corePath)
)
} else {
expect(sasjsConstants.macroCorePath).toEqual(
expect.toEndWith(['cli', 'node_modules', '@sasjs', 'core'].join(path.sep))
)
expect(sasjsConstants.macroCorePath).toEqual(expect.toEndWith(corePath))
}
}
11 changes: 9 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,20 @@ export const isSASjsProject = async () => {
return false
}

export const getNodeModulePath = async (module: string): Promise<string> => {
const localPath = path.join(process.cwd(), 'node_modules', module)
export const getCliNodeModulePath = async (module: string): Promise<string> => {
const cliDepsPath = path.join('@sasjs', 'cli', 'node_modules')
const localPath = path.join(
process.cwd(),
'node_modules',
cliDepsPath,
module
)

if (await folderExists(localPath)) return localPath

const globalPath = path.join(
shelljs.exec(`npm root -g`, { silent: true }).stdout.replace(/\n/, ''),
cliDepsPath,
module
)

Expand Down

0 comments on commit e1c571a

Please sign in to comment.