@jcoreio/toolchain 2.1.2 → 3.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "base JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"open": "^8.4.0",
|
|
28
28
|
"prettier": "^2.5.1",
|
|
29
|
+
"prompts": "^2.4.2",
|
|
29
30
|
"resolve-bin": "^1.0.0",
|
|
30
31
|
"semver": "^7.5.3",
|
|
31
32
|
"toposort": "^2.0.2",
|
|
@@ -5,6 +5,9 @@ const sortDeps = require('../../util/sortDeps.cjs')
|
|
|
5
5
|
const semver = require('semver')
|
|
6
6
|
const isEmpty = require('lodash/isEmpty')
|
|
7
7
|
const pick = require('lodash/pick')
|
|
8
|
+
const Path = require('path')
|
|
9
|
+
const { toolchainConfig } = require('../../util/findUps.cjs')
|
|
10
|
+
const confirm = require('../../util/confirm.cjs')
|
|
8
11
|
|
|
9
12
|
async function migrateProjectPackageJson() {
|
|
10
13
|
const { merge, unset } = require('lodash')
|
|
@@ -23,13 +26,10 @@ async function migrateProjectPackageJson() {
|
|
|
23
26
|
'config.mocha',
|
|
24
27
|
'config.prettier',
|
|
25
28
|
'eslintConfig',
|
|
26
|
-
'exports',
|
|
27
29
|
'files',
|
|
28
30
|
'husky',
|
|
29
31
|
'husky',
|
|
30
32
|
'lint-staged',
|
|
31
|
-
'main',
|
|
32
|
-
'module',
|
|
33
33
|
'nyc',
|
|
34
34
|
'prettier',
|
|
35
35
|
'renovate',
|
|
@@ -64,10 +64,55 @@ async function migrateProjectPackageJson() {
|
|
|
64
64
|
]) {
|
|
65
65
|
unset(packageJson, path)
|
|
66
66
|
}
|
|
67
|
+
if (!packageJson.main && !packageJson.exports && !packageJson.module) {
|
|
68
|
+
const hasIndexTypes =
|
|
69
|
+
(await fs.pathExists(Path.join('src', 'index.ts'))) ||
|
|
70
|
+
(await fs.pathExists(Path.join('src', 'index.tsx'))) ||
|
|
71
|
+
(await fs.pathExists(Path.join('src', 'index.d.ts')))
|
|
72
|
+
const hasIndex =
|
|
73
|
+
hasIndexTypes || (await fs.pathExists(Path.join('src', 'index.js')))
|
|
74
|
+
if (hasIndex) {
|
|
75
|
+
packageJson.main = 'index.js'
|
|
76
|
+
packageJson.module = 'index.mjs'
|
|
77
|
+
}
|
|
78
|
+
if (hasIndexTypes) {
|
|
79
|
+
packageJson.types = 'index.d.ts'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
67
82
|
for (const dep of require('./migrateRemoveDevDeps.cjs')) {
|
|
68
83
|
delete devDependencies[dep]
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
if (
|
|
87
|
+
!packageJson.exports &&
|
|
88
|
+
(await confirm({
|
|
89
|
+
type: 'confirm',
|
|
90
|
+
initial: true,
|
|
91
|
+
ifNotInteractive: false,
|
|
92
|
+
message: 'Add ./* exports map to package.json?',
|
|
93
|
+
}))
|
|
94
|
+
) {
|
|
95
|
+
packageJson.exports = {
|
|
96
|
+
'./package.json': './package.json',
|
|
97
|
+
...(packageJson.main
|
|
98
|
+
? {
|
|
99
|
+
'.': {
|
|
100
|
+
...(packageJson.types ? { types: packageJson.types } : {}),
|
|
101
|
+
...(toolchainConfig.outputEsm !== false && packageJson.module
|
|
102
|
+
? { import: packageJson.module }
|
|
103
|
+
: {}),
|
|
104
|
+
default: packageJson.main,
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
: {}),
|
|
108
|
+
'./*': {
|
|
109
|
+
types: './*.d.ts',
|
|
110
|
+
...(toolchainConfig.outputEsm !== false ? { import: './*.mjs' } : {}),
|
|
111
|
+
default: './*.js',
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
71
116
|
merge(
|
|
72
117
|
packageJson,
|
|
73
118
|
{
|
package/util/confirm.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const isInteractive = require('./isInteractive.cjs')
|
|
2
|
+
|
|
3
|
+
module.exports = async function confirm({
|
|
4
|
+
message,
|
|
5
|
+
initial,
|
|
6
|
+
ifNotInteractive = initial,
|
|
7
|
+
}) {
|
|
8
|
+
return isInteractive
|
|
9
|
+
? (
|
|
10
|
+
await require('prompts')({
|
|
11
|
+
type: 'confirm',
|
|
12
|
+
message,
|
|
13
|
+
initial,
|
|
14
|
+
name: 'yes',
|
|
15
|
+
})
|
|
16
|
+
).yes
|
|
17
|
+
: ifNotInteractive || false
|
|
18
|
+
}
|