From 0f6a1aeae5e35c9c7e9a760266a889b9ababe892 Mon Sep 17 00:00:00 2001 From: Doga Yuksel Date: Tue, 25 Jan 2022 09:56:58 +0100 Subject: [PATCH 1/3] refactor(fakerjs): use new fakerjs community package --- core/README.md | 2 +- core/package.json | 3 +- core/src/@jackfranklin/test-data-bot/index.ts | 7 ++-- models/category/package.json | 3 +- models/commons/package.json | 3 +- .../src/localized-string/presets/of-slugs.ts | 2 +- utils/package.json | 3 +- utils/src/create-related-dates.ts | 8 +++-- yarn.lock | 33 +++++++------------ 9 files changed, 26 insertions(+), 38 deletions(-) diff --git a/core/README.md b/core/README.md index c54eb0c1b..b4b517f7f 100644 --- a/core/README.md +++ b/core/README.md @@ -187,7 +187,7 @@ For example: ```ts // presets/author-with-one-book.ts import type { TAuthorBuilder } from './types'; -import * as faker from 'faker'; +import faker from '@faker-js/faker'; import * as Book from '../../book'; import Author from './builder'; diff --git a/core/package.json b/core/package.json index 450f4e414..ca0076b03 100644 --- a/core/package.json +++ b/core/package.json @@ -19,9 +19,8 @@ "dependencies": { "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", - "@types/faker": "^5.5.1", + "@faker-js/faker": "^6.0.0-alpha.3", "@types/lodash": "^4.14.168", - "faker": "^5.5.3", "lodash": "^4.17.21" } } diff --git a/core/src/@jackfranklin/test-data-bot/index.ts b/core/src/@jackfranklin/test-data-bot/index.ts index e924bb012..fd0d6b1e5 100644 --- a/core/src/@jackfranklin/test-data-bot/index.ts +++ b/core/src/@jackfranklin/test-data-bot/index.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import * as faker from 'faker'; +import type { Faker } from '@faker-js/faker'; +import faker from '@faker-js/faker'; import { mapValues } from 'lodash'; export type SequenceFunction = (counter: number) => unknown; @@ -12,7 +13,7 @@ export interface SequenceGenerator { export interface FakerGenerator { generatorType: 'faker'; - call: (fake: Faker.FakerStatic) => any; + call: (fake: Faker) => any; } export interface PerBuildGenerator { @@ -239,7 +240,7 @@ export const perBuild = (func: () => T): PerBuildGenerator => { }; }; -export type FakerUserArgs = (fake: Faker.FakerStatic) => any; +export type FakerUserArgs = (fake: Faker) => any; export const fake = (userDefinedUsage: FakerUserArgs): FakerGenerator => { return { diff --git a/models/category/package.json b/models/category/package.json index be57fa5e0..0f8cd9c50 100644 --- a/models/category/package.json +++ b/models/category/package.json @@ -21,8 +21,7 @@ "@babel/runtime-corejs3": "^7.13.10", "@commercetools-test-data/core": "2.4.1", "@commercetools-test-data/utils": "2.4.0", - "@types/faker": "^5.5.1", - "faker": "^5.5.3", + "@faker-js/faker": "^6.0.0-alpha.3", "lodash": "^4.17.21" } } diff --git a/models/commons/package.json b/models/commons/package.json index ee5298f8d..c6f6d20c3 100644 --- a/models/commons/package.json +++ b/models/commons/package.json @@ -20,8 +20,7 @@ "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", "@commercetools-test-data/core": "2.4.1", - "@types/faker": "^5.5.1", - "faker": "^5.5.3", + "@faker-js/faker": "^6.0.0-alpha.3", "lodash": "^4.17.21" } } diff --git a/models/commons/src/localized-string/presets/of-slugs.ts b/models/commons/src/localized-string/presets/of-slugs.ts index b74b3f254..9e6afb88a 100644 --- a/models/commons/src/localized-string/presets/of-slugs.ts +++ b/models/commons/src/localized-string/presets/of-slugs.ts @@ -1,6 +1,6 @@ import type { TLocalizedStringBuilder } from '../types'; -import * as faker from 'faker'; +import faker from '@faker-js/faker'; import LocalizedString from '../builder'; const ofSlugs = (): TLocalizedStringBuilder => diff --git a/utils/package.json b/utils/package.json index 5906e783a..c32dcf963 100644 --- a/utils/package.json +++ b/utils/package.json @@ -19,7 +19,6 @@ "dependencies": { "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", - "@types/faker": "^5.5.1", - "faker": "^5.5.3" + "@faker-js/faker": "^6.0.0-alpha.3" } } diff --git a/utils/src/create-related-dates.ts b/utils/src/create-related-dates.ts index 182376752..81346b1ac 100644 --- a/utils/src/create-related-dates.ts +++ b/utils/src/create-related-dates.ts @@ -1,3 +1,5 @@ +import type { Faker } from '@faker-js/faker'; + /** * Create two related dates (one comes before the other) by using a reference * in the past. The reference will be the result of invoking `Date.now()` when this @@ -32,15 +34,15 @@ */ const createRelatedDates = (recentDaysFromPastReference: number = 10) => { const pastReference = new Date(); - const getOlderDate = (f: Faker.FakerStatic) => + const getOlderDate = (f: Faker) => f.date.recent(recentDaysFromPastReference, pastReference.toISOString()); - const getNewerDate = (f: Faker.FakerStatic) => + const getNewerDate = (f: Faker) => f.date.between( new Date(pastReference).toISOString(), new Date().toISOString() ); - const getFutureDate = (f: Faker.FakerStatic) => f.date.future(); + const getFutureDate = (f: Faker) => f.date.future(); return [getOlderDate, getNewerDate, getFutureDate]; }; diff --git a/yarn.lock b/yarn.lock index ee9401324..4b6248374 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1883,8 +1883,7 @@ __metadata: "@babel/runtime-corejs3": ^7.13.10 "@commercetools-test-data/core": 2.4.1 "@commercetools-test-data/utils": 2.4.0 - "@types/faker": ^5.5.1 - faker: ^5.5.3 + "@faker-js/faker": ^6.0.0-alpha.3 lodash: ^4.17.21 languageName: unknown linkType: soft @@ -1896,8 +1895,7 @@ __metadata: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 "@commercetools-test-data/core": 2.4.1 - "@types/faker": ^5.5.1 - faker: ^5.5.3 + "@faker-js/faker": ^6.0.0-alpha.3 lodash: ^4.17.21 languageName: unknown linkType: soft @@ -1908,9 +1906,8 @@ __metadata: dependencies: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 - "@types/faker": ^5.5.1 + "@faker-js/faker": ^6.0.0-alpha.3 "@types/lodash": ^4.14.168 - faker: ^5.5.3 lodash: ^4.17.21 languageName: unknown linkType: soft @@ -1953,8 +1950,7 @@ __metadata: dependencies: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 - "@types/faker": ^5.5.1 - faker: ^5.5.3 + "@faker-js/faker": ^6.0.0-alpha.3 languageName: unknown linkType: soft @@ -2251,6 +2247,13 @@ __metadata: languageName: node linkType: hard +"@faker-js/faker@npm:^6.0.0-alpha.3": + version: 6.0.0-alpha.4 + resolution: "@faker-js/faker@npm:6.0.0-alpha.4" + checksum: afcb4651cf4328e7982e54956ba11e0f0a2c0bd52b16d7431c730dcd4e8fc2cefdc821f7ba12b0f2cba96248bfa33de7f5fa1cfbb181b4038907bfa4185255b4 + languageName: node + linkType: hard + "@gar/promisify@npm:^1.0.1": version: 1.1.2 resolution: "@gar/promisify@npm:1.1.2" @@ -2893,13 +2896,6 @@ __metadata: languageName: node linkType: hard -"@types/faker@npm:^5.5.1": - version: 5.5.9 - resolution: "@types/faker@npm:5.5.9" - checksum: c2cbd082abe29047c89cf29b86257e582d2a177a9d1ed3abf99aa1cc025d5e8a3d201dfaddf8441bfcc57ed43e4da80e666951e1c23a5b759ac441a5855b5c36 - languageName: node - linkType: hard - "@types/glob@npm:^7.1.1": version: 7.2.0 resolution: "@types/glob@npm:7.2.0" @@ -5669,13 +5665,6 @@ __metadata: languageName: node linkType: hard -"faker@npm:^5.5.3": - version: 5.5.3 - resolution: "faker@npm:5.5.3" - checksum: 684fd64c8d3897e54248f95b4f6319f75d97691b8500cd13adf4af2c28f9204f766c1d1aaa6b41338f0beaaa87256c3132f8708a1a8f189d122b92f6b98081c3 - languageName: node - linkType: hard - "fast-deep-equal@npm:^2.0.1": version: 2.0.1 resolution: "fast-deep-equal@npm:2.0.1" From 7e493973b59b18cc5e4169e6c2abe8a4faee3dc2 Mon Sep 17 00:00:00 2001 From: Doga Yuksel Date: Tue, 25 Jan 2022 10:06:05 +0100 Subject: [PATCH 2/3] chore: add changelog for the fakerjs library replacement --- .changeset/modern-bulldogs-sell.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/modern-bulldogs-sell.md diff --git a/.changeset/modern-bulldogs-sell.md b/.changeset/modern-bulldogs-sell.md new file mode 100644 index 000000000..304525bcf --- /dev/null +++ b/.changeset/modern-bulldogs-sell.md @@ -0,0 +1,8 @@ +--- +'@commercetools-test-data/core': patch +'@commercetools-test-data/category': patch +'@commercetools-test-data/commons': patch +'@commercetools-test-data/utils': patch +--- + +Replace deleted fakerjs library with the new community package (fakerjs.dev) From b9628348221e3ab3f7f9df86892a06066daa6fc7 Mon Sep 17 00:00:00 2001 From: Doga Yuksel Date: Tue, 25 Jan 2022 16:12:20 +0100 Subject: [PATCH 3/3] fix(fakerjs): bump up package version --- core/package.json | 2 +- models/category/package.json | 2 +- models/commons/package.json | 2 +- utils/package.json | 2 +- yarn.lock | 16 ++++++++-------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/package.json b/core/package.json index ca0076b03..b50042bb2 100644 --- a/core/package.json +++ b/core/package.json @@ -19,7 +19,7 @@ "dependencies": { "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", - "@faker-js/faker": "^6.0.0-alpha.3", + "@faker-js/faker": "^6.0.0-alpha.5", "@types/lodash": "^4.14.168", "lodash": "^4.17.21" } diff --git a/models/category/package.json b/models/category/package.json index 0f8cd9c50..b788f2c74 100644 --- a/models/category/package.json +++ b/models/category/package.json @@ -21,7 +21,7 @@ "@babel/runtime-corejs3": "^7.13.10", "@commercetools-test-data/core": "2.4.1", "@commercetools-test-data/utils": "2.4.0", - "@faker-js/faker": "^6.0.0-alpha.3", + "@faker-js/faker": "^6.0.0-alpha.5", "lodash": "^4.17.21" } } diff --git a/models/commons/package.json b/models/commons/package.json index c6f6d20c3..c3db0e625 100644 --- a/models/commons/package.json +++ b/models/commons/package.json @@ -20,7 +20,7 @@ "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", "@commercetools-test-data/core": "2.4.1", - "@faker-js/faker": "^6.0.0-alpha.3", + "@faker-js/faker": "^6.0.0-alpha.5", "lodash": "^4.17.21" } } diff --git a/utils/package.json b/utils/package.json index c32dcf963..3cd923dc0 100644 --- a/utils/package.json +++ b/utils/package.json @@ -19,6 +19,6 @@ "dependencies": { "@babel/runtime": "^7.13.10", "@babel/runtime-corejs3": "^7.13.10", - "@faker-js/faker": "^6.0.0-alpha.3" + "@faker-js/faker": "^6.0.0-alpha.5" } } diff --git a/yarn.lock b/yarn.lock index 4b6248374..e8b986c75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1883,7 +1883,7 @@ __metadata: "@babel/runtime-corejs3": ^7.13.10 "@commercetools-test-data/core": 2.4.1 "@commercetools-test-data/utils": 2.4.0 - "@faker-js/faker": ^6.0.0-alpha.3 + "@faker-js/faker": ^6.0.0-alpha.5 lodash: ^4.17.21 languageName: unknown linkType: soft @@ -1895,7 +1895,7 @@ __metadata: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 "@commercetools-test-data/core": 2.4.1 - "@faker-js/faker": ^6.0.0-alpha.3 + "@faker-js/faker": ^6.0.0-alpha.5 lodash: ^4.17.21 languageName: unknown linkType: soft @@ -1906,7 +1906,7 @@ __metadata: dependencies: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 - "@faker-js/faker": ^6.0.0-alpha.3 + "@faker-js/faker": ^6.0.0-alpha.5 "@types/lodash": ^4.14.168 lodash: ^4.17.21 languageName: unknown @@ -1950,7 +1950,7 @@ __metadata: dependencies: "@babel/runtime": ^7.13.10 "@babel/runtime-corejs3": ^7.13.10 - "@faker-js/faker": ^6.0.0-alpha.3 + "@faker-js/faker": ^6.0.0-alpha.5 languageName: unknown linkType: soft @@ -2247,10 +2247,10 @@ __metadata: languageName: node linkType: hard -"@faker-js/faker@npm:^6.0.0-alpha.3": - version: 6.0.0-alpha.4 - resolution: "@faker-js/faker@npm:6.0.0-alpha.4" - checksum: afcb4651cf4328e7982e54956ba11e0f0a2c0bd52b16d7431c730dcd4e8fc2cefdc821f7ba12b0f2cba96248bfa33de7f5fa1cfbb181b4038907bfa4185255b4 +"@faker-js/faker@npm:^6.0.0-alpha.5": + version: 6.0.0-alpha.5 + resolution: "@faker-js/faker@npm:6.0.0-alpha.5" + checksum: aa145eaeba624a65fe3237f2abfe4fa4a87fb7283cda983cafad95fd8b88b9e58eae403a36bdc4108f9625b0c64b81e901e68d11b33c04c8f24dae07c31e314f languageName: node linkType: hard