Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #147 from agutoli/2.7.0/release
Browse files Browse the repository at this point in the history
2.7.0/release
  • Loading branch information
agutoli authored Oct 18, 2023
2 parents f83ed9d + 066ac43 commit dcb3832
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 34 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ functions:
| packagePath | `string` | package.json | `(DEPRECATED)`: Available for `<= 1.5.0`, for versions `>= 2.x` please use `compatibleRuntimes` |
| dependenciesPath | `string` | package.json | Note: `>= 2.x` versions. You can specify custom path for your package.json |
| compatibleRuntimes | `array` | `['nodejs']` | Possible values: nodejs, nodejs10.x, nodejs12.x |
| layerOptimization.cleanupPatterns | `array` | [check](https://github.com/agutoli/serverless-layers/blob/master/src/runtimes/nodejs.js) | The pattern of files to cleanup in the layer artifact before uploading it. |

----------------------

Expand All @@ -126,6 +127,7 @@ functions:
| packageManager | `string` | bundle | Possible values: bundle |
| dependenciesPath | `string` | Gemfile | Note: Available for `>= 2.x` versions. You can specify custom path for your requirements.txt |
| compatibleRuntimes | `array` | `['ruby']` | Possible values: ruby2.5, ruby2.7 |
| layerOptimization.cleanupPatterns | `array` | [check](https://github.com/agutoli/serverless-layers/blob/master/src/runtimes/ruby.js) | The pattern of files to cleanup in the layer artifact before uploading it. |

----------------------

Expand All @@ -140,7 +142,8 @@ functions:
| -------------- | --------- | ----------- | ----------- |
| packageManager | `string` | pip | Possible values: pip |
| dependenciesPath | `string` | requirements.txt | Note: Available for `>= 2.x` versions. You can specify custom path for your requirements.txt |
| compatibleRuntimes | `array` | `['python']` | Possible values: python2.7, python3.6, python3.7 and python3.8 |
| compatibleRuntimes | `array` | `['python']` | Possible values: python2.7, python3.x |
| layerOptimization.cleanupPatterns | `array` | [check](https://github.com/agutoli/serverless-layers/blob/master/src/runtimes/python.js) | The pattern of files to cleanup in the layer artifact before uploading it. |

----------------------

Expand All @@ -151,7 +154,7 @@ This plugin will setup follow options automatically if not specified at `serverl
| Option | Type | Default |
| -------------- | --------- | ----------- |
| package.individually | `bool` | false |
| package.exclude | `array` | `['node_modules/**']` |
| package.patterns | `array` | `['node_modules/**']` |
| package.excludeDevDependencies | `bool` | false |

## Mininal Policy permissions for CI/CD IAM users
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-layers",
"version": "2.6.1",
"version": "2.7.0",
"description": "",
"main": "lib/index.js",
"bugs": {
Expand Down
24 changes: 11 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,11 @@ class ServerlessLayers {
return false;
}

// by pass settings
if (!this.settings.localDir) {
return false;
}

const manifest = '__meta__/manifest-settings.json';
const currentSettings = JSON.stringify(this.settings);
const currentSettings = JSON.stringify({
...this.settings,
patterns: this.service.package.patterns
});

// settings checked
this.hasSettingsVerified = true;
Expand Down Expand Up @@ -305,7 +303,7 @@ class ServerlessLayers {
hasDepsChanges,
hasFoldersChanges,
hasSettingsChanges,
hasCustomHashChanged
hasCustomHashChanged,
].some(x => x === true);

// merge package default options
Expand Down Expand Up @@ -423,26 +421,26 @@ class ServerlessLayers {
}

mergePackageOptions() {
const { packageExclude, artifact } = this.settings;
const { packagePatterns, artifact } = this.settings;
const pkg = this.service.package;

const opts = {
individually: false,
excludeDevDependencies: false,
exclude: []
patterns: []
};

this.service.package = {...opts, ...pkg};

for (const excludeFile of packageExclude) {
const hasRule = (this.service.package.exclude || '').indexOf(excludeFile);
for (const excludeFile of packagePatterns) {
const hasRule = (this.service.package.patterns || '').indexOf(excludeFile);
if (hasRule === -1) {
this.service.package.exclude.push(excludeFile);
this.service.package.patterns.push(excludeFile);
}
}

if (artifact) {
this.service.package.exclude.push(artifact);
this.service.package.patterns.push(artifact);
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/package/Dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Dependencies extends AbstractService {
*
* Reference: https://www.serverless.com/framework/docs/providers/aws/guide/packaging
*/
for (let pattern of this.plugin.service.package.patterns) {
for (let pattern of this.plugin.settings.layerOptimization.cleanupPatterns) {
if (pattern.startsWith('!')) {
const resolvedFiles = await resolveFile(pattern.substr(1), {
cwd: this.layersPackageDir
Expand All @@ -65,7 +65,9 @@ class Dependencies extends AbstractService {
filesToExclude.forEach((filename) => {
// check if folder or files are being ignored, and shouldn't be removed.
const shouldBeIgnored = filesToIgnore.filter(x => x.startsWith(filename)).length > 0;

if (!shouldBeIgnored) {
this.plugin.warn(`[layerOptimization.cleanupPatterns] Ignored: ${filename}`);
fs.rmSync(path.join(this.layersPackageDir, filename), {force: true, recursive: true});
}
});
Expand Down Expand Up @@ -146,7 +148,16 @@ class Dependencies extends AbstractService {
}

// cleanup files
await this.excludePatternFiles();
try {
await this.excludePatternFiles();
} catch(err) {
if (!this.plugin.service.package.patterns) {
this.plugin.warn(`[warning] package.patterns option is not set. @see https://www.serverless.com/framework/docs/providers/aws/guide/packaging`);
} else {
console.error(err);
process.exit(1);
}
}
}
}

Expand Down
39 changes: 36 additions & 3 deletions src/runtimes/nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,42 @@ class NodeJSRuntime {
'yarn.lock',
'package-lock.json'
],
packageExclude: [
'node_modules/**',
]
packagePatterns: [
'!node_modules/**',
],
layerOptimization: {
cleanupPatterns: [
"node_modules/aws-sdk/**",
"node_modules/**/.github",
"node_modules/**/.git/*",
"node_modules/**/.lint",
"node_modules/**/Gruntfile.js",
"node_modules/**/.jshintrc",
"node_modules/**/.nycrc",
"node_modules/**/.nvmrc",
"node_modules/**/.editorconfig",
"node_modules/**/.npmignore",
"node_modules/**/bower.json",
"node_modules/**/.eslint*",
"node_modules/**/.gitignore",
"node_modules/**/README.*",
"node_modules/**/LICENSE",
"node_modules/**/LICENSE.md",
"node_modules/**/CHANGES",
"node_modules/**/HISTORY.md",
"node_modules/**/CHANGES.md",
"node_modules/**/CHANGELOG.md",
"node_modules/**/sponsors.md",
"node_modules/**/license.txt",
"node_modules/**/tsconfig.json",
"node_modules/**/*.test.js",
"node_modules/**/*.spec.js",
"node_modules/**/.travis.y*ml",
"node_modules/**/yarn.lock",
"node_modules/**/.package-lock.json",
"node_modules/**/*.md",
]
}
};

this.commands = {
Expand Down
16 changes: 11 additions & 5 deletions src/runtimes/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ class PythonRuntime {
compatibleRuntimes: [runtime],
compatibleArchitectures: parent.compatibleArchitectures,
copyBeforeInstall: [],
packageExclude: [
'package.json',
'package-lock.json',
'node_modules/**',
]
packagePatterns: [
'!package.json',
'!package-lock.json',
'!node_modules/**',
],
layerOptimization: {
cleanupPatterns: [
"node_modules/**/*.pyc",
"node_modules/**/*.md",
]
}
};

this.commands = {
Expand Down
20 changes: 13 additions & 7 deletions src/runtimes/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ class RubyRuntime {
copyAfterInstall: [
{ from: 'ruby', to: 'gems' }
],
packageExclude: [
'node_modules/**',
'package.json',
'package-lock.json',
'vendor/**',
'.bundle'
]
packagePatterns: [
'!node_modules/**',
'!package.json',
'!package-lock.json',
'!vendor/**',
'!.bundle'
],
layerOptimization: {
cleanupPatterns: [
"node_modules/**/*.pyc",
"node_modules/**/*.md",
]
}
};

this.commands = {
Expand Down
35 changes: 34 additions & 1 deletion tests/fixtures/nodejsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,44 @@ module.exports = {
packageManagerExtraArgs: '',
libraryFolder: 'node_modules',
dependenciesPath: './fixtures/package.json',
layerOptimization: {
cleanupPatterns: [
"node_modules/aws-sdk/**",
"node_modules/**/.github",
"node_modules/**/.git/*",
"node_modules/**/.lint",
"node_modules/**/Gruntfile.js",
"node_modules/**/.jshintrc",
"node_modules/**/.nycrc",
"node_modules/**/.nvmrc",
"node_modules/**/.editorconfig",
"node_modules/**/.npmignore",
"node_modules/**/bower.json",
"node_modules/**/.eslint*",
"node_modules/**/.gitignore",
"node_modules/**/README.*",
"node_modules/**/LICENSE",
"node_modules/**/LICENSE.md",
"node_modules/**/CHANGES",
"node_modules/**/HISTORY.md",
"node_modules/**/CHANGES.md",
"node_modules/**/CHANGELOG.md",
"node_modules/**/sponsors.md",
"node_modules/**/license.txt",
"node_modules/**/tsconfig.json",
"node_modules/**/*.test.js",
"node_modules/**/*.spec.js",
"node_modules/**/.travis.y*ml",
"node_modules/**/yarn.lock",
"node_modules/**/.package-lock.json",
"node_modules/**/*.md"
]
},
compatibleRuntimes: [ 'nodejs' ],
compatibleArchitectures: [
"x86_64",
"arm64"
],
copyBeforeInstall: [ '.npmrc', 'yarn.lock', 'package-lock.json' ],
packageExclude: [ 'node_modules/**' ]
packagePatterns: [ '!node_modules/**' ]
}

0 comments on commit dcb3832

Please sign in to comment.