@sanity/pkg-utils 7.2.10-canary.0 → 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 -105
  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 +486 -443
  12. package/dist/index.d.ts +486 -443
  13. package/dist/index.js +1 -2389
  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 -202
  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
@@ -1,11 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- export function handleError(err: unknown): void {
4
- if (err instanceof Error) {
5
- console.error(chalk.red('error'), err.message)
6
- } else {
7
- console.error(err)
8
- }
9
-
10
- process.exit(1)
11
- }
package/src/cli/index.ts DELETED
@@ -1,65 +0,0 @@
1
- import {cac} from 'cac'
2
- import {version} from '../../package.json'
3
-
4
- const cli = cac()
5
-
6
- cli
7
- .command('', 'Check')
8
- .alias('check') // alias to align with the action name
9
- .option('--strict', 'Strict mode')
10
- .option('--tsconfig [tsconfig]', '[string] tsconfig.json')
11
- .action(async (options) => {
12
- const {checkAction} = await import('./checkAction')
13
-
14
- return checkAction(options)
15
- })
16
-
17
- cli
18
- .command('build', 'Build package')
19
- .option('--emitDeclarationOnly', 'Emit d.ts only')
20
- .option('--strict', 'Strict mode')
21
- .option('--tsconfig [tsconfig]', '[string] tsconfig.json')
22
- .option('--check', 'Run the check command after build (same as running `pkg build && pkg check`)')
23
- .option('--clean', 'Clean the dist directory before building')
24
- .action(async (options) => {
25
- const {check = false, ...buildOptions} = options
26
- const {buildAction} = await import('./buildAction')
27
-
28
- await buildAction(buildOptions)
29
-
30
- if (check) {
31
- const {checkAction} = await import('./checkAction')
32
-
33
- await checkAction({
34
- strict: options.strict,
35
- tsconfig: options.tsconfig,
36
- })
37
- }
38
- })
39
-
40
- cli.command('init [path]', 'Initialize package').action(async (p) => {
41
- const {initAction} = await import('./initAction')
42
-
43
- return initAction({
44
- path: p,
45
- })
46
- })
47
-
48
- cli
49
- .command('watch', 'Watch package')
50
- .option('--strict', 'Strict mode')
51
- .option('--tsconfig [tsconfig]', '[string] tsconfig.json')
52
- .action(async (options) => {
53
- const {watchAction} = await import('./watchAction')
54
-
55
- return watchAction(options)
56
- })
57
-
58
- // Display help message when `-h` or `--help` appears
59
- cli.help()
60
-
61
- // Display version number when `-v` or `--version` appears
62
- // It's also used in help message
63
- cli.version(version)
64
-
65
- cli.parse()
@@ -1,13 +0,0 @@
1
- import {init} from '../node/init'
2
- import {handleError} from './handleError'
3
-
4
- export async function initAction(options: {path: string}): Promise<void> {
5
- try {
6
- await init({
7
- cwd: process.cwd(),
8
- path: options.path,
9
- })
10
- } catch (err) {
11
- handleError(err)
12
- }
13
- }
@@ -1,14 +0,0 @@
1
- import {watch} from '../node/watch'
2
- import {handleError} from './handleError'
3
-
4
- export async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {
5
- try {
6
- await watch({
7
- cwd: process.cwd(),
8
- strict: options.strict,
9
- tsconfig: options.tsconfig,
10
- })
11
- } catch (err) {
12
- handleError(err)
13
- }
14
- }
package/src/global.ts DELETED
@@ -1,5 +0,0 @@
1
- declare global {
2
- var __DEV__: boolean
3
- }
4
-
5
- export type {}
@@ -1,154 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`{'noPackageJsonTypings': 'error'}} 1`] = `
4
- {
5
- "alwaysPackageJsonFiles": "error",
6
- "alwaysPackageJsonMain": "error",
7
- "alwaysPackageJsonTypes": "error",
8
- "noImplicitBrowsersList": "warn",
9
- "noImplicitSideEffects": "warn",
10
- "noPackageJsonTypings": "error",
11
- }
12
- `;
13
-
14
- exports[`{'noPackageJsonTypings': 'off'}} 1`] = `
15
- {
16
- "alwaysPackageJsonFiles": "error",
17
- "alwaysPackageJsonMain": "error",
18
- "alwaysPackageJsonTypes": "error",
19
- "noImplicitBrowsersList": "warn",
20
- "noImplicitSideEffects": "warn",
21
- "noPackageJsonTypings": "off",
22
- }
23
- `;
24
-
25
- exports[`{'noPackageJsonTypings': 'warn'}} 1`] = `
26
- {
27
- "alwaysPackageJsonFiles": "error",
28
- "alwaysPackageJsonMain": "error",
29
- "alwaysPackageJsonTypes": "error",
30
- "noImplicitBrowsersList": "warn",
31
- "noImplicitSideEffects": "warn",
32
- "noPackageJsonTypings": "warn",
33
- }
34
- `;
35
-
36
- exports[`{'noPackageJsonTypings': false}} 1`] = `
37
- [ZodError: [
38
- {
39
- "code": "invalid_union",
40
- "unionErrors": [
41
- {
42
- "issues": [
43
- {
44
- "received": false,
45
- "code": "invalid_literal",
46
- "expected": "error",
47
- "path": [
48
- "strictOptions",
49
- "noPackageJsonTypings"
50
- ],
51
- "message": "Validation error: Invalid literal value, expected \\"error\\" at \\"strictOptions.noPackageJsonTypings\\""
52
- }
53
- ],
54
- "name": "ZodError"
55
- },
56
- {
57
- "issues": [
58
- {
59
- "received": false,
60
- "code": "invalid_literal",
61
- "expected": "warn",
62
- "path": [
63
- "strictOptions",
64
- "noPackageJsonTypings"
65
- ],
66
- "message": "Validation error: Invalid literal value, expected \\"warn\\" at \\"strictOptions.noPackageJsonTypings\\""
67
- }
68
- ],
69
- "name": "ZodError"
70
- },
71
- {
72
- "issues": [
73
- {
74
- "received": false,
75
- "code": "invalid_literal",
76
- "expected": "off",
77
- "path": [
78
- "strictOptions",
79
- "noPackageJsonTypings"
80
- ],
81
- "message": "Validation error: Invalid literal value, expected \\"off\\" at \\"strictOptions.noPackageJsonTypings\\""
82
- }
83
- ],
84
- "name": "ZodError"
85
- }
86
- ],
87
- "path": [
88
- "strictOptions",
89
- "noPackageJsonTypings"
90
- ],
91
- "message": "Validation error: Validation error: Invalid literal value, expected \\"error\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\", or Validation error: Invalid literal value, expected \\"warn\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\", or Validation error: Invalid literal value, expected \\"off\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\""
92
- }
93
- ]]
94
- `;
95
-
96
- exports[`{'noPackageJsonTypings': true}} 1`] = `
97
- [ZodError: [
98
- {
99
- "code": "invalid_union",
100
- "unionErrors": [
101
- {
102
- "issues": [
103
- {
104
- "received": true,
105
- "code": "invalid_literal",
106
- "expected": "error",
107
- "path": [
108
- "strictOptions",
109
- "noPackageJsonTypings"
110
- ],
111
- "message": "Validation error: Invalid literal value, expected \\"error\\" at \\"strictOptions.noPackageJsonTypings\\""
112
- }
113
- ],
114
- "name": "ZodError"
115
- },
116
- {
117
- "issues": [
118
- {
119
- "received": true,
120
- "code": "invalid_literal",
121
- "expected": "warn",
122
- "path": [
123
- "strictOptions",
124
- "noPackageJsonTypings"
125
- ],
126
- "message": "Validation error: Invalid literal value, expected \\"warn\\" at \\"strictOptions.noPackageJsonTypings\\""
127
- }
128
- ],
129
- "name": "ZodError"
130
- },
131
- {
132
- "issues": [
133
- {
134
- "received": true,
135
- "code": "invalid_literal",
136
- "expected": "off",
137
- "path": [
138
- "strictOptions",
139
- "noPackageJsonTypings"
140
- ],
141
- "message": "Validation error: Invalid literal value, expected \\"off\\" at \\"strictOptions.noPackageJsonTypings\\""
142
- }
143
- ],
144
- "name": "ZodError"
145
- }
146
- ],
147
- "path": [
148
- "strictOptions",
149
- "noPackageJsonTypings"
150
- ],
151
- "message": "Validation error: Validation error: Invalid literal value, expected \\"error\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\", or Validation error: Invalid literal value, expected \\"warn\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\", or Validation error: Invalid literal value, expected \\"off\\" at \\"strictOptions.noPackageJsonTypings\\" at \\"strictOptions.noPackageJsonTypings\\""
152
- }
153
- ]]
154
- `;
package/src/node/build.ts DELETED
@@ -1,100 +0,0 @@
1
- import path from 'node:path'
2
- import {rimraf} from 'rimraf'
3
- import {loadConfig} from './core/config/loadConfig'
4
- import {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting'
5
- import {createLogger} from './logger'
6
- import {resolveBuildContext} from './resolveBuildContext'
7
- import {resolveBuildTasks} from './resolveBuildTasks'
8
- import {createSpinner} from './spinner'
9
- import {buildTaskHandlers} from './tasks'
10
- import {type BuildTask, type TaskHandler} from './tasks/types'
11
-
12
- /**
13
- * Build the distribution files of a npm package.
14
- *
15
- * @example
16
- * ```ts
17
- * import {build} from '@sanity/pkg-utils'
18
- *
19
- * build({
20
- * cwd: process.cwd(),
21
- * tsconfig: 'tsconfig.dist.json,
22
- * }).then(() => {
23
- * console.log('successfully built')
24
- * }).catch((err) => {
25
- * console.log(`build error: ${err.message}`)
26
- * })
27
- * ```
28
- *
29
- * @public
30
- */
31
- export async function build(options: {
32
- cwd: string
33
- emitDeclarationOnly?: boolean
34
- strict?: boolean
35
- tsconfig?: string
36
- clean?: boolean
37
- }): Promise<void> {
38
- const {
39
- cwd,
40
- emitDeclarationOnly,
41
- strict = false,
42
- tsconfig: tsconfigOption,
43
- clean = false,
44
- } = options
45
- const logger = createLogger()
46
-
47
- const config = await loadConfig({cwd})
48
-
49
- const pkg = await loadPkgWithReporting({cwd, logger, strict})
50
-
51
- const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
52
-
53
- const ctx = await resolveBuildContext({
54
- config,
55
- cwd,
56
- emitDeclarationOnly,
57
- logger,
58
- pkg,
59
- strict,
60
- tsconfig,
61
- })
62
-
63
- if (clean) {
64
- logger.log(
65
- `Deleting the \`dist\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,
66
- )
67
- await rimraf(ctx.distPath)
68
- }
69
-
70
- const buildTasks = resolveBuildTasks(ctx)
71
-
72
- for (const task of buildTasks) {
73
- const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>
74
- const taskName = handler.name(ctx, task)
75
-
76
- const spinner = createSpinner(taskName)
77
-
78
- try {
79
- const result = await handler.exec(ctx, task).toPromise()
80
-
81
- spinner.complete()
82
- ctx.logger.log()
83
-
84
- handler.complete(ctx, task, result)
85
- } catch (err) {
86
- spinner.error()
87
-
88
- if (err instanceof Error) {
89
- const RE_CWD = new RegExp(`${cwd}`, 'g')
90
-
91
- ctx.logger.error(err.message.replace(RE_CWD, '.'))
92
- ctx.logger.log()
93
- }
94
-
95
- handler.error(ctx, task, err)
96
-
97
- process.exit(1)
98
- }
99
- }
100
- }
package/src/node/check.ts DELETED
@@ -1,188 +0,0 @@
1
- import path from 'node:path'
2
- import esbuild, {type BuildFailure, type Message} from 'esbuild'
3
- import {createConsoleSpy} from './consoleSpy'
4
- import {loadConfig} from './core/config/loadConfig'
5
- import {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting'
6
- import {fileExists} from './fileExists'
7
- import {createLogger, type Logger} from './logger'
8
- import {printPackageTree} from './printPackageTree'
9
- import {resolveBuildContext} from './resolveBuildContext'
10
-
11
- /** @public */
12
- export async function check(options: {
13
- cwd: string
14
- strict?: boolean
15
- tsconfig?: string
16
- }): Promise<void> {
17
- const {cwd, strict = false, tsconfig: tsconfigOption} = options
18
- const logger = createLogger()
19
-
20
- const config = await loadConfig({cwd})
21
- const pkg = await loadPkgWithReporting({cwd, logger, strict})
22
- const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
23
- const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
24
-
25
- printPackageTree(ctx)
26
-
27
- if (strict) {
28
- const missingFiles: string[] = []
29
-
30
- // Check if there are missing files
31
- for (const [, exp] of Object.entries(ctx.exports || {})) {
32
- if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {
33
- missingFiles.push(exp.source)
34
- }
35
-
36
- if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {
37
- missingFiles.push(exp.require)
38
- }
39
-
40
- if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {
41
- missingFiles.push(exp.import)
42
- }
43
- }
44
-
45
- if (ctx.pkg.types && !fileExists(path.resolve(cwd, ctx.pkg.types))) {
46
- missingFiles.push(ctx.pkg.types)
47
- }
48
-
49
- if (missingFiles.length) {
50
- logger.error(`missing files: ${missingFiles.join(', ')}`)
51
- process.exit(1)
52
- }
53
-
54
- // Check if the files are resolved
55
- const exportPaths: {require: string[]; import: string[]} = {
56
- require: [],
57
- import: [],
58
- }
59
-
60
- for (const exp of Object.values(ctx.exports || {})) {
61
- if (!exp._exported) continue
62
- if (exp.require) exportPaths.require.push(exp.require)
63
- if (exp.import) exportPaths.import.push(exp.import)
64
- }
65
-
66
- const external = [
67
- ...Object.keys(pkg.dependencies || {}),
68
- ...Object.keys(pkg.devDependencies || {}),
69
- ]
70
-
71
- const consoleSpy = createConsoleSpy()
72
-
73
- if (exportPaths.import.length) {
74
- checkExports(exportPaths.import, {cwd, external, format: 'esm', logger})
75
- }
76
-
77
- if (exportPaths.require.length) {
78
- checkExports(exportPaths.require, {cwd, external, format: 'cjs', logger})
79
- }
80
-
81
- consoleSpy.restore()
82
- }
83
- }
84
-
85
- async function checkExports(
86
- exportPaths: string[],
87
- options: {cwd: string; external: string[]; format: 'esm' | 'cjs'; logger: Logger},
88
- ) {
89
- const {cwd, external, format, logger} = options
90
-
91
- const code = exportPaths
92
- .map((id) => (format ? `import('${id}');` : `require('${id}');`))
93
- .join('\n')
94
-
95
- try {
96
- const esbuildResult = await esbuild.build({
97
- bundle: true,
98
- external,
99
- format,
100
- logLevel: 'silent',
101
- // otherwise output maps to stdout as we're using stdin
102
- outfile: '/dev/null',
103
- platform: 'node',
104
- stdin: {
105
- contents: code,
106
- loader: 'js',
107
- resolveDir: cwd,
108
- },
109
- })
110
-
111
- if (esbuildResult.errors.length > 0) {
112
- for (const msg of esbuildResult.errors) {
113
- printEsbuildMessage(logger.warn, msg)
114
-
115
- logger.log()
116
- }
117
-
118
- process.exit(1)
119
- }
120
-
121
- const esbuildWarnings = esbuildResult.warnings.filter((msg) => {
122
- !(msg.detail || msg.text).includes(`does not affect esbuild's own target setting`)
123
- })
124
-
125
- for (const msg of esbuildWarnings) {
126
- printEsbuildMessage(logger.warn, msg)
127
-
128
- logger.log()
129
- }
130
- } catch (err) {
131
- if (isEsbuildFailure(err)) {
132
- const {errors} = err
133
-
134
- for (const msg of errors) {
135
- printEsbuildMessage(logger.error, msg)
136
-
137
- logger.log()
138
- }
139
- } else if (err instanceof Error) {
140
- logger.error(err.stack || err.message)
141
-
142
- logger.log()
143
- } else {
144
- logger.error(`${err}`)
145
-
146
- logger.log()
147
- }
148
-
149
- process.exit(1)
150
- }
151
- }
152
-
153
- function printEsbuildMessage(log: (...args: unknown[]) => void, msg: esbuild.Message) {
154
- if (msg.location) {
155
- log(
156
- [
157
- `${msg.detail || msg.text}\n`,
158
- `${msg.location.line} | ${msg.location.lineText}\n`,
159
- `in ./${msg.location.file}:${msg.location.line}:${msg.location.column}`,
160
- ].join(''),
161
- )
162
- } else {
163
- log(msg.detail || msg.text)
164
- }
165
- }
166
-
167
- function isEsbuildFailure(err: unknown): err is BuildFailure {
168
- return (
169
- err instanceof Error &&
170
- 'errors' in err &&
171
- Array.isArray(err.errors) &&
172
- err.errors.every(isEsbuildMessage) &&
173
- 'warnings' in err &&
174
- Array.isArray(err.warnings) &&
175
- err.warnings.every(isEsbuildMessage)
176
- )
177
- }
178
-
179
- function isEsbuildMessage(msg: unknown): msg is Message {
180
- return (
181
- typeof msg === 'object' &&
182
- msg !== null &&
183
- 'text' in msg &&
184
- typeof msg.text === 'string' &&
185
- 'location' in msg &&
186
- (msg.location === null || typeof msg.location === 'object')
187
- )
188
- }
@@ -1,39 +0,0 @@
1
- export interface ConsoleSpyMsg {
2
- type: 'log' | 'warn' | 'error'
3
- code?: string
4
- args: unknown[]
5
- }
6
-
7
- export interface ConsoleSpy {
8
- messages: ConsoleSpyMsg[]
9
- restore: () => void
10
- }
11
-
12
- export function createConsoleSpy(options?: {
13
- onRestored?: (messages: ConsoleSpyMsg[]) => void
14
- }): ConsoleSpy {
15
- const {onRestored} = options || {}
16
-
17
- const original = {
18
- log: console.log,
19
- warn: console.warn,
20
- error: console.error,
21
- }
22
-
23
- const messages: ConsoleSpyMsg[] = []
24
-
25
- console.log = (...args: unknown[]) => messages.push({type: 'log', args})
26
- console.warn = (...args: unknown[]) => messages.push({type: 'warn', args})
27
- console.error = (...args: unknown[]) => messages.push({type: 'error', args})
28
-
29
- return {
30
- messages,
31
- restore: () => {
32
- console.log = original.log
33
- console.warn = original.warn
34
- console.error = original.error
35
-
36
- onRestored?.(messages)
37
- },
38
- }
39
- }
@@ -1,6 +0,0 @@
1
- import type {PkgConfigOptions} from './types'
2
-
3
- /** @public */
4
- export function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T {
5
- return configOptions
6
- }
@@ -1,31 +0,0 @@
1
- import path from 'node:path'
2
- import findConfig from 'find-config'
3
- import {fileExists} from '../../fileExists'
4
-
5
- const CONFIG_FILE_NAMES = [
6
- 'package.config.ts',
7
- 'package.config.js',
8
- 'package.config.cjs',
9
- 'package.config.mjs',
10
- ]
11
-
12
- /** @internal */
13
- export function findConfigFile(cwd: string): string | undefined {
14
- const pkgJsonPath = findConfig('package.json', {cwd})
15
-
16
- if (!pkgJsonPath) return undefined
17
-
18
- const pkgPath = path.dirname(pkgJsonPath)
19
-
20
- for (const fileName of CONFIG_FILE_NAMES) {
21
- const configPath = path.resolve(pkgPath, fileName)
22
-
23
- const exists = fileExists(configPath)
24
-
25
- if (exists) {
26
- return configPath
27
- }
28
- }
29
-
30
- return undefined
31
- }
@@ -1,4 +0,0 @@
1
- export * from './defineConfig'
2
- export * from './loadConfig'
3
- export * from './resolveConfigProperty'
4
- export * from './types'
@@ -1,37 +0,0 @@
1
- import path from 'node:path'
2
- import {register} from 'esbuild-register/dist/node'
3
- import pkgUp from 'pkg-up'
4
- import {findConfigFile} from './findConfigFile'
5
- import type {PkgConfigOptions} from './types'
6
-
7
- /** @alpha */
8
- export async function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
9
- const {cwd} = options
10
-
11
- const pkgPath = await pkgUp({cwd})
12
-
13
- if (!pkgPath) return undefined
14
-
15
- const root = path.dirname(pkgPath)
16
-
17
- const configFile = await findConfigFile(root)
18
-
19
- if (!configFile) {
20
- return undefined
21
- }
22
-
23
- // Do not accept config files outside of the root
24
- if (!configFile.startsWith(cwd)) {
25
- return undefined
26
- }
27
-
28
- const esbuildOptions = {extensions: ['.js', '.mjs', '.ts']}
29
-
30
- const {unregister} = globalThis.__DEV__ ? {unregister: () => undefined} : register(esbuildOptions)
31
-
32
- const mod = require(configFile)
33
-
34
- unregister()
35
-
36
- return mod?.default || mod || undefined
37
- }
@@ -1,15 +0,0 @@
1
- import type {PkgConfigProperty, PkgConfigPropertyResolver} from './types'
2
-
3
- /** @internal */
4
- export function resolveConfigProperty<T>(
5
- prop: PkgConfigProperty<T> | undefined,
6
- initialValue: T,
7
- ): T {
8
- if (!prop) return initialValue
9
-
10
- if (typeof prop === 'function') {
11
- return (prop as PkgConfigPropertyResolver<T>)(initialValue)
12
- }
13
-
14
- return prop
15
- }