Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit e703135

Browse files
authored
chore: run eslint and add eslint rule for unhandled promise rejection (#1097)
1 parent 1a8c09b commit e703135

File tree

42 files changed

+267
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+267
-272
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ fixture
1111
integration/basic-app
1212
integration/basic-app-with-nested-next-config
1313
integration/app-with-serverless-offline
14+
packages/libs/lambda-at-edge/sharp_node_modules

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ module.exports = {
1919
"@typescript-eslint/ban-ts-ignore": "off",
2020
"@typescript-eslint/ban-ts-comment": "off"
2121
}
22+
},
23+
{
24+
files: ["*.ts", "*.tsx"],
25+
excludedFiles: ["**/cypress/integration/*.ts"],
26+
plugins: ["promise"],
27+
rules: {
28+
"promise/catch-or-return": "error"
29+
}
2230
}
2331
]
2432
};

documentation/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
2+
presets: [require.resolve("@docusaurus/core/lib/babel/preset")]
33
};

documentation/docusaurus.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ module.exports = {
3939
position: "right"
4040
},
4141
{
42-
href:
43-
"https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/serverless-components/nextjs-component/examples",
42+
href: "https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/serverless-components/nextjs-component/examples",
4443
label: "Examples",
4544
position: "right"
4645
}
@@ -75,8 +74,7 @@ module.exports = {
7574
},
7675
{
7776
label: "Examples",
78-
href:
79-
"https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/serverless-components/nextjs-component/examples"
77+
href: "https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/serverless-components/nextjs-component/examples"
8078
}
8179
]
8280
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"eslint": "^7.3.1",
5555
"eslint-config-prettier": "^6.11.0",
5656
"eslint-plugin-prettier": "^3.1.4",
57+
"eslint-plugin-promise": "5.1.0",
5758
"fs-extra": "^9.0.1",
5859
"husky": "^4.2.5",
5960
"jest": "^26.1.0",
@@ -124,7 +125,7 @@
124125
}
125126
},
126127
"lint-staged": {
127-
"*.{js,jsx,ts,tsx,md,yml}": "prettier --write"
128+
"*.{js,jsx,ts,tsx,md,yml}": ["eslint --fix","prettier --write"]
128129
},
129130
"resolutions": {
130131
"which": "^2.0.1",

packages/compat-layers/apigw-lambda-compat/lib/__tests__/compatLayer.request.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ describe("compatLayer.request", () => {
101101
path: "/"
102102
},
103103
multiValueQueryStringParameters: {
104-
url:
105-
"https://example.com/t/t?a=8&as=1&t=2&tk=1&url=https://example.com/õ",
104+
url: "https://example.com/t/t?a=8&as=1&t=2&tk=1&url=https://example.com/õ",
106105
clickSource: "yes",
107106
category: "cat"
108107
}

packages/deprecated/serverless-plugin/__mocks__/aws-sdk.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ const {
1919
mockPromise: mockDescribeStacksPromise
2020
} = promisify(jest.fn());
2121

22-
const {
23-
mockFunction: mockCreateStack,
24-
mockPromise: mockCreateStackPromise
25-
} = promisify(jest.fn());
22+
const { mockFunction: mockCreateStack, mockPromise: mockCreateStackPromise } =
23+
promisify(jest.fn());
2624

2725
const {
2826
mockFunction: mockDescribeStackEvents,
@@ -39,10 +37,8 @@ const {
3937
mockPromise: mockValidateTemplatePromise
4038
} = promisify(jest.fn());
4139

42-
const {
43-
mockFunction: mockUpdateStack,
44-
mockPromise: mockUpdateStackPromise
45-
} = promisify(jest.fn());
40+
const { mockFunction: mockUpdateStack, mockPromise: mockUpdateStackPromise } =
41+
promisify(jest.fn());
4642

4743
const {
4844
mockFunction: mockListStackResources,
@@ -76,23 +72,17 @@ const {
7672
mockFunction: mockGetQueueAttributes,
7773
mockPromise: mockGetQueueAttributesPromise
7874
} = promisify(jest.fn());
79-
const {
80-
mockFunction: mockCreateQueue,
81-
mockPromise: mockCreateQueuePromise
82-
} = promisify(jest.fn());
83-
const {
84-
mockFunction: mockDeleteQueue,
85-
mockPromise: mockDeleteQueuePromise
86-
} = promisify(jest.fn());
75+
const { mockFunction: mockCreateQueue, mockPromise: mockCreateQueuePromise } =
76+
promisify(jest.fn());
77+
const { mockFunction: mockDeleteQueue, mockPromise: mockDeleteQueuePromise } =
78+
promisify(jest.fn());
8779
MockSQS.prototype.createQueue = mockCreateQueue;
8880
MockSQS.prototype.deleteQueue = mockDeleteQueue;
8981
MockSQS.prototype.getQueueAttributes = mockGetQueueAttributes;
9082

9183
const MockAPIGateway = function () {};
92-
const {
93-
mockFunction: mockGetRestApis,
94-
mockPromise: mockGetRestApisPromise
95-
} = promisify(jest.fn());
84+
const { mockFunction: mockGetRestApis, mockPromise: mockGetRestApisPromise } =
85+
promisify(jest.fn());
9686
MockAPIGateway.prototype.getRestApis = mockGetRestApis;
9787

9888
const MockSharedIniFileCredentials = function () {};

packages/deprecated/serverless-plugin/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class ServerlessNextJsPlugin {
2626
this,
2727
this.build
2828
),
29-
"before:aws:package:finalize:mergeCustomProviderResources": this.hookWrapper.bind(
30-
this,
31-
this.addCustomStackResources
32-
),
29+
"before:aws:package:finalize:mergeCustomProviderResources":
30+
this.hookWrapper.bind(this, this.addCustomStackResources),
3331
"after:package:createDeploymentArtifacts": this.hookWrapper.bind(
3432
this,
3533
this.removePluginBuildDir

packages/deprecated/serverless-plugin/lib/__tests__/addCustomStackResources.test.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ describe("addCustomStackResources", () => {
3737

3838
const plugin = new ServerlessPluginBuilder().build();
3939

40-
plugin.serverless.service.provider.coreCloudFormationTemplate = clone(
41-
coreCfTemplate
42-
);
40+
plugin.serverless.service.provider.coreCloudFormationTemplate =
41+
clone(coreCfTemplate);
4342

4443
return addCustomStackResources.call(plugin).then(() => {
4544
expect(logger.log).toBeCalledWith(
@@ -174,9 +173,8 @@ describe("addCustomStackResources", () => {
174173
plugin.provider.getRegion = getRegion;
175174

176175
return addCustomStackResources.call(plugin).then(() => {
177-
const {
178-
RobotsProxyMethod
179-
} = plugin.serverless.service.resources.Resources;
176+
const { RobotsProxyMethod } =
177+
plugin.serverless.service.resources.Resources;
180178

181179
expect(getRegion).toBeCalled();
182180
expect(RobotsProxyMethod.Properties.Integration.Uri).toEqual(
@@ -289,15 +287,13 @@ describe("addCustomStackResources", () => {
289287
.mockResolvedValue(["robots.txt", "manifest.json"]);
290288

291289
return addCustomStackResources.call(plugin).then(() => {
292-
const {
293-
NextjsCloudFront
294-
} = plugin.serverless.service.resources.Resources;
290+
const { NextjsCloudFront } =
291+
plugin.serverless.service.resources.Resources;
295292

296293
expect(NextjsCloudFront).toBeDefined();
297294

298-
const {
299-
CacheBehaviors
300-
} = NextjsCloudFront.Properties.DistributionConfig;
295+
const { CacheBehaviors } =
296+
NextjsCloudFront.Properties.DistributionConfig;
301297

302298
expect(CacheBehaviors).toHaveLength(4); // behavior for static/*, _next/* origins and 2 other behaviours for robots and manifest
303299
expect(CacheBehaviors[2].PathPattern).toEqual("robots.txt");
@@ -323,9 +319,8 @@ describe("addCustomStackResources", () => {
323319
.build();
324320

325321
return addCustomStackResources.call(plugin).then(() => {
326-
const {
327-
NextjsCloudFront
328-
} = plugin.serverless.service.resources.Resources;
322+
const { NextjsCloudFront } =
323+
plugin.serverless.service.resources.Resources;
329324
expect(
330325
NextjsCloudFront.Properties.DistributionConfig.Aliases
331326
).toEqual(["myalias.com"]);

packages/deprecated/serverless-plugin/lib/addCustomStackResources.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ const addCustomStackResources = async function () {
185185
path.join(__dirname, "../resources/assets-bucket.yml")
186186
);
187187

188-
assetsBucketResource.Resources.NextStaticAssetsS3Bucket.Properties.BucketName = bucketName;
188+
assetsBucketResource.Resources.NextStaticAssetsS3Bucket.Properties.BucketName =
189+
bucketName;
189190

190191
merge(
191192
this.serverless.service.provider.coreCloudFormationTemplate,
@@ -204,9 +205,8 @@ const addCustomStackResources = async function () {
204205
merge(cloudFrontResource.Resources.NextjsCloudFront, cloudFront);
205206
}
206207

207-
const {
208-
DistributionConfig
209-
} = cloudFrontResource.Resources.NextjsCloudFront.Properties;
208+
const { DistributionConfig } =
209+
cloudFrontResource.Resources.NextjsCloudFront.Properties;
210210

211211
const findOrigin = (originId) =>
212212
DistributionConfig.Origins.find((o) => o.Id === originId);

packages/deprecated/serverless-plugin/lib/parseNextConfiguration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ let nextLoadConfig;
22
let PHASE_PRODUCTION_BUILD;
33
try {
44
nextLoadConfig = require("next-server/dist/server/config").default;
5-
PHASE_PRODUCTION_BUILD = require("next-server/dist/lib/constants")
6-
.PHASE_PRODUCTION_BUILD;
5+
PHASE_PRODUCTION_BUILD =
6+
require("next-server/dist/lib/constants").PHASE_PRODUCTION_BUILD;
77
} catch (e) {
88
// https://github.com/serverless-nextjs/serverless-next.js/issues/157
99
// Some files were moved in the dist/ directory in next.js 9.0.6
1010
// check the new location if the old location failed.
1111
nextLoadConfig = require("next/dist/next-server/server/config").default;
12-
PHASE_PRODUCTION_BUILD = require("next/dist/next-server/lib/constants")
13-
.PHASE_PRODUCTION_BUILD;
12+
PHASE_PRODUCTION_BUILD =
13+
require("next/dist/next-server/lib/constants").PHASE_PRODUCTION_BUILD;
1414
}
1515

1616
const s3Urls = require("@mapbox/s3urls");

packages/deprecated/serverless-plugin/utils/s3/upload.js

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,55 +66,54 @@ const cacheHeaderFactory = (buildId = "", rootPrefix) => {
6666
};
6767
};
6868

69-
module.exports = (awsProvider, buildId) => (
70-
dir,
71-
{ bucket, truncate = null, rootPrefix = null }
72-
) => {
73-
const getCacheHeader = cacheHeaderFactory(buildId, rootPrefix);
74-
const getObjectFromS3 = get(awsProvider);
75-
const promises = [];
76-
77-
logger.log(`Uploading ${dir} to ${bucket} ...`);
78-
79-
return new Promise((resolve, reject) => {
80-
walkDir(dir)
81-
.on("data", (item) => {
82-
const p = fse.lstat(item.path).then(async (stats) => {
83-
if (!stats.isDirectory()) {
84-
const CacheControl = getCacheHeader(item);
85-
const uploadParams = getUploadParameters(
86-
bucket,
87-
item.path,
88-
truncate,
89-
rootPrefix,
90-
CacheControl
91-
);
92-
93-
const s3Object = await getObjectFromS3(uploadParams.Key, bucket);
94-
95-
if (filesAreEqual(s3Object, stats)) {
96-
debug(`no need to upload ${uploadParams.Key}`);
97-
return Promise.resolve();
69+
module.exports =
70+
(awsProvider, buildId) =>
71+
(dir, { bucket, truncate = null, rootPrefix = null }) => {
72+
const getCacheHeader = cacheHeaderFactory(buildId, rootPrefix);
73+
const getObjectFromS3 = get(awsProvider);
74+
const promises = [];
75+
76+
logger.log(`Uploading ${dir} to ${bucket} ...`);
77+
78+
return new Promise((resolve, reject) => {
79+
walkDir(dir)
80+
.on("data", (item) => {
81+
const p = fse.lstat(item.path).then(async (stats) => {
82+
if (!stats.isDirectory()) {
83+
const CacheControl = getCacheHeader(item);
84+
const uploadParams = getUploadParameters(
85+
bucket,
86+
item.path,
87+
truncate,
88+
rootPrefix,
89+
CacheControl
90+
);
91+
92+
const s3Object = await getObjectFromS3(uploadParams.Key, bucket);
93+
94+
if (filesAreEqual(s3Object, stats)) {
95+
debug(`no need to upload ${uploadParams.Key}`);
96+
return Promise.resolve();
97+
}
98+
99+
debug(
100+
`uploading to s3 - ${uploadParams.Key} ${
101+
CacheControl ? " with cachecontrol " + CacheControl : ""
102+
}`
103+
);
104+
105+
return awsProvider("S3", "upload", uploadParams);
98106
}
99-
100-
debug(
101-
`uploading to s3 - ${uploadParams.Key} ${
102-
CacheControl ? " with cachecontrol " + CacheControl : ""
103-
}`
104-
);
105-
106-
return awsProvider("S3", "upload", uploadParams);
107-
}
107+
});
108+
109+
promises.push(p);
110+
})
111+
.on("end", () => {
112+
Promise.all(promises)
113+
.then(() => {
114+
resolve({ count: promises.length });
115+
})
116+
.catch(reject);
108117
});
109-
110-
promises.push(p);
111-
})
112-
.on("end", () => {
113-
Promise.all(promises)
114-
.then(() => {
115-
resolve({ count: promises.length });
116-
})
117-
.catch(reject);
118-
});
119-
});
120-
};
118+
});
119+
};

packages/e2e-tests/next-app-with-locales-using-serverless-trace/cypress/integration/image-optimizer.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ describe("Image Optimizer Tests", () => {
6464

6565
[
6666
{
67-
path:
68-
"/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app-with-locales-using-serverless-trace%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
67+
path: "/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app-with-locales-using-serverless-trace%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
6968
}
7069
].forEach(({ path }) => {
7170
it(`serves external image: ${path}`, () => {

packages/e2e-tests/next-app-with-locales/cypress/integration/image-optimizer.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ describe("Image Optimizer Tests", () => {
6464

6565
[
6666
{
67-
path:
68-
"/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app-with-locales%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
67+
path: "/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app-with-locales%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
6968
}
7069
].forEach(({ path }) => {
7170
it(`serves external image: ${path}`, () => {

packages/e2e-tests/next-app/cypress/integration/image-optimizer.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ describe("Image Optimizer Tests", () => {
6464

6565
[
6666
{
67-
path:
68-
"/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
67+
path: "/_next/image?url=https%3A%2F%2Fraw.githubusercontent.com%2Fserverless-nextjs%2Fserverless-next.js%2Fmaster%2Fpackages%2Fe2e-tests%2Fnext-app%2Fpublic%2Fapp-store-badge.png&q=100&w=128"
6968
}
7069
].forEach(({ path }) => {
7170
it(`serves external image: ${path}`, () => {

packages/e2e-tests/test-utils/scripts/cleanup-lambda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function removeLambdaVersion(
5555
lambda: AWS.Lambda,
5656
fnName: string,
5757
version: string
58-
): Promise<{}> {
58+
): Promise<unknown> {
5959
return new Promise((resolve, reject) => {
6060
lambda.deleteFunction(
6161
{ FunctionName: fnName, Qualifier: version },
@@ -72,7 +72,7 @@ function removeLambdaVersion(
7272

7373
async function cleanupVersions(
7474
region: string,
75-
removeIt: boolean = false,
75+
removeIt = false,
7676
nextMarker: string | undefined = undefined
7777
) {
7878
const lambda: AWS.Lambda = new AWS.Lambda({ region });

0 commit comments

Comments
 (0)