@sanity/pkg-utils 2.0.0-beta.2 → 2.0.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/README.md +3 -3
- package/dist/_chunks/{build-b879ad71.cjs → build-a76b6607.cjs} +8 -3
- package/dist/_chunks/build-a76b6607.cjs.map +1 -0
- package/dist/_chunks/{buildAction-232e6073.cjs → buildAction-bfc3483c.cjs} +4 -4
- package/dist/_chunks/{buildAction-232e6073.cjs.map → buildAction-bfc3483c.cjs.map} +1 -1
- package/dist/_chunks/{check-617f9494.cjs → check-5451f989.cjs} +7 -2
- package/dist/_chunks/check-5451f989.cjs.map +1 -0
- package/dist/_chunks/{checkAction-a2d388ad.cjs → checkAction-f67b99f8.cjs} +3 -3
- package/dist/_chunks/{checkAction-a2d388ad.cjs.map → checkAction-f67b99f8.cjs.map} +1 -1
- package/dist/_chunks/{index-b63b3deb.cjs → index-4a6d7209.cjs} +167 -117
- package/dist/_chunks/index-4a6d7209.cjs.map +1 -0
- package/dist/_chunks/{resolveBuildContext-bba19cd6.cjs → resolveBuildContext-2fe45294.cjs} +33 -13
- package/dist/_chunks/resolveBuildContext-2fe45294.cjs.map +1 -0
- package/dist/_chunks/{watch-6fb4e453.cjs → watch-b76059c1.cjs} +8 -3
- package/dist/_chunks/watch-b76059c1.cjs.map +1 -0
- package/dist/_chunks/{watchAction-8135afe0.cjs → watchAction-2eb6b41f.cjs} +4 -4
- package/dist/_chunks/{watchAction-8135afe0.cjs.map → watchAction-2eb6b41f.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +7 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -10
- package/dist/index.js +219 -135
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/node/build.ts +3 -1
- package/src/node/check.ts +3 -2
- package/src/node/core/contexts/buildContext.ts +2 -1
- package/src/node/core/index.ts +0 -1
- package/src/node/core/pkg/index.ts +1 -0
- package/src/node/core/pkg/parseExports.ts +4 -2
- package/src/node/core/pkg/pkgExt.ts +38 -0
- package/src/node/core/pkg/validateExports.ts +4 -4
- package/src/node/resolveBuildContext.ts +5 -1
- package/src/node/tasks/dts/buildTypes.ts +7 -22
- package/src/node/tasks/dts/doExtract.ts +2 -2
- package/src/node/tasks/dts/printDiagnostic.ts +42 -0
- package/src/node/tasks/rollup/consoleSpy.ts +41 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +22 -11
- package/src/node/tasks/rollup/rollupTask.ts +69 -78
- package/src/node/watch.ts +3 -2
- package/dist/_chunks/build-b879ad71.cjs.map +0 -1
- package/dist/_chunks/check-617f9494.cjs.map +0 -1
- package/dist/_chunks/index-b63b3deb.cjs.map +0 -1
- package/dist/_chunks/resolveBuildContext-bba19cd6.cjs.map +0 -1
- package/dist/_chunks/watch-6fb4e453.cjs.map +0 -1
- package/src/node/core/constants.ts +0 -14
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare interface BuildContext {
|
|
|
38
38
|
distPath: string
|
|
39
39
|
emitDeclarationOnly: boolean
|
|
40
40
|
exports: PkgExports | undefined
|
|
41
|
+
extMap: PkgExtMap
|
|
41
42
|
external: string[]
|
|
42
43
|
files: BuildFile[]
|
|
43
44
|
logger: Logger
|
|
@@ -82,6 +83,9 @@ export declare function createLogger(): Logger
|
|
|
82
83
|
/** @public */
|
|
83
84
|
export declare const DEFAULT_BROWSERSLIST_QUERY: string[]
|
|
84
85
|
|
|
86
|
+
/** @internal */
|
|
87
|
+
export declare const DEFAULT_PKG_EXT_MAP: PkgExtMap
|
|
88
|
+
|
|
85
89
|
/** @public */
|
|
86
90
|
export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions
|
|
87
91
|
|
|
@@ -128,6 +132,9 @@ export declare function getExtractMessagesConfig(options: {
|
|
|
128
132
|
rules: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
129
133
|
}): IExtractorMessagesConfig
|
|
130
134
|
|
|
135
|
+
/** @internal */
|
|
136
|
+
export declare function getPkgExtMap(options: {legacyExports: boolean}): PkgExtMap
|
|
137
|
+
|
|
131
138
|
/** @internal */
|
|
132
139
|
export declare function isRecord(value: unknown): value is Record<string, unknown>
|
|
133
140
|
|
|
@@ -158,15 +165,6 @@ export declare interface Logger {
|
|
|
158
165
|
success: (...args: unknown[]) => void
|
|
159
166
|
}
|
|
160
167
|
|
|
161
|
-
/** @internal */
|
|
162
|
-
export declare const MODULE_EXT: Record<
|
|
163
|
-
'commonjs' | 'module',
|
|
164
|
-
{
|
|
165
|
-
commonjs: string
|
|
166
|
-
esm: string
|
|
167
|
-
}
|
|
168
|
-
>
|
|
169
|
-
|
|
170
168
|
/** @internal */
|
|
171
169
|
export declare interface PackageJSON {
|
|
172
170
|
type: 'commonjs' | 'module'
|
|
@@ -207,7 +205,11 @@ export declare interface PackageJSON {
|
|
|
207
205
|
}
|
|
208
206
|
|
|
209
207
|
/** @internal */
|
|
210
|
-
export declare function parseExports(options: {
|
|
208
|
+
export declare function parseExports(options: {
|
|
209
|
+
extMap: PkgExtMap
|
|
210
|
+
pkg: PackageJSON
|
|
211
|
+
strict: boolean
|
|
212
|
+
}): (PkgExport & {
|
|
211
213
|
_path: string
|
|
212
214
|
})[]
|
|
213
215
|
|
|
@@ -314,6 +316,18 @@ export declare interface PkgExports {
|
|
|
314
316
|
[path: string]: PkgExport
|
|
315
317
|
}
|
|
316
318
|
|
|
319
|
+
/** @internal */
|
|
320
|
+
export declare interface PkgExtMap {
|
|
321
|
+
commonjs: {
|
|
322
|
+
commonjs: string
|
|
323
|
+
esm: string
|
|
324
|
+
}
|
|
325
|
+
module: {
|
|
326
|
+
commonjs: string
|
|
327
|
+
esm: string
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
317
331
|
/** @public */
|
|
318
332
|
export declare type PkgFormat = 'commonjs' | 'esm'
|
|
319
333
|
|
package/dist/index.js
CHANGED
|
@@ -41,16 +41,6 @@ import prettyBytes from 'pretty-bytes';
|
|
|
41
41
|
import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
42
42
|
import globby from 'globby';
|
|
43
43
|
import chokidar from 'chokidar';
|
|
44
|
-
const MODULE_EXT = {
|
|
45
|
-
commonjs: {
|
|
46
|
-
commonjs: ".js",
|
|
47
|
-
esm: ".mjs"
|
|
48
|
-
},
|
|
49
|
-
module: {
|
|
50
|
-
commonjs: ".cjs",
|
|
51
|
-
esm: ".js"
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
44
|
const DEFAULT_BROWSERSLIST_QUERY = ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"];
|
|
55
45
|
function isRecord(value) {
|
|
56
46
|
return Boolean(value) && !Array.isArray(value) && typeof value === "object";
|
|
@@ -203,9 +193,10 @@ function formatPath(segments) {
|
|
|
203
193
|
}
|
|
204
194
|
function validateExports(_exports, options) {
|
|
205
195
|
const {
|
|
196
|
+
extMap,
|
|
206
197
|
pkg
|
|
207
198
|
} = options;
|
|
208
|
-
const ext =
|
|
199
|
+
const ext = extMap[pkg.type];
|
|
209
200
|
const errors = [];
|
|
210
201
|
for (const exp of _exports) {
|
|
211
202
|
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
@@ -219,6 +210,7 @@ function validateExports(_exports, options) {
|
|
|
219
210
|
}
|
|
220
211
|
function parseExports(options) {
|
|
221
212
|
const {
|
|
213
|
+
extMap,
|
|
222
214
|
pkg,
|
|
223
215
|
strict
|
|
224
216
|
} = options;
|
|
@@ -278,6 +270,7 @@ function parseExports(options) {
|
|
|
278
270
|
}
|
|
279
271
|
const _exports = [rootExport, ...extraExports];
|
|
280
272
|
errors.push(...validateExports(_exports, {
|
|
273
|
+
extMap,
|
|
281
274
|
pkg
|
|
282
275
|
}));
|
|
283
276
|
if (errors.length) {
|
|
@@ -285,6 +278,29 @@ function parseExports(options) {
|
|
|
285
278
|
}
|
|
286
279
|
return _exports;
|
|
287
280
|
}
|
|
281
|
+
const DEFAULT_PKG_EXT_MAP = {
|
|
282
|
+
commonjs: {
|
|
283
|
+
commonjs: ".js",
|
|
284
|
+
esm: ".mjs"
|
|
285
|
+
},
|
|
286
|
+
module: {
|
|
287
|
+
commonjs: ".cjs",
|
|
288
|
+
esm: ".js"
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
function getPkgExtMap(options) {
|
|
292
|
+
const {
|
|
293
|
+
legacyExports
|
|
294
|
+
} = options;
|
|
295
|
+
const ret = _objectSpread({}, DEFAULT_PKG_EXT_MAP);
|
|
296
|
+
if (legacyExports) {
|
|
297
|
+
ret["commonjs"] = {
|
|
298
|
+
commonjs: ".js",
|
|
299
|
+
esm: ".esm.js"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
288
304
|
async function loadTSConfig(options) {
|
|
289
305
|
const {
|
|
290
306
|
cwd,
|
|
@@ -435,6 +451,7 @@ async function resolveBuildContext(options) {
|
|
|
435
451
|
config,
|
|
436
452
|
cwd,
|
|
437
453
|
emitDeclarationOnly = false,
|
|
454
|
+
extMap,
|
|
438
455
|
logger,
|
|
439
456
|
pkg,
|
|
440
457
|
strict,
|
|
@@ -459,6 +476,7 @@ async function resolveBuildContext(options) {
|
|
|
459
476
|
node: nodeTarget
|
|
460
477
|
};
|
|
461
478
|
const parsedExports = parseExports({
|
|
479
|
+
extMap,
|
|
462
480
|
pkg,
|
|
463
481
|
strict
|
|
464
482
|
}).reduce((acc, x) => {
|
|
@@ -500,6 +518,7 @@ async function resolveBuildContext(options) {
|
|
|
500
518
|
emitDeclarationOnly,
|
|
501
519
|
exports,
|
|
502
520
|
external,
|
|
521
|
+
extMap,
|
|
503
522
|
files: [],
|
|
504
523
|
logger,
|
|
505
524
|
pkg,
|
|
@@ -670,13 +689,40 @@ function printExtractMessages(ctx, messages) {
|
|
|
670
689
|
process.exit(1);
|
|
671
690
|
}
|
|
672
691
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
692
|
+
function printDiagnostic(options) {
|
|
693
|
+
const {
|
|
694
|
+
cwd,
|
|
695
|
+
logger,
|
|
696
|
+
diagnostic
|
|
697
|
+
} = options;
|
|
698
|
+
if (diagnostic.file && diagnostic.start) {
|
|
699
|
+
const {
|
|
700
|
+
line,
|
|
701
|
+
character
|
|
702
|
+
} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
703
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
704
|
+
const file = path.relative(cwd, diagnostic.file.fileName);
|
|
705
|
+
const output = ["".concat(chalk.yellow(file), ":").concat(chalk.blue(line + 1), ":").concat(chalk.blue(character + 1), " - "), "".concat(chalk.gray("TS".concat(diagnostic.code, ":")), " ").concat(message)].join("");
|
|
706
|
+
if (diagnostic.category === ts.DiagnosticCategory.Error) {
|
|
707
|
+
logger.error(output);
|
|
708
|
+
}
|
|
709
|
+
if (diagnostic.category === ts.DiagnosticCategory.Warning) {
|
|
710
|
+
logger.warn(output);
|
|
711
|
+
}
|
|
712
|
+
if (diagnostic.category === ts.DiagnosticCategory.Message) {
|
|
713
|
+
logger.log(output);
|
|
714
|
+
}
|
|
715
|
+
if (diagnostic.category === ts.DiagnosticCategory.Suggestion) {
|
|
716
|
+
logger.log(output);
|
|
717
|
+
}
|
|
718
|
+
} else {
|
|
719
|
+
logger.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
678
722
|
async function buildTypes(options) {
|
|
679
723
|
const {
|
|
724
|
+
cwd,
|
|
725
|
+
logger,
|
|
680
726
|
outDir,
|
|
681
727
|
tsconfig,
|
|
682
728
|
strict = false
|
|
@@ -691,22 +737,16 @@ async function buildTypes(options) {
|
|
|
691
737
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
692
738
|
const emitResult = program.emit();
|
|
693
739
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
702
|
-
} else {
|
|
703
|
-
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
704
|
-
}
|
|
705
|
-
});
|
|
740
|
+
for (const diagnostic of allDiagnostics) {
|
|
741
|
+
printDiagnostic({
|
|
742
|
+
cwd,
|
|
743
|
+
logger,
|
|
744
|
+
diagnostic
|
|
745
|
+
});
|
|
746
|
+
}
|
|
706
747
|
if (emitResult.emitSkipped) {
|
|
707
748
|
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
708
749
|
if (errors.length) {
|
|
709
|
-
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
710
750
|
if (strict) {
|
|
711
751
|
throw new Error("failed to compile TypeScript definitions");
|
|
712
752
|
}
|
|
@@ -934,6 +974,7 @@ async function doExtract(ctx, task) {
|
|
|
934
974
|
config,
|
|
935
975
|
cwd,
|
|
936
976
|
files,
|
|
977
|
+
logger,
|
|
937
978
|
strict,
|
|
938
979
|
ts
|
|
939
980
|
} = ctx;
|
|
@@ -954,6 +995,7 @@ async function doExtract(ctx, task) {
|
|
|
954
995
|
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
955
996
|
await buildTypes({
|
|
956
997
|
cwd,
|
|
998
|
+
logger,
|
|
957
999
|
outDir: tmpPath,
|
|
958
1000
|
strict,
|
|
959
1001
|
tsconfig: ts.config
|
|
@@ -1050,6 +1092,53 @@ const dtsWatchTask = {
|
|
|
1050
1092
|
}
|
|
1051
1093
|
}
|
|
1052
1094
|
};
|
|
1095
|
+
function createConsoleSpy(options) {
|
|
1096
|
+
const {
|
|
1097
|
+
onRestored
|
|
1098
|
+
} = options;
|
|
1099
|
+
const original = {
|
|
1100
|
+
log: console.log,
|
|
1101
|
+
warn: console.warn,
|
|
1102
|
+
error: console.error
|
|
1103
|
+
};
|
|
1104
|
+
const messages = [];
|
|
1105
|
+
console.log = function () {
|
|
1106
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
1107
|
+
args[_key5] = arguments[_key5];
|
|
1108
|
+
}
|
|
1109
|
+
return messages.push({
|
|
1110
|
+
type: "log",
|
|
1111
|
+
args
|
|
1112
|
+
});
|
|
1113
|
+
};
|
|
1114
|
+
console.warn = function () {
|
|
1115
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1116
|
+
args[_key6] = arguments[_key6];
|
|
1117
|
+
}
|
|
1118
|
+
return messages.push({
|
|
1119
|
+
type: "warn",
|
|
1120
|
+
args
|
|
1121
|
+
});
|
|
1122
|
+
};
|
|
1123
|
+
console.error = function () {
|
|
1124
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1125
|
+
args[_key7] = arguments[_key7];
|
|
1126
|
+
}
|
|
1127
|
+
return messages.push({
|
|
1128
|
+
type: "error",
|
|
1129
|
+
args
|
|
1130
|
+
});
|
|
1131
|
+
};
|
|
1132
|
+
return {
|
|
1133
|
+
messages,
|
|
1134
|
+
restore: () => {
|
|
1135
|
+
console.log = original.log;
|
|
1136
|
+
console.warn = original.warn;
|
|
1137
|
+
console.error = original.error;
|
|
1138
|
+
onRestored(messages);
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1053
1142
|
function resolveRollupConfig(ctx, buildTask) {
|
|
1054
1143
|
var _ref4, _ref7, _ref8, _ref9, _ref10, _ref11;
|
|
1055
1144
|
var _a, _b, _c;
|
|
@@ -1062,14 +1151,15 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1062
1151
|
config,
|
|
1063
1152
|
cwd,
|
|
1064
1153
|
exports: _exports,
|
|
1154
|
+
extMap,
|
|
1065
1155
|
external,
|
|
1066
1156
|
distPath,
|
|
1067
1157
|
logger,
|
|
1068
1158
|
pkg,
|
|
1069
1159
|
ts
|
|
1070
1160
|
} = ctx;
|
|
1071
|
-
const outputExt =
|
|
1072
|
-
const minify = (_ref4 = config == null ? void 0 : config.minify) !== null && _ref4 !== void 0 ? _ref4 :
|
|
1161
|
+
const outputExt = extMap[pkg.type][format];
|
|
1162
|
+
const minify = (_ref4 = config == null ? void 0 : config.minify) !== null && _ref4 !== void 0 ? _ref4 : false;
|
|
1073
1163
|
const outDir = path.relative(cwd, distPath);
|
|
1074
1164
|
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref5 => {
|
|
1075
1165
|
let [key, val] = _ref5;
|
|
@@ -1171,10 +1261,22 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1171
1261
|
}
|
|
1172
1262
|
},
|
|
1173
1263
|
outputOptions: {
|
|
1174
|
-
chunkFileNames: () =>
|
|
1264
|
+
chunkFileNames: () => {
|
|
1265
|
+
const parts = outputExt.split(".");
|
|
1266
|
+
if (parts.length === 3) {
|
|
1267
|
+
return "_chunks/[name]-[hash].".concat(parts[2]);
|
|
1268
|
+
}
|
|
1269
|
+
return "_chunks/[name]-[hash]".concat(outputExt);
|
|
1270
|
+
},
|
|
1175
1271
|
compact: minify,
|
|
1176
1272
|
dir: outDir,
|
|
1177
|
-
entryFileNames: () =>
|
|
1273
|
+
entryFileNames: () => {
|
|
1274
|
+
const parts = outputExt.split(".");
|
|
1275
|
+
if (parts.length === 3) {
|
|
1276
|
+
return "[name].".concat(parts[2]);
|
|
1277
|
+
}
|
|
1278
|
+
return "[name]".concat(outputExt);
|
|
1279
|
+
},
|
|
1178
1280
|
esModule: true,
|
|
1179
1281
|
format,
|
|
1180
1282
|
interop: "compat",
|
|
@@ -1195,54 +1297,9 @@ const rollupTask = {
|
|
|
1195
1297
|
},
|
|
1196
1298
|
complete: () => {},
|
|
1197
1299
|
error: (_ctx, _task, err) => {
|
|
1198
|
-
|
|
1199
|
-
console.log(err);
|
|
1200
|
-
}
|
|
1300
|
+
console.error(err);
|
|
1201
1301
|
}
|
|
1202
1302
|
};
|
|
1203
|
-
function createSpyConsole() {
|
|
1204
|
-
const original = {
|
|
1205
|
-
log: console.log,
|
|
1206
|
-
warn: console.warn,
|
|
1207
|
-
error: console.error
|
|
1208
|
-
};
|
|
1209
|
-
const messages = [];
|
|
1210
|
-
console.log = function () {
|
|
1211
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
1212
|
-
args[_key5] = arguments[_key5];
|
|
1213
|
-
}
|
|
1214
|
-
return messages.push({
|
|
1215
|
-
type: "log",
|
|
1216
|
-
args
|
|
1217
|
-
});
|
|
1218
|
-
};
|
|
1219
|
-
console.warn = function () {
|
|
1220
|
-
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1221
|
-
args[_key6] = arguments[_key6];
|
|
1222
|
-
}
|
|
1223
|
-
return messages.push({
|
|
1224
|
-
type: "warn",
|
|
1225
|
-
args
|
|
1226
|
-
});
|
|
1227
|
-
};
|
|
1228
|
-
console.error = function () {
|
|
1229
|
-
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1230
|
-
args[_key7] = arguments[_key7];
|
|
1231
|
-
}
|
|
1232
|
-
return messages.push({
|
|
1233
|
-
type: "error",
|
|
1234
|
-
args
|
|
1235
|
-
});
|
|
1236
|
-
};
|
|
1237
|
-
return {
|
|
1238
|
-
messages,
|
|
1239
|
-
restore: () => {
|
|
1240
|
-
console.log = original.log;
|
|
1241
|
-
console.warn = original.warn;
|
|
1242
|
-
console.error = original.error;
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
1303
|
async function execPromise(ctx, task) {
|
|
1247
1304
|
const {
|
|
1248
1305
|
distPath,
|
|
@@ -1250,56 +1307,68 @@ async function execPromise(ctx, task) {
|
|
|
1250
1307
|
logger
|
|
1251
1308
|
} = ctx;
|
|
1252
1309
|
const outDir = path.relative(ctx.cwd, distPath);
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
continue;
|
|
1277
|
-
}
|
|
1278
|
-
if (msg.type === "log") {
|
|
1279
|
-
logger.info(...msg.args);
|
|
1280
|
-
}
|
|
1281
|
-
if (msg.type === "warn") {
|
|
1282
|
-
logger.warn(...msg.args);
|
|
1283
|
-
}
|
|
1284
|
-
if (msg.type === "error") {
|
|
1285
|
-
logger.error(...msg.args);
|
|
1310
|
+
const consoleSpy = createConsoleSpy({
|
|
1311
|
+
onRestored: messages => {
|
|
1312
|
+
for (const msg of messages) {
|
|
1313
|
+
const text = String(msg.args[0]);
|
|
1314
|
+
if (msg.code === "CIRCULAR_DEPENDENCY") {
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (text.startsWith("Dynamic import can only")) {
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (text.startsWith("Sourcemap is likely to be incorrect")) {
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
if (msg.type === "log") {
|
|
1324
|
+
logger.info(...msg.args);
|
|
1325
|
+
}
|
|
1326
|
+
if (msg.type === "warn") {
|
|
1327
|
+
logger.warn(...msg.args);
|
|
1328
|
+
}
|
|
1329
|
+
if (msg.type === "error") {
|
|
1330
|
+
logger.error(...msg.args);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1286
1333
|
}
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1334
|
+
});
|
|
1335
|
+
try {
|
|
1336
|
+
const {
|
|
1337
|
+
inputOptions,
|
|
1338
|
+
outputOptions
|
|
1339
|
+
} = resolveRollupConfig(ctx, task);
|
|
1340
|
+
const bundle = await rollup(_objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
1341
|
+
onwarn(warning) {
|
|
1342
|
+
consoleSpy.messages.push({
|
|
1343
|
+
type: "warn",
|
|
1344
|
+
code: warning.code,
|
|
1345
|
+
args: [warning.message]
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
}));
|
|
1349
|
+
const {
|
|
1350
|
+
output
|
|
1351
|
+
} = await bundle.generate(outputOptions);
|
|
1352
|
+
for (const chunkOrAsset of output) {
|
|
1353
|
+
if (chunkOrAsset.type === "asset") {
|
|
1354
|
+
files.push({
|
|
1355
|
+
type: "asset",
|
|
1356
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1357
|
+
});
|
|
1358
|
+
} else {
|
|
1359
|
+
files.push({
|
|
1360
|
+
type: "chunk",
|
|
1361
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1299
1364
|
}
|
|
1365
|
+
await bundle.write(outputOptions);
|
|
1366
|
+
await bundle.close();
|
|
1367
|
+
consoleSpy.restore();
|
|
1368
|
+
} catch (err) {
|
|
1369
|
+
consoleSpy.restore();
|
|
1370
|
+
throw err;
|
|
1300
1371
|
}
|
|
1301
|
-
await bundle.write(outputOptions);
|
|
1302
|
-
await bundle.close();
|
|
1303
1372
|
}
|
|
1304
1373
|
const rollupWatchTask = {
|
|
1305
1374
|
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
@@ -1362,6 +1431,7 @@ const watchTaskHandlers = {
|
|
|
1362
1431
|
"watch:js": rollupWatchTask
|
|
1363
1432
|
};
|
|
1364
1433
|
async function build(options) {
|
|
1434
|
+
var _ref12;
|
|
1365
1435
|
const {
|
|
1366
1436
|
cwd,
|
|
1367
1437
|
emitDeclarationOnly,
|
|
@@ -1376,11 +1446,15 @@ async function build(options) {
|
|
|
1376
1446
|
const config = await loadConfig({
|
|
1377
1447
|
cwd
|
|
1378
1448
|
});
|
|
1449
|
+
const extMap = getPkgExtMap({
|
|
1450
|
+
legacyExports: (_ref12 = config == null ? void 0 : config.legacyExports) !== null && _ref12 !== void 0 ? _ref12 : false
|
|
1451
|
+
});
|
|
1379
1452
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1380
1453
|
const ctx = await resolveBuildContext({
|
|
1381
1454
|
config,
|
|
1382
1455
|
cwd,
|
|
1383
1456
|
emitDeclarationOnly,
|
|
1457
|
+
extMap,
|
|
1384
1458
|
logger,
|
|
1385
1459
|
pkg,
|
|
1386
1460
|
strict,
|
|
@@ -1442,8 +1516,8 @@ function printPackageTree(ctx) {
|
|
|
1442
1516
|
type: chalk.yellow(pkg.type)
|
|
1443
1517
|
};
|
|
1444
1518
|
if (pkg.bin) {
|
|
1445
|
-
tree.bin = Object.fromEntries(Object.entries(pkg.bin).map(
|
|
1446
|
-
let [name, file] =
|
|
1519
|
+
tree.bin = Object.fromEntries(Object.entries(pkg.bin).map(_ref13 => {
|
|
1520
|
+
let [name, file] = _ref13;
|
|
1447
1521
|
return [chalk.cyan(name), fileInfo(file)];
|
|
1448
1522
|
}));
|
|
1449
1523
|
}
|
|
@@ -1454,11 +1528,11 @@ function printPackageTree(ctx) {
|
|
|
1454
1528
|
}
|
|
1455
1529
|
return "".concat(chalk.yellow(file), " ").concat(chalk.gray(info.size));
|
|
1456
1530
|
}
|
|
1457
|
-
tree.exports = Object.fromEntries(Object.entries(exports).filter(
|
|
1458
|
-
let [, entry] =
|
|
1531
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref14 => {
|
|
1532
|
+
let [, entry] = _ref14;
|
|
1459
1533
|
return entry._exported;
|
|
1460
|
-
}).map(
|
|
1461
|
-
let [exportPath, entry] =
|
|
1534
|
+
}).map(_ref15 => {
|
|
1535
|
+
let [exportPath, entry] = _ref15;
|
|
1462
1536
|
const exp = {
|
|
1463
1537
|
types: void 0,
|
|
1464
1538
|
source: fileInfo(entry.source),
|
|
@@ -1506,6 +1580,7 @@ function printPackageTree(ctx) {
|
|
|
1506
1580
|
logger.log(treeify.asTree(tree, true, true));
|
|
1507
1581
|
}
|
|
1508
1582
|
async function check(options) {
|
|
1583
|
+
var _ref16;
|
|
1509
1584
|
const {
|
|
1510
1585
|
cwd,
|
|
1511
1586
|
strict = false,
|
|
@@ -1519,10 +1594,14 @@ async function check(options) {
|
|
|
1519
1594
|
const config = await loadConfig({
|
|
1520
1595
|
cwd
|
|
1521
1596
|
});
|
|
1597
|
+
const extMap = getPkgExtMap({
|
|
1598
|
+
legacyExports: (_ref16 = config == null ? void 0 : config.legacyExports) !== null && _ref16 !== void 0 ? _ref16 : false
|
|
1599
|
+
});
|
|
1522
1600
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1523
1601
|
const ctx = await resolveBuildContext({
|
|
1524
1602
|
config,
|
|
1525
1603
|
cwd,
|
|
1604
|
+
extMap,
|
|
1526
1605
|
logger,
|
|
1527
1606
|
pkg,
|
|
1528
1607
|
strict,
|
|
@@ -1628,8 +1707,8 @@ function resolveWatchTasks(ctx) {
|
|
|
1628
1707
|
target
|
|
1629
1708
|
} = ctx;
|
|
1630
1709
|
const tasks = [];
|
|
1631
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1632
|
-
let [_path, exp] =
|
|
1710
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref17 => {
|
|
1711
|
+
let [_path, exp] = _ref17;
|
|
1633
1712
|
return _objectSpread({
|
|
1634
1713
|
_path
|
|
1635
1714
|
}, exp);
|
|
@@ -1773,6 +1852,7 @@ async function watch(options) {
|
|
|
1773
1852
|
logger
|
|
1774
1853
|
});
|
|
1775
1854
|
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1855
|
+
var _ref18;
|
|
1776
1856
|
const files = configFiles.map(f => path.relative(cwd, f));
|
|
1777
1857
|
const packageJsonPath = files.find(f => f === "package.json");
|
|
1778
1858
|
if (!packageJsonPath) {
|
|
@@ -1785,10 +1865,14 @@ async function watch(options) {
|
|
|
1785
1865
|
const config = await loadConfig({
|
|
1786
1866
|
cwd
|
|
1787
1867
|
});
|
|
1868
|
+
const extMap = getPkgExtMap({
|
|
1869
|
+
legacyExports: (_ref18 = config == null ? void 0 : config.legacyExports) !== null && _ref18 !== void 0 ? _ref18 : false
|
|
1870
|
+
});
|
|
1788
1871
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1789
1872
|
return resolveBuildContext({
|
|
1790
1873
|
config,
|
|
1791
1874
|
cwd,
|
|
1875
|
+
extMap,
|
|
1792
1876
|
logger,
|
|
1793
1877
|
pkg,
|
|
1794
1878
|
strict,
|
|
@@ -1817,5 +1901,5 @@ async function watch(options) {
|
|
|
1817
1901
|
}
|
|
1818
1902
|
});
|
|
1819
1903
|
}
|
|
1820
|
-
export { DEFAULT_BROWSERSLIST_QUERY,
|
|
1904
|
+
export { DEFAULT_BROWSERSLIST_QUERY, DEFAULT_PKG_EXT_MAP, build, buildTaskHandlers, check, createLogger, defineConfig, dtsTask, dtsWatchTask, getExtractMessagesConfig, getPkgExtMap, isRecord, loadConfig, loadPkg, loadPkgWithReporting, loadTSConfig, parseExports, resolveBuildTasks, resolveConfigProperty, rollupTask, rollupWatchTask, watch, watchTaskHandlers };
|
|
1821
1905
|
//# sourceMappingURL=index.js.map
|