Skip to content

Commit

Permalink
fix: misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 14, 2023
1 parent 7e1b67b commit 40e414c
Show file tree
Hide file tree
Showing 28 changed files with 251 additions and 274 deletions.
5 changes: 4 additions & 1 deletion .github/actions/audit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ inputs:
runs:
using: composite
steps:
- name: Run Audit
- name: Run Production Audit
shell: ${{ inputs.shell }}
run: |
npm audit --omit=dev
- name: Run Full Audit
shell: ${{ inputs.shell }}
run: |
npm audit --audit-level=none
2 changes: 1 addition & 1 deletion .github/actions/changed-files/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
required: true

outputs:
files:
names:
value: ${{ steps.files.outputs.result }}

runs:
Expand Down
15 changes: 4 additions & 11 deletions .github/actions/changed-workspaces/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ name: Get Changed Workspaces
inputs:
token:
description: GitHub token to use
shell:
description: shell to run on
default: bash
all:
default: false
type: boolean
files:
description: json stringified array of file names
type: string
description: json stringified array of file names or --all

outputs:
flags:
Expand All @@ -24,14 +17,14 @@ runs:
steps:
- name: Get Changed Files
uses: ./.github/actions/changed-files
if: ${{ !inputs.all && !inputs.files }}
if: ${{ !inputs.files }}
id: files
with:
token: ${{ inputs.token }}

- name: Get Workspaces
shell: ${{ inputs.shell }}
shell: bash
id: workspaces
run: |
flags=$(npm exec --offline -- template-oss-changed-workspaces '${{ (inputs.all && '--all') || (inputs.files || steps.files.outputs.result) }}')
flags=$(npm exec --offline -- template-oss-changed-workspaces '${{ inputs.files || steps.files.outputs.names }}')
echo "flags=${flags}" >> $GITHUB_OUTPUT
3 changes: 3 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ runs:
shell: ${{ inputs.shell }}
run: |
npm run lint --ignore-scripts ${{ inputs.flags }}
- name: Post Lint
shell: ${{ inputs.shell }}
run: |
npm run postlint --ignore-scripts ${{ inputs.flags }}
12 changes: 5 additions & 7 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ inputs:
default: latest
cache:
description: whether to cache npm install or not
type: boolean
default: false
shell:
description: shell to run on
default: bash
deps:
description: whether to run the deps step
type: boolean
default: true
default: 'true'
deps-command:
description: command to run for the dependencies step
default: install --ignore-scripts --no-audit --no-fund
Expand All @@ -40,12 +38,12 @@ runs:
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
cache: ${{ (inputs.cache && 'npm') || null }}
cache: ${{ (inputs.cache == 'true' && 'npm') || '' }}

- name: Check Node Version
if: inputs.npm-version
id: node-version
shell: ${{ inputs.shell }}
shell: bash
run: |
NODE_VERSION=$(node --version)
echo $NODE_VERSION
Expand Down Expand Up @@ -83,13 +81,13 @@ runs:
run: npm -v

- name: Setup Dependencies
if: inputs.deps
if: inputs.deps == 'true'
uses: ./.github/actions/deps
with:
command: ${{ inputs.deps-command }}
flags: ${{ inputs.deps-flags }}

- name: Add Problem Matcher
shell: ${{ inputs.shell }}
shell: bash
run: |
[[ -f ./.github/matchers/tap.json ]] && echo "::add-matcher::.github/matchers/tap.json"
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
uses: ./.github/actions/changed-workspaces
with:
token: ${{ secrets.GITHUB_TOKEN }}
all: ${{ inputs.all }}
files: ${{ (inputs.all && '--all') || '' }}

- name: Lint
uses: ./.github/actions/lint
Expand Down Expand Up @@ -113,6 +113,7 @@ jobs:
steps:
- name: Continue Matrix Run
id: continue-matrix
shell: bash
run: |
if [[ "${{ matrix.node-version }}" == "14.17.0" || "${{ inputs.all }}" == "true" ]]; then
echo "result=true" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -148,9 +149,8 @@ jobs:
continue-on-error: ${{ !!steps.check.outputs.check-id }}
uses: ./.github/actions/changed-workspaces
with:
shell: ${{ matrix.platform.shell }}
token: ${{ secrets.GITHUB_TOKEN }}
all: ${{ inputs.all }}
files: ${{ (inputs.all && '--all') || '' }}

- name: Test
if: steps.continue-matrix.outputs.result
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name: Post Dependabot
on: pull_request

jobs:
template-oss:
name: template-oss
npmcli-template-oss:
name: "@npmcli/template-oss"
permissions:
contents: write
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
Expand Down
2 changes: 1 addition & 1 deletion bin/changed-workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const main = async ({ cwd, files, all }) => {

const arg = process.argv[2]
const all = arg === '--all'
const files = all ? [] : JSON.parse(arg ?? '[]')
const files = all ? [] : JSON.parse(arg || '[]')

module.exports = main({
cwd: process.cwd(),
Expand Down
10 changes: 9 additions & 1 deletion lib/check/check-required.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const log = require('proc-log')
const npa = require('npm-package-arg')
const { partition } = require('lodash')
const { NAME, VERSION } = require('../util/config.js')
const hasPackage = require('../util/has-package.js')

const rmCommand = (specs) =>
Expand All @@ -11,10 +12,17 @@ const installCommand = (specs, flags) => specs.length ?

// ensure required packages are present in the correct place
const run = ({ pkg, path, config: { requiredPackages = {} } }) => {
const allRequiredPackages = {
...requiredPackages,
devDependencies: [
`${NAME}@${VERSION}`,
...(requiredPackages.devDependencies || []),
],
}
// keys are the dependency location in package.json
// values are a filtered list of parsed specs that dont exist in the current package
// { [location]: [spec1, spec2] }
const requiredByLocation = Object.entries(requiredPackages)
const requiredByLocation = Object.entries(allRequiredPackages)
.reduce((acc, [location, pkgs]) => {
acc[location] = pkgs
.filter((spec) => !hasPackage(pkg, spec, [location], path))
Expand Down
21 changes: 5 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const log = require('proc-log')
const { resolve } = require('path')
const getConfig = require('@npmcli/template-oss-config')
const PackageJson = require('@npmcli/package-json')
const mapWorkspaces = require('@npmcli/map-workspaces')
const { getConfig, CONFIG_KEY } = require('./util/config.js')

const getPkg = async (path) => {
log.verbose('get-pkg', path)

const pkgJson = (await PackageJson.load(path)).content
const pkgConfig = getConfig.getPkgConfig(pkgJson)
const pkgConfig = pkgJson[CONFIG_KEY] || {}
log.verbose('get-pkg', pkgConfig)

if (pkgConfig.content) {
Expand Down Expand Up @@ -43,23 +43,12 @@ const getWsPkgs = async (root, rootPkg) => {
return wsPkgs
}

const getPkgs = async (root) => {
log.verbose('get-pkgs', 'root', root)
const runAll = async (root, checks) => {
const results = []

const rootPkg = await getPkg(root)

const wsPkgs = await getWsPkgs(root, rootPkg)

return {
rootPkg,
wsPkgs,
pkgs: [rootPkg].concat(wsPkgs),
}
}

const runAll = async (root, checks) => {
const results = []
const { pkgs, rootPkg, wsPkgs } = await getPkgs(root)
const pkgs = [rootPkg].concat(wsPkgs)

const fullRootConfig = await getConfig({
pkg: rootPkg,
Expand Down
38 changes: 38 additions & 0 deletions lib/util/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const getDefaultConfig = require('@npmcli/template-oss-config')

const { name: NAME, version: VERSION } = require('../../package.json')
const DEFAULT_CONTENT = require.resolve('@npmcli/template-oss-content')
const CONFIG_KEY = 'templateOSS'

const getConfig = async (opts) => {
const { pkg, rootPkg } = opts
const isLatest = pkg.config.version === VERSION
const isDogFood = rootPkg.pkgJson.name === NAME
const isForce = process.argv.includes('--force')

return {
...await getDefaultConfig({
...opts,
defaultContent: DEFAULT_CONTENT,
}),
__NAME__: NAME,
__NAME_FS__: NAME.replace(/\//g, '-').replace(/@/g, ''),
__CONFIG_KEY__: CONFIG_KEY,
__VERSION__: VERSION,
// needs update if we are dogfooding this repo, with force argv, or its
// behind the current version
needsUpdate: isForce || isDogFood || !isLatest,
// booleans to control application of updates
isForce,
isDogFood,
isLatest,
}
}

module.exports = {
getConfig,
NAME,
VERSION,
CONFIG_KEY,
DEFAULT_CONTENT,
}
2 changes: 1 addition & 1 deletion lib/util/has-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const semver = require('semver')
const npa = require('npm-package-arg')
const { has } = require('lodash')
const { join, extname } = require('path')
const { name: NAME } = require('../../package.json')
const { NAME } = require('../util/config.js')

const installLocations = [
'dependencies',
Expand Down
Loading

0 comments on commit 40e414c

Please sign in to comment.