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

Commit a7c430a

Browse files
Merge pull request #26 from danielcondemarin/windows-support-fixes
Windows support
2 parents 60cdf9d + c0bb2c4 commit a7c430a

14 files changed

+155
-85
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
sudo: false
2+
os:
3+
# - windows
4+
- linux
5+
- osx
26
language: node_js
37
node_js:
48
- "8"
@@ -9,7 +13,7 @@ install:
913
script:
1014
- npm run lint
1115
- npm test
12-
- npm run coveralls
16+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run coveralls; fi
1317
- npm run integration
1418
cache:
1519
directories:

__tests__/index.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require("path");
12
const ServerlessPluginBuilder = require("../utils/test/ServerlessPluginBuilder");
23
const parsedNextConfigurationFactory = require("../utils/test/parsedNextConfigurationFactory");
34
const uploadStaticAssetsToS3 = require("../lib/uploadStaticAssetsToS3");
@@ -172,9 +173,10 @@ describe("ServerlessNextJsPlugin", () => {
172173
});
173174

174175
it("should call uploadStaticAssetsToS3 with bucketName and next static dir", () => {
176+
const distDir = "build";
175177
parseNextConfiguration.mockReturnValueOnce(
176178
parsedNextConfigurationFactory({
177-
distDir: "build"
179+
distDir
178180
})
179181
);
180182

@@ -184,7 +186,7 @@ describe("ServerlessNextJsPlugin", () => {
184186

185187
return plugin.uploadStaticAssets().then(() => {
186188
expect(uploadStaticAssetsToS3).toBeCalledWith({
187-
staticAssetsPath: "build/static",
189+
staticAssetsPath: path.join(distDir, "static"),
188190
bucketName: "my-bucket",
189191
providerRequest: expect.any(Function)
190192
});

classes/NextPage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class NextPage {
2525

2626
get pageHandler() {
2727
const dir = path.dirname(this.pagePath);
28-
return path.join(dir, this.pageName + ".render");
28+
const handler = path.join(dir, this.pageName + ".render");
29+
const posixHandler = handler.replace(/\\/g, "/");
30+
return posixHandler;
2931
}
3032

3133
get functionName() {

classes/PluginBuildDir.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ const path = require("path");
22
const fs = require("fs-extra");
33
const logger = require("../utils/logger");
44

5+
const BUILD_DIR_NAME = "sls-next-build";
6+
57
class PluginBuildDir {
68
constructor(nextConfigDir) {
79
this.nextConfigDir = nextConfigDir;
810
}
911

1012
get buildDir() {
11-
return path.join(this.nextConfigDir, "sls-next-build");
13+
return path.join(this.nextConfigDir, BUILD_DIR_NAME);
14+
}
15+
16+
get posixBuildDir() {
17+
return path.posix.join(this.nextConfigDir, BUILD_DIR_NAME);
1218
}
1319

1420
setupBuildDir() {

classes/__tests__/NextPage.test.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require("path");
12
const NextPage = require("../NextPage");
23

34
describe("NextPage", () => {
@@ -12,7 +13,7 @@ describe("NextPage", () => {
1213

1314
describe("When is the index page", () => {
1415
const buildDir = "build";
15-
const pagePath = `${buildDir}/index.js`;
16+
const pagePath = path.join(buildDir, "index.js");
1617
let page;
1718

1819
beforeEach(() => {
@@ -33,7 +34,7 @@ describe("NextPage", () => {
3334

3435
describe("When is the _error page", () => {
3536
const buildDir = "build";
36-
const pagePath = `${buildDir}/_error.js`;
37+
const pagePath = path.join(buildDir, "_error.js");
3738
let page;
3839

3940
beforeEach(() => {
@@ -58,7 +59,7 @@ describe("NextPage", () => {
5859

5960
describe("When is a nested page", () => {
6061
const buildDir = "build";
61-
const pagePath = `${buildDir}/categories/fridge/fridges.js`;
62+
const pagePath = path.join(buildDir, "categories/fridge/fridges.js");
6263
let page;
6364

6465
beforeEach(() => {
@@ -79,6 +80,20 @@ describe("NextPage", () => {
7980
});
8081
});
8182

83+
describe("When pagePath has win format", () => {
84+
const buildDir = "build";
85+
const pagePath = `${buildDir}\\admin.js`;
86+
let page;
87+
88+
beforeEach(() => {
89+
page = new NextPage(pagePath);
90+
});
91+
92+
it("should return posix pageHandler", () => {
93+
expect(page.pageHandler).toEqual("build/admin.render");
94+
});
95+
});
96+
8297
describe("When a new instance is created", () => {
8398
const buildDir = "build";
8499
const pagePath = `${buildDir}/admin.js`;
@@ -89,11 +104,15 @@ describe("NextPage", () => {
89104
});
90105

91106
it("should have pageCompatPath", () => {
92-
expect(page.pageCompatPath).toEqual(`${buildDir}/admin.compat.js`);
107+
expect(page.pageCompatPath).toEqual(
108+
path.join(buildDir, "admin.compat.js")
109+
);
93110
});
94111

95112
it("should return pageOriginalPath", () => {
96-
expect(page.pageOriginalPath).toEqual(`${buildDir}/admin.original.js`);
113+
expect(page.pageOriginalPath).toEqual(
114+
path.join(buildDir, "admin.original.js")
115+
);
97116
});
98117

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

classes/__tests__/PluginBuildDir.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require("path");
12
const fs = require("fs-extra");
23
const PluginBuildDir = require("../PluginBuildDir");
34
const logger = require("../../utils/logger");
@@ -17,14 +18,23 @@ describe("PluginBuildDir", () => {
1718

1819
describe("When a new instance is created", () => {
1920
let pluginBuildDir;
21+
let nextConfigDir;
2022

2123
beforeEach(() => {
22-
const nextConfigDir = "path/to/nextApp";
24+
nextConfigDir = "path/to/nextApp";
2325
pluginBuildDir = new PluginBuildDir(nextConfigDir);
2426
});
2527

26-
it("should have buildDir one level above nextBuild", () => {
27-
expect(pluginBuildDir.buildDir).toEqual("path/to/nextApp/sls-next-build");
28+
it("should have buildDir at same level as next config.", () => {
29+
expect(pluginBuildDir.buildDir).toEqual(
30+
path.join(nextConfigDir, "sls-next-build")
31+
);
32+
});
33+
34+
it("should have posixBuildDir regardless the platform", () => {
35+
expect(pluginBuildDir.posixBuildDir).toEqual(
36+
"path/to/nextApp/sls-next-build"
37+
);
2838
});
2939
});
3040

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.join(pluginBuildDir.buildDir, "**"));
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe("copyBuildFiles", () => {
1313

1414
describe("when page files are copied correctly", () => {
1515
let pluginBuildDirObj;
16-
const pluginBuildDir = "path/to/sls-next-build";
17-
const nextBuildDir = "path/to/.next";
16+
const pluginBuildDir = path.normalize("path/to/sls-next-build");
17+
const nextBuildDir = path.normalize("path/to/.next");
1818

1919
beforeEach(() => {
2020
fse.copy.mockResolvedValue(null);
@@ -39,7 +39,7 @@ describe("copyBuildFiles", () => {
3939

4040
it("should copy serverless pages folder from next build directory", () => {
4141
expect(fse.copy).toBeCalledWith(
42-
`${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-
`${pluginBuildDir}/compatLayer.js`
54+
path.join(pluginBuildDir, "compatLayer.js")
5555
);
5656
});
5757
});

lib/__tests__/getCompatLayerCode.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1+
const path = require("path");
12
const getCompatLayerCode = require("../getCompatLayerCode");
23

34
describe("getCompatLayerCode", () => {
45
it("should require compatLayer", () => {
56
const compatHandlerContent = getCompatLayerCode(
6-
"sls-next-build/my-page.js"
7+
path.join("sls-next-build", "my-page.js")
78
);
89
expect(compatHandlerContent).toContain('require("./compatLayer")');
910
});
1011

1112
it("should require compatLayer with correct path when page is nested", () => {
1213
const compatHandlerContent = getCompatLayerCode(
13-
"sls-next-build/categories/fridge/fridges.js"
14+
path.join("sls-next-build", "categories/fridge/fridges.js")
1415
);
1516
expect(compatHandlerContent).toContain('require("../../compatLayer")');
1617
});
1718

1819
it("should require next page provided", () => {
1920
const compatHandlerContent = getCompatLayerCode(
20-
"sls-next-build/my-page.js"
21+
path.join("sls-next-build", "my-page.js")
2122
);
2223
expect(compatHandlerContent).toContain('require("./my-page.original.js")');
2324
});
2425

2526
it("should export render method", () => {
2627
const compatHandlerContent = getCompatLayerCode(
27-
"sls-next-build/my-page.js"
28+
path.join("sls-next-build", "my-page.js")
2829
);
2930
expect(compatHandlerContent).toContain("module.exports.render");
3031
});

0 commit comments

Comments
 (0)