Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/aws/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const _ = require('lodash');
const memoize = require('memoizee');
const PromiseQueue = require('promise-queue');
const promiseLimit = require('ext/promise/limit').bind(Promise);
const sdk = require('./sdk-v2');
const ServerlessError = require('../../lib/serverless-error');
const { log } = require('../utils/serverless-utils/log');
Expand Down Expand Up @@ -74,8 +74,7 @@ const timeout = process.env.AWS_CLIENT_TIMEOUT || process.env.aws_client_timeout
if (timeout) {
sdk.config.httpOptions.timeout = parseInt(timeout, 10);
}
PromiseQueue.configure(Promise);
const requestQueue = new PromiseQueue(2, Infinity);
const requestQueue = promiseLimit(2, async (task) => task());

const MAX_RETRIES = (() => {
const userValue = Number(process.env.SLS_AWS_REQUEST_MAX_RETRIES);
Expand Down Expand Up @@ -172,7 +171,7 @@ async function awsRequest(service, method, ...args) {
throw e;
}
};
const request = await requestQueue.add(() =>
const request = await requestQueue(() =>
persistentRequest(async () => {
const requestId = ++requestCounter;
const awsService = getServiceInstance(service, method);
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/deploy/lib/check-for-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const globby = require('globby');
const glob = require('../../../../utils/glob');
const BbPromise = require('bluebird');
const _ = require('lodash');
const normalizeFiles = require('../../lib/normalize-files');
Expand Down Expand Up @@ -191,7 +191,7 @@ module.exports = {
]);

// create hashes for all the zip files
const zipFiles = globby
const zipFiles = glob
.sync(['**.zip'], { cwd: serverlessDirPath, dot: true, silent: true })
.filter((basename) => !isOtelExtensionName(basename));
if (this.serverless.service.package.artifact) {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/invoke-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const download = require('../../../utils/serverless-utils/download');
const { ensureDir } = require('fs-extra');
const cachedir = require('cachedir');
const decompress = require('decompress');
const { v4: uuidv4 } = require('uuid');
const { randomUUID } = require('node:crypto');
const ServerlessError = require('../../../serverless-error');
const dirExists = require('../../../utils/fs/dir-exists');
const fileExists = require('../../../utils/fs/file-exists');
Expand Down Expand Up @@ -923,7 +923,7 @@ class AwsInvokeLocal {
Number(this.serverless.service.provider.timeout) ||
6;
let context = {
awsRequestId: uuidv4(),
awsRequestId: randomUUID(),
invokeid: 'id',
logGroupName: this.provider.naming.getLogGroupName(this.options.functionObj.name),
logStreamName: '2015/09/22/[HEAD]13370a84ca4ed8b77c427af260',
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/package/lib/package-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const path = require('path');
const fsp = require('fs').promises;
const globby = require('globby');
const glob = require('../../../utils/glob');
const _ = require('lodash');
const micromatch = require('micromatch');
const ServerlessError = require('../../../serverless-error');
Expand Down Expand Up @@ -289,7 +289,7 @@ module.exports = {
// NOTE: please keep this order of concatenating the include params
// rather than doing it the other way round!
// see https://github.com/serverless/serverless/pull/5825 for more information
return globby(['**'].concat(params.include), {
return glob(['**'].concat(params.include), {
cwd: path.join(this.serverless.serviceDir, prefix || ''),
dot: true,
silent: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/package/lib/zip-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require('path');
const crypto = require('crypto');
const fs = BbPromise.promisifyAll(require('fs'));
const childProcess = BbPromise.promisifyAll(require('child_process'));
const globby = require('globby');
const glob = require('../../../utils/glob');
const _ = require('lodash');
const ServerlessError = require('../../../serverless-error');
const { log } = require('../../../utils/serverless-utils/log');
Expand Down Expand Up @@ -149,7 +149,7 @@ async function excludeNodeDevDependencies(serviceDir) {
const nodeProdDepFile = path.join(tmpDir, `node-dependencies-${randHash}-prod`);

try {
const packageJsonFilePaths = globby.sync(
const packageJsonFilePaths = glob.sync(
[
'**/package.json',
// TODO add glob for node_modules filtering
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/download-template-from-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ async function downloadTemplateFromRepo(inputUrl, requestedServiceName, download
let sourceName;
let downloadServicePath;
const { username, password } = repoInformation;
const authRedirectHostnames = repoInformation.downloadUrl.startsWith('https://github.com/')
? ['codeload.github.com']
: [];

if (repoInformation.isSubdirectory) {
const folderName = repoInformation.pathToDirectory.split('/').splice(-1)[0];
Expand Down Expand Up @@ -313,6 +316,7 @@ async function downloadTemplateFromRepo(inputUrl, requestedServiceName, download
mode: '755',
username,
password,
allowedAuthRedirectHostnames: authRedirectHostnames,
};
// download service
return download(repoInformation.downloadUrl, downloadServicePath, downloadOptions)
Expand Down
165 changes: 165 additions & 0 deletions lib/utils/glob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
'use strict';

const fs = require('node:fs');
const path = require('node:path');
const fastGlob = require('fast-glob');

const toArray = (patterns) => {
return Array.isArray(patterns) ? patterns : [patterns];
};

const isDynamicPattern = (pattern) => /[*?{}()[\]]/.test(pattern);

const maybeExpandDirectoryPattern = (pattern, cwd) => {
if (isDynamicPattern(pattern)) {
return pattern;
}

const absolutePattern = path.resolve(cwd || process.cwd(), pattern);
try {
if (fs.statSync(absolutePattern).isDirectory()) {
const normalizedPattern = pattern.replace(/\\/g, '/').replace(/\/$/, '');
return `${normalizedPattern}/**/*`;
}
} catch {
// Ignore missing paths and let fast-glob handle them.
}

return pattern;
};

const expandPattern = (pattern, cwd, expandDirectories) => {
if (!expandDirectories) {
return pattern;
}

if (pattern.startsWith('!')) {
return `!${maybeExpandDirectoryPattern(pattern.slice(1), cwd)}`;
}

return maybeExpandDirectoryPattern(pattern, cwd);
};

const normalizeOptions = (options = {}) => {
const globOptions = { ...options };
const expandDirectories =
globOptions.expandDirectories !== undefined ? globOptions.expandDirectories : true;

delete globOptions.expandDirectories;
delete globOptions.nosort;

if (globOptions.follow !== undefined) {
globOptions.followSymbolicLinks = globOptions.follow;
delete globOptions.follow;
}

if (globOptions.nodir !== undefined) {
globOptions.onlyFiles = globOptions.nodir;
delete globOptions.nodir;
}

if (globOptions.silent !== undefined) {
globOptions.suppressErrors = globOptions.silent;
delete globOptions.silent;
}

return { expandDirectories, globOptions };
};

const buildTasks = (patterns, globOptions) => {
const tasks = [];
let remainingPatterns = patterns;

while (remainingPatterns.length > 0) {
const negativePatternIndex = remainingPatterns.findIndex((pattern) => pattern.startsWith('!'));

if (negativePatternIndex === -1) {
tasks.push({
patterns: remainingPatterns,
options: {
...globOptions,
ignore: [...(globOptions.ignore || [])],
},
});
break;
}

const ignorePattern = remainingPatterns[negativePatternIndex].slice(1);

for (const task of tasks) {
task.options.ignore.push(ignorePattern);
}

if (negativePatternIndex !== 0) {
tasks.push({
patterns: remainingPatterns.slice(0, negativePatternIndex),
options: {
...globOptions,
ignore: [...(globOptions.ignore || []), ignorePattern],
},
});
}

remainingPatterns = remainingPatterns.slice(negativePatternIndex + 1);
}

return tasks;
};

const collectResults = async (tasks) => {
const seen = new Set();
const results = [];

for (const task of tasks) {
for (const entry of await fastGlob(task.patterns, task.options)) {
if (seen.has(entry)) {
continue;
}

seen.add(entry);
results.push(entry);
}
}

return results;
};

const collectResultsSync = (tasks) => {
const seen = new Set();
const results = [];

for (const task of tasks) {
for (const entry of fastGlob.sync(task.patterns, task.options)) {
if (seen.has(entry)) {
continue;
}

seen.add(entry);
results.push(entry);
}
}

return results;
};

const glob = async (patterns, options = {}) => {
const normalizedPatterns = toArray(patterns);
const { expandDirectories, globOptions } = normalizeOptions(options);
const expandedPatterns = normalizedPatterns.map((pattern) =>
expandPattern(pattern, globOptions.cwd, expandDirectories)
);

return collectResults(buildTasks(expandedPatterns, globOptions));
};

glob.sync = (patterns, options = {}) => {
const normalizedPatterns = toArray(patterns);
const { expandDirectories, globOptions } = normalizeOptions(options);
const expandedPatterns = normalizedPatterns.map((pattern) =>
expandPattern(pattern, globOptions.cwd, expandDirectories)
);

return collectResultsSync(buildTasks(expandedPatterns, globOptions));
};

module.exports = glob;
4 changes: 2 additions & 2 deletions lib/utils/serverless-utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const p = require('path');
const os = require('os');
const fs = require('fs');
const { randomUUID } = require('node:crypto');

const _ = require('lodash');
const writeFileAtomic = require('write-file-atomic');
const uuid = require('uuid');
const { log } = require('./log');

const logDebug = log.get('config').debug;
Expand Down Expand Up @@ -60,7 +60,7 @@ function storeConfig(config, configPath) {

function createDefaultGlobalConfig() {
const defaultConfig = {
frameworkId: uuid.v1(),
frameworkId: randomUUID(),
meta: {
created_at: Math.round(Date.now() / 1000), // config file creation date
updated_at: null, // config file updated date
Expand Down
Loading