@sanity/pkg-utils 7.2.10-canary.1 → 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.
Files changed (95) hide show
  1. package/dist/_chunks-cjs/index.cjs +10 -106
  2. package/dist/_chunks-cjs/index.cjs.map +1 -1
  3. package/dist/_chunks-cjs/resolveRolldownConfig.cjs +114 -0
  4. package/dist/_chunks-cjs/resolveRolldownConfig.cjs.map +1 -0
  5. package/dist/_chunks-es/index.js +2311 -0
  6. package/dist/_chunks-es/index.js.map +1 -0
  7. package/dist/_chunks-es/resolveRolldownConfig.js +117 -0
  8. package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -0
  9. package/dist/cli.cjs +1 -1
  10. package/dist/cli.d.cts +1 -1
  11. package/dist/index.d.cts +487 -408
  12. package/dist/index.d.ts +487 -408
  13. package/dist/index.js +1 -2390
  14. package/dist/index.js.map +1 -1
  15. package/package.json +7 -8
  16. package/src/cli/buildAction.ts +0 -21
  17. package/src/cli/checkAction.ts +0 -14
  18. package/src/cli/handleError.ts +0 -11
  19. package/src/cli/index.ts +0 -65
  20. package/src/cli/initAction.ts +0 -13
  21. package/src/cli/watchAction.ts +0 -14
  22. package/src/global.ts +0 -5
  23. package/src/node/__snapshots__/strict.test.ts.snap +0 -154
  24. package/src/node/build.ts +0 -100
  25. package/src/node/check.ts +0 -188
  26. package/src/node/consoleSpy.ts +0 -39
  27. package/src/node/core/config/defineConfig.ts +0 -6
  28. package/src/node/core/config/findConfigFile.ts +0 -31
  29. package/src/node/core/config/index.ts +0 -4
  30. package/src/node/core/config/loadConfig.ts +0 -37
  31. package/src/node/core/config/resolveConfigProperty.ts +0 -15
  32. package/src/node/core/config/types.ts +0 -315
  33. package/src/node/core/contexts/buildContext.ts +0 -32
  34. package/src/node/core/contexts/index.ts +0 -1
  35. package/src/node/core/defaults.ts +0 -4
  36. package/src/node/core/findCommonPath.ts +0 -35
  37. package/src/node/core/isRecord.ts +0 -4
  38. package/src/node/core/pkg/helpers.ts +0 -36
  39. package/src/node/core/pkg/index.ts +0 -5
  40. package/src/node/core/pkg/loadPkg.ts +0 -21
  41. package/src/node/core/pkg/loadPkgWithReporting.ts +0 -154
  42. package/src/node/core/pkg/parseExports.ts +0 -233
  43. package/src/node/core/pkg/pkgExt.ts +0 -22
  44. package/src/node/core/pkg/types.ts +0 -60
  45. package/src/node/core/pkg/validateExports.ts +0 -30
  46. package/src/node/core/pkg/validatePkg.ts +0 -82
  47. package/src/node/core/template/createFromTemplate.ts +0 -84
  48. package/src/node/core/template/define.ts +0 -6
  49. package/src/node/core/template/index.ts +0 -3
  50. package/src/node/core/template/types.ts +0 -45
  51. package/src/node/core/ts/index.ts +0 -1
  52. package/src/node/core/ts/loadTSConfig.ts +0 -19
  53. package/src/node/fileExists.ts +0 -12
  54. package/src/node/getFilesize.ts +0 -8
  55. package/src/node/globFiles.ts +0 -6
  56. package/src/node/index.ts +0 -48
  57. package/src/node/init.ts +0 -54
  58. package/src/node/isEmptyDirectory.ts +0 -5
  59. package/src/node/logger.ts +0 -32
  60. package/src/node/printExtractMessages.ts +0 -59
  61. package/src/node/printPackageTree.ts +0 -95
  62. package/src/node/resolveBrowserTarget.ts +0 -17
  63. package/src/node/resolveBuildContext.ts +0 -202
  64. package/src/node/resolveBuildTasks.ts +0 -199
  65. package/src/node/resolveNodeTarget.ts +0 -9
  66. package/src/node/resolveWatchTasks.ts +0 -132
  67. package/src/node/spinner.ts +0 -17
  68. package/src/node/strict.test-d.ts +0 -6
  69. package/src/node/strict.ts +0 -84
  70. package/src/node/tasks/dts/DtsError.ts +0 -11
  71. package/src/node/tasks/dts/buildTypes.ts +0 -42
  72. package/src/node/tasks/dts/createApiExtractorConfig.ts +0 -67
  73. package/src/node/tasks/dts/createTSDocConfig.ts +0 -53
  74. package/src/node/tasks/dts/doExtract.ts +0 -80
  75. package/src/node/tasks/dts/dtsTask.ts +0 -50
  76. package/src/node/tasks/dts/dtsWatchTask.ts +0 -165
  77. package/src/node/tasks/dts/extractModuleBlocks.ts +0 -45
  78. package/src/node/tasks/dts/extractTypes.ts +0 -128
  79. package/src/node/tasks/dts/getExtractMessagesConfig.ts +0 -109
  80. package/src/node/tasks/dts/getTargetPaths.ts +0 -72
  81. package/src/node/tasks/dts/printDiagnostic.ts +0 -42
  82. package/src/node/tasks/dts/types.ts +0 -30
  83. package/src/node/tasks/index.ts +0 -19
  84. package/src/node/tasks/rolldown/resolveRolldownConfig.ts +0 -208
  85. package/src/node/tasks/rolldown/rolldownDtsTask.ts +0 -155
  86. package/src/node/tasks/rollup/resolveRollupConfig.ts +0 -264
  87. package/src/node/tasks/rollup/rollupTask.ts +0 -154
  88. package/src/node/tasks/rollup/rollupWatchTask.ts +0 -77
  89. package/src/node/tasks/types.ts +0 -69
  90. package/src/node/templates/default/index.ts +0 -1
  91. package/src/node/templates/default/template.ts +0 -547
  92. package/src/node/templates/index.ts +0 -1
  93. package/src/node/watch.ts +0 -66
  94. package/src/node/watchConfigFiles.ts +0 -53
  95. package/src/node/watchFiles.ts +0 -31
package/src/node/init.ts DELETED
@@ -1,54 +0,0 @@
1
- import {lstat} from 'node:fs/promises'
2
- import {resolve} from 'node:path'
3
- import {mkdirp} from 'mkdirp'
4
- import {createFromTemplate} from './core/template'
5
- import {fileExists} from './fileExists'
6
- import {isEmptyDirectory} from './isEmptyDirectory'
7
- import {createLogger} from './logger'
8
- import {defaultTemplate} from './templates/default/template'
9
-
10
- /** @public */
11
- export async function init(options: {cwd: string; path: string}): Promise<void> {
12
- if (!options.cwd) {
13
- throw new Error('Missing required option: cwd')
14
- }
15
-
16
- if (!options.path) {
17
- throw new Error('Missing required option: path')
18
- }
19
-
20
- const logger = createLogger()
21
-
22
- const packagePath = resolve(options.cwd, options.path)
23
-
24
- await ensurePackagePath(packagePath)
25
-
26
- await createFromTemplate({
27
- cwd: options.cwd,
28
- logger,
29
- template: defaultTemplate,
30
- packagePath,
31
- })
32
- }
33
-
34
- async function ensurePackagePath(packagePath: string): Promise<void> {
35
- const exists = fileExists(packagePath)
36
-
37
- if (!exists) {
38
- await mkdirp(packagePath)
39
-
40
- return
41
- }
42
-
43
- const dir = (await lstat(packagePath)).isDirectory()
44
-
45
- if (!dir) {
46
- throw new Error('the package path is a file, not a directory')
47
- }
48
-
49
- const empty = await isEmptyDirectory(packagePath)
50
-
51
- if (!empty) {
52
- throw new Error('the package directory is not empty')
53
- }
54
- }
@@ -1,5 +0,0 @@
1
- import {readdir} from 'node:fs/promises'
2
-
3
- export async function isEmptyDirectory(dirPath: string): Promise<boolean> {
4
- return (await readdir(dirPath)).length === 0
5
- }
@@ -1,32 +0,0 @@
1
- // oxlint-disable no-console
2
- import chalk from 'chalk'
3
-
4
- /** @alpha */
5
- export interface Logger {
6
- log: (...args: unknown[]) => void
7
- info: (...args: unknown[]) => void
8
- warn: (...args: unknown[]) => void
9
- error: (...args: unknown[]) => void
10
- success: (...args: unknown[]) => void
11
- }
12
-
13
- /** @alpha */
14
- export function createLogger(): Logger {
15
- return {
16
- log: (...args) => {
17
- console.log(...args)
18
- },
19
- info: (...args) => {
20
- console.log(chalk.blue('[info]'), ...args)
21
- },
22
- warn: (...args) => {
23
- console.log(chalk.yellow('[warning]'), ...args)
24
- },
25
- error: (...args) => {
26
- console.log(chalk.red('[error]'), ...args)
27
- },
28
- success: (...args) => {
29
- console.log(chalk.green('[success]'), ...args)
30
- },
31
- }
32
- }
@@ -1,59 +0,0 @@
1
- import path from 'node:path'
2
- import type {ExtractorMessage} from '@microsoft/api-extractor'
3
- import chalk from 'chalk'
4
- import type {BuildContext} from './core/contexts/buildContext'
5
-
6
- export function printExtractMessages(ctx: BuildContext, messages: ExtractorMessage[]): void {
7
- const {cwd, logger} = ctx
8
-
9
- const warnings = messages.filter((msg) => msg.logLevel === 'warning')
10
-
11
- if (warnings.length) {
12
- logger.log()
13
- }
14
-
15
- for (const msg of warnings) {
16
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
17
-
18
- if (msg.messageId === 'TS6307') {
19
- // Ignore this warning:
20
- // > TS6307: <filename> is not in project file list.
21
- // > Projects must list all files or use an 'include' pattern.
22
- continue
23
- }
24
-
25
- logger.log(
26
- [
27
- `${chalk.cyan(sourceFilePath || '?')}`,
28
- `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
29
- ` - ${chalk.yellow('warning')} ${chalk.gray(msg.messageId)}\n`,
30
- msg.text,
31
- '\n',
32
- ].join(''),
33
- )
34
- }
35
-
36
- const errors: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'error')
37
-
38
- if (!warnings.length && errors.length) {
39
- logger.log('')
40
- }
41
-
42
- for (const msg of errors) {
43
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
44
-
45
- logger.log(
46
- [
47
- `${chalk.cyan(sourceFilePath || '?')}`,
48
- `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
49
- ` - ${chalk.red('error')} ${chalk.gray(msg.messageId)}\n`,
50
- msg.text,
51
- '\n',
52
- ].join(''),
53
- )
54
- }
55
-
56
- if (errors.length) {
57
- process.exit(1)
58
- }
59
- }
@@ -1,95 +0,0 @@
1
- import path from 'node:path'
2
- import chalk from 'chalk'
3
- import treeify from 'treeify'
4
- import type {PkgExport} from './core/config/types'
5
- import type {BuildContext} from './core/contexts/buildContext'
6
- import {fileExists} from './fileExists'
7
- import {getFilesize} from './getFilesize'
8
-
9
- function getFileInfo(cwd: string, filePath: string) {
10
- const p = path.resolve(cwd, filePath)
11
- const exists = fileExists(p)
12
- const size = exists ? getFilesize(p) : undefined
13
-
14
- return {exists, size}
15
- }
16
-
17
- export function printPackageTree(ctx: BuildContext): void {
18
- const {cwd, exports, logger, pkg} = ctx
19
-
20
- if (!exports) return
21
-
22
- logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)
23
-
24
- const tree: Record<string, unknown> = {}
25
-
26
- if (pkg.type) {
27
- tree['type'] = chalk.yellow(pkg.type)
28
- }
29
-
30
- if (pkg.bin) {
31
- tree['bin'] = Object.fromEntries(
32
- Object.entries(pkg.bin).map(([name, file]) => [chalk.cyan(name), fileInfo(file)]),
33
- )
34
- }
35
-
36
- function fileInfo(file: string) {
37
- const info = getFileInfo(cwd, file)
38
-
39
- if (!info.size) {
40
- return `${chalk.gray(file)} ${chalk.red('does not exist')}`
41
- }
42
-
43
- return `${chalk.yellow(file)} ${chalk.gray(info.size)}`
44
- }
45
-
46
- tree['exports'] = Object.fromEntries(
47
- Object.entries(exports)
48
- .filter(([, entry]) => entry._exported)
49
- .map(([exportPath, entry]) => {
50
- const exp: Omit<PkgExport, '_exported'> = {
51
- source: fileInfo(entry.source),
52
- browser: undefined,
53
- require: undefined,
54
- node: undefined,
55
- import: undefined,
56
- default: fileInfo(entry.default),
57
- }
58
-
59
- if (entry.browser) {
60
- exp.browser = {source: fileInfo(entry.browser.source)}
61
-
62
- if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import)
63
- if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require)
64
- } else {
65
- delete exp.browser
66
- }
67
-
68
- if (entry.require) {
69
- exp.require = fileInfo(entry.require)
70
- } else {
71
- delete exp.require
72
- }
73
-
74
- if (entry.node) {
75
- exp.node = {}
76
-
77
- if (entry.node.source) exp.node.source = fileInfo(entry.node.source)
78
- if (entry.node.import) exp.node.import = fileInfo(entry.node.import)
79
- if (entry.node.require) exp.node.require = fileInfo(entry.node.require)
80
- } else {
81
- delete exp.node
82
- }
83
-
84
- if (entry.import) {
85
- exp.import = fileInfo(entry.import)
86
- } else {
87
- delete exp.import
88
- }
89
-
90
- return [chalk.cyan(path.join(pkg.name, exportPath)), exp]
91
- }),
92
- )
93
-
94
- logger.log(treeify.asTree(tree as Record<string, any>, true, true))
95
- }
@@ -1,17 +0,0 @@
1
- export function resolveBrowserTarget(versions: string[]): string[] | undefined {
2
- const target: string[] = versions.filter(
3
- (version) =>
4
- version.startsWith('chrome') ||
5
- version.startsWith('edge') ||
6
- version.startsWith('firefox') ||
7
- version.startsWith('ios') ||
8
- version.startsWith('safari') ||
9
- version.startsWith('opera'),
10
- )
11
-
12
- if (target.length === 0) {
13
- return undefined
14
- }
15
-
16
- return target
17
- }
@@ -1,202 +0,0 @@
1
- import path from 'node:path'
2
- import browserslistToEsbuild from 'browserslist-to-esbuild'
3
- import {resolveConfigProperty} from './core/config/resolveConfigProperty'
4
- import {type PkgConfigOptions, type PkgExports, type PkgRuntime} from './core/config/types'
5
- import type {BuildContext} from './core/contexts/buildContext'
6
- import {DEFAULT_BROWSERSLIST_QUERY} from './core/defaults'
7
- import {findCommonDirPath, pathContains} from './core/findCommonPath'
8
- import {parseExports} from './core/pkg/parseExports'
9
- import type {PackageJSON} from './core/pkg/types'
10
- import {loadTSConfig} from './core/ts/loadTSConfig'
11
- import type {Logger} from './logger'
12
- import {resolveBrowserTarget} from './resolveBrowserTarget'
13
- import {resolveNodeTarget} from './resolveNodeTarget'
14
- import {parseStrictOptions} from './strict'
15
-
16
- export async function resolveBuildContext(options: {
17
- config?: PkgConfigOptions
18
- cwd: string
19
- emitDeclarationOnly?: boolean
20
- logger: Logger
21
- pkg: PackageJSON
22
- strict: boolean
23
- tsconfig: string
24
- }): Promise<BuildContext> {
25
- const {
26
- config,
27
- cwd,
28
- emitDeclarationOnly = false,
29
- logger,
30
- pkg,
31
- strict,
32
- tsconfig: tsconfigPath,
33
- } = options
34
- const tsconfig = await loadTSConfig({cwd, tsconfigPath})
35
- const strictOptions = parseStrictOptions(config?.strictOptions ?? {})
36
-
37
- let browserslist = pkg.browserslist
38
- if (!browserslist) {
39
- if (strict && strictOptions.noImplicitBrowsersList !== 'off') {
40
- if (strictOptions.noImplicitBrowsersList === 'error') {
41
- throw new Error(
42
- '\n- ' +
43
- `package.json: "browserslist" is missing, set it to \`"browserslist": "extends @sanity/browserslist-config"\``,
44
- )
45
- } else {
46
- logger.warn(
47
- 'Could not detect a `browserslist` property in `package.json`, using default configuration. Add `"browserslist": "extends @sanity/browserslist-config"` to silence this warning.',
48
- )
49
- }
50
- }
51
- browserslist = DEFAULT_BROWSERSLIST_QUERY
52
- }
53
- const targetVersions = browserslistToEsbuild(browserslist)
54
-
55
- if (
56
- strict &&
57
- strictOptions.noImplicitSideEffects !== 'off' &&
58
- typeof pkg.sideEffects === 'undefined'
59
- ) {
60
- const msg =
61
- 'package.json: `sideEffects` is missing, see https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects for how to define `sideEffects`'
62
-
63
- if (strictOptions.noImplicitSideEffects === 'error') {
64
- throw new Error(msg)
65
- } else {
66
- logger.warn(msg)
67
- }
68
- }
69
-
70
- const nodeTarget = resolveNodeTarget(targetVersions)
71
- const webTarget = resolveBrowserTarget(targetVersions)
72
-
73
- if (!nodeTarget) {
74
- throw new Error('no matching `node` target')
75
- }
76
-
77
- if (!webTarget) {
78
- throw new Error('no matching `web` target')
79
- }
80
-
81
- const target: Record<PkgRuntime, string[]> = {
82
- '*': webTarget.concat(nodeTarget),
83
- 'browser': webTarget,
84
- 'node': nodeTarget,
85
- }
86
-
87
- const parsedExports = parseExports({
88
- cwd,
89
- pkg,
90
- strict,
91
- strictOptions,
92
- logger,
93
- }).reduce<PkgExports>(
94
- (acc, {_path: exportPath, ...exportEntry}) => Object.assign(acc, {[exportPath]: exportEntry}),
95
- {},
96
- )
97
-
98
- const exports = resolveConfigProperty(config?.exports, parsedExports)
99
-
100
- const parsedExternal = [
101
- ...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
102
- ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),
103
- ]
104
-
105
- // Merge externals if an array is provided, replace if it's a function
106
- const external =
107
- config && Array.isArray(config.external)
108
- ? [...parsedExternal, ...config.external]
109
- : resolveConfigProperty(config?.external, parsedExternal)
110
- // Merge bundledPackages with dev deps, replace if it's a function
111
- const externalWithTypes = new Set([pkg.name, ...external, ...external.map(transformPackageName)])
112
- const bundledDependencies = (pkg.devDependencies ? Object.keys(pkg.devDependencies) : []).filter(
113
- // Do not bundle anything that is marked as external
114
- (_) => !externalWithTypes.has(_),
115
- )
116
- const bundledPackages =
117
- config && Array.isArray(config.extract?.bundledPackages)
118
- ? [...bundledDependencies, ...config.extract.bundledPackages]
119
- : resolveConfigProperty(config?.extract?.bundledPackages, bundledDependencies)
120
-
121
- const outputPaths = Object.values(exports)
122
- .flatMap((exportEntry) => {
123
- return [
124
- exportEntry.import,
125
- exportEntry.require,
126
- exportEntry.browser?.import,
127
- exportEntry.browser?.require,
128
- exportEntry.node?.source && exportEntry.node.import,
129
- exportEntry.node?.source && exportEntry.node.require,
130
- ].filter(Boolean) as string[]
131
- })
132
- .map((p) => path.resolve(cwd, p))
133
-
134
- const commonDistPath = findCommonDirPath(outputPaths)
135
-
136
- if (commonDistPath === cwd) {
137
- throw new Error(
138
- 'all output files must share a common parent directory which is not the root package directory',
139
- )
140
- }
141
-
142
- if (commonDistPath && !pathContains(cwd, commonDistPath)) {
143
- throw new Error('all output files must be located within the package')
144
- }
145
-
146
- const configDistPath = config?.dist ? path.resolve(cwd, config.dist) : undefined
147
-
148
- if (
149
- configDistPath &&
150
- commonDistPath &&
151
- configDistPath !== commonDistPath &&
152
- !pathContains(configDistPath, commonDistPath)
153
- ) {
154
- logger.log(`did you mean to configure \`dist: './${path.relative(cwd, commonDistPath)}'\`?`)
155
-
156
- throw new Error('all output files must be located with the configured `dist` path')
157
- }
158
-
159
- const distPath = configDistPath || commonDistPath
160
-
161
- if (!distPath) {
162
- throw new Error('could not detect `dist` path')
163
- }
164
-
165
- const ctx: BuildContext = {
166
- config,
167
- cwd,
168
- distPath,
169
- emitDeclarationOnly,
170
- exports,
171
- external,
172
- bundledPackages,
173
- files: [],
174
- logger,
175
- pkg,
176
- runtime: config?.runtime ?? '*',
177
- strict,
178
- target,
179
- ts: {
180
- config: tsconfig,
181
- configPath: tsconfigPath,
182
- },
183
- dts: config?.dts === 'rolldown' ? 'rolldown' : 'api-extractor',
184
- }
185
-
186
- return ctx
187
- }
188
-
189
- function transformPackageName(packageName: string): string {
190
- if (packageName.startsWith('@types/')) {
191
- // If it already starts with @types, return it as is
192
- return packageName
193
- } else if (packageName.startsWith('@')) {
194
- // Handle scoped packages
195
- const [scope, name] = packageName.split('/')
196
-
197
- return `@types/${scope.slice(1)}__${name}`
198
- } else {
199
- // Handle regular packages
200
- return `@types/${packageName}`
201
- }
202
- }
@@ -1,199 +0,0 @@
1
- import path from 'node:path'
2
- import type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types'
3
- import type {BuildContext} from './core/contexts/buildContext'
4
- import {getTargetPaths} from './tasks/dts/getTargetPaths'
5
- import type {DtsTask} from './tasks/dts/types'
6
- import type {BuildTask, RolldownDtsTask, RollupTask, RollupTaskEntry} from './tasks/types'
7
-
8
- /** @internal */
9
- export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
10
- const {config, pkg, target} = ctx
11
-
12
- const bundles = config?.bundles || []
13
-
14
- const tasks: BuildTask[] = []
15
-
16
- const exports = Object.entries(ctx.exports || {}).map(
17
- ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},
18
- )
19
-
20
- const dtsTask: DtsTask = {
21
- type: 'build:dts',
22
- entries: [],
23
- }
24
-
25
- const rolldownDtsTask: Record<string, RolldownDtsTask> = {}
26
- const rollupTasks: Record<string, RollupTask> = {}
27
-
28
- function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
29
- const buildId = `${format}:${runtime}`
30
-
31
- if (ctx.dts === 'rolldown') {
32
- if (rolldownDtsTask[buildId]) {
33
- rolldownDtsTask[buildId].entries.push(entry)
34
- } else {
35
- rolldownDtsTask[buildId] = {
36
- type: 'rolldown:dts',
37
- buildId,
38
- entries: [entry],
39
- runtime,
40
- format,
41
- target: target[runtime],
42
- }
43
- }
44
- }
45
-
46
- if (!ctx.emitDeclarationOnly) {
47
- if (rollupTasks[buildId]) {
48
- rollupTasks[buildId].entries.push(entry)
49
- } else {
50
- rollupTasks[buildId] = {
51
- type: 'build:js',
52
- buildId,
53
- entries: [entry],
54
- runtime,
55
- format,
56
- target: target[runtime],
57
- }
58
- }
59
- }
60
- }
61
-
62
- if (ctx.dts === 'api-extractor') {
63
- // Parse `dts` tasks
64
- for (const exp of exports) {
65
- const importId = path.join(pkg.name, exp._path)
66
-
67
- if (exp.source?.endsWith('.ts')) {
68
- dtsTask.entries.push({
69
- importId,
70
- exportPath: exp._path,
71
- sourcePath: exp.source,
72
- targetPaths: getTargetPaths(pkg.type, exp),
73
- })
74
- }
75
-
76
- if (exp.browser?.source?.endsWith('.ts')) {
77
- dtsTask.entries.push({
78
- importId,
79
- exportPath: exp._path,
80
- sourcePath: exp.browser.source,
81
- targetPaths: getTargetPaths(pkg.type, exp.browser),
82
- })
83
- }
84
-
85
- if (exp.node?.source?.endsWith('.ts')) {
86
- dtsTask.entries.push({
87
- importId,
88
- exportPath: exp._path,
89
- sourcePath: exp.node.source,
90
- targetPaths: getTargetPaths(pkg.type, exp.node),
91
- })
92
- }
93
- }
94
-
95
- // Handle dts tasks for bundles
96
- for (const bundle of bundles) {
97
- if (bundle.source?.endsWith('.ts')) {
98
- // importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`
99
- // exportPath needs to be the path to the bundle, like `./dist/cli`
100
- // targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]
101
- const exportPath = (bundle.import || bundle.require)!.replace(/\.[mc]?js$/, '')
102
- const importId = path.join(pkg.name, exportPath)
103
-
104
- dtsTask.entries.push({
105
- importId,
106
- exportPath,
107
- sourcePath: bundle.source,
108
- targetPaths: getTargetPaths(pkg.type, bundle),
109
- })
110
- }
111
- }
112
-
113
- // Add dts task
114
- if (dtsTask.entries.length) {
115
- tasks.push(dtsTask)
116
- }
117
- }
118
-
119
- // Parse rollup:commonjs:* tasks
120
- for (const exp of exports) {
121
- const output = exp.require
122
-
123
- if (!output) continue
124
-
125
- addRollupTaskEntry('commonjs', ctx.runtime, {
126
- path: exp._path,
127
- source: exp.source,
128
- output,
129
- })
130
- }
131
-
132
- // Parse rollup:esm:* tasks
133
- for (const exp of exports) {
134
- const output = exp.import
135
-
136
- if (!output) continue
137
-
138
- addRollupTaskEntry('esm', ctx.runtime, {
139
- path: exp._path,
140
- source: exp.source,
141
- output,
142
- })
143
- }
144
-
145
- // Parse rollup:commonjs:browser tasks
146
- for (const exp of exports) {
147
- const output = exp.browser?.require
148
-
149
- if (!output) continue
150
-
151
- addRollupTaskEntry('commonjs', 'browser', {
152
- path: exp._path,
153
- source: exp.browser?.source || exp.source,
154
- output,
155
- })
156
- }
157
-
158
- // Parse rollup:esm:browser tasks
159
- for (const exp of exports) {
160
- const output = exp.browser?.import
161
-
162
- if (!output) continue
163
-
164
- addRollupTaskEntry('esm', 'browser', {
165
- path: exp._path,
166
- source: exp.browser?.source || exp.source,
167
- output,
168
- })
169
- }
170
-
171
- for (const bundle of bundles) {
172
- const idx = bundles.indexOf(bundle)
173
-
174
- if (bundle.require) {
175
- addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {
176
- path: `__$$bundle_cjs_${idx}$$__`,
177
- source: bundle.source,
178
- output: bundle.require,
179
- })
180
- }
181
-
182
- if (bundle.import) {
183
- addRollupTaskEntry('esm', bundle.runtime || ctx.runtime, {
184
- path: `__$$bundle_esm_${idx}$$__`,
185
- source: bundle.source,
186
- output: bundle.import,
187
- })
188
- }
189
- }
190
-
191
- // Perform rolldown dts tasks first, as they have special logic for removing non .d.ts chunks
192
- tasks.push(...Object.values(rolldownDtsTask))
193
- // Then run api-extractor tsdoc release tag checking (if rolldown is used for dts bundling, otherwise api-extractor performs both in the build:dts task)
194
- // @TODO
195
- // Then run rollup tasks
196
- tasks.push(...Object.values(rollupTasks))
197
-
198
- return tasks
199
- }
@@ -1,9 +0,0 @@
1
- export function resolveNodeTarget(versions: string[]): string[] | undefined {
2
- const target: string[] = versions.filter((version) => version.startsWith('node'))
3
-
4
- if (target.length === 0) {
5
- return undefined
6
- }
7
-
8
- return target
9
- }