@platformatic/service 0.15.1 → 0.16.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.
package/index.js CHANGED
@@ -97,9 +97,10 @@ async function platformaticService (app, opts, toLoad = []) {
97
97
  }
98
98
 
99
99
  async function loadPlugin (app, config, pluginOptions) {
100
- /* c8 ignore next 4 */
100
+ /* c8 ignore next 5 */
101
101
  if (pluginOptions.typescript !== undefined) {
102
- const pluginPath = getJSPluginPath(pluginOptions.path, pluginOptions.typescript.outDir)
102
+ const configPath = app.platformatic.configManager.fullPath
103
+ const pluginPath = getJSPluginPath(configPath, pluginOptions.path, pluginOptions.typescript.outDir)
103
104
  pluginOptions = { ...pluginOptions, path: pluginPath }
104
105
  }
105
106
 
@@ -107,8 +108,9 @@ async function loadPlugin (app, config, pluginOptions) {
107
108
 
108
109
  // if not defined, we defaults to true (which can happen only if config is set programmatically,
109
110
  // that's why we ignore the coverage of the `undefined` case, which cannot be covered in cli tests)
111
+ // all individual plugin hot reload settings will be overloaded by global hot reload
110
112
  /* c8 ignore next 35 */
111
- const hotReload = pluginOptions.hotReload !== false
113
+ const hotReload = config.hotReload ?? pluginOptions.hotReload !== false
112
114
  const isWatchEnabled = config.watch !== false
113
115
  if (isWatchEnabled && hotReload) {
114
116
  let options = pluginOptions
package/lib/compile.js CHANGED
@@ -53,7 +53,7 @@ async function execute (logger, args, config) {
53
53
  }
54
54
  }
55
55
 
56
- async function compileWatch () {
56
+ async function compileWatch (cwd) {
57
57
  const { execa } = await import('execa')
58
58
  const logger = pino(
59
59
  pretty({
@@ -62,8 +62,6 @@ async function compileWatch () {
62
62
  })
63
63
  )
64
64
 
65
- const cwd = process.cwd()
66
-
67
65
  const tscExecutablePath = await getTSCExecutablePath(cwd)
68
66
  /* c8 ignore next 4 */
69
67
  if (tscExecutablePath === undefined) {
package/lib/config.js CHANGED
@@ -38,6 +38,12 @@ class ServiceConfigManager extends ConfigManager {
38
38
  } else if (this.current.plugin) {
39
39
  this.current.plugin = fixPluginPath(this.current.plugin)
40
40
  }
41
+
42
+ // TODO: handle arrays
43
+ if (this.current.plugin?.typescript) {
44
+ const typescript = this.current.plugin.typescript
45
+ typescript.outDir = this._fixRelativePath(typescript.outDir)
46
+ }
41
47
  }
42
48
 
43
49
  _fixRelativePath (path) {
package/lib/schema.js CHANGED
@@ -249,6 +249,9 @@ const platformaticServiceSchema = {
249
249
  anyOf: [watch, {
250
250
  type: 'boolean'
251
251
  }]
252
+ },
253
+ hotReload: {
254
+ type: 'boolean'
252
255
  }
253
256
  },
254
257
  required: ['server']
package/lib/start.mjs CHANGED
@@ -23,8 +23,9 @@ async function start (_args) {
23
23
  config.plugin?.typescript?.build !== false
24
24
  ) {
25
25
  try {
26
- await compileWatch()
26
+ await compileWatch(dirname(configManager.fullPath))
27
27
  } catch (error) {
28
+ console.error(error)
28
29
  process.exit(1)
29
30
  }
30
31
  } else if (config.plugin?.typescript !== undefined && config.plugin?.typescript?.build === false) {
package/lib/utils.js CHANGED
@@ -41,14 +41,13 @@ function addLoggerToTheConfig (config) {
41
41
  }
42
42
  /* c8 ignore stop */
43
43
 
44
- function getJSPluginPath (tsPluginPath, compileDir) {
45
- const cwd = process.cwd()
46
- const tsPluginRelativePath = relative(cwd, tsPluginPath)
44
+ function getJSPluginPath (configPath, tsPluginPath, compileDir) {
45
+ const tsPluginRelativePath = relative(dirname(configPath), tsPluginPath)
47
46
  const jsPluginRelativePath = join(
48
47
  dirname(tsPluginRelativePath),
49
48
  basename(tsPluginRelativePath, '.ts') + '.js'
50
49
  )
51
- return join(cwd, compileDir, jsPluginRelativePath)
50
+ return join(compileDir, jsPluginRelativePath)
52
51
  }
53
52
 
54
53
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Matteo Collina <hello@matteocollina.com>",
@@ -54,8 +54,8 @@
54
54
  "pino-pretty": "^9.1.1",
55
55
  "rfdc": "^1.3.0",
56
56
  "ua-parser-js": "^1.0.32",
57
- "@platformatic/config": "0.15.1",
58
- "@platformatic/utils": "0.15.1"
57
+ "@platformatic/config": "0.16.0",
58
+ "@platformatic/utils": "0.16.0"
59
59
  },
60
60
  "standard": {
61
61
  "ignore": [
@@ -211,3 +211,36 @@ t.test('start command should not compile typescript if `build` is false', async
211
211
  t.pass()
212
212
  }
213
213
  })
214
+
215
+ t.test('should compile typescript plugin with start command with different cwd', async (t) => {
216
+ const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
217
+ const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-4')
218
+
219
+ await cp(testDir, dest, { recursive: true })
220
+
221
+ const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
222
+
223
+ t.teardown(async () => {
224
+ if (os.platform() === 'win32') {
225
+ try {
226
+ await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
227
+ } catch (err) {
228
+ console.error(`Failed to kill process ${child.pid})`)
229
+ }
230
+ } else {
231
+ child.kill('SIGINT')
232
+ }
233
+ })
234
+
235
+ const splitter = split()
236
+ child.stdout.pipe(splitter)
237
+
238
+ for await (const data of splitter) {
239
+ const sanitized = stripAnsi(data)
240
+ if (sanitized.includes('Typescript plugin loaded')) {
241
+ t.pass()
242
+ return
243
+ }
244
+ }
245
+ t.fail('should compile typescript plugin with start command')
246
+ })
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function default_1(app) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ app.log.info('Typescript plugin loaded');
15
+ });
16
+ }
17
+ exports.default = default_1;
18
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../plugin.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,mBAA+B,GAAoB;;QACjD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IAC1C,CAAC;CAAA;AAFD,4BAEC"}
@@ -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
+ }
@@ -7,8 +7,8 @@ const { join, resolve } = require('path')
7
7
  test('should get the path of a JS plugin', (t) => {
8
8
  t.plan(1)
9
9
 
10
- const result = getJSPluginPath('plugin.ts', 'dist')
11
- const expected = join(process.cwd(), 'dist', 'plugin.js')
10
+ const result = getJSPluginPath('/something/platformatic.service.json', '/something/plugin.ts', '/something/dist')
11
+ const expected = join('/something', 'dist', 'plugin.js')
12
12
  t.equal(result, expected)
13
13
  })
14
14