Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
feat: switch from shortid to nanoid, close #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Feb 23, 2022
1 parent 9dab21a commit 3d70e9f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/peeky-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"chokidar": "^3.5.3",
"consola": "^2.15.0",
"fs-extra": "^10.0.0",
"nanoid": "^3.3.1",
"pathe": "^0.2.0",
"shortid": "^2.2.16",
"vite": "^2.7.10"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/peeky-config/src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra'
import path from 'pathe'
import consola from 'consola'
import shortid from 'shortid'
import { nanoid } from 'nanoid'
import { fixWindowsAbsoluteFileUrl } from '@peeky/utils'
import type { PeekyConfig } from './types'
import { transformConfigCode } from './transform.js'
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function setupConfigLoader (options: PeekyConfigLoaderOptions = {})
async function loadConfig (loadFromVite = true): Promise<PeekyConfig> {
const cwd = options.baseDir || process.cwd()
const file = await resolveConfigFile(cwd)
const resolvedPath = file + shortid() + '.temp.mjs'
const resolvedPath = file + nanoid() + '.temp.mjs'
try {
let config: PeekyConfig = {}

Expand Down
3 changes: 1 addition & 2 deletions packages/peeky-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
"lodash": "^4.17.21",
"memfs": "^3.2.0",
"mlly": "^0.3.16",
"nanoid": "^3.3.1",
"pathe": "^0.2.0",
"pragma": "^1.0.0",
"pretty-format": "^27.4.2",
"shortid": "^2.2.16",
"sinon": "^9.2.3",
"slugify": "^1.6.0",
"source-map-support": "^0.5.19",
Expand All @@ -63,7 +63,6 @@
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.178",
"@types/node": "^14.14.21",
"@types/shortid": "^0.0.29",
"typescript": "^4.1.3"
}
}
6 changes: 3 additions & 3 deletions packages/peeky-runner/src/runtime/collect-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { basename, extname } from 'pathe'
import shortid from 'shortid'
import { nanoid } from 'nanoid'
import slugify from 'slugify'
import type { SuiteCollectData, TestCollectData } from '../message.js'
import type {
Expand Down Expand Up @@ -35,7 +35,7 @@ export function setupTestCollector (ctx: Context): {

const createSuite = (title: string, flag: TestFlag, parentSuite: TestSuite) => {
const suite: TestSuite = {
id: shortid(),
id: nanoid(),
title,
allTitles: [...parentSuite?.allTitles ?? [], title],
filePath: ctx.options.entry,
Expand Down Expand Up @@ -69,7 +69,7 @@ export function setupTestCollector (ctx: Context): {
getCurrentSuite().children.push([
'test',
{
id: shortid(),
id: nanoid(),
title,
handler,
error: null,
Expand Down
4 changes: 2 additions & 2 deletions packages/peeky-runner/src/runtime/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promisify } from 'util'
import { performance } from 'perf_hooks'
import fs from 'fs-extra'
import path from 'pathe'
import shortid from 'shortid'
import { nanoid } from 'nanoid'

export type V8Coverage = ReadonlyArray<Profiler.ScriptCoverage>

Expand All @@ -28,7 +28,7 @@ export function useCollectCoverage () {
await postSession('Profiler.stopPreciseCoverage')
await postSession('Profiler.disable')

const tempFile = path.join(process.cwd(), `node_modules/.temp/coverage/coverage-${shortid()}.json`)
const tempFile = path.join(process.cwd(), `node_modules/.temp/coverage/coverage-${nanoid()}.json`)
await fs.ensureDir(path.dirname(tempFile))
await fs.writeJson(tempFile, { result, timestamp: performance.now() })

Expand Down
4 changes: 2 additions & 2 deletions packages/peeky-runner/src/runtime/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MessagePort } from 'worker_threads'
import shortid from 'shortid'
import { nanoid } from 'nanoid'
import type { MainMessage, WorkerRemoteMethods } from '../message.js'

// Channel
Expand Down Expand Up @@ -38,7 +38,7 @@ export function toMainThread (): WorkerRemoteMethods {
toMainProxy = new Proxy({}, {
get: (target, method: string) => {
return (...args) => {
const id = shortid()
const id = nanoid()
const promise = !method.startsWith('on')
? new Promise((resolve, reject) => {
toMainPromiseMap.set(id, { resolve, reject })
Expand Down
3 changes: 1 addition & 2 deletions packages/peeky-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@
"graphql": "^15.4.0",
"graphql-ws": "^5.5.5",
"launch-editor": "^2.2.1",
"nanoid": "^3.3.1",
"nexus": "^1.0.0",
"object-inspect": "^1.11.0",
"pathe": "^0.2.0",
"random-emoji": "^1.0.2",
"shortid": "^2.2.16",
"slugify": "^1.6.0",
"ws": "^8.3.0"
},
"devDependencies": {
"@types/node": "^14.14.21",
"@types/shortid": "^0.0.29",
"@types/ws": "^8.2.2",
"typescript": "^4.1.3"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/peeky-server/src/schema/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs-extra'
import { fileURLToPath } from 'url'
import { performance } from 'perf_hooks'
import { arg, extendType, idArg, inputObjectType, nonNull, objectType } from 'nexus'
import shortid from 'shortid'
import { nanoid } from 'nanoid'
import { setupRunner, getStats, Runner } from '@peeky/runner'
import randomEmoji from 'random-emoji'
import objectInspect from 'object-inspect'
Expand Down Expand Up @@ -177,11 +177,11 @@ export interface CreateRunOptions {
}

export async function createRun (ctx: Context, options: CreateRunOptions) {
const runId = shortid()
const runId = nanoid()

const testFilesRaw = options.testFileIds ? testFiles.filter(f => options.testFileIds.includes(f.id)) : [...testFiles]
const runTestFiles: RunTestFileData[] = testFilesRaw.map(f => ({
id: shortid(),
id: nanoid(),
slug: f.relativePath.replace(/([\\/.])/g, '-'),
runId,
testFile: f,
Expand Down
36 changes: 12 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d70e9f

Please sign in to comment.