@pikku/cli 0.8.2 → 0.8.3
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 +11 -0
- package/dist/src/utils.js +8 -0
- package/package.json +1 -1
- package/src/utils.test.ts +38 -0
- package/src/utils.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @pikku/cli
|
|
2
2
|
|
|
3
|
+
## 0.8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9156577: Fix import path generation to handle same-package files and node_modules paths
|
|
8
|
+
|
|
9
|
+
- When files are in the same package directory, skip packageMappings and use relative paths
|
|
10
|
+
- When import paths include node_modules, strip everything before and including node_modules/ for cleaner imports
|
|
11
|
+
- This prevents issues where files within the same package would incorrectly reference themselves via package names
|
|
12
|
+
- Transforms ugly paths like `../../../../node_modules/@pikku/core/dist/types/core.types.d.js` into clean paths like `@pikku/core/dist/types/core.types.d.js`
|
|
13
|
+
|
|
3
14
|
## 0.8.2
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/src/utils.js
CHANGED
|
@@ -49,6 +49,14 @@ export const getFileImportRelativePath = (from, to, packageMappings) => {
|
|
|
49
49
|
if (!/^\.+\//.test(filePath)) {
|
|
50
50
|
filePath = `./${filePath}`;
|
|
51
51
|
}
|
|
52
|
+
// If the path includes node_modules, strip everything before and including node_modules/
|
|
53
|
+
if (filePath.includes('node_modules')) {
|
|
54
|
+
const nodeModulesIndex = filePath.indexOf('node_modules/');
|
|
55
|
+
if (nodeModulesIndex !== -1) {
|
|
56
|
+
filePath = filePath.substring(nodeModulesIndex + 'node_modules/'.length);
|
|
57
|
+
}
|
|
58
|
+
return filePath.replace('.ts', '.js');
|
|
59
|
+
}
|
|
52
60
|
const absolutePath = resolve(dirname(from), to);
|
|
53
61
|
const fromAbsolutePath = resolve(dirname(from));
|
|
54
62
|
// Check if both files are in the same package directory
|
package/package.json
CHANGED
package/src/utils.test.ts
CHANGED
|
@@ -134,4 +134,42 @@ describe('getFileImportRelativePath', () => {
|
|
|
134
134
|
|
|
135
135
|
assert.strictEqual(result, './file2.tsx'.replace('.ts', '.js'))
|
|
136
136
|
})
|
|
137
|
+
|
|
138
|
+
test('should strip everything before and including node_modules/', () => {
|
|
139
|
+
const from =
|
|
140
|
+
'/project/packages/functions/.pikku/http/pikku-http-routes-map.gen.d.ts'
|
|
141
|
+
const to =
|
|
142
|
+
'/project/packages/functions/../../../../node_modules/@pikku/core/dist/types/core.types.d.ts'
|
|
143
|
+
const packageMappings = {}
|
|
144
|
+
|
|
145
|
+
const result = getFileImportRelativePath(from, to, packageMappings)
|
|
146
|
+
|
|
147
|
+
assert.strictEqual(result, '@pikku/core/dist/types/core.types.d.js')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test('should handle node_modules path with package mappings', () => {
|
|
151
|
+
const from = '/project/packages/app/src/file1.ts'
|
|
152
|
+
const to = '/project/packages/app/node_modules/@myorg/utils/dist/utils.d.ts'
|
|
153
|
+
const packageMappings = {
|
|
154
|
+
'packages/app': '@myorg/app',
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const result = getFileImportRelativePath(from, to, packageMappings)
|
|
158
|
+
|
|
159
|
+
assert.strictEqual(result, '@myorg/utils/dist/utils.d.js')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('should handle deeply nested node_modules paths', () => {
|
|
163
|
+
const from =
|
|
164
|
+
'/Users/user/project/workspace-starter/packages/functions/.pikku/http/pikku-http-routes-map.gen.d.ts'
|
|
165
|
+
const to =
|
|
166
|
+
'/Users/user/project/workspace-starter/packages/functions/../../../../node_modules/@pikku/core/dist/types/core.types.d.ts'
|
|
167
|
+
const packageMappings = {
|
|
168
|
+
'packages/functions': '@workspace/functions',
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const result = getFileImportRelativePath(from, to, packageMappings)
|
|
172
|
+
|
|
173
|
+
assert.strictEqual(result, '@pikku/core/dist/types/core.types.d.js')
|
|
174
|
+
})
|
|
137
175
|
})
|
package/src/utils.ts
CHANGED
|
@@ -63,6 +63,15 @@ export const getFileImportRelativePath = (
|
|
|
63
63
|
filePath = `./${filePath}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// If the path includes node_modules, strip everything before and including node_modules/
|
|
67
|
+
if (filePath.includes('node_modules')) {
|
|
68
|
+
const nodeModulesIndex = filePath.indexOf('node_modules/')
|
|
69
|
+
if (nodeModulesIndex !== -1) {
|
|
70
|
+
filePath = filePath.substring(nodeModulesIndex + 'node_modules/'.length)
|
|
71
|
+
}
|
|
72
|
+
return filePath.replace('.ts', '.js')
|
|
73
|
+
}
|
|
74
|
+
|
|
66
75
|
const absolutePath = resolve(dirname(from), to)
|
|
67
76
|
const fromAbsolutePath = resolve(dirname(from))
|
|
68
77
|
|