@sanity/pkg-utils 1.17.0 → 1.17.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/dist/_chunks/{build-ce9b3fba.js → build-f2af311b.js} +2 -2
- package/dist/_chunks/{build-ce9b3fba.js.map → build-f2af311b.js.map} +1 -1
- package/dist/_chunks/{buildAction-1f1e18f0.js → buildAction-e362986d.js} +3 -3
- package/dist/_chunks/{buildAction-1f1e18f0.js.map → buildAction-e362986d.js.map} +1 -1
- package/dist/_chunks/{index-b6235a62.js → index-2c392b48.js} +48 -41
- package/dist/_chunks/index-2c392b48.js.map +1 -0
- package/dist/_chunks/{watch-7868b922.js → watch-29c57619.js} +2 -2
- package/dist/_chunks/{watch-7868b922.js.map → watch-29c57619.js.map} +1 -1
- package/dist/_chunks/{watchAction-9bef2175.js → watchAction-65236621.js} +3 -3
- package/dist/_chunks/{watchAction-9bef2175.js.map → watchAction-65236621.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.esm.js +55 -48
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/node/_tasks/dts/_declareModuleFix.ts +38 -26
- package/src/node/_tasks/dts/_doExtract.ts +3 -2
- package/dist/_chunks/index-b6235a62.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy(e) {
|
|
|
10
10
|
|
|
11
11
|
var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
|
|
12
12
|
|
|
13
|
-
var version = "1.17.
|
|
13
|
+
var version = "1.17.1";
|
|
14
14
|
const cli = cac__default["default"]();
|
|
15
15
|
cli.command("", "Check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async options => {
|
|
16
16
|
const {
|
|
@@ -24,7 +24,7 @@ cli.command("build", "Build package").option("--emitDeclarationOnly", "Emit d.ts
|
|
|
24
24
|
const {
|
|
25
25
|
buildAction
|
|
26
26
|
} = await Promise.resolve().then(function () {
|
|
27
|
-
return require('./_chunks/buildAction-
|
|
27
|
+
return require('./_chunks/buildAction-e362986d.js');
|
|
28
28
|
});
|
|
29
29
|
return buildAction(options);
|
|
30
30
|
});
|
|
@@ -32,7 +32,7 @@ cli.command("watch", "Watch package").option("--strict", "Strict mode").option("
|
|
|
32
32
|
const {
|
|
33
33
|
watchAction
|
|
34
34
|
} = await Promise.resolve().then(function () {
|
|
35
|
-
return require('./_chunks/watchAction-
|
|
35
|
+
return require('./_chunks/watchAction-65236621.js');
|
|
36
36
|
});
|
|
37
37
|
return watchAction(options);
|
|
38
38
|
});
|
package/dist/index.esm.js
CHANGED
|
@@ -568,59 +568,64 @@ async function _buildTypes(options) {
|
|
|
568
568
|
async function _appendModuleBlocks(_ref2) {
|
|
569
569
|
let {
|
|
570
570
|
tsOutDir,
|
|
571
|
+
extractResult,
|
|
571
572
|
extractTypesOutFile
|
|
572
573
|
} = _ref2;
|
|
573
|
-
const moduleBlocks = await _extractModuleBlocksFromTypes(
|
|
574
|
+
const moduleBlocks = await _extractModuleBlocksFromTypes({
|
|
575
|
+
tsOutDir,
|
|
576
|
+
extractResult
|
|
577
|
+
});
|
|
574
578
|
|
|
575
579
|
if (moduleBlocks.length) {
|
|
576
580
|
await fs.appendFile(extractTypesOutFile, "\n" + moduleBlocks.join("\n\n"));
|
|
577
581
|
}
|
|
578
582
|
}
|
|
579
583
|
|
|
580
|
-
async function _extractModuleBlocksFromTypes(
|
|
584
|
+
async function _extractModuleBlocksFromTypes(_ref3) {
|
|
585
|
+
let {
|
|
586
|
+
tsOutDir,
|
|
587
|
+
extractResult
|
|
588
|
+
} = _ref3;
|
|
581
589
|
const moduleBlocks = [];
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const content = await fs.readFile(path.resolve(dirname, fileName), {
|
|
586
|
-
encoding: "utf-8"
|
|
587
|
-
});
|
|
590
|
+
const program = extractResult.compilerState.program;
|
|
591
|
+
const allProgramFiles = [...program.getSourceFiles()];
|
|
592
|
+
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
588
593
|
|
|
589
|
-
|
|
590
|
-
|
|
594
|
+
for (const sourceFile of sourceFiles) {
|
|
595
|
+
if (sourceFile.text.includes("declare module")) {
|
|
596
|
+
moduleBlocks.push(..._extractModuleBlocks(sourceFile.text));
|
|
591
597
|
}
|
|
592
598
|
}
|
|
593
599
|
|
|
594
600
|
return moduleBlocks;
|
|
595
601
|
}
|
|
596
602
|
|
|
597
|
-
async function _getFileList(dirName) {
|
|
598
|
-
let files = [];
|
|
599
|
-
const filesInCurrentDir = await fs.readdir(dirName, {
|
|
600
|
-
withFileTypes: true
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
for (const fileInDir of filesInCurrentDir) {
|
|
604
|
-
if (fileInDir.isDirectory()) {
|
|
605
|
-
files = [...files, ...(await _getFileList(path.resolve(dirName, fileInDir.name)))];
|
|
606
|
-
} else {
|
|
607
|
-
files.push(path.resolve(dirName, fileInDir.name));
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
return files;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
603
|
function _extractModuleBlocks(fileContent) {
|
|
604
|
+
var _a;
|
|
605
|
+
|
|
615
606
|
const moduleBlocks = [];
|
|
616
607
|
let moduleIndentLevel = 0;
|
|
608
|
+
let insideComment = false;
|
|
617
609
|
let moduleLines = [];
|
|
618
610
|
const lines = fileContent.split("\n");
|
|
619
611
|
|
|
620
612
|
for (const line of lines) {
|
|
613
|
+
if (insideComment && line.includes("*/")) {
|
|
614
|
+
insideComment = false;
|
|
615
|
+
} else if (!insideComment && line.includes("/*") && line.includes("*/")) {
|
|
616
|
+
continue;
|
|
617
|
+
} else if (!insideComment && line.includes("/*")) {
|
|
618
|
+
insideComment = true;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (insideComment) {
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
|
|
621
625
|
if (!moduleLines.length) {
|
|
626
|
+
const isModuleDeclaration = (_a = line.match(/^\s*declare module.+$/)) == null ? void 0 : _a.length;
|
|
622
627
|
const moduleIndex = line.indexOf("declare module");
|
|
623
|
-
const isModuleStart = moduleIndex > -1;
|
|
628
|
+
const isModuleStart = isModuleDeclaration && moduleIndex > -1;
|
|
624
629
|
|
|
625
630
|
if (isModuleStart) {
|
|
626
631
|
moduleIndentLevel = moduleIndex;
|
|
@@ -886,12 +891,13 @@ async function _doExtract(ctx, task) {
|
|
|
886
891
|
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
887
892
|
const sourceTypesPath = path.resolve(tmpPath, path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
888
893
|
const targetPath = path.resolve(cwd, entry.targetPath);
|
|
894
|
+
const filePath = path.relative(outDir, targetPath);
|
|
889
895
|
const result = await _extractTypes({
|
|
890
896
|
customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
|
|
891
897
|
cwd,
|
|
892
898
|
exportPath,
|
|
893
899
|
files,
|
|
894
|
-
filePath
|
|
900
|
+
filePath,
|
|
895
901
|
projectPath: cwd,
|
|
896
902
|
rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
|
|
897
903
|
sourceTypesPath,
|
|
@@ -900,6 +906,7 @@ async function _doExtract(ctx, task) {
|
|
|
900
906
|
});
|
|
901
907
|
await _appendModuleBlocks({
|
|
902
908
|
tsOutDir: tmpPath,
|
|
909
|
+
extractResult: result.extractorResult,
|
|
903
910
|
extractTypesOutFile: path.resolve(outDir, targetPath)
|
|
904
911
|
});
|
|
905
912
|
messages.push(...result.messages);
|
|
@@ -984,7 +991,7 @@ const _dtsWatchTask = {
|
|
|
984
991
|
};
|
|
985
992
|
|
|
986
993
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
987
|
-
var
|
|
994
|
+
var _ref4, _ref7, _ref8, _ref9, _ref10, _ref11;
|
|
988
995
|
|
|
989
996
|
var _a, _b, _c;
|
|
990
997
|
|
|
@@ -1004,10 +1011,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1004
1011
|
ts
|
|
1005
1012
|
} = ctx;
|
|
1006
1013
|
const outputExt = _MODULE_EXT[pkg.type][format];
|
|
1007
|
-
const minify = (
|
|
1014
|
+
const minify = (_ref4 = config == null ? void 0 : config.minify) !== null && _ref4 !== void 0 ? _ref4 : true;
|
|
1008
1015
|
const outDir = path.relative(cwd, distPath);
|
|
1009
|
-
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(
|
|
1010
|
-
let [key, val] =
|
|
1016
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref5 => {
|
|
1017
|
+
let [key, val] = _ref5;
|
|
1011
1018
|
|
|
1012
1019
|
var _a2;
|
|
1013
1020
|
|
|
@@ -1023,8 +1030,8 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1023
1030
|
|
|
1024
1031
|
const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
|
|
1025
1032
|
|
|
1026
|
-
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(
|
|
1027
|
-
let [key, val] =
|
|
1033
|
+
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref6 => {
|
|
1034
|
+
let [key, val] = _ref6;
|
|
1028
1035
|
return [key, JSON.stringify(val)];
|
|
1029
1036
|
}));
|
|
1030
1037
|
const defaultPlugins = [replace({
|
|
@@ -1055,10 +1062,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1055
1062
|
esmExternals: false,
|
|
1056
1063
|
extensions: [".js"]
|
|
1057
1064
|
}), json(), esbuild({
|
|
1058
|
-
jsx: (
|
|
1059
|
-
jsxFactory: (
|
|
1060
|
-
jsxFragment: (
|
|
1061
|
-
jsxImportSource: (
|
|
1065
|
+
jsx: (_ref7 = config == null ? void 0 : config.jsx) !== null && _ref7 !== void 0 ? _ref7 : "automatic",
|
|
1066
|
+
jsxFactory: (_ref8 = config == null ? void 0 : config.jsxFactory) !== null && _ref8 !== void 0 ? _ref8 : "createElement",
|
|
1067
|
+
jsxFragment: (_ref9 = config == null ? void 0 : config.jsxFragment) !== null && _ref9 !== void 0 ? _ref9 : "Fragment",
|
|
1068
|
+
jsxImportSource: (_ref10 = config == null ? void 0 : config.jsxImportSource) !== null && _ref10 !== void 0 ? _ref10 : "react",
|
|
1062
1069
|
target,
|
|
1063
1070
|
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
1064
1071
|
}), getBabelOutputPlugin({
|
|
@@ -1132,7 +1139,7 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1132
1139
|
entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
|
|
1133
1140
|
format,
|
|
1134
1141
|
exports: "auto",
|
|
1135
|
-
sourcemap: (
|
|
1142
|
+
sourcemap: (_ref11 = config == null ? void 0 : config.sourcemap) !== null && _ref11 !== void 0 ? _ref11 : true
|
|
1136
1143
|
}
|
|
1137
1144
|
};
|
|
1138
1145
|
}
|
|
@@ -1421,7 +1428,7 @@ function _createLogger() {
|
|
|
1421
1428
|
}
|
|
1422
1429
|
|
|
1423
1430
|
async function _resolveBuildContext(options) {
|
|
1424
|
-
var
|
|
1431
|
+
var _ref12;
|
|
1425
1432
|
|
|
1426
1433
|
const {
|
|
1427
1434
|
config,
|
|
@@ -1515,7 +1522,7 @@ async function _resolveBuildContext(options) {
|
|
|
1515
1522
|
files: [],
|
|
1516
1523
|
logger,
|
|
1517
1524
|
pkg,
|
|
1518
|
-
runtime: (
|
|
1525
|
+
runtime: (_ref12 = config == null ? void 0 : config.runtime) !== null && _ref12 !== void 0 ? _ref12 : "*",
|
|
1519
1526
|
strict,
|
|
1520
1527
|
target,
|
|
1521
1528
|
ts: {
|
|
@@ -1641,11 +1648,11 @@ function _printPackageTree(ctx) {
|
|
|
1641
1648
|
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1642
1649
|
}
|
|
1643
1650
|
|
|
1644
|
-
tree.exports = Object.fromEntries(Object.entries(exports).filter(
|
|
1645
|
-
let [, entry] =
|
|
1651
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref13 => {
|
|
1652
|
+
let [, entry] = _ref13;
|
|
1646
1653
|
return entry._exported;
|
|
1647
|
-
}).map(
|
|
1648
|
-
let [exportPath, entry] =
|
|
1654
|
+
}).map(_ref14 => {
|
|
1655
|
+
let [exportPath, entry] = _ref14;
|
|
1649
1656
|
const exp = {
|
|
1650
1657
|
source: entry.source,
|
|
1651
1658
|
types: void 0,
|
|
@@ -1845,8 +1852,8 @@ function _resolveWatchTasks(ctx) {
|
|
|
1845
1852
|
target
|
|
1846
1853
|
} = ctx;
|
|
1847
1854
|
const tasks = [];
|
|
1848
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1849
|
-
let [_path, exp] =
|
|
1855
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref15 => {
|
|
1856
|
+
let [_path, exp] = _ref15;
|
|
1850
1857
|
return _objectSpread({
|
|
1851
1858
|
_path
|
|
1852
1859
|
}, exp);
|