@jcoreio/toolchain 5.4.4 → 5.5.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.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "base JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@eslint/js": "^9.23.0",
|
|
23
23
|
"@jcoreio/eslint-plugin-implicit-dependencies": "^1.1.1",
|
|
24
24
|
"chalk": "^4.0.0",
|
|
25
|
+
"debug": "^4.4.0",
|
|
25
26
|
"dedent-js": "^1.0.1",
|
|
26
27
|
"eslint": "^9.17.0",
|
|
27
28
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const semver = require('semver')
|
|
2
|
+
|
|
3
|
+
function migrateExportMap(
|
|
4
|
+
exportMap,
|
|
5
|
+
{ fromVersion = '0.0.0', outputEsm = true } = {}
|
|
6
|
+
) {
|
|
7
|
+
if (
|
|
8
|
+
(semver.lt(fromVersion || '0.0.0', '5.5.0') && exportMap,
|
|
9
|
+
outputEsm !== false)
|
|
10
|
+
) {
|
|
11
|
+
function process(obj) {
|
|
12
|
+
if (typeof obj.types === 'string') {
|
|
13
|
+
obj.types = {
|
|
14
|
+
import: obj.types.replace(/\.d\.ts$/, '.d.mts'),
|
|
15
|
+
default: obj.types,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const key in obj) {
|
|
19
|
+
if (
|
|
20
|
+
key !== 'types' &&
|
|
21
|
+
Object.hasOwnProperty.call(obj, key) &&
|
|
22
|
+
obj[key] != null &&
|
|
23
|
+
typeof obj[key] === 'object'
|
|
24
|
+
) {
|
|
25
|
+
process(obj[key])
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (exportMap != null && typeof exportMap === 'object') {
|
|
30
|
+
process(exportMap)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return exportMap
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = migrateExportMap
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
toolchainConfig: { outputEsm },
|
|
3
|
+
toolchainManaged,
|
|
4
|
+
} = require('../../util/findUps.cjs')
|
|
2
5
|
const { name } = require('../../package.json')
|
|
3
6
|
const getPluginsAsyncFunction = require('../../util/getPluginsAsyncFunction.cjs')
|
|
4
7
|
const fs = require('../../util/projectFs.cjs')
|
|
@@ -11,6 +14,7 @@ const confirmOutputEsm = require('./confirmOutputEsm.cjs')
|
|
|
11
14
|
const confirm = require('../../util/confirm.cjs')
|
|
12
15
|
const unset = require('../../util/unset.cjs')
|
|
13
16
|
const merge = require('../../util/merge.cjs')
|
|
17
|
+
const migrateExportMap = require('./migrateExportMap.cjs')
|
|
14
18
|
|
|
15
19
|
async function migrateProjectPackageJson({ fromVersion }) {
|
|
16
20
|
const packageJson = await fs.readJson('package.json')
|
|
@@ -142,7 +146,10 @@ async function migrateProjectPackageJson({ fromVersion }) {
|
|
|
142
146
|
...(dotStar ?
|
|
143
147
|
{
|
|
144
148
|
'./*': {
|
|
145
|
-
types:
|
|
149
|
+
types: {
|
|
150
|
+
...(outputEsm !== false ? { import: './*.d.mts' } : {}),
|
|
151
|
+
default: './*.d.ts',
|
|
152
|
+
},
|
|
146
153
|
...(outputEsm !== false ? { import: './*.mjs' } : {}),
|
|
147
154
|
default: './*.js',
|
|
148
155
|
},
|
|
@@ -152,6 +159,8 @@ async function migrateProjectPackageJson({ fromVersion }) {
|
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
|
|
162
|
+
migrateExportMap(packageJson.exports, { outputEsm, fromVersion })
|
|
163
|
+
|
|
155
164
|
merge(
|
|
156
165
|
packageJson,
|
|
157
166
|
fromVersion ?
|
package/util/findUps.cjs
CHANGED
|
@@ -6,26 +6,41 @@ const merge = require('./merge.cjs')
|
|
|
6
6
|
const once = require('./once.cjs')
|
|
7
7
|
const { name } = require('../package.json')
|
|
8
8
|
const configSchema = require('./configSchema.cjs')
|
|
9
|
+
const debug = require('debug')('@jcoreio/toolchain:findUps')
|
|
9
10
|
|
|
10
11
|
// First see if the cwd is within a project dir
|
|
11
12
|
let dir = process
|
|
12
13
|
.cwd()
|
|
13
14
|
.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
function matchNamedPackageJson(directory) {
|
|
17
|
+
try {
|
|
18
|
+
const json = fs.readJsonSync(Path.join(directory, 'package.json'))
|
|
19
|
+
if (json.name) return 'package.json'
|
|
20
|
+
} catch {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let packageJsonFile = findUp.sync(matchNamedPackageJson, {
|
|
15
26
|
cwd: dir,
|
|
16
27
|
type: 'file',
|
|
17
28
|
})
|
|
29
|
+
debug({ step: 0, cwd: process.cwd(), dir, packageJsonFile })
|
|
18
30
|
|
|
19
31
|
if (!packageJsonFile) {
|
|
20
32
|
// When the cwd is not within a project dir, see if this file is within a project dir
|
|
21
33
|
dir = __dirname.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
|
|
22
34
|
|
|
23
|
-
packageJsonFile = findUp.sync(
|
|
35
|
+
packageJsonFile = findUp.sync(matchNamedPackageJson, {
|
|
24
36
|
cwd: dir,
|
|
25
37
|
type: 'file',
|
|
26
38
|
})
|
|
27
39
|
}
|
|
40
|
+
debug({ step: 1, dir, packageJsonFile })
|
|
41
|
+
|
|
28
42
|
if (!packageJsonFile) {
|
|
43
|
+
debug(`failed to find project package.json in a parent directory of ${dir}`)
|
|
29
44
|
throw new Error(
|
|
30
45
|
`failed to find project package.json in a parent directory of ${dir}`
|
|
31
46
|
)
|
|
@@ -36,12 +51,26 @@ if (!packageJsonFile) {
|
|
|
36
51
|
// if @jcoreio/toolchains is operating on itself. But if we're invoking the CLI from
|
|
37
52
|
// a working copy of the monorepo from a cwd outside of it, we want to error out
|
|
38
53
|
let packageJson = fs.readJsonSync(packageJsonFile)
|
|
54
|
+
debug({ step: 2, 'packageJson.name': packageJson.name })
|
|
55
|
+
|
|
56
|
+
if (!packageJsonFile) {
|
|
57
|
+
debug(`failed to find project package.json in a parent directory of ${dir}`)
|
|
58
|
+
throw new Error(
|
|
59
|
+
`failed to find project package.json in a parent directory of ${dir}`
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
39
63
|
if (packageJson.name === name) {
|
|
40
|
-
packageJsonFile = findUp.sync(
|
|
64
|
+
packageJsonFile = findUp.sync(matchNamedPackageJson, {
|
|
41
65
|
cwd: Path.dirname(Path.dirname(packageJsonFile)),
|
|
42
66
|
type: 'file',
|
|
43
67
|
})
|
|
44
68
|
packageJson = packageJsonFile ? fs.readJsonSync(packageJsonFile) : undefined
|
|
69
|
+
debug({
|
|
70
|
+
step: 3,
|
|
71
|
+
packageJsonFile,
|
|
72
|
+
'packageJson.name': packageJson.name,
|
|
73
|
+
})
|
|
45
74
|
if (
|
|
46
75
|
// When vscode-prettier is trying to format a file in this monorepo, the
|
|
47
76
|
// cwd may be outside the monorepo, which would make our logic decide
|
|
@@ -54,6 +83,7 @@ if (packageJson.name === name) {
|
|
|
54
83
|
!packageJson ||
|
|
55
84
|
packageJson.name !== '@jcoreio/toolchains'
|
|
56
85
|
) {
|
|
86
|
+
debug(`failed to find project package.json in a parent directory of ${dir}`)
|
|
57
87
|
throw new Error(
|
|
58
88
|
`failed to find project package.json in a parent directory of ${dir}`
|
|
59
89
|
)
|
|
@@ -227,3 +257,5 @@ for (const toolchainPkgJson of Object.values(toolchainPackageJsons)) {
|
|
|
227
257
|
}
|
|
228
258
|
}
|
|
229
259
|
}
|
|
260
|
+
|
|
261
|
+
debug(exports)
|
package/util/getModules.cjs
CHANGED