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

fix: TS Errors #19

Merged
merged 4 commits into from
Feb 7, 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
34 changes: 23 additions & 11 deletions builder/policy/policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,48 @@ it('should neverBuiltDependencies', () => {
const allowBuild = createAllowBuildFunction({
neverBuiltDependencies: ['foo'],
})
expect(allowBuild('foo')).toBeFalsy()
expect(allowBuild('bar')).toBeTruthy()
expect(typeof allowBuild).toBe('function')
if (allowBuild) {
expect(allowBuild('foo')).toBeFalsy()
expect(allowBuild('bar')).toBeTruthy()
}
nachoaldamav marked this conversation as resolved.
Show resolved Hide resolved
})

it('should onlyBuiltDependencies', () => {
const allowBuild = createAllowBuildFunction({
onlyBuiltDependencies: ['foo'],
})
expect(allowBuild('foo')).toBeTruthy()
expect(allowBuild('bar')).toBeFalsy()
expect(typeof allowBuild).toBe('function')
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()
expect(typeof allowBuild).toBe('function')
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()
expect(typeof allowBuild).toBe('function')
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 as any).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.

2 changes: 2 additions & 0 deletions workspace.jsonc
Original file line number Diff line number Diff line change
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
Loading