Skip to content

Commit 0d757b8

Browse files
committed
fix: set package.json fields when using tap@16 + ts
1 parent 84d1bef commit 0d757b8

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

lib/config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const getFullConfig = async ({
166166
deleteJsExt: esm ? 'js' : 'cjs',
167167
// tap
168168
tap18: semver.coerce(pkg.pkgJson?.devDependencies?.tap)?.major === 18,
169+
tap16: semver.coerce(pkg.pkgJson?.devDependencies?.tap)?.major === 16,
169170
// booleans to control application of updates
170171
isForce,
171172
isDogFood,
@@ -198,11 +199,13 @@ const getFullConfig = async ({
198199
if (pkgConfig.typescript) {
199200
defaultsDeep(pkgConfig, { allowPaths: [], requiredPackages: { devDependencies: [] } })
200201
pkgConfig.distPaths = ['dist/']
202+
pkgConfig.allowDistPaths = false
201203
pkgConfig.allowPaths.push('/src/')
202204
pkgConfig.requiredPackages.devDependencies.push(
203205
'typescript',
204206
'tshy',
205-
'@typescript-eslint/parser'
207+
'@typescript-eslint/parser',
208+
...derived.tap16 ? ['c8', 'ts-node'] : []
206209
)
207210
}
208211

@@ -252,7 +255,7 @@ const getFullConfig = async ({
252255
]),
253256
...isRoot && pkgConfig.lockfile ? ['!/package-lock.json'] : [],
254257
...(pkgConfig.allowPaths || []).map((p) => `!${p}`),
255-
...(pkgConfig.distPaths || []).map((p) => `!/${p}`),
258+
...(pkgConfig.allowDistPaths ? pkgConfig.distPaths : []).map((p) => `!/${p}`),
256259
...(pkgConfig.ignorePaths || []),
257260
]),
258261
// these cant be sorted since they rely on order

lib/content/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ module.exports = {
155155
'bin/',
156156
'lib/',
157157
],
158+
allowDistPaths: true,
158159
allowPaths: [
159160
'/.eslintrc.local.*',
160161
'**/.gitignore',

lib/content/package-json.hbs

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"postlint": "template-oss-check",
88
"template-oss-apply": "template-oss-apply --force",
99
"lintfix": "{{ localNpmPath }} run lint -- --fix",
10-
"snap": "tap",
11-
"test": "tap",
10+
"snap": "{{#if typescript}}{{#if tap16}}c8 {{/if}}{{/if}}tap",
11+
"test": "{{#if typescript}}{{#if tap16}}c8 {{/if}}{{/if}}tap",
1212
"posttest": "{{ localNpmPath }} run lint",
1313
{{#if isRootMono}}
1414
"test-all": "{{ localNpmPath }} run test {{ allFlags }}",
@@ -34,6 +34,16 @@
3434
{{#if workspacePaths}}
3535
"test-ignore": "^({{ join workspacePaths "|" }})/",
3636
{{/if}}
37+
{{#if typescript}}
38+
{{#if tap16}}
39+
"coverage": false,
40+
"node-arg": [
41+
"--no-warnings",
42+
"--loader",
43+
"ts-node/esm"
44+
],
45+
{{/if}}
46+
{{/if}}
3747
"nyc-arg": {{#if tap18}}{{{ del }}}{{else}}[
3848
{{#each workspaceGlobs}}
3949
"--exclude",

test/apply/typescript.js

+22
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,25 @@ t.test('no default content', async (t) => {
5555

5656
t.strictSame(checks[0].body, ['typescript', 'tshy', '@typescript-eslint/parser'])
5757
})
58+
59+
t.test('with tap 16', async (t) => {
60+
const s = await setup(t, {
61+
ok: true,
62+
package: {
63+
devDependencies: {
64+
tap: '^16',
65+
},
66+
templateOSS: {
67+
typescript: true,
68+
},
69+
},
70+
})
71+
await s.apply()
72+
const checks = await s.check()
73+
const pkg = await s.readJson('package.json')
74+
75+
t.equal(pkg.scripts.test, 'c8 tap')
76+
t.equal(pkg.scripts.snap, 'c8 tap')
77+
t.strictSame(pkg.tap['node-arg'], ['--no-warnings', '--loader', 'ts-node/esm'])
78+
t.strictSame(checks[0].body, ['typescript', 'tshy', '@typescript-eslint/parser', 'c8', 'ts-node'])
79+
})

0 commit comments

Comments
 (0)