diff --git a/builder/policy/policy.spec.ts b/builder/policy/policy.spec.ts index 2f0530a..019f0a0 100644 --- a/builder/policy/policy.spec.ts +++ b/builder/policy/policy.spec.ts @@ -5,25 +5,34 @@ 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() + } }) 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', () => { @@ -31,10 +40,13 @@ it('should onlyBuiltDependencies set via a file and config', () => { 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', () => { diff --git a/config/env-replace/env-replace.ts b/config/env-replace/env-replace.ts index cfe597b..d4074cc 100644 --- a/config/env-replace/env-replace.ts +++ b/config/env-replace/env-replace.ts @@ -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 diff --git a/env/envs/pnpm-env/types/nerf.d.ts b/env/envs/pnpm-env/types/nerf.d.ts new file mode 100644 index 0000000..992a0b4 --- /dev/null +++ b/env/envs/pnpm-env/types/nerf.d.ts @@ -0,0 +1,3 @@ +declare module 'nerf-dart' { + export default function (uri: string): string; +} diff --git a/network/ca-file/ca-file.ts b/network/ca-file/ca-file.ts index bb8fae7..c057d93 100644 --- a/network/ca-file/ca-file.ts +++ b/network/ca-file/ca-file.ts @@ -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 } diff --git a/network/proxy-agent/proxy-agent.spec.ts b/network/proxy-agent/proxy-agent.spec.ts index 853d384..cb8779c 100644 --- a/network/proxy-agent/proxy-agent.spec.ts +++ b/network/proxy-agent/proxy-agent.spec.ts @@ -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, diff --git a/network/proxy-agent/proxy-agent.strict-ssl.spec.ts b/network/proxy-agent/proxy-agent.strict-ssl.spec.ts index 7a08b13..935a6e7 100644 --- a/network/proxy-agent/proxy-agent.strict-ssl.spec.ts +++ b/network/proxy-agent/proxy-agent.strict-ssl.spec.ts @@ -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 diff --git a/os/env/path-extender-windows/path-extender-windows.ts b/os/env/path-extender-windows/path-extender-windows.ts index ea46293..0cd60c3 100644 --- a/os/env/path-extender-windows/path-extender-windows.ts +++ b/os/env/path-extender-windows/path-extender-windows.ts @@ -30,7 +30,7 @@ export interface AddDirToWindowsEnvPathOpts { export interface EnvVariableChange { variable: string, action: EnvVariableChangeAction - oldValue: string, + oldValue: string | undefined, newValue: string, } @@ -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}`) } @@ -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 { @@ -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 } } } diff --git a/os/env/path-extender/path-extender.ts b/os/env/path-extender/path-extender.ts index 4d495c4..9978809 100644 --- a/os/env/path-extender/path-extender.ts +++ b/os/env/path-extender/path-extender.ts @@ -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}`) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 99a231d..118684c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,12 @@ importers: '@types/node': specifier: '>=18.11.9 <19.0.0' version: 18.19.8 + '@types/node-fetch': + specifier: ^2.6.11 + version: 2.6.11 + '@types/proxy': + specifier: ^1.0.4 + version: 1.0.4 '@types/react': specifier: ^17.0.8 version: 17.0.75 @@ -12902,6 +12908,13 @@ packages: resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==} dev: false + /@types/node-fetch@2.6.11: + resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==} + dependencies: + '@types/node': 18.19.8 + form-data: 4.0.0 + dev: true + /@types/node-forge@1.3.11: resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==} dependencies: @@ -12928,6 +12941,12 @@ packages: /@types/prop-types@15.7.11: resolution: {integrity: sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==} + /@types/proxy@1.0.4: + resolution: {integrity: sha512-KnYy7hpp3wXQ2U0ExvCMF9BvWZ6h2aI0XWb8g705mn26Zmn2HO/eLRi6UuhHELA6MNJtYtiZYWv38gobJN0xXQ==} + dependencies: + '@types/node': 18.19.8 + dev: true + /@types/qs@6.9.11: resolution: {integrity: sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==} dev: false @@ -18784,7 +18803,6 @@ packages: asynckit: 0.4.0 combined-stream: 1.0.8 mime-types: 2.1.35 - dev: false /format@0.2.2: resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==} diff --git a/workspace.jsonc b/workspace.jsonc index 7b2de1e..e0e10b5 100644 --- a/workspace.jsonc +++ b/workspace.jsonc @@ -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",