@jcoreio/toolchain 3.7.0 → 3.8.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/scripts/prepublish.cjs +1 -0
- package/scripts/smokeTestBuild.cjs +26 -0
- package/scripts/toolchain.cjs +1 -0
- package/util/getModules.cjs +72 -0
package/package.json
CHANGED
package/scripts/prepublish.cjs
CHANGED
|
@@ -6,6 +6,7 @@ exports.run = async function (args = []) {
|
|
|
6
6
|
if (scripts.coverage) await execa('tc', ['coverage'])
|
|
7
7
|
if (scripts['test:esm']) await execa('tc', ['test:esm'])
|
|
8
8
|
await execa('tc', ['build'])
|
|
9
|
+
await execa('tc', ['build:smoke-test'])
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
exports.description = 'run check, coverage, and build'
|
|
@@ -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
|
+
exports.run = async function smokeTestBuild() {
|
|
6
|
+
const { cjs, esm } = await getModules('dist/package.json')
|
|
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
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.description = 'smoke test that build output can be required/imported'
|
package/scripts/toolchain.cjs
CHANGED
|
@@ -9,6 +9,7 @@ const execa = require('../util/execa.cjs')
|
|
|
9
9
|
const scripts = {
|
|
10
10
|
migrate: require('./migrate.cjs'),
|
|
11
11
|
build: require('./build.cjs'),
|
|
12
|
+
'build:smoke-test': require('./smokeTestBuild.cjs'),
|
|
12
13
|
check: require('./check.cjs'),
|
|
13
14
|
clean: require('./clean.cjs'),
|
|
14
15
|
format: require('./format.cjs'),
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const fs = require('./projectFs.cjs')
|
|
2
|
+
const glob = require('./glob.cjs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
module.exports = async function getModules(packageJsonFile) {
|
|
6
|
+
const cjs = new Set()
|
|
7
|
+
const esm = new Set()
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
type = 'commonjs',
|
|
11
|
+
main,
|
|
12
|
+
module,
|
|
13
|
+
bin,
|
|
14
|
+
exports,
|
|
15
|
+
} = await fs.readJson(packageJsonFile)
|
|
16
|
+
|
|
17
|
+
const defaultType = type
|
|
18
|
+
function checkFile(
|
|
19
|
+
file,
|
|
20
|
+
type = file
|
|
21
|
+
? /\.cjs$/.test(file)
|
|
22
|
+
? 'commonjs'
|
|
23
|
+
: /\.mjs$/.test(file)
|
|
24
|
+
? 'module'
|
|
25
|
+
: /\.js$/.test(file)
|
|
26
|
+
? defaultType
|
|
27
|
+
: undefined
|
|
28
|
+
: undefined
|
|
29
|
+
) {
|
|
30
|
+
if (!file) return
|
|
31
|
+
if (type === 'commonjs') cjs.add(file)
|
|
32
|
+
else if (type === 'module') esm.add(file)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
checkFile(main)
|
|
36
|
+
checkFile(module)
|
|
37
|
+
if (typeof bin === 'string') checkFile(bin)
|
|
38
|
+
else if (bin instanceof Object) {
|
|
39
|
+
for (const file of Object.values(bin)) checkFile(file)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function checkExport(exp, type) {
|
|
43
|
+
if (typeof exp === 'string') {
|
|
44
|
+
if (exp.includes('*')) {
|
|
45
|
+
const files = await glob(exp.replace('*', '**'), {
|
|
46
|
+
cwd: path.dirname(packageJsonFile),
|
|
47
|
+
})
|
|
48
|
+
for (const file of files) checkFile(file, type)
|
|
49
|
+
} else {
|
|
50
|
+
checkFile(exp, type)
|
|
51
|
+
}
|
|
52
|
+
} else if (exp instanceof Object) {
|
|
53
|
+
for (const [key, value] of Object.entries(exp)) {
|
|
54
|
+
await checkExport(
|
|
55
|
+
value,
|
|
56
|
+
type ||
|
|
57
|
+
(key === 'require'
|
|
58
|
+
? 'commonjs'
|
|
59
|
+
: key === 'import'
|
|
60
|
+
? 'module'
|
|
61
|
+
: undefined)
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await checkExport(exports)
|
|
68
|
+
|
|
69
|
+
const resolvePath = (f) => path.resolve(path.dirname(packageJsonFile), f)
|
|
70
|
+
|
|
71
|
+
return { cjs: [...cjs].map(resolvePath), esm: [...esm].map(resolvePath) }
|
|
72
|
+
}
|