@sanity/pkg-utils 6.9.3 → 6.9.4-canary.1
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 +19 -2
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +8 -1
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +66 -12
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/init.cjs.map +1 -1
- package/dist/_chunks-cjs/logger.cjs +10 -0
- package/dist/_chunks-cjs/logger.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -16
- package/dist/index.d.ts +104 -16
- package/dist/index.js +103 -15
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/node/core/config/types.ts +104 -15
- package/src/node/core/pkg/validatePkg.ts +17 -7
- package/src/node/resolveBuildContext.ts +2 -0
- package/src/node/resolveBuildTasks.ts +47 -1
- package/src/node/tasks/dts/getTargetPaths.ts +11 -0
- package/src/node/tasks/index.ts +2 -1
- package/src/node/tasks/rollup/index.ts +1 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +12 -18
- package/src/node/tasks/rollup/rollupReactCompilerTask.ts +140 -0
- package/src/node/tasks/types.ts +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -64,12 +64,13 @@ export declare interface BuildFile {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/** @internal */
|
|
67
|
-
export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask
|
|
67
|
+
export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask | RollupReactCompilerTask
|
|
68
68
|
|
|
69
69
|
/** @internal */
|
|
70
70
|
export declare interface BuildTaskHandlers {
|
|
71
71
|
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
72
72
|
'build:js': TaskHandler<RollupTask>
|
|
73
|
+
'build:react-compiler': TaskHandler<RollupReactCompilerTask>
|
|
73
74
|
'build:legacy': TaskHandler<RollupLegacyTask>
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -290,14 +291,15 @@ export declare interface PkgConfigOptions {
|
|
|
290
291
|
babel?: {
|
|
291
292
|
plugins?: PluginItem[] | null | undefined
|
|
292
293
|
/** @alpha */
|
|
293
|
-
reactCompiler?:
|
|
294
|
-
| boolean
|
|
295
|
-
| {
|
|
296
|
-
compilationMode: 'infer' | 'annotation' | 'all'
|
|
297
|
-
panicThreshold: 'all_errors' | 'critical_errors' | 'none'
|
|
298
|
-
sources?: Array<string> | ((filename: string) => boolean) | null
|
|
299
|
-
}
|
|
294
|
+
reactCompiler?: boolean
|
|
300
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Configure the React Compiler.
|
|
298
|
+
* To enable it, either:
|
|
299
|
+
* - set `babel.reactCompiler` to `true`
|
|
300
|
+
* - add a `react-compiler` export condition, before any `browser`, `require` or `import` conditions. After any `react-server` and `node` conditions
|
|
301
|
+
* @alpha */
|
|
302
|
+
reactCompilerOptions?: ReactCompilerOptions
|
|
301
303
|
bundles?: PkgBundle[]
|
|
302
304
|
/** @alpha */
|
|
303
305
|
define?: Record<string, string | number | boolean | undefined | null>
|
|
@@ -399,22 +401,26 @@ export declare type PkgConfigPropertyResolver<T> = (prev: T) => T
|
|
|
399
401
|
/** @public */
|
|
400
402
|
export declare interface PkgExport {
|
|
401
403
|
/** @internal */
|
|
402
|
-
_exported?: boolean
|
|
403
|
-
browser?: {
|
|
404
|
+
'_exported'?: boolean
|
|
405
|
+
'browser'?: {
|
|
404
406
|
source: string
|
|
405
407
|
import?: string
|
|
406
408
|
require?: string
|
|
407
409
|
}
|
|
408
|
-
|
|
410
|
+
'react-compiler'?: {
|
|
411
|
+
source?: string
|
|
412
|
+
default: string
|
|
413
|
+
}
|
|
414
|
+
'node'?: {
|
|
409
415
|
source?: string
|
|
410
416
|
import?: string
|
|
411
417
|
require?: string
|
|
412
418
|
}
|
|
413
|
-
types?: string
|
|
414
|
-
source: string
|
|
415
|
-
import?: string
|
|
416
|
-
require?: string
|
|
417
|
-
default: string
|
|
419
|
+
'types'?: string
|
|
420
|
+
'source': string
|
|
421
|
+
'import'?: string
|
|
422
|
+
'require'?: string
|
|
423
|
+
'default': string
|
|
418
424
|
}
|
|
419
425
|
|
|
420
426
|
/** @public */
|
|
@@ -501,6 +507,76 @@ export declare interface PkgTemplateStringOption<T = string> {
|
|
|
501
507
|
validate?: (v: string) => string | true
|
|
502
508
|
}
|
|
503
509
|
|
|
510
|
+
/**
|
|
511
|
+
* @alpha
|
|
512
|
+
*/
|
|
513
|
+
export declare type ReactCompilerLogger = {
|
|
514
|
+
logEvent: (filename: string | null, event: ReactCompilerLoggerEvent) => void
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* @alpha
|
|
519
|
+
* Represents 'events' that may occur during compilation. Events are only
|
|
520
|
+
* recorded when a logger is set (through the config).
|
|
521
|
+
* These are the different types of events:
|
|
522
|
+
* CompileError:
|
|
523
|
+
* Forget skipped compilation of a function / file due to a known todo,
|
|
524
|
+
* invalid input, or compiler invariant being broken.
|
|
525
|
+
* CompileSuccess:
|
|
526
|
+
* Forget successfully compiled a function.
|
|
527
|
+
* PipelineError:
|
|
528
|
+
* Unexpected errors that occurred during compilation (e.g. failures in
|
|
529
|
+
* babel or other unhandled exceptions).
|
|
530
|
+
*/
|
|
531
|
+
export declare type ReactCompilerLoggerEvent =
|
|
532
|
+
| {
|
|
533
|
+
kind: 'CompileError'
|
|
534
|
+
fnLoc: unknown
|
|
535
|
+
detail: unknown
|
|
536
|
+
}
|
|
537
|
+
| {
|
|
538
|
+
kind: 'CompileDiagnostic'
|
|
539
|
+
fnLoc: unknown
|
|
540
|
+
detail: unknown
|
|
541
|
+
}
|
|
542
|
+
| {
|
|
543
|
+
kind: 'CompileSuccess'
|
|
544
|
+
fnLoc: unknown
|
|
545
|
+
fnName: string | null
|
|
546
|
+
memoSlots: number
|
|
547
|
+
memoBlocks: number
|
|
548
|
+
memoValues: number
|
|
549
|
+
prunedMemoBlocks: number
|
|
550
|
+
prunedMemoValues: number
|
|
551
|
+
}
|
|
552
|
+
| {
|
|
553
|
+
kind: 'PipelineError'
|
|
554
|
+
fnLoc: unknown
|
|
555
|
+
data: string
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Until these types are on npm: https://github.com/facebook/react/blob/2ba462b665bb4691067e67db3cfbffc56959b788/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L34-L120
|
|
560
|
+
* @alpha
|
|
561
|
+
*/
|
|
562
|
+
export declare interface ReactCompilerOptions {
|
|
563
|
+
logger?: ReactCompilerLogger | null
|
|
564
|
+
panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE'
|
|
565
|
+
compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
|
|
566
|
+
runtimeModule?: string | null | undefined
|
|
567
|
+
/**
|
|
568
|
+
* By default React Compiler will skip compilation of code that suppresses the default
|
|
569
|
+
* React ESLint rules, since this is a strong indication that the code may be breaking React rules
|
|
570
|
+
* in some way.
|
|
571
|
+
*
|
|
572
|
+
* Use eslintSuppressionRules to pass a custom set of rule names: any code which suppresses the
|
|
573
|
+
* provided rules will skip compilation. To disable this feature (never bailout of compilation
|
|
574
|
+
* even if the default ESLint is suppressed), pass an empty array.
|
|
575
|
+
*/
|
|
576
|
+
eslintSuppressionRules?: Array<string> | null | undefined
|
|
577
|
+
sources?: Array<string> | ((filename: string) => boolean) | null
|
|
578
|
+
}
|
|
579
|
+
|
|
504
580
|
/** @internal */
|
|
505
581
|
export declare function resolveBuildTasks(ctx: BuildContext): BuildTask[]
|
|
506
582
|
|
|
@@ -525,6 +601,18 @@ export declare const rollupLegacyTask: TaskHandler<RollupLegacyTask>
|
|
|
525
601
|
|
|
526
602
|
export {RollupPlugin}
|
|
527
603
|
|
|
604
|
+
/** @internal */
|
|
605
|
+
export declare interface RollupReactCompilerTask {
|
|
606
|
+
type: 'build:react-compiler'
|
|
607
|
+
entries: RollupTaskEntry[]
|
|
608
|
+
runtime: 'browser'
|
|
609
|
+
format: 'esm'
|
|
610
|
+
target: string[]
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** @internal */
|
|
614
|
+
export declare const rollupReactCompilerTask: TaskHandler<RollupReactCompilerTask>
|
|
615
|
+
|
|
528
616
|
/** @internal */
|
|
529
617
|
export declare interface RollupTask {
|
|
530
618
|
type: 'build:js'
|
package/dist/index.d.ts
CHANGED
|
@@ -64,12 +64,13 @@ export declare interface BuildFile {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/** @internal */
|
|
67
|
-
export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask
|
|
67
|
+
export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask | RollupReactCompilerTask
|
|
68
68
|
|
|
69
69
|
/** @internal */
|
|
70
70
|
export declare interface BuildTaskHandlers {
|
|
71
71
|
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
72
72
|
'build:js': TaskHandler<RollupTask>
|
|
73
|
+
'build:react-compiler': TaskHandler<RollupReactCompilerTask>
|
|
73
74
|
'build:legacy': TaskHandler<RollupLegacyTask>
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -290,14 +291,15 @@ export declare interface PkgConfigOptions {
|
|
|
290
291
|
babel?: {
|
|
291
292
|
plugins?: PluginItem[] | null | undefined
|
|
292
293
|
/** @alpha */
|
|
293
|
-
reactCompiler?:
|
|
294
|
-
| boolean
|
|
295
|
-
| {
|
|
296
|
-
compilationMode: 'infer' | 'annotation' | 'all'
|
|
297
|
-
panicThreshold: 'all_errors' | 'critical_errors' | 'none'
|
|
298
|
-
sources?: Array<string> | ((filename: string) => boolean) | null
|
|
299
|
-
}
|
|
294
|
+
reactCompiler?: boolean
|
|
300
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Configure the React Compiler.
|
|
298
|
+
* To enable it, either:
|
|
299
|
+
* - set `babel.reactCompiler` to `true`
|
|
300
|
+
* - add a `react-compiler` export condition, before any `browser`, `require` or `import` conditions. After any `react-server` and `node` conditions
|
|
301
|
+
* @alpha */
|
|
302
|
+
reactCompilerOptions?: ReactCompilerOptions
|
|
301
303
|
bundles?: PkgBundle[]
|
|
302
304
|
/** @alpha */
|
|
303
305
|
define?: Record<string, string | number | boolean | undefined | null>
|
|
@@ -399,22 +401,26 @@ export declare type PkgConfigPropertyResolver<T> = (prev: T) => T
|
|
|
399
401
|
/** @public */
|
|
400
402
|
export declare interface PkgExport {
|
|
401
403
|
/** @internal */
|
|
402
|
-
_exported?: boolean
|
|
403
|
-
browser?: {
|
|
404
|
+
'_exported'?: boolean
|
|
405
|
+
'browser'?: {
|
|
404
406
|
source: string
|
|
405
407
|
import?: string
|
|
406
408
|
require?: string
|
|
407
409
|
}
|
|
408
|
-
|
|
410
|
+
'react-compiler'?: {
|
|
411
|
+
source?: string
|
|
412
|
+
default: string
|
|
413
|
+
}
|
|
414
|
+
'node'?: {
|
|
409
415
|
source?: string
|
|
410
416
|
import?: string
|
|
411
417
|
require?: string
|
|
412
418
|
}
|
|
413
|
-
types?: string
|
|
414
|
-
source: string
|
|
415
|
-
import?: string
|
|
416
|
-
require?: string
|
|
417
|
-
default: string
|
|
419
|
+
'types'?: string
|
|
420
|
+
'source': string
|
|
421
|
+
'import'?: string
|
|
422
|
+
'require'?: string
|
|
423
|
+
'default': string
|
|
418
424
|
}
|
|
419
425
|
|
|
420
426
|
/** @public */
|
|
@@ -501,6 +507,76 @@ export declare interface PkgTemplateStringOption<T = string> {
|
|
|
501
507
|
validate?: (v: string) => string | true
|
|
502
508
|
}
|
|
503
509
|
|
|
510
|
+
/**
|
|
511
|
+
* @alpha
|
|
512
|
+
*/
|
|
513
|
+
export declare type ReactCompilerLogger = {
|
|
514
|
+
logEvent: (filename: string | null, event: ReactCompilerLoggerEvent) => void
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* @alpha
|
|
519
|
+
* Represents 'events' that may occur during compilation. Events are only
|
|
520
|
+
* recorded when a logger is set (through the config).
|
|
521
|
+
* These are the different types of events:
|
|
522
|
+
* CompileError:
|
|
523
|
+
* Forget skipped compilation of a function / file due to a known todo,
|
|
524
|
+
* invalid input, or compiler invariant being broken.
|
|
525
|
+
* CompileSuccess:
|
|
526
|
+
* Forget successfully compiled a function.
|
|
527
|
+
* PipelineError:
|
|
528
|
+
* Unexpected errors that occurred during compilation (e.g. failures in
|
|
529
|
+
* babel or other unhandled exceptions).
|
|
530
|
+
*/
|
|
531
|
+
export declare type ReactCompilerLoggerEvent =
|
|
532
|
+
| {
|
|
533
|
+
kind: 'CompileError'
|
|
534
|
+
fnLoc: unknown
|
|
535
|
+
detail: unknown
|
|
536
|
+
}
|
|
537
|
+
| {
|
|
538
|
+
kind: 'CompileDiagnostic'
|
|
539
|
+
fnLoc: unknown
|
|
540
|
+
detail: unknown
|
|
541
|
+
}
|
|
542
|
+
| {
|
|
543
|
+
kind: 'CompileSuccess'
|
|
544
|
+
fnLoc: unknown
|
|
545
|
+
fnName: string | null
|
|
546
|
+
memoSlots: number
|
|
547
|
+
memoBlocks: number
|
|
548
|
+
memoValues: number
|
|
549
|
+
prunedMemoBlocks: number
|
|
550
|
+
prunedMemoValues: number
|
|
551
|
+
}
|
|
552
|
+
| {
|
|
553
|
+
kind: 'PipelineError'
|
|
554
|
+
fnLoc: unknown
|
|
555
|
+
data: string
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Until these types are on npm: https://github.com/facebook/react/blob/2ba462b665bb4691067e67db3cfbffc56959b788/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L34-L120
|
|
560
|
+
* @alpha
|
|
561
|
+
*/
|
|
562
|
+
export declare interface ReactCompilerOptions {
|
|
563
|
+
logger?: ReactCompilerLogger | null
|
|
564
|
+
panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE'
|
|
565
|
+
compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
|
|
566
|
+
runtimeModule?: string | null | undefined
|
|
567
|
+
/**
|
|
568
|
+
* By default React Compiler will skip compilation of code that suppresses the default
|
|
569
|
+
* React ESLint rules, since this is a strong indication that the code may be breaking React rules
|
|
570
|
+
* in some way.
|
|
571
|
+
*
|
|
572
|
+
* Use eslintSuppressionRules to pass a custom set of rule names: any code which suppresses the
|
|
573
|
+
* provided rules will skip compilation. To disable this feature (never bailout of compilation
|
|
574
|
+
* even if the default ESLint is suppressed), pass an empty array.
|
|
575
|
+
*/
|
|
576
|
+
eslintSuppressionRules?: Array<string> | null | undefined
|
|
577
|
+
sources?: Array<string> | ((filename: string) => boolean) | null
|
|
578
|
+
}
|
|
579
|
+
|
|
504
580
|
/** @internal */
|
|
505
581
|
export declare function resolveBuildTasks(ctx: BuildContext): BuildTask[]
|
|
506
582
|
|
|
@@ -525,6 +601,18 @@ export declare const rollupLegacyTask: TaskHandler<RollupLegacyTask>
|
|
|
525
601
|
|
|
526
602
|
export {RollupPlugin}
|
|
527
603
|
|
|
604
|
+
/** @internal */
|
|
605
|
+
export declare interface RollupReactCompilerTask {
|
|
606
|
+
type: 'build:react-compiler'
|
|
607
|
+
entries: RollupTaskEntry[]
|
|
608
|
+
runtime: 'browser'
|
|
609
|
+
format: 'esm'
|
|
610
|
+
target: string[]
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** @internal */
|
|
614
|
+
export declare const rollupReactCompilerTask: TaskHandler<RollupReactCompilerTask>
|
|
615
|
+
|
|
528
616
|
/** @internal */
|
|
529
617
|
export declare interface RollupTask {
|
|
530
618
|
type: 'build:js'
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,16 @@ const pkgSchema = z.object({
|
|
|
111
111
|
require: z.optional(z.string())
|
|
112
112
|
})
|
|
113
113
|
),
|
|
114
|
+
"react-compiler": z.optional(
|
|
115
|
+
// z.union([
|
|
116
|
+
// @TODO add support for a string shortcut
|
|
117
|
+
// z.string(),
|
|
118
|
+
z.object({
|
|
119
|
+
source: z.optional(z.string()),
|
|
120
|
+
default: z.string()
|
|
121
|
+
})
|
|
122
|
+
// ]),
|
|
123
|
+
),
|
|
114
124
|
node: z.optional(
|
|
115
125
|
z.object({
|
|
116
126
|
source: z.optional(z.string()),
|
|
@@ -237,7 +247,12 @@ function getTargetPaths(_type, expOrBundle) {
|
|
|
237
247
|
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
238
248
|
), expOrBundle.node?.require && set.add(
|
|
239
249
|
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
240
|
-
))
|
|
250
|
+
)), expOrBundle["react-compiler"]?.source || expOrBundle["react-compiler"]?.default && set.add(
|
|
251
|
+
expOrBundle["react-compiler"].default.replace(
|
|
252
|
+
fileEnding,
|
|
253
|
+
type === "module" ? dtsEnding : mtsEnding
|
|
254
|
+
)
|
|
255
|
+
)), Array.from(set);
|
|
241
256
|
}
|
|
242
257
|
function isPkgExport$1(exp) {
|
|
243
258
|
return exp?.browser || exp?.node || exp?.default;
|
|
@@ -596,6 +611,8 @@ async function resolveBuildContext(options) {
|
|
|
596
611
|
exportEntry.browser?.require,
|
|
597
612
|
exportEntry.node?.source && exportEntry.node.import,
|
|
598
613
|
exportEntry.node?.source && exportEntry.node.require
|
|
614
|
+
// @TODO implement this
|
|
615
|
+
// exportEntry['react-compiler']?.source && exportEntry['react-compiler']?.default,
|
|
599
616
|
].filter(Boolean)).map((p) => path.resolve(cwd, p)), commonDistPath = findCommonDirPath(outputPaths);
|
|
600
617
|
if (commonDistPath === cwd)
|
|
601
618
|
throw new Error(
|
|
@@ -634,7 +651,13 @@ function resolveBuildTasks(ctx) {
|
|
|
634
651
|
), dtsTask2 = {
|
|
635
652
|
type: "build:dts",
|
|
636
653
|
entries: []
|
|
637
|
-
}, rollupTasks = {}, rollupLegacyTasks = {}
|
|
654
|
+
}, rollupTasks = {}, rollupLegacyTasks = {}, rollupReactCompilerTask2 = {
|
|
655
|
+
type: "build:react-compiler",
|
|
656
|
+
runtime: "browser",
|
|
657
|
+
format: "esm",
|
|
658
|
+
entries: [],
|
|
659
|
+
target: target.browser
|
|
660
|
+
};
|
|
638
661
|
function addRollupTaskEntry(format2, runtime, entry) {
|
|
639
662
|
const buildId = `${format2}:${runtime}`;
|
|
640
663
|
rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
@@ -658,6 +681,9 @@ function resolveBuildTasks(ctx) {
|
|
|
658
681
|
target: target[runtime]
|
|
659
682
|
};
|
|
660
683
|
}
|
|
684
|
+
function addRollupReactCompilerTaskEntry(entry) {
|
|
685
|
+
rollupReactCompilerTask2.entries.push(entry);
|
|
686
|
+
}
|
|
661
687
|
for (const exp of exports) {
|
|
662
688
|
const importId = path.join(pkg.name, exp._path);
|
|
663
689
|
exp.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
@@ -720,7 +746,15 @@ function resolveBuildTasks(ctx) {
|
|
|
720
746
|
output
|
|
721
747
|
});
|
|
722
748
|
}
|
|
723
|
-
|
|
749
|
+
for (const exp of exports) {
|
|
750
|
+
const output = exp["react-compiler"]?.default;
|
|
751
|
+
output && addRollupReactCompilerTaskEntry({
|
|
752
|
+
path: exp._path,
|
|
753
|
+
source: exp["react-compiler"]?.source || exp.source,
|
|
754
|
+
output
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
if (rollupReactCompilerTask2.entries.length && tasks.push(rollupReactCompilerTask2), config2?.legacyExports)
|
|
724
758
|
for (const exp of exports) {
|
|
725
759
|
const runtime = exp.browser?.import ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import;
|
|
726
760
|
if (!output) continue;
|
|
@@ -1148,7 +1182,7 @@ function createConsoleSpy(options) {
|
|
|
1148
1182
|
};
|
|
1149
1183
|
}
|
|
1150
1184
|
function resolveRollupConfig(ctx, buildTask) {
|
|
1151
|
-
const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", outputExt = isLegacyExports ? pkgExtMap.legacy : pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
1185
|
+
const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", isReactCompiler = buildTask.type === "build:react-compiler", outputExt = isLegacyExports ? pkgExtMap.legacy : pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
1152
1186
|
Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
|
|
1153
1187
|
), entries = buildTask.entries.map((entry) => ({
|
|
1154
1188
|
...entry,
|
|
@@ -1183,19 +1217,12 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1183
1217
|
}),
|
|
1184
1218
|
commonjs(),
|
|
1185
1219
|
json(),
|
|
1186
|
-
config2?.babel?.reactCompiler && babel({
|
|
1220
|
+
(isReactCompiler || config2?.babel?.reactCompiler) && babel({
|
|
1187
1221
|
babelrc: !1,
|
|
1188
1222
|
presets: ["@babel/preset-typescript"],
|
|
1189
1223
|
babelHelpers: "bundled",
|
|
1190
1224
|
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
1191
|
-
plugins: [
|
|
1192
|
-
[
|
|
1193
|
-
"babel-plugin-react-compiler",
|
|
1194
|
-
{
|
|
1195
|
-
...typeof config2?.babel?.reactCompiler == "object" ? config2?.babel?.reactCompiler : {}
|
|
1196
|
-
}
|
|
1197
|
-
]
|
|
1198
|
-
]
|
|
1225
|
+
plugins: [["babel-plugin-react-compiler", config2?.reactCompilerOptions || {}]]
|
|
1199
1226
|
}),
|
|
1200
1227
|
esbuild({
|
|
1201
1228
|
jsx: config2?.jsx ?? "automatic",
|
|
@@ -1227,7 +1254,7 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1227
1254
|
}
|
|
1228
1255
|
}
|
|
1229
1256
|
})
|
|
1230
|
-
].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
|
|
1257
|
+
].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isReactCompiler ? "_compiled" : isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
|
|
1231
1258
|
return {
|
|
1232
1259
|
inputOptions: {
|
|
1233
1260
|
context: cwd,
|
|
@@ -1298,6 +1325,65 @@ const rollupLegacyTask = {
|
|
|
1298
1325
|
...targetLines,
|
|
1299
1326
|
...entriesLines
|
|
1300
1327
|
].join(`
|
|
1328
|
+
`);
|
|
1329
|
+
},
|
|
1330
|
+
exec: (ctx, task) => new Observable((observer) => {
|
|
1331
|
+
execPromise$2(ctx, task).then((result) => {
|
|
1332
|
+
observer.next(result), observer.complete();
|
|
1333
|
+
}).catch((err) => observer.error(err));
|
|
1334
|
+
}),
|
|
1335
|
+
complete: () => {
|
|
1336
|
+
},
|
|
1337
|
+
error: (_ctx, _task, err) => {
|
|
1338
|
+
console.error(err);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
async function execPromise$2(ctx, task) {
|
|
1342
|
+
const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
|
|
1343
|
+
onRestored: (messages) => {
|
|
1344
|
+
for (const msg of messages) {
|
|
1345
|
+
const text = String(msg.args[0]);
|
|
1346
|
+
msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
try {
|
|
1351
|
+
const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
|
|
1352
|
+
...inputOptions,
|
|
1353
|
+
onwarn(warning) {
|
|
1354
|
+
consoleSpy.messages.push({
|
|
1355
|
+
type: "warn",
|
|
1356
|
+
code: warning.code,
|
|
1357
|
+
args: [warning.message]
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
}), { output } = await bundle.generate(outputOptions);
|
|
1361
|
+
for (const chunkOrAsset of output)
|
|
1362
|
+
chunkOrAsset.type === "asset" ? files.push({
|
|
1363
|
+
type: "asset",
|
|
1364
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1365
|
+
}) : files.push({
|
|
1366
|
+
type: "chunk",
|
|
1367
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1368
|
+
});
|
|
1369
|
+
await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
|
|
1370
|
+
} catch (err) {
|
|
1371
|
+
throw consoleSpy.restore(), err;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
const rollupReactCompilerTask = {
|
|
1375
|
+
name: (ctx, task) => {
|
|
1376
|
+
const entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], entriesLines = entries.length ? [
|
|
1377
|
+
" entries:",
|
|
1378
|
+
...entries.map(
|
|
1379
|
+
(e) => [
|
|
1380
|
+
" - ",
|
|
1381
|
+
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
1382
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
|
|
1383
|
+
].join("")
|
|
1384
|
+
)
|
|
1385
|
+
] : [];
|
|
1386
|
+
return ["Build react compiler exports...", ...targetLines, ...entriesLines].join(`
|
|
1301
1387
|
`);
|
|
1302
1388
|
},
|
|
1303
1389
|
exec: (ctx, task) => new Observable((observer) => {
|
|
@@ -1457,7 +1543,8 @@ const rollupWatchTask = {
|
|
|
1457
1543
|
}, buildTaskHandlers = {
|
|
1458
1544
|
"build:dts": dtsTask,
|
|
1459
1545
|
"build:js": rollupTask,
|
|
1460
|
-
"build:legacy": rollupLegacyTask
|
|
1546
|
+
"build:legacy": rollupLegacyTask,
|
|
1547
|
+
"build:react-compiler": rollupReactCompilerTask
|
|
1461
1548
|
}, watchTaskHandlers = {
|
|
1462
1549
|
"watch:dts": dtsWatchTask,
|
|
1463
1550
|
"watch:js": rollupWatchTask
|
|
@@ -2226,6 +2313,7 @@ export {
|
|
|
2226
2313
|
resolveBuildTasks,
|
|
2227
2314
|
resolveConfigProperty,
|
|
2228
2315
|
rollupLegacyTask,
|
|
2316
|
+
rollupReactCompilerTask,
|
|
2229
2317
|
rollupTask,
|
|
2230
2318
|
rollupWatchTask,
|
|
2231
2319
|
strictOptions,
|