@jcoreio/toolchain 2.1.2 → 3.1.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.1.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",
|
package/scripts/init.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const preinstall = require('./preinstall.cjs')
|
|
|
6
6
|
const execa = require('../util/execa.cjs')
|
|
7
7
|
const hasTSFiles = require('../util/hasTSFiles.cjs')
|
|
8
8
|
const { name, version } = require('../package.json')
|
|
9
|
+
const isInteractive = require('../util/isInteractive.cjs')
|
|
9
10
|
|
|
10
11
|
async function init(args = []) {
|
|
11
12
|
const { dependencies = {}, devDependencies = {} } = packageJson
|
|
@@ -33,6 +34,28 @@ async function init(args = []) {
|
|
|
33
34
|
if (isCircle) toolchains.add(`${name}-circle`)
|
|
34
35
|
if (isSemanticRelease) toolchains.add(`${name}-semantic-release`)
|
|
35
36
|
|
|
37
|
+
let selectedToolchains = [...toolchains]
|
|
38
|
+
if (isInteractive) {
|
|
39
|
+
;({ selectedToolchains } = await require('prompts')({
|
|
40
|
+
name: 'selectedToolchains',
|
|
41
|
+
type: 'multiselect',
|
|
42
|
+
message: 'Select toolchains to install',
|
|
43
|
+
choices: [
|
|
44
|
+
'mocha',
|
|
45
|
+
'esnext',
|
|
46
|
+
'flow',
|
|
47
|
+
'typescript',
|
|
48
|
+
'react',
|
|
49
|
+
'circle',
|
|
50
|
+
'semantic-release',
|
|
51
|
+
].map((value) => ({
|
|
52
|
+
title: `${name}-${value}`,
|
|
53
|
+
value: `${name}-${value}`,
|
|
54
|
+
selected: toolchains.has(`${name}-${value}`),
|
|
55
|
+
})),
|
|
56
|
+
}))
|
|
57
|
+
}
|
|
58
|
+
|
|
36
59
|
const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
|
|
37
60
|
|
|
38
61
|
await preinstall.run()
|
|
@@ -41,8 +64,10 @@ async function init(args = []) {
|
|
|
41
64
|
'-D',
|
|
42
65
|
isTest ? '../packages/base' : `${name}@^${version}`,
|
|
43
66
|
...(isTest
|
|
44
|
-
? [...
|
|
45
|
-
|
|
67
|
+
? [...selectedToolchains].map((t) =>
|
|
68
|
+
t.replace(`${name}-`, '../packages/')
|
|
69
|
+
)
|
|
70
|
+
: [...selectedToolchains].map((t) => `${t}@^${version}`)),
|
|
46
71
|
])
|
|
47
72
|
await execa('tc', ['migrate'])
|
|
48
73
|
}
|
|
@@ -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
|
+
}
|