@jcoreio/toolchain 5.5.9 → 5.7.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": "5.5.9",
3
+ "version": "5.7.0",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,6 @@
1
1
  const mapValues = require('../util/mapValues.cjs')
2
+ const { toolchainConfig } = require('@jcoreio/toolchain/util/findUps.cjs')
3
+ const outputEsm = toolchainConfig.outputEsm !== false
2
4
 
3
5
  module.exports = [
4
6
  async function buildDistPackageJson(packageJson) {
@@ -6,16 +8,37 @@ module.exports = [
6
8
  delete packageJson.scripts
7
9
  delete packageJson.config
8
10
 
9
- function replaceDist(path) {
10
- return path.replace(/^(\.\/)?dist\//, '$1')
11
+ function replaceDist(path, ext) {
12
+ path = path.replace(/^(\.\/)?(src|dist)\//, '$1')
13
+ if (ext) path = path.replace(/(\.d)?\.tsx?$/, ext)
14
+ return path
11
15
  }
12
16
 
13
- for (const key of ['main', 'module', 'browser', 'types', 'bin']) {
17
+ const dtsExtension = packageJson.type === 'module' ? '.d.cts' : '.d.ts'
18
+ const cjsExtension = packageJson.type === 'module' ? '.cjs' : '.js'
19
+ const esmExtension = packageJson.type === 'module' ? '.js' : '.mjs'
20
+
21
+ for (const key of ['main', 'module', 'browser', 'types', 'bin', 'types']) {
14
22
  if (typeof packageJson[key] === 'string') {
15
- packageJson[key] = replaceDist(packageJson[key])
23
+ packageJson[key] = replaceDist(
24
+ packageJson[key],
25
+ key === 'module' ? esmExtension
26
+ : key === 'main' ? cjsExtension
27
+ : key === 'types' ? dtsExtension
28
+ : outputEsm ? esmExtension
29
+ : cjsExtension
30
+ )
16
31
  }
17
32
  }
18
- for (const key of ['bin', 'directories']) {
33
+ for (const key of ['bin']) {
34
+ if (typeof packageJson[key] === 'object' && packageJson[key] != null) {
35
+ packageJson[key] = mapValues(packageJson[key], (path) =>
36
+ replaceDist(path, outputEsm ? esmExtension : cjsExtension)
37
+ )
38
+ }
39
+ }
40
+
41
+ for (const key of ['directories']) {
19
42
  if (typeof packageJson[key] === 'object' && packageJson[key] != null) {
20
43
  packageJson[key] = mapValues(packageJson[key], replaceDist)
21
44
  }