@sanity/pkg-utils 2.3.14 → 2.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.
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
32
32
  import replace from '@rollup/plugin-replace';
33
33
  import terser from '@rollup/plugin-terser';
34
34
  import esbuild from 'rollup-plugin-esbuild';
35
+ import preserveDirectives from 'rollup-plugin-preserve-directives';
35
36
  import esbuild$1 from 'esbuild';
36
37
  import treeify from 'treeify';
37
38
  import prettyBytes from 'pretty-bytes';
@@ -1457,10 +1458,10 @@ function resolveRollupConfig(ctx, buildTask) {
1457
1458
  modules: false
1458
1459
  }]]
1459
1460
  }), minify && terser({
1460
- compress: {
1461
+ compress: (config == null ? void 0 : config.preserveModuleDirectives) ? {
1461
1462
  // Needed until https://github.com/terser/terser/issues/1320 is fixed
1462
1463
  directives: false
1463
- },
1464
+ } : true,
1464
1465
  output: {
1465
1466
  comments: (_node, comment) => {
1466
1467
  const text = comment.value;
@@ -1471,7 +1472,9 @@ function resolveRollupConfig(ctx, buildTask) {
1471
1472
  return false;
1472
1473
  }
1473
1474
  }
1474
- })].filter(Boolean);
1475
+ }),
1476
+ // Allows marking export files with `'use client'` at the top
1477
+ (config == null ? void 0 : config.preserveModuleDirectives) && preserveDirectives()].filter(Boolean);
1475
1478
  const userPlugins = (_c = config == null ? void 0 : config.rollup) == null ? void 0 : _c.plugins;
1476
1479
  const plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty((_d = config == null ? void 0 : config.rollup) == null ? void 0 : _d.plugins, defaultPlugins);
1477
1480
  return {
@@ -1528,7 +1531,8 @@ function resolveRollupConfig(ctx, buildTask) {
1528
1531
  interop: "compat",
1529
1532
  minifyInternalExports: minify,
1530
1533
  sourcemap: (_ref11 = config == null ? void 0 : config.sourcemap) !== null && _ref11 !== void 0 ? _ref11 : true,
1531
- hoistTransitiveImports: false
1534
+ hoistTransitiveImports: false,
1535
+ preserveModules: (config == null ? void 0 : config.preserveModuleDirectives) ? true : false
1532
1536
  }
1533
1537
  };
1534
1538
  }
@@ -1594,6 +1598,19 @@ async function execPromise(ctx, task) {
1594
1598
  const bundle = await rollup({
1595
1599
  ...inputOptions,
1596
1600
  onwarn(warning) {
1601
+ var _a;
1602
+ if (
1603
+ // Ignore the directive warning until the preserveDirectives plugin does it automatically: https://github.com/Ephem/rollup-plugin-preserve-directives#rollup-plugin-preserve-directives-warning
1604
+ warning.message.includes('Module level directives cause errors when bundled, "use client" in')) {
1605
+ if (!((_a = ctx.config) == null ? void 0 : _a.preserveModuleDirectives)) {
1606
+ consoleSpy.messages.push({
1607
+ type: "warn",
1608
+ code: warning.code,
1609
+ args: ["".concat(warning.message, " You can preserve it by setting \"preserveModuleDirectives: true\" in your \"package.config.ts\"")]
1610
+ });
1611
+ }
1612
+ return;
1613
+ }
1597
1614
  consoleSpy.messages.push({
1598
1615
  type: "warn",
1599
1616
  code: warning.code,