create-platformatic 1.10.0 → 1.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-platformatic",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Create platformatic-db interactive tool",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,6 +15,7 @@
15
15
  "license": "Apache-2.0",
16
16
  "author": "Marco Piraccini <marco.piraccini@gmail.com>",
17
17
  "dependencies": {
18
+ "@types/node": "^20.8.10",
18
19
  "boring-name-generator": "^1.0.3",
19
20
  "chalk": "^5.3.0",
20
21
  "columnify": "^1.6.0",
@@ -35,7 +36,7 @@
35
36
  "strip-ansi": "^7.1.0",
36
37
  "undici": "^5.25.4",
37
38
  "which": "^3.0.1",
38
- "@platformatic/config": "1.10.0"
39
+ "@platformatic/config": "1.11.0"
39
40
  },
40
41
  "devDependencies": {
41
42
  "ajv": "^8.12.0",
@@ -48,8 +49,8 @@
48
49
  "tap": "^16.3.9",
49
50
  "typescript": "~5.2.2",
50
51
  "yaml": "^2.3.2",
51
- "@platformatic/db": "1.10.0",
52
- "@platformatic/service": "1.10.0"
52
+ "@platformatic/db": "1.11.0",
53
+ "@platformatic/service": "1.11.0"
53
54
  },
54
55
  "scripts": {
55
56
  "test:cli": "tap --no-coverage test/cli/*test.mjs -t120",
@@ -99,7 +99,7 @@ export async function createPlatformaticRuntime (_args) {
99
99
  if (addTypescriptDevDep) {
100
100
  const typescriptVersion = await getDependencyVersion('typescript')
101
101
  devDependencies.typescript = `^${typescriptVersion}`
102
- devDependencies['@types/node'] = 'latest'
102
+ devDependencies['@types/node'] = await getDependencyVersion('@types/node')
103
103
  }
104
104
 
105
105
  // Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
package/src/utils.mjs CHANGED
@@ -4,10 +4,13 @@ import { resolve, join, dirname } from 'path'
4
4
  import { createRequire } from 'module'
5
5
  import semver from 'semver'
6
6
  import * as desm from 'desm'
7
+ import * as url from 'url'
8
+
7
9
  import ConfigManager from '@platformatic/config'
8
10
 
9
11
  export const sleep = ms => new Promise((resolve) => setTimeout(resolve, ms))
10
12
  export const randomBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
13
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
11
14
 
12
15
  export async function isFileAccessible (filename, directory) {
13
16
  try {
@@ -73,21 +76,44 @@ export const findRuntimeConfigFile = async (directory) => (ConfigManager.findCon
73
76
  * @returns string
74
77
  */
75
78
  export const getDependencyVersion = async (dependencyName) => {
76
- const require = createRequire(import.meta.url)
77
- let dependencyPath = dirname(require.resolve(dependencyName))
78
- // some deps are resolved not at their root level
79
- // for instance 'typescript' will be risolved in its own ./lib directory
80
- // next loop is to find the nearest parent directory that contains a package.json file
81
- while (!await isFileAccessible(join(dependencyPath, 'package.json'))) {
82
- dependencyPath = join(dependencyPath, '..')
83
- if (dependencyPath === '/') {
84
- throw new Error(`Cannot find package.json for ${dependencyName}`)
79
+ const rootPackageJson = join(__dirname, '..', 'package.json')
80
+ const packageJsonContents = JSON.parse(await readFile(rootPackageJson, 'utf8'))
81
+ const dependencies = packageJsonContents.dependencies
82
+ const devDependencies = packageJsonContents.devDependencies
83
+ const regexp = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/
84
+ if (dependencies[dependencyName]) {
85
+ const match = dependencies[dependencyName].match(regexp)
86
+ if (!match) {
87
+ return await resolveWorkspaceDependency(dependencyName)
88
+ }
89
+ return match[0]
90
+ }
91
+
92
+ if (devDependencies[dependencyName]) {
93
+ const match = devDependencies[dependencyName].match(regexp)
94
+ if (!match) {
95
+ return await resolveWorkspaceDependency(dependencyName)
96
+ }
97
+ return match[0]
98
+ }
99
+
100
+ async function resolveWorkspaceDependency (dependencyName) {
101
+ const require = createRequire(import.meta.url)
102
+ let dependencyPath = dirname(require.resolve(dependencyName))
103
+ // some deps are resolved not at their root level
104
+ // for instance 'typescript' will be risolved in its own ./lib directory
105
+ // next loop is to find the nearest parent directory that contains a package.json file
106
+ while (!await isFileAccessible(join(dependencyPath, 'package.json'))) {
107
+ dependencyPath = join(dependencyPath, '..')
108
+ if (dependencyPath === '/') {
109
+ throw new Error(`Cannot find package.json for ${dependencyName}`)
110
+ }
85
111
  }
112
+ const pathToPackageJson = join(dependencyPath, 'package.json')
113
+ const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
114
+ const packageJson = JSON.parse(packageJsonFile)
115
+ return packageJson.version
86
116
  }
87
- const pathToPackageJson = join(dependencyPath, 'package.json')
88
- const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
89
- const packageJson = JSON.parse(packageJsonFile)
90
- return packageJson.version
91
117
  }
92
118
 
93
119
  export const minimumSupportedNodeVersions = ['18.8.0', '20.6.0']