@jcoreio/toolchain-esnext 5.6.0 → 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-esnext",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "ESNext JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"globals": "^16.0.0",
|
|
33
33
|
"resolve": "^1.22.2",
|
|
34
34
|
"resolve-bin": "^1.0.0",
|
|
35
|
-
"@jcoreio/toolchain": "5.
|
|
35
|
+
"@jcoreio/toolchain": "5.7.0"
|
|
36
36
|
},
|
|
37
37
|
"toolchainManaged": {
|
|
38
38
|
"dependencies": {
|
package/plugins/babelPlugins.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { packageJson } = require('@jcoreio/toolchain/util/findUps.cjs')
|
|
2
|
+
|
|
1
3
|
module.exports = [
|
|
2
4
|
(api) => {
|
|
3
5
|
const {
|
|
@@ -8,6 +10,11 @@ module.exports = [
|
|
|
8
10
|
api.cache.using(() => JCOREIO_TOOLCHAIN_CJS)
|
|
9
11
|
api.cache.using(() => JCOREIO_TOOLCHAIN_ESM)
|
|
10
12
|
api.cache.using(() => JCOREIO_TOOLCHAIN_TEST)
|
|
13
|
+
api.cache.using(() => packageJson.type)
|
|
14
|
+
|
|
15
|
+
const cjsExtension = packageJson.type === 'module' ? '.cjs' : '.js'
|
|
16
|
+
const esmExtension = packageJson.type === 'module' ? '.js' : '.mjs'
|
|
17
|
+
|
|
11
18
|
return [
|
|
12
19
|
require.resolve('@babel/plugin-transform-runtime'),
|
|
13
20
|
// for CJS tests, we leave off import extensions, since @babel/register resolves them.
|
|
@@ -19,7 +26,10 @@ module.exports = [
|
|
|
19
26
|
require.resolve('../util/babelPluginResolveImports.cjs'),
|
|
20
27
|
{
|
|
21
28
|
outputExtension:
|
|
22
|
-
JCOREIO_TOOLCHAIN_ESM && !JCOREIO_TOOLCHAIN_TEST ?
|
|
29
|
+
JCOREIO_TOOLCHAIN_ESM && !JCOREIO_TOOLCHAIN_TEST ? esmExtension
|
|
30
|
+
: JCOREIO_TOOLCHAIN_CJS ? cjsExtension
|
|
31
|
+
: packageJson.type === 'module' ? esmExtension
|
|
32
|
+
: cjsExtension,
|
|
23
33
|
},
|
|
24
34
|
],
|
|
25
35
|
!JCOREIO_TOOLCHAIN_ESM &&
|
package/plugins/compile.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const buildGlobOpts = require('@jcoreio/toolchain/util/buildGlobOpts.cjs')
|
|
|
5
5
|
const path = require('path')
|
|
6
6
|
const dedent = require('dedent-js')
|
|
7
7
|
const {
|
|
8
|
+
packageJson,
|
|
8
9
|
toolchainConfig,
|
|
9
10
|
projectDir,
|
|
10
11
|
} = require('@jcoreio/toolchain/util/findUps.cjs')
|
|
@@ -29,7 +30,7 @@ module.exports = [
|
|
|
29
30
|
'--out-dir',
|
|
30
31
|
'dist',
|
|
31
32
|
'--out-file-extension',
|
|
32
|
-
'.js',
|
|
33
|
+
packageJson.type === 'module' ? '.cjs' : '.js',
|
|
33
34
|
...(toolchainConfig.sourceMaps ?
|
|
34
35
|
['--source-maps', toolchainConfig.sourceMaps]
|
|
35
36
|
: []),
|
|
@@ -69,7 +70,7 @@ module.exports = [
|
|
|
69
70
|
'--out-dir',
|
|
70
71
|
'dist',
|
|
71
72
|
'--out-file-extension',
|
|
72
|
-
'.mjs',
|
|
73
|
+
packageJson.type === 'module' ? '.js' : '.mjs',
|
|
73
74
|
...(toolchainConfig.sourceMaps ?
|
|
74
75
|
['--source-maps', toolchainConfig.sourceMaps]
|
|
75
76
|
: []),
|
|
@@ -80,7 +81,7 @@ module.exports = [
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
if (extensions.length) {
|
|
83
|
-
for (const ext of ['.js', '.mjs']) {
|
|
84
|
+
for (const ext of ['.js', '.cjs', '.mjs']) {
|
|
84
85
|
if (!extensions.includes(ext)) {
|
|
85
86
|
const srcFiles = await glob(path.join('**', '*' + ext), {
|
|
86
87
|
...buildGlobOpts,
|
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url'
|
|
3
3
|
import { resolve, load as wrappedLoad } from 'babel-register-esm'
|
|
4
|
+
import fs from 'fs-extra'
|
|
5
|
+
import { packageJson, projectDir } from '@jcoreio/toolchain/util/findUps.cjs'
|
|
6
|
+
import hasTSSources from '@jcoreio/toolchain/util/hasTSSources.cjs'
|
|
7
|
+
|
|
8
|
+
const projectDirPrefix = pathToFileURL(projectDir) + '/'
|
|
4
9
|
|
|
5
10
|
export { resolve }
|
|
6
11
|
|
|
7
12
|
export async function load(url, context, nextLoad) {
|
|
13
|
+
if (!url.startsWith('file:') || url.includes('/node_modules/')) {
|
|
14
|
+
return await nextLoad(url, context)
|
|
15
|
+
}
|
|
16
|
+
const file = fileURLToPath(url)
|
|
8
17
|
// some versions of node support --experimental-default-type, but it was removed in Node 23.
|
|
9
18
|
// Since we allow the project to omit `type` in `package.json` and transpile the same source
|
|
10
19
|
// code to CJS and ESM, we need to set the module type based upon the mode the toolchain is
|
|
11
20
|
// running in here for Node >=23.
|
|
12
|
-
if (context.format == null &&
|
|
13
|
-
const extension = path.extname(
|
|
21
|
+
if (context.format == null && url.startsWith(projectDirPrefix)) {
|
|
22
|
+
const extension = path.extname(file)
|
|
14
23
|
if (
|
|
15
|
-
extension === '.js' ||
|
|
16
|
-
extension === '.jsx' ||
|
|
17
24
|
extension === '.ts' ||
|
|
18
|
-
extension === '.tsx'
|
|
25
|
+
extension === '.tsx' ||
|
|
26
|
+
(!(await hasTSSources()) && (extension === '.js' || extension === '.jsx'))
|
|
19
27
|
) {
|
|
20
28
|
return await wrappedLoad(
|
|
21
29
|
url,
|
|
22
30
|
{
|
|
23
31
|
...context,
|
|
24
|
-
format:
|
|
32
|
+
format:
|
|
33
|
+
(
|
|
34
|
+
extension.startsWith('.js') &&
|
|
35
|
+
packageJson.type !== 'module' &&
|
|
36
|
+
(await fs.pathExists(file)) &&
|
|
37
|
+
!(await hasTSSources())
|
|
38
|
+
) ?
|
|
39
|
+
'commonjs'
|
|
40
|
+
: process.env.JCOREIO_TOOLCHAIN_ESM ? 'module'
|
|
41
|
+
: 'commonjs',
|
|
25
42
|
},
|
|
26
43
|
nextLoad
|
|
27
44
|
)
|