Skip to content

Commit

Permalink
feat: move functionality to private workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 13, 2023
1 parent 142d017 commit 7e1b67b
Show file tree
Hide file tree
Showing 41 changed files with 393 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const localConfigs = readdir(__dirname)
module.exports = {
root: true,
ignorePatterns: [
'workspaces/content/**',
'workspaces/**',
],
extends: [
'@npmcli',
Expand Down
36 changes: 36 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ updates:
prefix-development: chore
labels:
- "Dependencies"
- package-ecosystem: npm
directory: workspaces/config/
schedule:
interval: daily
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
- package-ecosystem: npm
directory: workspaces/content/
schedule:
Expand All @@ -27,3 +39,27 @@ updates:
prefix-development: chore
labels:
- "Dependencies"
- package-ecosystem: npm
directory: workspaces/files/
schedule:
interval: daily
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
- package-ecosystem: npm
directory: workspaces/release-please/
schedule:
interval: daily
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
!/test/
!/workspaces/
/workspaces/*
!/workspaces/config/
!/workspaces/content/
!/workspaces/files/
!/workspaces/release-please/
2 changes: 1 addition & 1 deletion bin/release-please.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const core = require('@actions/core')
const main = require('../lib/release-please/index.js')
const main = require('@npmcli/template-oss-release-please')

const dryRun = !process.env.CI
const [branch, forcePullRequest] = process.argv.slice(2)
Expand Down
2 changes: 1 addition & 1 deletion lib/apply/apply-files.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs/promises')
const log = require('proc-log')
const { rmEach, parseEach } = require('../util/files.js')
const { rmEach, parseEach } = require('@npmcli/template-oss-files')

const run = async (dir, files, options) => {
const { rm, add } = files
Expand Down
2 changes: 1 addition & 1 deletion lib/check/check-apply.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const log = require('proc-log')
const { relative, basename } = require('path')
const { rmEach, parseEach } = require('../util/files.js')
const { rmEach, parseEach } = require('@npmcli/template-oss-files')
const { partition } = require('lodash')
const localeCompare = require('@isaacs/string-locale-compare')('en')

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const log = require('proc-log')
const { resolve } = require('path')
const getConfig = require('./config.js')
const getConfig = require('@npmcli/template-oss-config')
const PackageJson = require('@npmcli/package-json')
const mapWorkspaces = require('@npmcli/map-workspaces')

Expand Down
27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,15 @@
"@npmcli/git": "^4.0.0",
"@npmcli/map-workspaces": "^3.0.0",
"@npmcli/package-json": "^3.0.0",
"@npmcli/template-oss-config": "^1.0.0",
"@npmcli/template-oss-content": "^1.0.0",
"@npmcli/template-oss-files": "^1.0.0",
"@npmcli/template-oss-release-please": "^1.0.0",
"@octokit/rest": "^19.0.4",
"diff": "^5.0.0",
"glob": "^8.0.1",
"handlebars": "^4.7.7",
"hosted-git-info": "^6.0.0",
"ini": "^3.0.1",
"json-parse-even-better-errors": "^3.0.0",
"just-deep-map-values": "^1.1.1",
"just-diff": "^5.0.1",
"lodash": "^4.17.21",
"npm-package-arg": "^10.0.0",
"proc-log": "^3.0.0",
"release-please": "npm:@npmcli/release-please@^14.2.6",
"semver": "^7.3.5",
"yaml": "^2.1.1"
"semver": "^7.3.5"
},
"files": [
"bin/",
Expand All @@ -65,25 +58,27 @@
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "file:./",
"tap": "^16.0.0"
"tap": "^16.0.0",
"yaml": "^2.2.1"
},
"tap": {
"timeout": 600,
"nyc-arg": [
"--exclude",
"workspaces/content/**",
"workspaces/**",
"--exclude",
"tap-snapshots/**"
],
"test-ignore": "^(workspaces/content)/"
"test-ignore": "^(workspaces)/"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"//@npmcli/template-oss-config": "This file is partially managed by @npmcli/template-oss-config. Edits may be overwritten."
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"workspaces": [
"workspaces/content"
"workspaces/*"
]
}
17 changes: 17 additions & 0 deletions workspaces/config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This file is automatically added by @npmcli/template-oss. Do not edit. */

'use strict'

const { readdirSync: readdir } = require('fs')

const localConfigs = readdir(__dirname)
.filter((file) => file.startsWith('.eslintrc.local.'))
.map((file) => `./${file}`)

module.exports = {
root: true,
extends: [
'@npmcli',
...localConfigs,
],
}
21 changes: 21 additions & 0 deletions workspaces/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is automatically added by @npmcli/template-oss. Do not edit.

# ignore everything in the root
/*

# keep these
!**/.gitignore
!/.eslintrc.js
!/.eslintrc.local.*
!/.gitignore
!/bin/
!/CHANGELOG*
!/docs/
!/lib/
!/LICENSE*
!/map.js
!/package.json
!/README*
!/scripts/
!/tap-snapshots/
!/test/
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions lib/config.js → workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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 getGitUrl = require('./util/get-git-url.js')
const gitignore = require('./util/gitignore.js')
const { withArrays } = require('./util/merge.js')
const { FILE_KEYS, parseConfig: parseFiles, getAddedFiles } = require('./util/files.js')
const parseCIVersions = require('./parse-ci-versions.js')
const getGitUrl = require('./get-git-url.js')
const gitignore = require('./gitignore.js')
const withArrays = require('./merge-with-arrays.js')
const { FILE_KEYS, parseConfig: parseFiles, getAddedFiles } = require('@npmcli/template-oss-files')

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const { mergeWith } = require('lodash')

const merge = (...objects) => mergeWith({}, ...objects, (value, srcValue, key) => {
if (Array.isArray(srcValue)) {
// Dont merge arrays, last array wins
return srcValue
}
})

const mergeWithArrays = (...keys) =>
(...objects) => mergeWith({}, ...objects, (value, srcValue, key) => {
if (Array.isArray(srcValue)) {
Expand All @@ -17,5 +10,4 @@ const mergeWithArrays = (...keys) =>
}
})

module.exports = merge
module.exports.withArrays = mergeWithArrays
module.exports = mergeWithArrays
File renamed without changes.
59 changes: 59 additions & 0 deletions workspaces/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@npmcli/template-oss-config",
"version": "1.0.0",
"description": "The config for @npmcli/template-oss",
"private": true,
"main": "lib/index.js",
"scripts": {
"test": "tap",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"snap": "tap",
"posttest": "npm run lint"
},
"repository": {
"type": "git",
"url": "https://github.com/npm/template-oss.git",
"directory": "workspaces/config"
},
"dependencies": {
"@isaacs/string-locale-compare": "^1.1.0",
"@npmcli/git": "^4.0.3",
"@npmcli/template-oss-files": "^1.0.0",
"hosted-git-info": "^6.1.1",
"lodash": "^4.17.21",
"semver": "^7.3.8"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "file:../../",
"tap": "^16.0.0"
},
"keywords": [],
"author": "GitHub Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/template-oss/issues"
},
"homepage": "https://github.com/npm/template-oss#readme",
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"//@npmcli/template-oss-config": "This file is partially managed by @npmcli/template-oss-config. Edits may be overwritten."
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
],
"check-coverage": false
}
}
8 changes: 8 additions & 0 deletions workspaces/config/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { resolve } = require('path')
const t = require('tap')

t.test('resolved to content index', async (t) => {
const path = require.resolve('..')
t.equal(path, resolve('lib/index.js'))
t.ok(require(path))
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const parse = require('../../lib/util/parse-ci-versions.js')
const parse = require('../lib/parse-ci-versions.js')

const targets = [
[[], ''],
Expand Down
6 changes: 4 additions & 2 deletions workspaces/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"//@npmcli/template-oss-config": "This file is partially managed by @npmcli/template-oss-config. Edits may be overwritten."
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
],
"check-coverage": false
}
}
4 changes: 2 additions & 2 deletions workspaces/content/test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { resolve } = require('path')
const t = require('tap')

t.test('resolved to content index', () => {
t.test('resolved to content index', async (t) => {
const path = require.resolve('..')
t.equal(path, resolve('lib/index.js'))
t.ok(require(path))
})
})
17 changes: 17 additions & 0 deletions workspaces/files/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This file is automatically added by @npmcli/template-oss. Do not edit. */

'use strict'

const { readdirSync: readdir } = require('fs')

const localConfigs = readdir(__dirname)
.filter((file) => file.startsWith('.eslintrc.local.'))
.map((file) => `./${file}`)

module.exports = {
root: true,
extends: [
'@npmcli',
...localConfigs,
],
}
21 changes: 21 additions & 0 deletions workspaces/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is automatically added by @npmcli/template-oss. Do not edit.

# ignore everything in the root
/*

# keep these
!**/.gitignore
!/.eslintrc.js
!/.eslintrc.local.*
!/.gitignore
!/bin/
!/CHANGELOG*
!/docs/
!/lib/
!/LICENSE*
!/map.js
!/package.json
!/README*
!/scripts/
!/tap-snapshots/
!/test/
4 changes: 2 additions & 2 deletions lib/util/files.js → workspaces/files/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { join } = require('path')
const { defaultsDeep } = require('lodash')
const { promisify } = require('util')
const merge = require('./merge.js')
const { defaultsDeep } = require('lodash')
const deepMapValues = require('just-deep-map-values')
const glob = promisify(require('glob'))
const merge = require('./merge.js')
const Parser = require('./parser.js')
const template = require('./template.js')

Expand Down
File renamed without changes.
Loading

0 comments on commit 7e1b67b

Please sign in to comment.