Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into selected-ox
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Sep 15, 2023
2 parents bfd3e92 + cf286f5 commit 7ccc76a
Show file tree
Hide file tree
Showing 30 changed files with 371 additions and 396 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down Expand Up @@ -167,6 +167,7 @@ jobs:
- 16.x
- 18.0.0
- 18.x
- 20.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci-test-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down Expand Up @@ -113,6 +113,7 @@ jobs:
- 16.x
- 18.0.0
- 18.x
- 20.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down Expand Up @@ -113,6 +113,7 @@ jobs:
- 16.x
- 18.0.0
- 18.x
- 20.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
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 @@ -28,8 +28,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down Expand Up @@ -201,8 +201,8 @@ jobs:
uses: actions/setup-node@v3
id: node
with:
node-version: 18.x
check-latest: contains('18.x', '.x')
node-version: 20.x
check-latest: contains('20.x', '.x')

# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
Expand Down Expand Up @@ -425,7 +425,7 @@ jobs:
- name: Publish
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: npm publish --provenance
run: npm publish --provenance --tag=latest

post-release-integration:
needs: [ release, release-integration ]
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.18.1"
".": "4.19.0"
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [4.19.0](https://github.com/npm/template-oss/compare/v4.18.1...v4.19.0) (2023-09-15)

### Features

* [`994a278`](https://github.com/npm/template-oss/commit/994a2784df4b76c5e0362e9877fb6ae63e94bd77) [#356](https://github.com/npm/template-oss/pull/356) set ci versions from engines (@lukekarrys)
* [`cad156a`](https://github.com/npm/template-oss/commit/cad156a3a929ab30c5d9e595443b22f399f3941c) [#360](https://github.com/npm/template-oss/pull/360) set backport release from config instead of current branch (@lukekarrys)

### Bug Fixes

* [`de319e8`](https://github.com/npm/template-oss/commit/de319e8b20e5ab64770add7a9b847a2c76d22159) [#358](https://github.com/npm/template-oss/pull/358) allow overriding path to npm bin in workspaces (@lukekarrys)

## [4.18.1](https://github.com/npm/template-oss/compare/v4.18.0...v4.18.1) (2023-09-12)

### Bug Fixes
Expand Down
100 changes: 49 additions & 51 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
const { relative, dirname, join, extname, posix, win32 } = require('path')
const { defaults, pick, omit, uniq } = require('lodash')
const semver = require('semver')
const parseCIVersions = require('./util/parse-ci-versions.js')
const { defaults, pick, omit, uniq, isPlainObject } = require('lodash')
const ciVersions = require('./util/ci-versions.js')
const parseDependabot = require('./util/dependabot.js')
const git = require('./util/git.js')
const gitignore = require('./util/gitignore.js')
const { mergeWithArrays } = require('./util/merge.js')
const { mergeWithCustomizers, customizers } = require('./util/merge.js')
const { FILE_KEYS, parseConfig: parseFiles, getAddedFiles, mergeFiles } = require('./util/files.js')

const CONFIG_KEY = 'templateOSS'
const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {}

const { name: NAME, version: LATEST_VERSION } = require('../package.json')
const { minimatch } = require('minimatch')
const MERGE_KEYS = [...FILE_KEYS, 'defaultContent', 'content']
const DEFAULT_CONTENT = require.resolve(NAME)

const merge = mergeWithArrays('branches', 'distPaths', 'allowPaths', 'ignorePaths')
const merge = mergeWithCustomizers(
customizers.mergeArrays('branches', 'distPaths', 'allowPaths', 'ignorePaths'),
(value, srcValue, key) => {
if (key === 'ciVersions' && (Array.isArray(srcValue) || isPlainObject(srcValue))) {
return { ...ciVersions.parse(value), ...ciVersions.parse(srcValue) }
}
}
)

const makePosix = (v) => v.split(win32.sep).join(posix.sep)
const deglob = (v) => makePosix(v).replace(/[/*]+$/, '')
const posixDir = (v) => `${v === '.' ? '' : deglob(v).replace(/\/$/, '')}${posix.sep}`
const posixGlob = (str) => `${posixDir(str)}**`

const getCmdPath = (key, { rootConfig, defaultConfig, isRoot, pkg, rootPkg }) => {
// Make a path relative from a workspace to the root if we are in a workspace
const wsToRoot = (p) => isRoot ? p : makePosix(join(relative(pkg.path, rootPkg.path), p))
const getCmdPath = (key, { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) => {
const result = (local, isRelative) => {
let root = local
const isLocal = local.startsWith('.') || local.startsWith('/')

if (isLocal) {
if (isRelative) {
// Make a path relative from a workspace to the root if we are in a workspace
local = makePosix(join(relative(pkg.path, rootPkg.path), local))
}
local = `node ${local}`
root = `node ${root}`
}

return {
isLocal,
local,
root,
}
}

const rootPath = rootConfig[key]
const defaultPath = defaultConfig[key]
const isLocal = rootPath && rootPath !== defaultPath
if (pkgConfig[key]) {
return result(pkgConfig[key])
}

return {
isLocal,
root: !isLocal ? defaultPath : `node ${rootPath}`,
local: !isLocal ? defaultPath : `node ${wsToRoot(rootPath)}`,
if (rootConfig[key]) {
return result(rootConfig[key], !isRoot)
}

return result(key)
}

const mergeConfigs = (...configs) => {
Expand Down Expand Up @@ -139,9 +161,8 @@ const getFullConfig = async ({
] : [],
]

// root only configs
const npmPath = getCmdPath('npm', { rootConfig, defaultConfig, isRoot, pkg, rootPkg })
const npxPath = getCmdPath('npx', { rootConfig, defaultConfig, isRoot, pkg, rootPkg })
const npmPath = getCmdPath('npm', { pkgConfig, rootConfig, isRoot, pkg, rootPkg })
const npxPath = getCmdPath('npx', { pkgConfig, rootConfig, isRoot, pkg, rootPkg })

// these are written to ci yml files so it needs to always use posix
const pkgPath = makePosix(relative(rootPkg.path, pkg.path)) || '.'
Expand All @@ -157,9 +178,12 @@ const getFullConfig = async ({

const branches = uniq([...pkgConfig.branches ?? [], pkgConfig.releaseBranch]).filter(Boolean)
const gitBranches = await git.getBranches(rootPkg.path, branches)
const currentBranch = await git.currentBranch(rootPkg.path)
const isReleaseBranch = currentBranch ? minimatch(currentBranch, pkgConfig.releaseBranch) : false
const defaultBranch = await git.defaultBranch(rootPkg.path) ?? 'main'
const isReleaseBranch = !!pkgConfig.backport
const publishTag = isReleaseBranch ? `next-${pkgConfig.backport}` : 'latest'
const releaseBranch = isReleaseBranch
? pkgConfig.releaseBranch.replace(/\*/g, pkgConfig.backport)
: defaultBranch

// all derived keys
const derived = {
Expand All @@ -179,12 +203,11 @@ const getFullConfig = async ({
// controls whether we are in a monorepo with any public workspaces
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
// git
defaultBranch,
baseBranch: isReleaseBranch ? currentBranch : defaultBranch,
branches: gitBranches.branches,
branchPatterns: gitBranches.patterns,
isReleaseBranch,
// dependabot
releaseBranch,
publishTag,
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
// repo
repoDir: rootPkg.path,
Expand Down Expand Up @@ -218,6 +241,8 @@ const getFullConfig = async ({
// lockfiles are only present at the root, so this only should be set for
// all workspaces based on the root
lockfile: rootPkgConfig.lockfile,
// ci versions / engines
ciVersions: ciVersions.get(pkg.pkgJson.engines?.node, pkgConfig),
// gitignore
ignorePaths: [
...gitignore.sort([
Expand All @@ -242,33 +267,6 @@ const getFullConfig = async ({
__PARTIAL_DIRS__: fileDirs,
}

if (pkgConfig.ciVersions) {
let versions = pkgConfig.ciVersions
if (versions === 'latest' || (Array.isArray(versions) && versions.includes('latest'))) {
const { ciVersions } = [isWorkspace ? rootPkgConfig : {}, defaultConfig]
.find(c => Array.isArray(c.ciVersions))
const defaultLatest = ciVersions[ciVersions.length - 1]
versions = [].concat(versions).map(v => v === 'latest' ? defaultLatest : v)
}

const { targets, engines } = parseCIVersions(versions)

// get just a list of the target versions (not ranges)
// these are used for the node version when doing engines checks
// since we want to test in the lowest version of each major
let targetVersions = targets.filter(t => semver.valid(t))
// if the versions are all ranges then convert them to the lower bound of each range
if (!targetVersions.length) {
targetVersions = targets.filter(t => semver.validRange(t)).map(t => {
return new semver.Range(t).set[0][0].semver.version
})
}

derived.ciVersions = targets
derived.baseCiVersions = targetVersions
derived.engines = pkgConfig.engines || engines
}

if (!pkgConfig.eslint) {
derived.ignorePaths = derived.ignorePaths.filter(p => !p.includes('eslint'))
if (Array.isArray(pkgConfig.requiredPackages?.devDependencies)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/content/_job-release-integration.yml.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
- name: Publish
env:
PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }}
run: npm publish --provenance
run: npm publish --provenance --tag={{ publishTag }}
{{else}}
runs-on: ubuntu-latest
defaults:
Expand Down
2 changes: 1 addition & 1 deletion lib/content/ci-release.yml.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
ref:
required: true
type: string
default: {{ baseBranch }}
default: {{ releaseBranch }}
workflow_call:
inputs:
ref:
Expand Down
7 changes: 4 additions & 3 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ module.exports = {
windowsCI: true,
macCI: true,
branches: ['main', 'latest'],
// set this to the major version to backport
backport: null,
releaseBranch: 'release/v*',
distPaths: [
'bin/',
Expand All @@ -156,13 +158,12 @@ module.exports = {
'/CHANGELOG*',
],
ignorePaths: [],
ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'],
ciVersions: {},
latestCiVersion: 20,
lockfile: false,
codeowner: '@npm/cli-team',
eslint: true,
publish: false,
npm: 'npm',
npx: 'npx',
updateNpm: true,
dependabot: 'increase-if-necessary',
unwantedPackages: [
Expand Down
5 changes: 0 additions & 5 deletions lib/content/pkg.json.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
"postpublish": {{{ del }}}
},
"repository": {{#if repository}}{{{ json repository }}}{{else}}{{{ del }}}{{/if}},
"engines": {
{{#if engines}}
"node": {{{ json engines }}}
{{/if}}
},
{{{ json __CONFIG_KEY__ }}}: {
"version": {{#if isDogFood}}{{{ del }}}{{else}}{{{ json __VERSION__ }}}{{/if}}
},
Expand Down
Loading

0 comments on commit 7ccc76a

Please sign in to comment.