prebundle 1.2.4 → 1.2.7
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/compiled/fast-glob/index.js +361 -289
- package/compiled/fast-glob/package.json +1 -1
- package/compiled/fs-extra/index.js +185 -174
- package/compiled/fs-extra/license +1 -1
- package/compiled/fs-extra/package.json +1 -1
- package/compiled/rslog/index.js +9 -9
- package/compiled/rslog/package.json +1 -1
- package/dist/constant.d.ts +8 -0
- package/dist/helper.d.ts +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +353 -0
- package/dist/prebundle.d.ts +2 -0
- package/dist/types.d.ts +53 -0
- package/package.json +14 -14
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(The MIT License)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2011-
|
|
3
|
+
Copyright (c) 2011-2024 JP Richardson
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
|
6
6
|
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"fs-extra","author":"JP Richardson <jprichardson@gmail.com>","version":"11.
|
|
1
|
+
{"name":"fs-extra","author":"JP Richardson <jprichardson@gmail.com>","version":"11.3.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
|
package/compiled/rslog/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
"use strict";
|
|
3
3
|
var __webpack_modules__ = {
|
|
4
|
-
|
|
4
|
+
857: (module) => {
|
|
5
5
|
module.exports = require("os");
|
|
6
6
|
},
|
|
7
|
-
|
|
7
|
+
932: (module) => {
|
|
8
8
|
module.exports = require("process");
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
18: (module) => {
|
|
11
11
|
module.exports = require("tty");
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
436: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
14
14
|
var __create = Object.create;
|
|
15
15
|
var __defProp = Object.defineProperty;
|
|
16
16
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
logger: () => logger,
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(src_exports);
|
|
53
|
-
var import_node_process = __toESM(__nccwpck_require__(
|
|
54
|
-
var import_node_os = __toESM(__nccwpck_require__(
|
|
55
|
-
var import_node_tty = __toESM(__nccwpck_require__(
|
|
53
|
+
var import_node_process = __toESM(__nccwpck_require__(932));
|
|
54
|
+
var import_node_os = __toESM(__nccwpck_require__(857));
|
|
55
|
+
var import_node_tty = __toESM(__nccwpck_require__(18));
|
|
56
56
|
function hasFlag(
|
|
57
57
|
flag,
|
|
58
58
|
argv = globalThis.Deno
|
|
@@ -232,7 +232,7 @@
|
|
|
232
232
|
? supports_color_default.stdout.level
|
|
233
233
|
: 0;
|
|
234
234
|
var errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/;
|
|
235
|
-
var anonymousErrorStackRegExp =
|
|
235
|
+
var anonymousErrorStackRegExp = /at\s.*\(<anonymous>\)$/;
|
|
236
236
|
var isErrorStackMessage = (message) =>
|
|
237
237
|
errorStackRegExp.test(message) ||
|
|
238
238
|
anonymousErrorStackRegExp.test(message);
|
|
@@ -375,6 +375,6 @@
|
|
|
375
375
|
}
|
|
376
376
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
377
377
|
__nccwpck_require__.ab = __dirname + "/";
|
|
378
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
378
|
+
var __webpack_exports__ = __nccwpck_require__(436);
|
|
379
379
|
module.exports = __webpack_exports__;
|
|
380
380
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"rslog","version":"1.2.
|
|
1
|
+
{"name":"rslog","version":"1.2.3","types":"index.d.ts","type":"commonjs"}
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config, DependencyConfig, ParsedTask } from './types.js';
|
|
2
|
+
export declare function findDepPath(name: string): string | null;
|
|
3
|
+
export declare const resolveConfig: () => Promise<Config>;
|
|
4
|
+
export declare function parseTasks(dependencies: Array<string | DependencyConfig>, globalPrettier?: boolean): ParsedTask[];
|
|
5
|
+
export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U>): Pick<T, U>;
|
|
6
|
+
export declare function replaceFileContent(filePath: string, replaceFn: (content: string) => string): void;
|
|
7
|
+
export declare function pkgNameToAtTypes(name: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Find the direct type file for a given file path.
|
|
10
|
+
* @param filepath
|
|
11
|
+
*/
|
|
12
|
+
export declare function findDirectTypeFile(filepath: string): string | undefined;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__ from "../compiled/fs-extra/index.js";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__vercel_ncc_57e68fb3__ from "@vercel/ncc";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js_8d514d69__ from "../compiled/fast-glob/index.js";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__ from "../compiled/rslog/index.js";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_rollup_plugin_dts_1c9650fc__ from "rollup-plugin-dts";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_rollup__ from "rollup";
|
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE_terser__ from "terser";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE_prettier__ from "prettier";
|
|
12
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
13
|
+
const DIST_DIR = 'compiled';
|
|
14
|
+
const DEFAULT_EXTERNALS = {
|
|
15
|
+
'./package.json': './package.json',
|
|
16
|
+
'../package.json': './package.json',
|
|
17
|
+
'../../package.json': './package.json'
|
|
18
|
+
};
|
|
19
|
+
const NODE_BUILTINS = [
|
|
20
|
+
'_stream_duplex',
|
|
21
|
+
'_stream_passthrough',
|
|
22
|
+
'_stream_readable',
|
|
23
|
+
'_stream_transform',
|
|
24
|
+
'_stream_writable',
|
|
25
|
+
'assert',
|
|
26
|
+
'buffer',
|
|
27
|
+
'child_process',
|
|
28
|
+
'cluster',
|
|
29
|
+
'console',
|
|
30
|
+
'constants',
|
|
31
|
+
'crypto',
|
|
32
|
+
'dgram',
|
|
33
|
+
'dns',
|
|
34
|
+
'domain',
|
|
35
|
+
'events',
|
|
36
|
+
'fs',
|
|
37
|
+
'http',
|
|
38
|
+
'https',
|
|
39
|
+
'module',
|
|
40
|
+
'net',
|
|
41
|
+
'os',
|
|
42
|
+
'path',
|
|
43
|
+
'process',
|
|
44
|
+
'punycode',
|
|
45
|
+
'querystring',
|
|
46
|
+
'readline',
|
|
47
|
+
'repl',
|
|
48
|
+
'stream',
|
|
49
|
+
'string_decoder',
|
|
50
|
+
'sys',
|
|
51
|
+
'timers',
|
|
52
|
+
'tls',
|
|
53
|
+
'tty',
|
|
54
|
+
'url',
|
|
55
|
+
'util',
|
|
56
|
+
'vm',
|
|
57
|
+
'zlib'
|
|
58
|
+
];
|
|
59
|
+
const cwd = process.cwd();
|
|
60
|
+
const helper_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
|
|
61
|
+
function findDepPath(name) {
|
|
62
|
+
try {
|
|
63
|
+
let entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(helper_require.resolve((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(name), {
|
|
64
|
+
paths: [
|
|
65
|
+
cwd
|
|
66
|
+
]
|
|
67
|
+
}));
|
|
68
|
+
while(!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(entry).endsWith('node_modules'))entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(entry);
|
|
69
|
+
if (name.includes('/')) return (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(entry), name);
|
|
70
|
+
return entry;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const resolveConfig = async ()=>{
|
|
76
|
+
const configPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, 'prebundle.config.mjs');
|
|
77
|
+
const config = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(configPath).href);
|
|
78
|
+
return config.default;
|
|
79
|
+
};
|
|
80
|
+
function parseTasks(dependencies, globalPrettier) {
|
|
81
|
+
const result = [];
|
|
82
|
+
for (const dep of dependencies){
|
|
83
|
+
const depName = 'string' == typeof dep ? dep : dep.name;
|
|
84
|
+
const importPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, DIST_DIR, depName);
|
|
85
|
+
const distPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, DIST_DIR, depName);
|
|
86
|
+
const depPath = findDepPath(depName);
|
|
87
|
+
if (!depPath) throw new Error(`Failed to resolve dependency: ${depName}`);
|
|
88
|
+
const depEntry = helper_require.resolve(depName, {
|
|
89
|
+
paths: [
|
|
90
|
+
cwd
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
const info = {
|
|
94
|
+
depName,
|
|
95
|
+
depPath,
|
|
96
|
+
depEntry,
|
|
97
|
+
distPath,
|
|
98
|
+
importPath
|
|
99
|
+
};
|
|
100
|
+
if ('string' == typeof dep) result.push({
|
|
101
|
+
minify: false,
|
|
102
|
+
target: 'es2019',
|
|
103
|
+
externals: {},
|
|
104
|
+
dtsExternals: [],
|
|
105
|
+
emitFiles: [],
|
|
106
|
+
packageJsonField: [],
|
|
107
|
+
prettier: globalPrettier,
|
|
108
|
+
...info
|
|
109
|
+
});
|
|
110
|
+
else result.push({
|
|
111
|
+
minify: dep.minify ?? false,
|
|
112
|
+
target: dep.target ?? 'es2019',
|
|
113
|
+
ignoreDts: dep.ignoreDts,
|
|
114
|
+
externals: dep.externals ?? {},
|
|
115
|
+
dtsExternals: dep.dtsExternals ?? [],
|
|
116
|
+
emitFiles: dep.emitFiles ?? [],
|
|
117
|
+
prettier: dep.prettier ?? globalPrettier,
|
|
118
|
+
afterBundle: dep.afterBundle,
|
|
119
|
+
beforeBundle: dep.beforeBundle,
|
|
120
|
+
packageJsonField: dep.packageJsonField ?? [],
|
|
121
|
+
...info
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function pick(obj, keys) {
|
|
127
|
+
return keys.reduce((ret, key)=>{
|
|
128
|
+
if (void 0 !== obj[key]) ret[key] = obj[key];
|
|
129
|
+
return ret;
|
|
130
|
+
}, {});
|
|
131
|
+
}
|
|
132
|
+
function pkgNameToAtTypes(name) {
|
|
133
|
+
const mangled = name.replace(/^@([^\/]+)\/([^\/]+)/, '$1__$2');
|
|
134
|
+
return `@types/${mangled}`;
|
|
135
|
+
}
|
|
136
|
+
function findDirectTypeFile(filepath) {
|
|
137
|
+
if (/\.d\.[cm]?ts/.test(filepath)) return filepath;
|
|
138
|
+
const ext = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(filepath);
|
|
139
|
+
const base = filepath.slice(0, -ext.length);
|
|
140
|
+
const _find = (list)=>{
|
|
141
|
+
for (const f of list)try {
|
|
142
|
+
return helper_require.resolve(f, {
|
|
143
|
+
paths: [
|
|
144
|
+
cwd
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
} catch {}
|
|
148
|
+
};
|
|
149
|
+
switch(ext){
|
|
150
|
+
case '.js':
|
|
151
|
+
case '.ts':
|
|
152
|
+
return _find([
|
|
153
|
+
base + '.d.ts'
|
|
154
|
+
]);
|
|
155
|
+
case '.mjs':
|
|
156
|
+
case '.mts':
|
|
157
|
+
return _find([
|
|
158
|
+
base + '.d.mts',
|
|
159
|
+
base + '.d.ts'
|
|
160
|
+
]);
|
|
161
|
+
case '.cjs':
|
|
162
|
+
case '.cts':
|
|
163
|
+
return _find([
|
|
164
|
+
base + '.d.cts',
|
|
165
|
+
base + '.d.ts'
|
|
166
|
+
]);
|
|
167
|
+
default:
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const { logger } = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__["default"];
|
|
171
|
+
function emitAssets(assets, distPath) {
|
|
172
|
+
for (const key of Object.keys(assets)){
|
|
173
|
+
const asset = assets[key];
|
|
174
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].outputFileSync((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, key), asset.source);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function emitIndex(code, distPath, prettier) {
|
|
178
|
+
const distIndex = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, 'index.js');
|
|
179
|
+
if (prettier) {
|
|
180
|
+
const minimized = await (0, __WEBPACK_EXTERNAL_MODULE_terser__.minify)(code, {
|
|
181
|
+
compress: false,
|
|
182
|
+
mangle: false,
|
|
183
|
+
ecma: 2019
|
|
184
|
+
});
|
|
185
|
+
if (!minimized.code) throw new Error('terser minify failed');
|
|
186
|
+
const formatted = await (0, __WEBPACK_EXTERNAL_MODULE_prettier__.format)(minimized.code, {
|
|
187
|
+
filepath: distIndex
|
|
188
|
+
});
|
|
189
|
+
await __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].outputFile(distIndex, formatted);
|
|
190
|
+
} else await __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].outputFile(distIndex, code);
|
|
191
|
+
}
|
|
192
|
+
async function emitDts(task, externals) {
|
|
193
|
+
const outputDefaultDts = ()=>{
|
|
194
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].outputFileSync((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'index.d.ts'), 'export = any;\n');
|
|
195
|
+
};
|
|
196
|
+
if (task.ignoreDts) {
|
|
197
|
+
outputDefaultDts();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const getTypes = (json)=>{
|
|
201
|
+
var _json_exports;
|
|
202
|
+
return json && (json.types || json.typing || json.typings || getTypes(null === (_json_exports = json.exports) || void 0 === _json_exports ? void 0 : _json_exports['.'])) || null;
|
|
203
|
+
};
|
|
204
|
+
const getInput = ()=>{
|
|
205
|
+
const pkgPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.depPath, 'package.json');
|
|
206
|
+
const pkgJson = __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].readJsonSync(pkgPath, 'utf-8');
|
|
207
|
+
const types = getTypes(pkgJson);
|
|
208
|
+
if (types) return (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.depPath, types);
|
|
209
|
+
const directTypeFile = findDirectTypeFile(task.depEntry);
|
|
210
|
+
if (directTypeFile) return directTypeFile;
|
|
211
|
+
const depTypesPath = findDepPath(`${pkgNameToAtTypes(task.depName)}/package.json`);
|
|
212
|
+
if (!depTypesPath) return null;
|
|
213
|
+
const depTypesPkg = __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].readJsonSync(depTypesPath, 'utf-8');
|
|
214
|
+
const depTypes = getTypes(depTypesPkg);
|
|
215
|
+
return depTypes ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(depTypesPath), depTypes) : null;
|
|
216
|
+
};
|
|
217
|
+
const input = getInput();
|
|
218
|
+
if (!input) {
|
|
219
|
+
outputDefaultDts();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const inputConfig = {
|
|
224
|
+
input,
|
|
225
|
+
external: [
|
|
226
|
+
...Object.keys(externals),
|
|
227
|
+
...task.dtsExternals,
|
|
228
|
+
...NODE_BUILTINS
|
|
229
|
+
],
|
|
230
|
+
plugins: [
|
|
231
|
+
(0, __WEBPACK_EXTERNAL_MODULE_rollup_plugin_dts_1c9650fc__.dts)({
|
|
232
|
+
respectExternal: true,
|
|
233
|
+
compilerOptions: {
|
|
234
|
+
skipLibCheck: true,
|
|
235
|
+
preserveSymlinks: false,
|
|
236
|
+
composite: false,
|
|
237
|
+
declarationMap: false,
|
|
238
|
+
declaration: true,
|
|
239
|
+
noEmit: false,
|
|
240
|
+
emitDeclarationOnly: true,
|
|
241
|
+
noEmitOnError: true,
|
|
242
|
+
checkJs: false,
|
|
243
|
+
target: task.target
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
};
|
|
248
|
+
const outputConfig = {
|
|
249
|
+
dir: task.distPath,
|
|
250
|
+
format: 'esm',
|
|
251
|
+
exports: 'named',
|
|
252
|
+
entryFileNames: 'index.d.ts'
|
|
253
|
+
};
|
|
254
|
+
const bundle = await (0, __WEBPACK_EXTERNAL_MODULE_rollup__.rollup)(inputConfig);
|
|
255
|
+
await bundle.write(outputConfig);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
logger.error(`rollup-plugin-dts failed: ${task.depName}`);
|
|
258
|
+
logger.error(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function emitPackageJson(task, assets) {
|
|
262
|
+
const packageJsonPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.depPath, 'package.json');
|
|
263
|
+
const packageJson = __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].readJsonSync(packageJsonPath, 'utf-8');
|
|
264
|
+
const outputPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'package.json');
|
|
265
|
+
const pickedPackageJson = pick(packageJson, [
|
|
266
|
+
'name',
|
|
267
|
+
'author',
|
|
268
|
+
'version',
|
|
269
|
+
'funding',
|
|
270
|
+
'license',
|
|
271
|
+
...task.packageJsonField
|
|
272
|
+
]);
|
|
273
|
+
if (task.depName !== pickedPackageJson.name) pickedPackageJson.name = task.depName;
|
|
274
|
+
pickedPackageJson.types = 'index.d.ts';
|
|
275
|
+
pickedPackageJson.type = 'commonjs';
|
|
276
|
+
if (assets['package.json']) try {
|
|
277
|
+
Object.assign(pickedPackageJson, pick(JSON.parse(assets['package.json'].source), [
|
|
278
|
+
'type'
|
|
279
|
+
]));
|
|
280
|
+
} catch {}
|
|
281
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].writeJSONSync(outputPath, pickedPackageJson);
|
|
282
|
+
}
|
|
283
|
+
function emitLicense(task) {
|
|
284
|
+
const licensePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.depPath, 'LICENSE');
|
|
285
|
+
if (__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].existsSync(licensePath)) __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].copySync(licensePath, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'license'));
|
|
286
|
+
}
|
|
287
|
+
function emitExtraFiles(task) {
|
|
288
|
+
const { emitFiles } = task;
|
|
289
|
+
for (const item of emitFiles){
|
|
290
|
+
const path = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, item.path);
|
|
291
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].outputFileSync(path, item.content);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function removeSourceMap(task) {
|
|
295
|
+
const maps = __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js_8d514d69__["default"].sync((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, '**/*.map'));
|
|
296
|
+
for (const mapPath of maps)__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].removeSync(mapPath);
|
|
297
|
+
}
|
|
298
|
+
function renameDistFolder(task) {
|
|
299
|
+
const pkgPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'package.json');
|
|
300
|
+
const pkgJson = __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].readJsonSync(pkgPath, 'utf-8');
|
|
301
|
+
for (const key of [
|
|
302
|
+
'types',
|
|
303
|
+
'typing',
|
|
304
|
+
'typings'
|
|
305
|
+
]){
|
|
306
|
+
var _pkgJson_key;
|
|
307
|
+
if (null === (_pkgJson_key = pkgJson[key]) || void 0 === _pkgJson_key ? void 0 : _pkgJson_key.startsWith('dist/')) {
|
|
308
|
+
pkgJson[key] = pkgJson[key].replace('dist/', 'types/');
|
|
309
|
+
const distFolder = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'dist');
|
|
310
|
+
const typesFolder = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(task.distPath, 'types');
|
|
311
|
+
if (__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].existsSync(distFolder)) __WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].renameSync(distFolder, typesFolder);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].writeJSONSync(pkgPath, pkgJson);
|
|
315
|
+
}
|
|
316
|
+
const pkgName = process.argv[2];
|
|
317
|
+
async function prebundle(task, commonExternals = {}) {
|
|
318
|
+
if (pkgName && task.depName !== pkgName) return;
|
|
319
|
+
logger.start(`prebundle: ${task.depName}`);
|
|
320
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_fs_extra_index_js_a27e5f9c__["default"].removeSync(task.distPath);
|
|
321
|
+
if (task.beforeBundle) await task.beforeBundle(task);
|
|
322
|
+
const mergedExternals = {
|
|
323
|
+
...DEFAULT_EXTERNALS,
|
|
324
|
+
...commonExternals,
|
|
325
|
+
...task.externals
|
|
326
|
+
};
|
|
327
|
+
const nodeModulesPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'node_modules');
|
|
328
|
+
const hasNodeModules = (0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.existsSync)(nodeModulesPath);
|
|
329
|
+
const enableCache = !process.env.CI && hasNodeModules;
|
|
330
|
+
const { code, assets } = await (0, __WEBPACK_EXTERNAL_MODULE__vercel_ncc_57e68fb3__["default"])(task.depEntry, {
|
|
331
|
+
minify: task.minify,
|
|
332
|
+
target: task.target,
|
|
333
|
+
externals: mergedExternals,
|
|
334
|
+
assetBuilds: false,
|
|
335
|
+
cache: !!enableCache && (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(nodeModulesPath, '.cache', 'ncc-cache')
|
|
336
|
+
});
|
|
337
|
+
await emitIndex(code, task.distPath, task.prettier);
|
|
338
|
+
emitAssets(assets, task.distPath);
|
|
339
|
+
await emitDts(task, mergedExternals);
|
|
340
|
+
emitLicense(task);
|
|
341
|
+
emitPackageJson(task, assets);
|
|
342
|
+
removeSourceMap(task);
|
|
343
|
+
renameDistFolder(task);
|
|
344
|
+
emitExtraFiles(task);
|
|
345
|
+
if (task.afterBundle) await task.afterBundle(task);
|
|
346
|
+
logger.success(`prebundle: ${task.depName}\n\n`);
|
|
347
|
+
}
|
|
348
|
+
async function run() {
|
|
349
|
+
const config = await resolveConfig();
|
|
350
|
+
const parsedTasks = parseTasks(config.dependencies, config.prettier);
|
|
351
|
+
for (const task of parsedTasks)await prebundle(task, config.externals);
|
|
352
|
+
}
|
|
353
|
+
export { run };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type ImportMap = {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string;
|
|
4
|
+
};
|
|
5
|
+
export type DependencyConfig = {
|
|
6
|
+
/** Name of dependency */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Whether to minify the code. */
|
|
9
|
+
minify?: boolean;
|
|
10
|
+
/** Externals to leave as requires of the build. */
|
|
11
|
+
externals?: Record<string, string>;
|
|
12
|
+
/** Externals types */
|
|
13
|
+
dtsExternals?: Array<string | RegExp>;
|
|
14
|
+
/** Whether to prettier the code and strip comments */
|
|
15
|
+
prettier?: boolean;
|
|
16
|
+
/** Emit extra entry files to map imports. */
|
|
17
|
+
emitFiles?: ImportMap[];
|
|
18
|
+
/** Copy extra fields from original package.json to target package.json. */
|
|
19
|
+
packageJsonField?: string[];
|
|
20
|
+
/** Whether to ignore type definitions */
|
|
21
|
+
ignoreDts?: boolean;
|
|
22
|
+
/** Target ECMA version */
|
|
23
|
+
target?: string;
|
|
24
|
+
beforeBundle?: (task: ParsedTask) => void | Promise<void>;
|
|
25
|
+
afterBundle?: (task: ParsedTask) => void | Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
export type Config = {
|
|
28
|
+
/**
|
|
29
|
+
* Configure externals for all packages,
|
|
30
|
+
* will be merged with dependencies[i].externals.
|
|
31
|
+
*/
|
|
32
|
+
externals?: Record<string, string>;
|
|
33
|
+
dependencies: Array<string | DependencyConfig>;
|
|
34
|
+
/** Whether to prettier the code and strip comments */
|
|
35
|
+
prettier?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type ParsedTask = {
|
|
38
|
+
depPath: string;
|
|
39
|
+
depEntry: string;
|
|
40
|
+
distPath: string;
|
|
41
|
+
importPath: string;
|
|
42
|
+
ignoreDts?: boolean;
|
|
43
|
+
prettier?: boolean;
|
|
44
|
+
target: NonNullable<DependencyConfig['target']>;
|
|
45
|
+
minify: NonNullable<DependencyConfig['minify']>;
|
|
46
|
+
depName: NonNullable<DependencyConfig['name']>;
|
|
47
|
+
externals: NonNullable<DependencyConfig['externals']>;
|
|
48
|
+
dtsExternals: NonNullable<DependencyConfig['dtsExternals']>;
|
|
49
|
+
emitFiles: NonNullable<DependencyConfig['emitFiles']>;
|
|
50
|
+
afterBundle?: NonNullable<DependencyConfig['afterBundle']>;
|
|
51
|
+
beforeBundle?: NonNullable<DependencyConfig['beforeBundle']>;
|
|
52
|
+
packageJsonField: NonNullable<DependencyConfig['packageJsonField']>;
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prebundle",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rspack-contrib/prebundle"
|
|
@@ -19,26 +19,26 @@
|
|
|
19
19
|
"build": "rslib build",
|
|
20
20
|
"dev": "rslib build --watch",
|
|
21
21
|
"prebundle": "node ./bin.js",
|
|
22
|
-
"
|
|
22
|
+
"prepare": "npm run build",
|
|
23
23
|
"bump": "npx bumpp"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@vercel/ncc": "0.38.
|
|
27
|
-
"prettier": "^3.2
|
|
28
|
-
"rollup": "^4.
|
|
29
|
-
"rollup-plugin-dts": "^6.1.
|
|
30
|
-
"terser": "^5.
|
|
26
|
+
"@vercel/ncc": "0.38.3",
|
|
27
|
+
"prettier": "^3.4.2",
|
|
28
|
+
"rollup": "^4.30.1",
|
|
29
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
30
|
+
"terser": "^5.37.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@rslib/core": "0.
|
|
33
|
+
"@rslib/core": "0.3.1",
|
|
34
34
|
"@types/fs-extra": "^11.0.4",
|
|
35
|
-
"@types/node": "
|
|
36
|
-
"fast-glob": "^3.3.
|
|
37
|
-
"fs-extra": "^11.
|
|
38
|
-
"rslog": "^1.2.
|
|
39
|
-
"typescript": "^5.
|
|
35
|
+
"@types/node": "22.10.7",
|
|
36
|
+
"fast-glob": "^3.3.3",
|
|
37
|
+
"fs-extra": "^11.3.0",
|
|
38
|
+
"rslog": "^1.2.3",
|
|
39
|
+
"typescript": "^5.7.3"
|
|
40
40
|
},
|
|
41
|
-
"packageManager": "pnpm@9.
|
|
41
|
+
"packageManager": "pnpm@9.15.4",
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public",
|
|
44
44
|
"registry": "https://registry.npmjs.org/",
|