Skip to content

Commit

Permalink
Upgrade Jest, Typescript, Eslint dependencies (#156)
Browse files Browse the repository at this point in the history
This PR extends #154 (comment) to upgrade jest, which ends up upgrading the dependencies that caused those issues. It also upgrades typescript and eslint to resolve various issues associated with upgrading jest.

Looks like this also replaces: #155

This appears to resolve #153 for me.

cc @bryantbiggs @alexmarchis-toptal: let me know if this fixes your problems. Thanks for originally digging into this, @bryantbiggs!
  • Loading branch information
colinking authored Dec 1, 2020
1 parent 61fac02 commit d034830
Show file tree
Hide file tree
Showing 32 changed files with 3,250 additions and 2,324 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,28 @@ jobs:

test-web-javascript-dev:
docker:
- image: cypress/browsers:chrome69
- image: cypress/browsers:node10.16.3-chrome80-ff73
- image: segment/mock:v0.0.2
steps:
- attach_workspace: { at: . }
- run: make test-web-javascript-dev
test-web-javascript-prod:
docker:
- image: cypress/browsers:chrome69
- image: cypress/browsers:node10.16.3-chrome80-ff73
- image: segment/mock:v0.0.2
steps:
- attach_workspace: { at: . }
- run: make test-web-javascript-prod
test-web-typescript-dev:
docker:
- image: cypress/browsers:chrome69
- image: cypress/browsers:node10.16.3-chrome80-ff73
- image: segment/mock:v0.0.2
steps:
- attach_workspace: { at: . }
- run: make test-web-typescript-dev
test-web-typescript-prod:
docker:
- image: cypress/browsers:chrome69
- image: cypress/browsers:node10.16.3-chrome80-ff73
- image: segment/mock:v0.0.2
steps:
- attach_workspace: { at: . }
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Have an idea for improving Typewriter? [Submit an issue first](https://github.co
# Install dependencies
$ yarn
# Test your Typewriter installation by regenerating Typewriter's typewriter client.
$ yarn dev build
$ yarn build && yarn dev build
```

### Running Tests
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.15.3
10
2 changes: 1 addition & 1 deletion example/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Pane, Button, majorScale, Card, Paragraph, Text, Link } from 'evergreen
import Router, { withRouter } from 'next/router'
import { get } from 'lodash'

interface Props {
type Props = {
onSignOut: (props: { id: string }) => void
}

Expand Down
33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@
"@types/analytics-node": "^3.1.1",
"@types/got": "^9.6.7",
"@types/hapi__joi": "^15.0.2",
"@types/jest": "^24.0.11",
"@types/jest-expect-message": "^1.0.0",
"@types/jest": "^26.0.15",
"@types/jest-expect-message": "^1.0.3",
"@types/js-yaml": "^3.12.1",
"@types/json-schema": "^7.0.3",
"@types/json-stable-stringify": "^1.0.32",
"@types/lodash": "^4.14.123",
"@types/node": "^11.13.6",
"@types/prettier": "^1.16.3",
"@types/prompts": "2.0.0",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"@typescript-eslint/parser": "^1.6.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"copyfiles": "^2.1.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.14.2",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
"husky": "^2.1.0",
"jest": "^24.7.1",
"jest": "^26.6.3",
"jest-expect-message": "^1.0.2",
"lint-staged": "^8.1.7",
"np": "^5.0.1",
"snyk": "^1.250.0",
"ts-jest": "^24.0.2",
"ts-jest": "^26.4.4",
"ts-node": "^8.1.0",
"tsconfig-paths": "^3.8.0",
"typewriter": "^7.0.0-33"
"typewriter": "^7.3.0"
},
"dependencies": {
"@hapi/joi": "^15.1.1",
Expand All @@ -74,8 +74,8 @@
"react": "^16.9.0",
"semver": "^6.3.0",
"sort-keys": "^3.0.0",
"typescript": "^3.4.5",
"yargs": "^16.0.3"
"typescript": "^4.1.2",
"yargs": "^16.1.1"
},
"files": [
"dist",
Expand Down Expand Up @@ -114,13 +114,10 @@
}
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-use-before-define": [
"error",
"nofunc"
],
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/interface-name-prefix": "off"
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-empty-function": "off"
},
"overrides": [
{
Expand Down
22 changes: 8 additions & 14 deletions src/cli/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export namespace SegmentAPI {
export type GetTrackingPlanResponse = TrackingPlan

// https://reference.segmentapis.com/?version=latest#ef9f50a2-7031-4ddf-898a-387266894a04
export interface ListTrackingPlansResponse {
export type ListTrackingPlansResponse = {
tracking_plans: TrackingPlan[]
}

export interface TrackingPlan {
export type TrackingPlan = {
name: string
display_name: string
rules: {
Expand All @@ -27,19 +27,19 @@ export namespace SegmentAPI {
update_time: Date
}

export interface RuleMetadata {
export type RuleMetadata = {
name: string
description?: string
rules: JSONSchema7
version: number
}

// https://reference.segmentapis.com/?version=latest#7ed2968b-c4a5-4cfb-b4bf-7d28c7b38bd2
export interface ListWorkspacesResponse {
export type ListWorkspacesResponse = {
workspaces: Workspace[]
}

export interface Workspace {
export type Workspace = {
name: string
display_name: string
id: string
Expand All @@ -55,9 +55,7 @@ export async function fetchTrackingPlan(options: {
const url = `workspaces/${options.workspaceSlug}/tracking-plans/${options.id}`
const response = await apiGet<SegmentAPI.GetTrackingPlanResponse>(url, options.token)

// eslint-disable-next-line @typescript-eslint/camelcase
response.create_time = new Date(response.create_time)
// eslint-disable-next-line @typescript-eslint/camelcase
response.update_time = new Date(response.update_time)

return sanitizeTrackingPlan(response)
Expand All @@ -72,12 +70,9 @@ export async function fetchTrackingPlans(options: {
const url = `workspaces/${options.workspaceSlug}/tracking-plans`
const response = await apiGet<SegmentAPI.ListTrackingPlansResponse>(url, options.token)

// eslint-disable-next-line @typescript-eslint/camelcase
return response.tracking_plans.map(tp => ({
...tp,
// eslint-disable-next-line @typescript-eslint/camelcase
create_time: new Date(tp.create_time),
// eslint-disable-next-line @typescript-eslint/camelcase
update_time: new Date(tp.update_time),
}))
}
Expand All @@ -89,7 +84,7 @@ export async function fetchAllTrackingPlans(options: {
const trackingPlans = []

const workspaces = await fetchWorkspaces({ token: options.token })
for (var workspace of workspaces) {
for (const workspace of workspaces) {
const workspaceTPs = await fetchTrackingPlans({
workspaceSlug: workspace.name.replace('workspaces/', ''),
token: options.token,
Expand All @@ -107,15 +102,14 @@ export async function fetchWorkspaces(options: { token: string }): Promise<Segme

return resp.workspaces.map(w => ({
...w,
// eslint-disable-next-line @typescript-eslint/camelcase
create_time: new Date(w.create_time),
}))
}

// validateToken returns true if a token is a valid Segment API token.
// Note: results are cached in-memory since it is commonly called multiple times
// for the same token (f.e. in `config/`).
interface TokenValidationResult {
type TokenValidationResult = {
isValid: boolean
workspace?: SegmentAPI.Workspace
}
Expand All @@ -127,7 +121,7 @@ export async function validateToken(token: string | undefined): Promise<TokenVal

// If we don't have a cached result, query the API to find out if this is a valid token.
if (!tokenValidationCache[token]) {
let result: TokenValidationResult = { isValid: false }
const result: TokenValidationResult = { isValid: false }
try {
const workspaces = await fetchWorkspaces({ token })
result.isValid = workspaces.length > 0
Expand Down
8 changes: 4 additions & 4 deletions src/cli/api/trackingplans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function writeTrackingPlan(
configPath: string | undefined,
plan: SegmentAPI.TrackingPlan,
config: TrackingPlanConfig
) {
): Promise<void> {
const path = resolveRelativePath(configPath, config.path, TRACKING_PLAN_FILENAME)
await verifyDirectoryExists(path, 'file')

Expand All @@ -52,13 +52,13 @@ export async function writeTrackingPlan(
})
}

export function sanitizeTrackingPlan(plan: SegmentAPI.TrackingPlan) {
export function sanitizeTrackingPlan(plan: SegmentAPI.TrackingPlan): SegmentAPI.TrackingPlan {
// TODO: on JSON Schema Draft-04, required fields must have at least one element.
// Therefore, we strip `required: []` from your rules so this error isn't surfaced.
return sortKeys(plan, { deep: true })
}

export interface TrackingPlanDeltas {
export type TrackingPlanDeltas = {
added: number
modified: number
removed: number
Expand Down Expand Up @@ -107,7 +107,7 @@ export function computeDelta(
return deltas
}

export function parseTrackingPlanName(name: string) {
export function parseTrackingPlanName(name: string): { id: string; workspaceSlug: string } {
const parts = name.split('/')

// Sane fallback:
Expand Down
20 changes: 10 additions & 10 deletions src/cli/commands/build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { gen, RawTrackingPlan } from '../../generators/gen'
import { SEGMENT_AUTOGENERATED_FILE_WARNING } from '../../templates'
import { join } from 'path'
import { version } from '../../../package.json'
import { StandardProps, DebugContext, AnalyticsProps } from '../index'
import { StandardProps, DebugContext } from '../index'
import { ErrorContext, wrapError, toUnexpectedError, WrappedError, isWrappedError } from './error'
import figures from 'figures'
import { Init } from './init'
Expand All @@ -36,7 +36,7 @@ const readdir = promisify(fs.readdir)
const writeFile = promisify(fs.writeFile)
const unlink = promisify(fs.unlink)

interface Props extends StandardProps {
type Props = StandardProps & {
/** Whether or not to generate a production client. */
production: boolean
/** Whether or not to update the local `plan.json` with the latest Tracking Plan. */
Expand Down Expand Up @@ -117,7 +117,7 @@ export const Build: React.FC<Props> = ({
)
}

interface UpdatePlanStepProps {
type UpdatePlanStepProps = {
config: Config
configPath: string
update: boolean
Expand Down Expand Up @@ -262,7 +262,7 @@ export const UpdatePlanStep: React.FC<UpdatePlanStepProps> = ({
)
}

interface ClearFilesProps {
type ClearFilesProps = {
config: Config
configPath: string
step: number
Expand Down Expand Up @@ -306,7 +306,7 @@ export const ClearFilesStep: React.FC<ClearFilesProps> = ({ config, configPath,
// lines of every generated file.
async function clearFolder(path: string): Promise<void> {
const fileNames = await readdir(path, 'utf-8')
for (let fileName of fileNames) {
for (const fileName of fileNames) {
const fullPath = join(path, fileName)
try {
const contents = await readFile(fullPath, 'utf-8')
Expand All @@ -328,7 +328,7 @@ export const ClearFilesStep: React.FC<ClearFilesProps> = ({ config, configPath,
return <Step name={stepName} isRunning={isRunning} isDone={isDone} />
}

interface GenerationProps {
type GenerationProps = {
config: Config
configPath: string
production: boolean
Expand Down Expand Up @@ -357,7 +357,7 @@ export const GenerationStep: React.FC<GenerationProps> = ({
})

// Write it out to the specified directory:
for (var file of files) {
for (const file of files) {
const path = resolveRelativePath(configPath, trackingPlan.path, file.path)
await verifyDirectoryExists(path, 'file')
await writeFile(path, file.contents, {
Expand All @@ -381,7 +381,7 @@ export const GenerationStep: React.FC<GenerationProps> = ({
)
}

interface AfterStepProps {
type AfterStepProps = {
config: Config
configPath: string
step: number
Expand Down Expand Up @@ -463,7 +463,7 @@ function useStep<Arg>(
}
}

interface StepProps {
type StepProps = {
name: string
isSkipped?: boolean
isRunning: boolean
Expand Down Expand Up @@ -503,7 +503,7 @@ const Step: React.FC<StepProps> = ({ name, isSkipped, isRunning, isDone, childre
)
}

interface NoteProps {
type NoteProps = {
isWarning?: boolean
}

Expand Down
Loading

0 comments on commit d034830

Please # to comment.