From 5a764373c49d5fb313f50218ab8166f1638c2c32 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 10 Jan 2022 10:48:23 +0100 Subject: [PATCH] feat(Variables): Resign from `projectDir` concept --- docs/providers/aws/guide/serverless.yml.md | 2 -- docs/providers/aws/guide/variables.md | 2 -- lib/configuration/variables/sources/file.js | 11 ----------- .../programmatic/multiService/serviceA/serverless.yml | 2 -- .../lib/configuration/variables/sources/file.test.js | 7 +------ 5 files changed, 1 insertion(+), 23 deletions(-) diff --git a/docs/providers/aws/guide/serverless.yml.md b/docs/providers/aws/guide/serverless.yml.md index 82064b7fe68..2d2428c0b71 100644 --- a/docs/providers/aws/guide/serverless.yml.md +++ b/docs/providers/aws/guide/serverless.yml.md @@ -21,8 +21,6 @@ Here is a list of all available properties in `serverless.yml` when the provider service: myService -projectDir: ./ # Boundary of a project in which service is configured. Influences file resolution - frameworkVersion: '2' configValidationMode: warn # Modes for config validation. `error` throws an exception, `warn` logs error to console, `off` disables validation at all. The default is warn. enableLocalInstallationFallback: false # If set to 'true', guarantees that it's a locally (for service, in its node_modules) installed framework which processes the command diff --git a/docs/providers/aws/guide/variables.md b/docs/providers/aws/guide/variables.md index afe08277e7a..42cdac9385a 100644 --- a/docs/providers/aws/guide/variables.md +++ b/docs/providers/aws/guide/variables.md @@ -411,8 +411,6 @@ custom: You can reference properties in other YAML or JSON files. To reference properties in other YAML files use the `${file(./myFile.yml):someProperty}` syntax in your `serverless.yml` configuration file. -Files need to be referenced by relative paths, which should not reach out beyond project directory (by default service directory). If you work with multi-service project, you can change project directory boundary with `projectDir` setting (e.g. set `projectDir: ../` if you're service is nested in top level _service-x_ directory) - To reference properties in other JSON files use the `${file(./myFile.json):someProperty}` syntax. It is important that the file you are referencing has the correct suffix, or file extension, for its file type (`.yml` for YAML or `.json` for JSON) in order for it to be interpreted correctly. Here's an example: diff --git a/lib/configuration/variables/sources/file.js b/lib/configuration/variables/sources/file.js index acadebcb0d8..ed0c285cda6 100644 --- a/lib/configuration/variables/sources/file.js +++ b/lib/configuration/variables/sources/file.js @@ -44,17 +44,6 @@ module.exports = { errorCode: 'INVALID_FILE_SOURCE_PATH_ARGUMENT', }) ); - const projectDir = path.resolve( - serviceDir, - (await resolveConfigurationProperty(['projectDir'])) || '.' - ); - if (!filePath.startsWith(`${projectDir}${path.sep}`)) { - throw new ServerlessError( - 'Cannot load file from outside of a project directory ' + - '(configure "projectDir" to extend project boundary)', - 'FILE_SOURCE_PATH_OUTSIDE_OF_PROJECT' - ); - } if (address != null) { address = ensureString(address, { Error: ServerlessError, diff --git a/test/fixtures/programmatic/multiService/serviceA/serverless.yml b/test/fixtures/programmatic/multiService/serviceA/serverless.yml index 40b0ffaf722..41d4892a2aa 100644 --- a/test/fixtures/programmatic/multiService/serviceA/serverless.yml +++ b/test/fixtures/programmatic/multiService/serviceA/serverless.yml @@ -3,8 +3,6 @@ service: service configValidationMode: error frameworkVersion: '*' -projectDir: ../ - provider: name: aws runtime: nodejs12.x diff --git a/test/unit/lib/configuration/variables/sources/file.test.js b/test/unit/lib/configuration/variables/sources/file.test.js index cc2828b1eee..fc5789c6a88 100644 --- a/test/unit/lib/configuration/variables/sources/file.test.js +++ b/test/unit/lib/configuration/variables/sources/file.test.js @@ -49,7 +49,6 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { notFile: '${file(dir.yaml)}', noParams: '${file:}', noParams2: '${file():}', - external: '${file(../file.test.js)}', invalidYaml: '${file(invalid.yml)}', invalidJson: '${file(invalid.json)}', invalidJs: '${file(invalid.js)}', @@ -178,9 +177,6 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { expect(variablesMeta.get('noParams2').error.code).to.equal('VARIABLE_RESOLUTION_ERROR'); }); - it('should report with an error attempt to access external path', () => - expect(variablesMeta.get('external').error.code).to.equal('VARIABLE_RESOLUTION_ERROR')); - it('should report with an error an invalid YAML file', () => expect(variablesMeta.get('invalidYaml').error.code).to.equal('VARIABLE_RESOLUTION_ERROR')); @@ -222,9 +218,8 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { ); }); - it('should support "projectDir"', async () => { + it('should support reaching out beyond service directory', async () => { configuration = { - projectDir: '..', yml: '${file(../file.yml)}', }; variablesMeta = resolveMeta(configuration);