@sanity/pkg-utils 6.13.3 → 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 -58
- 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 +23 -67
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +10 -133
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/logger.cjs +2 -12
- 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 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -48
- package/dist/index.d.ts +12 -48
- package/dist/index.js +40 -283
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/node/build.ts +1 -2
- package/src/node/check.ts +1 -2
- package/src/node/core/config/types.ts +11 -16
- 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/core/pkg/validatePkg.ts +7 -17
- package/src/node/resolveBuildContext.ts +0 -3
- package/src/node/resolveBuildTasks.ts +4 -108
- package/src/node/resolveWatchTasks.ts +1 -23
- package/src/node/tasks/dts/createApiExtractorConfig.ts +1 -0
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +5 -1
- package/src/node/tasks/dts/getTargetPaths.ts +0 -13
- package/src/node/tasks/index.ts +1 -3
- package/src/node/tasks/rollup/index.ts +0 -2
- package/src/node/tasks/rollup/resolveRollupConfig.ts +7 -15
- package/src/node/tasks/types.ts +1 -22
- package/src/node/watch.ts +1 -2
- package/src/node/tasks/rollup/rollupLegacyTask.ts +0 -145
- package/src/node/tasks/rollup/rollupReactCompilerTask.ts +0 -140
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",
|
|
@@ -126,7 +126,6 @@
|
|
|
126
126
|
"@types/uuid": "^10.0.0",
|
|
127
127
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
128
128
|
"@typescript-eslint/parser": "^7.18.0",
|
|
129
|
-
"babel-plugin-react-compiler": "beta",
|
|
130
129
|
"browserslist-to-esbuild": "2.1.1",
|
|
131
130
|
"commitizen": "^4.3.1",
|
|
132
131
|
"cpx": "^1.5.0",
|
|
@@ -143,9 +142,9 @@
|
|
|
143
142
|
"rollup-plugin-visualizer": "^5.13.1",
|
|
144
143
|
"semver": "^7.6.0",
|
|
145
144
|
"ts-node": "^10.9.2",
|
|
146
|
-
"typescript": "5.7.
|
|
145
|
+
"typescript": "5.7.3",
|
|
147
146
|
"vitest": "^2.1.8",
|
|
148
|
-
"@sanity/pkg-utils": "
|
|
147
|
+
"@sanity/pkg-utils": "7.0.0"
|
|
149
148
|
},
|
|
150
149
|
"peerDependencies": {
|
|
151
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
|
|
|
@@ -16,30 +16,26 @@ export type PkgRuntime = '*' | 'browser' | 'node'
|
|
|
16
16
|
/** @public */
|
|
17
17
|
export interface PkgExport {
|
|
18
18
|
/** @internal */
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
_exported?: boolean
|
|
20
|
+
browser?: {
|
|
21
21
|
source: string
|
|
22
22
|
import?: string
|
|
23
23
|
require?: string
|
|
24
24
|
}
|
|
25
|
-
'react-compiler'?: {
|
|
26
|
-
source?: string
|
|
27
|
-
default: string
|
|
28
|
-
}
|
|
29
25
|
// electron?: {
|
|
30
26
|
// node?: string
|
|
31
27
|
// default?: string
|
|
32
28
|
// }
|
|
33
|
-
|
|
29
|
+
node?: {
|
|
34
30
|
source?: string
|
|
35
31
|
import?: string
|
|
36
32
|
require?: string
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
types?: string
|
|
35
|
+
source: string
|
|
36
|
+
import?: string
|
|
37
|
+
require?: string
|
|
38
|
+
default: string
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/** @public */
|
|
@@ -225,7 +221,7 @@ export interface PkgConfigOptions {
|
|
|
225
221
|
/**
|
|
226
222
|
* @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
|
|
227
223
|
*/
|
|
228
|
-
'ae-forgotten-export'?:
|
|
224
|
+
'ae-forgotten-export'?: never
|
|
229
225
|
'ae-incompatible-release-tags'?: PkgRuleLevel
|
|
230
226
|
'ae-internal-missing-underscore'?: PkgRuleLevel
|
|
231
227
|
'ae-missing-release-tag'?: PkgRuleLevel
|
|
@@ -259,10 +255,9 @@ export interface PkgConfigOptions {
|
|
|
259
255
|
*/
|
|
260
256
|
jsxImportSource?: string
|
|
261
257
|
/**
|
|
262
|
-
*
|
|
263
|
-
* @deprecated - will be removed in the next major version
|
|
258
|
+
* @deprecated no longer supported
|
|
264
259
|
*/
|
|
265
|
-
legacyExports?:
|
|
260
|
+
legacyExports?: never
|
|
266
261
|
minify?: boolean
|
|
267
262
|
/** @alpha */
|
|
268
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
|
|
@@ -22,35 +22,25 @@ const pkgSchema = z.object({
|
|
|
22
22
|
z.custom<`./${string}.json`>((val) => /^\.\/.*\.json$/.test(val as string)),
|
|
23
23
|
z.custom<`./${string}.css`>((val) => /^\.\/.*\.css$/.test(val as string)),
|
|
24
24
|
z.object({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
types: z.optional(z.string()),
|
|
26
|
+
source: z.optional(z.string()),
|
|
27
|
+
browser: z.optional(
|
|
28
28
|
z.object({
|
|
29
29
|
source: z.string(),
|
|
30
30
|
import: z.optional(z.string()),
|
|
31
31
|
require: z.optional(z.string()),
|
|
32
32
|
}),
|
|
33
33
|
),
|
|
34
|
-
|
|
35
|
-
// z.union([
|
|
36
|
-
// @TODO add support for a string shortcut
|
|
37
|
-
// z.string(),
|
|
38
|
-
z.object({
|
|
39
|
-
source: z.optional(z.string()),
|
|
40
|
-
default: z.string(),
|
|
41
|
-
}),
|
|
42
|
-
// ]),
|
|
43
|
-
),
|
|
44
|
-
'node': z.optional(
|
|
34
|
+
node: z.optional(
|
|
45
35
|
z.object({
|
|
46
36
|
source: z.optional(z.string()),
|
|
47
37
|
import: z.optional(z.string()),
|
|
48
38
|
require: z.optional(z.string()),
|
|
49
39
|
}),
|
|
50
40
|
),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
import: z.optional(z.string()),
|
|
42
|
+
require: z.optional(z.string()),
|
|
43
|
+
default: z.string(),
|
|
54
44
|
}),
|
|
55
45
|
z.object({
|
|
56
46
|
types: z.optional(z.string()),
|
|
@@ -96,7 +96,6 @@ export async function resolveBuildContext(options: {
|
|
|
96
96
|
cwd,
|
|
97
97
|
pkg,
|
|
98
98
|
strict,
|
|
99
|
-
legacyExports: config?.legacyExports ?? false,
|
|
100
99
|
strictOptions,
|
|
101
100
|
logger,
|
|
102
101
|
}).reduce<PkgExports>((acc, x) => {
|
|
@@ -139,8 +138,6 @@ export async function resolveBuildContext(options: {
|
|
|
139
138
|
exportEntry.browser?.require,
|
|
140
139
|
exportEntry.node?.source && exportEntry.node.import,
|
|
141
140
|
exportEntry.node?.source && exportEntry.node.require,
|
|
142
|
-
// @TODO implement this
|
|
143
|
-
// exportEntry['react-compiler']?.source && exportEntry['react-compiler']?.default,
|
|
144
141
|
].filter(Boolean) as string[]
|
|
145
142
|
})
|
|
146
143
|
.map((p) => path.resolve(cwd, p))
|
|
@@ -1,20 +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 {
|
|
6
|
-
|
|
7
|
-
DtsTask,
|
|
8
|
-
RollupLegacyTask,
|
|
9
|
-
RollupReactCompilerTask,
|
|
10
|
-
RollupTask,
|
|
11
|
-
RollupTaskEntry,
|
|
12
|
-
} from './tasks'
|
|
13
|
-
import {fileEnding, getTargetPaths, legacyEnding} from './tasks/dts/getTargetPaths'
|
|
4
|
+
import type {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'
|
|
5
|
+
import {getTargetPaths} from './tasks/dts/getTargetPaths'
|
|
14
6
|
|
|
15
7
|
/** @internal */
|
|
16
8
|
export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
17
|
-
const {config,
|
|
9
|
+
const {config, pkg, target} = ctx
|
|
18
10
|
|
|
19
11
|
const bundles = config?.bundles || []
|
|
20
12
|
|
|
@@ -30,14 +22,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
const rollupTasks: Record<string, RollupTask> = {}
|
|
33
|
-
const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}
|
|
34
|
-
const rollupReactCompilerTask: RollupReactCompilerTask = {
|
|
35
|
-
type: 'build:react-compiler',
|
|
36
|
-
runtime: 'browser',
|
|
37
|
-
format: 'esm',
|
|
38
|
-
entries: [],
|
|
39
|
-
target: target.browser,
|
|
40
|
-
}
|
|
41
25
|
|
|
42
26
|
function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
43
27
|
const buildId = `${format}:${runtime}`
|
|
@@ -56,28 +40,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
56
40
|
}
|
|
57
41
|
}
|
|
58
42
|
|
|
59
|
-
function addRollupLegacyTaskEntry(runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
60
|
-
const buildId = `esm:${runtime}`
|
|
61
|
-
|
|
62
|
-
if (rollupLegacyTasks[buildId]) {
|
|
63
|
-
rollupLegacyTasks[buildId].entries.push(entry)
|
|
64
|
-
} else {
|
|
65
|
-
rollupLegacyTasks[buildId] = {
|
|
66
|
-
type: 'build:legacy',
|
|
67
|
-
buildId,
|
|
68
|
-
entries: [entry],
|
|
69
|
-
runtime,
|
|
70
|
-
format: 'esm',
|
|
71
|
-
// @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
|
|
72
|
-
target: target[runtime],
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function addRollupReactCompilerTaskEntry(entry: RollupTaskEntry) {
|
|
78
|
-
rollupReactCompilerTask.entries.push(entry)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
43
|
// Parse `dts` tasks
|
|
82
44
|
for (const exp of exports) {
|
|
83
45
|
const importId = path.join(pkg.name, exp._path)
|
|
@@ -108,16 +70,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
108
70
|
targetPaths: getTargetPaths(pkg.type, exp.node),
|
|
109
71
|
})
|
|
110
72
|
}
|
|
111
|
-
|
|
112
|
-
// @TODO implement this
|
|
113
|
-
// if (exp['react-compiler']?.source?.endsWith('.ts')) {
|
|
114
|
-
// dtsTask.entries.push({
|
|
115
|
-
// importId,
|
|
116
|
-
// exportPath: exp._path,
|
|
117
|
-
// sourcePath: exp['react-compiler'].source,
|
|
118
|
-
// targetPaths: getTargetPaths(pkg.type, exp['react-compiler']),
|
|
119
|
-
// })
|
|
120
|
-
// }
|
|
121
73
|
}
|
|
122
74
|
|
|
123
75
|
// Handle dts tasks for bundles
|
|
@@ -196,43 +148,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
196
148
|
})
|
|
197
149
|
}
|
|
198
150
|
|
|
199
|
-
// Parse rollup:react-compiler tasks
|
|
200
|
-
for (const exp of exports) {
|
|
201
|
-
const output = exp['react-compiler']?.default
|
|
202
|
-
|
|
203
|
-
if (!output) continue
|
|
204
|
-
|
|
205
|
-
addRollupReactCompilerTaskEntry({
|
|
206
|
-
path: exp._path,
|
|
207
|
-
source: exp['react-compiler']?.source || exp.source,
|
|
208
|
-
output,
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Add react-compiler task
|
|
213
|
-
if (rollupReactCompilerTask.entries.length) {
|
|
214
|
-
tasks.push(rollupReactCompilerTask)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Create rollup bundles that legacy export files will re-export
|
|
218
|
-
if (config?.legacyExports) {
|
|
219
|
-
for (const exp of exports) {
|
|
220
|
-
const runtime = exp.browser?.import ? 'browser' : ctx.runtime
|
|
221
|
-
const output = exp.browser?.import || exp.import
|
|
222
|
-
|
|
223
|
-
if (!output) continue
|
|
224
|
-
|
|
225
|
-
// Change the suffix to what the legacy exports will use
|
|
226
|
-
const legacyOutput = output.replace(fileEnding, legacyEnding)
|
|
227
|
-
|
|
228
|
-
addRollupLegacyTaskEntry(runtime, {
|
|
229
|
-
path: exp._path,
|
|
230
|
-
source: exp.browser?.source || exp.source,
|
|
231
|
-
output: legacyOutput,
|
|
232
|
-
})
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
151
|
for (const bundle of bundles) {
|
|
237
152
|
const idx = bundles.indexOf(bundle)
|
|
238
153
|
|
|
@@ -253,26 +168,7 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
253
168
|
}
|
|
254
169
|
}
|
|
255
170
|
|
|
256
|
-
tasks.push(...Object.values(rollupTasks)
|
|
257
|
-
|
|
258
|
-
// Write legacy exports files
|
|
259
|
-
if (config?.legacyExports) {
|
|
260
|
-
for (const exp of exports) {
|
|
261
|
-
if (exp._exported && exp._path !== '.') {
|
|
262
|
-
const output = (exp.browser?.import || exp.import || '').replace(fileEnding, legacyEnding)
|
|
263
|
-
const relativeTargetPath = output.replace(/\.[^/.]+$/, '')
|
|
264
|
-
|
|
265
|
-
if (relativeTargetPath) {
|
|
266
|
-
fs.writeFileSync(
|
|
267
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
268
|
-
['// AUTO-GENERATED – DO NOT EDIT', `export * from '${relativeTargetPath}'`, ''].join(
|
|
269
|
-
'\n',
|
|
270
|
-
),
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
171
|
+
tasks.push(...Object.values(rollupTasks))
|
|
276
172
|
}
|
|
277
173
|
|
|
278
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
|
}
|
|
@@ -32,6 +32,7 @@ export function createApiExtractorConfig(options: {
|
|
|
32
32
|
reportFileName: '<unscopedPackageName>.api.md',
|
|
33
33
|
},
|
|
34
34
|
bundledPackages,
|
|
35
|
+
|
|
35
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`),
|
|
36
37
|
compiler: tsconfig.options.paths
|
|
37
38
|
? {
|
|
@@ -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
|
|
@@ -63,17 +61,6 @@ export function getTargetPaths(
|
|
|
63
61
|
)
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
|
|
67
|
-
if (!expOrBundle['react-compiler']?.source) {
|
|
68
|
-
if (expOrBundle['react-compiler']?.default) {
|
|
69
|
-
set.add(
|
|
70
|
-
expOrBundle['react-compiler'].default.replace(
|
|
71
|
-
fileEnding,
|
|
72
|
-
type === 'module' ? dtsEnding : mtsEnding,
|
|
73
|
-
),
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
return Array.from(set)
|
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,8 +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
|
-
'build:react-compiler': rollupReactCompilerTask,
|
|
15
13
|
}
|
|
16
14
|
|
|
17
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,13 +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 isReactCompiler = buildTask.type === 'build:react-compiler'
|
|
33
|
-
const outputExt = isLegacyExports ? extMap.legacy : extMap[pkg.type || 'commonjs'][format]
|
|
31
|
+
const outputExt = extMap[pkg.type || 'commonjs'][format]
|
|
34
32
|
const minify = config?.minify ?? false
|
|
35
33
|
const outDir = path.relative(cwd, distPath)
|
|
36
34
|
|
|
@@ -97,7 +95,7 @@ export function resolveRollupConfig(
|
|
|
97
95
|
}),
|
|
98
96
|
commonjs(),
|
|
99
97
|
json(),
|
|
100
|
-
(
|
|
98
|
+
(config?.babel?.reactCompiler || config?.babel?.styledComponents) &&
|
|
101
99
|
babel({
|
|
102
100
|
babelrc: false,
|
|
103
101
|
presets: ['@babel/preset-typescript'],
|
|
@@ -121,7 +119,7 @@ export function resolveRollupConfig(
|
|
|
121
119
|
: {}),
|
|
122
120
|
},
|
|
123
121
|
],
|
|
124
|
-
|
|
122
|
+
config?.babel?.reactCompiler && [
|
|
125
123
|
'babel-plugin-react-compiler',
|
|
126
124
|
config?.reactCompilerOptions || {},
|
|
127
125
|
],
|
|
@@ -181,15 +179,9 @@ export function resolveRollupConfig(
|
|
|
181
179
|
: resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
|
|
182
180
|
|
|
183
181
|
const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? false
|
|
184
|
-
const chunksFolder =
|
|
185
|
-
? '_compiled'
|
|
186
|
-
: isLegacyExports
|
|
187
|
-
? '_legacy'
|
|
188
|
-
: hashChunkFileNames
|
|
189
|
-
? '_chunks'
|
|
190
|
-
: '_chunks-[format]'
|
|
182
|
+
const chunksFolder = hashChunkFileNames ? '_chunks' : '_chunks-[format]'
|
|
191
183
|
const chunkFileNames = `${chunksFolder}/${hashChunkFileNames ? '[name]-[hash]' : '[name]'}${outputExt}`
|
|
192
|
-
const entryFileNames =
|
|
184
|
+
const entryFileNames = `[name]${outputExt}`
|
|
193
185
|
|
|
194
186
|
return {
|
|
195
187
|
inputOptions: {
|