@pikku/cli 0.8.1 → 0.8.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a02347b: fix: only insert package mapping if it's not the same package
8
+ - Updated dependencies [0fb4b3d]
9
+ - @pikku/core@0.8.2
10
+
3
11
  ## 0.8.1
4
12
 
5
13
  ### Patch Changes
package/cli.schema.json CHANGED
@@ -5,11 +5,23 @@
5
5
  "InspectorFilters": {
6
6
  "additionalProperties": false,
7
7
  "properties": {
8
+ "directories": {
9
+ "items": {
10
+ "type": "string"
11
+ },
12
+ "type": "array"
13
+ },
8
14
  "tags": {
9
15
  "items": {
10
16
  "type": "string"
11
17
  },
12
18
  "type": "array"
19
+ },
20
+ "types": {
21
+ "items": {
22
+ "type": "string"
23
+ },
24
+ "type": "array"
13
25
  }
14
26
  },
15
27
  "type": "object"
@@ -153,11 +165,11 @@
153
165
  "rpc": {
154
166
  "type": "string"
155
167
  },
156
- "scheduled": {
168
+ "scheduler": {
157
169
  "type": "string"
158
170
  }
159
171
  },
160
- "required": ["http", "scheduled", "channel", "rpc", "queue", "mcp"],
172
+ "required": ["http", "scheduler", "channel", "rpc", "queue", "mcp"],
161
173
  "type": "object"
162
174
  },
163
175
  "channelsFile": {
@@ -205,6 +217,12 @@
205
217
  "mcpJsonFile": {
206
218
  "type": "string"
207
219
  },
220
+ "middlewareServices": {
221
+ "items": {
222
+ "type": "string"
223
+ },
224
+ "type": "array"
225
+ },
208
226
  "nextBackendFile": {
209
227
  "type": "string"
210
228
  },
package/dist/src/utils.js CHANGED
@@ -50,14 +50,27 @@ export const getFileImportRelativePath = (from, to, packageMappings) => {
50
50
  filePath = `./${filePath}`;
51
51
  }
52
52
  const absolutePath = resolve(dirname(from), to);
53
- // let usesPackageName = false
54
- for (const [path, packageName] of Object.entries(packageMappings)) {
55
- if (absolutePath.includes(path)) {
56
- // usesPackageName = true
57
- filePath = absolutePath.replace(new RegExp(`.*${path}`), packageName);
53
+ const fromAbsolutePath = resolve(dirname(from));
54
+ // Check if both files are in the same package directory
55
+ // If so, skip packageMappings to use relative paths
56
+ let inSamePackage = false;
57
+ for (const [path] of Object.entries(packageMappings)) {
58
+ if (absolutePath.includes(path) && fromAbsolutePath.includes(path)) {
59
+ inSamePackage = true;
58
60
  break;
59
61
  }
60
62
  }
63
+ // Only apply packageMappings if files are not in the same package
64
+ if (!inSamePackage) {
65
+ // let usesPackageName = false
66
+ for (const [path, packageName] of Object.entries(packageMappings)) {
67
+ if (absolutePath.includes(path)) {
68
+ // usesPackageName = true
69
+ filePath = absolutePath.replace(new RegExp(`.*${path}`), packageName);
70
+ break;
71
+ }
72
+ }
73
+ }
61
74
  // if (usesPackageName) {
62
75
  // return filePath.replace('.ts', '')
63
76
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@openapi-contrib/json-schema-to-openapi-schema": "^3.0.2",
25
- "@pikku/core": "^0.8.1",
25
+ "@pikku/core": "^0.8.2",
26
26
  "@pikku/inspector": "^0.8.1",
27
27
  "@types/cookie": "^0.6.0",
28
28
  "@types/uuid": "^10.0.0",
@@ -0,0 +1,137 @@
1
+ import { strict as assert } from 'assert'
2
+ import { describe, test } from 'node:test'
3
+ import { getFileImportRelativePath } from './utils.js'
4
+
5
+ describe('getFileImportRelativePath', () => {
6
+ test('should return relative path for files in same directory', () => {
7
+ const from = '/project/src/file1.ts'
8
+ const to = '/project/src/file2.ts'
9
+ const packageMappings = {}
10
+
11
+ const result = getFileImportRelativePath(from, to, packageMappings)
12
+
13
+ assert.strictEqual(result, './file2.js')
14
+ })
15
+
16
+ test('should return relative path for files in different directories', () => {
17
+ const from = '/project/src/file1.ts'
18
+ const to = '/project/lib/file2.ts'
19
+ const packageMappings = {}
20
+
21
+ const result = getFileImportRelativePath(from, to, packageMappings)
22
+
23
+ assert.strictEqual(result, '../lib/file2.js')
24
+ })
25
+
26
+ test('should use package mapping when files are in different packages', () => {
27
+ const from = '/project/packages/app/src/file1.ts'
28
+ const to = '/project/packages/sdk/src/file2.ts'
29
+ const packageMappings = {
30
+ 'packages/sdk': '@myorg/sdk',
31
+ }
32
+
33
+ const result = getFileImportRelativePath(from, to, packageMappings)
34
+
35
+ assert.strictEqual(result, '@myorg/sdk/src/file2.js')
36
+ })
37
+
38
+ test('should NOT use package mapping when files are in same package', () => {
39
+ const from = '/project/packages/sdk/src/file1.ts'
40
+ const to = '/project/packages/sdk/lib/file2.ts'
41
+ const packageMappings = {
42
+ 'packages/sdk': '@myorg/sdk',
43
+ }
44
+
45
+ const result = getFileImportRelativePath(from, to, packageMappings)
46
+
47
+ assert.strictEqual(result, '../lib/file2.js')
48
+ })
49
+
50
+ test('should use package mapping when only target file is in mapped package', () => {
51
+ const from = '/project/apps/web/src/file1.ts'
52
+ const to = '/project/packages/sdk/src/file2.ts'
53
+ const packageMappings = {
54
+ 'packages/sdk': '@myorg/sdk',
55
+ }
56
+
57
+ const result = getFileImportRelativePath(from, to, packageMappings)
58
+
59
+ assert.strictEqual(result, '@myorg/sdk/src/file2.js')
60
+ })
61
+
62
+ test('should handle multiple package mappings correctly', () => {
63
+ const from = '/project/packages/app/src/file1.ts'
64
+ const to = '/project/packages/utils/src/file2.ts'
65
+ const packageMappings = {
66
+ 'packages/app': '@myorg/app',
67
+ 'packages/utils': '@myorg/utils',
68
+ }
69
+
70
+ const result = getFileImportRelativePath(from, to, packageMappings)
71
+
72
+ assert.strictEqual(result, '@myorg/utils/src/file2.js')
73
+ })
74
+
75
+ test('should preserve relative path when both files are in same package directory', () => {
76
+ const from = '/project/packages/sdk/src/components/file1.ts'
77
+ const to = '/project/packages/sdk/src/utils/file2.ts'
78
+ const packageMappings = {
79
+ 'packages/sdk': '@myorg/sdk',
80
+ }
81
+
82
+ const result = getFileImportRelativePath(from, to, packageMappings)
83
+
84
+ assert.strictEqual(result, '../utils/file2.js')
85
+ })
86
+
87
+ test('should work with nested package structures', () => {
88
+ const from = '/project/packages/app/src/file1.ts'
89
+ const to = '/project/packages/app/lib/nested/file2.ts'
90
+ const packageMappings = {
91
+ 'packages/app': '@myorg/app',
92
+ 'packages/sdk': '@myorg/sdk',
93
+ }
94
+
95
+ const result = getFileImportRelativePath(from, to, packageMappings)
96
+
97
+ assert.strictEqual(result, '../lib/nested/file2.js')
98
+ })
99
+
100
+ test('should handle complex path structures', () => {
101
+ const from =
102
+ '/Users/user/project/workspace-starter/packages/sdk/.pikku/pikku-fetch.gen.ts'
103
+ const to =
104
+ '/Users/user/project/workspace-starter/packages/functions/.pikku/http/pikku-http-routes-map.gen.d.ts'
105
+ const packageMappings = {
106
+ 'packages/sdk': '@workspace/sdk',
107
+ 'packages/functions': '@workspace/functions',
108
+ }
109
+
110
+ const result = getFileImportRelativePath(from, to, packageMappings)
111
+
112
+ assert.strictEqual(
113
+ result,
114
+ '@workspace/functions/.pikku/http/pikku-http-routes-map.gen.d.js'
115
+ )
116
+ })
117
+
118
+ test('should handle empty package mappings', () => {
119
+ const from = '/project/src/file1.ts'
120
+ const to = '/project/lib/file2.ts'
121
+ const packageMappings = {}
122
+
123
+ const result = getFileImportRelativePath(from, to, packageMappings)
124
+
125
+ assert.strictEqual(result, '../lib/file2.js')
126
+ })
127
+
128
+ test('should replace .ts extension with .js', () => {
129
+ const from = '/project/src/file1.ts'
130
+ const to = '/project/src/file2.tsx'
131
+ const packageMappings = {}
132
+
133
+ const result = getFileImportRelativePath(from, to, packageMappings)
134
+
135
+ assert.strictEqual(result, './file2.tsx'.replace('.ts', '.js'))
136
+ })
137
+ })
package/src/utils.ts CHANGED
@@ -64,15 +64,30 @@ export const getFileImportRelativePath = (
64
64
  }
65
65
 
66
66
  const absolutePath = resolve(dirname(from), to)
67
- // let usesPackageName = false
68
- for (const [path, packageName] of Object.entries(packageMappings)) {
69
- if (absolutePath.includes(path)) {
70
- // usesPackageName = true
71
- filePath = absolutePath.replace(new RegExp(`.*${path}`), packageName)
67
+ const fromAbsolutePath = resolve(dirname(from))
68
+
69
+ // Check if both files are in the same package directory
70
+ // If so, skip packageMappings to use relative paths
71
+ let inSamePackage = false
72
+ for (const [path] of Object.entries(packageMappings)) {
73
+ if (absolutePath.includes(path) && fromAbsolutePath.includes(path)) {
74
+ inSamePackage = true
72
75
  break
73
76
  }
74
77
  }
75
78
 
79
+ // Only apply packageMappings if files are not in the same package
80
+ if (!inSamePackage) {
81
+ // let usesPackageName = false
82
+ for (const [path, packageName] of Object.entries(packageMappings)) {
83
+ if (absolutePath.includes(path)) {
84
+ // usesPackageName = true
85
+ filePath = absolutePath.replace(new RegExp(`.*${path}`), packageName)
86
+ break
87
+ }
88
+ }
89
+ }
90
+
76
91
  // if (usesPackageName) {
77
92
  // return filePath.replace('.ts', '')
78
93
  // }