Skip to content

Commit

Permalink
feat(allow-scripts): prototype of declaration file generation
Browse files Browse the repository at this point in the history
This adds `.d.ts` generation to `@lavamoat/allow-scripts`.

- Many type defs added to `src/types` for those modules which do not have them (nor are there any published to DefinitelyTyped).  In the future, some of these could be submitted to DefinitelyTyped, if we wish.
- Upgrade `yargs`
- Create reusable TS configuration supporting incremental builds
- Declaration files generated at build time and shipped in the `types` folder (which is now in `.gitignore`)
- Created `.depcheckrc`
- Added, updated, removed and/or fixed many docstring types

Note: the uncommon `skipLibCheck = false` setting in this module's `tsconfig.json` enables typechecking of the `.d.ts` files themselves.  These files are not compiled.
  • Loading branch information
boneskull committed Aug 21, 2023
1 parent 227df10 commit b01880d
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ temp/

# JetBrains
.idea

packages/allow-scripts/types
13 changes: 13 additions & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"composite": true,
"types": ["node"]
},
"extends": "@tsconfig/node14/tsconfig.json"
}
48 changes: 43 additions & 5 deletions package-lock.json

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

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@metamask/eslint-config-nodejs": "^12.0.0",
"@tsconfig/node14": "^14.1.0",
"@types/node": "^20.4.1",
"@types/yargs": "^17.0.24",
"ava": "^5.3.1",
"conventional-changelog-conventionalcommits": "^6.1.0",
"cross-env": "^7.0.3",
Expand All @@ -20,6 +23,7 @@
"eslint-plugin-react": "^7.33.0",
"husky": "^8.0.3",
"lerna": "^7.1.4",
"typescript": "^5.1.6",
"lint-staged": "^13.2.3"
},
"engines": {
Expand All @@ -32,8 +36,12 @@
"lint:eslint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:deps": "lerna run lint:deps",
"build": "npm -w @lavamoat/lavapack -w @lavamoat/viz -w @lavamoat/yarn-plugin-allow-scripts run build",
"build": "npm -w @lavamoat/lavapack -w @lavamoat/viz -w @lavamoat/yarn-plugin-allow-scripts run build && npm run build:types",
"build:types": "tsc -b",
"clean:types": "tsc -b --clean",
"watch:types": "tsc -b --watch",
"rebuild": "npm -w @lavamoat/lavapack -w @lavamoat/viz -w @lavamoat/yarn-plugin-allow-scripts run rebuild",
"rebuild:types": "npm run clean:types; npm run build:types",
"lint:staged": "lint-staged",
"lint:commit": "commitlint",
"postinstall": "husky install",
Expand Down
4 changes: 4 additions & 0 deletions packages/allow-scripts/.depcheckrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ignores:
# monorepo deps
- 'ava'
- "@types/npmcli__promise-spawn"

# only types (from @types/npmcli__promise-spawn) are referenced
- "@npmcli/promise-spawn"
8 changes: 6 additions & 2 deletions packages/allow-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@npmcli/run-script": "^6.0.0",
"bin-links": "4.0.1",
"npm-normalize-package-bin": "^3.0.0",
"yargs": "^16.2.0"
"yargs": "^17.7.2"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +29,9 @@
"directories": {
"test": "test"
},
"devDependencies": {
"@types/npmcli__promise-spawn": "^6.0.0"
},
"scripts": {
"test": "npm run test:prep && test:run",
"test:run": "ava",
Expand All @@ -45,5 +48,6 @@
"test/*.spec.js"
],
"timeout": "30s"
}
},
"types": "./types/index.d.ts"
}
9 changes: 5 additions & 4 deletions packages/allow-scripts/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env node

const yargs = require('yargs')
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const { runAllowedPackages, setDefaultConfiguration, printPackagesList } = require('./index.js')
const { writeRcFile, editPackageJson } = require('./setup.js')
const { FEATURE } = require('./toggles')
const { FEATURE } = require('./toggles')

start().catch((err) => {
console.error(err)
Expand Down Expand Up @@ -46,7 +47,7 @@ async function start () {
}

function parseArgs () {
const argsParser = yargs
const argsParser = yargs(hideBin(process.argv))
.usage('Usage: $0 <command> [options]')
.command('$0', 'run the allowed scripts')
.command('run', 'run the allowed scripts')
Expand All @@ -60,7 +61,7 @@ function parseArgs () {
})
.help()

const parsedArgs = argsParser.parse()
const parsedArgs = argsParser.parseSync()
parsedArgs.command = parsedArgs._[0]

return parsedArgs
Expand Down

0 comments on commit b01880d

Please sign in to comment.