@platformatic/basic 2.68.0 → 2.69.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
@@ -1,8 +1,8 @@
1
1
  import { ConfigManager } from '@platformatic/config'
2
- import { createRequire } from '@platformatic/utils'
2
+ import { detectApplicationType } from '@platformatic/utils'
3
3
  import jsonPatch from 'fast-json-patch'
4
- import { existsSync } from 'node:fs'
5
4
  import { readFile } from 'node:fs/promises'
5
+ import { createRequire } from 'node:module'
6
6
  import { relative, resolve } from 'node:path'
7
7
  import { workerData } from 'node:worker_threads'
8
8
  import pino from 'pino'
@@ -11,28 +11,6 @@ import { importFile } from './lib/utils.js'
11
11
 
12
12
  const importStackablePackageMarker = '__pltImportStackablePackage.js'
13
13
 
14
- export const configCandidates = [
15
- 'platformatic.application.json',
16
- 'platformatic.json',
17
- 'watt.json',
18
- 'platformatic.application.yaml',
19
- 'platformatic.yaml',
20
- 'watt.yaml',
21
- 'platformatic.application.yml',
22
- 'platformatic.yml',
23
- 'watt.yml',
24
- 'platformatic.application.toml',
25
- 'platformatic.toml',
26
- 'watt.toml',
27
- 'platformatic.application.tml',
28
- 'platformatic.tml',
29
- 'watt.tml'
30
- ]
31
-
32
- function hasDependency (packageJson, dependency) {
33
- return packageJson.dependencies?.[dependency] || packageJson.devDependencies?.[dependency]
34
- }
35
-
36
14
  function isImportFailedError (error, pkg) {
37
15
  if (error.code !== 'ERR_MODULE_NOT_FOUND' && error.code !== 'MODULE_NOT_FOUND') {
38
16
  return false
@@ -70,31 +48,6 @@ async function importStackablePackage (directory, pkg) {
70
48
  }
71
49
  }
72
50
 
73
- export async function detectStackable (root, packageJson) {
74
- let name = '@platformatic/node'
75
- let label = 'Node.js'
76
-
77
- if (hasDependency(packageJson, '@nestjs/core')) {
78
- name = '@platformatic/nest'
79
- label = 'NestJS'
80
- } else if (hasDependency(packageJson, 'next')) {
81
- name = '@platformatic/next'
82
- label = 'Next.js'
83
- } else if (hasDependency(packageJson, '@remix-run/dev')) {
84
- name = '@platformatic/remix'
85
- label = 'Remix'
86
- } else if (hasDependency(packageJson, 'astro')) {
87
- name = '@platformatic/astro'
88
- label = 'Astro'
89
- // Since Vite is often used with other frameworks, we must check for Vite last
90
- } else if (hasDependency(packageJson, 'vite')) {
91
- name = '@platformatic/vite'
92
- label = 'Vite'
93
- }
94
-
95
- return { name, label }
96
- }
97
-
98
51
  export async function importStackableAndConfig (root, config, context) {
99
52
  let rootPackageJson
100
53
  try {
@@ -106,17 +59,16 @@ export async function importStackableAndConfig (root, config, context) {
106
59
  const hadConfig = !!config
107
60
 
108
61
  if (!config) {
109
- for (const candidate of configCandidates) {
110
- const candidatePath = resolve(root, candidate)
62
+ config = await ConfigManager.findConfigFile(root, 'application')
63
+ }
111
64
 
112
- if (existsSync(candidatePath)) {
113
- config = candidatePath
114
- break
115
- }
116
- }
65
+ const appType = await detectApplicationType(root, rootPackageJson)
66
+
67
+ if (!appType) {
68
+ throw new Error(`Unable to detect application type in ${root}.`)
117
69
  }
118
70
 
119
- const { label, name: moduleName } = await detectStackable(root, rootPackageJson)
71
+ const { label, name: moduleName } = appType
120
72
 
121
73
  if (context) {
122
74
  const serviceRoot = relative(process.cwd(), root)
package/lib/base.js CHANGED
@@ -354,7 +354,7 @@ export class BaseStackable extends EventEmitter {
354
354
  isEntrypoint: this.isEntrypoint,
355
355
  runtimeBasePath: this.runtimeConfig?.basePath ?? null,
356
356
  wantsAbsoluteUrls: meta.composer?.wantsAbsoluteUrls ?? false,
357
- /* c8 ignore next 2 - Else branches */
357
+ /* c8 ignore next 2 - else */
358
358
  port: (this.isEntrypoint ? this.serverConfig?.port || 0 : undefined) ?? true,
359
359
  host: (this.isEntrypoint ? this.serverConfig?.hostname : undefined) ?? true,
360
360
  telemetryConfig: this.telemetryConfig
package/lib/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRequire } from '@platformatic/utils'
1
+ import { createRequire } from 'node:module'
2
2
  import { pathToFileURL } from 'node:url'
3
3
  import { request } from 'undici'
4
4
 
@@ -65,7 +65,7 @@ export function resolvePackage (root, pkg) {
65
65
  // We need to add the main module paths to the require.resolve call
66
66
  // Note that `require.main` is not defined in `next` if we set sthe instrumentation hook reequired for ESM applications.
67
67
  // see: https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md#instrumentation-hook-required-for-esm
68
- return require.resolve(pkg, { paths: [root, ...require.main?.paths || []] })
68
+ return require.resolve(pkg, { paths: [root, ...(require.main?.paths || [])] })
69
69
  }
70
70
 
71
71
  export function cleanBasePath (basePath) {
@@ -1,9 +1,9 @@
1
1
  import { ITC } from '@platformatic/itc'
2
- import { createDirectory, createRequire, ensureLoggableError } from '@platformatic/utils'
2
+ import { createDirectory, ensureLoggableError } from '@platformatic/utils'
3
3
  import { once } from 'node:events'
4
4
  import { rm, writeFile } from 'node:fs/promises'
5
5
  import { createServer } from 'node:http'
6
- import { register } from 'node:module'
6
+ import { createRequire, register } from 'node:module'
7
7
  import { platform, tmpdir } from 'node:os'
8
8
  import { dirname, join, resolve } from 'node:path'
9
9
  import { pathToFileURL } from 'node:url'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/basic",
3
- "version": "2.68.0",
3
+ "version": "2.69.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,11 +24,11 @@
24
24
  "split2": "^4.2.0",
25
25
  "undici": "^7.0.0",
26
26
  "ws": "^8.18.0",
27
- "@platformatic/config": "2.68.0",
28
- "@platformatic/itc": "2.68.0",
29
- "@platformatic/metrics": "2.68.0",
30
- "@platformatic/telemetry": "2.68.0",
31
- "@platformatic/utils": "2.68.0"
27
+ "@platformatic/config": "2.69.0",
28
+ "@platformatic/itc": "2.69.0",
29
+ "@platformatic/metrics": "2.69.0",
30
+ "@platformatic/telemetry": "2.69.0",
31
+ "@platformatic/utils": "2.69.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "borp": "^0.20.0",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.68.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.69.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",