@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,96 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import path from 'path'
4
- import chalk from 'chalk'
5
- import {rollup} from 'rollup'
6
- import {PackageSubPathExportEntry} from '../../../core'
7
- import {_BuildContext} from '../../_types'
8
- import {_resolveRollupConfig} from './_resolveRollupConfig'
9
-
10
- /**
11
- * @internal
12
- */
13
- export interface _RollupTask {
14
- type: 'rollup'
15
- buildId: string
16
- entries: (PackageSubPathExportEntry & {path: string})[]
17
- runtime: 'node' | 'web'
18
- format: 'commonjs' | 'esm'
19
- target: string[]
20
- }
21
-
22
- export async function _rollupTask(ctx: _BuildContext, buildTask: _RollupTask): Promise<void> {
23
- console.log('=================================================================================')
24
-
25
- console.log(chalk.gray('task '), 'rollup')
26
- console.log(chalk.gray('target '), buildTask.target.join(', '))
27
- console.log(chalk.gray('format '), buildTask.format)
28
-
29
- const {cwd, files, dist: outDir, pkg} = ctx
30
-
31
- const {inputOptions, outputOptions} = _resolveRollupConfig(ctx, buildTask)
32
-
33
- // Create bundle
34
- const bundle = await rollup(inputOptions)
35
-
36
- // an array of file names this bundle depends on
37
- // console.log(bundle.watchFiles)
38
-
39
- // generate output specific code in-memory
40
- // you can call this function multiple times on the same bundle object
41
- const {output} = await bundle.generate(outputOptions)
42
-
43
- for (const chunkOrAsset of output) {
44
- if (chunkOrAsset.type === 'asset') {
45
- files.push({
46
- type: 'asset',
47
- path: path.resolve(outDir, chunkOrAsset.fileName),
48
- })
49
- } else {
50
- files.push({
51
- type: 'chunk',
52
- path: path.resolve(outDir, chunkOrAsset.fileName),
53
- })
54
- }
55
- }
56
-
57
- // or write the bundle to disk
58
- await bundle.write(outputOptions)
59
-
60
- // closes the bundle
61
- await bundle.close()
62
-
63
- for (const entry of buildTask.entries) {
64
- console.log(`- ${path.join(pkg.name, entry.path)}`)
65
-
66
- console.log(chalk.gray(' source '), path.relative(cwd, path.resolve(cwd, entry.source)))
67
-
68
- const defaultFile = files.find(
69
- (f) => entry.default && f.path === path.resolve(cwd, entry.default)
70
- )
71
-
72
- const requireFile = files.find(
73
- (f) => entry.require && f.path === path.resolve(cwd, entry.require)
74
- )
75
-
76
- const typesFile = files.find((f) => entry.types && f.path === path.resolve(cwd, entry.types))
77
-
78
- if (buildTask.format.includes('esm'))
79
- console.log(
80
- chalk.gray(' default '),
81
- defaultFile ? path.relative(cwd, defaultFile.path) : undefined
82
- )
83
-
84
- if (buildTask.format.includes('commonjs'))
85
- console.log(
86
- chalk.gray(' require '),
87
- requireFile ? path.relative(cwd, requireFile.path) : undefined
88
- )
89
-
90
- if (entry.types)
91
- console.log(
92
- chalk.gray(' types '),
93
- typesFile ? path.relative(cwd, typesFile.path) : undefined
94
- )
95
- }
96
- }
package/src/cli.ts DELETED
@@ -1,25 +0,0 @@
1
- import cac from 'cac'
2
- import {build} from './build'
3
-
4
- const cli = cac()
5
-
6
- cli
7
- .command('build', 'Build package')
8
- .option('--extract', 'Extract API reference')
9
- .option('--tsconfig [tsconfig]', '[string] tsconfig.json')
10
- .action(async (options) => {
11
- await build({
12
- cwd: process.cwd(),
13
- extract: options.extract ? Boolean(options.extract) : undefined,
14
- tsconfig: options.tsconfig,
15
- })
16
- })
17
-
18
- // Display help message when `-h` or `--help` appears
19
- cli.help()
20
-
21
- // Display version number when `-v` or `--version` appears
22
- // It's also used in help message
23
- cli.version('0.0.0')
24
-
25
- cli.parse()
@@ -1,9 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export const _DEFAULTS = {
5
- target: {
6
- node: ['node12'],
7
- web: ['chrome58', 'edge16', 'firefox54', 'opera44', 'safari11'],
8
- },
9
- }
@@ -1,12 +0,0 @@
1
- import {ConfigProperty, ConfigPropertyResolver} from './types'
2
-
3
- /**
4
- * @internal
5
- */
6
- export function _resolveConfigProperty<T>(prop: ConfigProperty<T>, initialValue: T): T {
7
- if (typeof prop === 'function') {
8
- return (prop as ConfigPropertyResolver<T>)(initialValue)
9
- }
10
-
11
- return prop
12
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * @public
3
- */
4
- export interface PackageSubPathExportEntry {
5
- runtime?: 'node' | 'web'
6
-
7
- // paths
8
- source: string
9
- require?: string
10
- default?: string
11
- types?: string
12
- }
13
-
14
- /**
15
- * @public
16
- */
17
- export type ConfigPropertyResolver<T> = (prev: T) => T
18
-
19
- /**
20
- * @public
21
- */
22
- export type ConfigProperty<T> = ConfigPropertyResolver<T> | T
23
-
24
- /**
25
- * @public
26
- */
27
- export interface PackageExports {
28
- [path: string]: PackageSubPathExportEntry
29
- }
30
-
31
- /**
32
- * @public
33
- */
34
- export interface PkgConfigOptions {
35
- /**
36
- * Directory of distributed & bundled files.
37
- */
38
- dist?: string
39
- exports?: ConfigProperty<PackageExports>
40
- /**
41
- * Packages to exclude from the bundles.
42
- */
43
- external?: ConfigProperty<string[]>
44
- /**
45
- * Default runtime of package exports
46
- */
47
- runtime?: 'node' | 'web'
48
- /**
49
- * Directory of source files.
50
- */
51
- src?: string
52
- target?: {
53
- node?: string[]
54
- web?: string[]
55
- }
56
- }
@@ -1,13 +0,0 @@
1
- import pkgUp from 'pkg-up'
2
- import {_PackageJSON} from './_types'
3
-
4
- /**
5
- * @internal
6
- */
7
- export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
8
- const {cwd} = options
9
-
10
- const pkgPath = await pkgUp({cwd})
11
-
12
- return pkgPath ? require(pkgPath) : undefined
13
- }
@@ -1,40 +0,0 @@
1
- import {_isRecord} from '../_isRecord'
2
- import {PackageSubPathExportEntry} from '../config'
3
- import {_PackageJSON} from './_types'
4
-
5
- /**
6
- * @internal
7
- */
8
- export function _parseExports(pkg: _PackageJSON): (PackageSubPathExportEntry & {path: string})[] {
9
- const rootExport: PackageSubPathExportEntry & {path: string} = {
10
- path: '.',
11
- runtime: undefined,
12
-
13
- source: pkg.source || 'index.js',
14
- require: pkg.main,
15
- default: pkg.module,
16
- types: pkg.types,
17
- }
18
-
19
- const extraExports: (PackageSubPathExportEntry & {path: string})[] = []
20
-
21
- if (pkg.exports) {
22
- for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
23
- if (_isRecord(exportEntry)) {
24
- if (exportPath === '.') {
25
- Object.assign(rootExport, exportEntry)
26
- } else {
27
- extraExports.push({
28
- path: exportPath,
29
- source: exportEntry.source,
30
- ...exportEntry,
31
- })
32
- }
33
- } else {
34
- throw new Error('string entries are not supported')
35
- }
36
- }
37
- }
38
-
39
- return [rootExport, ...extraExports]
40
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './build'
2
- export * from './core'