@jcoreio/toolchain 4.8.0 → 4.9.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": "4.8.0",
3
+ "version": "4.9.0",
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": "^7.2.0",
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",
@@ -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
- /* eslint-env node, es2018 */
77
- const base = require('${name}/${file}')
78
- module.exports = {
79
- ...base,
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
  ? []
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,4 +1,4 @@
1
- const glob = require('../../util/glob.cjs')
1
+ const { glob } = require('../../util/glob.cjs')
2
2
  const Path = require('path')
3
3
  const JSON5 = require('json5')
4
4
  const fs = require('../../util/projectFs.cjs')
@@ -1,4 +1,4 @@
1
- const glob = require('../../util/glob.cjs')
1
+ const { glob } = require('../../util/glob.cjs')
2
2
  const fs = require('../../util/projectFs.cjs')
3
3
  const path = require('path')
4
4
 
@@ -0,0 +1,8 @@
1
+ const isBuildIgnored = require('./isBuildIgnored.cjs')
2
+
3
+ module.exports = {
4
+ ignore: {
5
+ ignored: (p) => isBuildIgnored(p.fullpath()),
6
+ childrenIgnored: (p) => isBuildIgnored(p.fullpath()),
7
+ },
8
+ }
@@ -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 glob = require('glob')
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
- glob.sync(Path.join(p, 'package.json'), { cwd: monorepoProjectDir })
67
+ globSync(Path.join(p, 'package.json'), { cwd: monorepoProjectDir })
68
68
  )
69
69
  ),
70
70
  ].map((f) => Path.resolve(monorepoProjectDir, f))
@@ -1,5 +1,5 @@
1
1
  const fs = require('./projectFs.cjs')
2
- const glob = require('./glob.cjs')
2
+ const { glob } = require('./glob.cjs')
3
3
  const path = require('path')
4
4
 
5
5
  module.exports = async function getModules(packageJsonFile) {
package/util/glob.cjs CHANGED
@@ -1,6 +1,23 @@
1
- const _glob = require('util').promisify(require('glob'))
1
+ const { glob, globSync, globIterate, globIterateSync } = require('glob')
2
2
  const { projectDir } = require('./findUps.cjs')
3
3
 
4
- const glob = (what, options) => _glob(what, { cwd: projectDir, ...options })
5
-
6
- module.exports = glob
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
+ }
@@ -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 fs.readdir('src')
6
- return files.some((f) => /\.[cm]?tsx?$/.test(f))
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
- const files = fs.readdirSync('src')
6
- return files.some((f) => /\.[cm]?tsx?$/.test(f) && !/\.d\.[cm]?tsx?$/.test(f))
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
+ }