-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtypescript.js
87 lines (77 loc) · 1.99 KB
/
typescript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-disable no-console */
import mergeOptions from 'merge-options'
import { semanticReleaseConfig } from '../semantic-release-config.js'
import {
sortFields,
sortExportsMap,
constructManifest
} from '../utils.js'
const merge = mergeOptions.bind({ ignoreUndefined: true })
/**
* @param {any} manifest
* @param {string} branchName
* @param {string} repoUrl
* @param {string} [homePage]
*/
export async function typescriptManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
let proposedManifest = constructManifest(manifest, {
type: 'module',
types: './dist/src/index.d.ts',
typesVersions: undefined,
files: [
'src',
'dist',
'!dist/test',
'!**/*.tsbuildinfo'
],
exports: sortExportsMap(
merge({
'.': {
types: './dist/src/index.d.ts',
import: './dist/src/index.js'
}
}, manifest.exports)
),
eslintConfig: merge({
extends: 'ipfs',
parserOptions: {
project: true,
sourceType: 'module'
}
}, manifest.eslintConfig),
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
}, repoUrl, homePage)
if (proposedManifest.exports != null && Object.keys(proposedManifest.exports).length > 1) {
console.info('Multiple exports detected')
proposedManifest.typesVersions = {
'*': {
'*': [
'*',
'dist/*',
'dist/src/*',
'dist/src/*/index'
],
'src/*': [
'*',
'dist/*',
'dist/src/*',
'dist/src/*/index'
]
}
}
}
const rest = {
...sortFields(manifest)
}
for (const key of Object.keys(proposedManifest)) {
delete rest[key]
}
proposedManifest = {
...proposedManifest,
...rest,
contributors: undefined,
leadMaintainer: undefined
}
delete proposedManifest.main
return proposedManifest
}