@sanity/pkg-utils 6.13.4 → 7.0.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/dist/_chunks-cjs/build.cjs +6 -41
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +3 -3
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +22 -59
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +20 -86
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/logger.cjs +2 -2
- package/dist/_chunks-cjs/logger.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +5 -21
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -23
- package/dist/index.d.ts +4 -23
- package/dist/index.js +49 -201
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/node/build.ts +1 -2
- package/src/node/check.ts +1 -2
- package/src/node/core/config/types.ts +3 -4
- package/src/node/core/pkg/loadPkgWithReporting.ts +2 -10
- package/src/node/core/pkg/parseExports.ts +7 -46
- package/src/node/core/pkg/pkgExt.ts +1 -4
- package/src/node/core/pkg/validateExports.ts +0 -1
- package/src/node/resolveBuildContext.ts +0 -1
- package/src/node/resolveBuildTasks.ts +4 -62
- package/src/node/resolveWatchTasks.ts +1 -23
- package/src/node/tasks/dts/createApiExtractorConfig.ts +12 -32
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +5 -1
- package/src/node/tasks/dts/getTargetPaths.ts +0 -2
- package/src/node/tasks/index.ts +1 -2
- package/src/node/tasks/rollup/index.ts +0 -1
- package/src/node/tasks/rollup/resolveRollupConfig.ts +5 -10
- package/src/node/tasks/types.ts +1 -12
- package/src/node/watch.ts +1 -2
- package/src/node/tasks/rollup/rollupLegacyTask.ts +0 -145
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@babel/core": "^7.26.0",
|
|
71
71
|
"@babel/preset-typescript": "^7.26.0",
|
|
72
72
|
"@babel/types": "^7.26.3",
|
|
73
|
-
"@microsoft/api-extractor": "7.
|
|
73
|
+
"@microsoft/api-extractor": "7.49.0",
|
|
74
74
|
"@microsoft/tsdoc-config": "0.17.1",
|
|
75
75
|
"@optimize-lodash/rollup-plugin": "5.0.0",
|
|
76
76
|
"@rollup/plugin-alias": "^5.1.1",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"ts-node": "^10.9.2",
|
|
145
145
|
"typescript": "5.7.3",
|
|
146
146
|
"vitest": "^2.1.8",
|
|
147
|
-
"@sanity/pkg-utils": "
|
|
147
|
+
"@sanity/pkg-utils": "7.0.0"
|
|
148
148
|
},
|
|
149
149
|
"peerDependencies": {
|
|
150
150
|
"babel-plugin-react-compiler": "*",
|
package/src/node/build.ts
CHANGED
|
@@ -46,8 +46,7 @@ export async function build(options: {
|
|
|
46
46
|
|
|
47
47
|
const config = await loadConfig({cwd})
|
|
48
48
|
|
|
49
|
-
const
|
|
50
|
-
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
49
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
51
50
|
|
|
52
51
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
53
52
|
|
package/src/node/check.ts
CHANGED
|
@@ -19,8 +19,7 @@ export async function check(options: {
|
|
|
19
19
|
const logger = createLogger()
|
|
20
20
|
|
|
21
21
|
const config = await loadConfig({cwd})
|
|
22
|
-
const
|
|
23
|
-
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
22
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
24
23
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
25
24
|
const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|
|
26
25
|
|
|
@@ -221,7 +221,7 @@ export interface PkgConfigOptions {
|
|
|
221
221
|
/**
|
|
222
222
|
* @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
|
|
223
223
|
*/
|
|
224
|
-
'ae-forgotten-export'?:
|
|
224
|
+
'ae-forgotten-export'?: never
|
|
225
225
|
'ae-incompatible-release-tags'?: PkgRuleLevel
|
|
226
226
|
'ae-internal-missing-underscore'?: PkgRuleLevel
|
|
227
227
|
'ae-missing-release-tag'?: PkgRuleLevel
|
|
@@ -255,10 +255,9 @@ export interface PkgConfigOptions {
|
|
|
255
255
|
*/
|
|
256
256
|
jsxImportSource?: string
|
|
257
257
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @deprecated - will be removed in the next major version
|
|
258
|
+
* @deprecated no longer supported
|
|
260
259
|
*/
|
|
261
|
-
legacyExports?:
|
|
260
|
+
legacyExports?: never
|
|
262
261
|
minify?: boolean
|
|
263
262
|
/** @alpha */
|
|
264
263
|
rollup?: {
|
|
@@ -11,23 +11,15 @@ export async function loadPkgWithReporting(options: {
|
|
|
11
11
|
cwd: string
|
|
12
12
|
logger: Logger
|
|
13
13
|
strict: boolean
|
|
14
|
-
legacyExports: boolean
|
|
15
14
|
}): Promise<PackageJSON> {
|
|
16
|
-
const {cwd, logger, strict
|
|
15
|
+
const {cwd, logger, strict} = options
|
|
17
16
|
|
|
18
17
|
try {
|
|
19
18
|
const pkg = await loadPkg({cwd})
|
|
20
19
|
let shouldError = false
|
|
21
20
|
|
|
22
21
|
if (strict) {
|
|
23
|
-
if (
|
|
24
|
-
shouldError = true
|
|
25
|
-
logger.error(
|
|
26
|
-
`the \`type\` field in \`./package.json\` shouldn't be "commonjs" when \`legacyExports\` is set to true)`,
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!legacyExports && !pkg.type) {
|
|
22
|
+
if (!pkg.type) {
|
|
31
23
|
shouldError = true
|
|
32
24
|
logger.error(
|
|
33
25
|
`the \`type\` field in \`./package.json\` must be either "module" or "commonjs")`,
|
|
@@ -3,7 +3,7 @@ import {resolve as resolvePath} from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import type {Logger} from '../../logger'
|
|
5
5
|
import type {InferredStrictOptions} from '../../strict'
|
|
6
|
-
import {defaultEnding, fileEnding
|
|
6
|
+
import {defaultEnding, fileEnding} from '../../tasks/dts/getTargetPaths'
|
|
7
7
|
import type {PkgExport} from '../config'
|
|
8
8
|
import {isRecord} from '../isRecord'
|
|
9
9
|
import {pkgExtMap} from './pkgExt'
|
|
@@ -16,10 +16,9 @@ export function parseExports(options: {
|
|
|
16
16
|
pkg: PackageJSON
|
|
17
17
|
strict: boolean
|
|
18
18
|
strictOptions: InferredStrictOptions
|
|
19
|
-
legacyExports: boolean
|
|
20
19
|
logger: Logger
|
|
21
20
|
}): (PkgExport & {_path: string})[] {
|
|
22
|
-
const {cwd, pkg, strict, strictOptions,
|
|
21
|
+
const {cwd, pkg, strict, strictOptions, logger} = options
|
|
23
22
|
const type = pkg.type || 'commonjs'
|
|
24
23
|
const errors: string[] = []
|
|
25
24
|
|
|
@@ -72,20 +71,12 @@ export function parseExports(options: {
|
|
|
72
71
|
browserConditions.push(
|
|
73
72
|
` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`,
|
|
74
73
|
)
|
|
75
|
-
} else if (legacyExports) {
|
|
76
|
-
const browserImport = pkg.main.replace(fileEnding, `.browser${extMap.esm}`)
|
|
77
|
-
|
|
78
|
-
browserConditions.push(` "import": ${JSON.stringify(browserImport)}`)
|
|
79
74
|
}
|
|
80
75
|
|
|
81
76
|
if (pkg.browser?.[pkg.main]) {
|
|
82
77
|
browserConditions.push(
|
|
83
78
|
` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`,
|
|
84
79
|
)
|
|
85
|
-
} else if (legacyExports) {
|
|
86
|
-
const browserRequire = pkg.main.replace(fileEnding, `.browser${extMap.commonjs}`)
|
|
87
|
-
|
|
88
|
-
browserConditions.push(` "require": ${JSON.stringify(browserRequire)}`)
|
|
89
80
|
}
|
|
90
81
|
|
|
91
82
|
if (browserConditions.length) {
|
|
@@ -106,11 +97,8 @@ export function parseExports(options: {
|
|
|
106
97
|
` "source": ${JSON.stringify(pkg.source)},`,
|
|
107
98
|
// If browser conditions are detected then add them to the suggestion
|
|
108
99
|
...(maybeBrowserCondition.length > 0 ? maybeBrowserCondition : []),
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
` "import": ${JSON.stringify(importExport)},`,
|
|
112
|
-
(legacyExports || type === 'module') &&
|
|
113
|
-
` "require": ${JSON.stringify(requireExport)},`,
|
|
100
|
+
type === 'commonjs' && ` "import": ${JSON.stringify(importExport)},`,
|
|
101
|
+
type === 'module' && ` "require": ${JSON.stringify(requireExport)},`,
|
|
114
102
|
` "default": ${JSON.stringify(defaultExport)}`,
|
|
115
103
|
` },`,
|
|
116
104
|
` "./package.json": "./package.json"`,
|
|
@@ -142,8 +130,6 @@ export function parseExports(options: {
|
|
|
142
130
|
|
|
143
131
|
const _exports: (PkgExport & {_path: string})[] = []
|
|
144
132
|
|
|
145
|
-
// @TODO validate typesVersions when legacyExports is true
|
|
146
|
-
|
|
147
133
|
if (strict && strictOptions.noPackageJsonTypings !== 'off' && 'typings' in pkg) {
|
|
148
134
|
report(strictOptions.noPackageJsonTypings, 'package.json: `typings` should be `types`')
|
|
149
135
|
}
|
|
@@ -202,18 +188,6 @@ export function parseExports(options: {
|
|
|
202
188
|
if (fallback) {
|
|
203
189
|
exp.default = fallback
|
|
204
190
|
}
|
|
205
|
-
|
|
206
|
-
if (legacyExports) {
|
|
207
|
-
if (fallback) {
|
|
208
|
-
errors.push(
|
|
209
|
-
`package.json - \`exports["${exp._path}"].default\` should be set to "${fallback}" when "legacyExports" is true`,
|
|
210
|
-
)
|
|
211
|
-
} else {
|
|
212
|
-
errors.push(
|
|
213
|
-
`package.json - \`exports["${exp._path}"].default\` should be specified when "legacyExports" is true`,
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
191
|
}
|
|
218
192
|
|
|
219
193
|
// Infer the `require` condition based on the `type` and other conditions
|
|
@@ -233,23 +207,10 @@ export function parseExports(options: {
|
|
|
233
207
|
)
|
|
234
208
|
}
|
|
235
209
|
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
legacyEnding,
|
|
210
|
+
if (exportEntry.import && pkg.module && exportEntry.import !== pkg.module) {
|
|
211
|
+
errors.push(
|
|
212
|
+
'package.json: mismatch between "module" and "exports.import" These must be equal.',
|
|
240
213
|
)
|
|
241
|
-
|
|
242
|
-
if (indexLegacyExport !== pkg.module) {
|
|
243
|
-
errors.push(
|
|
244
|
-
`package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`,
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
if (exportEntry.import && pkg.module && exportEntry.import !== pkg.module) {
|
|
249
|
-
errors.push(
|
|
250
|
-
'package.json: mismatch between "module" and "exports.import" These must be equal.',
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
214
|
}
|
|
254
215
|
}
|
|
255
216
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {cjsEnding, defaultEnding,
|
|
1
|
+
import {cjsEnding, defaultEnding, mjsEnding} from '../../tasks/dts/getTargetPaths'
|
|
2
2
|
|
|
3
3
|
/** @internal */
|
|
4
4
|
export interface PkgExtMap {
|
|
5
5
|
commonjs: {commonjs: string; esm: string}
|
|
6
6
|
module: {commonjs: string; esm: string}
|
|
7
|
-
legacy: string
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
/** @internal */
|
|
@@ -20,6 +19,4 @@ export const pkgExtMap = {
|
|
|
20
19
|
commonjs: cjsEnding,
|
|
21
20
|
esm: defaultEnding,
|
|
22
21
|
},
|
|
23
|
-
// package.config.legacyExports: true
|
|
24
|
-
legacy: legacyEnding,
|
|
25
22
|
} satisfies PkgExtMap
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
1
|
import path from 'node:path'
|
|
3
2
|
|
|
4
3
|
import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
|
|
5
|
-
import type {BuildTask, DtsTask,
|
|
6
|
-
import {
|
|
4
|
+
import type {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'
|
|
5
|
+
import {getTargetPaths} from './tasks/dts/getTargetPaths'
|
|
7
6
|
|
|
8
7
|
/** @internal */
|
|
9
8
|
export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
10
|
-
const {config,
|
|
9
|
+
const {config, pkg, target} = ctx
|
|
11
10
|
|
|
12
11
|
const bundles = config?.bundles || []
|
|
13
12
|
|
|
@@ -23,7 +22,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
const rollupTasks: Record<string, RollupTask> = {}
|
|
26
|
-
const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}
|
|
27
25
|
|
|
28
26
|
function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
29
27
|
const buildId = `${format}:${runtime}`
|
|
@@ -42,24 +40,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
function addRollupLegacyTaskEntry(runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
46
|
-
const buildId = `esm:${runtime}`
|
|
47
|
-
|
|
48
|
-
if (rollupLegacyTasks[buildId]) {
|
|
49
|
-
rollupLegacyTasks[buildId].entries.push(entry)
|
|
50
|
-
} else {
|
|
51
|
-
rollupLegacyTasks[buildId] = {
|
|
52
|
-
type: 'build:legacy',
|
|
53
|
-
buildId,
|
|
54
|
-
entries: [entry],
|
|
55
|
-
runtime,
|
|
56
|
-
format: 'esm',
|
|
57
|
-
// @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
|
|
58
|
-
target: target[runtime],
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
43
|
// Parse `dts` tasks
|
|
64
44
|
for (const exp of exports) {
|
|
65
45
|
const importId = path.join(pkg.name, exp._path)
|
|
@@ -168,25 +148,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
168
148
|
})
|
|
169
149
|
}
|
|
170
150
|
|
|
171
|
-
// Create rollup bundles that legacy export files will re-export
|
|
172
|
-
if (config?.legacyExports) {
|
|
173
|
-
for (const exp of exports) {
|
|
174
|
-
const runtime = exp.browser?.import ? 'browser' : ctx.runtime
|
|
175
|
-
const output = exp.browser?.import || exp.import
|
|
176
|
-
|
|
177
|
-
if (!output) continue
|
|
178
|
-
|
|
179
|
-
// Change the suffix to what the legacy exports will use
|
|
180
|
-
const legacyOutput = output.replace(fileEnding, legacyEnding)
|
|
181
|
-
|
|
182
|
-
addRollupLegacyTaskEntry(runtime, {
|
|
183
|
-
path: exp._path,
|
|
184
|
-
source: exp.browser?.source || exp.source,
|
|
185
|
-
output: legacyOutput,
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
151
|
for (const bundle of bundles) {
|
|
191
152
|
const idx = bundles.indexOf(bundle)
|
|
192
153
|
|
|
@@ -207,26 +168,7 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
207
168
|
}
|
|
208
169
|
}
|
|
209
170
|
|
|
210
|
-
tasks.push(...Object.values(rollupTasks)
|
|
211
|
-
|
|
212
|
-
// Write legacy exports files
|
|
213
|
-
if (config?.legacyExports) {
|
|
214
|
-
for (const exp of exports) {
|
|
215
|
-
if (exp._exported && exp._path !== '.') {
|
|
216
|
-
const output = (exp.browser?.import || exp.import || '').replace(fileEnding, legacyEnding)
|
|
217
|
-
const relativeTargetPath = output.replace(/\.[^/.]+$/, '')
|
|
218
|
-
|
|
219
|
-
if (relativeTargetPath) {
|
|
220
|
-
fs.writeFileSync(
|
|
221
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
222
|
-
['// AUTO-GENERATED – DO NOT EDIT', `export * from '${relativeTargetPath}'`, ''].join(
|
|
223
|
-
'\n',
|
|
224
|
-
),
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
171
|
+
tasks.push(...Object.values(rollupTasks))
|
|
230
172
|
}
|
|
231
173
|
|
|
232
174
|
return tasks
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
1
|
import path from 'node:path'
|
|
3
2
|
|
|
4
3
|
import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
|
|
@@ -7,7 +6,7 @@ import {getTargetPaths} from './tasks/dts/getTargetPaths'
|
|
|
7
6
|
|
|
8
7
|
/** @internal */
|
|
9
8
|
export function resolveWatchTasks(ctx: BuildContext): WatchTask[] {
|
|
10
|
-
const {
|
|
9
|
+
const {pkg, target} = ctx
|
|
11
10
|
const tasks: WatchTask[] = []
|
|
12
11
|
|
|
13
12
|
const exports = Object.entries(ctx.exports || {}).map(
|
|
@@ -128,26 +127,5 @@ export function resolveWatchTasks(ctx: BuildContext): WatchTask[] {
|
|
|
128
127
|
|
|
129
128
|
tasks.push(...Object.values(rollupTasks))
|
|
130
129
|
|
|
131
|
-
// Write legacy exports files
|
|
132
|
-
if (config?.legacyExports) {
|
|
133
|
-
for (const exp of exports) {
|
|
134
|
-
if (exp._exported && exp._path !== '.') {
|
|
135
|
-
const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(
|
|
136
|
-
/\.[^/.]+$/,
|
|
137
|
-
'',
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
if (relativeTargetPath) {
|
|
141
|
-
fs.writeFileSync(
|
|
142
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
143
|
-
[`// AUTO-GENERATED – DO NOT EDIT`, `export * from '${relativeTargetPath}'`, ``].join(
|
|
144
|
-
'\n',
|
|
145
|
-
),
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
130
|
return tasks
|
|
153
131
|
}
|
|
@@ -26,34 +26,6 @@ export function createApiExtractorConfig(options: {
|
|
|
26
26
|
tsconfigPath,
|
|
27
27
|
} = options
|
|
28
28
|
|
|
29
|
-
// When the module is 'preserve' it's necessary to override the tsconfig file as api-extractor doesn't handle it out of the box
|
|
30
|
-
const workaroundModulePreserve = tsconfig.options.module === ts.ModuleKind.Preserve
|
|
31
|
-
// If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
|
|
32
|
-
const workaroundPaths = !!tsconfig.options.paths
|
|
33
|
-
|
|
34
|
-
const overrideTsconfig = {
|
|
35
|
-
extends: tsconfigPath,
|
|
36
|
-
compilerOptions: {},
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (workaroundModulePreserve) {
|
|
40
|
-
Object.assign(overrideTsconfig.compilerOptions, {
|
|
41
|
-
// Set the equivalent options to `module: 'Preserve'`
|
|
42
|
-
// https://github.com/microsoft/TypeScript/pull/56785/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.symbols&file-filters%5B%5D=.ts&file-filters%5B%5D=.types&show-viewed-files=true#diff-31d3c12bafea26bc9e8c8a77920c41af0c593206442add70c45a06c063767445
|
|
43
|
-
module: 'ESNext',
|
|
44
|
-
moduleResolution: 'Bundler',
|
|
45
|
-
esModuleInterop: true,
|
|
46
|
-
resolveJsonModule: true,
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (workaroundPaths) {
|
|
51
|
-
Object.assign(overrideTsconfig.compilerOptions, {
|
|
52
|
-
// An empty object replaces whatever is in the original tsconfig file
|
|
53
|
-
paths: {},
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
29
|
return {
|
|
58
30
|
apiReport: {
|
|
59
31
|
enabled: false,
|
|
@@ -61,10 +33,18 @@ export function createApiExtractorConfig(options: {
|
|
|
61
33
|
},
|
|
62
34
|
bundledPackages,
|
|
63
35
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
// If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
|
|
37
|
+
compiler: tsconfig.options.paths
|
|
38
|
+
? {
|
|
39
|
+
overrideTsconfig: {
|
|
40
|
+
extends: tsconfigPath,
|
|
41
|
+
compilerOptions: {
|
|
42
|
+
// An empty object replaces whatever is in the original tsconfig file
|
|
43
|
+
paths: {},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
: {tsconfigFilePath: tsconfigPath},
|
|
68
48
|
|
|
69
49
|
docModel: {
|
|
70
50
|
enabled: false,
|
|
@@ -38,7 +38,11 @@ export function getExtractMessagesConfig(options: {
|
|
|
38
38
|
},
|
|
39
39
|
|
|
40
40
|
'ae-forgotten-export': {
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* This is hardcoded to `none` as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
|
|
43
|
+
* It's hardcoded to `none` since supported by API Extractor when using `module: 'Preserve'` doesn't support it well since `@microsoft/api-extractor` v7.49.0, which upgraded from TS 5.4 to 5.7 internally
|
|
44
|
+
*/
|
|
45
|
+
logLevel: 'none' as ExtractorLogLevel,
|
|
42
46
|
addToApiReportFile: false,
|
|
43
47
|
},
|
|
44
48
|
|
|
@@ -7,8 +7,6 @@ export const dtsEnding = '.d.ts' as const
|
|
|
7
7
|
/** @internal */
|
|
8
8
|
export const defaultEnding = '.js' as const
|
|
9
9
|
/** @internal */
|
|
10
|
-
export const legacyEnding = `.esm${defaultEnding}` as const
|
|
11
|
-
/** @internal */
|
|
12
10
|
export const mjsEnding = '.mjs' as const
|
|
13
11
|
/** @internal */
|
|
14
12
|
export const cjsEnding = '.cjs' as const
|
package/src/node/tasks/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {dtsTask, dtsWatchTask} from './dts'
|
|
2
|
-
import {
|
|
2
|
+
import {rollupTask, rollupWatchTask} from './rollup'
|
|
3
3
|
import type {BuildTaskHandlers, WatchTaskHandlers} from './types'
|
|
4
4
|
|
|
5
5
|
export * from './dts'
|
|
@@ -10,7 +10,6 @@ export * from './types'
|
|
|
10
10
|
export const buildTaskHandlers: BuildTaskHandlers = {
|
|
11
11
|
'build:dts': dtsTask,
|
|
12
12
|
'build:js': rollupTask,
|
|
13
|
-
'build:legacy': rollupLegacyTask,
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/** @internal */
|
|
@@ -14,7 +14,7 @@ import esbuild from 'rollup-plugin-esbuild'
|
|
|
14
14
|
|
|
15
15
|
import {pkgExtMap as extMap} from '../../../node/core/pkg/pkgExt'
|
|
16
16
|
import {type BuildContext, type PackageJSON, resolveConfigProperty} from '../../core'
|
|
17
|
-
import type {
|
|
17
|
+
import type {RollupTask, RollupWatchTask} from '../types'
|
|
18
18
|
|
|
19
19
|
export interface RollupConfig {
|
|
20
20
|
inputOptions: InputOptions
|
|
@@ -24,12 +24,11 @@ export interface RollupConfig {
|
|
|
24
24
|
/** @internal */
|
|
25
25
|
export function resolveRollupConfig(
|
|
26
26
|
ctx: BuildContext,
|
|
27
|
-
buildTask: RollupTask |
|
|
27
|
+
buildTask: RollupTask | RollupWatchTask,
|
|
28
28
|
): RollupConfig {
|
|
29
29
|
const {format, runtime, target} = buildTask
|
|
30
30
|
const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx
|
|
31
|
-
const
|
|
32
|
-
const outputExt = isLegacyExports ? extMap.legacy : extMap[pkg.type || 'commonjs'][format]
|
|
31
|
+
const outputExt = extMap[pkg.type || 'commonjs'][format]
|
|
33
32
|
const minify = config?.minify ?? false
|
|
34
33
|
const outDir = path.relative(cwd, distPath)
|
|
35
34
|
|
|
@@ -180,13 +179,9 @@ export function resolveRollupConfig(
|
|
|
180
179
|
: resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
|
|
181
180
|
|
|
182
181
|
const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? false
|
|
183
|
-
const chunksFolder =
|
|
184
|
-
? '_legacy'
|
|
185
|
-
: hashChunkFileNames
|
|
186
|
-
? '_chunks'
|
|
187
|
-
: '_chunks-[format]'
|
|
182
|
+
const chunksFolder = hashChunkFileNames ? '_chunks' : '_chunks-[format]'
|
|
188
183
|
const chunkFileNames = `${chunksFolder}/${hashChunkFileNames ? '[name]-[hash]' : '[name]'}${outputExt}`
|
|
189
|
-
const entryFileNames =
|
|
184
|
+
const entryFileNames = `[name]${outputExt}`
|
|
190
185
|
|
|
191
186
|
return {
|
|
192
187
|
inputOptions: {
|
package/src/node/tasks/types.ts
CHANGED
|
@@ -21,16 +21,6 @@ export interface RollupTask {
|
|
|
21
21
|
target: string[]
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/** @internal */
|
|
25
|
-
export interface RollupLegacyTask {
|
|
26
|
-
type: 'build:legacy'
|
|
27
|
-
buildId: string
|
|
28
|
-
entries: RollupTaskEntry[]
|
|
29
|
-
runtime: PkgRuntime
|
|
30
|
-
format: 'esm'
|
|
31
|
-
target: string[]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
/** @internal */
|
|
35
25
|
export interface RollupWatchTask {
|
|
36
26
|
type: 'watch:js'
|
|
@@ -42,7 +32,7 @@ export interface RollupWatchTask {
|
|
|
42
32
|
}
|
|
43
33
|
|
|
44
34
|
/** @internal */
|
|
45
|
-
export type BuildTask = DtsTask | RollupTask
|
|
35
|
+
export type BuildTask = DtsTask | RollupTask
|
|
46
36
|
|
|
47
37
|
/** @internal */
|
|
48
38
|
export type WatchTask = DtsWatchTask | RollupWatchTask
|
|
@@ -59,7 +49,6 @@ export type TaskHandler<Task, Result = void> = {
|
|
|
59
49
|
export interface BuildTaskHandlers {
|
|
60
50
|
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
61
51
|
'build:js': TaskHandler<RollupTask>
|
|
62
|
-
'build:legacy': TaskHandler<RollupLegacyTask>
|
|
63
52
|
}
|
|
64
53
|
|
|
65
54
|
/** @internal */
|
package/src/node/watch.ts
CHANGED
|
@@ -32,8 +32,7 @@ export async function watch(options: {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const config = await loadConfig({cwd})
|
|
35
|
-
const
|
|
36
|
-
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
35
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
37
36
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
38
37
|
|
|
39
38
|
return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|