@sanity/pkg-utils 7.2.10-canary.0 → 7.2.10-canary.2
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/index.cjs +10 -105
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs +114 -0
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs.map +1 -0
- package/dist/_chunks-es/index.js +2311 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +117 -0
- package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/index.d.cts +486 -443
- package/dist/index.d.ts +486 -443
- package/dist/index.js +1 -2389
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/cli/buildAction.ts +0 -21
- package/src/cli/checkAction.ts +0 -14
- package/src/cli/handleError.ts +0 -11
- package/src/cli/index.ts +0 -65
- package/src/cli/initAction.ts +0 -13
- package/src/cli/watchAction.ts +0 -14
- package/src/global.ts +0 -5
- package/src/node/__snapshots__/strict.test.ts.snap +0 -154
- package/src/node/build.ts +0 -100
- package/src/node/check.ts +0 -188
- package/src/node/consoleSpy.ts +0 -39
- package/src/node/core/config/defineConfig.ts +0 -6
- package/src/node/core/config/findConfigFile.ts +0 -31
- package/src/node/core/config/index.ts +0 -4
- package/src/node/core/config/loadConfig.ts +0 -37
- package/src/node/core/config/resolveConfigProperty.ts +0 -15
- package/src/node/core/config/types.ts +0 -315
- package/src/node/core/contexts/buildContext.ts +0 -32
- package/src/node/core/contexts/index.ts +0 -1
- package/src/node/core/defaults.ts +0 -4
- package/src/node/core/findCommonPath.ts +0 -35
- package/src/node/core/isRecord.ts +0 -4
- package/src/node/core/pkg/helpers.ts +0 -36
- package/src/node/core/pkg/index.ts +0 -5
- package/src/node/core/pkg/loadPkg.ts +0 -21
- package/src/node/core/pkg/loadPkgWithReporting.ts +0 -154
- package/src/node/core/pkg/parseExports.ts +0 -233
- package/src/node/core/pkg/pkgExt.ts +0 -22
- package/src/node/core/pkg/types.ts +0 -60
- package/src/node/core/pkg/validateExports.ts +0 -30
- package/src/node/core/pkg/validatePkg.ts +0 -82
- package/src/node/core/template/createFromTemplate.ts +0 -84
- package/src/node/core/template/define.ts +0 -6
- package/src/node/core/template/index.ts +0 -3
- package/src/node/core/template/types.ts +0 -45
- package/src/node/core/ts/index.ts +0 -1
- package/src/node/core/ts/loadTSConfig.ts +0 -19
- package/src/node/fileExists.ts +0 -12
- package/src/node/getFilesize.ts +0 -8
- package/src/node/globFiles.ts +0 -6
- package/src/node/index.ts +0 -48
- package/src/node/init.ts +0 -54
- package/src/node/isEmptyDirectory.ts +0 -5
- package/src/node/logger.ts +0 -32
- package/src/node/printExtractMessages.ts +0 -59
- package/src/node/printPackageTree.ts +0 -95
- package/src/node/resolveBrowserTarget.ts +0 -17
- package/src/node/resolveBuildContext.ts +0 -202
- package/src/node/resolveBuildTasks.ts +0 -199
- package/src/node/resolveNodeTarget.ts +0 -9
- package/src/node/resolveWatchTasks.ts +0 -132
- package/src/node/spinner.ts +0 -17
- package/src/node/strict.test-d.ts +0 -6
- package/src/node/strict.ts +0 -84
- package/src/node/tasks/dts/DtsError.ts +0 -11
- package/src/node/tasks/dts/buildTypes.ts +0 -42
- package/src/node/tasks/dts/createApiExtractorConfig.ts +0 -67
- package/src/node/tasks/dts/createTSDocConfig.ts +0 -53
- package/src/node/tasks/dts/doExtract.ts +0 -80
- package/src/node/tasks/dts/dtsTask.ts +0 -50
- package/src/node/tasks/dts/dtsWatchTask.ts +0 -165
- package/src/node/tasks/dts/extractModuleBlocks.ts +0 -45
- package/src/node/tasks/dts/extractTypes.ts +0 -128
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +0 -109
- package/src/node/tasks/dts/getTargetPaths.ts +0 -72
- package/src/node/tasks/dts/printDiagnostic.ts +0 -42
- package/src/node/tasks/dts/types.ts +0 -30
- package/src/node/tasks/index.ts +0 -19
- package/src/node/tasks/rolldown/resolveRolldownConfig.ts +0 -202
- package/src/node/tasks/rolldown/rolldownDtsTask.ts +0 -155
- package/src/node/tasks/rollup/resolveRollupConfig.ts +0 -264
- package/src/node/tasks/rollup/rollupTask.ts +0 -154
- package/src/node/tasks/rollup/rollupWatchTask.ts +0 -77
- package/src/node/tasks/types.ts +0 -69
- package/src/node/templates/default/index.ts +0 -1
- package/src/node/templates/default/template.ts +0 -547
- package/src/node/templates/index.ts +0 -1
- package/src/node/watch.ts +0 -66
- package/src/node/watchConfigFiles.ts +0 -53
- package/src/node/watchFiles.ts +0 -31
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import {rollup} from 'rollup'
|
|
4
|
-
import {Observable} from 'rxjs'
|
|
5
|
-
import {createConsoleSpy} from '../../consoleSpy'
|
|
6
|
-
import type {BuildContext} from '../../core/contexts/buildContext'
|
|
7
|
-
import type {RollupTask, TaskHandler} from '../types'
|
|
8
|
-
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
9
|
-
|
|
10
|
-
/** @internal */
|
|
11
|
-
export const rollupTask: TaskHandler<RollupTask> = {
|
|
12
|
-
name: (ctx, task) => {
|
|
13
|
-
const bundleEntries = task.entries.filter((e) => e.path.includes('__$$bundle_'))
|
|
14
|
-
const entries = task.entries.filter((e) => !e.path.includes('__$$bundle_'))
|
|
15
|
-
|
|
16
|
-
const targetLines = task.target.length
|
|
17
|
-
? [` target:`, ...task.target.map((t) => ` - ${chalk.yellow(t)}`)]
|
|
18
|
-
: []
|
|
19
|
-
|
|
20
|
-
const bundlesLines = bundleEntries.length
|
|
21
|
-
? [
|
|
22
|
-
' bundles:',
|
|
23
|
-
...bundleEntries.map((e) =>
|
|
24
|
-
[
|
|
25
|
-
` - `,
|
|
26
|
-
`${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
|
|
27
|
-
].join(''),
|
|
28
|
-
),
|
|
29
|
-
]
|
|
30
|
-
: []
|
|
31
|
-
|
|
32
|
-
const entriesLines = entries.length
|
|
33
|
-
? [
|
|
34
|
-
' entries:',
|
|
35
|
-
...entries.map((e) =>
|
|
36
|
-
[
|
|
37
|
-
` - `,
|
|
38
|
-
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
39
|
-
`${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
|
|
40
|
-
].join(''),
|
|
41
|
-
),
|
|
42
|
-
]
|
|
43
|
-
: []
|
|
44
|
-
|
|
45
|
-
return [
|
|
46
|
-
`Build javascript files...`,
|
|
47
|
-
` format: ${chalk.yellow(task.format)}`,
|
|
48
|
-
...targetLines,
|
|
49
|
-
...bundlesLines,
|
|
50
|
-
...entriesLines,
|
|
51
|
-
].join('\n')
|
|
52
|
-
},
|
|
53
|
-
exec: (ctx, task) => {
|
|
54
|
-
return new Observable((observer) => {
|
|
55
|
-
execPromise(ctx, task)
|
|
56
|
-
.then((result) => {
|
|
57
|
-
observer.next(result)
|
|
58
|
-
observer.complete()
|
|
59
|
-
})
|
|
60
|
-
.catch((err) => observer.error(err))
|
|
61
|
-
})
|
|
62
|
-
},
|
|
63
|
-
complete: () => {
|
|
64
|
-
//
|
|
65
|
-
},
|
|
66
|
-
error: (_ctx, _task, err) => {
|
|
67
|
-
console.error(err)
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function execPromise(ctx: BuildContext, task: RollupTask) {
|
|
72
|
-
const {distPath, files, logger} = ctx
|
|
73
|
-
const outDir = path.relative(ctx.cwd, distPath)
|
|
74
|
-
|
|
75
|
-
// Prevent rollup from printing directly to the console
|
|
76
|
-
const consoleSpy = createConsoleSpy({
|
|
77
|
-
onRestored: (messages) => {
|
|
78
|
-
for (const msg of messages) {
|
|
79
|
-
const text = String(msg.args[0])
|
|
80
|
-
|
|
81
|
-
if (msg.code === 'CIRCULAR_DEPENDENCY') {
|
|
82
|
-
continue // ignore
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (text.startsWith('Dynamic import can only')) {
|
|
86
|
-
continue // ignore
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (text.startsWith('Sourcemap is likely to be incorrect')) {
|
|
90
|
-
continue // ignore
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (msg.type === 'log') {
|
|
94
|
-
logger.info(...msg.args)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (msg.type === 'warn') {
|
|
98
|
-
logger.warn(...msg.args)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (msg.type === 'error') {
|
|
102
|
-
logger.error(...msg.args)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
110
|
-
|
|
111
|
-
// Create bundle
|
|
112
|
-
const bundle = await rollup({
|
|
113
|
-
...inputOptions,
|
|
114
|
-
onwarn(warning) {
|
|
115
|
-
consoleSpy.messages.push({
|
|
116
|
-
type: 'warn',
|
|
117
|
-
code: warning.code,
|
|
118
|
-
args: [warning.message],
|
|
119
|
-
})
|
|
120
|
-
},
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
// generate output specific code in-memory
|
|
124
|
-
// you can call this function multiple times on the same bundle object
|
|
125
|
-
const {output} = await bundle.generate(outputOptions)
|
|
126
|
-
|
|
127
|
-
for (const chunkOrAsset of output) {
|
|
128
|
-
if (chunkOrAsset.type === 'asset') {
|
|
129
|
-
files.push({
|
|
130
|
-
type: 'asset',
|
|
131
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
132
|
-
})
|
|
133
|
-
} else {
|
|
134
|
-
files.push({
|
|
135
|
-
type: 'chunk',
|
|
136
|
-
path: path.resolve(outDir, chunkOrAsset.fileName),
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// or write the bundle to disk
|
|
142
|
-
await bundle.write(outputOptions)
|
|
143
|
-
|
|
144
|
-
// closes the bundle
|
|
145
|
-
await bundle.close()
|
|
146
|
-
|
|
147
|
-
// Restore console
|
|
148
|
-
consoleSpy.restore()
|
|
149
|
-
} catch (err) {
|
|
150
|
-
// Restore console
|
|
151
|
-
consoleSpy.restore()
|
|
152
|
-
throw err
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import {watch as rollupWatch, type RollupWatcherEvent, type RollupWatchOptions} from 'rollup'
|
|
4
|
-
import {Observable} from 'rxjs'
|
|
5
|
-
import type {RollupWatchTask, TaskHandler} from '../types'
|
|
6
|
-
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
7
|
-
|
|
8
|
-
/** @internal */
|
|
9
|
-
export const rollupWatchTask: TaskHandler<RollupWatchTask, RollupWatcherEvent> = {
|
|
10
|
-
name: (ctx, task) =>
|
|
11
|
-
`build javascript files (target ${task.target.join(' + ')}, format ${
|
|
12
|
-
task.format
|
|
13
|
-
})\n ${task.entries
|
|
14
|
-
.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`)
|
|
15
|
-
.join('\n ')}`,
|
|
16
|
-
exec: (ctx, task) => {
|
|
17
|
-
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
18
|
-
|
|
19
|
-
return new Observable((observer) => {
|
|
20
|
-
const watchOptions: RollupWatchOptions = {
|
|
21
|
-
...inputOptions,
|
|
22
|
-
output: outputOptions,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const watcher = rollupWatch(watchOptions)
|
|
26
|
-
|
|
27
|
-
watcher.on('event', (event) => {
|
|
28
|
-
observer.next(event)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
return () => {
|
|
32
|
-
watcher.close()
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
},
|
|
36
|
-
complete: (ctx, task, event) => {
|
|
37
|
-
const {logger} = ctx
|
|
38
|
-
|
|
39
|
-
if (event.code === 'BUNDLE_END') {
|
|
40
|
-
logger.success(
|
|
41
|
-
`build javascript files (target ${task.target.join(' + ')}, format ${
|
|
42
|
-
task.format
|
|
43
|
-
})\n ${task.entries
|
|
44
|
-
.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`)
|
|
45
|
-
.join('\n ')}`,
|
|
46
|
-
)
|
|
47
|
-
logger.log('')
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (event.code === 'BUNDLE_START') {
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (event.code === 'END') {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (event.code === 'ERROR') {
|
|
61
|
-
logger.error(event.code, event)
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (event.code === 'START') {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
error: (ctx, _task, err) => {
|
|
71
|
-
const {logger} = ctx
|
|
72
|
-
|
|
73
|
-
if (err instanceof Error) {
|
|
74
|
-
logger.log(err)
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
}
|
package/src/node/tasks/types.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type {RollupWatcherEvent} from 'rollup'
|
|
2
|
-
import type {Observable} from 'rxjs'
|
|
3
|
-
import type {PkgRuntime} from '../core/config/types'
|
|
4
|
-
import type {BuildContext} from '../core/contexts/buildContext'
|
|
5
|
-
import type {DtsResult, DtsTask, DtsWatchTask} from './dts/types'
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export interface RollupTaskEntry {
|
|
9
|
-
path: string
|
|
10
|
-
source: string
|
|
11
|
-
output: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** @internal */
|
|
15
|
-
export interface RollupTask {
|
|
16
|
-
type: 'build:js'
|
|
17
|
-
buildId: string
|
|
18
|
-
entries: RollupTaskEntry[]
|
|
19
|
-
runtime: PkgRuntime
|
|
20
|
-
format: 'commonjs' | 'esm'
|
|
21
|
-
target: string[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** @internal */
|
|
25
|
-
export interface RolldownDtsTask {
|
|
26
|
-
type: 'rolldown:dts'
|
|
27
|
-
buildId: string
|
|
28
|
-
entries: RollupTaskEntry[]
|
|
29
|
-
runtime: PkgRuntime
|
|
30
|
-
format: 'commonjs' | 'esm'
|
|
31
|
-
target: string[]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** @internal */
|
|
35
|
-
export interface RollupWatchTask {
|
|
36
|
-
type: 'watch:js'
|
|
37
|
-
buildId: string
|
|
38
|
-
entries: RollupTaskEntry[]
|
|
39
|
-
runtime: PkgRuntime
|
|
40
|
-
format: 'commonjs' | 'esm'
|
|
41
|
-
target: string[]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** @internal */
|
|
45
|
-
export type BuildTask = DtsTask | RollupTask | RolldownDtsTask
|
|
46
|
-
|
|
47
|
-
/** @internal */
|
|
48
|
-
export type WatchTask = DtsWatchTask | RollupWatchTask
|
|
49
|
-
|
|
50
|
-
/** @internal */
|
|
51
|
-
export type TaskHandler<Task, Result = void> = {
|
|
52
|
-
name: (ctx: BuildContext, task: Task) => string
|
|
53
|
-
exec: (ctx: BuildContext, task: Task) => Observable<Result>
|
|
54
|
-
complete: (ctx: BuildContext, task: Task, result: Result) => void
|
|
55
|
-
error: (ctx: BuildContext, task: Task, error: unknown) => void
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @internal */
|
|
59
|
-
export interface BuildTaskHandlers {
|
|
60
|
-
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
61
|
-
'build:js': TaskHandler<RollupTask>
|
|
62
|
-
'rolldown:dts': TaskHandler<RolldownDtsTask>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** @internal */
|
|
66
|
-
export interface WatchTaskHandlers {
|
|
67
|
-
'watch:dts': TaskHandler<DtsWatchTask, DtsResult>
|
|
68
|
-
'watch:js': TaskHandler<RollupWatchTask, RollupWatcherEvent>
|
|
69
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './template'
|