Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/fix, fix generate-random-string to be of a consistent size and extract it to a new component #8689

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,13 @@
"mainFile": "index.ts",
"rootDir": "scopes/toolbox/string/get-initials"
},
"string/random": {
"name": "string/random",
"scope": "teambit.toolbox",
"version": "0.0.1",
"mainFile": "index.ts",
"rootDir": "scopes/toolbox/string/random"
},
"string/strip-trailing-char": {
"name": "string/strip-trailing-char",
"scope": "teambit.toolbox",
Expand Down
225 changes: 0 additions & 225 deletions e2e/fixtures/testers/capsule/tester.js

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/harmony/deduplication.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chai, { expect } from 'chai';
import path from 'path';
import { generateRandomStr } from '@teambit/toolbox.string.random';
import NpmCiRegistry, { supportNpmCiRegistryTesting } from '../npm-ci-registry';
import Helper from '../../src/e2e-helper/e2e-helper';
import { generateRandomStr } from '../../src/utils';

chai.use(require('chai-fs'));

Expand Down
2 changes: 1 addition & 1 deletion e2e/harmony/dependency-resolver.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import chai, { expect } from 'chai';
import path from 'path';
import { Modules, readModulesManifest } from '@pnpm/modules-yaml';
import { generateRandomStr } from '@teambit/toolbox.string.random';
import { Extensions } from '../../src/constants';
import Helper from '../../src/e2e-helper/e2e-helper';
import * as fixtures from '../../src/fixtures/fixtures';
import { generateRandomStr } from '../../src/utils';
import NpmCiRegistry, { supportNpmCiRegistryTesting } from '../npm-ci-registry';

chai.use(require('chai-fs'));
Expand Down
3 changes: 1 addition & 2 deletions e2e/harmony/publish.e2e.4.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import chai, { expect } from 'chai';

import { generateRandomStr } from '@teambit/toolbox.string.random';
import Helper from '../../src/e2e-helper/e2e-helper';
import { DEFAULT_OWNER } from '../../src/e2e-helper/e2e-scopes';
import { generateRandomStr } from '../../src/utils';
import NpmCiRegistry, { supportNpmCiRegistryTesting } from '../npm-ci-registry';

chai.use(require('chai-fs'));
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"@teambit/styling.deps-detectors.detective-sass": "~0.0.2",
"@teambit/styling.deps-detectors.detective-scss": "~0.0.2",
"@teambit/styling.deps-lookups.lookup-styling": "~0.0.1",
"@teambit/toolbox.string.random": "~0.0.1",
"@teambit/cloud.models.cloud-user": "~0.0.5",
"@teambit/component-id": "^1.2.0",
"@teambit/typescript.deps-detectors.detective-typescript": "~0.0.6",
"@teambit/typescript.deps-lookups.lookup-typescript": "~0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion scopes/component/graph/graph-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import GraphLib from 'graphlib';
import { Command, CommandOptions } from '@teambit/cli';
import { ComponentID } from '@teambit/component-id';
import { generateRandomStr } from '@teambit/legacy/dist/utils';
import { generateRandomStr } from '@teambit/toolbox.string.random';
import VisualDependencyGraph from '@teambit/legacy/dist/scope/graph/vizgraph';
import { Consumer, loadConsumerIfExist } from '@teambit/legacy/dist/consumer';
import DependencyGraph from '@teambit/legacy/dist/scope/graph/scope-graph';
Expand Down
9 changes: 9 additions & 0 deletions scopes/toolbox/string/random/generate-random-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import crypto from 'crypto';

/**
* Generates random string of a specific size
* @param size - the maximum size can be 40 characters
*/
export function generateRandomStr(size = 8): string {
return crypto.randomBytes(20).toString('hex').substring(0, size);
}
1 change: 1 addition & 0 deletions scopes/toolbox/string/random/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { generateRandomStr } from './generate-random-string';
3 changes: 2 additions & 1 deletion scripts/validate-pkg-exist-in-pkg-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const getPackagesUsedInCode = (content = '') => {
// regex to find all packages in the "import" statements.
// notice the flag "m" next to the "g" flag, it's for multi-line matching.
// needed because I match only lines that start with "import".
const regex = /^import.+from\s+'([\w@/-]+)'/gm;
const regex = /^import.+from.+'(.+)'/gm;
let match;
while ((match = regex.exec(content))) {
if (match[1].startsWith('.')) continue; // ignore local imports
packages.push(match[1]);
}
return packages;
Expand Down
2 changes: 1 addition & 1 deletion src/consumer/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Scope } from '../scope';
import { getAutoTagPending } from '../scope/component-ops/auto-tag';
import { ComponentNotFound } from '../scope/exceptions';
import { Lane, ModelComponent, Version } from '../scope/models';
import { generateRandomStr } from '../utils';
import { generateRandomStr } from '@teambit/toolbox.string.random';
import { sortObjectByKeys } from '@teambit/toolbox.object.sorter';
import { composeComponentPath } from '../utils/bit/compose-component-path';
import {
Expand Down
Loading