@jcoreio/toolchain 4.8.0 → 4.9.1
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 +3 -2
- package/plugins/compile.cjs +2 -0
- package/plugins/getConfigFiles.cjs +9 -7
- package/plugins/smokeTestBuild.cjs +26 -0
- package/scripts/build.cjs +1 -1
- package/scripts/migrate/migrateEslintConfigs.cjs +1 -1
- package/scripts/migrate/migrateMoveTypeDefs.cjs +1 -1
- package/scripts/smokeTestBuild.cjs +3 -22
- package/scripts/toolchain.cjs +6 -1
- package/util/buildGlobOpts.cjs +8 -0
- package/util/configSchema.cjs +2 -0
- package/util/findUps.cjs +2 -2
- package/util/getModules.cjs +1 -1
- package/util/glob.cjs +21 -4
- package/util/hasTSFiles.cjs +3 -3
- package/util/hasTSSources.cjs +15 -0
- package/util/hasTSSourcesSync.cjs +11 -3
- package/util/initBuildIgnore.cjs +18 -0
- package/util/isBuildIgnored.cjs +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.1",
|
|
4
4
|
"description": "base JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
"execa": "^5.0.0",
|
|
23
23
|
"find-up": "^5.0.0",
|
|
24
24
|
"fs-extra": "^10.0.0",
|
|
25
|
-
"glob": "^
|
|
25
|
+
"glob": "^11.0.0",
|
|
26
26
|
"json5": "^2.2.1",
|
|
27
27
|
"lint-staged": "^15.2.2",
|
|
28
|
+
"minimatch": "^10.0.1",
|
|
28
29
|
"open": "^8.4.0",
|
|
29
30
|
"prettier": "^2.5.1",
|
|
30
31
|
"prompts": "^2.4.2",
|
package/plugins/compile.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Path = require('path')
|
|
2
2
|
const { projectDir } = require('../util/findUps.cjs')
|
|
3
3
|
const fs = require('../util/projectFs.cjs')
|
|
4
|
+
const isBuildIgnored = require('../util/isBuildIgnored.cjs')
|
|
4
5
|
|
|
5
6
|
module.exports = [
|
|
6
7
|
async function compile(args = []) {
|
|
@@ -8,6 +9,7 @@ module.exports = [
|
|
|
8
9
|
if (err.code !== 'ENOENT') throw err
|
|
9
10
|
}
|
|
10
11
|
const filter = (src, dest) => {
|
|
12
|
+
if (isBuildIgnored(src)) return false
|
|
11
13
|
// eslint-disable-next-line no-console
|
|
12
14
|
console.error(
|
|
13
15
|
Path.relative(projectDir, src),
|
|
@@ -4,6 +4,7 @@ const fs = require('../util/projectFs.cjs')
|
|
|
4
4
|
const JSON5 = require('json5')
|
|
5
5
|
const { isMonorepoSubpackage } = require('../util/findUps.cjs')
|
|
6
6
|
const getPluginsArraySync = require('../util/getPluginsArraySync.cjs')
|
|
7
|
+
const initBuildIgnore = require('../util/initBuildIgnore.cjs')
|
|
7
8
|
|
|
8
9
|
async function getRootEslintConfig() {
|
|
9
10
|
if (await fs.pathExists('.eslintrc.json')) {
|
|
@@ -53,6 +54,7 @@ module.exports = [
|
|
|
53
54
|
return dedent`
|
|
54
55
|
/* eslint-env node, es2018 */
|
|
55
56
|
module.exports = {
|
|
57
|
+
buildIgnore: ${JSON.stringify(await initBuildIgnore(), null, 2)},
|
|
56
58
|
// scripts: {
|
|
57
59
|
// pretest: 'docker compose up -d',
|
|
58
60
|
// jsExample: {
|
|
@@ -73,13 +75,13 @@ module.exports = [
|
|
|
73
75
|
existing && fromVersion
|
|
74
76
|
? existing
|
|
75
77
|
: dedent`
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
/* eslint-env node, es2018 */
|
|
79
|
+
const base = require('${name}/${file}')
|
|
80
|
+
module.exports = {
|
|
81
|
+
...base,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
`
|
|
83
85
|
}
|
|
84
86
|
const tasks = isMonorepoSubpackage
|
|
85
87
|
? []
|
|
@@ -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/build.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const Path = require('path')
|
|
|
3
3
|
const { projectDir } = require('../util/findUps.cjs')
|
|
4
4
|
const fs = require('../util/projectFs.cjs')
|
|
5
5
|
const execa = require('../util/execa.cjs')
|
|
6
|
-
const glob = require('../util/glob.cjs')
|
|
6
|
+
const { glob } = require('../util/glob.cjs')
|
|
7
7
|
|
|
8
8
|
exports.run = async function build(args = []) {
|
|
9
9
|
await execa('tc', ['clean'])
|
|
@@ -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
|
@@ -42,12 +42,17 @@ const scripts = toolchainConfig
|
|
|
42
42
|
...Object.fromEntries(
|
|
43
43
|
Object.entries(toolchainConfig.scripts || {}).map(([name, script]) => [
|
|
44
44
|
name,
|
|
45
|
-
typeof script === 'string'
|
|
45
|
+
typeof script === 'string' && script.trim()
|
|
46
46
|
? {
|
|
47
47
|
run: (args = []) =>
|
|
48
48
|
execa([script, ...args].join(' '), { shell: true }),
|
|
49
49
|
description: script,
|
|
50
50
|
}
|
|
51
|
+
: !script || typeof script === 'string'
|
|
52
|
+
? {
|
|
53
|
+
run: () => {},
|
|
54
|
+
description: '(no-op)',
|
|
55
|
+
}
|
|
51
56
|
: script,
|
|
52
57
|
])
|
|
53
58
|
),
|
package/util/configSchema.cjs
CHANGED
|
@@ -5,6 +5,8 @@ module.exports = z.object({
|
|
|
5
5
|
esmBabelEnv: z.record(z.unknown()).optional(),
|
|
6
6
|
esWrapper: z.boolean().optional(),
|
|
7
7
|
outputEsm: z.boolean().optional(),
|
|
8
|
+
hasTypeScriptSources: z.boolean().optional(),
|
|
9
|
+
buildIgnore: z.array(z.string()).optional(),
|
|
8
10
|
sourceMaps: z
|
|
9
11
|
.union([
|
|
10
12
|
/**
|
package/util/findUps.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const findUp = require('find-up')
|
|
2
2
|
const Path = require('path')
|
|
3
3
|
const fs = require('fs-extra')
|
|
4
|
-
const
|
|
4
|
+
const { globSync } = require('glob')
|
|
5
5
|
const merge = require('./merge.cjs')
|
|
6
6
|
const once = require('./once.cjs')
|
|
7
7
|
const { name } = require('../package.json')
|
|
@@ -64,7 +64,7 @@ exports.monorepoSubpackageJsonFiles = pnpmWorkspace
|
|
|
64
64
|
? [
|
|
65
65
|
...new Set(
|
|
66
66
|
pnpmWorkspace.packages.flatMap((p) =>
|
|
67
|
-
|
|
67
|
+
globSync(Path.join(p, 'package.json'), { cwd: monorepoProjectDir })
|
|
68
68
|
)
|
|
69
69
|
),
|
|
70
70
|
].map((f) => Path.resolve(monorepoProjectDir, f))
|
package/util/getModules.cjs
CHANGED
package/util/glob.cjs
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { glob, globSync, globIterate, globIterateSync } = require('glob')
|
|
2
2
|
const { projectDir } = require('./findUps.cjs')
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
module.exports = {
|
|
5
|
+
glob: (what, options) => glob(what, { cwd: projectDir, ...options }),
|
|
6
|
+
globSync: (what, options) => globSync(what, { cwd: projectDir, ...options }),
|
|
7
|
+
globIterate: (what, options) =>
|
|
8
|
+
globIterate(what, { cwd: projectDir, ...options }),
|
|
9
|
+
globIterateSync: (what, options) =>
|
|
10
|
+
globIterateSync(what, { cwd: projectDir, ...options }),
|
|
11
|
+
globExists: async (what, options) => {
|
|
12
|
+
for await (const _ of module.exports.globIterate(what, options)) {
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
return false
|
|
16
|
+
},
|
|
17
|
+
globExistsSync: (what, options) => {
|
|
18
|
+
for (const _ of module.exports.globIterateSync(what, options)) {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
return false
|
|
22
|
+
},
|
|
23
|
+
}
|
package/util/hasTSFiles.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const fs = require('./projectFs.cjs')
|
|
2
1
|
const once = require('./once.cjs')
|
|
2
|
+
const { glob } = require('./glob.cjs')
|
|
3
3
|
|
|
4
4
|
module.exports = once(async function hasTSFiles() {
|
|
5
|
-
const files = await
|
|
6
|
-
return files.
|
|
5
|
+
const files = await glob('**/*.{ts,tsx}')
|
|
6
|
+
return files.length > 0
|
|
7
7
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const once = require('./once.cjs')
|
|
2
|
+
const { globExists } = require('./glob.cjs')
|
|
3
|
+
const { toolchainConfig } = require('./findUps.cjs')
|
|
4
|
+
|
|
5
|
+
module.exports = once(async function hasTSSources() {
|
|
6
|
+
if (
|
|
7
|
+
toolchainConfig &&
|
|
8
|
+
typeof toolchainConfig.hasTypeScriptSources === 'boolean'
|
|
9
|
+
) {
|
|
10
|
+
return toolchainConfig.hasTypeScriptSources
|
|
11
|
+
}
|
|
12
|
+
return await globExists('src/**/*.{ts,cts,mts,tsx,ctsx,mtsx}', {
|
|
13
|
+
ignore: '**/*.d.{ts,cts,mts}',
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
const fs = require('./projectFs.cjs')
|
|
2
1
|
const once = require('./once.cjs')
|
|
2
|
+
const { globExistsSync } = require('./glob.cjs')
|
|
3
|
+
const { toolchainConfig } = require('./findUps.cjs')
|
|
3
4
|
|
|
4
5
|
module.exports = once(function hasTSSourcesSync() {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
if (
|
|
7
|
+
toolchainConfig &&
|
|
8
|
+
typeof toolchainConfig.hasTypeScriptSources === 'boolean'
|
|
9
|
+
) {
|
|
10
|
+
return toolchainConfig.hasTypeScriptSources
|
|
11
|
+
}
|
|
12
|
+
return globExistsSync('src/**/*.{ts,cts,mts,tsx,ctsx,mtsx}', {
|
|
13
|
+
ignore: '**/*.d.{ts,cts,mts}',
|
|
14
|
+
})
|
|
7
15
|
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { globExists } = require('@jcoreio/toolchain/util/glob.cjs')
|
|
2
|
+
const getPluginsArraySync = require('@jcoreio/toolchain/util/getPluginsArraySync.cjs')
|
|
3
|
+
|
|
4
|
+
module.exports = async function initBuildIgnore() {
|
|
5
|
+
const buildIgnore = []
|
|
6
|
+
if (await globExists('src/**/__tests__')) {
|
|
7
|
+
buildIgnore.push('src/**/__tests__')
|
|
8
|
+
}
|
|
9
|
+
for (const extension of getPluginsArraySync('sourceExtensions')) {
|
|
10
|
+
for (const suffix of ['test', 'spec']) {
|
|
11
|
+
const pattern = `src/**/*.${suffix}.${extension}`
|
|
12
|
+
if (await globExists(pattern, { ignore: 'src/**/__tests__/**' })) {
|
|
13
|
+
buildIgnore.push(pattern)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return buildIgnore
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const { toolchainConfig, projectDir } = require('./findUps.cjs')
|
|
3
|
+
const { Minimatch } = require('minimatch')
|
|
4
|
+
|
|
5
|
+
const matchers = ((toolchainConfig && toolchainConfig.buildIgnore) || []).map(
|
|
6
|
+
(pattern) => new Minimatch(pattern)
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
module.exports = function isBuildIgnored(file) {
|
|
10
|
+
if (path.isAbsolute(file)) file = path.relative(projectDir, file)
|
|
11
|
+
return matchers.some((m) => m.match(file))
|
|
12
|
+
}
|