Skip to content

Commit

Permalink
fixes mostly lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Dec 14, 2023
1 parent 7696f78 commit 154dcef
Show file tree
Hide file tree
Showing 71 changed files with 789 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
site
.eslintrc.js
.eslintrc.cjs
build_utils
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ node_modules/
# Coverage
coverage

# Transpiled files
build/

# Optional npm cache directory
.npm

Expand Down
4 changes: 1 addition & 3 deletions build_utils/eslintrc.js → build_utils/eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
'single',
{ avoidEscape: true, allowTemplateLiterals: false },
],
'import/extensions': 'off',
'dot-location': 'warn',
'no-trailing-spaces': 'warn',
'no-multi-spaces': 'warn',
Expand Down Expand Up @@ -101,9 +102,6 @@ module.exports = {
}
],
'jest/valid-describe': ['off'],
'import/extensions': ['error', 'never', {
'json': 'always',
}],
'no-restricted-imports': ['error', { patterns: ['**/dist/**', 'src/*'] }],
// copied from https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js#L334
// removed rule about generators/iterators since es2019 natively supports them
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.eslintrc.js
/.eslintrc.cjs
/dist
/build.mjs
1 change: 1 addition & 0 deletions packages/cli-common/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/cli-common/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@jest/globals": "29.7.0",
"@types/lodash-es": "^4.17.12",
"@types/node": "18",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"eslint": "^8.36.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/plugins/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FlagProps } from '@oclif/core/lib/interfaces/parser.js'
import { Topic } from '@oclif/core/lib/interfaces'
import { Command, Interfaces } from '@oclif/core'
import { Command } from '@oclif/core'
import { ComposeModel, config as coreConfig } from '@preevy/core'
import { PluginInitContext } from './context.js'
import { HookFuncs, HooksListeners } from '../hooks.js'
Expand Down
1 change: 1 addition & 0 deletions packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/cli/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_modules/
coverage

# Transpiled files
build/
/build/

# Optional npm cache directory
.npm
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@types/lodash-es": "^4.17.12",
"@types/node": "18",
"@types/shell-escape": "^0.2.1",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"eslint": "^8.36.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-oclif": "^4",
Expand Down
16 changes: 5 additions & 11 deletions packages/cli/src/commands/profile/cp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Flags, ux } from '@oclif/core'
import inquirer from 'inquirer'
import * as inquirer from '@inquirer/prompts'
import { BaseCommand, text } from '@preevy/cli-common'
import { LocalProfilesConfig } from '@preevy/core'
import { loadProfileConfig } from '../../profile-command.js'
Expand All @@ -13,16 +13,10 @@ const validateFsType = (fsType: string) => {
return fsType
}

const chooseTargetAlias = async (defaultAlias: string) => (
await inquirer.prompt<{ targetAlias: string }>([
{
type: 'input',
name: 'targetAlias',
message: 'Target profile name',
default: defaultAlias,
},
])
).targetAlias
const chooseTargetAlias = async (defaultAlias: string) => await inquirer.input({
message: 'Target profile name',
default: defaultAlias,
})

// eslint-disable-next-line no-use-before-define
export default class CopyProfile extends BaseCommand<typeof CopyProfile> {
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/profile/link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { link, Org, localFs, profileStore, TokenExpiredError, getLivecycleTokensFromLocalFs } from '@preevy/core'
import { Flags, ux } from '@oclif/core'
import inquirer from 'inquirer'
import * as inquirer from '@inquirer/prompts'
import ProfileCommand from '../../profile-command.js'
import { LC_API_URL } from '../../defaults.js'

Expand Down Expand Up @@ -43,14 +43,13 @@ export default class Link extends ProfileCommand<typeof Link> {
if (orgs.length === 1) {
return orgs[0]
}
const selection = await inquirer.prompt<{org: string}>({ type: 'list',
name: 'org',
org = await inquirer.select({
message: 'Choose the organization to link the profile to',
choices: orgs.map(o => ({
name: o.name,
value: o.slug,
})) })
org = selection.org
})),
})
}
const orgInfo = orgs.find(o => o.slug === org)
if (!orgInfo) {
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const chooseFs: Record<FsType, FsChooser> = {
}) => {
const region = await inquirerAutoComplete<string>({
message: 'S3 bucket region',
source: async input => S3_REGIONS.filter(r => !input || r.includes(input.toLowerCase())).map(value => ({ value })),
source: async input => S3_REGIONS
.filter(r => !input || r.includes(input.toLowerCase()))
.map(value => ({ value })),
default: driver?.name === 'lightsail' && S3_REGIONS.includes(driver.flags.region as string)
? driver.flags.region as string
: 'us-east-1',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.eslintrc.js
/.eslintrc.cjs
/dist
/build.mjs
1 change: 1 addition & 0 deletions packages/common/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/common/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"@types/node": "18",
"@types/shell-escape": "^0.2.1",
"@types/ssh2": "^1.11.8",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"esbuild": "^0.19.9",
"eslint": "^8.36.0",
"husky": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/compose-tunnel-agent/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.eslintrc.js
/.eslintrc.cjs
/dist
/build.mjs
1 change: 1 addition & 0 deletions packages/compose-tunnel-agent/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/compose-tunnel-agent/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/compose-tunnel-agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'
import Docker from 'dockerode'
import { rimraf } from 'rimraf'
import { pino } from 'pino'
import { default as pinoPrettyModule } from 'pino-pretty'
import pinoPrettyModule from 'pino-pretty'
import {
requiredEnv,
formatPublicKey,
Expand Down
4 changes: 2 additions & 2 deletions packages/compose-tunnel-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"@types/node-fetch": "^2.6.3",
"@types/shell-escape": "^0.2.1",
"@types/ssh2": "^1.11.8",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"esbuild": "^0.19.9",
"eslint": "^8.36.0",
"husky": "^8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/compose-tunnel-agent/src/api-server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { AddressInfo } from 'node:net'
import { describe, expect, beforeAll, afterAll, jest, it } from '@jest/globals'
import { ChildProcess, spawn, exec } from 'child_process'
import { pino } from 'pino'
import { default as pinoPrettyModule } from 'pino-pretty'
import pinoPrettyModule from 'pino-pretty'
import Dockerode from 'dockerode'
import { inspect, promisify } from 'node:util'
import { default as waitForExpectModule } from 'wait-for-expect'
import waitForExpectModule from 'wait-for-expect'
import WebSocket from 'ws'
import stripAnsi from 'strip-ansi'
import { createApp } from './index.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.eslintrc.js
/.eslintrc.cjs
/dist
/build.mjs
1 change: 1 addition & 0 deletions packages/core/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/core/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"@types/sshpk": "^1.17.1",
"@types/tar": "^6.1.4",
"@types/tar-stream": "^2.2.2",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"eslint": "^8.36.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
Expand Down
96 changes: 96 additions & 0 deletions packages/core/src/build/image-tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { beforeEach, describe, it, expect } from '@jest/globals'
import { GitContext } from '../git.js'
import { FsReader } from '../store/index.js'
import { MockFunctions, mockFunction } from '../test-helpers.js'
import { ImageTagCalculator, imageTagCalculator } from './image-tag.js'

describe('imageTagCalculator', () => {
const dockerfileContents = 'FROM my-image'

type PartialGitContext = Pick<GitContext, 'commit' | 'localChanges'>

let mockReader: MockFunctions<FsReader>
beforeEach(() => {
mockReader = { read: mockFunction<FsReader['read']>() }
})

let mockGitContextCreator: () => PartialGitContext
let mockGitContext: MockFunctions<PartialGitContext>
beforeEach(() => {
mockGitContext = {
commit: mockFunction<GitContext['commit']>(async () => 'abcdef'),
localChanges: mockFunction<GitContext['localChanges']>(async () => ''),
}
mockGitContextCreator = mockFunction<() => PartialGitContext>(() => mockGitContext)
})

describe('sanity', () => {
let c: ImageTagCalculator
let tag: string

beforeEach(async () => {
c = imageTagCalculator({
gitContext: mockGitContextCreator,
fsReader: mockReader,
})

tag = await c({
context: '/context',
dockerfile: 'Dockerfile',
})
})

it('should call the commit function correctly', async () => {
expect(mockGitContext.commit).toHaveBeenCalledWith({ short: true })
})

it('should generate a tag', async () => {
expect(tag).toMatch(/^[a-z0-9-]+$/)
})

it('should generate the same tag for the same build', async () => {
expect(await c({
context: '/context',
dockerfile: 'Dockerfile',
})).toEqual(tag)
})

it('should generate the same tag if the dockerfile path changed', async () => {
expect(await c({
context: '/context',
dockerfile: 'Dockerfile.a',
})).toEqual(tag)
})

it('should generate a different tag if the context changed', async () => {
expect(await c({
context: '/context/a',
dockerfile: 'Dockerfile',
})).not.toEqual(tag)
})

it('should generate a different tag if the dockerfile contents changed', async () => {
mockReader.read.mockResolvedValue(Buffer.from(`${dockerfileContents}a`))
expect(await c({
context: '/context/a',
dockerfile: 'Dockerfile',
})).not.toEqual(tag)
})

it('should generate a different tag if the build args changed', async () => {
expect(await c({
context: '/context/a',
dockerfile: 'Dockerfile',
args: { foo: 'bar' },
})).not.toEqual(tag)
})

it('should generate a different tag if the build target changed', async () => {
expect(await c({
context: '/context/a',
dockerfile: 'Dockerfile',
target: 'dev',
})).not.toEqual(tag)
})
})
})
Loading

0 comments on commit 154dcef

Please sign in to comment.