Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Oct 30, 2023
1 parent 43d0d3d commit 601450f
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 303 deletions.
2 changes: 1 addition & 1 deletion packages/shared-lib-blitz-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@willbooster/eslint-config-ts": "10.5.1",
"@willbooster/prettier-config": "9.1.2",
"blitz": "2.0.0-beta.34",
"build-ts": "11.0.8",
"build-ts": "11.0.9",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-lib-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@typescript-eslint/parser": "6.9.0",
"@willbooster/eslint-config-ts": "10.5.1",
"@willbooster/prettier-config": "9.1.2",
"build-ts": "11.0.8",
"build-ts": "11.0.9",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-lib-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export {
readAndApplyEnvironmentVariables,
removeNpmAndYarnEnvironmentVariables,
yargsOptionsBuilderForEnv,
EnvReaderOptions,
} from './env.js';
export type { EnvReaderOptions } from './env.js';
export { existsAsync } from './exists.js';
export { calculateHashFromFiles, canSkipSeed, updateHashFromFiles } from './hash.js';
export { spawnAsync } from './spawn.js';
14 changes: 7 additions & 7 deletions packages/shared-lib-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"devDependencies": {
"@babel/core": "7.23.2",
"@mdx-js/react": "3.0.0",
"@storybook/addon-actions": "7.5.1",
"@storybook/addon-docs": "7.5.1",
"@storybook/addon-essentials": "7.5.1",
"@storybook/addon-interactions": "7.5.1",
"@storybook/addon-links": "7.5.1",
"@storybook/addon-actions": "7.5.2",
"@storybook/addon-docs": "7.5.2",
"@storybook/addon-essentials": "7.5.2",
"@storybook/addon-interactions": "7.5.2",
"@storybook/addon-links": "7.5.2",
"@storybook/builder-webpack4": "6.5.16",
"@storybook/manager-webpack4": "6.5.16",
"@storybook/react": "7.5.1",
"@storybook/react": "7.5.2",
"@storybook/testing-library": "0.2.2",
"@types/eslint": "8.44.6",
"@types/micromatch": "4.0.4",
Expand All @@ -53,7 +53,7 @@
"@willbooster/eslint-config-ts-react": "10.1.9",
"@willbooster/prettier-config": "9.1.2",
"babel-loader": "9.1.3",
"build-ts": "11.0.8",
"build-ts": "11.0.9",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@typescript-eslint/parser": "6.9.0",
"@willbooster/eslint-config-ts": "10.5.1",
"@willbooster/prettier-config": "9.1.2",
"build-ts": "11.0.8",
"build-ts": "11.0.9",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/wb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"@typescript-eslint/parser": "6.9.0",
"@willbooster/eslint-config-ts": "10.5.1",
"@willbooster/prettier-config": "9.1.2",
"at-decorators": "1.2.0",
"build-ts": "11.0.8",
"at-decorators": "1.2.2",
"build-ts": "11.0.9",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
58 changes: 56 additions & 2 deletions packages/wb/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,65 @@ 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';

/**
* A memoization decorator/function that caches the results of the latest method/getter/function call to improve performance.
* This decorator/function can be applied to methods and getters in a class as a decorator, and functions without context as a function.
* The cache only stores the latest value. When a new value is computed, the previous cached value is replaced.
*
* @template This The type of the `this` context within the method, getter or function.
* @template Args The types of the arguments to the method, getter or function.
* @template Return The return type of the method, getter or function.
*
* @param {Function | keyof This} target The method, function or the name of getter to be memoized.
* @param {ClassMethodDecoratorContext | ClassGetterDecoratorContext} [context] The context in which the decorator is being applied. Optional for standard functions.
*
* @returns {Function} A new function that wraps the original method or getter, function with caching logic.
*/
export function memoizeOne<This, Args extends unknown[], Return>(
target: ((this: This, ...args: Args) => Return) | ((...args: Args) => Return) | keyof This,
context?:
| ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>
| ClassGetterDecoratorContext<This, Return>
): (this: This, ...args: Args) => Return {
let lastCache: Return;

if (context?.kind === 'getter') {
let cached = false;
return function (this: This): Return {
console.log(`Entering getter ${String(context.name)}.`);

if (!cached) {
cached = true;
lastCache = (target as (this: This) => Return).call(this);
}

console.log(`Exiting getter ${String(context.name)}.`);
return lastCache;
};
}

let lastCacheKey: string;

return function (this: This, ...args: Args): Return {
console.log(`Entering ${context ? `method ${String(context.name)}` : 'function'}(${JSON.stringify(args)}).`);

const key = JSON.stringify(args);
if (lastCacheKey !== key) {
lastCacheKey = key;
lastCache = context
? (target as (this: This, ...args: Args) => Return).call(this, ...args)
: (target as (...args: Args) => Return)(...args);
}

console.log(`Exiting ${context ? `method ${String(context.name)}` : 'function'}.`);
return lastCache;
};
}

export class Project {
private _dirPath: string;
private _pathByName = new Map<string, string>();
Expand Down Expand Up @@ -139,7 +193,7 @@ export function findRootAndSelfProjects(

const thisProject = new Project(dirPath, argv);
let rootProject = thisProject;
if (!thisProject.packageJson.workspaces && path.dirname(dirPath) === 'packages') {
if (!thisProject.packageJson.workspaces && path.dirname(dirPath).endsWith('/packages')) {
const rootDirPath = path.resolve(dirPath, '..', '..');
if (fs.existsSync(path.join(rootDirPath, 'package.json'))) {
rootProject = new Project(rootDirPath, argv);
Expand Down
2 changes: 1 addition & 1 deletion packages/wb/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "ESNext",
"target": "ES2022",
"typeRoots": ["../../node_modules/@types", "../../@types", "./@types"]
},
"include": ["scripts/**/*", "src/**/*", "tests/**/*"]
Expand Down
Loading

0 comments on commit 601450f

Please sign in to comment.