@npmcli/template-oss 4.1.1 → 4.2.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.
@@ -3,35 +3,37 @@ const { basename, extname, join } = require('path')
3
3
  const fs = require('fs')
4
4
  const DELETE = '__DELETE__'
5
5
 
6
- const partialName = (s) =>
7
- basename(s, extname(s)).replace(/-([a-z])/g, (_, g) => g.toUpperCase())
6
+ const partialName = (s) => basename(s, extname(s)) // remove extension
7
+ .replace(/^_/, '') // remove leading underscore
8
+ .replace(/-([a-z])/g, (_, g) => g.toUpperCase()) // camelcase
8
9
 
9
- const setupHandlebars = (partialsDir) => {
10
+ const setupHandlebars = (...partialDirs) => {
10
11
  Handlebars.registerHelper('obj', ({ hash }) => hash)
11
12
  Handlebars.registerHelper('json', (c) => JSON.stringify(c))
12
13
  Handlebars.registerHelper('del', () => JSON.stringify(DELETE))
13
14
 
14
- // Load all content files as camelcase partial names
15
- for (const f of fs.readdirSync(join(partialsDir))) {
16
- Handlebars.registerPartial(
17
- partialName(f),
18
- fs.readFileSync(join(partialsDir, f)).toString()
19
- )
15
+ // Load all files as camelcase partial names.
16
+ // all other content dirs only get special underscore leading
17
+ // files as partials. this prevents recursion loops when overwriting
18
+ // a filename to use as a enw file
19
+ let isBase = true
20
+ for (const dir of partialDirs) {
21
+ for (const f of fs.readdirSync(dir)) {
22
+ if (f.startsWith('_') || isBase) {
23
+ Handlebars.registerPartial(
24
+ partialName(f),
25
+ fs.readFileSync(join(dir, f)).toString()
26
+ )
27
+ }
28
+ }
29
+ isBase = false
20
30
  }
21
31
  }
22
32
 
23
- const cache = new Map()
24
-
25
33
  const template = (str, { config, ...options }) => {
26
- if (cache.size === 0) {
27
- setupHandlebars(config.sourceDir)
28
- }
34
+ setupHandlebars(...config.__PARTIAL_DIRS__)
29
35
 
30
- let t = cache.get(str)
31
- if (t == null) {
32
- t = Handlebars.compile(str, { strict: true })
33
- cache.set(str, t)
34
- }
36
+ const t = Handlebars.compile(str, { strict: true })
35
37
 
36
38
  // merge in config as top level data in templates
37
39
  return t({ ...options, ...config })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/template-oss",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "description": "templated files used in npm CLI team oss projects",
5
5
  "main": "lib/content/index.js",
6
6
  "bin": {
@@ -32,6 +32,7 @@
32
32
  "@actions/core": "^1.9.1",
33
33
  "@commitlint/cli": "^17.1.1",
34
34
  "@commitlint/config-conventional": "^17.1.0",
35
+ "@isaacs/string-locale-compare": "^1.1.0",
35
36
  "@npmcli/fs": "^2.0.1",
36
37
  "@npmcli/git": "^3.0.0",
37
38
  "@npmcli/map-workspaces": "^2.0.2",
@@ -41,6 +42,7 @@
41
42
  "handlebars": "^4.7.7",
42
43
  "hosted-git-info": "^5.0.0",
43
44
  "json-parse-even-better-errors": "^2.3.1",
45
+ "just-deep-map-values": "^1.1.1",
44
46
  "just-diff": "^5.0.1",
45
47
  "lodash": "^4.17.21",
46
48
  "npm-package-arg": "^9.0.1",
@@ -59,7 +61,11 @@
59
61
  "tap": "^16.0.0"
60
62
  },
61
63
  "tap": {
62
- "timeout": 600
64
+ "timeout": 600,
65
+ "nyc-arg": [
66
+ "--exclude",
67
+ "tap-snapshots/**"
68
+ ]
63
69
  },
64
70
  "templateOSS": {
65
71
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."
@@ -1,46 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- workflow_call:
5
- inputs:
6
- ref:
7
- required: true
8
- type: string
9
-
10
- jobs:
11
- lint-all:
12
- runs-on: ubuntu-latest
13
- steps:
14
- {{> setupGit with=(obj ref="${{ inputs.ref }}")}}
15
- {{> setupNode}}
16
- {{> setupDeps}}
17
- - run: npm run lint --if-present --workspaces --include-workspace-root
18
-
19
- test-all:
20
- strategy:
21
- fail-fast: false
22
- matrix:
23
- node-version:
24
- {{#each ciVersions}}
25
- - {{.}}
26
- {{/each}}
27
- platform:
28
- - os: ubuntu-latest
29
- shell: bash
30
- - os: macos-latest
31
- shell: bash
32
- {{#if windowsCI}}
33
- - os: windows-latest
34
- shell: cmd
35
- {{/if}}
36
- runs-on: $\{{ matrix.platform.os }}
37
- defaults:
38
- run:
39
- shell: $\{{ matrix.platform.shell }}
40
- steps:
41
- {{> setupGit with=(obj ref="${{ inputs.ref }}")}}
42
- {{> setupNode useMatrix=true}}
43
- {{> setupDeps}}
44
- - name: add tap problem matcher
45
- run: echo "::add-matcher::.github/matchers/tap.json"
46
- - run: npm run test --if-present --workspaces --include-workspace-root
@@ -1 +0,0 @@
1
- - run: npm i --ignore-scripts --no-audit --no-fund {{~#if flags}} {{flags}}{{/if}}