@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
|
@@ -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
|
-
}
|