Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Use the path provided by serverless as the base
Browse files Browse the repository at this point in the history
  • Loading branch information
warrickhill committed Aug 10, 2021
1 parent 6df1d65 commit c2c4402
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path'
import { statSync, realpathSync } from 'fs'
import { statSync } from 'fs'
import set from 'lodash.set'
import difference from 'lodash.difference'
import merge from './merge'
Expand All @@ -9,7 +9,6 @@ const SERVERLESS = 'serverless'
const DIRNAME = 'dirname'
const JS_EXTNAME = '.js'
const CONFIG_EXTNAMES = new Set(['.yml', '.yaml', JS_EXTNAME])
const REALPATH = realpathSync('.')

interface ImportedConfig {
custom?: {
Expand Down Expand Up @@ -39,7 +38,7 @@ class ImportConfigPlugin {
this.serverless = serverless
this.originalPlugins = this.serverless.service.plugins?.slice() ?? []

this.importConfigs(this.serverless.service, { basedir: REALPATH })
this.importConfigs(this.serverless.service, { basedir: this.serverless.serviceDir })
this.loadImportedPlugins()
}

Expand Down Expand Up @@ -99,12 +98,12 @@ class ImportConfigPlugin {
}

private prepareImportedConfig(options: { importPath: string, config: ImportedConfig }) {
const { variables } = this.serverless
const { variables, serviceDir } = this.serverless
const { importPath, config } = options

// make all function handlers relative to the imported config file
const { functions } = config
const importDir = path.relative(REALPATH, path.dirname(importPath))
const importDir = path.relative(serviceDir, path.dirname(importPath))
const toPosixPath = (location: string) => location.split(path.sep).join(path.posix.sep);
if (functions != null) {
Object.values(functions).forEach(func => {
Expand Down
2 changes: 2 additions & 0 deletions src/serverless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ declare namespace Serverless {
}
}

serviceDir: string

utils: {
readFileSync: (path: string) => object
}
Expand Down

0 comments on commit c2c4402

Please sign in to comment.