@sanity/pkg-utils 1.2.0 → 1.3.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/{_build-e608bb7c.cjs → _build-f08e1020.cjs} +97 -11
- package/dist/_build-f08e1020.cjs.map +1 -0
- package/dist/cli.cjs +2 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -9
- package/dist/index.js +95 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/build/_parseBrowserslistVersions.ts +60 -0
- package/src/build/_parseNodeTarget.ts +15 -0
- package/src/build/_parseTasks.ts +3 -3
- package/src/build/_parseWebTarget.ts +35 -0
- package/src/build/_types.ts +1 -0
- package/src/build/build.ts +20 -9
- package/src/core/_defaults.ts +6 -4
- package/src/core/config/_resolveConfigProperty.ts +3 -1
- package/src/core/config/types.ts +0 -4
- package/src/core/pkg/_types.ts +1 -0
- package/dist/_build-e608bb7c.cjs.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var cac = require('cac');
|
|
4
|
-
var build = require('./_build-
|
|
4
|
+
var build = require('./_build-f08e1020.cjs');
|
|
5
5
|
require('path');
|
|
6
6
|
require('chalk');
|
|
7
7
|
require('fs');
|
|
@@ -10,6 +10,7 @@ require('esbuild');
|
|
|
10
10
|
require('process');
|
|
11
11
|
require('find-config');
|
|
12
12
|
require('pkg-up');
|
|
13
|
+
require('browserslist');
|
|
13
14
|
require('util');
|
|
14
15
|
require('rimraf');
|
|
15
16
|
require('typescript');
|
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":"
|
|
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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var build = require('./_build-
|
|
3
|
+
var build = require('./_build-f08e1020.cjs');
|
|
4
4
|
require('path');
|
|
5
5
|
require('chalk');
|
|
6
6
|
require('fs');
|
|
@@ -9,6 +9,7 @@ require('esbuild');
|
|
|
9
9
|
require('process');
|
|
10
10
|
require('find-config');
|
|
11
11
|
require('pkg-up');
|
|
12
|
+
require('browserslist');
|
|
12
13
|
require('util');
|
|
13
14
|
require('rimraf');
|
|
14
15
|
require('typescript');
|
package/dist/index.cjs.map
CHANGED
|
@@ -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":"
|
|
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
|
@@ -20,6 +20,10 @@ export declare interface _BuildContext {
|
|
|
20
20
|
dist: string;
|
|
21
21
|
pkg: _PackageJSON;
|
|
22
22
|
src: string;
|
|
23
|
+
target: {
|
|
24
|
+
node: string[];
|
|
25
|
+
web: string[];
|
|
26
|
+
};
|
|
23
27
|
tsconfig?: string;
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -45,10 +49,7 @@ export declare type ConfigPropertyResolver<T> = (prev: T) => T;
|
|
|
45
49
|
* @internal
|
|
46
50
|
*/
|
|
47
51
|
export declare const _DEFAULTS: {
|
|
48
|
-
|
|
49
|
-
node: string[];
|
|
50
|
-
web: string[];
|
|
51
|
-
};
|
|
52
|
+
browserslist: string[];
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
/**
|
|
@@ -99,6 +100,7 @@ export declare interface _PackageJSON {
|
|
|
99
100
|
source?: string;
|
|
100
101
|
module?: string;
|
|
101
102
|
types?: string;
|
|
103
|
+
browserslist?: string[];
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
/**
|
|
@@ -140,15 +142,11 @@ export declare interface PkgConfigOptions {
|
|
|
140
142
|
* Directory of source files.
|
|
141
143
|
*/
|
|
142
144
|
src?: string;
|
|
143
|
-
target?: {
|
|
144
|
-
node?: string[];
|
|
145
|
-
web?: string[];
|
|
146
|
-
};
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
/**
|
|
150
148
|
* @internal
|
|
151
149
|
*/
|
|
152
|
-
export declare function _resolveConfigProperty<T>(prop: ConfigProperty<T
|
|
150
|
+
export declare function _resolveConfigProperty<T>(prop: ConfigProperty<T> | undefined, initialValue: T): T;
|
|
153
151
|
|
|
154
152
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import require$$3 from 'esbuild';
|
|
|
6
6
|
import require$$4 from 'process';
|
|
7
7
|
import findConfig from 'find-config';
|
|
8
8
|
import pkgUp from 'pkg-up';
|
|
9
|
+
import browserslist from 'browserslist';
|
|
9
10
|
import { promisify } from 'util';
|
|
10
11
|
import rimrafCallback from 'rimraf';
|
|
11
12
|
import ts from 'typescript';
|
|
@@ -22,10 +23,12 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
|
22
23
|
import esbuild from 'rollup-plugin-esbuild';
|
|
23
24
|
|
|
24
25
|
const _DEFAULTS = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
browserslist: [
|
|
27
|
+
"> 0.2% and supports es6-module and supports es6-module-dynamic-import",
|
|
28
|
+
"not dead",
|
|
29
|
+
"not IE 11",
|
|
30
|
+
"maintained node versions"
|
|
31
|
+
]
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
function _isRecord(value) {
|
|
@@ -4926,6 +4929,8 @@ function _findConfigFile(cwd) {
|
|
|
4926
4929
|
}
|
|
4927
4930
|
|
|
4928
4931
|
function _resolveConfigProperty(prop, initialValue) {
|
|
4932
|
+
if (!prop)
|
|
4933
|
+
return initialValue;
|
|
4929
4934
|
if (typeof prop === "function") {
|
|
4930
4935
|
return prop(initialValue);
|
|
4931
4936
|
}
|
|
@@ -4972,8 +4977,57 @@ function _parseExports(pkg) {
|
|
|
4972
4977
|
return [rootExport, ...extraExports];
|
|
4973
4978
|
}
|
|
4974
4979
|
|
|
4980
|
+
function _sortAsNumber(a, b) {
|
|
4981
|
+
const aVersion = Number(a);
|
|
4982
|
+
const bVersion = Number(b);
|
|
4983
|
+
return aVersion - bVersion;
|
|
4984
|
+
}
|
|
4985
|
+
function _parseBrowserslistVersions(query) {
|
|
4986
|
+
const result = browserslist(query);
|
|
4987
|
+
const entries = result.map((key) => {
|
|
4988
|
+
const [name, version] = key.split(" ");
|
|
4989
|
+
return { name, version: version.split("-")[0].split(".")[0] };
|
|
4990
|
+
});
|
|
4991
|
+
const andChr = entries.filter((b) => b.name === "and_chr");
|
|
4992
|
+
const andFf = entries.filter((b) => b.name === "and_ff");
|
|
4993
|
+
const chrome = entries.filter((b) => b.name === "chrome");
|
|
4994
|
+
const edge = entries.filter((b) => b.name === "edge");
|
|
4995
|
+
const ff = entries.filter((b) => b.name === "firefox");
|
|
4996
|
+
const iosSaf = entries.filter((b) => b.name === "ios_saf");
|
|
4997
|
+
const saf = entries.filter((b) => b.name === "safari");
|
|
4998
|
+
const opera = entries.filter((b) => b.name === "opera");
|
|
4999
|
+
const node = entries.filter((b) => b.name === "node");
|
|
5000
|
+
const versions = {
|
|
5001
|
+
chrome: andChr.concat(chrome).map((b) => b.version),
|
|
5002
|
+
ff: andFf.concat(ff).map((b) => b.version),
|
|
5003
|
+
edge: edge.map((b) => b.version),
|
|
5004
|
+
iosSaf: iosSaf.map((b) => b.version),
|
|
5005
|
+
saf: saf.map((b) => b.version),
|
|
5006
|
+
opera: opera.map((b) => b.version),
|
|
5007
|
+
node: node.map((b) => b.version)
|
|
5008
|
+
};
|
|
5009
|
+
versions.chrome.sort(_sortAsNumber);
|
|
5010
|
+
versions.ff.sort(_sortAsNumber);
|
|
5011
|
+
versions.edge.sort(_sortAsNumber);
|
|
5012
|
+
versions.iosSaf.sort(_sortAsNumber);
|
|
5013
|
+
versions.saf.sort(_sortAsNumber);
|
|
5014
|
+
versions.opera.sort(_sortAsNumber);
|
|
5015
|
+
versions.node.sort(_sortAsNumber);
|
|
5016
|
+
return versions;
|
|
5017
|
+
}
|
|
5018
|
+
|
|
5019
|
+
function _parseNodeTarget(versions) {
|
|
5020
|
+
const target = [];
|
|
5021
|
+
if (versions.node.length) {
|
|
5022
|
+
target.push(`node${versions.node[0]}`);
|
|
5023
|
+
}
|
|
5024
|
+
if (target.length === 0) {
|
|
5025
|
+
return void 0;
|
|
5026
|
+
}
|
|
5027
|
+
return target;
|
|
5028
|
+
}
|
|
5029
|
+
|
|
4975
5030
|
function _parseTasks(ctx) {
|
|
4976
|
-
var _a, _b;
|
|
4977
5031
|
const { config, pkg } = ctx;
|
|
4978
5032
|
const entries = Object.entries(ctx.exports || {}).map(
|
|
4979
5033
|
([path2, entry]) => ({ path: path2, ...entry })
|
|
@@ -5005,10 +5059,10 @@ function _parseTasks(ctx) {
|
|
|
5005
5059
|
format.push("esm");
|
|
5006
5060
|
}
|
|
5007
5061
|
if (runtime === "node") {
|
|
5008
|
-
target.push(...
|
|
5062
|
+
target.push(...ctx.target.node);
|
|
5009
5063
|
}
|
|
5010
5064
|
if (runtime === "web") {
|
|
5011
|
-
target.push(...
|
|
5065
|
+
target.push(...ctx.target.web);
|
|
5012
5066
|
}
|
|
5013
5067
|
for (const f of format) {
|
|
5014
5068
|
const buildId = `${runtime}:${f}:${target.join(",")}`;
|
|
@@ -5036,6 +5090,32 @@ function _parseTasks(ctx) {
|
|
|
5036
5090
|
return tasks;
|
|
5037
5091
|
}
|
|
5038
5092
|
|
|
5093
|
+
function _parseWebTarget(versions) {
|
|
5094
|
+
const target = [];
|
|
5095
|
+
if (versions.chrome.length) {
|
|
5096
|
+
target.push(`chrome${versions.chrome[0]}`);
|
|
5097
|
+
}
|
|
5098
|
+
if (versions.ff.length) {
|
|
5099
|
+
target.push(`firefox${versions.ff[0]}`);
|
|
5100
|
+
}
|
|
5101
|
+
if (versions.edge.length) {
|
|
5102
|
+
target.push(`edge${versions.edge[0]}`);
|
|
5103
|
+
}
|
|
5104
|
+
if (versions.iosSaf.length) {
|
|
5105
|
+
target.push(`ios${versions.iosSaf[0]}`);
|
|
5106
|
+
}
|
|
5107
|
+
if (versions.saf.length) {
|
|
5108
|
+
target.push(`safari${versions.saf[0]}`);
|
|
5109
|
+
}
|
|
5110
|
+
if (versions.opera.length) {
|
|
5111
|
+
target.push(`opera${versions.opera[0]}`);
|
|
5112
|
+
}
|
|
5113
|
+
if (target.length === 0) {
|
|
5114
|
+
return void 0;
|
|
5115
|
+
}
|
|
5116
|
+
return target;
|
|
5117
|
+
}
|
|
5118
|
+
|
|
5039
5119
|
async function _loadTSConfig(options) {
|
|
5040
5120
|
const { cwd, tsconfigPath } = options;
|
|
5041
5121
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
@@ -5390,12 +5470,13 @@ async function build(options) {
|
|
|
5390
5470
|
const { path: exportPath, ...exportEntry } = x;
|
|
5391
5471
|
return { ...acc, [exportPath]: exportEntry };
|
|
5392
5472
|
}, {});
|
|
5393
|
-
const exports = (config == null ? void 0 : config.exports
|
|
5394
|
-
const
|
|
5473
|
+
const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
5474
|
+
const parsedExternal = [
|
|
5395
5475
|
...pkg.dependencies ? Object.keys(pkg.dependencies) : [],
|
|
5396
5476
|
...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []
|
|
5397
5477
|
];
|
|
5398
|
-
const external = (config == null ? void 0 : config.external
|
|
5478
|
+
const external = _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
5479
|
+
const targetVersions = _parseBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
|
|
5399
5480
|
const srcPath = path.resolve(cwd, (config == null ? void 0 : config.src) || "src");
|
|
5400
5481
|
const distPath = path.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
|
|
5401
5482
|
const context = {
|
|
@@ -5408,6 +5489,10 @@ async function build(options) {
|
|
|
5408
5489
|
dist: path.relative(cwd, distPath),
|
|
5409
5490
|
pkg,
|
|
5410
5491
|
src: path.relative(cwd, srcPath),
|
|
5492
|
+
target: {
|
|
5493
|
+
node: _parseNodeTarget(targetVersions) || _DEFAULTS.target.node,
|
|
5494
|
+
web: _parseWebTarget(targetVersions) || _DEFAULTS.target.web
|
|
5495
|
+
},
|
|
5411
5496
|
tsconfig
|
|
5412
5497
|
};
|
|
5413
5498
|
console.log(chalk.gray("cwd "), context.cwd);
|