@jcoreio/toolchain 5.4.5 → 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
|
@@ -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
|
@@ -13,7 +13,16 @@ let dir = process
|
|
|
13
13
|
.cwd()
|
|
14
14
|
.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
|
|
15
15
|
|
|
16
|
-
|
|
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, {
|
|
17
26
|
cwd: dir,
|
|
18
27
|
type: 'file',
|
|
19
28
|
})
|
|
@@ -23,7 +32,7 @@ if (!packageJsonFile) {
|
|
|
23
32
|
// When the cwd is not within a project dir, see if this file is within a project dir
|
|
24
33
|
dir = __dirname.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
|
|
25
34
|
|
|
26
|
-
packageJsonFile = findUp.sync(
|
|
35
|
+
packageJsonFile = findUp.sync(matchNamedPackageJson, {
|
|
27
36
|
cwd: dir,
|
|
28
37
|
type: 'file',
|
|
29
38
|
})
|
|
@@ -44,8 +53,15 @@ if (!packageJsonFile) {
|
|
|
44
53
|
let packageJson = fs.readJsonSync(packageJsonFile)
|
|
45
54
|
debug({ step: 2, 'packageJson.name': packageJson.name })
|
|
46
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
|
+
|
|
47
63
|
if (packageJson.name === name) {
|
|
48
|
-
packageJsonFile = findUp.sync(
|
|
64
|
+
packageJsonFile = findUp.sync(matchNamedPackageJson, {
|
|
49
65
|
cwd: Path.dirname(Path.dirname(packageJsonFile)),
|
|
50
66
|
type: 'file',
|
|
51
67
|
})
|
package/util/getModules.cjs
CHANGED