Skip to content

Commit

Permalink
fix(wb): memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Nov 6, 2023
1 parent 53b62d3 commit 814cb75
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions packages/wb/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'node:path';

import type { EnvReaderOptions } from '@willbooster/shared-lib-node/src';
import { readEnvironmentVariables } from '@willbooster/shared-lib-node/src';
import { memoizeOne } from 'at-decorators';
import type { PackageJson } from 'type-fest';

import type { ScriptArgv } from './scripts/builder.js';
Expand All @@ -20,7 +19,6 @@ export class Project {
this.loadEnv = loadEnv;
}

@memoizeOne
getBuildCommand(argv?: ScriptArgv): string {
return this.packageJson.scripts?.build?.includes('buildIfNeeded')
? 'yarn build'
Expand All @@ -35,19 +33,16 @@ export class Project {
this._dirPath = path.resolve(newDirPath);
}

@memoizeOne
get rootDirPath(): string {
return fs.existsSync(path.join(this.dirPath, '..', '..', 'package.json'))
? path.resolve(this.dirPath, '..', '..')
: this.dirPath;
}

@memoizeOne
get dockerfile(): string {
return fs.readFileSync(this.findFile('Dockerfile'), 'utf8');
}

@memoizeOne
get hasDockerfile(): boolean {
try {
return !!this.findFile('Dockerfile');
Expand All @@ -56,35 +51,29 @@ export class Project {
}
}

@memoizeOne
get name(): string {
return this.packageJson.name || 'unknown';
}

@memoizeOne
get dockerImageName(): string {
const name = this.packageJson.name || 'unknown';
return name.replaceAll('@', '').replaceAll('/', '-');
}

@memoizeOne
get env(): Record<string, string | undefined> {
return this.loadEnv ? { ...readEnvironmentVariables(this.argv, this.dirPath), ...process.env } : process.env;
}

@memoizeOne
get packageJson(): PackageJson {
return JSON.parse(fs.readFileSync(path.join(this.dirPath, 'package.json'), 'utf8'));
}

@memoizeOne
get rootPackageJson(): PackageJson {
return this.rootDirPath === this.dirPath
? this.packageJson
: JSON.parse(fs.readFileSync(path.join(this.rootDirPath, 'package.json'), 'utf8'));
}

@memoizeOne
get dockerPackageJson(): PackageJson {
return path.dirname(this.findFile('Dockerfile')) === this.dirPath
? this.packageJson
Expand Down

0 comments on commit 814cb75

Please sign in to comment.