@jcoreio/toolchain-esnext 4.5.8 → 4.6.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-esnext",
3
- "version": "4.5.8",
3
+ "version": "4.6.0",
4
4
  "description": "ESNext JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "fs-extra": "^10.0.0",
32
32
  "resolve": "^1.22.2",
33
33
  "resolve-bin": "^1.0.0",
34
- "@jcoreio/toolchain": "4.5.8"
34
+ "@jcoreio/toolchain": "4.6.0"
35
35
  },
36
36
  "toolchainManaged": {
37
37
  "dependencies": {
@@ -8,6 +8,7 @@ const {
8
8
  projectDir,
9
9
  } = require('@jcoreio/toolchain/util/findUps.cjs')
10
10
  const getPluginsArraySync = require('@jcoreio/toolchain/util/getPluginsArraySync.cjs')
11
+ const fixSourceMaps = require('../util/fixSourceMaps.cjs')
11
12
 
12
13
  module.exports = [
13
14
  [
@@ -24,6 +25,9 @@ module.exports = [
24
25
  'dist',
25
26
  '--out-file-extension',
26
27
  '.js',
28
+ ...(toolchainConfig.sourceMaps
29
+ ? ['--source-maps', toolchainConfig.sourceMaps]
30
+ : []),
27
31
  ],
28
32
  { env: { ...process.env, JCOREIO_TOOLCHAIN_CJS: '1' } }
29
33
  )
@@ -57,6 +61,9 @@ module.exports = [
57
61
  'dist',
58
62
  '--out-file-extension',
59
63
  '.mjs',
64
+ ...(toolchainConfig.sourceMaps
65
+ ? ['--source-maps', toolchainConfig.sourceMaps]
66
+ : []),
60
67
  ],
61
68
  { env: { ...process.env, JCOREIO_TOOLCHAIN_ESM: '1' } }
62
69
  )
@@ -81,6 +88,21 @@ module.exports = [
81
88
  }
82
89
  }
83
90
  }
91
+
92
+ if (toolchainConfig.sourceMaps) {
93
+ const srcFiles = await glob(path.join('src', '**'))
94
+ await Promise.all(
95
+ srcFiles.map(async (src) => {
96
+ if (src === 'src') return
97
+ const dest = path.join('dist', src)
98
+ // eslint-disable-next-line no-console
99
+ console.error(src, '->', dest)
100
+ await fs.copy(src, dest)
101
+ })
102
+ )
103
+
104
+ await fixSourceMaps()
105
+ }
84
106
  },
85
107
  { insteadOf: '@jcoreio/toolchain' },
86
108
  ],
@@ -18,6 +18,7 @@ module.exports = [
18
18
  outputEsm ? '// ' : ''
19
19
  }outputEsm: false, // disables ESM output (default: true)
20
20
  // esWrapper: true, // outputs ES module wrappers for CJS modules (default: false)
21
+ // sourceMaps: false, // default is true (outputs .map files, also accepts 'inline' or 'both')
21
22
  // scripts: {
22
23
  // pretest: 'docker compose up -d',
23
24
  // jsExample: {
@@ -0,0 +1,23 @@
1
+ const path = require('path')
2
+ const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
3
+ const glob = require('@jcoreio/toolchain/util/glob.cjs')
4
+
5
+ module.exports = async function fixSourceMaps() {
6
+ const mapFiles = await glob(
7
+ path.join('dist', '**', '*.{js,cjs,mjs,d.ts,d.cts,d.mts}.map')
8
+ )
9
+ await Promise.all(
10
+ mapFiles.map(async (file) => {
11
+ const content = await fs.readJson(file)
12
+ const { sources } = content
13
+ let changed = false
14
+ for (let i = 0; i < sources.length; i++) {
15
+ if (sources[i].startsWith('../src/')) {
16
+ changed = true
17
+ sources[i] = sources[i].substring('../'.length)
18
+ }
19
+ }
20
+ if (changed) await fs.writeJson(file, content)
21
+ })
22
+ )
23
+ }