diff --git a/.github/dependabot.yml b/.github/dependabot.yml index aeb65346..ac29398e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,4 +9,4 @@ updates: ignore: - dependency-name: eslint versions: - - "> 5.16.0" + - "> 7.22.0" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 285917dd..1e6b9ee8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,19 +4,14 @@ on: [push, pull_request] jobs: build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - node-version: [12] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Node ${{ matrix.node-version }} uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 14 - name: Install deps run: npm install diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index baf74a56..6a1e7d26 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,11 +6,13 @@ jobs: publish-npm: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v2 with: - version: 12 + version: 14 registry-url: https://registry.npmjs.org/ + - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77b64aa6..aa94f4b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,8 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - python-version: [3.6, 2.7] - node-version: [12] + python-version: [2.7, 3.6] steps: - uses: actions/checkout@v2 @@ -19,10 +18,10 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Set up Node ${{ matrix.node-version }} + - name: Set up Node uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 14 - name: Check python version run: | diff --git a/.gitignore b/.gitignore index 85e60616..db119782 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ __pycache__ #NODE STUFF package-lock.json +yarn.lock diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index f9e0b286..00000000 --- a/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -nodejs 6.16.0 -python 3.6.8 2.7.15 diff --git a/lib/clean.js b/lib/clean.js index 119ab586..e0bff238 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -14,7 +14,7 @@ function cleanup() { const artifacts = ['.requirements']; if (this.options.zip) { if (this.serverless.service.package.individually) { - this.targetFuncs.forEach(f => { + this.targetFuncs.forEach((f) => { artifacts.push(path.join(f.module, '.requirements.zip')); artifacts.push(path.join(f.module, 'unzip_requirements.py')); }); @@ -25,7 +25,7 @@ function cleanup() { } return BbPromise.all( - artifacts.map(artifact => + artifacts.map((artifact) => fse.removeAsync(path.join(this.servicePath, artifact)) ) ); @@ -47,7 +47,7 @@ function cleanupCache() { const promises = []; glob .sync([path.join(cacheLocation, '*slspyc/')], { mark: true, dot: false }) - .forEach(file => { + .forEach((file) => { promises.push(fse.removeAsync(file)); }); return BbPromise.all(promises); diff --git a/lib/docker.js b/lib/docker.js index 1132f1de..328e3088 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -81,7 +81,7 @@ function tryBindPath(serverless, bindPath, testFile) { `${bindPath}:/test`, 'alpine', 'ls', - `/test/${testFile}` + `/test/${testFile}`, ]; try { if (debug) serverless.cli.log(`Trying bindPath ${bindPath} (${options})`); @@ -167,7 +167,7 @@ function getDockerUid(bindPath) { 'stat', '-c', '%u', - '/bin/sh' + '/bin/sh', ]; const ps = dockerCommand(options); return ps.stdout.trim(); diff --git a/lib/inject.js b/lib/inject.js index 876e1b75..3cad758d 100644 --- a/lib/inject.js +++ b/lib/inject.js @@ -21,15 +21,15 @@ function injectRequirements(requirementsPath, packagePath, options) { return fse .readFileAsync(packagePath) - .then(buffer => JSZip.loadAsync(buffer)) - .then(zip => + .then((buffer) => JSZip.loadAsync(buffer)) + .then((zip) => BbPromise.resolve( glob.sync([path.join(requirementsPath, '**')], { mark: true, - dot: true + dot: true, }) ) - .map(file => [file, path.relative(requirementsPath, file)]) + .map((file) => [file, path.relative(requirementsPath, file)]) .filter( ([file, relativeFile]) => !file.endsWith('/') && @@ -42,7 +42,7 @@ function injectRequirements(requirementsPath, packagePath, options) { .mapSeries(([file, relativeFile, fileStat]) => zipFile(zip, relativeFile, fse.readFileAsync(file), { unixPermissions: fileStat.mode, - createFolders: false + createFolders: false, }) ) .then(() => writeZip(zip, packagePath)) @@ -61,16 +61,16 @@ function moveModuleUp(source, target, module) { return fse .readFileAsync(source) - .then(buffer => JSZip.loadAsync(buffer)) - .then(sourceZip => + .then((buffer) => JSZip.loadAsync(buffer)) + .then((sourceZip) => sourceZip.filter( - file => + (file) => file.startsWith(module + '/') || file.startsWith('serverless_sdk/') || file.match(/^s_.*\.py/) !== null ) ) - .map(srcZipObj => + .map((srcZipObj) => zipFile( targetZip, srcZipObj.name.startsWith(module + '/') @@ -96,18 +96,18 @@ function injectAllRequirements(funcArtifact) { if (this.serverless.service.package.individually) { return BbPromise.resolve(this.targetFuncs) - .filter(func => + .filter((func) => (func.runtime || this.serverless.service.provider.runtime).match( /^python.*/ ) ) - .map(func => { + .map((func) => { if (!get(func, 'module')) { set(func, ['module'], '.'); } return func; }) - .map(func => { + .map((func) => { if (func.module !== '.') { const artifact = func.package ? func.package.artifact : funcArtifact; const newArtifact = path.join( @@ -122,7 +122,7 @@ function injectAllRequirements(funcArtifact) { return func; } }) - .map(func => { + .map((func) => { return this.options.zip ? func : injectRequirements( diff --git a/lib/layer.js b/lib/layer.js index f512ded1..12d338ec 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -36,7 +36,7 @@ function createLayers() { }-${this.serverless.providers.aws.getStage()}-python-requirements`, description: 'Python requirements generated by serverless-python-requirements.', - compatibleRuntimes: [this.serverless.service.provider.runtime] + compatibleRuntimes: [this.serverless.service.provider.runtime], }, this.options.layer ); @@ -55,11 +55,9 @@ function layerRequirements() { this.serverless.cli.log('Packaging Python Requirements Lambda Layer...'); - return BbPromise.bind(this) - .then(zipRequirements) - .then(createLayers); + return BbPromise.bind(this).then(zipRequirements).then(createLayers); } module.exports = { - layerRequirements + layerRequirements, }; diff --git a/lib/pip.js b/lib/pip.js index 32cb9a83..244010c8 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -12,7 +12,7 @@ const { checkForAndDeleteMaxCacheVersions, sha256Path, getRequirementsWorkingPath, - getUserCachePath + getUserCachePath, } = require('./shared'); /** @@ -22,7 +22,7 @@ const { * @return {string[][]} a list of valid commands. */ function filterCommands(commands) { - return commands.filter(cmd => Boolean(cmd) && cmd.length > 0); + return commands.filter((cmd) => Boolean(cmd) && cmd.length > 0); } /** @@ -129,7 +129,7 @@ function installRequirements(targetFolder, serverless, options) { Array.isArray(options.pipCmdExtraArgs) && options.pipCmdExtraArgs.length > 0 ) { - options.pipCmdExtraArgs.forEach(cmd => { + options.pipCmdExtraArgs.forEach((cmd) => { const parts = cmd.split(/\s+/, 2); pipCmd.push(...parts); }); @@ -140,9 +140,11 @@ function installRequirements(targetFolder, serverless, options) { // Check if we're using the legacy --cache-dir command... if (options.pipCmdExtraArgs.indexOf('--cache-dir') > -1) { if (options.dockerizePip) { - throw 'Error: You can not use --cache-dir with Docker any more, please\n' + + throw ( + 'Error: You can not use --cache-dir with Docker any more, please\n' + ' use the new option useDownloadCache instead. Please see:\n' + - ' https://github.com/UnitedIncome/serverless-python-requirements#caching'; + ' https://github.com/UnitedIncome/serverless-python-requirements#caching' + ); } else { serverless.cli.log('=================================================='); serverless.cli.log( @@ -239,7 +241,7 @@ function installRequirements(targetFolder, serverless, options) { if (options.dockerEnv) { // Add environment variables to docker run cmd - options.dockerEnv.forEach(function(item) { + options.dockerEnv.forEach(function (item) { dockerCmd.push('-e', item); }); } @@ -256,7 +258,7 @@ function installRequirements(targetFolder, serverless, options) { 'chown', '-R', `${process.getuid()}:${process.getgid()}`, - '/var/task' + '/var/task', ]); } else { // Use same user so --cache-dir works @@ -274,7 +276,7 @@ function installRequirements(targetFolder, serverless, options) { 'chown', '-R', `${process.getuid()}:${process.getgid()}`, - dockerDownloadCacheDir + dockerDownloadCacheDir, ]); } } @@ -384,7 +386,7 @@ function filterRequirementsFile(source, target, options, serverless) { const noDeploy = new Set(options.noDeploy || []); const requirements = getRequirements(source); var prepend = []; - const filteredRequirements = requirements.filter(req => { + const filteredRequirements = requirements.filter((req) => { req = req.trim(); if (req.startsWith('#')) { // Skip comments @@ -440,7 +442,7 @@ function copyVendors(vendorFolder, targetFolder, serverless) { `Copying vendor libraries from ${vendorFolder} to ${targetFolder}...` ); - fse.readdirSync(vendorFolder).map(file => { + fse.readdirSync(vendorFolder).map((file) => { let source = path.join(vendorFolder, file); let dest = path.join(targetFolder, file); if (fse.existsSync(dest)) { @@ -603,12 +605,12 @@ function installAllRequirements() { if (this.serverless.service.package.individually) { let doneModules = []; this.targetFuncs - .filter(func => + .filter((func) => (func.runtime || this.serverless.service.provider.runtime).match( /^python.*/ ) ) - .map(f => { + .map((f) => { if (!get(f, 'module')) { set(f, ['module'], '.'); } diff --git a/lib/pipenv.js b/lib/pipenv.js index 6718844c..063fb5d8 100644 --- a/lib/pipenv.js +++ b/lib/pipenv.js @@ -20,7 +20,7 @@ function pipfileToRequirements() { 'pipenv', ['lock', '--requirements', '--keep-outdated'], { - cwd: this.servicePath + cwd: this.servicePath, } ); if (res.error) { diff --git a/lib/poetry.js b/lib/poetry.js index 984baf52..c9062df2 100644 --- a/lib/poetry.js +++ b/lib/poetry.js @@ -23,10 +23,10 @@ function pyprojectTomlToRequirements() { 'requirements.txt', '-o', 'requirements.txt', - '--with-credentials' + '--with-credentials', ], { - cwd: this.servicePath + cwd: this.servicePath, } ); if (res.error) { @@ -46,7 +46,7 @@ function pyprojectTomlToRequirements() { const requirementsContents = res.stdout.toString().trim() || // As of poetry 1.0.0b1, requirements.txt is printed to standard output when the -o option is not specified. fse.readFileSync(sourceRequirements, { - encoding: 'utf-8' + encoding: 'utf-8', }); if (requirementsContents.match(editableFlag)) { diff --git a/lib/shared.js b/lib/shared.js index 34f61eb2..79b60cef 100644 --- a/lib/shared.js +++ b/lib/shared.js @@ -27,7 +27,7 @@ function checkForAndDeleteMaxCacheVersions(options, serverless) { // Check if we have too many if (files.length >= options.staticCacheMaxVersions) { // Sort by modified time - files.sort(function(a, b) { + files.sort(function (a, b) { return ( fse.statSync(a).mtime.getTime() - fse.statSync(b).mtime.getTime() ); @@ -90,7 +90,7 @@ function getUserCachePath(options) { // Otherwise, find/use the python-ey appdirs cache location const dirs = new Appdir({ appName: 'serverless-python-requirements', - appAuthor: 'UnitedIncome' + appAuthor: 'UnitedIncome', }); return dirs.userCache(); } @@ -108,5 +108,5 @@ module.exports = { checkForAndDeleteMaxCacheVersions, getRequirementsWorkingPath, getUserCachePath, - sha256Path + sha256Path, }; diff --git a/lib/slim.js b/lib/slim.js index ae9155fb..8ead7fcc 100644 --- a/lib/slim.js +++ b/lib/slim.js @@ -2,7 +2,7 @@ const isWsl = require('is-wsl'); const glob = require('glob-all'); const fse = require('fs-extra'); -const getStripMode = options => { +const getStripMode = (options) => { if ( options.strip === false || options.strip === 'false' || @@ -30,7 +30,7 @@ const getStripCommand = (options, folderPath) => [ '-exec', 'strip', '{}', - ';' + ';', ]; const deleteFiles = (options, folderPath) => { @@ -55,5 +55,5 @@ const deleteFiles = (options, folderPath) => { module.exports = { getStripMode, getStripCommand, - deleteFiles + deleteFiles, }; diff --git a/lib/zip.js b/lib/zip.js index 1139d0d9..9076fb81 100644 --- a/lib/zip.js +++ b/lib/zip.js @@ -17,7 +17,7 @@ function addVendorHelper() { if (this.options.zip) { if (this.serverless.service.package.individually) { return BbPromise.resolve(this.targetFuncs) - .map(f => { + .map((f) => { if (!get(f, 'package.include')) { set(f, ['package', 'include'], []); } @@ -27,8 +27,8 @@ function addVendorHelper() { f.package.include.push('unzip_requirements.py'); return f; }) - .then(functions => uniqBy(functions, func => func.module)) - .map(f => { + .then((functions) => uniqBy(functions, (func) => func.module)) + .map((f) => { this.serverless.cli.log( `Adding Python requirements helper to ${f.module}...` ); @@ -63,14 +63,14 @@ function removeVendorHelper() { if (this.options.zip && this.options.cleanupZipHelper) { if (this.serverless.service.package.individually) { return BbPromise.resolve(this.targetFuncs) - .map(f => { + .map((f) => { if (!get(f, 'module')) { set(f, ['module'], '.'); } return f; }) - .then(funcs => uniqBy(funcs, f => f.module)) - .map(f => { + .then((funcs) => uniqBy(funcs, (f) => f.module)) + .map((f) => { this.serverless.cli.log( `Removing Python requirements helper from ${f.module}...` ); @@ -95,14 +95,14 @@ function packRequirements() { if (this.options.zip) { if (this.serverless.service.package.individually) { return BbPromise.resolve(this.targetFuncs) - .map(f => { + .map((f) => { if (!get(f, 'module')) { set(f, ['module'], '.'); } return f; }) - .then(funcs => uniqBy(funcs, f => f.module)) - .map(f => { + .then((funcs) => uniqBy(funcs, (f) => f.module)) + .map((f) => { this.serverless.cli.log( `Zipping required Python packages for ${f.module}...` ); @@ -110,12 +110,12 @@ function packRequirements() { return addTree( new JSZip(), `.serverless/${f.module}/requirements` - ).then(zip => writeZip(zip, `${f.module}/.requirements.zip`)); + ).then((zip) => writeZip(zip, `${f.module}/.requirements.zip`)); }); } else { this.serverless.cli.log('Zipping required Python packages...'); this.serverless.service.package.include.push('.requirements.zip'); - return addTree(new JSZip(), '.serverless/requirements').then(zip => + return addTree(new JSZip(), '.serverless/requirements').then((zip) => writeZip(zip, path.join(this.servicePath, '.requirements.zip')) ); } diff --git a/lib/zipTree.js b/lib/zipTree.js index d45aded0..1654f665 100644 --- a/lib/zipTree.js +++ b/lib/zipTree.js @@ -15,17 +15,17 @@ function addTree(zip, src) { return fse .readdirAsync(srcN) - .map(name => { + .map((name) => { const srcPath = path.join(srcN, name); - return fse.statAsync(srcPath).then(stat => { + return fse.statAsync(srcPath).then((stat) => { if (stat.isDirectory()) { return addTree(zip.folder(name), srcPath); } else { const opts = { date: stat.mtime, unixPermissions: stat.mode }; return fse .readFileAsync(srcPath) - .then(data => zip.file(name, data, opts)); + .then((data) => zip.file(name, data, opts)); } }); }) @@ -43,10 +43,10 @@ function writeZip(zip, targetPath) { platform: process.platform == 'win32' ? 'DOS' : 'UNIX', compression: 'DEFLATE', compressionOptions: { - level: 9 - } + level: 9, + }, }; - return new BbPromise(resolve => + return new BbPromise((resolve) => zip .generateNodeStream(opts) .pipe(fse.createWriteStream(targetPath)) @@ -64,7 +64,7 @@ function writeZip(zip, targetPath) { */ function zipFile(zip, zipPath, bufferPromise, fileOpts) { return bufferPromise - .then(buffer => + .then((buffer) => zip.file( zipPath, buffer, @@ -72,7 +72,7 @@ function zipFile(zip, zipPath, bufferPromise, fileOpts) { {}, { // necessary to get the same hash when zipping the same content - date: new Date(0) + date: new Date(0), }, fileOpts ) diff --git a/package.json b/package.json index b5b3c394..0ffc0c50 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "serverless-python-requirements", "version": "5.1.0", "engines": { - "node": ">=10.0" + "node": ">=12.0" }, "description": "Serverless Python Requirements Plugin", "author": "United Income ", @@ -44,28 +44,28 @@ "format": "prettier --write '{.,lib}/*.{js,md}'" }, "devDependencies": { - "eslint": "^5.16.0", - "prettier": "^1", "cross-spawn": "*", + "eslint": "^7.22.0", + "lodash": "^4.17.21", + "prettier": "^2", "tape": "*", - "tape-promise": "*", - "lodash": "^4.16.15" + "tape-promise": "*" }, "dependencies": { - "@iarna/toml": "^2.2.3", + "@iarna/toml": "^2.2.5", "appdirectory": "^0.1.0", - "bluebird": "^3.0.6", - "fs-extra": "^8.1.0", - "glob-all": "^3.1.0", - "is-wsl": "^2.0.0", - "jszip": "^3.1.0", + "bluebird": "^3.7.2", + "fs-extra": "^9.1.0", + "glob-all": "^3.2.1", + "is-wsl": "^2.2.0", + "jszip": "^3.6.0", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", - "lodash.uniqby": "^4.0.0", + "lodash.uniqby": "^4.7.0", "lodash.values": "^4.3.0", "rimraf": "^3.0.2", "sha256-file": "1.0.0", - "shell-quote": "^1.6.1" + "shell-quote": "^1.7.2" }, "eslintConfig": { "extends": "eslint:recommended",