-
-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lambda-at-edge): for serverless-trace target, exclude files that … #758
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...edge/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.next |
3 changes: 3 additions & 0 deletions
3
.../integration/serverless-trace-with-dynamic-import-typescript/fixture/components/hello.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as React from "react"; | ||
|
||
export default () => <span>Hello World</span>; |
2 changes: 2 additions & 0 deletions
2
...e/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/next-env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
5 changes: 5 additions & 0 deletions
5
...ts/integration/serverless-trace-with-dynamic-import-typescript/fixture/pages/api/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default (req: any, res: any) => { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify({ name: "John Doe" })); | ||
}; |
15 changes: 15 additions & 0 deletions
15
...tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/pages/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import dynamic from "next/dynamic"; | ||
import * as React from "react"; | ||
|
||
const DynamicComponent = dynamic(() => import("../components/hello")); | ||
|
||
const Page = () => <DynamicComponent />; | ||
|
||
Page.getInitialProps = () => { | ||
// just forcing this page to be server side rendered | ||
return { | ||
foo: "bar" | ||
}; | ||
}; | ||
|
||
export default Page; |
29 changes: 29 additions & 0 deletions
29
...e/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
75 changes: 75 additions & 0 deletions
75
...ce-with-dynamic-import-typescript/serverless-trace-with-dynamic-import-typescript.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { remove, readdir, pathExists } from "fs-extra"; | ||
import path from "path"; | ||
import os from "os"; | ||
import Builder from "../../../src/build"; | ||
import { getNextBinary } from "../../test-utils"; | ||
import klaw from "klaw"; | ||
|
||
jest.unmock("execa"); | ||
|
||
describe("Serverless Trace With Dynamic Import - TypeScript", () => { | ||
const nextBinary = getNextBinary(); | ||
const fixtureDir = path.join(__dirname, "./fixture"); | ||
let outputDir: string; | ||
|
||
beforeAll(async () => { | ||
outputDir = path.join(os.tmpdir(), "slsnext-test-build"); | ||
const builder = new Builder(fixtureDir, outputDir, { | ||
cwd: fixtureDir, | ||
cmd: nextBinary, | ||
args: ["build"], | ||
useServerlessTraceTarget: true | ||
}); | ||
|
||
await builder.build(); | ||
}); | ||
|
||
afterAll(() => { | ||
return Promise.all( | ||
[".next"].map((file) => remove(path.join(fixtureDir, file))) | ||
); | ||
}); | ||
|
||
it("copies node_modules to default lambda artefact", async () => { | ||
const nodeModules = await readdir( | ||
path.join(outputDir, "default-lambda/node_modules") | ||
); | ||
expect(nodeModules.length).toBeGreaterThan(5); // 5 is just an arbitrary number to ensure dependencies are being copied | ||
}); | ||
|
||
it("copies node_modules to api lambda artefact", async () => { | ||
const nodeModules = await readdir( | ||
path.join(outputDir, "api-lambda/node_modules") | ||
); | ||
expect(nodeModules).toEqual(["next"]); | ||
}); | ||
|
||
it("copies dynamic chunk to default lambda artefact", async () => { | ||
const chunkFileName = ( | ||
await readdir(path.join(fixtureDir, ".next/serverless")) | ||
).find((file) => { | ||
return /^[\d]+\.+[\w,\s-]+\.(js)$/.test(file); | ||
}); | ||
|
||
expect(chunkFileName).toBeDefined(); | ||
|
||
const chunkExistsInOutputBuild = await pathExists( | ||
path.join(outputDir, "default-lambda", chunkFileName as string) | ||
); | ||
|
||
expect(chunkExistsInOutputBuild).toBe(true); | ||
}); | ||
|
||
it("does not copy TypeScript sources", async () => { | ||
const defaultLambdaFiles: string[] = []; | ||
klaw(path.join(outputDir, "default-lambda")).on("data", (item) => | ||
defaultLambdaFiles.push(item.path) | ||
); | ||
|
||
const typeScriptFileName = defaultLambdaFiles.find((file) => { | ||
return /^[\d]+\.+[\w,\s-]+\.(ts|tsx)$/.test(file); | ||
}); | ||
|
||
expect(typeScriptFileName).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we could prevent FS from copying if src == dest but I think this should work for now.