@npmcli/template-oss 2.4.2 → 2.6.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 +6 -0
- package/lib/config.js +3 -0
- package/lib/content/ci-no-windows.yml +48 -0
- package/lib/content/ci-workspace.yml +26 -39
- package/lib/content/ci.yml +13 -5
- package/lib/postinstall/copy-content.js +14 -2
- package/lib/postinstall/update-package.js +5 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ These fields will be set in the project's `package.json`:
|
|
|
41
41
|
lint: `eslint '**/*.js'`,
|
|
42
42
|
postlint: 'npm-template-check',
|
|
43
43
|
lintfix: 'npm run lint -- --fix',
|
|
44
|
+
'template-copy': 'npm-template-copy --force',
|
|
44
45
|
preversion: 'npm test',
|
|
45
46
|
postversion: 'npm publish',
|
|
46
47
|
prepublishOnly: 'git push origin --follow-tags',
|
|
@@ -99,6 +100,11 @@ your new file. The object keys are destination paths, and values are source.
|
|
|
99
100
|
`npm-template-check` is run by `postlint` and will error if the `package.json`
|
|
100
101
|
is not configured properly, with steps to run to correct any problems.
|
|
101
102
|
|
|
103
|
+
### Manual copy
|
|
104
|
+
|
|
105
|
+
Template files will be copied automatically when `template-oss` is updated.
|
|
106
|
+
You can force an update with `npm run template-copy`.
|
|
107
|
+
|
|
102
108
|
#### Extending
|
|
103
109
|
|
|
104
110
|
Add any unwanted packages to `unwantedPackages` in `lib/check.js`. Currently
|
package/lib/config.js
CHANGED
|
@@ -7,6 +7,7 @@ const defaultConfig = {
|
|
|
7
7
|
applyRootModuleFiles: true,
|
|
8
8
|
workspaces: [],
|
|
9
9
|
paths: [],
|
|
10
|
+
force: false,
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
module.exports = async (root) => {
|
|
@@ -44,5 +45,7 @@ module.exports = async (root) => {
|
|
|
44
45
|
|
|
45
46
|
config.paths.push(root)
|
|
46
47
|
|
|
48
|
+
config.force = process.argv.indexOf('--force') !== -1
|
|
49
|
+
|
|
47
50
|
return config
|
|
48
51
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# This file is automatically added by @npmcli/template-oss. Do not edit.
|
|
2
|
+
|
|
3
|
+
name: CI
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
pull_request:
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
- latest
|
|
11
|
+
schedule:
|
|
12
|
+
# "At 02:00 on Monday" https://crontab.guru/#0_1_*_*_1
|
|
13
|
+
- cron: "0 2 * * 1"
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
lint:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v2
|
|
20
|
+
- uses: actions/setup-node@v2
|
|
21
|
+
with:
|
|
22
|
+
node-version: '16'
|
|
23
|
+
- run: npm i --prefer-online -g npm@latest
|
|
24
|
+
- run: npm i
|
|
25
|
+
- run: npm run lint
|
|
26
|
+
|
|
27
|
+
test:
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
node-version: [12.13.0, 12.x, 14.15.0, 14.x, 16.13.0, 16.x]
|
|
32
|
+
platform:
|
|
33
|
+
- os: ubuntu-latest
|
|
34
|
+
shell: bash
|
|
35
|
+
- os: macos-latest
|
|
36
|
+
shell: bash
|
|
37
|
+
runs-on: ${{ matrix.platform.os }}
|
|
38
|
+
defaults:
|
|
39
|
+
run:
|
|
40
|
+
shell: ${{ matrix.platform.shell }}
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@v2
|
|
43
|
+
- uses: actions/setup-node@v2
|
|
44
|
+
with:
|
|
45
|
+
node-version: ${{ matrix.node-version }}
|
|
46
|
+
- run: npm i --prefer-online -g npm@latest
|
|
47
|
+
- run: npm i
|
|
48
|
+
- run: npm test --ignore-scripts
|
|
@@ -4,8 +4,6 @@ on:
|
|
|
4
4
|
pull_request:
|
|
5
5
|
paths:
|
|
6
6
|
- %%pkgpath%%/**
|
|
7
|
-
branches:
|
|
8
|
-
- '*'
|
|
9
7
|
push:
|
|
10
8
|
paths:
|
|
11
9
|
- %%pkgpath%%/**
|
|
@@ -20,57 +18,46 @@ jobs:
|
|
|
20
18
|
steps:
|
|
21
19
|
# Checkout the npm/cli repo
|
|
22
20
|
- uses: actions/checkout@v2
|
|
23
|
-
-
|
|
24
|
-
uses: actions/setup-node@v2
|
|
21
|
+
- uses: actions/setup-node@v2
|
|
25
22
|
with:
|
|
26
|
-
node-version: 16
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
node ./bin/npm-cli.js install --ignore-scripts --no-audit
|
|
31
|
-
node ./bin/npm-cli.js rebuild
|
|
32
|
-
- name: Run linting
|
|
33
|
-
run: node ./bin/npm-cli.js run posttest -w %%pkgpath%%
|
|
34
|
-
env:
|
|
35
|
-
DEPLOY_VERSION: testing
|
|
23
|
+
node-version: '16'
|
|
24
|
+
- run: npm i --prefer-online -g npm@latest
|
|
25
|
+
- run: npm i
|
|
26
|
+
- run: npm run lint -w %%pkgpath%%
|
|
36
27
|
|
|
37
28
|
test:
|
|
38
29
|
strategy:
|
|
39
30
|
fail-fast: false
|
|
40
31
|
matrix:
|
|
41
|
-
node-version: [
|
|
32
|
+
node-version: [12.13.0, 12.x, 14.15.0, 14.x, 16.13.0, 16.x]
|
|
42
33
|
platform:
|
|
43
34
|
- os: ubuntu-latest
|
|
44
35
|
shell: bash
|
|
45
36
|
- os: macos-latest
|
|
46
37
|
shell: bash
|
|
47
38
|
- os: windows-latest
|
|
48
|
-
shell:
|
|
49
|
-
- os: windows-latest
|
|
50
|
-
shell: powershell
|
|
51
|
-
|
|
39
|
+
shell: cmd
|
|
52
40
|
runs-on: ${{ matrix.platform.os }}
|
|
53
41
|
defaults:
|
|
54
42
|
run:
|
|
55
43
|
shell: ${{ matrix.platform.shell }}
|
|
56
|
-
|
|
57
44
|
steps:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
run:
|
|
45
|
+
- uses: actions/checkout@v2
|
|
46
|
+
- uses: actions/setup-node@v2
|
|
47
|
+
with:
|
|
48
|
+
node-version: ${{ matrix.node-version }}
|
|
49
|
+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
|
|
50
|
+
- name: Update to workable npm (windows)
|
|
51
|
+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12') || startsWith(matrix.node-version, '14'))
|
|
52
|
+
run: |
|
|
53
|
+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
|
|
54
|
+
tar xf npm-7.5.4.tgz
|
|
55
|
+
cd package
|
|
56
|
+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
|
|
57
|
+
cd ..
|
|
58
|
+
rmdir /s /q package
|
|
59
|
+
- name: Update npm
|
|
60
|
+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
|
|
61
|
+
- run: npm -v
|
|
62
|
+
- run: npm i
|
|
63
|
+
- run: npm test --ignore-scripts -w %%pkgpath%%
|
package/lib/content/ci.yml
CHANGED
|
@@ -34,12 +34,8 @@ jobs:
|
|
|
34
34
|
shell: bash
|
|
35
35
|
- os: macos-latest
|
|
36
36
|
shell: bash
|
|
37
|
-
- os: windows-latest
|
|
38
|
-
shell: bash
|
|
39
37
|
- os: windows-latest
|
|
40
38
|
shell: cmd
|
|
41
|
-
- os: windows-latest
|
|
42
|
-
shell: powershell
|
|
43
39
|
runs-on: ${{ matrix.platform.os }}
|
|
44
40
|
defaults:
|
|
45
41
|
run:
|
|
@@ -49,6 +45,18 @@ jobs:
|
|
|
49
45
|
- uses: actions/setup-node@v2
|
|
50
46
|
with:
|
|
51
47
|
node-version: ${{ matrix.node-version }}
|
|
52
|
-
|
|
48
|
+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
|
|
49
|
+
- name: Update to workable npm (windows)
|
|
50
|
+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12') || startsWith(matrix.node-version, '14'))
|
|
51
|
+
run: |
|
|
52
|
+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
|
|
53
|
+
tar xf npm-7.5.4.tgz
|
|
54
|
+
cd package
|
|
55
|
+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
|
|
56
|
+
cd ..
|
|
57
|
+
rmdir /s /q package
|
|
58
|
+
- name: Update npm
|
|
59
|
+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
|
|
60
|
+
- run: npm -v
|
|
53
61
|
- run: npm i
|
|
54
62
|
- run: npm test --ignore-scripts
|
|
@@ -38,6 +38,7 @@ const defaultConfig = {
|
|
|
38
38
|
applyRootRepoFiles: true,
|
|
39
39
|
applyWorkspaceRepoFiles: true,
|
|
40
40
|
applyRootModuleFiles: true,
|
|
41
|
+
windowsCI: true,
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const copyFiles = async (targetDir, files) => {
|
|
@@ -78,9 +79,18 @@ const copyContent = async (path, rootPath, config) => {
|
|
|
78
79
|
if (!isWorkspace) {
|
|
79
80
|
if (config.applyRootRepoFiles) {
|
|
80
81
|
await copyFiles(rootPath, repoFiles)
|
|
82
|
+
if (!config.windowsCI) {
|
|
83
|
+
// copyFiles already did the mkdir so we can just fs.copyFile now
|
|
84
|
+
await fs.copyFile(
|
|
85
|
+
join(contentDir, 'ci-no-windows.yml'),
|
|
86
|
+
join(rootPath, '.github', 'workflows', 'ci.yml')
|
|
87
|
+
)
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
return
|
|
83
|
-
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// only workspace now
|
|
84
94
|
|
|
85
95
|
// TODO: await copyFiles(path, workspaceFiles)
|
|
86
96
|
// if we ever have workspace specific files
|
|
@@ -89,6 +99,8 @@ const copyContent = async (path, rootPath, config) => {
|
|
|
89
99
|
// copy and edit workspace repo file (ci github action)
|
|
90
100
|
const workspacePkg = (await PackageJson.load(path)).content
|
|
91
101
|
const workspaceName = workspacePkg.name
|
|
102
|
+
let workspaceFile = `ci-${workspaceName.replace(/\//g, '-')}.yml`
|
|
103
|
+
workspaceFile = workspaceFile.replace(/@/g, '')
|
|
92
104
|
const workflowPath = join(rootPath, '.github', 'workflows')
|
|
93
105
|
await fs.mkdir(workflowPath, {
|
|
94
106
|
owner: 'inherit',
|
|
@@ -105,7 +117,7 @@ const copyContent = async (path, rootPath, config) => {
|
|
|
105
117
|
workflowData = workflowData.replace(/%%pkgpath%%/g, relPath)
|
|
106
118
|
workflowData = workflowData.replace(/%%pkgname%%/g, workspaceName)
|
|
107
119
|
|
|
108
|
-
await fs.writeFile(join(workflowPath,
|
|
120
|
+
await fs.writeFile(join(workflowPath, workspaceFile), workflowData)
|
|
109
121
|
}
|
|
110
122
|
}
|
|
111
123
|
copyContent.moduleFiles = moduleFiles
|
|
@@ -11,6 +11,7 @@ const changes = {
|
|
|
11
11
|
scripts: {
|
|
12
12
|
lint: `eslint '**/*.js'`,
|
|
13
13
|
postlint: 'npm-template-check',
|
|
14
|
+
'template-copy': 'npm-template-copy --force',
|
|
14
15
|
lintfix: 'npm run lint -- --fix',
|
|
15
16
|
preversion: 'npm test',
|
|
16
17
|
postversion: 'npm publish',
|
|
@@ -26,6 +27,7 @@ const changes = {
|
|
|
26
27
|
|
|
27
28
|
const patchPackage = async (path, root, config) => {
|
|
28
29
|
const pkg = await PackageJson.load(path)
|
|
30
|
+
config = config || {}
|
|
29
31
|
|
|
30
32
|
// If we are running this on itself, we always run the script.
|
|
31
33
|
// We also don't set templateVersion in package.json because
|
|
@@ -38,7 +40,9 @@ const patchPackage = async (path, root, config) => {
|
|
|
38
40
|
// if the target package.json has a templateVersion field matching our own
|
|
39
41
|
// current version, we return false here so the postinstall script knows to
|
|
40
42
|
// exit early instead of running everything again
|
|
41
|
-
if (
|
|
43
|
+
if (!config.force
|
|
44
|
+
&& currentVersion === TEMPLATE_VERSION
|
|
45
|
+
&& !isDogfood) {
|
|
42
46
|
return false
|
|
43
47
|
}
|
|
44
48
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npmcli/template-oss",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "templated files used in npm CLI team oss projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"npm-template-check": "bin/npm-template-check.js"
|
|
7
|
+
"npm-template-check": "bin/npm-template-check.js",
|
|
8
|
+
"npm-template-copy": "bin/postinstall.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"lint": "eslint '**/*.js'",
|
|
@@ -16,7 +17,8 @@
|
|
|
16
17
|
"prepublishOnly": "git push origin --follow-tags",
|
|
17
18
|
"preversion": "npm test",
|
|
18
19
|
"snap": "tap",
|
|
19
|
-
"test": "tap"
|
|
20
|
+
"test": "tap",
|
|
21
|
+
"template-copy": "npm-template-copy --force"
|
|
20
22
|
},
|
|
21
23
|
"repository": {
|
|
22
24
|
"type": "git",
|