Skip to content

Commit

Permalink
chore: fix TS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Feb 6, 2024
1 parent 78f612d commit 19e788a
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 24 deletions.
30 changes: 19 additions & 11 deletions builder/policy/policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,44 @@ it('should neverBuiltDependencies', () => {
const allowBuild = createAllowBuildFunction({
neverBuiltDependencies: ['foo'],
})
expect(allowBuild('foo')).toBeFalsy()
expect(allowBuild('bar')).toBeTruthy()
if (allowBuild) {
expect(allowBuild('foo')).toBeFalsy()
expect(allowBuild('bar')).toBeTruthy()
}
})

it('should onlyBuiltDependencies', () => {
const allowBuild = createAllowBuildFunction({
onlyBuiltDependencies: ['foo'],
})
expect(allowBuild('foo')).toBeTruthy()
expect(allowBuild('bar')).toBeFalsy()
if (allowBuild) {
expect(allowBuild('foo')).toBeTruthy()
expect(allowBuild('bar')).toBeFalsy()
}
})

it('should onlyBuiltDependencies set via a file', () => {
const allowBuild = createAllowBuildFunction({
onlyBuiltDependenciesFile: path.join(__dirname, 'onlyBuild.json'),
})
expect(allowBuild('zoo')).toBeTruthy()
expect(allowBuild('qar')).toBeTruthy()
expect(allowBuild('bar')).toBeFalsy()
if (allowBuild) {
expect(allowBuild('zoo')).toBeTruthy()
expect(allowBuild('qar')).toBeTruthy()
expect(allowBuild('bar')).toBeFalsy()
}
})

it('should onlyBuiltDependencies set via a file and config', () => {
const allowBuild = createAllowBuildFunction({
onlyBuiltDependencies: ['bar'],
onlyBuiltDependenciesFile: path.join(__dirname, 'onlyBuild.json'),
})
expect(allowBuild('zoo')).toBeTruthy()
expect(allowBuild('qar')).toBeTruthy()
expect(allowBuild('bar')).toBeTruthy()
expect(allowBuild('esbuild')).toBeFalsy()
if (allowBuild) {
expect(allowBuild('zoo')).toBeTruthy()
expect(allowBuild('qar')).toBeTruthy()
expect(allowBuild('bar')).toBeTruthy()
expect(allowBuild('esbuild')).toBeFalsy()
}
})

it('should return undefined if no policy is set', () => {
Expand Down
2 changes: 1 addition & 1 deletion config/env-replace/env-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function replaceEnvMatch (env: NodeJS.ProcessEnv, orig: string, escape: string,

const ENV_VALUE = /([^:-]+)(:?)-(.+)/

function getEnvValue (env: NodeJS.ProcessEnv, name: string): string {
function getEnvValue (env: NodeJS.ProcessEnv, name: string): string | undefined {
const matched = name.match(ENV_VALUE)
if (!matched) return env[name]
const [, variableName, colon, fallback] = matched
Expand Down
3 changes: 3 additions & 0 deletions env/envs/pnpm-env/types/nerf.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'nerf-dart' {
export default function (uri: string): string;
}
2 changes: 1 addition & 1 deletion network/ca-file/ca-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function readCAFileSync (filePath: string): string[] | undefined {
.filter((ca) => Boolean(ca.trim()))
.map((ca) => `${ca.trimLeft()}${delim}`)
return output
} catch (err) {
} catch (err: any) { // eslint-disable-line
if (err.code === 'ENOENT') return undefined
throw err
}
Expand Down
2 changes: 1 addition & 1 deletion network/proxy-agent/proxy-agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('a socks proxy', () => {
}
const agent = getProxyAgent('https://foo.com/bar', opts)
expect(agent instanceof SocksProxyAgent).toBeTruthy()
expect(agent['proxy']).toEqual({
expect((agent instanceof SocksProxyAgent)['proxy']).toEqual({
host: 'my.proxy',
port: 1234,
type: 5,
Expand Down
2 changes: 1 addition & 1 deletion network/proxy-agent/proxy-agent.strict-ssl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getProxyAgent } from './proxy-agent'
import Proxy from 'proxy'

describe('untrusted certificate', () => {
let proxy: Proxy
let proxy: any
let proxyPort: number
beforeAll((done) => {
// setup HTTP proxy server
Expand Down
11 changes: 7 additions & 4 deletions os/env/path-extender-windows/path-extender-windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AddDirToWindowsEnvPathOpts {
export interface EnvVariableChange {
variable: string,
action: EnvVariableChangeAction
oldValue: string,
oldValue: string | undefined,
newValue: string,
}

Expand All @@ -41,7 +41,10 @@ export async function addDirToWindowsEnvPath (dir: string, opts?: AddDirToWindow
// Otherwise, the non-ascii characters in the environment variables will become garbled characters.
const chcpResult = await execa('chcp')
const cpMatch = /\d+/.exec(chcpResult.stdout) ?? []
const cpBak = parseInt(cpMatch[0])
if (cpMatch.length === 0) {
throw new PnpmError('CHCP', `exec chcp failed: ${chcpResult.stderr}`)
}
const cpBak = parseInt(cpMatch[0] as string)
if (chcpResult.failed || !(cpBak > 0)) {
throw new PnpmError('CHCP', `exec chcp failed: ${cpBak}, ${chcpResult.stderr}`)
}
Expand All @@ -64,7 +67,7 @@ async function _addDirToWindowsEnvPath (dir: string, opts: AddDirToWindowsEnvPat
if (opts.proxyVarName) {
changes.push(await updateEnvVariable(registryOutput, opts.proxyVarName, addedDir, {
expandableString: false,
overwrite: opts.overwriteProxyVar,
overwrite: opts.overwriteProxyVar ?? false
}))
changes.push(await addToPath(registryOutput, `%${opts.proxyVarName}%`, opts.position))
} else {
Expand All @@ -91,7 +94,7 @@ async function updateEnvVariable (
return { variable: name, action: 'skipped', oldValue: currentValue, newValue: value }
} else {
await setEnvVarInRegistry(name, value, { expandableString: opts.expandableString })
return { variable: name, action: 'updated', oldValue: currentValue, newValue: value }
return { variable: name, action: 'updated', oldValue: currentValue as string, newValue: value }
}
}

Expand Down
4 changes: 2 additions & 2 deletions os/env/path-extender/path-extender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function addDirToEnvPath(dir: string, opts: AddDirToEnvPathOpts): P
}

export function renderWindowsReport (changedEnvVariables: PathExtenderWindowsReport): PathExtenderReport {
const oldSettings = []
const newSettings = []
const oldSettings: string[] = []
const newSettings: string[] = []
for (const changedEnvVariable of changedEnvVariables) {
if (changedEnvVariable.oldValue) {
oldSettings.push(`${changedEnvVariable.variable}=${changedEnvVariable.oldValue}`)
Expand Down
20 changes: 19 additions & 1 deletion pnpm-lock.yaml

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

8 changes: 6 additions & 2 deletions workspace.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* this is the main configuration file of your bit workspace.
* for full documentation, please see: https://bit.dev/docs/workspace/workspace-configuration
**/ {
**/{
"$schema": "https://static.bit.dev/teambit/schemas/schema.json",
/**
* main configuration of the Bit workspace.
Expand Down Expand Up @@ -51,6 +51,8 @@
"@teambit/react.react-env": "^1.0.34",
"@teambit/typescript.typescript-compiler": "^2.0.15",
"@types/graceful-fs": "4.1.5",
"@types/node-fetch": "^2.6.11",
"@types/proxy": "^1.0.4",
"@types/string.prototype.matchall": "4.0.1",
"agentkeepalive": "4.2.1",
"ci-info": "^3.9.0",
Expand Down Expand Up @@ -80,7 +82,9 @@
"teambit.workspace/variants": {
"*": {
"teambit.pkg/pkg": {
"packageManagerPublishArgs": ["--access public"],
"packageManagerPublishArgs": [
"--access public"
],
"packageJson": {
"name": "@pnpm/{scope}.{name}",
"private": false,
Expand Down

0 comments on commit 19e788a

Please sign in to comment.