prebundle 1.0.4 → 1.1.0-beta.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.
@@ -1 +1 @@
1
- {"name":"fs-extra","author":"JP Richardson <jprichardson@gmail.com>","version":"11.2.0","license":"MIT","type":"commonjs"}
1
+ {"name":"fs-extra","author":"JP Richardson <jprichardson@gmail.com>","version":"11.2.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -0,0 +1,66 @@
1
+ type ColorFn = (input: string | number | null | undefined) => string;
2
+
3
+ declare let LOG_TYPES: {
4
+ error: {
5
+ label: string;
6
+ level: "error";
7
+ color: ColorFn;
8
+ };
9
+ warn: {
10
+ label: string;
11
+ level: "warn";
12
+ color: ColorFn;
13
+ };
14
+ info: {
15
+ label: string;
16
+ level: "info";
17
+ color: ColorFn;
18
+ };
19
+ start: {
20
+ label: string;
21
+ level: "info";
22
+ color: ColorFn;
23
+ };
24
+ ready: {
25
+ label: string;
26
+ level: "info";
27
+ color: ColorFn;
28
+ };
29
+ success: {
30
+ label: string;
31
+ level: "info";
32
+ color: ColorFn;
33
+ };
34
+ log: {
35
+ level: "log";
36
+ };
37
+ debug: {
38
+ label: string;
39
+ level: "verbose";
40
+ color: ColorFn;
41
+ };
42
+ };
43
+
44
+ type LogLevel = 'error' | 'warn' | 'info' | 'log' | 'verbose';
45
+ type LogMessage = unknown;
46
+ interface LogType {
47
+ label?: string;
48
+ level: LogLevel;
49
+ color?: ColorFn;
50
+ }
51
+ type LogFunction = (message?: LogMessage, ...args: any[]) => void;
52
+ interface Options {
53
+ level?: LogLevel;
54
+ }
55
+ type LogMethods = keyof typeof LOG_TYPES;
56
+ type Logger = Record<LogMethods, LogFunction> & {
57
+ greet: (message: string) => void;
58
+ level: LogLevel;
59
+ override: (customLogger: Partial<Record<LogMethods, LogFunction>>) => void;
60
+ };
61
+
62
+ declare let createLogger: (options?: Options) => Logger;
63
+
64
+ declare let logger: Logger;
65
+
66
+ export { type LogFunction, type LogLevel, type LogMessage, type LogType, type Logger, type Options, createLogger, logger };
@@ -0,0 +1,410 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ var __webpack_modules__ = ({
4
+
5
+ /***/ 37:
6
+ /***/ ((module) => {
7
+
8
+ module.exports = require("os");
9
+
10
+ /***/ }),
11
+
12
+ /***/ 282:
13
+ /***/ ((module) => {
14
+
15
+ module.exports = require("process");
16
+
17
+ /***/ }),
18
+
19
+ /***/ 224:
20
+ /***/ ((module) => {
21
+
22
+ module.exports = require("tty");
23
+
24
+ /***/ }),
25
+
26
+ /***/ 103:
27
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
28
+
29
+
30
+ var __create = Object.create;
31
+ var __defProp = Object.defineProperty;
32
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
33
+ var __getOwnPropNames = Object.getOwnPropertyNames;
34
+ var __getProtoOf = Object.getPrototypeOf;
35
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
36
+ var __export = (target, all) => {
37
+ for (var name in all)
38
+ __defProp(target, name, { get: all[name], enumerable: true });
39
+ };
40
+ var __copyProps = (to, from, except, desc) => {
41
+ if (from && typeof from === "object" || typeof from === "function") {
42
+ for (let key of __getOwnPropNames(from))
43
+ if (!__hasOwnProp.call(to, key) && key !== except)
44
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
45
+ }
46
+ return to;
47
+ };
48
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
49
+ // If the importer is in node compatibility mode or this is not an ESM
50
+ // file that has been converted to a CommonJS file using a Babel-
51
+ // compatible transform (i.e. "__esModule" has not been set), then set
52
+ // "default" to the CommonJS "module.exports" for node compatibility.
53
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
54
+ mod
55
+ ));
56
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
57
+
58
+ // src/index.ts
59
+ var src_exports = {};
60
+ __export(src_exports, {
61
+ createLogger: () => createLogger,
62
+ logger: () => logger
63
+ });
64
+ module.exports = __toCommonJS(src_exports);
65
+
66
+ // node_modules/.pnpm/supports-color@9.4.0/node_modules/supports-color/index.js
67
+ var import_node_process = __toESM(__nccwpck_require__(282));
68
+ var import_node_os = __toESM(__nccwpck_require__(37));
69
+ var import_node_tty = __toESM(__nccwpck_require__(224));
70
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
71
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
72
+ const position = argv.indexOf(prefix + flag);
73
+ const terminatorPosition = argv.indexOf("--");
74
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
75
+ }
76
+ var { env } = import_node_process.default;
77
+ var flagForceColor;
78
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
79
+ flagForceColor = 0;
80
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
81
+ flagForceColor = 1;
82
+ }
83
+ function envForceColor() {
84
+ if ("FORCE_COLOR" in env) {
85
+ if (env.FORCE_COLOR === "true") {
86
+ return 1;
87
+ }
88
+ if (env.FORCE_COLOR === "false") {
89
+ return 0;
90
+ }
91
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
92
+ }
93
+ }
94
+ function translateLevel(level) {
95
+ if (level === 0) {
96
+ return false;
97
+ }
98
+ return {
99
+ level,
100
+ hasBasic: true,
101
+ has256: level >= 2,
102
+ has16m: level >= 3
103
+ };
104
+ }
105
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
106
+ const noFlagForceColor = envForceColor();
107
+ if (noFlagForceColor !== void 0) {
108
+ flagForceColor = noFlagForceColor;
109
+ }
110
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
111
+ if (forceColor === 0) {
112
+ return 0;
113
+ }
114
+ if (sniffFlags) {
115
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
116
+ return 3;
117
+ }
118
+ if (hasFlag("color=256")) {
119
+ return 2;
120
+ }
121
+ }
122
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
123
+ return 1;
124
+ }
125
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
126
+ return 0;
127
+ }
128
+ const min = forceColor || 0;
129
+ if (env.TERM === "dumb") {
130
+ return min;
131
+ }
132
+ if (import_node_process.default.platform === "win32") {
133
+ const osRelease = import_node_os.default.release().split(".");
134
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
135
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
136
+ }
137
+ return 1;
138
+ }
139
+ if ("CI" in env) {
140
+ if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
141
+ return 3;
142
+ }
143
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
144
+ return 1;
145
+ }
146
+ return min;
147
+ }
148
+ if ("TEAMCITY_VERSION" in env) {
149
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
150
+ }
151
+ if (env.COLORTERM === "truecolor") {
152
+ return 3;
153
+ }
154
+ if (env.TERM === "xterm-kitty") {
155
+ return 3;
156
+ }
157
+ if ("TERM_PROGRAM" in env) {
158
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
159
+ switch (env.TERM_PROGRAM) {
160
+ case "iTerm.app": {
161
+ return version >= 3 ? 3 : 2;
162
+ }
163
+ case "Apple_Terminal": {
164
+ return 2;
165
+ }
166
+ }
167
+ }
168
+ if (/-256(color)?$/i.test(env.TERM)) {
169
+ return 2;
170
+ }
171
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
172
+ return 1;
173
+ }
174
+ if ("COLORTERM" in env) {
175
+ return 1;
176
+ }
177
+ return min;
178
+ }
179
+ function createSupportsColor(stream, options = {}) {
180
+ const level = _supportsColor(stream, {
181
+ streamIsTTY: stream && stream.isTTY,
182
+ ...options
183
+ });
184
+ return translateLevel(level);
185
+ }
186
+ var supportsColor = {
187
+ stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
188
+ stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
189
+ };
190
+ var supports_color_default = supportsColor;
191
+
192
+ // src/utils.ts
193
+ var colorLevel = supports_color_default.stdout ? supports_color_default.stdout.level : 0;
194
+ var errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/;
195
+ var anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
196
+ var isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
197
+
198
+ // src/color.ts
199
+ var formatter = (open, close, replace = open) => colorLevel >= 2 ? (input) => {
200
+ let string = "" + input;
201
+ let index = string.indexOf(close, open.length);
202
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
203
+ } : String;
204
+ var replaceClose = (string, close, replace, index) => {
205
+ let start = string.substring(0, index) + replace;
206
+ let end = string.substring(index + close.length);
207
+ let nextIndex = end.indexOf(close);
208
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
209
+ };
210
+ var bold = formatter("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m");
211
+ var red = formatter("\x1B[31m", "\x1B[39m");
212
+ var green = formatter("\x1B[32m", "\x1B[39m");
213
+ var yellow = formatter("\x1B[33m", "\x1B[39m");
214
+ var magenta = formatter("\x1B[35m", "\x1B[39m");
215
+ var cyan = formatter("\x1B[36m", "\x1B[39m");
216
+ var gray = formatter("\x1B[90m", "\x1B[39m");
217
+
218
+ // src/gradient.ts
219
+ var startColor = [189, 255, 243];
220
+ var endColor = [74, 194, 154];
221
+ var isWord = (char) => !/[\s\n]/.test(char);
222
+ var gradient = (message) => {
223
+ if (colorLevel < 3) {
224
+ return colorLevel === 2 ? bold(cyan(message)) : message;
225
+ }
226
+ let chars = [...message];
227
+ let steps = chars.filter(isWord).length;
228
+ let r = startColor[0];
229
+ let g = startColor[1];
230
+ let b = startColor[2];
231
+ let rStep = (endColor[0] - r) / steps;
232
+ let gStep = (endColor[1] - g) / steps;
233
+ let bStep = (endColor[2] - b) / steps;
234
+ let output = "";
235
+ for (let char of chars) {
236
+ if (isWord(char)) {
237
+ r += rStep;
238
+ g += gStep;
239
+ b += bStep;
240
+ }
241
+ output += `\x1B[38;2;${Math.round(r)};${Math.round(g)};${Math.round(
242
+ b
243
+ )}m${char}\x1B[39m`;
244
+ }
245
+ return bold(output);
246
+ };
247
+
248
+ // src/constants.ts
249
+ var LOG_LEVEL = {
250
+ error: 0,
251
+ warn: 1,
252
+ info: 2,
253
+ log: 3,
254
+ verbose: 4
255
+ };
256
+ var LOG_TYPES = {
257
+ // Level error
258
+ error: {
259
+ label: "error",
260
+ level: "error",
261
+ color: red
262
+ },
263
+ // Level warn
264
+ warn: {
265
+ label: "warn",
266
+ level: "warn",
267
+ color: yellow
268
+ },
269
+ // Level info
270
+ info: {
271
+ label: "info",
272
+ level: "info",
273
+ color: cyan
274
+ },
275
+ start: {
276
+ label: "start",
277
+ level: "info",
278
+ color: cyan
279
+ },
280
+ ready: {
281
+ label: "ready",
282
+ level: "info",
283
+ color: green
284
+ },
285
+ success: {
286
+ label: "success",
287
+ level: "info",
288
+ color: green
289
+ },
290
+ // Level log
291
+ log: {
292
+ level: "log"
293
+ },
294
+ // Level debug
295
+ debug: {
296
+ label: "debug",
297
+ level: "verbose",
298
+ color: magenta
299
+ }
300
+ };
301
+
302
+ // src/createLogger.ts
303
+ var createLogger = (options = {}) => {
304
+ let maxLevel = options.level || "log";
305
+ let log = (type, message, ...args) => {
306
+ if (LOG_LEVEL[LOG_TYPES[type].level] > LOG_LEVEL[maxLevel]) {
307
+ return;
308
+ }
309
+ if (message === void 0 || message === null) {
310
+ return console.log();
311
+ }
312
+ let logType = LOG_TYPES[type];
313
+ let label = "";
314
+ let text = "";
315
+ if ("label" in logType) {
316
+ label = (logType.label || "").padEnd(7);
317
+ label = bold(logType.color ? logType.color(label) : label);
318
+ }
319
+ if (message instanceof Error) {
320
+ if (message.stack) {
321
+ let [name, ...rest] = message.stack.split("\n");
322
+ if (name.startsWith("Error: ")) {
323
+ name = name.slice(7);
324
+ }
325
+ text = `${name}
326
+ ${gray(rest.join("\n"))}`;
327
+ } else {
328
+ text = message.message;
329
+ }
330
+ } else if (logType.level === "error" && typeof message === "string") {
331
+ let lines = message.split("\n");
332
+ text = lines.map((line) => isErrorStackMessage(line) ? gray(line) : line).join("\n");
333
+ } else {
334
+ text = `${message}`;
335
+ }
336
+ console.log(label.length ? `${label} ${text}` : text, ...args);
337
+ };
338
+ let logger2 = {
339
+ greet: (message) => log("log", gradient(message))
340
+ };
341
+ Object.keys(LOG_TYPES).forEach((key) => {
342
+ logger2[key] = (...args) => log(key, ...args);
343
+ });
344
+ Object.defineProperty(logger2, "level", {
345
+ get: () => maxLevel,
346
+ set(val) {
347
+ maxLevel = val;
348
+ }
349
+ });
350
+ logger2.override = (customLogger) => {
351
+ Object.assign(logger2, customLogger);
352
+ };
353
+ return logger2;
354
+ };
355
+
356
+ // src/index.ts
357
+ var logger = createLogger();
358
+ // Annotate the CommonJS export names for ESM import in node:
359
+ 0 && (0);
360
+
361
+
362
+ /***/ })
363
+
364
+ /******/ });
365
+ /************************************************************************/
366
+ /******/ // The module cache
367
+ /******/ var __webpack_module_cache__ = {};
368
+ /******/
369
+ /******/ // The require function
370
+ /******/ function __nccwpck_require__(moduleId) {
371
+ /******/ // Check if module is in cache
372
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
373
+ /******/ if (cachedModule !== undefined) {
374
+ /******/ return cachedModule.exports;
375
+ /******/ }
376
+ /******/ // Create a new module (and put it into the cache)
377
+ /******/ var module = __webpack_module_cache__[moduleId] = {
378
+ /******/ // no module.id needed
379
+ /******/ // no module.loaded needed
380
+ /******/ exports: {}
381
+ /******/ };
382
+ /******/
383
+ /******/ // Execute the module function
384
+ /******/ var threw = true;
385
+ /******/ try {
386
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
387
+ /******/ threw = false;
388
+ /******/ } finally {
389
+ /******/ if(threw) delete __webpack_module_cache__[moduleId];
390
+ /******/ }
391
+ /******/
392
+ /******/ // Return the exports of the module
393
+ /******/ return module.exports;
394
+ /******/ }
395
+ /******/
396
+ /************************************************************************/
397
+ /******/ /* webpack/runtime/compat */
398
+ /******/
399
+ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
400
+ /******/
401
+ /************************************************************************/
402
+ /******/
403
+ /******/ // startup
404
+ /******/ // Load entry module and return exports
405
+ /******/ // This entry module is referenced by other modules so it can't be inlined
406
+ /******/ var __webpack_exports__ = __nccwpck_require__(103);
407
+ /******/ module.exports = __webpack_exports__;
408
+ /******/
409
+ /******/ })()
410
+ ;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ {"name":"rslog","version":"1.2.2","types":"index.d.ts","type":"commonjs"}
package/dist/helper.js CHANGED
@@ -2,7 +2,6 @@ import { dirname, join } from 'node:path';
2
2
  import fs from '../compiled/fs-extra/index.js';
3
3
  import { cwd, DIST_DIR } from './constant.js';
4
4
  import { createRequire } from 'node:module';
5
- import { pathToFileURL } from 'node:url';
6
5
  const require = createRequire(import.meta.url);
7
6
  export function findDepPath(name) {
8
7
  let entry = dirname(require.resolve(join(name), { paths: [cwd] }));
@@ -16,7 +15,7 @@ export function findDepPath(name) {
16
15
  }
17
16
  export const resolveConfig = async () => {
18
17
  const configPath = join(cwd, 'prebundle.config.mjs');
19
- const config = await import(pathToFileURL(configPath).href);
18
+ const config = await import(configPath);
20
19
  return config.default;
21
20
  };
22
21
  export function parseTasks(dependencies) {
@@ -36,7 +35,8 @@ export function parseTasks(dependencies) {
36
35
  };
37
36
  if (typeof dep === 'string') {
38
37
  result.push({
39
- minify: true,
38
+ minify: false,
39
+ target: 'es2019',
40
40
  externals: {},
41
41
  emitFiles: [],
42
42
  packageJsonField: [],
@@ -45,7 +45,8 @@ export function parseTasks(dependencies) {
45
45
  }
46
46
  else {
47
47
  result.push({
48
- minify: dep.minify ?? true,
48
+ minify: dep.minify ?? false,
49
+ target: dep.target ?? 'es2019',
49
50
  ignoreDts: dep.ignoreDts,
50
51
  externals: dep.externals ?? {},
51
52
  emitFiles: dep.emitFiles ?? [],
package/dist/prebundle.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { join } from 'node:path';
2
2
  import ncc from '@vercel/ncc';
3
- import { Package as DtsPacker } from 'dts-packer';
4
3
  import fastGlob from '../compiled/fast-glob/index.js';
5
4
  import fs from '../compiled/fs-extra/index.js';
6
- import { cwd, DEFAULT_EXTERNALS } from './constant.js';
5
+ import { logger } from 'rslog';
6
+ import { DEFAULT_EXTERNALS } from './constant.js';
7
7
  import { pick, replaceFileContent } from './helper.js';
8
+ import { dts } from 'rollup-plugin-dts';
9
+ import { rollup } from 'rollup';
8
10
  function emitAssets(assets, distPath) {
9
11
  for (const key of Object.keys(assets)) {
10
12
  const asset = assets[key];
@@ -25,25 +27,65 @@ function fixTypeExternalPath(file, task, externals) {
25
27
  return newContent;
26
28
  });
27
29
  }
28
- function emitDts(task, externals) {
29
- if (task.ignoreDts) {
30
+ async function emitDts(task, externals) {
31
+ const outputDefaultDts = () => {
30
32
  fs.writeFileSync(join(task.distPath, 'index.d.ts'), 'export = any;\n');
33
+ };
34
+ if (task.ignoreDts) {
35
+ outputDefaultDts();
36
+ return;
37
+ }
38
+ const pkgPath = join(task.depPath, 'package.json');
39
+ const pkgJson = fs.readJsonSync(pkgPath, 'utf-8');
40
+ const types = pkgJson.types || pkgJson.typing || pkgJson.typings;
41
+ if (!types) {
42
+ outputDefaultDts();
31
43
  return;
32
44
  }
33
45
  try {
34
- const { files } = new DtsPacker({
35
- cwd,
36
- name: task.depName,
37
- typesRoot: task.distPath,
38
- externals: Object.keys(externals),
39
- });
40
- for (const file of Object.keys(files)) {
41
- fixTypeExternalPath(file, task, externals);
42
- }
46
+ const inputConfig = {
47
+ input: join(task.depPath, types),
48
+ external: Object.keys(externals),
49
+ plugins: [
50
+ dts({
51
+ respectExternal: true,
52
+ compilerOptions: {
53
+ skipLibCheck: true,
54
+ // https://github.com/Swatinem/rollup-plugin-dts/issues/143,
55
+ // but it will cause error when bundle ts which import another ts file.
56
+ preserveSymlinks: false,
57
+ // https://github.com/Swatinem/rollup-plugin-dts/issues/127
58
+ composite: false,
59
+ // https://github.com/Swatinem/rollup-plugin-dts/issues/113
60
+ declarationMap: false,
61
+ // Ensure ".d.ts" modules are generated
62
+ declaration: true,
63
+ // Skip ".js" generation
64
+ noEmit: false,
65
+ emitDeclarationOnly: true,
66
+ // Skip code generation when error occurs
67
+ noEmitOnError: true,
68
+ // Avoid extra work
69
+ checkJs: false,
70
+ // Ensure we can parse the latest code
71
+ // @ts-expect-error
72
+ target: task.target,
73
+ },
74
+ }),
75
+ ],
76
+ };
77
+ const outputConfig = {
78
+ dir: task.distPath,
79
+ format: 'esm',
80
+ exports: 'named',
81
+ entryFileNames: '[name].ts',
82
+ };
83
+ const bundle = await rollup(inputConfig);
84
+ await bundle.write(outputConfig);
43
85
  }
44
86
  catch (error) {
45
- console.error(`DtsPacker failed: ${task.depName}`);
46
- console.error(error);
87
+ logger.error(`rollup-plugin-dts failed: ${task.depName}`);
88
+ logger.error(error);
47
89
  }
48
90
  }
49
91
  function emitPackageJson(task) {
@@ -56,19 +98,12 @@ function emitPackageJson(task) {
56
98
  'version',
57
99
  'funding',
58
100
  'license',
59
- 'types',
60
- 'typing',
61
- 'typings',
62
101
  ...task.packageJsonField,
63
102
  ]);
64
103
  if (task.depName !== pickedPackageJson.name) {
65
104
  pickedPackageJson.name = task.depName;
66
105
  }
67
- if (task.ignoreDts) {
68
- delete pickedPackageJson.typing;
69
- delete pickedPackageJson.typings;
70
- pickedPackageJson.types = 'index.d.ts';
71
- }
106
+ pickedPackageJson.types = 'index.d.ts';
72
107
  fs.writeJSONSync(outputPath, pickedPackageJson);
73
108
  }
74
109
  function emitLicense(task) {
@@ -112,7 +147,7 @@ export async function prebundle(task, commonExternals = {}) {
112
147
  if (pkgName && task.depName !== pkgName) {
113
148
  return;
114
149
  }
115
- console.log(`==== Start prebundle "${task.depName}" ====`);
150
+ logger.info(`prebundle: ${task.depName}`);
116
151
  fs.removeSync(task.distPath);
117
152
  if (task.beforeBundle) {
118
153
  await task.beforeBundle(task);
@@ -124,13 +159,13 @@ export async function prebundle(task, commonExternals = {}) {
124
159
  };
125
160
  const { code, assets } = await ncc(task.depEntry, {
126
161
  minify: task.minify,
127
- target: 'es2019',
162
+ target: task.target,
128
163
  externals: mergedExternals,
129
164
  assetBuilds: false,
130
165
  });
131
166
  emitIndex(code, task.distPath);
132
167
  emitAssets(assets, task.distPath);
133
- emitDts(task, mergedExternals);
168
+ await emitDts(task, mergedExternals);
134
169
  emitLicense(task);
135
170
  emitPackageJson(task);
136
171
  removeSourceMap(task);
@@ -139,5 +174,5 @@ export async function prebundle(task, commonExternals = {}) {
139
174
  if (task.afterBundle) {
140
175
  await task.afterBundle(task);
141
176
  }
142
- console.log(`==== Finish prebundle "${task.depName}" ====\n\n`);
177
+ logger.success(`prebundle: ${task.depName}\n\n`);
143
178
  }