@platformatic/service 0.28.1 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/fixtures/hello-client-ts/tsconfig.json +3 -2
  2. package/fixtures/hello-client-ts-without-deps/hello.d.ts +34 -0
  3. package/fixtures/hello-client-ts-without-deps/hello.openapi.json +22 -0
  4. package/fixtures/hello-client-ts-without-deps/platformatic.service.json +23 -0
  5. package/fixtures/hello-client-ts-without-deps/plugin.ts +8 -0
  6. package/fixtures/hello-client-ts-without-deps/tsconfig.json +22 -0
  7. package/fixtures/hello-client-without-deps/hello.d.ts +34 -0
  8. package/fixtures/hello-client-without-deps/hello.openapi.json +22 -0
  9. package/fixtures/hello-client-without-deps/platformatic.service.json +21 -0
  10. package/fixtures/hello-client-without-deps/plugin.js +8 -0
  11. package/help/compile.txt +2 -1
  12. package/index.js +9 -1
  13. package/lib/compile.js +14 -11
  14. package/lib/plugins/clients.js +7 -3
  15. package/lib/plugins/plugins.js +20 -8
  16. package/lib/schema.js +50 -4
  17. package/package.json +6 -6
  18. package/test/cli/compile-1.test.mjs +500 -0
  19. package/test/cli/{compile.test.mjs → compile-2.test.mjs} +173 -149
  20. package/test/cli/helper.mjs +15 -0
  21. package/test/cli/tap-parallel-not-ok +0 -0
  22. package/test/clients.test.js +27 -2
  23. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +1 -1
  24. package/test/fixtures/bad-typescript-plugin/tsconfig.json +1 -1
  25. package/test/fixtures/typescript-autoload/tsconfig.json +3 -3
  26. package/test/fixtures/typescript-compiled/compiled/plugin.js +6 -0
  27. package/test/fixtures/typescript-compiled/platformatic.service.json +18 -0
  28. package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +18 -0
  29. package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +5 -0
  30. package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +22 -0
  31. package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +22 -0
  32. package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +18 -0
  33. package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +5 -0
  34. package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +3 -3
  35. package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +18 -0
  36. package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +5 -0
  37. package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +22 -0
  38. package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +16 -0
  39. package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +5 -0
  40. package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +22 -0
  41. package/test/fixtures/typescript-plugin-string/platformatic.service.json +16 -0
  42. package/test/fixtures/typescript-plugin-string/plugin.ts +5 -0
  43. package/test/fixtures/typescript-plugin-string/tsconfig.json +22 -0
  44. package/test/tap-parallel-ok +0 -0
@@ -1,68 +1,113 @@
1
1
  import path from 'path'
2
2
  import os from 'os'
3
- import { access, rename, cp } from 'fs/promises'
3
+ import { access, cp, rm, mkdir } from 'fs/promises'
4
4
  import t from 'tap'
5
5
  import { execa } from 'execa'
6
6
  import stripAnsi from 'strip-ansi'
7
7
  import split from 'split2'
8
- import { cliPath } from './helper.mjs'
8
+ import { cliPath, safeKill } from './helper.mjs'
9
9
  import { fileURLToPath } from 'url'
10
10
 
11
+ let count = 0
12
+
13
+ if (os.platform() !== 'win32') {
14
+ t.jobs = 5
15
+ }
16
+ t.setTimeout(360000)
17
+
11
18
  function urlDirname (url) {
12
19
  return path.dirname(fileURLToPath(url))
13
20
  }
14
21
 
22
+ async function getCWD (t) {
23
+ const dir = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone2-${count++}`)
24
+ try {
25
+ await rm(dir, { recursive: true })
26
+ } catch {}
27
+
28
+ await mkdir(dir, { recursive: true })
29
+
30
+ t.teardown(async () => {
31
+ try {
32
+ await rm(dir, { recursive: true })
33
+ } catch {}
34
+ })
35
+ return dir
36
+ }
37
+
15
38
  function exitOnTeardown (child) {
16
39
  return async () => {
17
- if (os.platform() === 'win32') {
18
- try {
19
- await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
20
- } catch (err) {
21
- console.error(`Failed to kill process ${child.pid})`)
22
- }
23
- } else {
24
- child.kill('SIGINT')
25
- }
40
+ await safeKill(child)
26
41
  }
27
42
  }
28
43
 
29
- t.test('should compile typescript plugin', async (t) => {
30
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
31
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-1')
44
+ t.test('start command should not compile typescript if `typescript` is false', async (t) => {
45
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
46
+ const cwd = await getCWD(t)
32
47
 
33
48
  await cp(testDir, cwd, { recursive: true })
34
49
 
35
- const child = execa('node', [cliPath, 'compile'], { cwd })
50
+ const child = execa('node', [cliPath, 'start'], { cwd })
51
+ t.teardown(exitOnTeardown(child))
52
+
53
+ const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
54
+ try {
55
+ await access(jsPluginPath)
56
+ t.fail("should not have created 'dist/plugin.js'")
57
+ } catch (err) {
58
+ // cannot start because the plugin is not compiled
59
+ t.equal(err.code, 'ENOENT')
60
+ t.equal(err.path, jsPluginPath)
61
+ t.pass()
62
+ }
63
+ })
64
+
65
+ t.test('should compile typescript plugin with start command with different cwd', async (t) => {
66
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
67
+ const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone-${count++}`)
68
+
69
+ await cp(testDir, dest, { recursive: true })
70
+
71
+ const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
36
72
 
37
73
  t.teardown(exitOnTeardown(child))
38
74
 
39
75
  const splitter = split()
40
76
  child.stdout.pipe(splitter)
77
+ child.stderr.pipe(process.stderr)
41
78
 
42
79
  for await (const data of splitter) {
43
80
  const sanitized = stripAnsi(data)
44
- if (sanitized.includes('Typescript compilation completed successfully.')) {
45
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
46
- try {
47
- await access(jsPluginPath)
48
- } catch (err) {
49
- t.fail(err)
50
- }
51
-
81
+ if (sanitized.includes('Typescript plugin loaded')) {
52
82
  t.pass()
53
83
  return
54
84
  }
55
85
  }
56
- t.fail('should compile typescript plugin with a compile command')
86
+ t.fail('should compile typescript plugin with start command')
57
87
  })
58
88
 
59
- t.test('should compile typescript plugin even if typescript is `false`', async (t) => {
60
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
61
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-2')
89
+ t.test('valid tsconfig file inside an inner folder', async (t) => {
90
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
91
+ const cwd = await getCWD(t)
62
92
 
63
93
  await cp(testDir, cwd, { recursive: true })
64
94
 
65
- const child = execa('node', [cliPath, 'compile'], { cwd })
95
+ try {
96
+ await execa('node', [cliPath, 'compile'], { cwd, stdio: 'inherit' })
97
+ } catch (err) {
98
+ t.fail('should not catch any error')
99
+ }
100
+
101
+ t.pass()
102
+ })
103
+
104
+ t.test('should compile typescript plugin with start command from a folder', async (t) => {
105
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-autoload')
106
+ const cwd = await getCWD(t)
107
+
108
+ await cp(testDir, cwd, { recursive: true })
109
+
110
+ const child = execa('node', [cliPath, 'start'], { cwd })
66
111
 
67
112
  t.teardown(exitOnTeardown(child))
68
113
 
@@ -71,27 +116,22 @@ t.test('should compile typescript plugin even if typescript is `false`', async (
71
116
 
72
117
  for await (const data of splitter) {
73
118
  const sanitized = stripAnsi(data)
74
- if (sanitized.includes('Typescript compilation completed successfully.')) {
75
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
76
- try {
77
- await access(jsPluginPath)
78
- } catch (err) {
79
- t.fail(err)
80
- }
81
-
119
+ if (sanitized.includes('Typescript plugin loaded')) {
82
120
  t.pass()
83
121
  return
84
122
  }
85
123
  }
86
- t.fail('should compile typescript plugin with a compile command')
124
+ t.fail('should compile typescript plugin with start command')
87
125
  })
88
126
 
89
- t.test('should compile typescript plugin with start command', async (t) => {
90
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
91
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-3')
127
+ t.test('should start the service if it was precompiled and typescript is `false`', async (t) => {
128
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
129
+ const cwd = await getCWD(t)
92
130
 
93
131
  await cp(testDir, cwd, { recursive: true })
94
132
 
133
+ await execa('node', [cliPath, 'compile'], { cwd })
134
+
95
135
  const child = execa('node', [cliPath, 'start'], { cwd })
96
136
 
97
137
  const splitter = split()
@@ -104,176 +144,160 @@ t.test('should compile typescript plugin with start command', async (t) => {
104
144
  return
105
145
  }
106
146
  }
107
- t.fail('should compile typescript plugin with start command')
147
+ t.fail('should load the typescript plugin without compiling it')
108
148
  })
109
149
 
110
- t.test('should not compile bad typescript plugin', async (t) => {
111
- const cwd = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
150
+ t.test('should not start the service if it was not precompiled and typescript is `false`', async (t) => {
151
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
152
+ const cwd = await getCWD(t)
112
153
 
113
- try {
114
- await execa('node', [cliPath, 'compile'], { cwd })
115
- t.fail('should not compile bad typescript plugin')
116
- } catch (err) {
117
- t.comment(err.stdout)
118
- t.comment(err.stderr)
119
- t.equal(err.stdout.includes('Found 1 error in plugin.ts'), true)
120
- }
154
+ await cp(testDir, cwd, { recursive: true })
121
155
 
122
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
123
- try {
124
- await access(jsPluginPath)
125
- t.fail('should not compile bad typescript plugin')
126
- } catch (err) {
127
- t.pass(err)
156
+ const child = execa('node', [cliPath, 'start'], { cwd })
157
+
158
+ const splitter = split()
159
+ child.stdout.pipe(splitter)
160
+ child.stderr.pipe(splitter)
161
+
162
+ for await (const data of splitter) {
163
+ const sanitized = stripAnsi(data)
164
+ if (sanitized.includes('Unknown file extension ".ts" for')) {
165
+ t.pass()
166
+ return
167
+ }
128
168
  }
169
+ t.fail('should load the typescript plugin without compiling it')
129
170
  })
130
171
 
131
- t.test('missing tsconfig file', async (t) => {
132
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
133
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-4')
172
+ t.test('should compile typescript plugin with string config', async (t) => {
173
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-string')
174
+ const cwd = await getCWD(t)
134
175
 
135
176
  await cp(testDir, cwd, { recursive: true })
136
177
 
137
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
138
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
139
-
140
- await rename(pathToTSConfig, pathToTSConfigBackup)
141
-
142
- try {
143
- await execa('node', [cliPath, 'compile'], { cwd })
144
- t.fail('should not compile typescript plugin')
145
- } catch (err) {
146
- t.comment(err.stdout)
147
- t.comment(err.stderr)
148
- t.equal(err.stdout.includes('The tsconfig.json file was not found.'), true)
149
- }
150
-
151
- t.pass()
152
- })
178
+ const child = execa('node', [cliPath, 'compile'], { cwd })
153
179
 
154
- t.test('start command should not compile typescript plugin with errors', async (t) => {
155
- const cwd = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
180
+ t.teardown(exitOnTeardown(child))
156
181
 
157
- const childProcess = execa('node', [cliPath, 'start'], { cwd })
182
+ const splitter = split()
183
+ child.stdout.pipe(splitter)
158
184
 
159
- t.teardown(() => {
160
- childProcess.kill('SIGINT')
161
- })
185
+ for await (const data of splitter) {
186
+ const sanitized = stripAnsi(data)
187
+ if (sanitized.includes('Typescript compilation completed successfully.')) {
188
+ const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
189
+ try {
190
+ await access(jsPluginPath)
191
+ } catch (err) {
192
+ t.fail(err)
193
+ }
162
194
 
163
- try {
164
- await childProcess
165
- t.fail('should not compile bad typescript plugin')
166
- } catch (err) {
167
- if (!err.stdout.includes('Found 1 error')) {
168
- t.comment(err.stdout)
169
- t.comment(err.stderr)
170
- t.fail('should throw one ts error')
195
+ t.pass()
196
+ return
171
197
  }
172
- childProcess.kill('SIGINT')
173
- }
174
-
175
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
176
- try {
177
- await access(jsPluginPath)
178
- t.fail('should not compile bad typescript plugin')
179
- } catch (err) {
180
- t.pass(err)
181
198
  }
199
+ t.fail('should compile typescript plugin with a compile command')
182
200
  })
183
201
 
184
- t.test('should not compile typescript plugin with start without tsconfig', async (t) => {
185
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
186
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-5')
202
+ t.test('should not start the service if it was not precompiled and typescript is `"false"`', async (t) => {
203
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
204
+ const cwd = await getCWD(t)
187
205
 
188
206
  await cp(testDir, cwd, { recursive: true })
189
207
 
190
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
191
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
208
+ const child = execa('node', [cliPath, 'start'], { cwd })
192
209
 
193
- await rename(pathToTSConfig, pathToTSConfigBackup)
210
+ const splitter = split()
211
+ child.stdout.pipe(splitter)
212
+ child.stderr.pipe(splitter)
194
213
 
195
- try {
196
- const child = await execa('node', [cliPath, 'start'], { cwd })
197
- t.teardown(() => child.kill('SIGINT'))
198
- t.fail('should not compile typescript plugin with start without tsconfig')
199
- } catch (err) {
200
- t.comment(err.stdout)
201
- t.equal(err.stdout.includes('The tsconfig.json file was not found.'), true)
214
+ for await (const data of splitter) {
215
+ const sanitized = stripAnsi(data)
216
+ if (sanitized.includes('Unknown file extension ".ts" for')) {
217
+ t.pass()
218
+ return
219
+ }
202
220
  }
221
+ t.fail('should load the typescript plugin without compiling it')
203
222
  })
204
223
 
205
- t.test('start command should not compile typescript if `typescript` is false', async (t) => {
206
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
207
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-6')
224
+ t.test('should compile typescript plugin with start command with custom tsconfig', async (t) => {
225
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-custom-tsconfig')
226
+ const cwd = await getCWD(t)
208
227
 
209
228
  await cp(testDir, cwd, { recursive: true })
210
229
 
211
230
  const child = execa('node', [cliPath, 'start'], { cwd })
212
- t.teardown(exitOnTeardown(child))
213
231
 
214
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
215
- try {
216
- await access(jsPluginPath)
217
- t.fail("should not have created 'dist/plugin.js'")
218
- } catch (err) {
219
- // cannot start because the plugin is not compiled
220
- t.equal(err.code, 'ENOENT')
221
- t.equal(err.path, jsPluginPath)
222
- t.pass()
232
+ const splitter = split()
233
+ child.stdout.pipe(splitter)
234
+ child.stderr.pipe(splitter)
235
+
236
+ for await (const data of splitter) {
237
+ const sanitized = stripAnsi(data)
238
+ if (sanitized.includes('Typescript plugin loaded')) {
239
+ t.pass()
240
+ return
241
+ }
223
242
  }
243
+ t.fail('should compile typescript plugin with start command')
224
244
  })
225
245
 
226
- t.test('should compile typescript plugin with start command with different cwd', async (t) => {
227
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
228
- const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-4')
229
-
230
- await cp(testDir, dest, { recursive: true })
246
+ t.test('should not start the service if it was not precompiled and typescript is `false`', async (t) => {
247
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile-enabled')
248
+ const cwd = await getCWD(t)
231
249
 
232
- const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
250
+ await cp(testDir, cwd, { recursive: true })
233
251
 
234
- t.teardown(exitOnTeardown(child))
252
+ const child = execa('node', [cliPath, 'start'], { cwd })
235
253
 
236
254
  const splitter = split()
237
255
  child.stdout.pipe(splitter)
238
- child.stderr.pipe(process.stderr)
256
+ child.stderr.pipe(splitter)
239
257
 
240
258
  for await (const data of splitter) {
241
259
  const sanitized = stripAnsi(data)
242
- if (sanitized.includes('Typescript plugin loaded')) {
260
+ if (sanitized.includes('Unknown file extension ".ts" for')) {
243
261
  t.pass()
244
262
  return
245
263
  }
246
264
  }
247
- t.fail('should compile typescript plugin with start command')
265
+ t.fail('should load the typescript plugin without compiling it')
248
266
  })
249
267
 
250
- t.test('valid tsconfig file inside an inner folder', async (t) => {
251
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
252
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-7/inner-folder')
268
+ t.test('should start without a tsconfig but with a outDir configuration', async (t) => {
269
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-compiled')
270
+ const cwd = await getCWD(t)
253
271
 
254
272
  await cp(testDir, cwd, { recursive: true })
255
273
 
256
- try {
257
- await execa('node', [cliPath, 'compile'], { cwd, stdio: 'inherit' })
258
- } catch (err) {
259
- t.fail('should not catch any error')
260
- }
274
+ const child = execa('node', [cliPath, 'start'], { cwd })
261
275
 
262
- t.pass()
276
+ const splitter = split()
277
+ child.stdout.pipe(splitter)
278
+ child.stderr.pipe(splitter)
279
+
280
+ for await (const data of splitter) {
281
+ const sanitized = stripAnsi(data)
282
+ if (sanitized.includes('Typescript plugin loaded')) {
283
+ t.pass()
284
+ return
285
+ }
286
+ }
287
+ t.fail('should compile typescript plugin with start command')
263
288
  })
264
289
 
265
- t.test('should compile typescript plugin with start command from a folder', async (t) => {
266
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-autoload')
267
- const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-8')
290
+ t.test('should compile typescript plugin with start command with custom flags', async (t) => {
291
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-custom-flags')
292
+ const cwd = await getCWD(t)
268
293
 
269
294
  await cp(testDir, cwd, { recursive: true })
270
295
 
271
296
  const child = execa('node', [cliPath, 'start'], { cwd })
272
297
 
273
- t.teardown(exitOnTeardown(child))
274
-
275
298
  const splitter = split()
276
299
  child.stdout.pipe(splitter)
300
+ child.stderr.pipe(splitter)
277
301
 
278
302
  for await (const data of splitter) {
279
303
  const sanitized = stripAnsi(data)
@@ -4,6 +4,7 @@ import { execa } from 'execa'
4
4
  import split from 'split2'
5
5
  import { join } from 'desm'
6
6
  import tap from 'tap'
7
+ import os from 'node:os'
7
8
 
8
9
  setGlobalDispatcher(new Agent({
9
10
  keepAliveTimeout: 10,
@@ -50,3 +51,17 @@ export async function start (commandOpts, exacaOpts = {}) {
50
51
  }
51
52
  }
52
53
  }
54
+
55
+ export async function safeKill (child) {
56
+ child.kill('SIGINT')
57
+ if (os.platform() === 'win32') {
58
+ try {
59
+ await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
60
+ } catch (err) {
61
+ if (err.stderr.indexOf('not found') === 0) {
62
+ console.error(`Failed to kill process ${child.pid}`)
63
+ console.error(err)
64
+ }
65
+ }
66
+ }
67
+ }
File without changes
@@ -6,7 +6,7 @@ const { buildServer } = require('..')
6
6
  const { join } = require('path')
7
7
  const { request } = require('undici')
8
8
  const { compile } = require('../lib/compile')
9
- const { rmdir } = require('fs/promises')
9
+ const { rm } = require('fs/promises')
10
10
 
11
11
  test('client is loaded', async ({ teardown, equal, same }) => {
12
12
  const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
@@ -44,10 +44,12 @@ test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
44
44
  const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
45
45
 
46
46
  try {
47
- await rmdir(join(targetDir, 'dist'))
47
+ await rm(join(targetDir, 'dist'), { recursive: true })
48
48
  } catch {}
49
49
 
50
+ console.time('compile')
50
51
  await compile(targetDir, { server: { logger: { level: 'warn' } } })
52
+ console.timeEnd('compile')
51
53
 
52
54
  const app2 = await buildServer(join(targetDir, 'platformatic.service.json'))
53
55
  teardown(async () => {
@@ -60,3 +62,26 @@ test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
60
62
  const data = await res.body.json()
61
63
  same(data, { hello: 'world' })
62
64
  })
65
+
66
+ test('client is loaded dependencyless', async ({ teardown, equal, same }) => {
67
+ const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
68
+
69
+ teardown(async () => {
70
+ await app1.close()
71
+ })
72
+ await app1.start()
73
+
74
+ process.env.PLT_CLIENT_URL = app1.url
75
+
76
+ const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client-without-deps', 'platformatic.service.json'))
77
+
78
+ teardown(async () => {
79
+ await app2.close()
80
+ })
81
+ await app2.start()
82
+
83
+ const res = await request(`${app2.url}/`)
84
+ equal(res.statusCode, 200, 'status code')
85
+ const data = await res.body.json()
86
+ same(data, { hello: 'world' })
87
+ })
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "hostname": "127.0.0.1",
7
7
  "port": "3042",
8
- "pluginTimeout": 30000,
8
+ "pluginTimeout": 60000,
9
9
  "keepAliveTimeout": 1
10
10
  },
11
11
  "plugins": {
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "module": "commonjs",
4
4
  "esModuleInterop": true,
5
- "target": "es6",
5
+ "target": "es2020",
6
6
  "moduleResolution": "node",
7
7
  "sourceMap": true,
8
8
  "pretty": true,
@@ -2,10 +2,10 @@
2
2
  "compilerOptions": {
3
3
  "module": "commonjs",
4
4
  "esModuleInterop": true,
5
- "target": "es2019",
5
+ "target": "es2020",
6
6
  "moduleResolution": "node",
7
- "sourceMap": true,
8
- "pretty": true,
7
+ "sourceMap": false,
8
+ "pretty": false,
9
9
  "noEmitOnError": true,
10
10
  "outDir": "dist"
11
11
  },
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+
3
+ async function plugin (app) {
4
+ app.log.info('Typescript plugin loaded')
5
+ }
6
+ module.exports = plugin
@@ -0,0 +1,18 @@
1
+ {
2
+ "server": {
3
+ "logger": {
4
+ "level": "info"
5
+ },
6
+ "hostname": "127.0.0.1",
7
+ "port": "0",
8
+ "pluginTimeout": 60000,
9
+ "keepAliveTimeout": 1
10
+ },
11
+ "plugins": {
12
+ "paths": ["plugin.ts"],
13
+ "typescript": {
14
+ "outDir": "compiled"
15
+ }
16
+ },
17
+ "watch": false
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "server": {
3
+ "logger": {
4
+ "level": "info"
5
+ },
6
+ "hostname": "127.0.0.1",
7
+ "port": "0",
8
+ "pluginTimeout": 60000,
9
+ "keepAliveTimeout": 1
10
+ },
11
+ "plugins": {
12
+ "paths": ["plugin.ts"],
13
+ "typescript": {
14
+ "flags": ["-b"]
15
+ }
16
+ },
17
+ "watch": false
18
+ }
@@ -0,0 +1,5 @@
1
+ import { FastifyInstance } from 'fastify'
2
+
3
+ export default async function (app: FastifyInstance) {
4
+ app.log.info('Typescript plugin loaded')
5
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "esModuleInterop": true,
5
+ "target": "es2020",
6
+ "moduleResolution": "node",
7
+ "sourceMap": false,
8
+ "pretty": false,
9
+ "noEmitOnError": true,
10
+ "outDir": "dist"
11
+ },
12
+ "watchOptions": {
13
+ "watchFile": "fixedPollingInterval",
14
+ "watchDirectory": "fixedPollingInterval",
15
+ "fallbackPolling": "dynamicPriority",
16
+ "synchronousWatchDirectory": true,
17
+ "excludeDirectories": [
18
+ "**/node_modules",
19
+ "dist"
20
+ ]
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "esModuleInterop": true,
5
+ "target": "es6",
6
+ "moduleResolution": "node",
7
+ "sourceMap": true,
8
+ "pretty": true,
9
+ "noEmitOnError": true,
10
+ "outDir": "dist"
11
+ },
12
+ "watchOptions": {
13
+ "watchFile": "fixedPollingInterval",
14
+ "watchDirectory": "fixedPollingInterval",
15
+ "fallbackPolling": "dynamicPriority",
16
+ "synchronousWatchDirectory": true,
17
+ "excludeDirectories": [
18
+ "**/node_modules",
19
+ "dist"
20
+ ]
21
+ }
22
+ }