@sanity/pkg-utils 6.3.0 → 6.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/pkg-utils",
3
- "version": "6.3.0",
3
+ "version": "6.4.1",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -135,7 +135,7 @@
135
135
  "typescript": "5.4.5",
136
136
  "vitest": "^1.4.0",
137
137
  "vitest-github-actions-reporter": "^0.11.1",
138
- "@sanity/pkg-utils": "6.3.0"
138
+ "@sanity/pkg-utils": "6.4.1"
139
139
  },
140
140
  "peerDependencies": {
141
141
  "typescript": "5.4.x"
@@ -5,6 +5,7 @@ export async function buildAction(options: {
5
5
  emitDeclarationOnly?: boolean
6
6
  strict?: boolean
7
7
  tsconfig?: string
8
+ clean?: boolean
8
9
  }): Promise<void> {
9
10
  try {
10
11
  await build({
@@ -12,6 +13,7 @@ export async function buildAction(options: {
12
13
  emitDeclarationOnly: options.emitDeclarationOnly,
13
14
  strict: options.strict,
14
15
  tsconfig: options.tsconfig,
16
+ clean: options.clean,
15
17
  })
16
18
  } catch (err) {
17
19
  handleError(err)
package/src/cli/index.ts CHANGED
@@ -21,6 +21,7 @@ cli
21
21
  .option('--strict', 'Strict mode')
22
22
  .option('--tsconfig [tsconfig]', '[string] tsconfig.json')
23
23
  .option('--check', 'Run the check command after build (same as running `pkg build && pkg check`)')
24
+ .option('--clean', 'Clean the dist directory before building')
24
25
  .action(async (options) => {
25
26
  const {check = false, ...buildOptions} = options
26
27
  const {buildAction} = await import('./buildAction')
package/src/node/build.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import path from 'node:path'
2
+
3
+ import rimraf from 'rimraf'
4
+
1
5
  import {loadConfig, loadPkgWithReporting} from './core'
2
6
  import {createLogger} from './logger'
3
7
  import {resolveBuildContext} from './resolveBuildContext'
@@ -29,11 +33,19 @@ export async function build(options: {
29
33
  emitDeclarationOnly?: boolean
30
34
  strict?: boolean
31
35
  tsconfig?: string
36
+ clean?: boolean
32
37
  }): Promise<void> {
33
- const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options
38
+ const {
39
+ cwd,
40
+ emitDeclarationOnly,
41
+ strict = false,
42
+ tsconfig: tsconfigOption,
43
+ clean = false,
44
+ } = options
34
45
  const logger = createLogger()
35
46
 
36
47
  const config = await loadConfig({cwd})
48
+
37
49
  const legacyExports = config?.legacyExports ?? false
38
50
  const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
39
51
 
@@ -49,6 +61,13 @@ export async function build(options: {
49
61
  tsconfig,
50
62
  })
51
63
 
64
+ if (clean) {
65
+ logger.log(
66
+ `Deleting the \`dist\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,
67
+ )
68
+ await rimraf(ctx.distPath)
69
+ }
70
+
52
71
  const buildTasks = resolveBuildTasks(ctx)
53
72
 
54
73
  for (const task of buildTasks) {