@sanity/pkg-utils 5.1.11 → 6.0.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/dist/_chunks-cjs/build.cjs +1 -1
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +2 -2
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +14 -7
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/init.cjs +1 -1
- package/dist/_chunks-cjs/init.cjs.map +1 -1
- package/dist/_chunks-cjs/logger.cjs +1 -1
- package/dist/_chunks-cjs/logger.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +1 -1
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/node/check.ts +2 -1
- package/src/node/core/config/findConfigFile.ts +2 -1
- package/src/node/core/config/loadConfig.ts +3 -2
- package/src/node/core/config/resolveConfigProperty.ts +1 -1
- package/src/node/core/config/types.ts +9 -0
- package/src/node/core/findCommonPath.ts +1 -1
- package/src/node/core/pkg/loadPkg.ts +3 -2
- package/src/node/core/pkg/validatePkg.ts +1 -1
- package/src/node/core/template/createFromTemplate.ts +5 -4
- package/src/node/core/template/define.ts +1 -1
- package/src/node/core/template/types.ts +1 -1
- package/src/node/fileExists.ts +1 -1
- package/src/node/getFilesize.ts +2 -1
- package/src/node/globFiles.ts +2 -1
- package/src/node/init.ts +3 -2
- package/src/node/isEmptyDirectory.ts +1 -1
- package/src/node/printExtractMessages.ts +2 -1
- package/src/node/printPackageTree.ts +3 -2
- package/src/node/resolveBuildContext.ts +2 -1
- package/src/node/resolveBuildTasks.ts +2 -2
- package/src/node/resolveWatchTasks.ts +2 -2
- package/src/node/spinner.ts +1 -1
- package/src/node/tasks/dts/DtsError.ts +1 -1
- package/src/node/tasks/dts/createApiExtractorConfig.ts +2 -1
- package/src/node/tasks/dts/createTSDocConfig.ts +2 -1
- package/src/node/tasks/dts/doExtract.ts +2 -1
- package/src/node/tasks/dts/dtsWatchTask.ts +1 -1
- package/src/node/tasks/dts/extractTypes.ts +3 -2
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +2 -2
- package/src/node/tasks/dts/printDiagnostic.ts +3 -2
- package/src/node/tasks/rollup/resolveRollupConfig.ts +21 -2
- package/src/node/tasks/rollup/rollupLegacyTask.ts +2 -1
- package/src/node/tasks/rollup/rollupTask.ts +2 -1
- package/src/node/tasks/rollup/rollupWatchTask.ts +4 -3
- package/src/node/templates/default/template.ts +11 -4
- package/src/node/watch.ts +2 -1
- package/src/node/watchConfigFiles.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@babel/types": "^7.24.0",
|
|
64
64
|
"@microsoft/api-extractor": "7.43.0",
|
|
65
65
|
"@microsoft/tsdoc-config": "^0.16.2",
|
|
66
|
+
"@optimize-lodash/rollup-plugin": "4.0.4",
|
|
66
67
|
"@rollup/plugin-alias": "^5.1.0",
|
|
67
68
|
"@rollup/plugin-babel": "^6.0.4",
|
|
68
69
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"pretty-bytes": "^5.6.0",
|
|
92
93
|
"prompts": "^2.4.2",
|
|
93
94
|
"rimraf": "^4.4.1",
|
|
94
|
-
"rollup": "^4.14.
|
|
95
|
+
"rollup": "^4.14.1",
|
|
95
96
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
96
97
|
"rxjs": "^7.8.1",
|
|
97
98
|
"treeify": "^1.1.0",
|
|
@@ -111,8 +112,8 @@
|
|
|
111
112
|
"@types/rimraf": "^3.0.2",
|
|
112
113
|
"@types/treeify": "^1.0.3",
|
|
113
114
|
"@types/uuid": "^9.0.8",
|
|
114
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
115
|
-
"@typescript-eslint/parser": "^7.
|
|
115
|
+
"@typescript-eslint/eslint-plugin": "^7.6.0",
|
|
116
|
+
"@typescript-eslint/parser": "^7.6.0",
|
|
116
117
|
"browserslist-to-esbuild": "2.1.1",
|
|
117
118
|
"commitizen": "^4.3.0",
|
|
118
119
|
"cpx": "^1.5.0",
|
|
@@ -132,14 +133,14 @@
|
|
|
132
133
|
"typescript": "5.4.2",
|
|
133
134
|
"vitest": "^1.4.0",
|
|
134
135
|
"vitest-github-actions-reporter": "^0.11.1",
|
|
135
|
-
"@sanity/pkg-utils": "
|
|
136
|
+
"@sanity/pkg-utils": "6.0.0"
|
|
136
137
|
},
|
|
137
138
|
"peerDependencies": {
|
|
138
139
|
"typescript": "5.4.2"
|
|
139
140
|
},
|
|
140
141
|
"packageManager": "pnpm@8.15.6",
|
|
141
142
|
"engines": {
|
|
142
|
-
"node": ">=
|
|
143
|
+
"node": ">=18.17.0"
|
|
143
144
|
},
|
|
144
145
|
"publishConfig": {
|
|
145
146
|
"access": "public"
|
package/src/node/check.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
1
3
|
import {register} from 'esbuild-register/dist/node'
|
|
2
|
-
import path from 'path'
|
|
3
4
|
import pkgUp from 'pkg-up'
|
|
4
5
|
|
|
5
6
|
import {findConfigFile} from './findConfigFile'
|
|
6
|
-
import {PkgConfigOptions} from './types'
|
|
7
|
+
import type {PkgConfigOptions} from './types'
|
|
7
8
|
|
|
8
9
|
/** @internal */
|
|
9
10
|
export async function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {PluginItem as BabelPluginItem} from '@babel/core'
|
|
2
|
+
import type {OptimizeLodashOptions} from '@optimize-lodash/rollup-plugin'
|
|
2
3
|
import type {NormalizedOutputOptions, Plugin as RollupPlugin, TreeshakingOptions} from 'rollup'
|
|
3
4
|
|
|
4
5
|
// re-export
|
|
@@ -137,6 +138,14 @@ export interface PkgConfigOptions {
|
|
|
137
138
|
* @defaultValue false
|
|
138
139
|
*/
|
|
139
140
|
hashChunkFileNames?: boolean
|
|
141
|
+
/**
|
|
142
|
+
* Optimizes lodash imports using `@optimize-lodash/rollup-plugin` when set to `true`.
|
|
143
|
+
* It's enabled if `lodash` is found in `dependencies` or `peerDependencies`.
|
|
144
|
+
* It will use `lodash-es` for ESM targets if found in `dependencies` or `peerDependencies`.
|
|
145
|
+
* @defaultValue true
|
|
146
|
+
* @alpha
|
|
147
|
+
*/
|
|
148
|
+
optimizeLodash?: boolean | OptimizeLodashOptions
|
|
140
149
|
}
|
|
141
150
|
/**
|
|
142
151
|
* Default runtime of package exports
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {writeFile} from 'fs/promises'
|
|
1
|
+
import {writeFile} from 'node:fs/promises'
|
|
2
|
+
import {dirname, relative, resolve} from 'node:path'
|
|
3
|
+
|
|
2
4
|
import {mkdirp} from 'mkdirp'
|
|
3
|
-
import {dirname, relative, resolve} from 'path'
|
|
4
5
|
import prompts from 'prompts'
|
|
5
6
|
|
|
6
|
-
import {Logger} from '../../logger'
|
|
7
|
-
import {PkgTemplate} from './types'
|
|
7
|
+
import type {Logger} from '../../logger'
|
|
8
|
+
import type {PkgTemplate} from './types'
|
|
8
9
|
|
|
9
10
|
const promptsTypes = {
|
|
10
11
|
string: 'text' as const,
|
package/src/node/fileExists.ts
CHANGED
package/src/node/getFilesize.ts
CHANGED
package/src/node/globFiles.ts
CHANGED
package/src/node/init.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {lstat} from 'fs/promises'
|
|
1
|
+
import {lstat} from 'node:fs/promises'
|
|
2
|
+
import {resolve} from 'node:path'
|
|
3
|
+
|
|
2
4
|
import {mkdirp} from 'mkdirp'
|
|
3
|
-
import {resolve} from 'path'
|
|
4
5
|
|
|
5
6
|
import {createFromTemplate} from './core/template'
|
|
6
7
|
import {fileExists} from './fileExists'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
1
3
|
import chalk from 'chalk'
|
|
2
|
-
import path from 'path'
|
|
3
4
|
import treeify from 'treeify'
|
|
4
5
|
|
|
5
|
-
import {BuildContext, PkgExport} from './core'
|
|
6
|
+
import type {BuildContext, PkgExport} from './core'
|
|
6
7
|
import {fileExists} from './fileExists'
|
|
7
8
|
import {getFilesize} from './getFilesize'
|
|
8
9
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
|
|
5
5
|
import type {BuildTask, DtsTask, RollupLegacyTask, RollupTask, RollupTaskEntry} from './tasks'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
|
|
5
5
|
import type {DtsWatchTask, RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks'
|
package/src/node/spinner.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function createSpinner(msg: string): {complete: () => void; error: () =>
|
|
|
12
12
|
console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)
|
|
13
13
|
},
|
|
14
14
|
error: () => {
|
|
15
|
-
console.log(`${chalk.red(
|
|
15
|
+
console.log(`${chalk.red('[error]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)
|
|
16
16
|
},
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -11,7 +11,7 @@ import type {DtsResult, DtsWatchTask} from './types'
|
|
|
11
11
|
export const dtsWatchTask: TaskHandler<DtsWatchTask, DtsResult> = {
|
|
12
12
|
name: (_ctx, task) =>
|
|
13
13
|
[
|
|
14
|
-
|
|
14
|
+
'build type definitions',
|
|
15
15
|
...task.entries.map((entry) => {
|
|
16
16
|
return entry.targetPaths.map((targetPath) => {
|
|
17
17
|
return [
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
1
4
|
import {
|
|
2
5
|
Extractor,
|
|
3
6
|
ExtractorConfig,
|
|
4
7
|
type ExtractorMessage,
|
|
5
8
|
type ExtractorResult,
|
|
6
9
|
} from '@microsoft/api-extractor'
|
|
7
|
-
import fs from 'fs/promises'
|
|
8
10
|
import {mkdirp} from 'mkdirp'
|
|
9
|
-
import path from 'path'
|
|
10
11
|
import prettier from 'prettier'
|
|
11
12
|
import type ts from 'typescript'
|
|
12
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {ExtractorLogLevel, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
1
|
+
import type {ExtractorLogLevel, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
2
2
|
|
|
3
|
-
import {PkgConfigOptions, PkgRuleLevel} from '../../core'
|
|
3
|
+
import type {PkgConfigOptions, PkgRuleLevel} from '../../core'
|
|
4
4
|
|
|
5
5
|
const LOG_LEVELS: Record<PkgRuleLevel, ExtractorLogLevel> = {
|
|
6
6
|
error: 'error' as ExtractorLogLevel.Error,
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import {optimizeLodashImports} from '@optimize-lodash/rollup-plugin'
|
|
1
4
|
import alias from '@rollup/plugin-alias'
|
|
2
5
|
import {getBabelOutputPlugin} from '@rollup/plugin-babel'
|
|
3
6
|
import commonjs from '@rollup/plugin-commonjs'
|
|
@@ -5,12 +8,11 @@ import json from '@rollup/plugin-json'
|
|
|
5
8
|
import {nodeResolve} from '@rollup/plugin-node-resolve'
|
|
6
9
|
import replace from '@rollup/plugin-replace'
|
|
7
10
|
import terser from '@rollup/plugin-terser'
|
|
8
|
-
import path from 'path'
|
|
9
11
|
import type {InputOptions, OutputOptions, Plugin} from 'rollup'
|
|
10
12
|
import esbuild from 'rollup-plugin-esbuild'
|
|
11
13
|
|
|
12
14
|
import {pkgExtMap as extMap} from '../../../node/core/pkg/pkgExt'
|
|
13
|
-
import {type BuildContext, resolveConfigProperty} from '../../core'
|
|
15
|
+
import {type BuildContext, type PackageJSON, resolveConfigProperty} from '../../core'
|
|
14
16
|
import type {RollupLegacyTask, RollupTask, RollupWatchTask} from '../types'
|
|
15
17
|
|
|
16
18
|
export interface RollupConfig {
|
|
@@ -52,6 +54,8 @@ export function resolveRollupConfig(
|
|
|
52
54
|
Object.entries(config?.define || {}).map(([key, val]) => [key, JSON.stringify(val)]),
|
|
53
55
|
)
|
|
54
56
|
|
|
57
|
+
const {optimizeLodash: enableOptimizeLodash = hasDependency(pkg, 'lodash')} = config?.rollup || {}
|
|
58
|
+
|
|
55
59
|
const defaultPlugins = [
|
|
56
60
|
replace({
|
|
57
61
|
preventAssignment: true,
|
|
@@ -90,6 +94,13 @@ export function resolveRollupConfig(
|
|
|
90
94
|
preferBuiltins: true,
|
|
91
95
|
}),
|
|
92
96
|
commonjs(),
|
|
97
|
+
enableOptimizeLodash &&
|
|
98
|
+
optimizeLodashImports({
|
|
99
|
+
useLodashEs: format === 'esm' && hasDependency(pkg, 'lodash-es') ? true : undefined,
|
|
100
|
+
...(typeof config?.rollup?.optimizeLodash === 'boolean'
|
|
101
|
+
? {}
|
|
102
|
+
: config?.rollup?.optimizeLodash),
|
|
103
|
+
}),
|
|
93
104
|
json(),
|
|
94
105
|
esbuild({
|
|
95
106
|
jsx: config?.jsx ?? 'automatic',
|
|
@@ -215,3 +226,11 @@ export function resolveRollupConfig(
|
|
|
215
226
|
},
|
|
216
227
|
}
|
|
217
228
|
}
|
|
229
|
+
|
|
230
|
+
function hasDependency(pkg: PackageJSON, packageName: string): boolean {
|
|
231
|
+
return pkg.dependencies
|
|
232
|
+
? packageName in pkg.dependencies
|
|
233
|
+
: pkg.peerDependencies
|
|
234
|
+
? packageName in pkg.peerDependencies
|
|
235
|
+
: false
|
|
236
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
1
3
|
import chalk from 'chalk'
|
|
2
|
-
import
|
|
3
|
-
import {RollupWatcherEvent, RollupWatchOptions, watch as rollupWatch} from 'rollup'
|
|
4
|
+
import {type RollupWatcherEvent, type RollupWatchOptions, watch as rollupWatch} from 'rollup'
|
|
4
5
|
import {Observable} from 'rxjs'
|
|
5
6
|
|
|
6
|
-
import {RollupWatchTask, TaskHandler} from '../types'
|
|
7
|
+
import type {RollupWatchTask, TaskHandler} from '../types'
|
|
7
8
|
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
8
9
|
|
|
9
10
|
/** @internal */
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import {resolve} from 'node:path'
|
|
2
|
+
|
|
1
3
|
import getLatestVersion from 'get-latest-version'
|
|
2
4
|
import gitUrlParse from 'git-url-parse'
|
|
3
5
|
import {outdent} from 'outdent'
|
|
4
6
|
import parseGitConfig from 'parse-git-config'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import prettier, {type Config as PrettierConfig} from 'prettier'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
defineTemplateOption,
|
|
11
|
+
isRecord,
|
|
12
|
+
type PackageJSON,
|
|
13
|
+
type PkgTemplate,
|
|
14
|
+
type PkgTemplateFile,
|
|
15
|
+
} from '../../core'
|
|
9
16
|
|
|
10
17
|
const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i
|
|
11
18
|
|
package/src/node/watch.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import type {Observable} from 'rxjs'
|
|
3
4
|
import {distinctUntilChanged, scan, startWith} from 'rxjs/operators'
|
|
4
5
|
|
|
5
6
|
import {globFiles} from './globFiles'
|
|
6
|
-
import {Logger} from './logger'
|
|
7
|
+
import type {Logger} from './logger'
|
|
7
8
|
import {watchFiles} from './watchFiles'
|
|
8
9
|
|
|
9
10
|
export async function watchConfigFiles(options: {
|