@sanity/pkg-utils 1.18.0 → 1.19.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 (106) hide show
  1. package/dist/_chunks/{build-f39a3550.js → build-bcb33ba5.js} +19 -19
  2. package/dist/_chunks/build-bcb33ba5.js.map +1 -0
  3. package/dist/_chunks/{buildAction-8f449d1d.js → buildAction-f240dab8.js} +6 -6
  4. package/dist/_chunks/buildAction-f240dab8.js.map +1 -0
  5. package/dist/_chunks/{check-87cbb6cc.js → check-1ea361f5.js} +26 -26
  6. package/dist/_chunks/check-1ea361f5.js.map +1 -0
  7. package/dist/_chunks/{checkAction-e7e455d4.js → checkAction-16be1201.js} +5 -5
  8. package/dist/_chunks/checkAction-16be1201.js.map +1 -0
  9. package/dist/_chunks/{_handleError-869dec25.js → handleError-65cf3242.js} +3 -3
  10. package/dist/_chunks/handleError-65cf3242.js.map +1 -0
  11. package/dist/_chunks/{index-7a851efa.js → index-79fdb33f.js} +63 -63
  12. package/dist/_chunks/index-79fdb33f.js.map +1 -0
  13. package/dist/_chunks/{_resolveBuildContext-7ca7e64e.js → resolveBuildContext-f2feec19.js} +60 -62
  14. package/dist/_chunks/resolveBuildContext-f2feec19.js.map +1 -0
  15. package/dist/_chunks/{watch-f6cf9246.js → watch-02c85f8a.js} +25 -25
  16. package/dist/_chunks/watch-02c85f8a.js.map +1 -0
  17. package/dist/_chunks/{watchAction-4cf253a0.js → watchAction-9cb9681b.js} +6 -6
  18. package/dist/_chunks/watchAction-9cb9681b.js.map +1 -0
  19. package/dist/cli.js +4 -4
  20. package/dist/index.d.ts +44 -46
  21. package/dist/index.esm.js +165 -167
  22. package/dist/index.esm.js.map +1 -1
  23. package/dist/index.js +22 -22
  24. package/dist/index.js.map +1 -1
  25. package/package.json +48 -1
  26. package/src/cli/buildAction.ts +2 -2
  27. package/src/cli/checkAction.ts +2 -2
  28. package/src/cli/{_handleError.ts → handleError.ts} +1 -1
  29. package/src/cli/watchAction.ts +2 -2
  30. package/src/node/build.ts +11 -11
  31. package/src/node/check.ts +11 -11
  32. package/src/node/{_core → core}/config/defineConfig.ts +0 -0
  33. package/src/node/{_core/config/_findConfigFile.ts → core/config/findConfigFile.ts} +3 -3
  34. package/src/node/core/config/index.ts +4 -0
  35. package/src/node/{_core/config/_loadConfig.ts → core/config/loadConfig.ts} +3 -3
  36. package/src/node/{_core/config/_resolveConfigProperty.ts → core/config/resolveConfigProperty.ts} +1 -1
  37. package/src/node/{_core → core}/config/types.ts +0 -0
  38. package/src/node/{_core/_constants.ts → core/constants.ts} +1 -1
  39. package/src/node/{_core → core}/contexts/buildContext.ts +5 -5
  40. package/src/node/{_core → core}/contexts/index.ts +0 -0
  41. package/src/node/core/defaults.ts +7 -0
  42. package/src/node/core/findCommonPath.test.ts +9 -0
  43. package/src/node/{_core/_findCommonPath.ts → core/findCommonPath.ts} +3 -3
  44. package/src/node/{_core → core}/index.ts +3 -3
  45. package/src/node/{_core/_isRecord.ts → core/isRecord.ts} +1 -1
  46. package/src/node/core/pkg/index.ts +4 -0
  47. package/src/node/{_core/pkg/_loadPkg.ts → core/pkg/loadPkg.ts} +4 -4
  48. package/src/node/{_core/pkg/_loadPkgWithReporting.ts → core/pkg/loadPkgWithReporting.ts} +6 -6
  49. package/src/node/{_core/pkg/_parseExports.ts → core/pkg/parseExports.ts} +7 -7
  50. package/src/node/{_core/pkg/_types.ts → core/pkg/types.ts} +1 -1
  51. package/src/node/{_core/pkg/_validateExports.ts → core/pkg/validateExports.ts} +5 -5
  52. package/src/node/{_core/pkg/_validatePkg.ts → core/pkg/validatePkg.ts} +2 -2
  53. package/src/node/core/ts/index.ts +1 -0
  54. package/src/node/{_core/ts/_loadTSConfig.ts → core/ts/loadTSConfig.ts} +1 -1
  55. package/src/node/{_getFilesize.ts → getFilesize.ts} +1 -1
  56. package/src/node/globFiles.ts +5 -0
  57. package/src/node/index.ts +3 -3
  58. package/src/node/{_printExtractMessages.ts → printExtractMessages.ts} +2 -2
  59. package/src/node/{_printPackageTree.ts → printPackageTree.ts} +17 -17
  60. package/src/node/{_resolveBrowserTarget.ts → resolveBrowserTarget.ts} +2 -2
  61. package/src/node/{_resolveBrowserslistVersions.ts → resolveBrowserslistVersions.ts} +11 -11
  62. package/src/node/{_resolveBuildContext.ts → resolveBuildContext.ts} +28 -28
  63. package/src/node/{_resolveBuildTasks.ts → resolveBuildTasks.ts} +13 -13
  64. package/src/node/{_resolveNodeTarget.ts → resolveNodeTarget.ts} +2 -2
  65. package/src/node/{_resolveWatchTasks.ts → resolveWatchTasks.ts} +11 -11
  66. package/src/node/{_spinner.ts → spinner.ts} +1 -1
  67. package/src/node/{_tasks/dts/_DtsError.ts → tasks/dts/DtsError.ts} +1 -1
  68. package/src/node/{_tasks/dts/_buildTypes.ts → tasks/dts/buildTypes.ts} +1 -1
  69. package/src/node/{_tasks/dts/_createApiExtractorConfig.ts → tasks/dts/createApiExtractorConfig.ts} +1 -1
  70. package/src/node/{_tasks/dts/_createTSDocConfig.ts → tasks/dts/createTSDocConfig.ts} +1 -1
  71. package/src/node/{_tasks/dts/_doExtract.ts → tasks/dts/doExtract.ts} +12 -12
  72. package/src/node/{_tasks/dts/_dtsTask.ts → tasks/dts/dtsTask.ts} +10 -10
  73. package/src/node/{_tasks/dts/_dtsWatchTask.ts → tasks/dts/dtsWatchTask.ts} +10 -10
  74. package/src/node/{_tasks/dts/_extractModuleBlocks.ts → tasks/dts/extractModuleBlocks.ts} +3 -3
  75. package/src/node/{_tasks/dts/_extractTypes.ts → tasks/dts/extractTypes.ts} +11 -11
  76. package/src/node/{_tasks/dts/_getExtractMessagesConfig.ts → tasks/dts/getExtractMessagesConfig.ts} +12 -12
  77. package/src/node/tasks/dts/index.ts +4 -0
  78. package/src/node/{_tasks/dts/_types.ts → tasks/dts/types.ts} +3 -3
  79. package/src/node/tasks/index.ts +19 -0
  80. package/src/node/tasks/rollup/index.ts +2 -0
  81. package/src/node/{_tasks/rollup/_resolveRollupConfig.ts → tasks/rollup/resolveRollupConfig.ts} +16 -11
  82. package/src/node/{_tasks/rollup/_rollupTask.ts → tasks/rollup/rollupTask.ts} +7 -7
  83. package/src/node/{_tasks/rollup/_rollupWatchTask.ts → tasks/rollup/rollupWatchTask.ts} +4 -4
  84. package/src/node/tasks/types.ts +57 -0
  85. package/src/node/watch.ts +13 -13
  86. package/src/node/{_watchConfigFiles.ts → watchConfigFiles.ts} +5 -5
  87. package/src/node/{_watchFiles.ts → watchFiles.ts} +5 -5
  88. package/dist/_chunks/_handleError-869dec25.js.map +0 -1
  89. package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +0 -1
  90. package/dist/_chunks/build-f39a3550.js.map +0 -1
  91. package/dist/_chunks/buildAction-8f449d1d.js.map +0 -1
  92. package/dist/_chunks/check-87cbb6cc.js.map +0 -1
  93. package/dist/_chunks/checkAction-e7e455d4.js.map +0 -1
  94. package/dist/_chunks/index-7a851efa.js.map +0 -1
  95. package/dist/_chunks/watch-f6cf9246.js.map +0 -1
  96. package/dist/_chunks/watchAction-4cf253a0.js.map +0 -1
  97. package/src/node/_core/_defaults.ts +0 -9
  98. package/src/node/_core/_findCommonPath.test.ts +0 -9
  99. package/src/node/_core/config/index.ts +0 -4
  100. package/src/node/_core/pkg/index.ts +0 -4
  101. package/src/node/_core/ts/index.ts +0 -1
  102. package/src/node/_globFiles.ts +0 -5
  103. package/src/node/_tasks/_types.ts +0 -57
  104. package/src/node/_tasks/dts/index.ts +0 -4
  105. package/src/node/_tasks/index.ts +0 -19
  106. package/src/node/_tasks/rollup/index.ts +0 -2
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  });
6
- var _resolveBuildContext = require('./_chunks/_resolveBuildContext-7ca7e64e.js');
7
- var build = require('./_chunks/build-f39a3550.js');
8
- var index = require('./_chunks/index-7a851efa.js');
9
- var check = require('./_chunks/check-87cbb6cc.js');
10
- var watch = require('./_chunks/watch-f6cf9246.js');
6
+ var resolveBuildContext = require('./_chunks/resolveBuildContext-f2feec19.js');
7
+ var build = require('./_chunks/build-bcb33ba5.js');
8
+ var index = require('./_chunks/index-79fdb33f.js');
9
+ var check = require('./_chunks/check-1ea361f5.js');
10
+ var watch = require('./_chunks/watch-02c85f8a.js');
11
11
  require('path');
12
12
  require('esbuild-register/dist/node');
13
13
  require('pkg-up');
@@ -46,24 +46,24 @@ require('chokidar');
46
46
  function defineConfig(configOptions) {
47
47
  return configOptions;
48
48
  }
49
- exports._DEFAULTS = _resolveBuildContext._DEFAULTS;
50
- exports._MODULE_EXT = _resolveBuildContext._MODULE_EXT;
51
- exports._isRecord = _resolveBuildContext._isRecord;
52
- exports._loadConfig = _resolveBuildContext._loadConfig;
53
- exports._loadPkg = _resolveBuildContext._loadPkg;
54
- exports._loadPkgWithReporting = _resolveBuildContext._loadPkgWithReporting;
55
- exports._loadTSConfig = _resolveBuildContext._loadTSConfig;
56
- exports._parseExports = _resolveBuildContext._parseExports;
57
- exports._resolveConfigProperty = _resolveBuildContext._resolveConfigProperty;
58
- exports._resolveBuildTasks = build._resolveBuildTasks;
49
+ exports.DEFAULT_BROWSERSLIST_QUERY = resolveBuildContext.DEFAULT_BROWSERSLIST_QUERY;
50
+ exports.MODULE_EXT = resolveBuildContext.MODULE_EXT;
51
+ exports.isRecord = resolveBuildContext.isRecord;
52
+ exports.loadConfig = resolveBuildContext.loadConfig;
53
+ exports.loadPkg = resolveBuildContext.loadPkg;
54
+ exports.loadPkgWithReporting = resolveBuildContext.loadPkgWithReporting;
55
+ exports.loadTSConfig = resolveBuildContext.loadTSConfig;
56
+ exports.parseExports = resolveBuildContext.parseExports;
57
+ exports.resolveConfigProperty = resolveBuildContext.resolveConfigProperty;
59
58
  exports.build = build.build;
60
- exports._buildTaskHandlers = index._buildTaskHandlers;
61
- exports._dtsTask = index._dtsTask;
62
- exports._dtsWatchTask = index._dtsWatchTask;
63
- exports._getExtractMessagesConfig = index._getExtractMessagesConfig;
64
- exports._rollupTask = index._rollupTask;
65
- exports._rollupWatchTask = index._rollupWatchTask;
66
- exports._watchTaskHandlers = index._watchTaskHandlers;
59
+ exports.resolveBuildTasks = build.resolveBuildTasks;
60
+ exports.buildTaskHandlers = index.buildTaskHandlers;
61
+ exports.dtsTask = index.dtsTask;
62
+ exports.dtsWatchTask = index.dtsWatchTask;
63
+ exports.getExtractMessagesConfig = index.getExtractMessagesConfig;
64
+ exports.rollupTask = index.rollupTask;
65
+ exports.rollupWatchTask = index.rollupWatchTask;
66
+ exports.watchTaskHandlers = index.watchTaskHandlers;
67
67
  exports.check = check.check;
68
68
  exports.watch = watch.watch;
69
69
  exports.defineConfig = defineConfig;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/node/_core/config/defineConfig.ts"],"sourcesContent":["import {PkgConfigOptions} from './types'\n\n/** @public */\nexport function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions {\n return configOptions\n}\n"],"names":["defineConfig","configOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAASA,YAAY,CAACC,aAAa,EAAE;EAC1C,OAAOA,aAAa;AACtB;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/node/core/config/defineConfig.ts"],"sourcesContent":["import {PkgConfigOptions} from './types'\n\n/** @public */\nexport function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions {\n return configOptions\n}\n"],"names":["defineConfig","configOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAASA,YAAY,CAACC,aAAa,EAAE;EAC1C,OAAOA,aAAa;AACtB;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/pkg-utils",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "author": "Sanity.io <hello@sanity.io>",
5
5
  "license": "MIT",
6
6
  "description": "Simple utilities for modern npm packages.",
@@ -140,6 +140,11 @@
140
140
  "url": "https://github.com/sanity-io/pkg-utils/issues"
141
141
  },
142
142
  "homepage": "https://github.com/sanity-io/pkg-utils#readme",
143
+ "commitlint": {
144
+ "extends": [
145
+ "@commitlint/config-conventional"
146
+ ]
147
+ },
143
148
  "publishConfig": {
144
149
  "access": "public"
145
150
  },
@@ -148,5 +153,47 @@
148
153
  "overrides": {
149
154
  "@sanity/pkg-utils": "workspace:*"
150
155
  }
156
+ },
157
+ "prettier": {
158
+ "bracketSpacing": false,
159
+ "printWidth": 100,
160
+ "semi": false,
161
+ "singleQuote": true,
162
+ "tabWidth": 2,
163
+ "overrides": [
164
+ {
165
+ "files": [
166
+ "*.json5"
167
+ ],
168
+ "options": {
169
+ "singleQuote": false,
170
+ "quoteProps": "preserve"
171
+ }
172
+ },
173
+ {
174
+ "files": [
175
+ "*.yml"
176
+ ],
177
+ "options": {
178
+ "singleQuote": false
179
+ }
180
+ }
181
+ ]
182
+ },
183
+ "release": {
184
+ "extends": "@sanity/semantic-release-preset",
185
+ "branches": [
186
+ "+([0-9])?(.{+([0-9]),x}).x",
187
+ "main",
188
+ "next",
189
+ {
190
+ "name": "beta",
191
+ "prerelease": true
192
+ },
193
+ {
194
+ "name": "alpha",
195
+ "prerelease": true
196
+ }
197
+ ]
151
198
  }
152
199
  }
@@ -1,5 +1,5 @@
1
1
  import {build} from '../node/build'
2
- import {_handleError} from './_handleError'
2
+ import {handleError} from './handleError'
3
3
 
4
4
  export async function buildAction(options: {
5
5
  emitDeclarationOnly?: boolean
@@ -14,6 +14,6 @@ export async function buildAction(options: {
14
14
  tsconfig: options.tsconfig,
15
15
  })
16
16
  } catch (err) {
17
- _handleError(err)
17
+ handleError(err)
18
18
  }
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import {check} from '../node/check'
2
- import {_handleError} from './_handleError'
2
+ import {handleError} from './handleError'
3
3
 
4
4
  export async function checkAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {
5
5
  try {
@@ -9,6 +9,6 @@ export async function checkAction(options: {strict?: boolean; tsconfig?: string}
9
9
  tsconfig: options.tsconfig,
10
10
  })
11
11
  } catch (err) {
12
- _handleError(err)
12
+ handleError(err)
13
13
  }
14
14
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import chalk from 'chalk'
4
4
 
5
- export function _handleError(err: unknown): void {
5
+ export function handleError(err: unknown): void {
6
6
  if (err instanceof Error) {
7
7
  console.error(chalk.red('error'), err.message)
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import {watch} from '../node/watch'
2
- import {_handleError} from './_handleError'
2
+ import {handleError} from './handleError'
3
3
 
4
4
  export async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {
5
5
  try {
@@ -9,6 +9,6 @@ export async function watchAction(options: {strict?: boolean; tsconfig?: string}
9
9
  tsconfig: options.tsconfig,
10
10
  })
11
11
  } catch (err) {
12
- _handleError(err)
12
+ handleError(err)
13
13
  }
14
14
  }
package/src/node/build.ts CHANGED
@@ -1,8 +1,8 @@
1
- import {_loadConfig, _loadPkgWithReporting} from './_core'
2
- import {_resolveBuildContext} from './_resolveBuildContext'
3
- import {_resolveBuildTasks} from './_resolveBuildTasks'
4
- import {_spinner} from './_spinner'
5
- import {_BuildTask, _TaskHandler, _buildTaskHandlers} from './_tasks'
1
+ import {loadConfig, loadPkgWithReporting} from './core'
2
+ import {resolveBuildContext} from './resolveBuildContext'
3
+ import {resolveBuildTasks} from './resolveBuildTasks'
4
+ import {createSpinner} from './spinner'
5
+ import {BuildTask, TaskHandler, buildTaskHandlers} from './tasks'
6
6
 
7
7
  /**
8
8
  * Build the distribution files of a npm package.
@@ -31,18 +31,18 @@ export async function build(options: {
31
31
  }): Promise<void> {
32
32
  const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options
33
33
 
34
- const pkg = await _loadPkgWithReporting({cwd})
35
- const config = await _loadConfig({cwd})
34
+ const pkg = await loadPkgWithReporting({cwd})
35
+ const config = await loadConfig({cwd})
36
36
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
37
- const ctx = await _resolveBuildContext({config, cwd, emitDeclarationOnly, pkg, strict, tsconfig})
37
+ const ctx = await resolveBuildContext({config, cwd, emitDeclarationOnly, pkg, strict, tsconfig})
38
38
 
39
- const buildTasks = _resolveBuildTasks(ctx)
39
+ const buildTasks = resolveBuildTasks(ctx)
40
40
 
41
41
  for (const task of buildTasks) {
42
- const handler = _buildTaskHandlers[task.type] as _TaskHandler<_BuildTask>
42
+ const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>
43
43
  const taskName = handler.name(ctx, task)
44
44
 
45
- const spinner = _spinner(taskName)
45
+ const spinner = createSpinner(taskName)
46
46
 
47
47
  try {
48
48
  const result = await handler.exec(ctx, task).toPromise()
package/src/node/check.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from 'path'
2
2
  import esbuild, {BuildFailure} from 'esbuild'
3
- import {_loadConfig, _loadPkgWithReporting} from './_core'
4
- import {_fileExists, _printPackageTree} from './_printPackageTree'
5
- import {_resolveBuildContext} from './_resolveBuildContext'
3
+ import {loadConfig, loadPkgWithReporting} from './core'
4
+ import {fileExists, printPackageTree} from './printPackageTree'
5
+ import {resolveBuildContext} from './resolveBuildContext'
6
6
 
7
7
  /** @public */
8
8
  export async function check(options: {
@@ -12,32 +12,32 @@ export async function check(options: {
12
12
  }): Promise<void> {
13
13
  const {cwd, strict = false, tsconfig: tsconfigOption} = options
14
14
 
15
- const pkg = await _loadPkgWithReporting({cwd})
16
- const config = await _loadConfig({cwd})
15
+ const pkg = await loadPkgWithReporting({cwd})
16
+ const config = await loadConfig({cwd})
17
17
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
18
- const ctx = await _resolveBuildContext({config, cwd, pkg, strict, tsconfig})
18
+ const ctx = await resolveBuildContext({config, cwd, pkg, strict, tsconfig})
19
19
  const {logger} = ctx
20
20
 
21
- _printPackageTree(ctx)
21
+ printPackageTree(ctx)
22
22
 
23
23
  if (strict) {
24
24
  const missingFiles: string[] = []
25
25
 
26
26
  // Check if there are missing files
27
27
  for (const [, exp] of Object.entries(ctx.exports || {})) {
28
- if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
28
+ if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {
29
29
  missingFiles.push(exp.source)
30
30
  }
31
31
 
32
- if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
32
+ if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {
33
33
  missingFiles.push(exp.require)
34
34
  }
35
35
 
36
- if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
36
+ if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {
37
37
  missingFiles.push(exp.import)
38
38
  }
39
39
 
40
- if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
40
+ if (exp.types && !fileExists(path.resolve(cwd, exp.types))) {
41
41
  missingFiles.push(exp.types)
42
42
  }
43
43
  }
File without changes
@@ -9,7 +9,7 @@ const CONFIG_FILE_NAMES = [
9
9
  'package.config.mjs',
10
10
  ]
11
11
 
12
- export async function _findConfigFile(cwd: string): Promise<string | undefined> {
12
+ export async function findConfigFile(cwd: string): Promise<string | undefined> {
13
13
  const pkgJsonPath = findConfig('package.json', {cwd})
14
14
 
15
15
  if (!pkgJsonPath) return undefined
@@ -19,7 +19,7 @@ export async function _findConfigFile(cwd: string): Promise<string | undefined>
19
19
  for (const fileName of CONFIG_FILE_NAMES) {
20
20
  const configPath = path.resolve(pkgPath, fileName)
21
21
 
22
- const exists = await _fileExists(configPath)
22
+ const exists = await fileExists(configPath)
23
23
 
24
24
  if (exists) {
25
25
  return configPath
@@ -29,7 +29,7 @@ export async function _findConfigFile(cwd: string): Promise<string | undefined>
29
29
  return undefined
30
30
  }
31
31
 
32
- async function _fileExists(filePath: string) {
32
+ async function fileExists(filePath: string) {
33
33
  try {
34
34
  await stat(filePath)
35
35
 
@@ -0,0 +1,4 @@
1
+ export * from './loadConfig'
2
+ export * from './resolveConfigProperty'
3
+ export * from './defineConfig'
4
+ export * from './types'
@@ -1,11 +1,11 @@
1
1
  import path from 'path'
2
2
  import {register} from 'esbuild-register/dist/node'
3
3
  import pkgUp from 'pkg-up'
4
- import {_findConfigFile} from './_findConfigFile'
4
+ import {findConfigFile} from './findConfigFile'
5
5
  import {PkgConfigOptions} from './types'
6
6
 
7
7
  /** @internal */
8
- export async function _loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
8
+ export async function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
9
9
  const {cwd} = options
10
10
 
11
11
  const pkgPath = await pkgUp({cwd})
@@ -14,7 +14,7 @@ export async function _loadConfig(options: {cwd: string}): Promise<PkgConfigOpti
14
14
 
15
15
  const root = path.dirname(pkgPath)
16
16
 
17
- const configFile = await _findConfigFile(root)
17
+ const configFile = await findConfigFile(root)
18
18
 
19
19
  if (!configFile) {
20
20
  return undefined
@@ -1,7 +1,7 @@
1
1
  import {PkgConfigProperty, PkgConfigPropertyResolver} from './types'
2
2
 
3
3
  /** @internal */
4
- export function _resolveConfigProperty<T>(
4
+ export function resolveConfigProperty<T>(
5
5
  prop: PkgConfigProperty<T> | undefined,
6
6
  initialValue: T
7
7
  ): T {
File without changes
@@ -1,5 +1,5 @@
1
1
  /** @internal */
2
- export const _MODULE_EXT: Record<'commonjs' | 'module', {commonjs: string; esm: string}> = {
2
+ export const MODULE_EXT: Record<'commonjs' | 'module', {commonjs: string; esm: string}> = {
3
3
  // pkg.type: "commonjs"
4
4
  commonjs: {
5
5
  commonjs: '.js',
@@ -1,22 +1,22 @@
1
1
  import ts from 'typescript'
2
2
  import {PkgExports, PkgRuntime, PkgConfigOptions} from '../config'
3
- import {_PackageJSON} from '../pkg'
3
+ import {PackageJSON} from '../pkg'
4
4
 
5
5
  /** @internal */
6
- export interface _BuildFile {
6
+ export interface BuildFile {
7
7
  type: 'asset' | 'chunk' | 'types'
8
8
  path: string
9
9
  }
10
10
 
11
11
  /** @internal */
12
- export interface _BuildContext {
12
+ export interface BuildContext {
13
13
  config?: PkgConfigOptions
14
14
  cwd: string
15
15
  distPath: string
16
16
  emitDeclarationOnly: boolean
17
17
  exports: PkgExports | undefined
18
18
  external: string[]
19
- files: _BuildFile[]
19
+ files: BuildFile[]
20
20
  logger: {
21
21
  log: (...args: unknown[]) => void
22
22
  info: (...args: unknown[]) => void
@@ -24,7 +24,7 @@ export interface _BuildContext {
24
24
  error: (...args: unknown[]) => void
25
25
  success: (...args: unknown[]) => void
26
26
  }
27
- pkg: _PackageJSON
27
+ pkg: PackageJSON
28
28
  runtime: PkgRuntime
29
29
  strict: boolean
30
30
  target: Record<PkgRuntime, string[]>
File without changes
@@ -0,0 +1,7 @@
1
+ /** @public */
2
+ export const DEFAULT_BROWSERSLIST_QUERY = [
3
+ '> 0.2% and supports es6-module and supports es6-module-dynamic-import',
4
+ 'not dead',
5
+ 'not IE 11',
6
+ 'maintained node versions',
7
+ ]
@@ -0,0 +1,9 @@
1
+ import {expect, test} from 'vitest'
2
+ import {findCommonDirPath} from './findCommonPath'
3
+
4
+ test('should find common parent directory of paths', () => {
5
+ expect(findCommonDirPath(['test/a', 'test/b/a'])).toBe('test')
6
+ expect(findCommonDirPath(['/test/a', '/test/b/a'])).toBe('/test')
7
+ expect(findCommonDirPath(['/test/a/b', '/test/a/b/c'])).toBe('/test/a')
8
+ expect(findCommonDirPath(['test/a/b', 'test/a/b', 'test/b/c', 'test/b/a'])).toBe('test')
9
+ })
@@ -1,10 +1,10 @@
1
1
  import path from 'path'
2
2
 
3
- export function _pathContains(containerPath: string, itemPath: string): boolean {
3
+ export function pathContains(containerPath: string, itemPath: string): boolean {
4
4
  return !path.relative(containerPath, itemPath).startsWith('..')
5
5
  }
6
6
 
7
- export function _findCommonDirPath(filePaths: string[]): string | undefined {
7
+ export function findCommonDirPath(filePaths: string[]): string | undefined {
8
8
  let ret: string | undefined = undefined
9
9
 
10
10
  for (const filePath of filePaths) {
@@ -22,7 +22,7 @@ export function _findCommonDirPath(filePaths: string[]): string | undefined {
22
22
  break
23
23
  }
24
24
 
25
- if (_pathContains(dirPath, ret)) {
25
+ if (pathContains(dirPath, ret)) {
26
26
  ret = dirPath
27
27
  break
28
28
  }
@@ -1,6 +1,6 @@
1
- export * from './_constants'
2
- export * from './_defaults'
3
- export * from './_isRecord'
1
+ export * from './constants'
2
+ export * from './defaults'
3
+ export * from './isRecord'
4
4
  export * from './config'
5
5
  export * from './contexts'
6
6
  export * from './pkg'
@@ -1,4 +1,4 @@
1
1
  /** @internal */
2
- export function _isRecord(value: unknown): value is Record<string, unknown> {
2
+ export function isRecord(value: unknown): value is Record<string, unknown> {
3
3
  return Boolean(value) && !Array.isArray(value) && typeof value === 'object'
4
4
  }
@@ -0,0 +1,4 @@
1
+ export * from './loadPkg'
2
+ export * from './loadPkgWithReporting'
3
+ export * from './parseExports'
4
+ export * from './types'
@@ -1,10 +1,10 @@
1
1
  import fs from 'fs/promises'
2
2
  import pkgUp from 'pkg-up'
3
- import {_PackageJSON} from './_types'
4
- import {_validatePkg} from './_validatePkg'
3
+ import {PackageJSON} from './types'
4
+ import {validatePkg} from './validatePkg'
5
5
 
6
6
  /** @internal */
7
- export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
7
+ export async function loadPkg(options: {cwd: string}): Promise<PackageJSON> {
8
8
  const {cwd} = options
9
9
 
10
10
  const pkgPath = await pkgUp({cwd})
@@ -13,5 +13,5 @@ export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
13
13
 
14
14
  const buf = await fs.readFile(pkgPath)
15
15
 
16
- return _validatePkg(JSON.parse(buf.toString()))
16
+ return validatePkg(JSON.parse(buf.toString()))
17
17
  }
@@ -2,20 +2,20 @@
2
2
 
3
3
  import chalk from 'chalk'
4
4
  import {ZodError} from 'zod'
5
- import {_loadPkg} from './_loadPkg'
6
- import {_PackageJSON} from './_types'
5
+ import {loadPkg} from './loadPkg'
6
+ import {PackageJSON} from './types'
7
7
 
8
8
  /** @internal */
9
- export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_PackageJSON> {
9
+ export async function loadPkgWithReporting(options: {cwd: string}): Promise<PackageJSON> {
10
10
  try {
11
- return await _loadPkg(options)
11
+ return await loadPkg(options)
12
12
  } catch (err) {
13
13
  if (err instanceof ZodError) {
14
14
  for (const issue of err.issues) {
15
15
  if (issue.code === 'invalid_type') {
16
16
  console.log(
17
17
  [
18
- `${chalk.red('fail')} \`${_formatPath(issue.path)}\` `,
18
+ `${chalk.red('fail')} \`${formatPath(issue.path)}\` `,
19
19
  `in ./package.json must be of type ${chalk.magenta(issue.expected)} `,
20
20
  `(received ${chalk.magenta(issue.received)})`,
21
21
  ].join('')
@@ -30,7 +30,7 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa
30
30
  }
31
31
  }
32
32
 
33
- function _formatPath(segments: Array<string | number>) {
33
+ function formatPath(segments: Array<string | number>) {
34
34
  return segments
35
35
  .map((s, idx) => {
36
36
  if (idx === 0) return s
@@ -1,11 +1,11 @@
1
- import {_isRecord} from '../_isRecord'
2
1
  import {PkgExport} from '../config'
3
- import {_PackageJSON} from './_types'
4
- import {_validateExports} from './_validateExports'
2
+ import {isRecord} from '../isRecord'
3
+ import {PackageJSON} from './types'
4
+ import {validateExports} from './validateExports'
5
5
 
6
6
  /** @internal */
7
- export function _parseExports(options: {
8
- pkg: _PackageJSON
7
+ export function parseExports(options: {
8
+ pkg: PackageJSON
9
9
  strict: boolean
10
10
  }): (PkgExport & {_path: string})[] {
11
11
  const {pkg, strict} = options
@@ -41,7 +41,7 @@ export function _parseExports(options: {
41
41
  errors.push('package.json: `exports["./package.json"] must be "./package.json".')
42
42
  }
43
43
  }
44
- } else if (_isRecord(exportEntry)) {
44
+ } else if (isRecord(exportEntry)) {
45
45
  if (exportPath === '.') {
46
46
  if (
47
47
  exportEntry.require &&
@@ -89,7 +89,7 @@ export function _parseExports(options: {
89
89
 
90
90
  const _exports = [rootExport, ...extraExports]
91
91
 
92
- errors.push(..._validateExports(_exports, {pkg}))
92
+ errors.push(...validateExports(_exports, {pkg}))
93
93
 
94
94
  if (errors.length) {
95
95
  throw new Error('\n- ' + errors.join('\n- '))
@@ -1,5 +1,5 @@
1
1
  /** @internal */
2
- export interface _PackageJSON {
2
+ export interface PackageJSON {
3
3
  type: 'commonjs' | 'module'
4
4
  version: string
5
5
  private?: boolean
@@ -1,13 +1,13 @@
1
- import {_MODULE_EXT} from '../_constants'
2
1
  import {PkgExport} from '../config'
3
- import {_PackageJSON} from './_types'
2
+ import {MODULE_EXT} from '../constants'
3
+ import {PackageJSON} from './types'
4
4
 
5
- export function _validateExports(
5
+ export function validateExports(
6
6
  _exports: (PkgExport & {_path: string})[],
7
- options: {pkg: _PackageJSON}
7
+ options: {pkg: PackageJSON}
8
8
  ): string[] {
9
9
  const {pkg} = options
10
- const ext = _MODULE_EXT[pkg.type]
10
+ const ext = MODULE_EXT[pkg.type]
11
11
 
12
12
  const errors: string[] = []
13
13
 
@@ -1,5 +1,5 @@
1
1
  import {z} from 'zod'
2
- import {_PackageJSON} from './_types'
2
+ import {PackageJSON} from './types'
3
3
 
4
4
  const pkgSchema = z.object({
5
5
  type: z.optional(z.enum(['commonjs', 'module'])),
@@ -46,7 +46,7 @@ const pkgSchema = z.object({
46
46
  browserslist: z.optional(z.array(z.string())),
47
47
  })
48
48
 
49
- export function _validatePkg(input: unknown): _PackageJSON {
49
+ export function validatePkg(input: unknown): PackageJSON {
50
50
  const pkg = pkgSchema.parse(input)
51
51
 
52
52
  return {...pkg, type: pkg.type || 'commonjs'}
@@ -0,0 +1 @@
1
+ export * from './loadTSConfig'
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript'
2
2
 
3
3
  /** @internal */
4
- export async function _loadTSConfig(options: {
4
+ export async function loadTSConfig(options: {
5
5
  cwd: string
6
6
  tsconfigPath: string
7
7
  }): Promise<ts.ParsedCommandLine> {
@@ -1,7 +1,7 @@
1
1
  import {statSync} from 'fs'
2
2
  import prettyBytes from 'pretty-bytes'
3
3
 
4
- export function _getFilesize(file: string): string {
4
+ export function getFilesize(file: string): string {
5
5
  const stats = statSync(file)
6
6
 
7
7
  return prettyBytes(stats.size)
@@ -0,0 +1,5 @@
1
+ import globby from 'globby'
2
+
3
+ export function globFiles(patterns: string[]): Promise<string[]> {
4
+ return globby(patterns)
5
+ }
package/src/node/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './_core'
2
- export * from './_resolveBuildTasks'
3
- export * from './_tasks'
1
+ export * from './core'
2
+ export * from './resolveBuildTasks'
3
+ export * from './tasks'
4
4
  export * from './build'
5
5
  export * from './check'
6
6
  export * from './watch'