Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Walker-GM committed Aug 18, 2024
1 parent c3a14f8 commit 9d455c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build:pack": "yarn pack -o redwoodjs-api.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
"check:attw": "yarn rw-fwtools-attw $(pwd)",
"check:attw": "yarn rw-fwtools-attw",
"check:package": "concurrently npm:check:attw yarn:publint",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "vitest run",
Expand Down
27 changes: 12 additions & 15 deletions packages/framework-tools/src/attw.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { execSync } from 'node:child_process'
import fs from 'node:fs/promises'
import { createRequire } from 'node:module'
import path from 'node:path'

import { $ } from 'zx'
$.verbose = true

interface Problem {
kind: string
entrypoint?: string
resolutionKind?: string
}

interface Options {
cwd: string
}

export async function attw({ cwd }: Options): Promise<Problem[]> {
export async function attw(): Promise<Problem[]> {
// We can't rely on directly running the attw binary because it's not
// a direct dependency of the package that will ultimately use this.
// Instead, we have to do a little work to find the attw binary and run it.
Expand All @@ -27,15 +22,17 @@ export async function attw({ cwd }: Options): Promise<Problem[]> {
)

// Run attw via it's CLI
await $({
nothrow: true,
cwd,
})`node ${attwBinPath} -P -f json > .attw.json`
const outputFile = '.attw.json'
try {
execSync(`node ${attwBinPath} -P -f json > ${outputFile}`)

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
} catch {
// We don't care about non-zero exit codes
}

// Read the resulting JSON file
const output = await $`cat .attw.json`
await $`rm .attw.json`
const json = JSON.parse(output.stdout)
const output = await fs.readFile(outputFile, 'utf8')
await fs.unlink(outputFile)
const json = JSON.parse(output)

// If no errors were found then return early
if (!json.analysis.problems || json.analysis.problems.length === 0) {
Expand Down
12 changes: 4 additions & 8 deletions packages/framework-tools/src/bins/rw-fwtools-attw.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import process from 'node:process'

import { attw } from '../attw.js'

async function main() {
const cwd = process.argv[2]
if (!cwd) {
console.error('Usage: rw-fwtools-attw <path-to-package>')
process.exit(1)
}

console.log(`Running attw against: ${cwd}`)
console.log(`Running attw against: ${process.cwd()}`)

const problems = await attw({ cwd })
const problems = await attw()
if (problems.length > 0) {
console.error('Problems found:')
for (const problem of problems) {
Expand Down

0 comments on commit 9d455c9

Please sign in to comment.