Skip to content

Commit b5cbbbc

Browse files
committed
fix: Path not importing correctly
1 parent 58162e7 commit b5cbbbc

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.1.0-beta.5",
3+
"version": "1.1.0-beta.6",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {

src/resources/shell/path/path-resource.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,19 @@ export PATH="\${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"
110110
])
111111
})
112112

113+
it('Can match path declaration at end of file with no trailing newline', () => {
114+
const pathResource = new PathResource();
115+
116+
const result = pathResource.findAllPathDeclarations(
117+
`export PNPM_HOME="/Users/kevinwang/Library/pnpm"
118+
export PATH="$PNPM_HOME:$PATH"`);
119+
120+
expect(result).toMatchObject([
121+
{
122+
declaration: 'export PATH="$PNPM_HOME:$PATH"',
123+
path: '$PNPM_HOME'
124+
}
125+
])
126+
})
127+
113128
})

src/resources/shell/path/path-resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const exampleConfig: ExampleConfig = {
4242
}
4343

4444
export class PathResource extends Resource<PathConfig> {
45-
private readonly PATH_DECLARATION_REGEX = /((export PATH=)|(path+=\()|(path=\())(.+?)[\n;]/g;
45+
private readonly PATH_DECLARATION_REGEX = /((export PATH=)|(path\+=\()|(path=\())(.+?)(?:[\n;]|$)/g;
4646
private readonly filePaths = Utils.getShellRcFiles()
4747

4848
getSettings(): ResourceSettings<PathConfig> {
@@ -257,7 +257,7 @@ export class PathResource extends Resource<PathConfig> {
257257
for (const declaration of pathDeclarations) {
258258
const trimmedDeclaration = declaration[0];
259259
// Extract the value portion after the = or ( and strip surrounding quotes/parens
260-
const valueMatch = trimmedDeclaration.match(/(?:export PATH=|path\+=\(|path=\()(["']?)(.+?)\1[\n;)]/s);
260+
const valueMatch = trimmedDeclaration.match(/(?:export PATH=|path\+=\(|path=\()(["']?)(.+?)\1(?:[\n;)"]|$)/s);
261261
if (!valueMatch) {
262262
continue;
263263
}

0 commit comments

Comments
 (0)