@jcoreio/toolchain 4.9.0 → 4.10.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 +1 -1
- package/plugins/smokeTestBuild.cjs +26 -0
- package/scripts/create.cjs +1 -1
- package/scripts/init.cjs +1 -1
- package/scripts/install-optional-deps.cjs +66 -0
- package/scripts/smokeTestBuild.cjs +3 -22
- package/scripts/toolchain.cjs +7 -1
- package/util/confirm.cjs +1 -1
- package/util/hasJSSources.cjs +6 -0
- package/util/prompt.cjs +15 -0
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const getModules = require('../util/getModules.cjs')
|
|
2
|
+
const execa = require('../util/execa.cjs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
async function smokeTestBuild() {
|
|
7
|
+
const { cjs, esm } = await getModules('dist/package.json')
|
|
8
|
+
|
|
9
|
+
function relpath(file) {
|
|
10
|
+
const result = path.relative(process.cwd(), file)
|
|
11
|
+
return result.startsWith('.') ? result : `./${result}`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
for (const file of cjs) {
|
|
15
|
+
await execa('node', ['-e', `require(${JSON.stringify(relpath(file))})`])
|
|
16
|
+
}
|
|
17
|
+
for (const file of esm) {
|
|
18
|
+
await execa('node', [
|
|
19
|
+
'--input-type',
|
|
20
|
+
'module',
|
|
21
|
+
'-e',
|
|
22
|
+
`import ${JSON.stringify(relpath(file))}`,
|
|
23
|
+
])
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
]
|
package/scripts/create.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const parseRepositoryUrl = require('../util/parseRepositoryUrl.cjs')
|
|
|
7
7
|
const markdownBadges = require('../util/markdownBadges.cjs')
|
|
8
8
|
|
|
9
9
|
async function create(args = []) {
|
|
10
|
-
const prompt = require('
|
|
10
|
+
const prompt = require('../util/prompt.cjs')
|
|
11
11
|
|
|
12
12
|
let monorepoPackageJson, monorepoProjectDir
|
|
13
13
|
try {
|
package/scripts/init.cjs
CHANGED
|
@@ -35,7 +35,7 @@ async function init(args = []) {
|
|
|
35
35
|
|
|
36
36
|
let selectedToolchains = [...toolchains]
|
|
37
37
|
if (isInteractive) {
|
|
38
|
-
;({ selectedToolchains } = await require('
|
|
38
|
+
;({ selectedToolchains } = await require('../uitl/prompt')({
|
|
39
39
|
name: 'selectedToolchains',
|
|
40
40
|
type: 'multiselect',
|
|
41
41
|
message: 'Select toolchains to install',
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const execa = require('../util/execa.cjs')
|
|
2
|
+
const {
|
|
3
|
+
packageJson,
|
|
4
|
+
isMonorepoRoot,
|
|
5
|
+
toolchainManaged,
|
|
6
|
+
} = require('../util/findUps.cjs')
|
|
7
|
+
|
|
8
|
+
async function installOptionalDeps() {
|
|
9
|
+
const choices = new Set()
|
|
10
|
+
const { dependencies = {}, devDependencies = {} } = packageJson
|
|
11
|
+
for (const dep of Object.keys({
|
|
12
|
+
...toolchainManaged.optionalDependencies,
|
|
13
|
+
...toolchainManaged.optionalDevDependencies,
|
|
14
|
+
})) {
|
|
15
|
+
if (!dependencies[dep] && !devDependencies[dep]) {
|
|
16
|
+
choices.add(dep)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!choices.size) {
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.error('There are no additional optional dependencies to install')
|
|
22
|
+
process.exit(0)
|
|
23
|
+
}
|
|
24
|
+
const finalChoices = [...choices].sort()
|
|
25
|
+
const { selected } = await require('../util/prompt.cjs')({
|
|
26
|
+
name: 'selected',
|
|
27
|
+
type: 'multiselect',
|
|
28
|
+
message: 'Select optional dependencies to install',
|
|
29
|
+
choices: finalChoices,
|
|
30
|
+
})
|
|
31
|
+
const selectedSet = new Set(selected.map((i) => finalChoices[i]))
|
|
32
|
+
|
|
33
|
+
const selectedDeps = Object.keys(
|
|
34
|
+
toolchainManaged.optionalDependencies || {}
|
|
35
|
+
).filter((dep) => selectedSet.has(dep))
|
|
36
|
+
const selectedDevDeps = Object.keys(
|
|
37
|
+
toolchainManaged.optionalDevDependencies || {}
|
|
38
|
+
).filter((dep) => selectedSet.has(dep))
|
|
39
|
+
|
|
40
|
+
if (selectedDeps.length) {
|
|
41
|
+
await execa('pnpm', [
|
|
42
|
+
'add',
|
|
43
|
+
'--prefer-offline',
|
|
44
|
+
...(isMonorepoRoot ? ['-w'] : []),
|
|
45
|
+
...selectedDeps.map(
|
|
46
|
+
(dep) => `${dep}@${toolchainManaged.optionalDependencies[dep]}`
|
|
47
|
+
),
|
|
48
|
+
])
|
|
49
|
+
}
|
|
50
|
+
if (selectedDevDeps.length) {
|
|
51
|
+
await execa('pnpm', [
|
|
52
|
+
'add',
|
|
53
|
+
'-D',
|
|
54
|
+
'--prefer-offline',
|
|
55
|
+
...(isMonorepoRoot ? ['-w'] : []),
|
|
56
|
+
...selectedDevDeps.map(
|
|
57
|
+
(dep) => `${dep}@${toolchainManaged.optionalDevDependencies[dep]}`
|
|
58
|
+
),
|
|
59
|
+
])
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.description =
|
|
64
|
+
'select and install optional toolchain-managed dependencies'
|
|
65
|
+
|
|
66
|
+
exports.run = installOptionalDeps
|
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const execa = require('../util/execa.cjs')
|
|
3
|
-
const path = require('path')
|
|
1
|
+
const getPluginsAsyncFunction = require('../util/getPluginsAsyncFunction.cjs')
|
|
4
2
|
|
|
5
|
-
exports.run = async function smokeTestBuild() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function relpath(file) {
|
|
9
|
-
const result = path.relative(process.cwd(), file)
|
|
10
|
-
return result.startsWith('.') ? result : `./${result}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (const file of cjs) {
|
|
14
|
-
await execa('node', ['-e', `require(${JSON.stringify(relpath(file))})`])
|
|
15
|
-
}
|
|
16
|
-
for (const file of esm) {
|
|
17
|
-
await execa('node', [
|
|
18
|
-
'--input-type',
|
|
19
|
-
'module',
|
|
20
|
-
'-e',
|
|
21
|
-
`import ${JSON.stringify(relpath(file))}`,
|
|
22
|
-
])
|
|
23
|
-
}
|
|
3
|
+
exports.run = async function smokeTestBuild(args) {
|
|
4
|
+
await getPluginsAsyncFunction('smokeTestBuild')(args)
|
|
24
5
|
}
|
|
25
6
|
|
|
26
7
|
exports.description = 'smoke test that build output can be required/imported'
|
package/scripts/toolchain.cjs
CHANGED
|
@@ -37,17 +37,23 @@ const scripts = toolchainConfig
|
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
'install-git-hooks': require('./install-git-hooks.cjs'),
|
|
40
|
+
'install-optional-deps': require('./install-optional-deps.cjs'),
|
|
40
41
|
...(isMonorepoRoot ? { create: require('./create.cjs') } : {}),
|
|
41
42
|
...getPluginsObjectSync('scripts'),
|
|
42
43
|
...Object.fromEntries(
|
|
43
44
|
Object.entries(toolchainConfig.scripts || {}).map(([name, script]) => [
|
|
44
45
|
name,
|
|
45
|
-
typeof script === 'string'
|
|
46
|
+
typeof script === 'string' && script.trim()
|
|
46
47
|
? {
|
|
47
48
|
run: (args = []) =>
|
|
48
49
|
execa([script, ...args].join(' '), { shell: true }),
|
|
49
50
|
description: script,
|
|
50
51
|
}
|
|
52
|
+
: !script || typeof script === 'string'
|
|
53
|
+
? {
|
|
54
|
+
run: () => {},
|
|
55
|
+
description: '(no-op)',
|
|
56
|
+
}
|
|
51
57
|
: script,
|
|
52
58
|
])
|
|
53
59
|
),
|
package/util/confirm.cjs
CHANGED
package/util/prompt.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const prompts = require('prompts')
|
|
2
|
+
|
|
3
|
+
module.exports = async function prompt(...args) {
|
|
4
|
+
const handleKeypress = function (_chunk, key) {
|
|
5
|
+
if (key && key.name === 'c' && key.ctrl) {
|
|
6
|
+
process.kill(process.pid, 'SIGINT')
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
process.stdin.on('keypress', handleKeypress)
|
|
11
|
+
return await prompts(...args)
|
|
12
|
+
} finally {
|
|
13
|
+
process.stdin.off('keypress', handleKeypress)
|
|
14
|
+
}
|
|
15
|
+
}
|