@npmcli/template-oss 3.1.2 → 3.2.2

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.
@@ -18,7 +18,7 @@ module.exports = [{
18
18
  options.config.repoFiles,
19
19
  options
20
20
  ),
21
- when: ({ config: c }) => c.isForce || (c.needsUpdate && c.applyRepo),
21
+ when: ({ config: c }) => c.applyRepo && c.needsUpdate,
22
22
  name: 'apply-repo',
23
23
  }, {
24
24
  run: (options) => run(
@@ -26,6 +26,6 @@ module.exports = [{
26
26
  options.config.moduleFiles,
27
27
  options
28
28
  ),
29
- when: ({ config: c }) => c.isForce || (c.needsUpdate && c.applyModule),
29
+ when: ({ config: c }) => c.applyModule && c.needsUpdate,
30
30
  name: 'apply-module',
31
31
  }]
@@ -0,0 +1,26 @@
1
+ const log = require('proc-log')
2
+ const PackageJson = require('@npmcli/package-json')
3
+
4
+ const run = async ({ config: c }) => {
5
+ const {
6
+ moduleDir: dir,
7
+ __CONFIG_KEY__: key,
8
+ __VERSION__: version,
9
+ } = c
10
+
11
+ log.verbose('apply-version', dir)
12
+
13
+ const pkg = await PackageJson.load(dir)
14
+ if (!pkg.content[key]) {
15
+ pkg.content[key] = { version }
16
+ } else {
17
+ pkg.content[key].version = version
18
+ }
19
+ await pkg.save()
20
+ }
21
+
22
+ module.exports = {
23
+ run,
24
+ when: ({ config: c }) => c.needsUpdate && !c.isDogFood,
25
+ name: 'apply-version',
26
+ }
@@ -2,4 +2,5 @@ const run = require('../index.js')
2
2
 
3
3
  module.exports = (root, content) => run(root, content, [
4
4
  require('./apply-files.js'),
5
+ require('./apply-version.js'),
5
6
  ])
package/lib/config.js CHANGED
@@ -56,6 +56,7 @@ const getConfig = async ({
56
56
  const isRoot = root === path
57
57
  const isLatest = version === LATEST_VERSION
58
58
  const isDogFood = pkg.name === NAME
59
+ const isForce = process.argv.includes('--force')
59
60
 
60
61
  // this is written to ci yml files so it needs to always use posix
61
62
  const pkgRelPath = makePosix(relative(root, path))
@@ -111,16 +112,18 @@ const getConfig = async ({
111
112
  pkgName: pkg.name,
112
113
  pkgNameFs: pkg.name.replace(/\//g, '-').replace(/@/g, ''),
113
114
  pkgRelPath: pkgRelPath,
114
- // force changes if we are dogfooding this repo or with force argv
115
- // XXX: setup proper cli arg parsing
116
- isForce: isDogFood || process.argv.includes('--force'),
115
+ pkgPrivate: !!pkg.private,
116
+ // booleans to control application of updates
117
+ isForce,
118
+ isDogFood,
117
119
  isLatest,
118
- needsUpdate: !isLatest,
120
+ // needs update if we are dogfooding this repo, with force argv, or its
121
+ // behind the current version
122
+ needsUpdate: isForce || isDogFood || !isLatest,
119
123
  // templateoss specific values
120
124
  __NAME__: NAME,
121
125
  __CONFIG_KEY__: CONFIG_KEY,
122
126
  __VERSION__: LATEST_VERSION,
123
- __DOGFOOD__: isDogFood,
124
127
  }
125
128
 
126
129
  // merge the rest of base and pkg content to make the
@@ -12,5 +12,5 @@ jobs:
12
12
  steps:
13
13
  {{> setupGit}}
14
14
  {{> setupNode}}
15
- - run: npm i --package-lock
15
+ - run: npm i --ignore-scripts --package-lock
16
16
  - run: npm audit
@@ -28,7 +28,7 @@ jobs:
28
28
  steps:
29
29
  {{> setupGit}}
30
30
  {{> setupNode}}
31
- - run: npm i
31
+ - run: npm i --ignore-scripts
32
32
  - run: npm run lint {{~#if isWorkspace}} -w {{pkgName}}{{/if}}
33
33
 
34
34
  test:
@@ -55,5 +55,5 @@ jobs:
55
55
  steps:
56
56
  {{> setupGit}}
57
57
  {{> setupNode useMatrix=true}}
58
- - run: npm i
58
+ - run: npm i --ignore-scripts
59
59
  - run: npm test --ignore-scripts {{~#if isWorkspace}} -w {{pkgName}}{{/if}}
@@ -5,6 +5,7 @@ const localConfigs = readdir(__dirname)
5
5
  .map((file) => `./${file}`)
6
6
 
7
7
  module.exports = {
8
+ root: true,
8
9
  extends: [
9
10
  '@npmcli',
10
11
  ...localConfigs,
@@ -38,7 +38,10 @@ const rootModule = {
38
38
  // Changes for each workspace but applied to the root of the repo
39
39
  const workspaceRepo = {
40
40
  add: {
41
- '.github/workflows/release-please-{{pkgNameFs}}.yml': 'release-please.yml',
41
+ '.github/workflows/release-please-{{pkgNameFs}}.yml': {
42
+ file: 'release-please.yml',
43
+ filter: (o) => !o.pkg.private,
44
+ },
42
45
  '.github/workflows/ci-{{pkgNameFs}}.yml': 'ci.yml',
43
46
  },
44
47
  }
@@ -53,6 +56,7 @@ const workspaceModule = {
53
56
  rm: [
54
57
  '.npmrc',
55
58
  '.eslintrc.!(js|local.*)',
59
+ 'SECURITY.md',
56
60
  ],
57
61
  }
58
62
 
@@ -7,8 +7,12 @@
7
7
  "template-oss-apply": "template-oss-apply --force",
8
8
  "lintfix": "npm run lint -- --fix",
9
9
  "preversion": "npm test",
10
+ {{#if pkgPrivate}}
11
+ "postversion": "git push origin --follow-tags",
12
+ {{else}}
10
13
  "postversion": "npm publish",
11
14
  "prepublishOnly": "git push origin --follow-tags",
15
+ {{/if}}
12
16
  "snap": "tap",
13
17
  "test": "tap",
14
18
  "posttest": "npm run lint",
@@ -20,7 +24,7 @@
20
24
  "node": {{{json engines}}}
21
25
  },
22
26
  {{{json __CONFIG_KEY__}}}: {
23
- "version": {{#if __DOGFOOD__}}{{{del}}}{{else}}{{{json __VERSION__}}}{{/if}}
27
+ "version": {{#if isDogFood}}{{{del}}}{{else}}{{{json __VERSION__}}}{{/if}}
24
28
  },
25
29
  "templateVersion": {{{del}}},
26
30
  "standard": {{{del}}}
@@ -26,8 +26,9 @@ jobs:
26
26
  GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
27
27
  run: |
28
28
  gh pr checkout $\{{ github.event.pull_request.number }}
29
- npm install --no-scripts
29
+ npm install --ignore-scripts
30
30
  npm run template-oss-apply
31
31
  git add .
32
32
  git commit -am "chore: postinstall for dependabot template-oss PR"
33
33
  git push
34
+ npm run lint
@@ -21,7 +21,7 @@ jobs:
21
21
  release-type: node
22
22
  {{#if pkgRelPath}}
23
23
  monorepo-tags: true
24
- paths: {{pkgRelPath}}
24
+ path: {{pkgRelPath}}
25
25
  {{/if}}
26
26
  changelog-types: >
27
27
  [
package/lib/util/files.js CHANGED
@@ -9,13 +9,24 @@ const fullTarget = (dir, file, options) => join(dir, template(file, options))
9
9
 
10
10
  // given an obj of files, return the full target/source paths and associated parser
11
11
  const getParsers = (dir, files, options) => Object.entries(files).map(([t, s]) => {
12
- let { file, parser: fileParser } = typeof s === 'string' ? { file: s } : s
13
- const target = fullTarget(dir, t, options)
12
+ let {
13
+ file,
14
+ parser: fileParser,
15
+ filter,
16
+ } = typeof s === 'string' ? { file: s } : s
17
+
14
18
  file = join(options.config.sourceDir, file)
19
+ const target = fullTarget(dir, t, options)
20
+
21
+ if (typeof filter === 'function' && !filter(options)) {
22
+ return null
23
+ }
24
+
15
25
  if (fileParser) {
16
26
  // allow files to extend base parsers or create new ones
17
27
  return new (fileParser(Parser.Parsers))(target, file, options)
18
28
  }
29
+
19
30
  return new (Parser(file))(target, file, options)
20
31
  })
21
32
 
@@ -32,7 +43,9 @@ const rmEach = async (dir, files, options, fn) => {
32
43
  const parseEach = async (dir, files, options, fn) => {
33
44
  const res = []
34
45
  for (const parser of getParsers(dir, files, options)) {
35
- res.push(await fn(parser))
46
+ if (parser) {
47
+ res.push(await fn(parser))
48
+ }
36
49
  }
37
50
  return res.filter(Boolean)
38
51
  }
@@ -249,7 +249,7 @@ class PackageJson extends JsonMerge {
249
249
  return unset(pkg.content, keys)
250
250
  }
251
251
  })
252
- pkg.save()
252
+ await pkg.save()
253
253
  }
254
254
  }
255
255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/template-oss",
3
- "version": "3.1.2",
3
+ "version": "3.2.2",
4
4
  "description": "templated files used in npm CLI team oss projects",
5
5
  "main": "lib/content/index.js",
6
6
  "bin": {
@@ -44,7 +44,7 @@
44
44
  "npm-package-arg": "^9.0.1",
45
45
  "proc-log": "^2.0.0",
46
46
  "semver": "^7.3.5",
47
- "yaml": "^2.0.0-10"
47
+ "yaml": "^2.0.0-11"
48
48
  },
49
49
  "files": [
50
50
  "bin/",