@sanity/pkg-utils 5.1.2 → 5.1.3-canary.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/pkg-utils",
3
- "version": "5.1.2",
3
+ "version": "5.1.3-canary.0",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -132,7 +132,7 @@
132
132
  "typescript": "5.4.2",
133
133
  "vitest": "^1.4.0",
134
134
  "vitest-github-actions-reporter": "^0.11.1",
135
- "@sanity/pkg-utils": "5.1.2"
135
+ "@sanity/pkg-utils": "5.1.3-canary.0"
136
136
  },
137
137
  "peerDependencies": {
138
138
  "typescript": "5.4.2"
package/src/node/build.ts CHANGED
@@ -36,7 +36,7 @@ export async function build(options: {
36
36
  const pkg = await loadPkgWithReporting({cwd, logger, strict})
37
37
 
38
38
  const config = await loadConfig({cwd})
39
- const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
39
+ const extMap = getPkgExtMap()
40
40
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
41
41
 
42
42
  const ctx = await resolveBuildContext({
package/src/node/check.ts CHANGED
@@ -19,7 +19,7 @@ export async function check(options: {
19
19
 
20
20
  const pkg = await loadPkgWithReporting({cwd, logger, strict})
21
21
  const config = await loadConfig({cwd})
22
- const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
22
+ const extMap = getPkgExtMap()
23
23
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
24
24
  const ctx = await resolveBuildContext({config, cwd, extMap, logger, pkg, strict, tsconfig})
25
25
 
@@ -1,3 +1,4 @@
1
+ import {fileEnding, legacyEnding} from '../../tasks/dts/getTargetPaths'
1
2
  import type {PkgExport} from '../config'
2
3
  import {isRecord} from '../isRecord'
3
4
  import type {PkgExtMap} from './pkgExt'
@@ -9,8 +10,9 @@ export function parseExports(options: {
9
10
  extMap: PkgExtMap
10
11
  pkg: PackageJSON
11
12
  strict: boolean
13
+ legacyExports: boolean
12
14
  }): (PkgExport & {_path: string})[] {
13
- const {extMap, pkg, strict} = options
15
+ const {extMap, pkg, strict, legacyExports} = options
14
16
 
15
17
  const rootExport: PkgExport & {_path: string} = {
16
18
  _exported: true,
@@ -30,17 +32,19 @@ export function parseExports(options: {
30
32
 
31
33
  const errors: string[] = []
32
34
 
33
- if (strict && !pkg.types && pkg.source?.endsWith('.ts') && pkg.exports) {
34
- errors.push(
35
- 'package.json: `types` must be declared for the npm listing to show as a TypeScript module.',
36
- )
37
- }
35
+ // @TODO validate typesVersions when legacyExports is true
38
36
 
39
37
  if (strict && 'typings' in pkg) {
40
38
  errors.push('package.json: `typings` should be `types`')
41
39
  }
42
40
 
43
41
  if (pkg.exports) {
42
+ if (strict && !pkg.types && pkg.source?.endsWith('.ts')) {
43
+ errors.push(
44
+ 'package.json: `types` must be declared for the npm listing to show as a TypeScript module.',
45
+ )
46
+ }
47
+
44
48
  if (strict && !pkg.exports['./package.json']) {
45
49
  errors.push('package.json: `exports["./package.json"] must be declared.')
46
50
  }
@@ -66,10 +70,31 @@ export function parseExports(options: {
66
70
  )
67
71
  }
68
72
 
69
- if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
70
- errors.push(
71
- 'package.json: mismatch between "module" and "exports.import" These must be equal.',
72
- )
73
+ // @TODO do not run this check when legacyExports is true
74
+ if (legacyExports) {
75
+ const indexLegacyExport = (
76
+ exportEntry.browser?.import ||
77
+ exportEntry.import ||
78
+ exportEntry.browser?.require ||
79
+ exportEntry.require ||
80
+ ''
81
+ ).replace(fileEnding, legacyEnding)
82
+
83
+ if (indexLegacyExport !== rootExport.import) {
84
+ errors.push(
85
+ `package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`,
86
+ )
87
+ }
88
+ } else {
89
+ if (
90
+ exportEntry.import &&
91
+ rootExport.import &&
92
+ exportEntry.import !== rootExport.import
93
+ ) {
94
+ errors.push(
95
+ 'package.json: mismatch between "module" and "exports.import" These must be equal.',
96
+ )
97
+ }
73
98
  }
74
99
 
75
100
  if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
@@ -1,11 +1,14 @@
1
+ import {legacyEnding} from '../../tasks/dts/getTargetPaths'
2
+
1
3
  /** @internal */
2
4
  export interface PkgExtMap {
3
5
  commonjs: {commonjs: string; esm: string}
4
6
  module: {commonjs: string; esm: string}
7
+ legacy: string
5
8
  }
6
9
 
7
10
  /** @internal */
8
- export const DEFAULT_PKG_EXT_MAP: PkgExtMap = {
11
+ export const pkgExtMap: PkgExtMap = {
9
12
  // pkg.type: "commonjs"
10
13
  commonjs: {
11
14
  commonjs: '.js',
@@ -17,22 +20,14 @@ export const DEFAULT_PKG_EXT_MAP: PkgExtMap = {
17
20
  commonjs: '.cjs',
18
21
  esm: '.js',
19
22
  },
23
+ // package.config.legacyExports: true
24
+ legacy: legacyEnding,
20
25
  }
21
26
 
22
- /** @internal */
23
- export function getPkgExtMap(options: {legacyExports: boolean}): PkgExtMap {
24
- const {legacyExports} = options
25
-
26
- const ret = {...DEFAULT_PKG_EXT_MAP}
27
-
28
- // Fall back to legacy file extensions for package.json with `"type": "commonjs"`
29
- // NOTE: Not supported by Node 14+ and will be removed in a future version
30
- if (legacyExports) {
31
- ret['commonjs'] = {
32
- commonjs: '.js',
33
- esm: '.esm.js',
34
- }
35
- }
36
-
37
- return ret
27
+ /**
28
+ * @deprecated use `pkgExtMap` instead
29
+ * @internal
30
+ */
31
+ export function getPkgExtMap(): PkgExtMap {
32
+ return pkgExtMap
38
33
  }
@@ -1,6 +1,6 @@
1
- import {PkgExport} from '../config'
2
- import {PkgExtMap} from './pkgExt'
3
- import {PackageJSON} from './types'
1
+ import type {PkgExport} from '../config'
2
+ import type {PkgExtMap} from './pkgExt'
3
+ import type {PackageJSON} from './types'
4
4
 
5
5
  export function validateExports(
6
6
  _exports: (PkgExport & {_path: string})[],
@@ -11,6 +11,7 @@ export function validateExports(
11
11
 
12
12
  const errors: string[] = []
13
13
 
14
+ // @TODO validate that no exports declare the legacy exports
14
15
  for (const exp of _exports) {
15
16
  if (exp.require && !exp.require.endsWith(ext.commonjs)) {
16
17
  errors.push(
@@ -76,7 +76,12 @@ export async function resolveBuildContext(options: {
76
76
  'node': nodeTarget,
77
77
  }
78
78
 
79
- const parsedExports = parseExports({extMap, pkg, strict}).reduce<PkgExports>((acc, x) => {
79
+ const parsedExports = parseExports({
80
+ extMap,
81
+ pkg,
82
+ strict,
83
+ legacyExports: config?.legacyExports ?? false,
84
+ }).reduce<PkgExports>((acc, x) => {
80
85
  const {_path: exportPath, ...exportEntry} = x
81
86
 
82
87
  return {...acc, [exportPath]: exportEntry}
@@ -2,8 +2,8 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
 
4
4
  import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
5
- import type {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'
6
- import {getTargetPaths} from './tasks/dts/getTargetPaths'
5
+ import type {BuildTask, DtsTask, RollupLegacyTask, RollupTask, RollupTaskEntry} from './tasks'
6
+ import {fileEnding, getTargetPaths, legacyEnding} from './tasks/dts/getTargetPaths'
7
7
 
8
8
  /** @internal */
9
9
  export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
@@ -23,6 +23,7 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
23
23
  }
24
24
 
25
25
  const rollupTasks: Record<string, RollupTask> = {}
26
+ const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}
26
27
 
27
28
  function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
28
29
  const buildId = `${format}:${runtime}`
@@ -41,6 +42,24 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
41
42
  }
42
43
  }
43
44
 
45
+ function addRollupLegacyTaskEntry(runtime: PkgRuntime, entry: RollupTaskEntry) {
46
+ const buildId = `esm:${runtime}`
47
+
48
+ if (rollupLegacyTasks[buildId]) {
49
+ rollupLegacyTasks[buildId].entries.push(entry)
50
+ } else {
51
+ rollupLegacyTasks[buildId] = {
52
+ type: 'build:legacy',
53
+ buildId,
54
+ entries: [entry],
55
+ runtime,
56
+ format: 'esm',
57
+ // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
58
+ target: target[runtime],
59
+ }
60
+ }
61
+ }
62
+
44
63
  // Parse `dts` tasks
45
64
  for (const exp of exports) {
46
65
  const importId = path.join(pkg.name, exp._path)
@@ -149,6 +168,25 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
149
168
  })
150
169
  }
151
170
 
171
+ // Create rollup bundles that legacy export files will re-export
172
+ if (config?.legacyExports) {
173
+ for (const exp of exports) {
174
+ const runtime = exp.browser?.import || exp.browser?.require ? 'browser' : ctx.runtime
175
+ const output = exp.browser?.import || exp.import || exp.browser?.require || exp.require
176
+
177
+ if (!output) continue
178
+
179
+ // Change the suffix to what the legacy exports will use
180
+ const legacyOutput = output.replace(fileEnding, legacyEnding)
181
+
182
+ addRollupLegacyTaskEntry(runtime, {
183
+ path: exp._path,
184
+ source: exp.browser?.source || exp.source,
185
+ output: legacyOutput,
186
+ })
187
+ }
188
+ }
189
+
152
190
  for (const bundle of bundles) {
153
191
  const idx = bundles.indexOf(bundle)
154
192
 
@@ -169,16 +207,20 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
169
207
  }
170
208
  }
171
209
 
172
- tasks.push(...Object.values(rollupTasks))
210
+ tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks))
173
211
 
174
212
  // Write legacy exports files
175
213
  if (config?.legacyExports) {
176
214
  for (const exp of exports) {
177
215
  if (exp._exported && exp._path !== '.') {
178
- const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(
179
- /\.[^/.]+$/,
180
- '',
181
- )
216
+ const output = (
217
+ exp.browser?.import ||
218
+ exp.import ||
219
+ exp.browser?.require ||
220
+ exp.require ||
221
+ ''
222
+ ).replace(fileEnding, legacyEnding)
223
+ const relativeTargetPath = output.replace(/\.[^/.]+$/, '')
182
224
 
183
225
  if (relativeTargetPath) {
184
226
  fs.writeFileSync(
@@ -40,7 +40,11 @@ export async function buildTypes(options: {
40
40
  const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
41
41
 
42
42
  for (const diagnostic of allDiagnostics) {
43
- printDiagnostic({cwd, logger, diagnostic})
43
+ // @TODO match the import with known export paths
44
+ // Ignore TS2307 errors as they'll be captured elsewhere if they're actually a problem
45
+ if (diagnostic.code !== 2307) {
46
+ printDiagnostic({cwd, logger, diagnostic})
47
+ }
44
48
  }
45
49
 
46
50
  if (emitResult.emitSkipped) {
@@ -1,7 +1,11 @@
1
1
  import type {PackageJSON, PkgBundle, PkgExport} from '../../core'
2
2
 
3
- const fileEnding = /\.[mc]?js$/
4
- const dtsEnding = '.d.ts'
3
+ /** @internal */
4
+ export const fileEnding = /\.[mc]?js$/
5
+ /** @internal */
6
+ export const dtsEnding = '.d.ts'
7
+ /** @internal */
8
+ export const legacyEnding = '.esm.js'
5
9
  const mtsEnding = '.d.mts'
6
10
  const ctsEnding = '.d.cts'
7
11
 
@@ -1,6 +1,6 @@
1
1
  import {dtsTask, dtsWatchTask} from './dts'
2
- import {rollupTask, rollupWatchTask} from './rollup'
3
- import {BuildTaskHandlers, WatchTaskHandlers} from './types'
2
+ import {rollupLegacyTask, rollupTask, rollupWatchTask} from './rollup'
3
+ import type {BuildTaskHandlers, WatchTaskHandlers} from './types'
4
4
 
5
5
  export * from './dts'
6
6
  export * from './rollup'
@@ -10,6 +10,7 @@ export * from './types'
10
10
  export const buildTaskHandlers: BuildTaskHandlers = {
11
11
  'build:dts': dtsTask,
12
12
  'build:js': rollupTask,
13
+ 'build:legacy': rollupLegacyTask,
13
14
  }
14
15
 
15
16
  /** @internal */
@@ -1,2 +1,3 @@
1
+ export * from './rollupLegacyTask'
1
2
  export * from './rollupTask'
2
3
  export * from './rollupWatchTask'
@@ -9,8 +9,9 @@ import path from 'path'
9
9
  import type {InputOptions, OutputOptions, Plugin} from 'rollup'
10
10
  import esbuild from 'rollup-plugin-esbuild'
11
11
 
12
+ import {pkgExtMap as extMap} from '../../../node/core/pkg/pkgExt'
12
13
  import {type BuildContext, resolveConfigProperty} from '../../core'
13
- import type {RollupTask, RollupWatchTask} from '../types'
14
+ import type {RollupLegacyTask, RollupTask, RollupWatchTask} from '../types'
14
15
 
15
16
  export interface RollupConfig {
16
17
  inputOptions: InputOptions
@@ -20,11 +21,12 @@ export interface RollupConfig {
20
21
  /** @internal */
21
22
  export function resolveRollupConfig(
22
23
  ctx: BuildContext,
23
- buildTask: RollupTask | RollupWatchTask,
24
+ buildTask: RollupTask | RollupLegacyTask | RollupWatchTask,
24
25
  ): RollupConfig {
25
26
  const {format, runtime, target} = buildTask
26
- const {config, cwd, exports: _exports, extMap, external, distPath, logger, pkg, ts} = ctx
27
- const outputExt = extMap[pkg.type || 'commonjs'][format]
27
+ const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx
28
+ const isLegacyExports = buildTask.type === 'build:legacy'
29
+ const outputExt = isLegacyExports ? extMap.legacy : extMap[pkg.type || 'commonjs'][format]
28
30
  const minify = config?.minify ?? false
29
31
  const outDir = path.relative(cwd, distPath)
30
32
 
@@ -115,10 +117,10 @@ export function resolveRollupConfig(
115
117
  output: {
116
118
  comments: (_node, comment) => {
117
119
  const text = comment.value
118
- const type = comment.type
120
+ const cType = comment.type
119
121
 
120
122
  // Check if this is a multiline comment
121
- if (type === 'comment2') {
123
+ if (cType === 'comment2') {
122
124
  // Keep licensing comments
123
125
  return /@preserve|@license|@cc_on/i.test(text)
124
126
  }
@@ -135,6 +137,22 @@ export function resolveRollupConfig(
135
137
  ? defaultPlugins.concat(userPlugins)
136
138
  : resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
137
139
 
140
+ // When using legacyExports then we need to hash the chunk file names to avoid chunks overwriting each other
141
+ if (config?.rollup?.hashChunkFileNames === false && config.legacyExports) {
142
+ throw new TypeError(
143
+ "when `legacyExports: true` you can't set `rollup.hashChunkFileNames: false` – this would cause chunks to overwrite each other. Please remove the `hashChunkFileNames` option or set it to `true",
144
+ )
145
+ }
146
+
147
+ const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? false
148
+ const chunksFolder = isLegacyExports
149
+ ? '_legacy'
150
+ : hashChunkFileNames
151
+ ? '_chunks'
152
+ : '_chunks-[format]'
153
+ const chunkFileNames = `${chunksFolder}/${hashChunkFileNames ? '[name]-[hash]' : '[name]'}${outputExt}`
154
+ const entryFileNames = isLegacyExports ? '[name].js' : `[name]${outputExt}`
155
+
138
156
  return {
139
157
  inputOptions: {
140
158
  context: cwd,
@@ -192,28 +210,10 @@ export function resolveRollupConfig(
192
210
  experimentalLogSideEffects: config?.rollup?.experimentalLogSideEffects,
193
211
  },
194
212
  outputOptions: {
195
- chunkFileNames: () => {
196
- const parts = outputExt.split('.')
197
- const prefix = config?.rollup?.hashChunkFileNames ? '[name]-[hash]' : '[name]'
198
- const folder = config?.rollup?.hashChunkFileNames ? '_chunks' : '_chunks-[format]'
199
-
200
- if (parts.length === 3) {
201
- return `${folder}/${prefix}.${parts[2]}`
202
- }
203
-
204
- return `${folder}/${prefix}${outputExt}`
205
- },
213
+ chunkFileNames,
206
214
  compact: minify,
207
215
  dir: outDir,
208
- entryFileNames: () => {
209
- const parts = outputExt.split('.')
210
-
211
- if (parts.length === 3) {
212
- return `[name].${parts[2]}`
213
- }
214
-
215
- return `[name]${outputExt}`
216
- },
216
+ entryFileNames,
217
217
  esModule: true,
218
218
  format,
219
219
  interop: 'compat',
@@ -0,0 +1,144 @@
1
+ import chalk from 'chalk'
2
+ import path from 'path'
3
+ import {rollup} from 'rollup'
4
+ import {Observable} from 'rxjs'
5
+
6
+ import {createConsoleSpy} from '../../consoleSpy'
7
+ import type {BuildContext} from '../../core'
8
+ import type {RollupLegacyTask, TaskHandler} from '../types'
9
+ import {resolveRollupConfig} from './resolveRollupConfig'
10
+
11
+ /** @internal */
12
+ export const rollupLegacyTask: TaskHandler<RollupLegacyTask> = {
13
+ name: (ctx, task) => {
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 entriesLines = entries.length
21
+ ? [
22
+ ' entries:',
23
+ ...entries.map((e) =>
24
+ [
25
+ ' - ',
26
+ `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
27
+ `${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
28
+ ].join(''),
29
+ ),
30
+ ]
31
+ : []
32
+
33
+ // @TODO list out the root level files that are generated
34
+
35
+ return [
36
+ 'Build legacy exports...',
37
+ ` format: ${chalk.yellow(task.format)}`,
38
+ ...targetLines,
39
+ ...entriesLines,
40
+ ].join('\n')
41
+ },
42
+ exec: (ctx, task) => {
43
+ return new Observable((observer) => {
44
+ execPromise(ctx, task)
45
+ .then((result) => {
46
+ observer.next(result)
47
+ observer.complete()
48
+ })
49
+ .catch((err) => observer.error(err))
50
+ })
51
+ },
52
+ complete: () => {
53
+ //
54
+ },
55
+ error: (_ctx, _task, err) => {
56
+ // eslint-disable-next-line no-console
57
+ console.error(err)
58
+ },
59
+ }
60
+
61
+ async function execPromise(ctx: BuildContext, task: RollupLegacyTask) {
62
+ const {distPath, files, logger} = ctx
63
+ const outDir = path.relative(ctx.cwd, distPath)
64
+
65
+ // Prevent rollup from printing directly to the console
66
+ const consoleSpy = createConsoleSpy({
67
+ onRestored: (messages) => {
68
+ for (const msg of messages) {
69
+ const text = String(msg.args[0])
70
+
71
+ if (msg.code === 'CIRCULAR_DEPENDENCY') {
72
+ continue // ignore
73
+ }
74
+
75
+ if (text.startsWith('Dynamic import can only')) {
76
+ continue // ignore
77
+ }
78
+
79
+ if (text.startsWith('Sourcemap is likely to be incorrect')) {
80
+ continue // ignore
81
+ }
82
+
83
+ if (msg.type === 'log') {
84
+ logger.info(...msg.args)
85
+ }
86
+
87
+ if (msg.type === 'warn') {
88
+ logger.warn(...msg.args)
89
+ }
90
+
91
+ if (msg.type === 'error') {
92
+ logger.error(...msg.args)
93
+ }
94
+ }
95
+ },
96
+ })
97
+
98
+ try {
99
+ const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
100
+
101
+ // Create bundle
102
+ const bundle = await rollup({
103
+ ...inputOptions,
104
+ onwarn(warning) {
105
+ consoleSpy.messages.push({
106
+ type: 'warn',
107
+ code: warning.code,
108
+ args: [warning.message],
109
+ })
110
+ },
111
+ })
112
+
113
+ // generate output specific code in-memory
114
+ // you can call this function multiple times on the same bundle object
115
+ const {output} = await bundle.generate(outputOptions)
116
+
117
+ for (const chunkOrAsset of output) {
118
+ if (chunkOrAsset.type === 'asset') {
119
+ files.push({
120
+ type: 'asset',
121
+ path: path.resolve(outDir, chunkOrAsset.fileName),
122
+ })
123
+ } else {
124
+ files.push({
125
+ type: 'chunk',
126
+ path: path.resolve(outDir, chunkOrAsset.fileName),
127
+ })
128
+ }
129
+ }
130
+
131
+ // or write the bundle to disk
132
+ await bundle.write(outputOptions)
133
+
134
+ // closes the bundle
135
+ await bundle.close()
136
+
137
+ // Restore console
138
+ consoleSpy.restore()
139
+ } catch (err) {
140
+ // Restore console
141
+ consoleSpy.restore()
142
+ throw err
143
+ }
144
+ }
@@ -4,8 +4,8 @@ import {rollup} from 'rollup'
4
4
  import {Observable} from 'rxjs'
5
5
 
6
6
  import {createConsoleSpy} from '../../consoleSpy'
7
- import {BuildContext} from '../../core'
8
- import {RollupTask, TaskHandler} from '../types'
7
+ import type {BuildContext} from '../../core'
8
+ import type {RollupTask, TaskHandler} from '../types'
9
9
  import {resolveRollupConfig} from './resolveRollupConfig'
10
10
 
11
11
  /** @internal */
@@ -1,8 +1,8 @@
1
- import {RollupWatcherEvent} from 'rollup'
2
- import {Observable} from 'rxjs'
1
+ import type {RollupWatcherEvent} from 'rollup'
2
+ import type {Observable} from 'rxjs'
3
3
 
4
- import {BuildContext, PkgRuntime} from '../core'
5
- import {DtsResult, DtsTask, DtsWatchTask} from './dts'
4
+ import type {BuildContext, PkgRuntime} from '../core'
5
+ import type {DtsResult, DtsTask, DtsWatchTask} from './dts'
6
6
 
7
7
  /** @internal */
8
8
  export interface RollupTaskEntry {
@@ -21,6 +21,16 @@ 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
+
24
34
  /** @internal */
25
35
  export interface RollupWatchTask {
26
36
  type: 'watch:js'
@@ -32,7 +42,7 @@ export interface RollupWatchTask {
32
42
  }
33
43
 
34
44
  /** @internal */
35
- export type BuildTask = DtsTask | RollupTask
45
+ export type BuildTask = DtsTask | RollupTask | RollupLegacyTask
36
46
 
37
47
  /** @internal */
38
48
  export type WatchTask = DtsWatchTask | RollupWatchTask
@@ -49,6 +59,7 @@ export type TaskHandler<Task, Result = void> = {
49
59
  export interface BuildTaskHandlers {
50
60
  'build:dts': TaskHandler<DtsTask, DtsResult>
51
61
  'build:js': TaskHandler<RollupTask>
62
+ 'build:legacy': TaskHandler<RollupLegacyTask>
52
63
  }
53
64
 
54
65
  /** @internal */
package/src/node/watch.ts CHANGED
@@ -5,7 +5,7 @@ import {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'
5
5
  import {createLogger} from './logger'
6
6
  import {resolveBuildContext} from './resolveBuildContext'
7
7
  import {resolveWatchTasks} from './resolveWatchTasks'
8
- import {TaskHandler, WatchTask, watchTaskHandlers} from './tasks'
8
+ import {type TaskHandler, type WatchTask, watchTaskHandlers} from './tasks'
9
9
  import {watchConfigFiles} from './watchConfigFiles'
10
10
 
11
11
  /** @public */
@@ -32,7 +32,7 @@ export async function watch(options: {
32
32
 
33
33
  const pkg = await loadPkgWithReporting({cwd, logger, strict})
34
34
  const config = await loadConfig({cwd})
35
- const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
35
+ const extMap = getPkgExtMap()
36
36
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
37
37
 
38
38
  return resolveBuildContext({config, cwd, extMap, logger, pkg, strict, tsconfig})