@npmcli/template-oss 4.18.1 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -11
- package/bin/release-manager.js +6 -0
- package/lib/config.js +112 -136
- package/lib/content/{_job-matrix.yml → _job-matrix-yml.hbs} +1 -1
- package/lib/content/{_job-release-integration.yml → _job-release-integration-yml.hbs} +2 -2
- package/lib/content/{_job.yml → _job-yml.hbs} +1 -1
- package/lib/content/_step-node-yml.hbs +60 -0
- package/lib/content/_steps-setup-yml.hbs +6 -0
- package/lib/content/{audit.yml → audit-yml.hbs} +2 -2
- package/lib/content/{ci-release.yml → ci-release-yml.hbs} +7 -7
- package/lib/content/ci-yml.hbs +13 -0
- package/lib/content/{codeql-analysis.yml → codeql-analysis-yml.hbs} +1 -1
- package/lib/content/{eslintrc.js → eslintrc-js.hbs} +11 -1
- package/lib/content/{gitignore → gitignore.hbs} +2 -0
- package/lib/content/index.js +47 -42
- package/lib/content/{pkg.json → package-json.hbs} +8 -9
- package/lib/content/{post-dependabot.yml → post-dependabot-yml.hbs} +1 -1
- package/lib/content/{pull-request.yml → pull-request-yml.hbs} +1 -1
- package/lib/content/{release.yml → release-yml.hbs} +10 -10
- package/lib/content/tsconfig-json.hbs +17 -0
- package/lib/util/ci-versions.js +80 -0
- package/lib/util/files.js +29 -20
- package/lib/util/get-cmd-path.js +36 -0
- package/lib/util/git.js +6 -11
- package/lib/util/import-or-require.js +29 -0
- package/lib/util/merge.js +0 -1
- package/lib/util/parser.js +6 -1
- package/lib/util/path.js +13 -0
- package/lib/util/template.js +9 -6
- package/package.json +10 -10
- package/lib/content/_step-node.yml +0 -57
- package/lib/content/_steps-setup.yml +0 -6
- package/lib/content/ci.yml +0 -13
- package/lib/util/parse-ci-versions.js +0 -78
- /package/lib/content/{CODEOWNERS → CODEOWNERS.hbs} +0 -0
- /package/lib/content/{CODE_OF_CONDUCT.md → CODE_OF_CONDUCT-md.hbs} +0 -0
- /package/lib/content/{CONTRIBUTING.md → CONTRIBUTING-md.hbs} +0 -0
- /package/lib/content/{LICENSE.md → LICENSE-md.hbs} +0 -0
- /package/lib/content/{SECURITY.md → SECURITY-md.hbs} +0 -0
- /package/lib/content/{_on-ci.yml → _on-ci-yml.hbs} +0 -0
- /package/lib/content/{_step-audit.yml → _step-audit-yml.hbs} +0 -0
- /package/lib/content/{_step-checks.yml → _step-checks-yml.hbs} +0 -0
- /package/lib/content/{_step-deps.yml → _step-deps-yml.hbs} +0 -0
- /package/lib/content/{_step-git.yml → _step-git-yml.hbs} +0 -0
- /package/lib/content/{_step-lint.yml → _step-lint-yml.hbs} +0 -0
- /package/lib/content/{_step-test.yml → _step-test-yml.hbs} +0 -0
- /package/lib/content/{bug.yml → bug-yml.hbs} +0 -0
- /package/lib/content/{commitlintrc.js → commitlintrc-js.hbs} +0 -0
- /package/lib/content/{config.yml → config-yml.hbs} +0 -0
- /package/lib/content/{dependabot.yml → dependabot-yml.hbs} +0 -0
- /package/lib/content/{npmrc → npmrc.hbs} +0 -0
- /package/lib/content/{release-please-config.json → release-please-config-json.hbs} +0 -0
- /package/lib/content/{release-please-manifest.json → release-please-manifest-json.hbs} +0 -0
- /package/lib/content/{settings.yml → settings-yml.hbs} +0 -0
- /package/lib/content/{tap.json → tap-json.hbs} +0 -0
package/lib/content/index.js
CHANGED
|
@@ -5,46 +5,47 @@ const isPublic = (p) => p.config.isPublic
|
|
|
5
5
|
const sharedRootAdd = (name) => ({
|
|
6
6
|
// release
|
|
7
7
|
'.github/workflows/release.yml': {
|
|
8
|
-
file: 'release.
|
|
8
|
+
file: 'release-yml.hbs',
|
|
9
9
|
filter: isPublic,
|
|
10
10
|
},
|
|
11
11
|
'.github/workflows/ci-release.yml': {
|
|
12
|
-
file: 'ci-release.
|
|
12
|
+
file: 'ci-release-yml.hbs',
|
|
13
13
|
filter: isPublic,
|
|
14
14
|
},
|
|
15
15
|
'.release-please-manifest.json': {
|
|
16
|
-
file: 'release-please-manifest.
|
|
16
|
+
file: 'release-please-manifest-json.hbs',
|
|
17
17
|
filter: isPublic,
|
|
18
|
-
parser: (p) =>
|
|
19
|
-
comment = null
|
|
20
|
-
},
|
|
18
|
+
parser: (p) => p.JsonMergeNoComment,
|
|
21
19
|
},
|
|
22
20
|
'release-please-config.json': {
|
|
23
|
-
file: 'release-please-config.
|
|
21
|
+
file: 'release-please-config-json.hbs',
|
|
24
22
|
filter: isPublic,
|
|
25
|
-
parser: (p) =>
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
parser: (p) => p.JsonMergeNoComment,
|
|
24
|
+
},
|
|
25
|
+
'tsconfig.json': {
|
|
26
|
+
file: 'tsconfig-json.hbs',
|
|
27
|
+
filter: (p) => p.config.typescript,
|
|
28
|
+
parser: (p) => p.JsonMergeNoComment,
|
|
28
29
|
},
|
|
29
30
|
// this lint commits which is only necessary for releases
|
|
30
31
|
'.github/workflows/pull-request.yml': {
|
|
31
|
-
file: 'pull-request.
|
|
32
|
+
file: 'pull-request-yml.hbs',
|
|
32
33
|
filter: isPublic,
|
|
33
34
|
},
|
|
34
35
|
// ci
|
|
35
|
-
'.github/matchers/tap.json': 'tap.
|
|
36
|
-
[`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci.
|
|
36
|
+
'.github/matchers/tap.json': 'tap-json.hbs',
|
|
37
|
+
[`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci-yml.hbs',
|
|
37
38
|
// dependabot
|
|
38
39
|
'.github/dependabot.yml': {
|
|
39
|
-
file: 'dependabot.
|
|
40
|
+
file: 'dependabot-yml.hbs',
|
|
40
41
|
filter: (p) => p.config.dependabot,
|
|
41
42
|
},
|
|
42
43
|
'.github/workflows/post-dependabot.yml': {
|
|
43
|
-
file: 'post-dependabot.
|
|
44
|
+
file: 'post-dependabot-yml.hbs',
|
|
44
45
|
filter: (p) => p.config.dependabot,
|
|
45
46
|
},
|
|
46
47
|
'.github/settings.yml': {
|
|
47
|
-
file: 'settings.
|
|
48
|
+
file: 'settings-yml.hbs',
|
|
48
49
|
filter: (p) => !p.config.isReleaseBranch,
|
|
49
50
|
},
|
|
50
51
|
})
|
|
@@ -61,15 +62,16 @@ const sharedRootRm = () => ({
|
|
|
61
62
|
// Changes applied to the root of the repo
|
|
62
63
|
const rootRepo = {
|
|
63
64
|
add: {
|
|
64
|
-
'.commitlintrc.
|
|
65
|
-
'.github/ISSUE_TEMPLATE/bug.yml': 'bug.
|
|
66
|
-
'.github/ISSUE_TEMPLATE/config.yml': 'config.
|
|
67
|
-
'.github/CODEOWNERS': 'CODEOWNERS',
|
|
68
|
-
'.github/workflows/audit.yml': 'audit.
|
|
69
|
-
'.github/workflows/codeql-analysis.yml': 'codeql-analysis.
|
|
65
|
+
'.commitlintrc.{{ cjsExt }}': 'commitlintrc-js.hbs',
|
|
66
|
+
'.github/ISSUE_TEMPLATE/bug.yml': 'bug-yml.hbs',
|
|
67
|
+
'.github/ISSUE_TEMPLATE/config.yml': 'config-yml.hbs',
|
|
68
|
+
'.github/CODEOWNERS': 'CODEOWNERS.hbs',
|
|
69
|
+
'.github/workflows/audit.yml': 'audit-yml.hbs',
|
|
70
|
+
'.github/workflows/codeql-analysis.yml': 'codeql-analysis-yml.hbs',
|
|
70
71
|
...sharedRootAdd(),
|
|
71
72
|
},
|
|
72
73
|
rm: {
|
|
74
|
+
'.commitlintrc.{{ deleteJsExt }}': true,
|
|
73
75
|
'.github/workflows/release-test.yml': true,
|
|
74
76
|
'.github/workflows/release-please.yml': true,
|
|
75
77
|
...sharedRootRm(),
|
|
@@ -83,19 +85,19 @@ const rootRepo = {
|
|
|
83
85
|
// dir. so we might want to combine these
|
|
84
86
|
const rootModule = {
|
|
85
87
|
add: {
|
|
86
|
-
'.eslintrc.
|
|
87
|
-
file: 'eslintrc.
|
|
88
|
+
'.eslintrc.{{ cjsExt }}': {
|
|
89
|
+
file: 'eslintrc-js.hbs',
|
|
88
90
|
filter: (p) => p.config.eslint,
|
|
89
91
|
},
|
|
90
|
-
'.gitignore': 'gitignore',
|
|
91
|
-
'.npmrc': 'npmrc',
|
|
92
|
-
'SECURITY.md': 'SECURITY.
|
|
93
|
-
'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT.
|
|
94
|
-
'CONTRIBUTING.md': 'CONTRIBUTING.
|
|
95
|
-
'package.json': '
|
|
92
|
+
'.gitignore': 'gitignore.hbs',
|
|
93
|
+
'.npmrc': 'npmrc.hbs',
|
|
94
|
+
'SECURITY.md': 'SECURITY-md.hbs',
|
|
95
|
+
'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT-md.hbs',
|
|
96
|
+
'CONTRIBUTING.md': 'CONTRIBUTING-md.hbs',
|
|
97
|
+
'package.json': 'package-json.hbs',
|
|
96
98
|
},
|
|
97
99
|
rm: [
|
|
98
|
-
'.eslintrc.!(
|
|
100
|
+
'.eslintrc.!({{ cjsExt }}|local.*)',
|
|
99
101
|
],
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -114,16 +116,16 @@ const workspaceRepo = {
|
|
|
114
116
|
// Changes for each workspace but applied to the relative workspace dir
|
|
115
117
|
const workspaceModule = {
|
|
116
118
|
add: {
|
|
117
|
-
'.eslintrc.
|
|
118
|
-
file: 'eslintrc.
|
|
119
|
+
'.eslintrc.{{ cjsExt }}': {
|
|
120
|
+
file: 'eslintrc-js.hbs',
|
|
119
121
|
filter: (p) => p.config.eslint,
|
|
120
122
|
},
|
|
121
|
-
'.gitignore': 'gitignore',
|
|
122
|
-
'package.json': '
|
|
123
|
+
'.gitignore': 'gitignore.hbs',
|
|
124
|
+
'package.json': 'package-json.hbs',
|
|
123
125
|
},
|
|
124
126
|
rm: [
|
|
125
127
|
'.npmrc',
|
|
126
|
-
'.eslintrc.!(
|
|
128
|
+
'.eslintrc.!({{ cjsExt }}|local.*)',
|
|
127
129
|
'SECURITY.md',
|
|
128
130
|
],
|
|
129
131
|
}
|
|
@@ -136,14 +138,14 @@ module.exports = {
|
|
|
136
138
|
windowsCI: true,
|
|
137
139
|
macCI: true,
|
|
138
140
|
branches: ['main', 'latest'],
|
|
141
|
+
// set this to the major version to backport
|
|
142
|
+
backport: null,
|
|
139
143
|
releaseBranch: 'release/v*',
|
|
140
144
|
distPaths: [
|
|
141
145
|
'bin/',
|
|
142
146
|
'lib/',
|
|
143
147
|
],
|
|
144
148
|
allowPaths: [
|
|
145
|
-
'/bin/',
|
|
146
|
-
'/lib/',
|
|
147
149
|
'/.eslintrc.local.*',
|
|
148
150
|
'**/.gitignore',
|
|
149
151
|
'/docs/',
|
|
@@ -155,14 +157,17 @@ module.exports = {
|
|
|
155
157
|
'/LICENSE*',
|
|
156
158
|
'/CHANGELOG*',
|
|
157
159
|
],
|
|
158
|
-
ignorePaths: [
|
|
159
|
-
|
|
160
|
+
ignorePaths: [
|
|
161
|
+
/* to be provided by consuming package */
|
|
162
|
+
],
|
|
163
|
+
ciVersions: {},
|
|
164
|
+
latestCiVersion: 20,
|
|
160
165
|
lockfile: false,
|
|
161
166
|
codeowner: '@npm/cli-team',
|
|
162
167
|
eslint: true,
|
|
163
168
|
publish: false,
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
typescript: false,
|
|
170
|
+
esm: false,
|
|
166
171
|
updateNpm: true,
|
|
167
172
|
dependabot: 'increase-if-necessary',
|
|
168
173
|
unwantedPackages: [
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "GitHub Inc.",
|
|
3
|
-
"files": {{{ json distPaths }}},
|
|
3
|
+
"files": {{#if typescript}}{{{ del }}}{{else}}{{{ json distPaths }}}{{/if}},
|
|
4
|
+
"type": {{#if esm}}"module"{{else}}{{{ del }}}{{/if}},
|
|
4
5
|
"scripts": {
|
|
5
|
-
"lint": "{{#if eslint}}eslint \"**/*.js\"{{else}}echo linting disabled{{/if}}",
|
|
6
|
+
"lint": "{{#if eslint}}eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"{{else}}echo linting disabled{{/if}}",
|
|
6
7
|
"postlint": "template-oss-check",
|
|
7
8
|
"template-oss-apply": "template-oss-apply --force",
|
|
8
9
|
"lintfix": "{{ localNpmPath }} run lint -- --fix",
|
|
@@ -13,6 +14,9 @@
|
|
|
13
14
|
"test-all": "{{ localNpmPath }} run test {{ allFlags }}",
|
|
14
15
|
"lint-all": "{{ localNpmPath }} run lint {{ allFlags }}",
|
|
15
16
|
{{/if}}
|
|
17
|
+
{{#if typescript}}
|
|
18
|
+
"prepare": "tshy",
|
|
19
|
+
{{/if}}
|
|
16
20
|
"template-copy": {{{ del }}},
|
|
17
21
|
"lint:fix": {{{ del }}},
|
|
18
22
|
"preversion": {{{ del }}},
|
|
@@ -21,11 +25,6 @@
|
|
|
21
25
|
"postpublish": {{{ del }}}
|
|
22
26
|
},
|
|
23
27
|
"repository": {{#if repository}}{{{ json repository }}}{{else}}{{{ del }}}{{/if}},
|
|
24
|
-
"engines": {
|
|
25
|
-
{{#if engines}}
|
|
26
|
-
"node": {{{ json engines }}}
|
|
27
|
-
{{/if}}
|
|
28
|
-
},
|
|
29
28
|
{{{ json __CONFIG_KEY__ }}}: {
|
|
30
29
|
"version": {{#if isDogFood}}{{{ del }}}{{else}}{{{ json __VERSION__ }}}{{/if}}
|
|
31
30
|
},
|
|
@@ -35,13 +34,13 @@
|
|
|
35
34
|
{{#if workspacePaths}}
|
|
36
35
|
"test-ignore": "^({{ join workspacePaths "|" }})/",
|
|
37
36
|
{{/if}}
|
|
38
|
-
"nyc-arg": [
|
|
37
|
+
"nyc-arg": {{#if tap18}}{{{ del }}}{{else}}[
|
|
39
38
|
{{#each workspaceGlobs}}
|
|
40
39
|
"--exclude",
|
|
41
40
|
"{{ . }}",
|
|
42
41
|
{{/each}}
|
|
43
42
|
"--exclude",
|
|
44
43
|
"tap-snapshots/**"
|
|
45
|
-
]
|
|
44
|
+
]{{/if}}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -27,7 +27,7 @@ jobs:
|
|
|
27
27
|
pr-number: $\{{ steps.release.outputs.pr-number }}
|
|
28
28
|
comment-id: $\{{ steps.pr-comment.outputs.result }}
|
|
29
29
|
check-id: $\{{ steps.check.outputs.check_id }}
|
|
30
|
-
{{>
|
|
30
|
+
{{> jobYml jobName="Release" }}
|
|
31
31
|
- name: Release Please
|
|
32
32
|
id: release
|
|
33
33
|
env:
|
|
@@ -66,14 +66,14 @@ jobs:
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
return commentId
|
|
69
|
-
{{>
|
|
69
|
+
{{> stepChecksYml jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }}
|
|
70
70
|
|
|
71
71
|
update:
|
|
72
72
|
needs: release
|
|
73
73
|
outputs:
|
|
74
74
|
sha: $\{{ steps.commit.outputs.sha }}
|
|
75
75
|
check-id: $\{{ steps.check.outputs.check_id }}
|
|
76
|
-
{{>
|
|
76
|
+
{{> jobYml
|
|
77
77
|
jobName="Update - Release"
|
|
78
78
|
jobIf="needs.release.outputs.pr"
|
|
79
79
|
jobCheckout=(obj ref="${{ needs.release.outputs.branch }}" fetch-depth=0)
|
|
@@ -94,8 +94,8 @@ jobs:
|
|
|
94
94
|
git commit --all --amend --no-edit || true
|
|
95
95
|
git push --force-with-lease
|
|
96
96
|
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
|
|
97
|
-
{{>
|
|
98
|
-
{{>
|
|
97
|
+
{{> stepChecksYml jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}}
|
|
98
|
+
{{> stepChecksYml jobCheck=(obj id="needs.release.outputs.check-id" )}}
|
|
99
99
|
|
|
100
100
|
ci:
|
|
101
101
|
name: CI - Release
|
|
@@ -108,7 +108,7 @@ jobs:
|
|
|
108
108
|
|
|
109
109
|
post-ci:
|
|
110
110
|
needs: [release, update, ci]
|
|
111
|
-
{{>
|
|
111
|
+
{{> jobYml jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }}
|
|
112
112
|
- name: Get Needs Result
|
|
113
113
|
id: needs-result
|
|
114
114
|
run: |
|
|
@@ -121,11 +121,11 @@ jobs:
|
|
|
121
121
|
result="success"
|
|
122
122
|
fi
|
|
123
123
|
echo "result=$result" >> $GITHUB_OUTPUT
|
|
124
|
-
{{>
|
|
124
|
+
{{> stepChecksYml jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }}
|
|
125
125
|
|
|
126
126
|
post-release:
|
|
127
127
|
needs: release
|
|
128
|
-
{{>
|
|
128
|
+
{{> jobYml jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }}
|
|
129
129
|
- name: Create Release PR Comment
|
|
130
130
|
uses: actions/github-script@v6
|
|
131
131
|
env:
|
|
@@ -163,11 +163,11 @@ jobs:
|
|
|
163
163
|
needs: release
|
|
164
164
|
name: Release Integration
|
|
165
165
|
if: needs.release.outputs.release
|
|
166
|
-
{{>
|
|
166
|
+
{{> jobReleaseIntegrationYml }}
|
|
167
167
|
|
|
168
168
|
post-release-integration:
|
|
169
169
|
needs: [release, release-integration]
|
|
170
|
-
{{>
|
|
170
|
+
{{> jobYml jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }}
|
|
171
171
|
- name: Get Needs Result
|
|
172
172
|
id: needs-result
|
|
173
173
|
run: |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"inlineSources": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"moduleResolution": "nodenext",
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"target": "es2022",
|
|
15
|
+
"module": "nodenext"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { uniq, range, isPlainObject } = require('lodash')
|
|
2
|
+
const semver = require('semver')
|
|
3
|
+
|
|
4
|
+
const parseCiVersions = (ciVersions) => {
|
|
5
|
+
if (Array.isArray(ciVersions)) {
|
|
6
|
+
return Object.fromEntries(ciVersions.map((v) => [v, true]))
|
|
7
|
+
}
|
|
8
|
+
if (isPlainObject(ciVersions)) {
|
|
9
|
+
return ciVersions
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getLowerBounds = (sRange) => {
|
|
14
|
+
return new semver.Range(sRange).set.map(c => c[0])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getCiVersions = (nodeEngines, pkgConfig) => {
|
|
18
|
+
let allCiVersions = {}
|
|
19
|
+
|
|
20
|
+
// get ci versions
|
|
21
|
+
const { latestCiVersion, ciVersions } = pkgConfig
|
|
22
|
+
|
|
23
|
+
if (latestCiVersion) {
|
|
24
|
+
allCiVersions[`${latestCiVersion}.x`] = true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// determine the ci versions from the node engines set
|
|
28
|
+
if (nodeEngines) {
|
|
29
|
+
const lowerBounds = getLowerBounds(nodeEngines)
|
|
30
|
+
.map(v => v.semver)
|
|
31
|
+
.filter(v => v.version)
|
|
32
|
+
|
|
33
|
+
for (const version of lowerBounds) {
|
|
34
|
+
allCiVersions[version.version] = true
|
|
35
|
+
allCiVersions[`${version.major}.x`] = true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const lowestCiVersion = semver.sort(lowerBounds)[0]?.major
|
|
39
|
+
if (lowestCiVersion && latestCiVersion) {
|
|
40
|
+
for (const major of range(lowestCiVersion, latestCiVersion, 2)) {
|
|
41
|
+
allCiVersions[`${major}.x`] = true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ciVersions === 'latest' && latestCiVersion) {
|
|
47
|
+
// the plain string 'latest' means latest only and everything else is removed
|
|
48
|
+
allCiVersions = { [`${latestCiVersion}.x`]: true }
|
|
49
|
+
} else {
|
|
50
|
+
// this allows ciVersions to turn off default versions by setting them to a falsy value
|
|
51
|
+
Object.assign(allCiVersions, parseCiVersions(ciVersions))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (allCiVersions.latest && latestCiVersion) {
|
|
55
|
+
delete allCiVersions.latest
|
|
56
|
+
allCiVersions[`${latestCiVersion}.x`] = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const filteredCiVersions = Object.entries(allCiVersions)
|
|
60
|
+
.filter(([, v]) => v)
|
|
61
|
+
.map(([k]) => k)
|
|
62
|
+
|
|
63
|
+
return uniq(filteredCiVersions).sort((a, b) => {
|
|
64
|
+
const aComp = getLowerBounds(a)[0]
|
|
65
|
+
const bComp = getLowerBounds(b)[0]
|
|
66
|
+
|
|
67
|
+
if (aComp.semver.major > bComp.semver.major) {
|
|
68
|
+
return 1
|
|
69
|
+
} else if (aComp.semver.major < bComp.semver.major) {
|
|
70
|
+
return -1
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return aComp.operator ? 1 : -1
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
parse: parseCiVersions,
|
|
79
|
+
get: getCiVersions,
|
|
80
|
+
}
|
package/lib/util/files.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { join } = require('path')
|
|
2
|
-
const { defaultsDeep, omit } = require('lodash')
|
|
2
|
+
const { defaultsDeep, omit, isPlainObject } = require('lodash')
|
|
3
3
|
const deepMapValues = require('just-deep-map-values')
|
|
4
4
|
const { glob } = require('glob')
|
|
5
5
|
const { mergeWithCustomizers, customizers } = require('./merge.js')
|
|
@@ -12,6 +12,11 @@ const FILE_KEYS = ['rootRepo', 'rootModule', 'workspaceRepo', 'workspaceModule']
|
|
|
12
12
|
|
|
13
13
|
const globify = pattern => pattern.split('\\').join('/')
|
|
14
14
|
|
|
15
|
+
const deepMapKeys = (obj, fn) => Object.entries(obj).reduce((acc, [key, value]) => {
|
|
16
|
+
acc[fn(key)] = isPlainObject(value) ? deepMapKeys(value, fn) : value
|
|
17
|
+
return acc
|
|
18
|
+
}, {})
|
|
19
|
+
|
|
15
20
|
const mergeFiles = mergeWithCustomizers((value, srcValue, key, target, source, stack) => {
|
|
16
21
|
// This will merge all files except if the src file has overwrite:false. Then
|
|
17
22
|
// the files will be turned into an array so they can be applied on top of
|
|
@@ -35,7 +40,7 @@ const fileEntries = (dir, files, options, { allowMultipleSources = true } = {})
|
|
|
35
40
|
continue
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
// target paths need to be
|
|
43
|
+
// target paths need to be joined with dir and templated
|
|
39
44
|
const target = join(dir, template(key, options))
|
|
40
45
|
|
|
41
46
|
if (Array.isArray(source)) {
|
|
@@ -66,7 +71,7 @@ const getParsers = (dir, files, options, parseOptions) => {
|
|
|
66
71
|
const clean = typeof shouldClean === 'function' ? shouldClean(options) : false
|
|
67
72
|
|
|
68
73
|
if (parser) {
|
|
69
|
-
|
|
74
|
+
// allow files to extend base parsers or create new ones
|
|
70
75
|
return new (parser(Parser.Parsers))(target, file, options, { clean })
|
|
71
76
|
}
|
|
72
77
|
|
|
@@ -105,23 +110,27 @@ const parseEach = async (dir, files, options, parseOptions, fn) => {
|
|
|
105
110
|
return res.filter(Boolean)
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
const parseConfig = (files, dir, overrides) => {
|
|
109
|
-
const normalizeFiles = (v) =>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return acc
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
const parseConfig = (files, dir, overrides, templateSettings) => {
|
|
114
|
+
const normalizeFiles = (v) => {
|
|
115
|
+
v = deepMapKeys(v, (s) => template(s, templateSettings))
|
|
116
|
+
return deepMapValues(v, (value, key) => {
|
|
117
|
+
if (key === RM_KEY && Array.isArray(value)) {
|
|
118
|
+
return value.reduce((acc, k) => {
|
|
119
|
+
// template files nows since they need to be normalized before merging
|
|
120
|
+
acc[template(k, templateSettings)] = true
|
|
121
|
+
return acc
|
|
122
|
+
}, {})
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === 'string') {
|
|
125
|
+
const file = join(dir, value)
|
|
126
|
+
return key === 'file' ? file : { file }
|
|
127
|
+
}
|
|
128
|
+
if (value === true && FILE_KEYS.includes(key)) {
|
|
129
|
+
return {}
|
|
130
|
+
}
|
|
131
|
+
return value
|
|
132
|
+
})
|
|
133
|
+
}
|
|
125
134
|
|
|
126
135
|
const merged = mergeFiles(normalizeFiles(files), normalizeFiles(overrides))
|
|
127
136
|
const withDefaults = defaultsDeep(merged, FILE_KEYS.reduce((acc, k) => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { join, relative } = require('path')
|
|
2
|
+
const { makePosix } = require('./path.js')
|
|
3
|
+
|
|
4
|
+
const getCmdPath = (key, { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) => {
|
|
5
|
+
const result = (local, isRelative) => {
|
|
6
|
+
let root = local
|
|
7
|
+
const isLocal = local.startsWith('.') || local.startsWith('/')
|
|
8
|
+
|
|
9
|
+
if (isLocal) {
|
|
10
|
+
if (isRelative) {
|
|
11
|
+
// Make a path relative from a workspace to the root if we are in a workspace
|
|
12
|
+
local = makePosix(join(relative(pkg.path, rootPkg.path), local))
|
|
13
|
+
}
|
|
14
|
+
local = `node ${local}`
|
|
15
|
+
root = `node ${root}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
isLocal,
|
|
20
|
+
local,
|
|
21
|
+
root,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (pkgConfig[key]) {
|
|
26
|
+
return result(pkgConfig[key])
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (rootConfig[key]) {
|
|
30
|
+
return result(rootConfig[key], !isRoot)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result(key)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = getCmdPath
|
package/lib/util/git.js
CHANGED
|
@@ -19,9 +19,9 @@ const tryGit = async (path, ...args) => {
|
|
|
19
19
|
|
|
20
20
|
// parse a repo from a git origin into a format
|
|
21
21
|
// for a package.json#repository object
|
|
22
|
-
const
|
|
22
|
+
const getRemoteUrl = async (path, remote) => {
|
|
23
23
|
try {
|
|
24
|
-
const urlStr = await tryGit(path, 'remote', 'get-url',
|
|
24
|
+
const urlStr = await tryGit(path, 'remote', 'get-url', remote)
|
|
25
25
|
const { domain, user, project } = hgi.fromUrl(urlStr)
|
|
26
26
|
const url = new URL(`https://${domain}`)
|
|
27
27
|
url.pathname = `/${user}/${project}.git`
|
|
@@ -31,6 +31,10 @@ const getUrl = async (path) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
const getUrl = async (path) => {
|
|
35
|
+
return (await getRemoteUrl(path, 'upstream')) ?? (await getRemoteUrl(path, 'origin'))
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
const getBranches = async (path, branchPatterns) => {
|
|
35
39
|
let matchingBranches = new Set()
|
|
36
40
|
let matchingPatterns = new Set()
|
|
@@ -66,17 +70,8 @@ const defaultBranch = async (path) => {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
const currentBranch = async (path) => {
|
|
70
|
-
try {
|
|
71
|
-
return await tryGit(path, 'rev-parse', '--abbrev-ref', 'HEAD')
|
|
72
|
-
} catch {
|
|
73
|
-
// ignore errors
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
73
|
module.exports = {
|
|
78
74
|
getUrl,
|
|
79
75
|
getBranches,
|
|
80
76
|
defaultBranch,
|
|
81
|
-
currentBranch,
|
|
82
77
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// This fixes weird behavior I was seeing where calls to require(path) would
|
|
2
|
+
// fail the first time and then fetch via dynamic import which is correct, but
|
|
3
|
+
// then subsequent requires for the same path would return an empty object. Not
|
|
4
|
+
// sure if a bug or I'm doing something wrong but since the require/imports here
|
|
5
|
+
// are short lived, it is safe to create our own cache and use that.
|
|
6
|
+
const { pathToFileURL } = require('url')
|
|
7
|
+
|
|
8
|
+
const importOrRequireCache = new Map()
|
|
9
|
+
|
|
10
|
+
const importOrRequire = async (path) => {
|
|
11
|
+
if (importOrRequireCache.has(path)) {
|
|
12
|
+
return importOrRequireCache.get(path)
|
|
13
|
+
}
|
|
14
|
+
let content = {}
|
|
15
|
+
try {
|
|
16
|
+
content = require(path)
|
|
17
|
+
} catch {
|
|
18
|
+
try {
|
|
19
|
+
content = await import(pathToFileURL(path)).then(r => r.default)
|
|
20
|
+
} catch {
|
|
21
|
+
// its ok if this fails since the content dir might only be to provide
|
|
22
|
+
// other files. the index.js is optional
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
importOrRequireCache.set(path, content)
|
|
26
|
+
return content
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = importOrRequire
|
package/lib/util/merge.js
CHANGED
|
@@ -65,7 +65,6 @@ const customizers = {
|
|
|
65
65
|
module.exports = {
|
|
66
66
|
// default merge is to overwrite arrays
|
|
67
67
|
merge: mergeWithCustomizers(customizers.overwriteArrays),
|
|
68
|
-
mergeWithArrays: (...keys) => mergeWithCustomizers(customizers.mergeArrays(...keys)),
|
|
69
68
|
mergeWithCustomizers,
|
|
70
69
|
mergeWith,
|
|
71
70
|
customizers,
|
package/lib/util/parser.js
CHANGED
|
@@ -173,7 +173,7 @@ class Gitignore extends Base {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
class Js extends Base {
|
|
176
|
-
static types = ['*.js']
|
|
176
|
+
static types = ['*.js', '*.cjs']
|
|
177
177
|
comment = (c) => `/* ${c} */`
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -306,6 +306,10 @@ class JsonMerge extends Json {
|
|
|
306
306
|
merge = (t, s) => merge(t, s)
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
class JsonMergeNoComment extends JsonMerge {
|
|
310
|
+
comment = null
|
|
311
|
+
}
|
|
312
|
+
|
|
309
313
|
class PackageJson extends JsonMerge {
|
|
310
314
|
static types = ['package.json']
|
|
311
315
|
|
|
@@ -346,6 +350,7 @@ const Parsers = {
|
|
|
346
350
|
YmlMerge,
|
|
347
351
|
Json,
|
|
348
352
|
JsonMerge,
|
|
353
|
+
JsonMergeNoComment,
|
|
349
354
|
PackageJson,
|
|
350
355
|
}
|
|
351
356
|
|
package/lib/util/path.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { posix, win32 } = require('path')
|
|
2
|
+
|
|
3
|
+
const makePosix = (v) => v.split(win32.sep).join(posix.sep)
|
|
4
|
+
const deglob = (v) => makePosix(v).replace(/[/*]+$/, '')
|
|
5
|
+
const posixDir = (v) => `${v === '.' ? '' : deglob(v).replace(/\/$/, '')}${posix.sep}`
|
|
6
|
+
const posixGlob = (str) => `${posixDir(str)}**`
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
makePosix,
|
|
10
|
+
deglob,
|
|
11
|
+
posixDir,
|
|
12
|
+
posixGlob,
|
|
13
|
+
}
|