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

Commit 6f10bba

Browse files
build: fix linting issues
1 parent a776a8d commit 6f10bba

11 files changed

+65
-48
lines changed

__tests__/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const ServerlessPluginBuilder = require("../utils/test/ServerlessPluginBuilder");
33
const parsedNextConfigurationFactory = require("../utils/test/parsedNextConfigurationFactory");
44
const uploadStaticAssetsToS3 = require("../lib/uploadStaticAssetsToS3");
@@ -173,7 +173,7 @@ describe("ServerlessNextJsPlugin", () => {
173173
});
174174

175175
it("should call uploadStaticAssetsToS3 with bucketName and next static dir", () => {
176-
const distDir = 'build';
176+
const distDir = "build";
177177
parseNextConfiguration.mockReturnValueOnce(
178178
parsedNextConfigurationFactory({
179179
distDir
@@ -186,7 +186,7 @@ describe("ServerlessNextJsPlugin", () => {
186186

187187
return plugin.uploadStaticAssets().then(() => {
188188
expect(uploadStaticAssetsToS3).toBeCalledWith({
189-
staticAssetsPath: path.join(distDir, 'static'),
189+
staticAssetsPath: path.join(distDir, "static"),
190190
bucketName: "my-bucket",
191191
providerRequest: expect.any(Function)
192192
});

classes/__tests__/NextPage.test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const NextPage = require("../NextPage");
33

44
describe("NextPage", () => {
@@ -13,7 +13,7 @@ describe("NextPage", () => {
1313

1414
describe("When is the index page", () => {
1515
const buildDir = "build";
16-
const pagePath = path.join(buildDir, 'index.js');
16+
const pagePath = path.join(buildDir, "index.js");
1717
let page;
1818

1919
beforeEach(() => {
@@ -34,7 +34,7 @@ describe("NextPage", () => {
3434

3535
describe("When is the _error page", () => {
3636
const buildDir = "build";
37-
const pagePath = path.join(buildDir, '_error.js');
37+
const pagePath = path.join(buildDir, "_error.js");
3838
let page;
3939

4040
beforeEach(() => {
@@ -59,7 +59,7 @@ describe("NextPage", () => {
5959

6060
describe("When is a nested page", () => {
6161
const buildDir = "build";
62-
const pagePath = path.join(buildDir, 'categories/fridge/fridges.js');
62+
const pagePath = path.join(buildDir, "categories/fridge/fridges.js");
6363
let page;
6464

6565
beforeEach(() => {
@@ -104,11 +104,15 @@ describe("NextPage", () => {
104104
});
105105

106106
it("should have pageCompatPath", () => {
107-
expect(page.pageCompatPath).toEqual(path.join(buildDir, "admin.compat.js"));
107+
expect(page.pageCompatPath).toEqual(
108+
path.join(buildDir, "admin.compat.js")
109+
);
108110
});
109111

110112
it("should return pageOriginalPath", () => {
111-
expect(page.pageOriginalPath).toEqual(path.join(buildDir, "admin.original.js"));
113+
expect(page.pageOriginalPath).toEqual(
114+
path.join(buildDir, "admin.original.js")
115+
);
112116
});
113117

114118
it("should return pageDir", () => {

classes/__tests__/PluginBuildDir.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const fs = require("fs-extra");
33
const PluginBuildDir = require("../PluginBuildDir");
44
const logger = require("../../utils/logger");
@@ -26,11 +26,15 @@ describe("PluginBuildDir", () => {
2626
});
2727

2828
it("should have buildDir at same level as next config.", () => {
29-
expect(pluginBuildDir.buildDir).toEqual(path.join(nextConfigDir, 'sls-next-build'));
29+
expect(pluginBuildDir.buildDir).toEqual(
30+
path.join(nextConfigDir, "sls-next-build")
31+
);
3032
});
3133

3234
it("should have posixBuildDir regardless the platform", () => {
33-
expect(pluginBuildDir.posixBuildDir).toEqual("path/to/nextApp/sls-next-build");
35+
expect(pluginBuildDir.posixBuildDir).toEqual(
36+
"path/to/nextApp/sls-next-build"
37+
);
3438
});
3539
});
3640

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class ServerlessNextJsPlugin {
5353
const servicePackage = this.serverless.service.package;
5454

5555
servicePackage.include = servicePackage.include || [];
56-
servicePackage.include.push(path.posix.join(pluginBuildDir.posixBuildDir, "**"));
56+
servicePackage.include.push(
57+
path.posix.join(pluginBuildDir.posixBuildDir, "**")
58+
);
5759
return build(pluginBuildDir, this.getPluginConfigValue("pageConfig")).then(
5860
nextPages => this.setNextPages(nextPages)
5961
);

lib/__tests__/copyBuildFiles.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("copyBuildFiles", () => {
3939

4040
it("should copy serverless pages folder from next build directory", () => {
4141
expect(fse.copy).toBeCalledWith(
42-
path.join(nextBuildDir, 'serverless/pages'),
42+
path.join(nextBuildDir, "serverless/pages"),
4343
pluginBuildDir
4444
);
4545
});
@@ -51,7 +51,7 @@ describe("copyBuildFiles", () => {
5151
it("should call fs copy with the compatLayer file", () => {
5252
expect(fse.copy).toBeCalledWith(
5353
path.join(__dirname, "..", `compatLayer.js`),
54-
path.join(pluginBuildDir, 'compatLayer.js')
54+
path.join(pluginBuildDir, "compatLayer.js")
5555
);
5656
});
5757
});

lib/__tests__/getCompatLayerCode.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const getCompatLayerCode = require("../getCompatLayerCode");
33

44
describe("getCompatLayerCode", () => {

lib/__tests__/getNextPagesFromBuildDir.test.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("getNextPagesFromBuildDir", () => {
2626
it("should return an empty array when there are no pages", () => {
2727
expect.assertions(1);
2828

29-
const buildDir = path.normalize("/path/to/build/dir")
29+
const buildDir = path.normalize("/path/to/build/dir");
3030

3131
const getPagesPromise = getNextPagesFromBuildDir(buildDir).then(
3232
nextPages => {
@@ -48,9 +48,9 @@ describe("getNextPagesFromBuildDir", () => {
4848
const promise = getNextPagesFromBuildDir(buildDir).then(nextPages => {
4949
expect(nextPages).toHaveLength(2);
5050
expect(nextPages[0].pageName).toEqual("index");
51-
expect(nextPages[0].pagePath).toEqual(path.join('build', 'index.js'));
51+
expect(nextPages[0].pagePath).toEqual(path.join("build", "index.js"));
5252
expect(nextPages[1].pageName).toEqual("about");
53-
expect(nextPages[1].pagePath).toEqual(path.join('build', 'about.js'));
53+
expect(nextPages[1].pagePath).toEqual(path.join("build", "about.js"));
5454
});
5555

5656
mockedStream.emit("data", {
@@ -75,7 +75,7 @@ describe("getNextPagesFromBuildDir", () => {
7575
about: aboutPageConfigOverride
7676
};
7777

78-
const buildDir = path.normalize('/path/to/build');
78+
const buildDir = path.normalize("/path/to/build");
7979

8080
const promise = getNextPagesFromBuildDir(buildDir, pageConfig).then(
8181
nextPages => {
@@ -98,7 +98,7 @@ describe("getNextPagesFromBuildDir", () => {
9898
it("should log pages found", () => {
9999
expect.assertions(1);
100100

101-
const buildDir = path.normalize('/path/to/build');
101+
const buildDir = path.normalize("/path/to/build");
102102

103103
const promise = getNextPagesFromBuildDir(buildDir).then(() => {
104104
expect(logger.log).toBeCalledWith(`Found 1 next page(s)`);
@@ -136,14 +136,12 @@ describe("getNextPagesFromBuildDir", () => {
136136
it("should skip compatLayer file", () => {
137137
expect.assertions(2);
138138

139-
const buildDir = path.normalize('/path/to/build');
139+
const buildDir = path.normalize("/path/to/build");
140140

141-
const promise = getNextPagesFromBuildDir(buildDir).then(
142-
nextPages => {
143-
expect(nextPages).toHaveLength(1);
144-
expect(nextPages[0].pageName).toEqual("home");
145-
}
146-
);
141+
const promise = getNextPagesFromBuildDir(buildDir).then(nextPages => {
142+
expect(nextPages).toHaveLength(1);
143+
expect(nextPages[0].pageName).toEqual("home");
144+
});
147145

148146
mockedStream.emit("data", { path: path.join(buildDir, "compatLayer.js") });
149147
mockedStream.emit("data", { path: path.join(buildDir, "home.js") });
@@ -161,9 +159,13 @@ describe("getNextPagesFromBuildDir", () => {
161159
const promise = getNextPagesFromBuildDir(buildDir).then(nextPages => {
162160
expect(nextPages).toHaveLength(2);
163161
expect(nextPages[0].pageName).toEqual("hello-world");
164-
expect(nextPages[0].pagePath).toEqual(path.join(buildDir, "one", "hello-world.js"));
162+
expect(nextPages[0].pagePath).toEqual(
163+
path.join(buildDir, "one", "hello-world.js")
164+
);
165165
expect(nextPages[1].pageName).toEqual("hello-world");
166-
expect(nextPages[1].pagePath).toEqual(path.join(buildDir, "one", "two", "hello-world.js"));
166+
expect(nextPages[1].pagePath).toEqual(
167+
path.join(buildDir, "one", "two", "hello-world.js")
168+
);
167169
});
168170

169171
mockedStream.emit("data", {

lib/__tests__/rewritePageHandlers.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const fs = require("fs");
33
const rewritePageHandlers = require("../rewritePageHandlers");
44
const getCompatLayerCode = require("../getCompatLayerCode");
@@ -45,7 +45,9 @@ describe("rewritePageHandlers", () => {
4545

4646
it("should call getCompatLayerCode with the next page path", () => {
4747
expect(getCompatLayerCode).toBeCalledWith(path.join(pagesDir, "home.js"));
48-
expect(getCompatLayerCode).toBeCalledWith(path.join(pagesDir, "about.js"));
48+
expect(getCompatLayerCode).toBeCalledWith(
49+
path.join(pagesDir, "about.js")
50+
);
4951
});
5052

5153
it("should write new js files with the compat layer code", () => {
@@ -66,14 +68,14 @@ describe("rewritePageHandlers", () => {
6668
fs.rename.mockImplementation((fileName, newFileName, cb) => cb(null, ""));
6769

6870
expect(fs.rename).toBeCalledWith(
69-
path.join(pagesDir, "home.js"),
70-
path.join(pagesDir, "home.original.js"),
71+
path.join(pagesDir, "home.js"),
72+
path.join(pagesDir, "home.original.js"),
7173
expect.any(Function)
7274
);
7375

7476
expect(fs.rename).toBeCalledWith(
75-
path.join(pagesDir, "about.js"),
76-
path.join(pagesDir, "about.original.js"),
77+
path.join(pagesDir, "about.js"),
78+
path.join(pagesDir, "about.original.js"),
7779
expect.any(Function)
7880
);
7981
});
@@ -82,13 +84,13 @@ describe("rewritePageHandlers", () => {
8284
expect.assertions(2);
8385

8486
expect(fs.rename).toBeCalledWith(
85-
path.join(pagesDir, "home.compat.js"),
87+
path.join(pagesDir, "home.compat.js"),
8688
path.join(pagesDir, "home.js"),
8789
expect.any(Function)
8890
);
8991

9092
expect(fs.rename).toBeCalledWith(
91-
path.join(pagesDir, "about.compat.js"),
93+
path.join(pagesDir, "about.compat.js"),
9294
path.join(pagesDir, "about.js"),
9395
expect.any(Function)
9496
);

lib/__tests__/uploadStaticAssetsToS3.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require("path");
22
const fs = require("fs");
33
const walkDir = require("klaw");
44
const mime = require("mime");
@@ -40,7 +40,7 @@ describe("uploadStaticAssetsToS3", () => {
4040
});
4141

4242
mockedStream.emit("data", {
43-
path: path.normalize("users/foo/static/chunks/foo.js")
43+
path: path.normalize("users/foo/static/chunks/foo.js")
4444
});
4545
mockedStream.emit("end");
4646

@@ -60,7 +60,7 @@ describe("uploadStaticAssetsToS3", () => {
6060
});
6161

6262
mockedStream.emit("data", {
63-
path: path.normalize("users/foo/static/chunks/foo.js")
63+
path: path.normalize("users/foo/static/chunks/foo.js")
6464
});
6565
mockedStream.emit("end");
6666

@@ -78,7 +78,7 @@ describe("uploadStaticAssetsToS3", () => {
7878
});
7979

8080
mockedStream.emit("data", {
81-
path: path.normalize("users/foo/static/chunks/foo.js")
81+
path: path.normalize("users/foo/static/chunks/foo.js")
8282
});
8383
mockedStream.emit("end");
8484

@@ -89,14 +89,14 @@ describe("uploadStaticAssetsToS3", () => {
8989
expect.assertions(1);
9090

9191
const promise = uploadStaticAssetsToS3({
92-
staticAssetsPath: path.join("build", "static"),
92+
staticAssetsPath: path.join("build", "static"),
9393
providerRequest: () => {}
9494
}).then(() => {
9595
expect(walkDir).toBeCalledWith(path.join("build", "static"));
9696
});
9797

9898
mockedStream.emit("data", {
99-
path: path.normalize("users/foo/static/chunks/foo.js")
99+
path: path.normalize("users/foo/static/chunks/foo.js")
100100
});
101101
mockedStream.emit("end");
102102

@@ -114,7 +114,7 @@ describe("uploadStaticAssetsToS3", () => {
114114
mime.getType.mockImplementation(() => "application/foo");
115115

116116
const promise = uploadStaticAssetsToS3({
117-
staticAssetsPath: path.join('build', 'static'),
117+
staticAssetsPath: path.join("build", "static"),
118118
providerRequest,
119119
bucketName
120120
}).then(() => {

lib/uploadStaticAssetsToS3.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const uploadStaticAssetsToS3 = ({
1818
.on("data", item => {
1919
const itemPath = item.path;
2020
const isFile = !fs.lstatSync(itemPath).isDirectory();
21-
const posixItemPath = item.path.replace(/\\/g, '/');
21+
const posixItemPath = item.path.replace(/\\/g, "/");
2222

2323
if (isFile) {
2424
uploadPromises.push(
@@ -27,7 +27,10 @@ const uploadStaticAssetsToS3 = ({
2727
Bucket: bucketName,
2828
Key: path.posix.join(
2929
"_next",
30-
posixItemPath.substring(posixItemPath.indexOf("/static"), posixItemPath.length)
30+
posixItemPath.substring(
31+
posixItemPath.indexOf("/static"),
32+
posixItemPath.length
33+
)
3134
),
3235
ContentType: mime.getType(itemPath),
3336
Body: fs.createReadStream(itemPath)

0 commit comments

Comments
 (0)