File size: 5,347 Bytes
b2cad4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
diff --git a/test/production/standalone-mode/server-action-externals/app/actions.ts b/test/production/standalone-mode/server-action-externals/app/actions.ts
new file mode 100644
index 0000000000..d7e81ac580
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/actions.ts
@@ -0,0 +1,10 @@
+'use server'
+
+import _ from 'lodash'
+import Queue from 'yocto-queue'
+
+export async function doStuff() {
+  const queue = new Queue<string>()
+  queue.enqueue(_.camelCase('hello world'))
+  return queue.dequeue() ?? ''
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/button.tsx b/test/production/standalone-mode/server-action-externals/app/button.tsx
new file mode 100644
index 0000000000..c45a38d655
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/button.tsx
@@ -0,0 +1,14 @@
+'use client'
+
+import { useState } from 'react'
+import { doStuff } from './actions'
+
+export function Button() {
+  const [result, setResult] = useState('')
+  return (
+    <>
+      <button onClick={async () => setResult(await doStuff())}>go</button>
+      <p id="result">{result}</p>
+    </>
+  )
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/layout.tsx b/test/production/standalone-mode/server-action-externals/app/layout.tsx
new file mode 100644
index 0000000000..888614deda
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/layout.tsx
@@ -0,0 +1,8 @@
+import { ReactNode } from 'react'
+export default function Root({ children }: { children: ReactNode }) {
+  return (
+    <html>
+      <body>{children}</body>
+    </html>
+  )
+}
diff --git a/test/production/standalone-mode/server-action-externals/app/page.tsx b/test/production/standalone-mode/server-action-externals/app/page.tsx
new file mode 100644
index 0000000000..24c9d8de35
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/app/page.tsx
@@ -0,0 +1,5 @@
+import { Button } from './button'
+
+export default function Page() {
+  return <Button />
+}
diff --git a/test/production/standalone-mode/server-action-externals/next.config.js b/test/production/standalone-mode/server-action-externals/next.config.js
new file mode 100644
index 0000000000..e362786ab0
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/next.config.js
@@ -0,0 +1,9 @@
+/**
+ * @type {import('next').NextConfig}
+ */
+const nextConfig = {
+  output: 'standalone',
+  serverExternalPackages: ['lodash', 'yocto-queue'],
+}
+
+module.exports = nextConfig
diff --git a/test/production/standalone-mode/server-action-externals/package.json b/test/production/standalone-mode/server-action-externals/package.json
new file mode 100644
index 0000000000..6f0860051d
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/package.json
@@ -0,0 +1,7 @@
+{
+  "dependencies": {
+    "@types/lodash": "4.17.13",
+    "lodash": "4.17.21",
+    "yocto-queue": "1.2.1"
+  }
+}
diff --git a/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts b/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts
new file mode 100644
index 0000000000..c146365258
--- /dev/null
+++ b/test/production/standalone-mode/server-action-externals/standalone-mode-server-action-externals.test.ts
@@ -0,0 +1,64 @@
+import { ChildProcess } from 'child_process'
+import { nextTestSetup } from 'e2e-utils'
+import fs from 'fs-extra'
+import { findPort, initNextServerScript, killApp, retry } from 'next-test-utils'
+import { join } from 'path'
+
+// The external packages are only imported by a server action, so the
+// standalone output only contains them if the route's trace includes them.
+describe('standalone mode: server action externals', () => {
+  let server: ChildProcess
+  let appPort: number
+
+  const { next } = nextTestSetup({
+    files: __dirname,
+    dependencies: require('./package.json').dependencies,
+    skipStart: true,
+  })
+
+  beforeAll(async () => {
+    await next.build()
+
+    await fs.move(
+      join(next.testDir, '.next/standalone'),
+      join(next.testDir, 'standalone')
+    )
+
+    await fs.copy(
+      join(next.testDir, '.next/static'),
+      join(next.testDir, 'standalone/.next/static')
+    )
+
+    // Remove everything else (including node_modules) so that the server can
+    // only load what the file traces brought into the standalone output.
+    for (const file of await fs.readdir(next.testDir)) {
+      if (file !== 'standalone') {
+        await fs.remove(join(next.testDir, file))
+      }
+    }
+
+    const testServer = join(next.testDir, 'standalone/server.js')
+    appPort = await findPort()
+    server = await initNextServerScript(testServer, /- Local:/, {
+      ...process.env,
+      ...next.env,
+      HOSTNAME: '::',
+      PORT: '' + appPort,
+    })
+  })
+
+  afterAll(async () => {
+    if (server) {
+      await killApp(server)
+    }
+  })
+
+  it('should execute a server action that uses external packages', async () => {
+    const browser = await next.browser('/', { baseUrl: appPort })
+    await browser.elementByCss('button').click()
+
+    await retry(async () => {
+      expect(await browser.elementByCss('#result').text()).toBe('helloWorld')
+    })
+  })
+})