Skip to content

Commit

Permalink
fix: issue on path for windows (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-crouzet authored Feb 1, 2024
2 parents 53702db + f7093e1 commit 3850282
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/@o3r/telemetry/src/builders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createBuilderWithMetrics: BuilderWrapper = (builderFn, sendData = d
// context.builder.builderName does not contain the package name
const builderName = context.builder.name as string;
context.logger.info(`${builderName} run in ${duration}ms`);
const environment = getEnvironmentInfo();
const environment = await getEnvironmentInfo();
const data: BuilderMetricData = {
environment,
duration,
Expand Down
12 changes: 6 additions & 6 deletions packages/@o3r/telemetry/src/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface EnvironmentMetricData {
* Get all environment information
* Could be useful for debugging issue
*/
export const getEnvironmentInfo = (): EnvironmentMetricData => {
export const getEnvironmentInfo = async (): Promise<EnvironmentMetricData> => {
const osInfo = {
architecture: os.arch(),
platform: os.platform(),
Expand All @@ -136,17 +136,17 @@ export const getEnvironmentInfo = (): EnvironmentMetricData => {
otterCorePackageJsonPath = require.resolve('@o3r/core/package.json');
} catch {
// Fallback to the @o3r/telemetry package version if @o3r/core is not found
otterCorePackageJsonPath = path.posix.join(__dirname, '..', '..', 'package.json');
otterCorePackageJsonPath = path.join(__dirname, '..', '..', 'package.json');
}
const otterInfo = {
version: otterCorePackageJsonPath ? JSON.parse(fs.readFileSync(otterCorePackageJsonPath, { encoding: 'utf-8' })).version as string : undefined
version: otterCorePackageJsonPath ? JSON.parse(await fs.promises.readFile(otterCorePackageJsonPath, { encoding: 'utf-8' })).version as string : undefined
};

const ci = typeof process.env.CI !== undefined && process.env.CI?.toLowerCase() !== 'false';

let projectName: string | undefined;
try {
projectName = JSON.parse(fs.readFileSync(path.posix.join(process.cwd(), 'package.json'), { encoding: 'utf-8' })).name;
projectName = JSON.parse(await fs.promises.readFile(path.join(process.cwd(), 'package.json'), { encoding: 'utf-8' })).name;
} catch {}

return {
Expand All @@ -162,8 +162,8 @@ export const getEnvironmentInfo = (): EnvironmentMetricData => {
* Stringify the result of `getEnvironmentInfo`
* @see getEnvironmentInfo
*/
export const getEnvironmentInfoStringify = () => {
const { os: osInfo, node: nodeInfo, packageManager: packageManagerInfo, otter: otterInfo, ci } = getEnvironmentInfo();
export const getEnvironmentInfoStringify = async () => {
const { os: osInfo, node: nodeInfo, packageManager: packageManagerInfo, otter: otterInfo, ci } = await getEnvironmentInfo();
return `
- User Agent Architecture: ${osInfo.architecture}
- User Agent Platform: ${osInfo.platform}
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/telemetry/src/schematics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createSchematicWithMetrics: SchematicWrapper =
finally {
const endTime = Math.floor(performance.now());
const duration = endTime - startTime;
const environment = getEnvironmentInfo();
const environment = await getEnvironmentInfo();
const schematic = {
name: `${context.schematic.description.collection.name}:${context.schematic.description.name}`,
options,
Expand Down

0 comments on commit 3850282

Please sign in to comment.