@sanity/pkg-utils 1.2.0 → 1.4.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.
Files changed (105) hide show
  1. package/README.md +8 -0
  2. package/dist/__printPackageTree-793a302b.cjs +75 -0
  3. package/dist/__printPackageTree-793a302b.cjs.map +1 -0
  4. package/dist/__resolveBuildContext-1b29cff2.cjs +336 -0
  5. package/dist/__resolveBuildContext-1b29cff2.cjs.map +1 -0
  6. package/dist/_build-08236974.cjs +169 -0
  7. package/dist/_build-08236974.cjs.map +1 -0
  8. package/dist/_buildAction-586dfb5f.cjs +43 -0
  9. package/dist/_buildAction-586dfb5f.cjs.map +1 -0
  10. package/dist/_check-9d180462.cjs +16 -0
  11. package/dist/_check-9d180462.cjs.map +1 -0
  12. package/dist/_index-c5bd1bc8.cjs +565 -0
  13. package/dist/_index-c5bd1bc8.cjs.map +1 -0
  14. package/dist/_statusAction-385b72dd.cjs +27 -0
  15. package/dist/_statusAction-385b72dd.cjs.map +1 -0
  16. package/dist/_watch-0623c005.cjs +217 -0
  17. package/dist/_watch-0623c005.cjs.map +1 -0
  18. package/dist/_watchAction-4b8d7301.cjs +42 -0
  19. package/dist/_watchAction-4b8d7301.cjs.map +1 -0
  20. package/dist/cli.cjs +14 -30
  21. package/dist/cli.cjs.map +1 -1
  22. package/dist/index.cjs +42 -16
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +278 -154
  25. package/dist/index.js +965 -5129
  26. package/dist/index.js.map +1 -1
  27. package/package.json +25 -9
  28. package/src/cli/buildAction.ts +8 -0
  29. package/src/cli/index.ts +41 -0
  30. package/src/cli/statusAction.ts +8 -0
  31. package/src/cli/watchAction.ts +8 -0
  32. package/src/node/_core/_defaults.ts +9 -0
  33. package/src/{core → node/_core}/_isRecord.ts +1 -3
  34. package/src/{core → node/_core}/config/_loadConfig.ts +1 -3
  35. package/src/node/_core/config/_resolveConfigProperty.ts +15 -0
  36. package/src/{core → node/_core}/config/defineConfig.ts +1 -3
  37. package/src/{core → node/_core}/config/index.ts +0 -0
  38. package/src/node/_core/config/types.ts +69 -0
  39. package/src/node/_core/contexts/buildContext.ts +34 -0
  40. package/src/node/_core/contexts/index.ts +1 -0
  41. package/src/{core → node/_core}/index.ts +2 -0
  42. package/src/node/_core/pkg/_loadPkg.ts +54 -0
  43. package/src/node/_core/pkg/_loadPkgWithReporting.ts +29 -0
  44. package/src/node/_core/pkg/_parseExports.ts +45 -0
  45. package/src/{core → node/_core}/pkg/_types.ts +17 -5
  46. package/src/{core → node/_core}/pkg/index.ts +1 -0
  47. package/src/{build/tasks/dts → node/_core/ts}/_loadTSConfig.ts +1 -0
  48. package/src/node/_core/ts/index.ts +1 -0
  49. package/src/node/_getFilesize.ts +8 -0
  50. package/src/node/_globFiles.ts +5 -0
  51. package/src/node/_printExtractMessages.ts +56 -0
  52. package/src/node/_printPackageTree.ts +72 -0
  53. package/src/node/_resolveBrowserTarget.ts +35 -0
  54. package/src/node/_resolveBrowserslistVersions.ts +60 -0
  55. package/src/node/_resolveBuildContext.ts +104 -0
  56. package/src/node/_resolveBuildTasks.ts +129 -0
  57. package/src/node/_resolveNodeTarget.ts +15 -0
  58. package/src/node/_resolveWatchTasks.ts +129 -0
  59. package/src/node/_spinner.ts +26 -0
  60. package/src/node/_tasks/_types.ts +57 -0
  61. package/src/node/_tasks/dts/_DtsError.ts +11 -0
  62. package/src/{build/tasks → node/_tasks}/dts/_buildTypes.ts +20 -16
  63. package/src/node/_tasks/dts/_createApiExtractorConfig.ts +41 -0
  64. package/src/{build/tasks → node/_tasks}/dts/_createTSDocConfig.ts +2 -6
  65. package/src/node/_tasks/dts/_doExtract.ts +46 -0
  66. package/src/node/_tasks/dts/_dtsTask.ts +38 -0
  67. package/src/node/_tasks/dts/_dtsWatchTask.ts +43 -0
  68. package/src/node/_tasks/dts/_extractTypes.ts +161 -0
  69. package/src/node/_tasks/dts/_types.ts +25 -0
  70. package/src/node/_tasks/dts/index.ts +3 -0
  71. package/src/node/_tasks/index.ts +19 -0
  72. package/src/node/_tasks/rollup/_resolveRollupConfig.ts +132 -0
  73. package/src/node/_tasks/rollup/_rollupTask.ts +71 -0
  74. package/src/node/_tasks/rollup/_rollupWatchTask.ts +78 -0
  75. package/src/node/_tasks/rollup/index.ts +2 -0
  76. package/src/node/_watchConfigFiles.ts +52 -0
  77. package/src/node/_watchFiles.ts +29 -0
  78. package/src/node/build.ts +47 -0
  79. package/src/node/check.ts +14 -0
  80. package/src/node/index.ts +6 -0
  81. package/src/node/watch.ts +56 -0
  82. package/dist/_build-e608bb7c.cjs +0 -5458
  83. package/dist/_build-e608bb7c.cjs.map +0 -1
  84. package/src/build/_parseTasks.ts +0 -87
  85. package/src/build/_types.ts +0 -25
  86. package/src/build/build.ts +0 -82
  87. package/src/build/index.ts +0 -2
  88. package/src/build/tasks/_types.ts +0 -8
  89. package/src/build/tasks/dts/_createApiExtractorConfig.ts +0 -88
  90. package/src/build/tasks/dts/_extractTypes.ts +0 -100
  91. package/src/build/tasks/dts/dts.ts +0 -59
  92. package/src/build/tasks/dts/index.ts +0 -1
  93. package/src/build/tasks/extract/_extractTask.ts +0 -49
  94. package/src/build/tasks/extract/index.ts +0 -1
  95. package/src/build/tasks/index.ts +0 -4
  96. package/src/build/tasks/rollup/_resolveRollupConfig.ts +0 -95
  97. package/src/build/tasks/rollup/index.ts +0 -1
  98. package/src/build/tasks/rollup/rollup.ts +0 -96
  99. package/src/cli.ts +0 -25
  100. package/src/core/_defaults.ts +0 -9
  101. package/src/core/config/_resolveConfigProperty.ts +0 -12
  102. package/src/core/config/types.ts +0 -56
  103. package/src/core/pkg/_loadPkg.ts +0 -13
  104. package/src/core/pkg/_parseExports.ts +0 -40
  105. package/src/index.ts +0 -2
@@ -1,87 +0,0 @@
1
- import path from 'path'
2
- import {PackageSubPathExportEntry, _DEFAULTS} from '../core'
3
- import {_BuildContext} from './_types'
4
- import {_BuildTask, _DtsTask, _RollupTask} from './tasks'
5
-
6
- /**
7
- * @internal
8
- */
9
- export function _parseTasks(ctx: _BuildContext): _BuildTask[] {
10
- const {config, pkg} = ctx
11
-
12
- const entries = Object.entries(ctx.exports || {}).map(
13
- ([path, entry]) => ({path, ...entry} as PackageSubPathExportEntry & {path: string})
14
- )
15
-
16
- const dtsTasks: Record<string, _DtsTask> = {}
17
- const rollupTasks: Record<string, _RollupTask> = {}
18
-
19
- // Parse `dts` tasks
20
- for (const entry of entries) {
21
- const exportId = path.join(pkg.name, entry.path)
22
-
23
- if (entry.types) {
24
- if (!dtsTasks[exportId]) {
25
- dtsTasks[exportId] = {
26
- type: 'dts',
27
- exportId,
28
- exportPath: entry.path === '.' ? './index' : entry.path,
29
- source: entry.source,
30
- output: entry.types,
31
- }
32
- }
33
- }
34
- }
35
-
36
- // Parse `rollup` tasks
37
- for (const entry of entries) {
38
- const runtime = entry.runtime || config?.runtime || 'web'
39
-
40
- const format: ('commonjs' | 'esm')[] = []
41
- const target: string[] = []
42
-
43
- if (entry.require) {
44
- format.push('commonjs')
45
- }
46
-
47
- if (entry.default) {
48
- format.push('esm')
49
- }
50
-
51
- if (runtime === 'node') {
52
- target.push(...(config?.target?.node || _DEFAULTS.target.node))
53
- }
54
-
55
- if (runtime === 'web') {
56
- target.push(...(config?.target?.web || _DEFAULTS.target.web))
57
- }
58
-
59
- for (const f of format) {
60
- const buildId = `${runtime}:${f}:${target.join(',')}`
61
-
62
- if (!rollupTasks[buildId]) {
63
- rollupTasks[buildId] = {
64
- type: 'rollup',
65
- buildId,
66
- entries: [entry],
67
- runtime,
68
- format: f,
69
- target,
70
- }
71
- } else {
72
- rollupTasks[buildId].entries.push(entry)
73
- }
74
- }
75
- }
76
-
77
- const tasks: _BuildTask[] = [...Object.values(dtsTasks), ...Object.values(rollupTasks)]
78
-
79
- if (ctx.extract && pkg.types) {
80
- tasks.push({
81
- type: 'extract',
82
- mainEntryPointPath: pkg.types,
83
- })
84
- }
85
-
86
- return tasks
87
- }
@@ -1,25 +0,0 @@
1
- import {PackageExports, PkgConfigOptions, _PackageJSON} from '../core'
2
-
3
- /**
4
- * @internal
5
- */
6
- export interface _BuildFile {
7
- type: 'asset' | 'chunk' | 'types'
8
- path: string
9
- }
10
-
11
- /**
12
- * @internal
13
- */
14
- export interface _BuildContext {
15
- config?: PkgConfigOptions
16
- cwd: string
17
- exports: PackageExports | undefined
18
- external: string[]
19
- extract: boolean
20
- files: _BuildFile[]
21
- dist: string
22
- pkg: _PackageJSON
23
- src: string
24
- tsconfig?: string
25
- }
@@ -1,82 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import path from 'path'
4
- import chalk from 'chalk'
5
- import {PackageExports, _loadConfig, _loadPkg, _parseExports, _resolveConfigProperty} from '../core'
6
- import {_parseTasks} from './_parseTasks'
7
- import {_BuildContext} from './_types'
8
- import {_dtsTask, _extractTask, _rollupTask} from './tasks'
9
-
10
- /**
11
- * @public
12
- */
13
- export async function build(options: {
14
- cwd: string
15
- extract?: boolean
16
- tsconfig?: string
17
- }): Promise<void> {
18
- const {cwd, extract = false, tsconfig = 'tsconfig.json'} = options
19
- const pkg = await _loadPkg({cwd})
20
- const config = await _loadConfig({cwd})
21
-
22
- const parsedExports = _parseExports(pkg).reduce<PackageExports>((acc, x) => {
23
- const {path: exportPath, ...exportEntry} = x
24
-
25
- return {...acc, [exportPath]: exportEntry}
26
- }, {})
27
-
28
- const exports = config?.exports
29
- ? _resolveConfigProperty(config.exports, parsedExports)
30
- : parsedExports
31
-
32
- const initialExternal = [
33
- ...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
34
- ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),
35
- ]
36
-
37
- const external = config?.external
38
- ? _resolveConfigProperty(config.external, initialExternal)
39
- : initialExternal
40
-
41
- const srcPath = path.resolve(cwd, config?.src || 'src')
42
- const distPath = path.resolve(cwd, config?.dist || 'dist')
43
-
44
- const context: _BuildContext = {
45
- config,
46
- cwd,
47
- exports,
48
- extract,
49
- files: [],
50
- external,
51
- dist: path.relative(cwd, distPath),
52
- pkg,
53
- src: path.relative(cwd, srcPath),
54
- tsconfig,
55
- }
56
-
57
- console.log(chalk.gray('cwd '), context.cwd)
58
- // console.log('external ', context.external)
59
- console.log(chalk.gray('src '), context.src)
60
- console.log(chalk.gray('dist '), context.dist)
61
- console.log(chalk.gray('tsconfig '), context.tsconfig)
62
-
63
- if (exports) {
64
- const buildTasks = _parseTasks(context)
65
-
66
- for (const task of buildTasks) {
67
- if (task.type === 'dts') {
68
- await _dtsTask(context, task)
69
- }
70
-
71
- if (task.type === 'extract') {
72
- await _extractTask(context, task)
73
- }
74
-
75
- if (task.type === 'rollup') {
76
- await _rollupTask(context, task)
77
- }
78
- }
79
- } else {
80
- throw new Error('no exports')
81
- }
82
- }
@@ -1,2 +0,0 @@
1
- export * from './_types'
2
- export * from './build'
@@ -1,8 +0,0 @@
1
- import {_DtsTask} from './dts'
2
- import {_ExtractTask} from './extract'
3
- import {_RollupTask} from './rollup'
4
-
5
- /**
6
- * @internal
7
- */
8
- export type _BuildTask = _DtsTask | _ExtractTask | _RollupTask
@@ -1,88 +0,0 @@
1
- import path from 'path'
2
- import {ExtractorLogLevel, IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
3
-
4
- export const DEFAULT_MESSAGES_CONFIG: IExtractorMessagesConfig = {
5
- compilerMessageReporting: {
6
- default: {
7
- logLevel: 'warning' as ExtractorLogLevel,
8
- },
9
- },
10
-
11
- extractorMessageReporting: {
12
- default: {
13
- logLevel: 'warning' as ExtractorLogLevel,
14
- addToApiReportFile: false,
15
- },
16
-
17
- // 'ae-extra-release-tag': {
18
- // logLevel: 'error' as ExtractorLogLevel,
19
- // addToApiReportFile: false
20
- // },
21
-
22
- // 'ae-forgotten-export': {
23
- // logLevel: 'error' as ExtractorLogLevel,
24
- // addToApiReportFile: false
25
- // }
26
- },
27
-
28
- tsdocMessageReporting: {
29
- default: {
30
- logLevel: 'warning' as ExtractorLogLevel,
31
- addToApiReportFile: false,
32
- },
33
-
34
- // 'tsdoc-link-tag-unescaped-text': {
35
- // logLevel: 'warning' as ExtractorLogLevel,
36
- // addToApiReportFile: false
37
- // },
38
-
39
- // 'tsdoc-unsupported-tag': {
40
- // logLevel: 'none' as ExtractorLogLevel,
41
- // addToApiReportFile: false
42
- // },
43
-
44
- // 'tsdoc-undefined-tag': {
45
- // logLevel: 'none' as ExtractorLogLevel,
46
- // addToApiReportFile: false
47
- // }
48
- },
49
- }
50
-
51
- export function _createApiExtractorConfig(options: {
52
- exportPath: string
53
- projectPath: string
54
- sourcePath: string
55
- tsconfigPath: string
56
- distPath: string
57
- }): IConfigFile {
58
- const {exportPath, projectPath, sourcePath, tsconfigPath, distPath} = options
59
-
60
- return {
61
- apiReport: {
62
- enabled: false,
63
- reportFileName: '<unscopedPackageName>.api.md',
64
- // reportFileName: path.resolve(distPath, `${exportPath}.api.md`)
65
- },
66
- // bundledPackages: [],
67
- compiler: {
68
- tsconfigFilePath: tsconfigPath,
69
- },
70
- docModel: {
71
- enabled: false,
72
- // apiJsonFilePath: '<unscopedPackageName>.api.json'
73
- apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),
74
- },
75
- dtsRollup: {
76
- enabled: true,
77
- untrimmedFilePath: path.resolve(distPath, `${exportPath}.d.ts`),
78
- // betaTrimmedFilePath: path.resolve(distPath, `${exportPath}-beta.d.ts`),
79
- // publicTrimmedFilePath: path.resolve(distPath, `${exportPath}-public.d.ts`)
80
- },
81
- tsdocMetadata: {
82
- enabled: false,
83
- },
84
- messages: DEFAULT_MESSAGES_CONFIG,
85
- mainEntryPointFilePath: sourcePath,
86
- projectFolder: projectPath,
87
- }
88
- }
@@ -1,100 +0,0 @@
1
- import path from 'path'
2
- import {
3
- Extractor,
4
- ExtractorConfig,
5
- ExtractorMessage,
6
- ExtractorResult,
7
- } from '@microsoft/api-extractor'
8
- import chalk from 'chalk'
9
- import {_BuildFile} from '../../_types'
10
- import {_createApiExtractorConfig} from './_createApiExtractorConfig'
11
- import {_createTSDocConfig} from './_createTSDocConfig'
12
-
13
- export async function _extractTypes(options: {
14
- cwd: string
15
- distPath: string
16
- exportPath: string
17
- files: _BuildFile[]
18
- projectPath: string
19
- quiet?: boolean
20
- sourcePath: string
21
- tsconfigPath: string
22
- }): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
23
- const {cwd, distPath, exportPath, files, projectPath, quiet, sourcePath, tsconfigPath} = options
24
-
25
- const tsdocConfigFile = await _createTSDocConfig({
26
- customTags: [],
27
- })
28
-
29
- const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
30
- configObject: _createApiExtractorConfig({
31
- exportPath,
32
- projectPath,
33
- sourcePath,
34
- distPath,
35
- tsconfigPath,
36
- }),
37
- configObjectFullPath: undefined,
38
- tsdocConfigFile,
39
- packageJsonFullPath: path.resolve(projectPath, 'package.json'),
40
- })
41
-
42
- const messages: ExtractorMessage[] = []
43
-
44
- // Invoke API Extractor
45
- const extractorResult = Extractor.invoke(extractorConfig, {
46
- // Equivalent to the "--local" command-line parameter
47
- localBuild: true,
48
- // Equivalent to the "--verbose" command-line parameter
49
- showVerboseMessages: true,
50
- // handle messages
51
- messageCallback(message: ExtractorMessage) {
52
- messages.push(message)
53
- message.handled = true
54
- },
55
- })
56
-
57
- if (!quiet) {
58
- const warnings: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'warning')
59
-
60
- for (const msg of warnings) {
61
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
62
-
63
- // eslint-disable-next-line no-console
64
- console.log(
65
- [
66
- `${chalk.cyan(sourceFilePath || '?')}`,
67
- `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
68
- ` - ${chalk.yellow('warning')} ${chalk.gray(msg.messageId)}\n`,
69
- msg.text,
70
- '\n',
71
- ].join('')
72
- )
73
- }
74
- }
75
-
76
- const errors: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'error')
77
-
78
- for (const msg of errors) {
79
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
80
-
81
- // eslint-disable-next-line no-console
82
- console.log(
83
- [
84
- `${chalk.cyan(sourceFilePath || '?')}`,
85
- `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
86
- ` - ${chalk.red('error')} ${chalk.gray(msg.messageId)}\n`,
87
- msg.text,
88
- '\n',
89
- ].join('')
90
- )
91
- }
92
-
93
- // Add to `files` in context
94
- files.push({
95
- type: 'types',
96
- path: path.resolve(distPath, `${exportPath}.d.ts`),
97
- })
98
-
99
- return {extractorResult, messages}
100
- }
@@ -1,59 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import path from 'path'
4
- import {promisify} from 'util'
5
- import chalk from 'chalk'
6
- import rimrafCallback from 'rimraf'
7
- import {_BuildContext} from '../../_types'
8
- import {_buildTypes} from './_buildTypes'
9
- import {_extractTypes} from './_extractTypes'
10
-
11
- const rimraf = promisify(rimrafCallback)
12
-
13
- /**
14
- * @internal
15
- */
16
- export interface _DtsTask {
17
- type: 'dts'
18
- exportId: string
19
- exportPath: string
20
- source: string
21
- output: string
22
- }
23
-
24
- /**
25
- * @internal
26
- */
27
- export async function _dtsTask(ctx: _BuildContext, task: _DtsTask): Promise<void> {
28
- const {cwd, dist, files, tsconfig} = ctx
29
- const exportPath = task.exportPath === '.' ? './index' : task.exportPath
30
- const distPath = path.resolve(cwd, dist)
31
- const tmpPath = path.resolve(cwd, dist, 'tmp')
32
- const tsconfigPath = path.resolve(cwd, tsconfig || 'tsconfig.json')
33
-
34
- console.log('=================================================================================')
35
- console.log(chalk.gray('task '), 'd.ts')
36
- console.log(chalk.gray('source '), path.join('', task.source))
37
- console.log(chalk.gray('export '), path.join(dist, `${exportPath}.d.ts`))
38
- console.log(chalk.gray('tsconfig '), path.relative(cwd, tsconfigPath))
39
-
40
- const types = await _buildTypes({
41
- cwd,
42
- outDir: tmpPath,
43
- sourcePath: task.source,
44
- tsconfigPath,
45
- })
46
-
47
- await _extractTypes({
48
- cwd,
49
- exportPath,
50
- files,
51
- projectPath: cwd,
52
- sourcePath: types.path,
53
- tsconfigPath,
54
- distPath,
55
- })
56
-
57
- // Delete tmp directory
58
- await rimraf(tmpPath)
59
- }
@@ -1 +0,0 @@
1
- export * from './dts'
@@ -1,49 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import fs from 'fs/promises'
4
- import path from 'path'
5
- import {extract, transform} from '@sanity/tsdoc-to-portable-text'
6
- import chalk from 'chalk'
7
- import mkdirp from 'mkdirp'
8
- import {_BuildContext} from '../../_types'
9
-
10
- /**
11
- * @internal
12
- */
13
- export interface _ExtractTask {
14
- type: 'extract'
15
- mainEntryPointPath: string
16
- }
17
-
18
- export async function _extractTask(ctx: _BuildContext, task: _ExtractTask): Promise<void> {
19
- const {mainEntryPointPath} = task
20
-
21
- console.log('=================================================================================')
22
- console.log(chalk.gray('task '), 'extract')
23
- console.log(
24
- chalk.gray('source '),
25
- path.relative(ctx.cwd, path.resolve(ctx.cwd, mainEntryPointPath))
26
- )
27
-
28
- const extracted = await extract(ctx.cwd, {
29
- tsconfigPath: path.resolve(ctx.cwd, ctx.tsconfig || 'tsconfig.json'),
30
- })
31
-
32
- const transformed = transform(extracted, {
33
- package: {
34
- version: ctx.pkg.version,
35
- },
36
- })
37
-
38
- const apiJsonDirPath = path.resolve(ctx.cwd, 'etc/api', ctx.pkg.name)
39
-
40
- await mkdirp(apiJsonDirPath)
41
-
42
- const jsonPath = path.resolve(apiJsonDirPath, `${ctx.pkg.version}.json`)
43
-
44
- if (transformed.length) {
45
- await fs.writeFile(jsonPath, JSON.stringify(transformed, null, 2) + '\n')
46
-
47
- console.log(chalk.gray('result '), path.relative(ctx.cwd, jsonPath))
48
- }
49
- }
@@ -1 +0,0 @@
1
- export * from './_extractTask'
@@ -1,4 +0,0 @@
1
- export * from './_types'
2
- export * from './dts'
3
- export * from './extract'
4
- export * from './rollup'
@@ -1,95 +0,0 @@
1
- import commonjs from '@rollup/plugin-commonjs'
2
- import json from '@rollup/plugin-json'
3
- import {nodeResolve} from '@rollup/plugin-node-resolve'
4
- import {InputOptions, OutputOptions} from 'rollup'
5
- import esbuild from 'rollup-plugin-esbuild'
6
- import {_BuildContext} from '../../_types'
7
- import {_RollupTask} from './rollup'
8
-
9
- /**
10
- * @internal
11
- */
12
- export function _resolveRollupConfig(
13
- ctx: _BuildContext,
14
- buildTask: _RollupTask
15
- ): {
16
- inputOptions: InputOptions
17
- outputOptions: OutputOptions
18
- } {
19
- const {format, runtime, target} = buildTask
20
- const {cwd, external, dist: outDir, pkg, tsconfig} = ctx
21
- const outputExt = format === 'commonjs' ? '.cjs' : pkg.type === 'module' ? '.mjs' : '.js'
22
-
23
- return {
24
- inputOptions: {
25
- context: cwd,
26
-
27
- external,
28
-
29
- input: buildTask.entries.reduce<{[entryAlias: string]: string}>((acc, entry) => {
30
- const key = entry.path === '.' ? 'index' : entry.path.slice(2)
31
-
32
- return {...acc, [key]: entry.source || ''}
33
- }, {}),
34
-
35
- plugins: [
36
- nodeResolve({
37
- mainFields: ['module', 'jsnext', 'main'],
38
- browser: runtime !== 'node',
39
- exportConditions: [runtime === 'node' ? 'node' : 'browser'],
40
- extensions: ['.cjs', '.mjs', '.js', '.jsx', '.json', '.node'],
41
- preferBuiltins: runtime === 'node',
42
- }),
43
- commonjs({
44
- esmExternals: false,
45
- include: /\/node_modules\//,
46
- // requireReturnsDefault: 'namespace',
47
- }),
48
- json(),
49
- esbuild({
50
- // include: /\.[jt]sx?$/, // default, inferred from `loaders` option
51
- // exclude: /node_modules/, // default
52
- // sourceMap: false, // by default inferred from rollup's `output.sourcemap` option
53
- minify: false, // process.env.NODE_ENV === 'production',
54
- // target: 'es2017', // default, or 'es20XX', 'esnext'
55
- jsx: 'transform', // default, or 'preserve'
56
- jsxFactory: 'React.createElement',
57
- jsxFragment: 'React.Fragment',
58
- // // Like @rollup/plugin-replace
59
- // define: {
60
- // __VERSION__: '"x.y.z"',
61
- // },
62
- // plugins: [],
63
- target,
64
- // target:
65
- // target === 'node'
66
- // ? ['node12']
67
- // : ['es2020', 'chrome104', 'edge104', 'firefox103', 'safari15'],
68
- tsconfig: tsconfig || 'tsconfig.json', // 'tsconfig.json', // default
69
- // Add extra loaders
70
- loaders: {
71
- // Add .json files support
72
- // require @rollup/plugin-commonjs
73
- '.json': 'json',
74
- // Enable JSX in .js files too
75
- // '.js': 'jsx',
76
- },
77
- }),
78
- ],
79
-
80
- treeshake: {
81
- propertyReadSideEffects: false,
82
- },
83
- },
84
- outputOptions: {
85
- chunkFileNames: () => `_[name]-[hash]${outputExt}`,
86
- dir: outDir,
87
- entryFileNames: () => `[name]${outputExt}`,
88
- format,
89
- esModule: false,
90
- exports: 'auto',
91
- freeze: false,
92
- sourcemap: true,
93
- },
94
- }
95
- }
@@ -1 +0,0 @@
1
- export * from './rollup'