@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/src/node/tasks/types.ts
CHANGED
|
@@ -21,25 +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
|
-
/** @internal */
|
|
35
|
-
export interface RollupReactCompilerTask {
|
|
36
|
-
type: 'build:react-compiler'
|
|
37
|
-
entries: RollupTaskEntry[]
|
|
38
|
-
runtime: 'browser'
|
|
39
|
-
format: 'esm'
|
|
40
|
-
target: string[]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
24
|
/** @internal */
|
|
44
25
|
export interface RollupWatchTask {
|
|
45
26
|
type: 'watch:js'
|
|
@@ -51,7 +32,7 @@ export interface RollupWatchTask {
|
|
|
51
32
|
}
|
|
52
33
|
|
|
53
34
|
/** @internal */
|
|
54
|
-
export type BuildTask = DtsTask | RollupTask
|
|
35
|
+
export type BuildTask = DtsTask | RollupTask
|
|
55
36
|
|
|
56
37
|
/** @internal */
|
|
57
38
|
export type WatchTask = DtsWatchTask | RollupWatchTask
|
|
@@ -68,8 +49,6 @@ export type TaskHandler<Task, Result = void> = {
|
|
|
68
49
|
export interface BuildTaskHandlers {
|
|
69
50
|
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
70
51
|
'build:js': TaskHandler<RollupTask>
|
|
71
|
-
'build:react-compiler': TaskHandler<RollupReactCompilerTask>
|
|
72
|
-
'build:legacy': TaskHandler<RollupLegacyTask>
|
|
73
52
|
}
|
|
74
53
|
|
|
75
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})
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import {rollup} from 'rollup'
|
|
5
|
-
import {Observable} from 'rxjs'
|
|
6
|
-
|
|
7
|
-
import {createConsoleSpy} from '../../consoleSpy'
|
|
8
|
-
import type {BuildContext} from '../../core'
|
|
9
|
-
import type {RollupLegacyTask, TaskHandler} from '../types'
|
|
10
|
-
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export const rollupLegacyTask: TaskHandler<RollupLegacyTask> = {
|
|
14
|
-
name: (ctx, task) => {
|
|
15
|
-
const entries = task.entries.filter((e) => !e.path.includes('__$$bundle_'))
|
|
16
|
-
|
|
17
|
-
const targetLines = task.target.length
|
|
18
|
-
? [' target:', ...task.target.map((t) => ` - ${chalk.yellow(t)}`)]
|
|
19
|
-
: []
|
|
20
|
-
|
|
21
|
-
const entriesLines = entries.length
|
|
22
|
-
? [
|
|
23
|
-
' entries:',
|
|
24
|
-
...entries.map((e) =>
|
|
25
|
-
[
|
|
26
|
-
' - ',
|
|
27
|
-
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
28
|
-
`${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
|
|
29
|
-
].join(''),
|
|
30
|
-
),
|
|
31
|
-
]
|
|
32
|
-
: []
|
|
33
|
-
|
|
34
|
-
// @TODO list out the root level files that are generated
|
|
35
|
-
|
|
36
|
-
return [
|
|
37
|
-
'Build legacy exports...',
|
|
38
|
-
` format: ${chalk.yellow(task.format)}`,
|
|
39
|
-
...targetLines,
|
|
40
|
-
...entriesLines,
|
|
41
|
-
].join('\n')
|
|
42
|
-
},
|
|
43
|
-
exec: (ctx, task) => {
|
|
44
|
-
return new Observable((observer) => {
|
|
45
|
-
execPromise(ctx, task)
|
|
46
|
-
.then((result) => {
|
|
47
|
-
observer.next(result)
|
|
48
|
-
observer.complete()
|
|
49
|
-
})
|
|
50
|
-
.catch((err) => observer.error(err))
|
|
51
|
-
})
|
|
52
|
-
},
|
|
53
|
-
complete: () => {
|
|
54
|
-
//
|
|
55
|
-
},
|
|
56
|
-
error: (_ctx, _task, err) => {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.error(err)
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function execPromise(ctx: BuildContext, task: RollupLegacyTask) {
|
|
63
|
-
const {distPath, files, logger} = ctx
|
|
64
|
-
const outDir = path.relative(ctx.cwd, distPath)
|
|
65
|
-
|
|
66
|
-
// Prevent rollup from printing directly to the console
|
|
67
|
-
const consoleSpy = createConsoleSpy({
|
|
68
|
-
onRestored: (messages) => {
|
|
69
|
-
for (const msg of messages) {
|
|
70
|
-
const text = String(msg.args[0])
|
|
71
|
-
|
|
72
|
-
if (msg.code === 'CIRCULAR_DEPENDENCY') {
|
|
73
|
-
continue // ignore
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (text.startsWith('Dynamic import can only')) {
|
|
77
|
-
continue // ignore
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (text.startsWith('Sourcemap is likely to be incorrect')) {
|
|
81
|
-
continue // ignore
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (msg.type === 'log') {
|
|
85
|
-
logger.info(...msg.args)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (msg.type === 'warn') {
|
|
89
|
-
logger.warn(...msg.args)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (msg.type === 'error') {
|
|
93
|
-
logger.error(...msg.args)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
101
|
-
|
|
102
|
-
// Create bundle
|
|
103
|
-
const bundle = await rollup({
|
|
104
|
-
...inputOptions,
|
|
105
|
-
onwarn(warning) {
|
|
106
|
-
consoleSpy.messages.push({
|
|
107
|
-
type: 'warn',
|
|
108
|
-
code: warning.code,
|
|
109
|
-
args: [warning.message],
|
|
110
|
-
})
|
|
111
|
-
},
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
// generate output specific code in-memory
|
|
115
|
-
// you can call this function multiple times on the same bundle object
|
|
116
|
-
const {output} = await bundle.generate(outputOptions)
|
|
117
|
-
|
|
118
|
-
for (const chunkOrAsset of output) {
|
|
119
|
-
if (chunkOrAsset.type === 'asset') {
|
|
120
|
-
files.push({
|
|
121
|
-
type: 'asset',
|
|
122
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
123
|
-
})
|
|
124
|
-
} else {
|
|
125
|
-
files.push({
|
|
126
|
-
type: 'chunk',
|
|
127
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// or write the bundle to disk
|
|
133
|
-
await bundle.write(outputOptions)
|
|
134
|
-
|
|
135
|
-
// closes the bundle
|
|
136
|
-
await bundle.close()
|
|
137
|
-
|
|
138
|
-
// Restore console
|
|
139
|
-
consoleSpy.restore()
|
|
140
|
-
} catch (err) {
|
|
141
|
-
// Restore console
|
|
142
|
-
consoleSpy.restore()
|
|
143
|
-
throw err
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import {rollup} from 'rollup'
|
|
5
|
-
import {Observable} from 'rxjs'
|
|
6
|
-
|
|
7
|
-
import {createConsoleSpy} from '../../consoleSpy'
|
|
8
|
-
import type {BuildContext} from '../../core'
|
|
9
|
-
import type {RollupReactCompilerTask, TaskHandler} from '../types'
|
|
10
|
-
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export const rollupReactCompilerTask: TaskHandler<RollupReactCompilerTask> = {
|
|
14
|
-
name: (ctx, task) => {
|
|
15
|
-
const entries = task.entries.filter((e) => !e.path.includes('__$$bundle_'))
|
|
16
|
-
|
|
17
|
-
const targetLines = task.target.length
|
|
18
|
-
? [' target:', ...task.target.map((t) => ` - ${chalk.yellow(t)}`)]
|
|
19
|
-
: []
|
|
20
|
-
|
|
21
|
-
const entriesLines = entries.length
|
|
22
|
-
? [
|
|
23
|
-
' entries:',
|
|
24
|
-
...entries.map((e) =>
|
|
25
|
-
[
|
|
26
|
-
' - ',
|
|
27
|
-
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
28
|
-
`${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
|
|
29
|
-
].join(''),
|
|
30
|
-
),
|
|
31
|
-
]
|
|
32
|
-
: []
|
|
33
|
-
|
|
34
|
-
// @TODO list out the root level files that are generated
|
|
35
|
-
|
|
36
|
-
return ['Build react compiler exports...', ...targetLines, ...entriesLines].join('\n')
|
|
37
|
-
},
|
|
38
|
-
exec: (ctx, task) => {
|
|
39
|
-
return new Observable((observer) => {
|
|
40
|
-
execPromise(ctx, task)
|
|
41
|
-
.then((result) => {
|
|
42
|
-
observer.next(result)
|
|
43
|
-
observer.complete()
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => observer.error(err))
|
|
46
|
-
})
|
|
47
|
-
},
|
|
48
|
-
complete: () => {
|
|
49
|
-
//
|
|
50
|
-
},
|
|
51
|
-
error: (_ctx, _task, err) => {
|
|
52
|
-
// eslint-disable-next-line no-console
|
|
53
|
-
console.error(err)
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function execPromise(ctx: BuildContext, task: RollupReactCompilerTask) {
|
|
58
|
-
const {distPath, files, logger} = ctx
|
|
59
|
-
const outDir = path.relative(ctx.cwd, distPath)
|
|
60
|
-
|
|
61
|
-
// Prevent rollup from printing directly to the console
|
|
62
|
-
const consoleSpy = createConsoleSpy({
|
|
63
|
-
onRestored: (messages) => {
|
|
64
|
-
for (const msg of messages) {
|
|
65
|
-
const text = String(msg.args[0])
|
|
66
|
-
|
|
67
|
-
if (msg.code === 'CIRCULAR_DEPENDENCY') {
|
|
68
|
-
continue // ignore
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (text.startsWith('Dynamic import can only')) {
|
|
72
|
-
continue // ignore
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (text.startsWith('Sourcemap is likely to be incorrect')) {
|
|
76
|
-
continue // ignore
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (msg.type === 'log') {
|
|
80
|
-
logger.info(...msg.args)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (msg.type === 'warn') {
|
|
84
|
-
logger.warn(...msg.args)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (msg.type === 'error') {
|
|
88
|
-
logger.error(...msg.args)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
96
|
-
|
|
97
|
-
// Create bundle
|
|
98
|
-
const bundle = await rollup({
|
|
99
|
-
...inputOptions,
|
|
100
|
-
onwarn(warning) {
|
|
101
|
-
consoleSpy.messages.push({
|
|
102
|
-
type: 'warn',
|
|
103
|
-
code: warning.code,
|
|
104
|
-
args: [warning.message],
|
|
105
|
-
})
|
|
106
|
-
},
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// generate output specific code in-memory
|
|
110
|
-
// you can call this function multiple times on the same bundle object
|
|
111
|
-
const {output} = await bundle.generate(outputOptions)
|
|
112
|
-
|
|
113
|
-
for (const chunkOrAsset of output) {
|
|
114
|
-
if (chunkOrAsset.type === 'asset') {
|
|
115
|
-
files.push({
|
|
116
|
-
type: 'asset',
|
|
117
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
118
|
-
})
|
|
119
|
-
} else {
|
|
120
|
-
files.push({
|
|
121
|
-
type: 'chunk',
|
|
122
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// or write the bundle to disk
|
|
128
|
-
await bundle.write(outputOptions)
|
|
129
|
-
|
|
130
|
-
// closes the bundle
|
|
131
|
-
await bundle.close()
|
|
132
|
-
|
|
133
|
-
// Restore console
|
|
134
|
-
consoleSpy.restore()
|
|
135
|
-
} catch (err) {
|
|
136
|
-
// Restore console
|
|
137
|
-
consoleSpy.restore()
|
|
138
|
-
throw err
|
|
139
|
-
}
|
|
140
|
-
}
|