Skip to content

Commit

Permalink
chore: update type definitions
Browse files Browse the repository at this point in the history
New definitions reflect that `getgid()` is only available on POSIX
platforms, leading to these type errors:

    fig/Attributes.ts:101:19 - error TS2532: Object is possibly 'undefined'.

    101       this.#gid = process.getgid();
                          ~~~~~~~~~~~~~~

    fig/Attributes.ts:101:19 - error TS2722: Cannot invoke an object which is possibly 'undefined'.

    101       this.#gid = process.getgid();
                          ~~~~~~~~~~~~~~

    Found 2 errors in the same file, starting at: fig/Attributes.ts:101

As you can see in the diff, `getuid()` already had a type definition
like that, hence my `typeof` check. I refactored that to make it match
the change I'm making to the `getgid()` call as well.

The explicit imports of `process` aren't actually needed, but it seemed
a nice idea to make the dependence on the global explicit, so I went
through and did that too.
  • Loading branch information
wincent committed Jul 11, 2022
1 parent 5e53599 commit 1fd4383
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions aspects/dotfiles/files/.zsh/github/lib/gg/main.js
@@ -1,6 +1,7 @@
const child_process = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const process = require('node:process');
const {createInterface} = require('node:readline');

const TOOL_NAME = 'gg';
Expand Down
2 changes: 2 additions & 0 deletions aspects/node/index.ts
@@ -1,3 +1,5 @@
import * as process from 'node:process';

import {command, file, helpers, path, skip, task} from 'fig';

const {when} = helpers;
Expand Down
5 changes: 3 additions & 2 deletions fig/Attributes.ts
@@ -1,4 +1,5 @@
import * as os from 'node:os';
import * as process from 'node:process';

import assert from './assert.js';
import {existsSync} from './fs.js';
Expand Down Expand Up @@ -98,7 +99,7 @@ export default class Attributes {

get gid(): number {
if (typeof this.#gid !== 'number') {
this.#gid = process.getgid();
this.#gid = process.getgid?.() || -1;
}

return this.#gid;
Expand Down Expand Up @@ -150,7 +151,7 @@ export default class Attributes {

get uid(): number {
if (typeof this.#uid !== 'number') {
this.#uid = typeof process.getuid === 'function' ? process.getuid() : -1;
this.#uid = process.getuid?.() || -1;
}

return this.#uid;
Expand Down
2 changes: 2 additions & 0 deletions fig/Context.ts
@@ -1,3 +1,5 @@
import * as process from 'node:process';

import Attributes from './Attributes.js';
import ErrorWithMetadata from './ErrorWithMetadata.js';
import Compiler from './Compiler.js';
Expand Down
5 changes: 3 additions & 2 deletions fig/__tests__/resource-test.ts
@@ -1,4 +1,5 @@
import {join} from 'node:path';
import {cwd} from 'node:process';

import Context from '../Context.js';
import {file, files, template} from '../dsl/resource.js';
Expand Down Expand Up @@ -62,7 +63,7 @@ describe('file()', () => {
const example: any = file('example.txt');

expect(example.resolve.toString()).toBe(
join(process.cwd(), 'aspects/meta/files/example.txt')
join(cwd(), 'aspects/meta/files/example.txt')
);
})
);
Expand All @@ -86,7 +87,7 @@ describe('file()', () => {
const example: any = file('example.txt');

expect(example.resolve.dirname.join('other.txt').toString()).toBe(
join(process.cwd(), 'aspects/meta/files/other.txt')
join(cwd(), 'aspects/meta/files/other.txt')
);
})
);
Expand Down
1 change: 1 addition & 0 deletions fig/console.ts
@@ -1,3 +1,4 @@
import * as process from 'node:process';
import {clearLine, cursorTo} from 'node:readline';

import lock from './lock.js';
Expand Down
1 change: 1 addition & 0 deletions fig/main.ts
@@ -1,4 +1,5 @@
import {join} from 'node:path';
import * as process from 'node:process';

import variables from '../variables.js';
import Context from './Context.js';
Expand Down
1 change: 1 addition & 0 deletions fig/prompt.ts
@@ -1,3 +1,4 @@
import * as process from 'node:process';
import * as readline from 'node:readline';
import {Writable} from 'node:stream';

Expand Down
1 change: 1 addition & 0 deletions fig/test/harness.ts
@@ -1,4 +1,5 @@
import * as assert from 'node:assert';
import * as process from 'node:process';
import {Writable} from 'node:stream';

import ErrorWithMetadata from '../ErrorWithMetadata.js';
Expand Down
2 changes: 2 additions & 0 deletions variables.ts
@@ -1,3 +1,5 @@
import * as process from 'node:process';

import Context from 'fig/Context.js';

/**
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -3,11 +3,11 @@


"@types/node@*":
version "17.0.35"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.35.tgz#635b7586086d51fb40de0a2ec9d1014a5283ba4a"
integrity sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==
version "18.0.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.3.tgz#463fc47f13ec0688a33aec75d078a0541a447199"
integrity sha512-HzNRZtp4eepNitP+BD6k2L6DROIDG4Q0fm4x+dwfsr6LGmROENnok75VGw40628xf+iR24WeMFcHuuBDUAzzsQ==

typescript@*:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

0 comments on commit 1fd4383

Please sign in to comment.