Skip to content

Commit

Permalink
fix: Cross platform filenames
Browse files Browse the repository at this point in the history
Support issues with Windows and Linux filename paths being used as keys
in the filesToProjects map.
- store keys as forward slacked files and convert back at the last
  moment
  • Loading branch information
owenrumney committed Jun 19, 2024
1 parent cd20a8a commit 63d6da2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "infracost",
"displayName": "Infracost",
"description": "Cloud cost estimates for Terraform in your editor",
"version": "0.2.27",
"version": "0.2.28",
"publisher": "Infracost",
"license": "Apache-2.0",
"icon": "infracost-logo.png",
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class CLI {
INFRACOST_CLI_PLATFORM: 'vscode',
INFRACOST_NO_COLOR: 'true',
INFRACOST_SKIP_UPDATE_CHECK: 'true',
INFRACOST_GRAPH_EVALUATOR: 'true'
INFRACOST_GRAPH_EVALUATOR: 'true',
},
});

Expand Down
9 changes: 1 addition & 8 deletions src/lens.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import {
CodeLens,
CodeLensProvider,
Event,
TextDocument,
} from 'vscode';
import { CodeLens, CodeLensProvider, Event, TextDocument } from 'vscode';
import Workspace from './workspace';
import { cleanFilename } from './utils';
import logger from './log';
import { InfracostCommand } from './command';
import context from './context';
import path = require('path');

export default class InfracostLensProvider implements CodeLensProvider {
workspace: Workspace;
Expand Down
19 changes: 15 additions & 4 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ export default class Workspace {

logger.debug(`detected file change for path ${filename}`);

const projects = this.filesToProjects[filename];
const key = filename.split(path.sep).join('/');
const projects =
this.filesToProjects[
Object.keys(this.filesToProjects).find(
(k: string) => k.toLowerCase() === key.toLowerCase()
) || key
];

if (projects === undefined) {
logger.debug(
`no valid projects found for path ${filename} attempting to locate project for file`
Expand Down Expand Up @@ -156,9 +163,13 @@ export default class Workspace {
// TODO: determine or allow users to switch the project they are using.
project(filename: string): { [key: string]: Block } {
const key = filename.split(path.sep).join('/');
const projectKey = this.filesToProjects[Object.keys(this.filesToProjects).find((k: string) => k.toLowerCase() === key.toLowerCase()) || key];


const projectKey =
this.filesToProjects[
Object.keys(this.filesToProjects).find(
(k: string) => k.toLowerCase() === key.toLowerCase()
) || key
];

if (projectKey && Object.keys(projectKey).length > 0) {
const project = Object.keys(projectKey)[0];
return this.projects[project].blocks;
Expand Down

0 comments on commit 63d6da2

Please sign in to comment.