@jcoreio/toolchain-esnext 1.0.0-beta.2 → 1.0.0-beta.3
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": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "ESNext JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"resolve-bin": "^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@jcoreio/toolchain": "1.0.0-beta.
|
|
37
|
+
"@jcoreio/toolchain": "1.0.0-beta.3"
|
|
38
38
|
},
|
|
39
39
|
"bin": {
|
|
40
40
|
"babel": "./bin/babel",
|
package/plugins/babelPresets.cjs
CHANGED
|
@@ -9,18 +9,17 @@ module.exports = [
|
|
|
9
9
|
const exportMap = { './package.json': './package.json' }
|
|
10
10
|
let usesBabelRuntime = false
|
|
11
11
|
for (const file of files) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
''
|
|
15
|
-
|
|
12
|
+
const fileInDist = `./${Path.relative('dist', file)}`
|
|
13
|
+
const key = fileInDist
|
|
14
|
+
.replace(/(\.[^/.]*)*$/, '')
|
|
15
|
+
.replace(/\/index$/, '')
|
|
16
16
|
const forFile = exportMap[key] || (exportMap[key] = {})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
] = `./${file}`
|
|
17
|
+
const condition = /\.d\.ts$/.test(file)
|
|
18
|
+
? 'types'
|
|
19
|
+
: /\.c?js$/.test(file)
|
|
20
|
+
? 'require'
|
|
21
|
+
: 'import'
|
|
22
|
+
forFile[condition] = fileInDist
|
|
24
23
|
usesBabelRuntime =
|
|
25
24
|
usesBabelRuntime ||
|
|
26
25
|
// this could return false positives in rare cases, but keeps the test simple
|
package/plugins/compile.cjs
CHANGED
|
@@ -3,14 +3,13 @@ const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
|
|
|
3
3
|
const glob = require('@jcoreio/toolchain/util/glob.cjs')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const dedent = require('dedent-js')
|
|
6
|
-
const {
|
|
6
|
+
const { toolchainConfig } = require('@jcoreio/toolchain/util/findUps.cjs')
|
|
7
7
|
const getPluginsArraySync = require('@jcoreio/toolchain/util/getPluginsArraySync.cjs')
|
|
8
8
|
const resolveImportsCodemod = require('../util/resolveImportsCodemod.cjs')
|
|
9
9
|
|
|
10
10
|
module.exports = [
|
|
11
11
|
[
|
|
12
12
|
async function compile(args = []) {
|
|
13
|
-
const config = packageJson['@jcoreio/toolchain']
|
|
14
13
|
const extensions = getPluginsArraySync('babelExtensions')
|
|
15
14
|
|
|
16
15
|
await execa('babel', [
|
|
@@ -23,7 +22,7 @@ module.exports = [
|
|
|
23
22
|
])
|
|
24
23
|
const jsFiles = await glob(path.join('dist', '**', '*.js'))
|
|
25
24
|
await resolveImportsCodemod(jsFiles)
|
|
26
|
-
if (
|
|
25
|
+
if (toolchainConfig.esWrapper) {
|
|
27
26
|
await Promise.all(
|
|
28
27
|
jsFiles.map((file) =>
|
|
29
28
|
fs.writeFile(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs-extra')
|
|
2
2
|
const { parseAsync } = require('babel-parse-wild-code')
|
|
3
3
|
const getImportSources = require('./getImportSources.cjs')
|
|
4
|
+
const replaceRanges = require('@jcoreio/toolchain/util/replaceRanges.cjs')
|
|
4
5
|
|
|
5
6
|
async function transformImportSources({ file, source, ast, transform }) {
|
|
6
7
|
if (!source) source = await fs.readFile(file, 'utf8')
|
|
@@ -13,23 +14,8 @@ async function transformImportSources({ file, source, ast, transform }) {
|
|
|
13
14
|
source: value,
|
|
14
15
|
})
|
|
15
16
|
if (replacement === value) continue
|
|
16
|
-
replacements.push({ value: replacement, start, end })
|
|
17
|
+
replacements.push({ value: JSON.stringify(replacement), start, end })
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const parts = []
|
|
21
|
-
let end = 0
|
|
22
|
-
for (const r of replacements) {
|
|
23
|
-
if (r.start > end) {
|
|
24
|
-
parts.push(source.substring(end, r.start))
|
|
25
|
-
}
|
|
26
|
-
parts.push(JSON.stringify(r.value))
|
|
27
|
-
end = r.end
|
|
28
|
-
}
|
|
29
|
-
if (end < source.length) {
|
|
30
|
-
parts.push(source.substring(end))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return parts.join('')
|
|
19
|
+
return replaceRanges(source, replacements)
|
|
34
20
|
}
|
|
35
21
|
module.exports = transformImportSources
|