@sanity/pkg-utils 1.1.0 → 1.2.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/cli.cjs CHANGED
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var cac = require('cac');
4
- var build = require('./_build-f5ddd6ac.cjs');
4
+ var build = require('./_build-e608bb7c.cjs');
5
5
  require('path');
6
6
  require('chalk');
7
7
  require('fs');
8
8
  require('module');
9
9
  require('esbuild');
10
10
  require('process');
11
+ require('find-config');
11
12
  require('pkg-up');
12
13
  require('util');
13
14
  require('rimraf');
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","sources":["../src/cli.ts"],"sourcesContent":["import cac from 'cac'\nimport {build} from './build'\n\nconst cli = cac()\n\ncli\n .command('build', 'Build package')\n .option('--extract', 'Extract API reference')\n .option('--tsconfig [tsconfig]', '[string] tsconfig.json')\n .action(async (options) => {\n await build({\n cwd: process.cwd(),\n extract: options.extract ? Boolean(options.extract) : undefined,\n tsconfig: options.tsconfig,\n })\n })\n\n// Display help message when `-h` or `--help` appears\ncli.help()\n\n// Display version number when `-v` or `--version` appears\n// It's also used in help message\ncli.version('0.0.0')\n\ncli.parse()\n"],"names":["cac","build"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,GAAG,GAAGA,uBAAG,EAAE,CAAC;AAClB,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC,MAAM,CAAC,uBAAuB,EAAE,wBAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,KAAK;AACvK,EAAE,MAAMC,WAAK,CAAC;AACd,IAAI,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;AACtB,IAAI,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;AAChE,IAAI,QAAQ,EAAE,OAAO,CAAC,QAAQ;AAC9B,GAAG,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AACH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACrB,GAAG,CAAC,KAAK,EAAE;;"}
1
+ {"version":3,"file":"cli.cjs","sources":["../src/cli.ts"],"sourcesContent":["import cac from 'cac'\nimport {build} from './build'\n\nconst cli = cac()\n\ncli\n .command('build', 'Build package')\n .option('--extract', 'Extract API reference')\n .option('--tsconfig [tsconfig]', '[string] tsconfig.json')\n .action(async (options) => {\n await build({\n cwd: process.cwd(),\n extract: options.extract ? Boolean(options.extract) : undefined,\n tsconfig: options.tsconfig,\n })\n })\n\n// Display help message when `-h` or `--help` appears\ncli.help()\n\n// Display version number when `-v` or `--version` appears\n// It's also used in help message\ncli.version('0.0.0')\n\ncli.parse()\n"],"names":["cac","build"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,GAAG,GAAGA,uBAAG,EAAE,CAAC;AAClB,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC,MAAM,CAAC,uBAAuB,EAAE,wBAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,KAAK;AACvK,EAAE,MAAMC,WAAK,CAAC;AACd,IAAI,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;AACtB,IAAI,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;AAChE,IAAI,QAAQ,EAAE,OAAO,CAAC,QAAQ;AAC9B,GAAG,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AACH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACrB,GAAG,CAAC,KAAK,EAAE;;"}
package/dist/index.cjs CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var build = require('./_build-f5ddd6ac.cjs');
3
+ var build = require('./_build-e608bb7c.cjs');
4
4
  require('path');
5
5
  require('chalk');
6
6
  require('fs');
7
7
  require('module');
8
8
  require('esbuild');
9
9
  require('process');
10
+ require('find-config');
10
11
  require('pkg-up');
11
12
  require('util');
12
13
  require('rimraf');
@@ -27,6 +28,7 @@ function defineConfig(configOptions) {
27
28
  return configOptions;
28
29
  }
29
30
 
31
+ exports._DEFAULTS = build._DEFAULTS;
30
32
  exports._isRecord = build._isRecord;
31
33
  exports._loadConfig = build._loadConfig;
32
34
  exports._loadPkg = build._loadPkg;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/core/config/defineConfig.ts"],"sourcesContent":["import {PkgConfigOptions} from './types'\n\n/**\n * @public\n */\nexport function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions {\n return configOptions\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,YAAY,CAAC,aAAa,EAAE;AAC5C,EAAE,OAAO,aAAa,CAAC;AACvB;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/core/config/defineConfig.ts"],"sourcesContent":["import {PkgConfigOptions} from './types'\n\n/**\n * @public\n */\nexport function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions {\n return configOptions\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,YAAY,CAAC,aAAa,EAAE;AAC5C,EAAE,OAAO,aAAa,CAAC;AACvB;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -41,6 +41,16 @@ export declare type ConfigProperty<T> = ConfigPropertyResolver<T> | T;
41
41
  */
42
42
  export declare type ConfigPropertyResolver<T> = (prev: T) => T;
43
43
 
44
+ /**
45
+ * @internal
46
+ */
47
+ export declare const _DEFAULTS: {
48
+ target: {
49
+ node: string[];
50
+ web: string[];
51
+ };
52
+ };
53
+
44
54
  /**
45
55
  * @public
46
56
  */
@@ -95,7 +105,7 @@ export declare interface _PackageJSON {
95
105
  * @public
96
106
  */
97
107
  export declare interface PackageSubPathExportEntry {
98
- runtime: 'node' | 'web';
108
+ runtime?: 'node' | 'web';
99
109
  source: string;
100
110
  require?: string;
101
111
  default?: string;
@@ -122,10 +132,18 @@ export declare interface PkgConfigOptions {
122
132
  * Packages to exclude from the bundles.
123
133
  */
124
134
  external?: ConfigProperty<string[]>;
135
+ /**
136
+ * Default runtime of package exports
137
+ */
138
+ runtime?: 'node' | 'web';
125
139
  /**
126
140
  * Directory of source files.
127
141
  */
128
142
  src?: string;
143
+ target?: {
144
+ node?: string[];
145
+ web?: string[];
146
+ };
129
147
  }
130
148
 
131
149
  /**
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import require$$1 from 'fs';
4
4
  import require$$2 from 'module';
5
5
  import require$$3 from 'esbuild';
6
6
  import require$$4 from 'process';
7
+ import findConfig from 'find-config';
7
8
  import pkgUp from 'pkg-up';
8
9
  import { promisify } from 'util';
9
10
  import rimrafCallback from 'rimraf';
@@ -20,6 +21,13 @@ import json from '@rollup/plugin-json';
20
21
  import { nodeResolve } from '@rollup/plugin-node-resolve';
21
22
  import esbuild from 'rollup-plugin-esbuild';
22
23
 
24
+ const _DEFAULTS = {
25
+ target: {
26
+ node: ["node12"],
27
+ web: ["chrome58", "edge16", "firefox54", "opera44", "safari11"]
28
+ }
29
+ };
30
+
23
31
  function _isRecord(value) {
24
32
  return Boolean(value) && !Array.isArray(value) && typeof value === "object";
25
33
  }
@@ -4894,15 +4902,28 @@ async function _loadConfig(options) {
4894
4902
  if (!pkgPath)
4895
4903
  return void 0;
4896
4904
  const root = path.dirname(pkgPath);
4905
+ const configFile = _findConfigFile(root);
4906
+ if (!configFile) {
4907
+ return void 0;
4908
+ }
4897
4909
  try {
4898
- const { unregister } = node.register({ extensions: [".js", ".ts"] });
4899
- const mod = require(path.resolve(root, "package.config.ts"));
4910
+ const { unregister } = configFile.transform ? node.register({ extensions: [".js", ".ts"] }) : { unregister: () => void 0 };
4911
+ const mod = require(configFile.path);
4900
4912
  unregister();
4901
- return mod.default;
4913
+ return (mod == null ? void 0 : mod.default) || mod || void 0;
4902
4914
  } catch (_) {
4903
4915
  return void 0;
4904
4916
  }
4905
4917
  }
4918
+ function _findConfigFile(cwd) {
4919
+ const ts = findConfig("package.config.ts", { cwd });
4920
+ if (ts)
4921
+ return { path: ts, transform: true };
4922
+ const cjs = findConfig("package.config.cjs", { cwd });
4923
+ if (cjs)
4924
+ return { path: cjs, transform: false };
4925
+ return null;
4926
+ }
4906
4927
 
4907
4928
  function _resolveConfigProperty(prop, initialValue) {
4908
4929
  if (typeof prop === "function") {
@@ -4924,7 +4945,7 @@ async function _loadPkg(options) {
4924
4945
  function _parseExports(pkg) {
4925
4946
  const rootExport = {
4926
4947
  path: ".",
4927
- runtime: "web",
4948
+ runtime: void 0,
4928
4949
  source: pkg.source || "index.js",
4929
4950
  require: pkg.main,
4930
4951
  default: pkg.module,
@@ -4939,7 +4960,6 @@ function _parseExports(pkg) {
4939
4960
  } else {
4940
4961
  extraExports.push({
4941
4962
  path: exportPath,
4942
- runtime: "web",
4943
4963
  source: exportEntry.source,
4944
4964
  ...exportEntry
4945
4965
  });
@@ -4953,7 +4973,8 @@ function _parseExports(pkg) {
4953
4973
  }
4954
4974
 
4955
4975
  function _parseTasks(ctx) {
4956
- const { pkg } = ctx;
4976
+ var _a, _b;
4977
+ const { config, pkg } = ctx;
4957
4978
  const entries = Object.entries(ctx.exports || {}).map(
4958
4979
  ([path2, entry]) => ({ path: path2, ...entry })
4959
4980
  );
@@ -4974,6 +4995,7 @@ function _parseTasks(ctx) {
4974
4995
  }
4975
4996
  }
4976
4997
  for (const entry of entries) {
4998
+ const runtime = entry.runtime || (config == null ? void 0 : config.runtime) || "web";
4977
4999
  const format = [];
4978
5000
  const target = [];
4979
5001
  if (entry.require) {
@@ -4982,20 +5004,20 @@ function _parseTasks(ctx) {
4982
5004
  if (entry.default) {
4983
5005
  format.push("esm");
4984
5006
  }
4985
- if (entry.runtime === "node") {
4986
- target.push("node12");
5007
+ if (runtime === "node") {
5008
+ target.push(...((_a = config == null ? void 0 : config.target) == null ? void 0 : _a.node) || _DEFAULTS.target.node);
4987
5009
  }
4988
- if (entry.runtime === "web") {
4989
- target.push("chrome104");
5010
+ if (runtime === "web") {
5011
+ target.push(...((_b = config == null ? void 0 : config.target) == null ? void 0 : _b.web) || _DEFAULTS.target.web);
4990
5012
  }
4991
5013
  for (const f of format) {
4992
- const buildId = `${entry.runtime}:${f}:${target.join(",")}`;
5014
+ const buildId = `${runtime}:${f}:${target.join(",")}`;
4993
5015
  if (!rollupTasks[buildId]) {
4994
5016
  rollupTasks[buildId] = {
4995
5017
  type: "rollup",
4996
5018
  buildId,
4997
5019
  entries: [entry],
4998
- runtime: entry.runtime,
5020
+ runtime,
4999
5021
  format: f,
5000
5022
  target
5001
5023
  };
@@ -5410,5 +5432,5 @@ async function build(options) {
5410
5432
  }
5411
5433
  }
5412
5434
 
5413
- export { _isRecord, _loadConfig, _loadPkg, _parseExports, _resolveConfigProperty, build, defineConfig };
5435
+ export { _DEFAULTS, _isRecord, _loadConfig, _loadPkg, _parseExports, _resolveConfigProperty, build, defineConfig };
5414
5436
  //# sourceMappingURL=index.js.map