packitup 0.2.0 → 0.2.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/README.md +3 -0
- package/dist/packitup.js +1 -763
- package/dist/packitup.mjs +1 -767
- package/package.json +2 -2
package/dist/packitup.js
CHANGED
|
@@ -1,763 +1 @@
|
|
|
1
|
-
((moduleDict, mainfile, projectName, globalExport, isesm) => {
|
|
2
|
-
const caches = { __proto__: null };
|
|
3
|
-
const proc = {
|
|
4
|
-
moduleDict,
|
|
5
|
-
workdir: '/' + projectName
|
|
6
|
-
};
|
|
7
|
-
const simpRequire = moduleId => {
|
|
8
|
-
if (moduleId in caches) return caches[moduleId];
|
|
9
|
-
const factory = moduleDict['/modules/' + moduleId + '.js'];
|
|
10
|
-
const module = {
|
|
11
|
-
exports: {}
|
|
12
|
-
};
|
|
13
|
-
factory(simpRequire, module.exports, module, proc);
|
|
14
|
-
caches[moduleId] = module.exports;
|
|
15
|
-
return module.exports;
|
|
16
|
-
};
|
|
17
|
-
simpRequire.original = typeof require === 'function'? require : simpRequire;
|
|
18
|
-
proc.isMain = typeof module === 'object'? simpRequire.original.main === module : false;
|
|
19
|
-
const Module = simpRequire('module');
|
|
20
|
-
const factory = () => {
|
|
21
|
-
const main = new Module(mainfile);
|
|
22
|
-
return Module._load(mainfile, void 0, true);
|
|
23
|
-
};
|
|
24
|
-
if (isesm) {
|
|
25
|
-
return factory();
|
|
26
|
-
}
|
|
27
|
-
else if (typeof exports === 'object') {
|
|
28
|
-
module.exports = factory();
|
|
29
|
-
}
|
|
30
|
-
else if (typeof define === 'function') {
|
|
31
|
-
define(projectName, [], factory);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
globalThis[globalExport] = factory();
|
|
35
|
-
}
|
|
36
|
-
})({"/packitup/src/index.js"(require,exports,module){
|
|
37
|
-
const build = require('./lib/build.js');
|
|
38
|
-
const builder = require('./lib/builder.js');
|
|
39
|
-
const cli = require('./lib/cli.js');
|
|
40
|
-
|
|
41
|
-
module.exports = {
|
|
42
|
-
...build,
|
|
43
|
-
...builder
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// 运行主函数
|
|
47
|
-
if (require.main === module) {
|
|
48
|
-
cli.main();
|
|
49
|
-
}
|
|
50
|
-
},"/packitup/src/lib/build-template.js"(require,exports,module){
|
|
51
|
-
module.exports = (moduleDict, mainfile, projectName, globalExport, isesm) => {
|
|
52
|
-
const caches = { __proto__: null };
|
|
53
|
-
const proc = {
|
|
54
|
-
moduleDict,
|
|
55
|
-
workdir: '/' + projectName
|
|
56
|
-
};
|
|
57
|
-
const simpRequire = moduleId => {
|
|
58
|
-
if (moduleId in caches) return caches[moduleId];
|
|
59
|
-
const factory = moduleDict['/modules/' + moduleId + '.js'];
|
|
60
|
-
const module = {
|
|
61
|
-
exports: {}
|
|
62
|
-
};
|
|
63
|
-
factory(simpRequire, module.exports, module, proc);
|
|
64
|
-
caches[moduleId] = module.exports;
|
|
65
|
-
return module.exports;
|
|
66
|
-
};
|
|
67
|
-
simpRequire.original = typeof require === 'function'? require : simpRequire;
|
|
68
|
-
proc.isMain = typeof module === 'object'? simpRequire.original.main === module : false;
|
|
69
|
-
const Module = simpRequire('module');
|
|
70
|
-
const factory = () => {
|
|
71
|
-
const main = new Module(mainfile);
|
|
72
|
-
return Module._load(mainfile, void 0, true);
|
|
73
|
-
};
|
|
74
|
-
if (isesm) {
|
|
75
|
-
return factory();
|
|
76
|
-
}
|
|
77
|
-
else if (typeof exports === 'object') {
|
|
78
|
-
module.exports = factory();
|
|
79
|
-
}
|
|
80
|
-
else if (typeof define === 'function') {
|
|
81
|
-
define(projectName, [], factory);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
globalThis[globalExport] = factory();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
},"/packitup/src/lib/build.js"(require,exports,module){
|
|
88
|
-
const fs = require('fs');
|
|
89
|
-
const { sep: pathSep, join: pathJoin, resolve } = require('path');
|
|
90
|
-
const templateFunction = require('./build-template.js');
|
|
91
|
-
const { moduleDict: mdict } = module.$build$? require('[build]') : {};
|
|
92
|
-
|
|
93
|
-
const search = (path, rule) => {
|
|
94
|
-
const listdir = fs.readdirSync(path);
|
|
95
|
-
const result = [];
|
|
96
|
-
for (const filename of listdir) {
|
|
97
|
-
const file = path + pathSep + filename;
|
|
98
|
-
if (fs.statSync(file).isDirectory()) {
|
|
99
|
-
let subfiles = search(file, rule);
|
|
100
|
-
subfiles = subfiles.filter(filePath => rule.test(filePath));
|
|
101
|
-
result.push(...subfiles)
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (rule.test(file)) result.push(file);
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const build = (allJS, main, options = {}) => {
|
|
110
|
-
const {
|
|
111
|
-
projectName = 'project',
|
|
112
|
-
globalExportName = projectName,
|
|
113
|
-
esmExport = 'export default module;',
|
|
114
|
-
dontPack = [],
|
|
115
|
-
move = path => path
|
|
116
|
-
} = options;
|
|
117
|
-
const moduleMap = {};
|
|
118
|
-
for (let filePath of allJS) {
|
|
119
|
-
if (filePath.startsWith('./')) filePath = filePath.slice(2);
|
|
120
|
-
if (dontPack.some(dont => dont.test(filePath))) continue;
|
|
121
|
-
const saveFilePath = move(pathSep + projectName + pathSep + filePath);
|
|
122
|
-
if (!filePath) continue;
|
|
123
|
-
moduleMap[saveFilePath] = fs.readFileSync(filePath);
|
|
124
|
-
}
|
|
125
|
-
mdict && Object.entries(mdict).forEach(([key, value]) => {
|
|
126
|
-
if (key.startsWith('/modules/')) {
|
|
127
|
-
value = String(value).match(/\{([\S\s]*)\}/)[1];
|
|
128
|
-
moduleMap[key] = value;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const moduleDict = (() => {
|
|
132
|
-
const mapping = [];
|
|
133
|
-
for (const [key, value] of Object.entries(moduleMap)) {
|
|
134
|
-
const pathKey = JSON.stringify(key);
|
|
135
|
-
if (key.endsWith(".js")) {
|
|
136
|
-
mapping.push(`${pathKey}(require,exports,module){${value}}`);
|
|
137
|
-
}
|
|
138
|
-
else if (key.endsWith(".json")) {
|
|
139
|
-
mapping.push(`${pathKey}:${value}`);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
mapping.push(`${pathKey}:${JSON.stringify(value)}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return `{${mapping}}`;
|
|
146
|
-
})();
|
|
147
|
-
const template = `(${templateFunction})`;
|
|
148
|
-
const esmTemplate = esmExport;
|
|
149
|
-
const projectNameStr = JSON.stringify(projectName);
|
|
150
|
-
const globalExportNameStr = JSON.stringify(globalExportName);
|
|
151
|
-
let dist = `${template}(${moduleDict},${JSON.stringify(main)},${projectNameStr},${globalExportNameStr});`;
|
|
152
|
-
const esmValue = `${template}(${moduleDict},${JSON.stringify(main)},${projectNameStr},${globalExportNameStr},1)`;
|
|
153
|
-
let distESM = `const module=${esmValue};${esmTemplate}`;
|
|
154
|
-
return {
|
|
155
|
-
umd: dist,
|
|
156
|
-
esm: distESM,
|
|
157
|
-
options
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const buildDirectory = (directory, options = {}) => {
|
|
162
|
-
if (!options.projectName) {
|
|
163
|
-
let projectName = resolve(directory);
|
|
164
|
-
const paths = projectName.split(pathSep);
|
|
165
|
-
let index = 1;
|
|
166
|
-
do {
|
|
167
|
-
projectName = paths[paths.length - index];
|
|
168
|
-
index++;
|
|
169
|
-
} while (
|
|
170
|
-
[ 'src', 'lib' ].includes(projectName) && index < paths.length
|
|
171
|
-
)
|
|
172
|
-
options.projectName = projectName;
|
|
173
|
-
}
|
|
174
|
-
if (!options.extensions) options.extensions = [
|
|
175
|
-
".js",
|
|
176
|
-
".json",
|
|
177
|
-
".txt",
|
|
178
|
-
".svg",
|
|
179
|
-
".xml",
|
|
180
|
-
".html"
|
|
181
|
-
];
|
|
182
|
-
// 我又没说必须是正则对象[doge]
|
|
183
|
-
const test = (path) => options.extensions.some(ext => path.endsWith(ext));
|
|
184
|
-
const allJS = search(directory, { test });
|
|
185
|
-
const parent = fs.readdirSync(resolve(directory).split(pathSep).slice(0, -1).join(pathSep));
|
|
186
|
-
if (parent.includes('node_modules')) {
|
|
187
|
-
const node_modules = search(parent, { test });
|
|
188
|
-
allJS.push(...node_modules);
|
|
189
|
-
}
|
|
190
|
-
return build(allJS,pathSep + pathJoin(options.projectName, directory, 'index.js'), options);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
module.exports = {
|
|
194
|
-
build,
|
|
195
|
-
buildDirectory
|
|
196
|
-
};
|
|
197
|
-
},"/packitup/src/lib/builder.js"(require,exports,module){
|
|
198
|
-
const fs = require('fs');
|
|
199
|
-
const path = require('path');
|
|
200
|
-
const { buildDirectory } = require('./build.js');
|
|
201
|
-
|
|
202
|
-
exports.outputBundle = options => {
|
|
203
|
-
let {
|
|
204
|
-
sourcePath,
|
|
205
|
-
umdFile,
|
|
206
|
-
esmFile,
|
|
207
|
-
distPath,
|
|
208
|
-
esmTemplate
|
|
209
|
-
} = options;
|
|
210
|
-
if (esmTemplate) options.esmExport = fs.readFileSync(esmTemplate);
|
|
211
|
-
const dist = buildDirectory(sourcePath, options);
|
|
212
|
-
const projectName = dist.options.projectName;
|
|
213
|
-
if (!distPath.endsWith(path.sep)) distPath += path.sep;
|
|
214
|
-
umdFile ??= distPath + projectName + '.js';
|
|
215
|
-
esmFile ??= distPath + projectName + '.mjs';
|
|
216
|
-
fs.writeFileSync(umdFile, dist.umd);
|
|
217
|
-
fs.writeFileSync(esmFile, dist.esm);
|
|
218
|
-
};
|
|
219
|
-
},"/packitup/src/lib/cli.js"(require,exports,module){const path = require('path');
|
|
220
|
-
const fs = require('fs');
|
|
221
|
-
const { outputBundle } = require('./builder.js');
|
|
222
|
-
|
|
223
|
-
// 解析简单参数
|
|
224
|
-
function parseArgs() {
|
|
225
|
-
const args = process.argv.slice(2);
|
|
226
|
-
const options = {};
|
|
227
|
-
const positional = [];
|
|
228
|
-
const parser = {
|
|
229
|
-
index: 0,
|
|
230
|
-
curr: args[0],
|
|
231
|
-
next() {
|
|
232
|
-
this.index++;
|
|
233
|
-
this.curr = args[this.index];
|
|
234
|
-
},
|
|
235
|
-
peek(n = 1) {
|
|
236
|
-
return args[this.index + n];
|
|
237
|
-
},
|
|
238
|
-
parse() {
|
|
239
|
-
while (this.curr) {
|
|
240
|
-
this.parseArgument();
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
parseArgument() {
|
|
244
|
-
if (this.curr.startsWith('--')) {
|
|
245
|
-
const key = this.curr.slice(2);
|
|
246
|
-
const nextArg = this.peek();
|
|
247
|
-
if (nextArg && !nextArg.startsWith('--')) {
|
|
248
|
-
this.next();
|
|
249
|
-
options[key] = nextArg;
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
options[key] = true;
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (this.curr.startsWith('-')) {
|
|
256
|
-
options[this.curr.slice(1)] = true;
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
positional.push(this.curr);
|
|
260
|
-
this.next();
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
parser.parse();
|
|
264
|
-
return {
|
|
265
|
-
options,
|
|
266
|
-
positional
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 显示帮助信息
|
|
271
|
-
function showHelp() {
|
|
272
|
-
console.log(`
|
|
273
|
-
📦 PackItUp - JavaScript Packager
|
|
274
|
-
|
|
275
|
-
ATTENTION: If you're running for the first time, please cd to module path and run "npm run install".
|
|
276
|
-
|
|
277
|
-
Usage: packitup [command] [options]
|
|
278
|
-
|
|
279
|
-
Commands:
|
|
280
|
-
build <input-directory> [output-directory] Pack a directory
|
|
281
|
-
|
|
282
|
-
Options:
|
|
283
|
-
--name <projectName> Specify project name
|
|
284
|
-
--umd <fileName> Specify UMD output file name
|
|
285
|
-
--esm <fileName> Specify ESM output file name
|
|
286
|
-
--esm-template <template> Specify ESM output template
|
|
287
|
-
--help Show this help message
|
|
288
|
-
|
|
289
|
-
`);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// 主函数
|
|
293
|
-
async function main() {
|
|
294
|
-
const { options, positional } = parseArgs();
|
|
295
|
-
|
|
296
|
-
// 显示帮助
|
|
297
|
-
if (options.help || positional.length === 0) {
|
|
298
|
-
showHelp();
|
|
299
|
-
process.exit(0);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const command = positional[0];
|
|
303
|
-
|
|
304
|
-
switch (command) {
|
|
305
|
-
case 'build': {
|
|
306
|
-
const input = positional[1];
|
|
307
|
-
const output = positional[2] || '.';
|
|
308
|
-
|
|
309
|
-
if (!input) {
|
|
310
|
-
console.error('❌ Error: Please specify input directory');
|
|
311
|
-
showHelp();
|
|
312
|
-
process.exit(1);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
console.log(`🚀 Starting pack: ${input} → ${output}`);
|
|
316
|
-
outputBundle({
|
|
317
|
-
sourcePath: input,
|
|
318
|
-
projectName: options.name,
|
|
319
|
-
distPath: output,
|
|
320
|
-
umdFile: options.umd,
|
|
321
|
-
esmFile: options.esm,
|
|
322
|
-
move: options.move? pth => {
|
|
323
|
-
if (options['move-from'] && pth.startsWith(options['move-from'])) {
|
|
324
|
-
return pth.replace(options['move-from'], options['move-to'] || options['move-from']);
|
|
325
|
-
}
|
|
326
|
-
return pth;
|
|
327
|
-
} : void 0,
|
|
328
|
-
dontExport: (options['dont-export'] ?? '').split(' '),
|
|
329
|
-
esmTemplate: options['esm-template']
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
console.log('✅ Pack complete!');
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
default:
|
|
336
|
-
console.error(`❌ Unknown command: ${command}`);
|
|
337
|
-
showHelp();
|
|
338
|
-
process.exit(1);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// 导出
|
|
343
|
-
module.exports = {
|
|
344
|
-
parseArgs,
|
|
345
|
-
main
|
|
346
|
-
};},"/modules/[build].js"(require,exports,module){
|
|
347
|
-
module.exports = arguments[3];
|
|
348
|
-
},"/modules/module.js"(require,exports,module){
|
|
349
|
-
const proc = require('[build]');
|
|
350
|
-
const { moduleDict } = proc;
|
|
351
|
-
const path = require('path');
|
|
352
|
-
|
|
353
|
-
let mainModule;
|
|
354
|
-
|
|
355
|
-
function updateChildren(parent, child, scan) {
|
|
356
|
-
const children = parent?.children;
|
|
357
|
-
if (children && !(scan && children.includes(child))) {
|
|
358
|
-
children.push(child);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function wrapModuleLoad(request, parent, isMain) {
|
|
362
|
-
return Module._load.call({
|
|
363
|
-
__proto__: null,
|
|
364
|
-
parentFilename: parent?.filename,
|
|
365
|
-
id: request,
|
|
366
|
-
}, request, parent, isMain);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function raiseModuleNotFound(request) {
|
|
370
|
-
const modname = request.replaceAll('\'', '\\\'');
|
|
371
|
-
throw new Error('Cannot find module \'' + modname + '\'');
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function findModule(request, parent) {
|
|
375
|
-
if (['.', '..', ''].some(start => request.startsWith(start + path.sep))) {
|
|
376
|
-
const requestPath = request.startsWith(path.sep)? request : path.resolve(request);
|
|
377
|
-
if (requestPath in moduleDict) {
|
|
378
|
-
return requestPath;
|
|
379
|
-
}
|
|
380
|
-
const extensions = Object.keys(Module._extensions);
|
|
381
|
-
for (const extension of extensions) {
|
|
382
|
-
const withext = requestPath + extension;
|
|
383
|
-
if (withext in moduleDict) {
|
|
384
|
-
return withext;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const indexPath = path.join(requestPath, 'index');
|
|
388
|
-
for (const extension of extensions) {
|
|
389
|
-
const withext = indexPath + extension;
|
|
390
|
-
if (withext in moduleDict) {
|
|
391
|
-
return withext;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
raiseModuleNotFound(request);
|
|
395
|
-
}
|
|
396
|
-
if (parent)
|
|
397
|
-
for (const maybeNm of parent.paths) {
|
|
398
|
-
const [ moduleName, ...subdirs ] = request.split(path.sep);
|
|
399
|
-
const subdir = subdirs.length? path.join(...subdirs) : '.';
|
|
400
|
-
const maybe = path.join(maybeNm, moduleName);
|
|
401
|
-
const packageJSON = moduleDict[path.join(maybe, 'package.json')];
|
|
402
|
-
if (packageJSON) {
|
|
403
|
-
if (packageJSON.exports) {
|
|
404
|
-
const { exports } = packageJSON;
|
|
405
|
-
if (typeof exports === 'string') {
|
|
406
|
-
return path.join(maybe, exports);
|
|
407
|
-
}
|
|
408
|
-
// 上面已经确保了packageJSON.exports是真值 所以这里一定不是null
|
|
409
|
-
if (typeof exports === 'object' && exports[subdir]) {
|
|
410
|
-
const entry = exports[subdir];
|
|
411
|
-
if (typeof entry === 'string') return path.join(maybe, entry);
|
|
412
|
-
// 同理 这里entry肯定不是null
|
|
413
|
-
if (typeof entry === 'object') {
|
|
414
|
-
if (entry.require) return path.join(maybe, entry.require);
|
|
415
|
-
if (entry.default) return path.join(maybe, entry.default);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (packageJSON.main) return path.join(maybe, packageJSON.main);
|
|
420
|
-
}
|
|
421
|
-
const indexPath = path.join(maybe, request, 'index.js');
|
|
422
|
-
if (indexPath in moduleDict) return indexPath;
|
|
423
|
-
}
|
|
424
|
-
raiseModuleNotFound(request);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function Module(id = '', parent) {
|
|
428
|
-
this.id = id;
|
|
429
|
-
this.path = path.dirname(id);
|
|
430
|
-
this.exports = {};
|
|
431
|
-
updateChildren(parent, this, false);
|
|
432
|
-
this.filename = null;
|
|
433
|
-
this.loaded = false;
|
|
434
|
-
this.children = [];
|
|
435
|
-
}
|
|
436
|
-
Module.Module = Module;
|
|
437
|
-
Module._nodeModulePaths = function(from) {
|
|
438
|
-
from = path.resolve(from);
|
|
439
|
-
const paths = [];
|
|
440
|
-
for (let current = from; current !== path.dirname(current); current = path.dirname(current)) {
|
|
441
|
-
paths.push(path.join(current, 'node_modules'));
|
|
442
|
-
}
|
|
443
|
-
paths.push('/node_modules');
|
|
444
|
-
return paths;
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
Module._cache = Object.create(null);
|
|
448
|
-
Module._extensions = Object.create(null);
|
|
449
|
-
|
|
450
|
-
Module.builtinModules = [
|
|
451
|
-
'_http_agent', '_http_client', '_http_common',
|
|
452
|
-
'_http_incoming', '_http_outgoing', '_http_server',
|
|
453
|
-
'_stream_duplex', '_stream_passthrough', '_stream_readable',
|
|
454
|
-
'_stream_transform', '_stream_wrap', '_stream_writable',
|
|
455
|
-
'_tls_common', '_tls_wrap', 'assert',
|
|
456
|
-
'assert/strict', 'async_hooks', 'buffer',
|
|
457
|
-
'child_process', 'cluster', 'console',
|
|
458
|
-
'constants', 'crypto', 'dgram',
|
|
459
|
-
'diagnostics_channel', 'dns', 'dns/promises',
|
|
460
|
-
'domain', 'events', 'fs',
|
|
461
|
-
'fs/promises', 'http', 'http2',
|
|
462
|
-
'https', 'inspector', 'inspector/promises',
|
|
463
|
-
'module', 'net', 'os',
|
|
464
|
-
'path', 'path/posix', 'path/win32',
|
|
465
|
-
'perf_hooks', 'process', 'punycode',
|
|
466
|
-
'querystring', 'readline', 'readline/promises',
|
|
467
|
-
'repl', 'stream', 'stream/consumers',
|
|
468
|
-
'stream/promises', 'stream/web', 'string_decoder',
|
|
469
|
-
'sys', 'timers', 'timers/promises',
|
|
470
|
-
'tls', 'trace_events', 'tty',
|
|
471
|
-
'url', 'util', 'util/types',
|
|
472
|
-
'v8', 'vm', 'wasi',
|
|
473
|
-
'worker_threads', 'zlib', 'node:sea',
|
|
474
|
-
'node:sqlite', 'node:test', 'node:test/reporters'
|
|
475
|
-
];
|
|
476
|
-
|
|
477
|
-
const SpecialModules = [ 'module', '[build]' ];
|
|
478
|
-
|
|
479
|
-
Module._load = function(request, parent, isMain) {
|
|
480
|
-
if (Module.builtinModules.includes(request)) return require.original(request);
|
|
481
|
-
if (SpecialModules.includes(request)) return require(request);
|
|
482
|
-
const filename = findModule(request, parent);
|
|
483
|
-
const cachedModule = Module._cache[filename];
|
|
484
|
-
if (cachedModule !== undefined) {
|
|
485
|
-
updateChildren(parent, cachedModule, true);
|
|
486
|
-
if (cachedModule.loaded) {
|
|
487
|
-
return cachedModule.exports;
|
|
488
|
-
}
|
|
489
|
-
if (!cachedModule[kIsCachedByESMLoader]) {
|
|
490
|
-
return getExportsForCircularRequire(cachedModule);
|
|
491
|
-
}
|
|
492
|
-
if (cachedModule[kModuleCircularVisited]) {
|
|
493
|
-
return getExportsForCircularRequire(cachedModule);
|
|
494
|
-
}
|
|
495
|
-
cachedModule[kModuleCircularVisited] = true;
|
|
496
|
-
}
|
|
497
|
-
const module = cachedModule || new Module(filename, parent);
|
|
498
|
-
if (!cachedModule) {
|
|
499
|
-
if (isMain) {
|
|
500
|
-
if (proc.isMain) {
|
|
501
|
-
mainModule = module;
|
|
502
|
-
Module.prototype.require.main = null;
|
|
503
|
-
}
|
|
504
|
-
module.id = '.';
|
|
505
|
-
}
|
|
506
|
-
Module._cache[filename] = module;
|
|
507
|
-
module.load(filename);
|
|
508
|
-
}
|
|
509
|
-
return module.exports;
|
|
510
|
-
};
|
|
511
|
-
Module.prototype.load = function(filename) {
|
|
512
|
-
this.filename ??= filename;
|
|
513
|
-
this.paths ??= Module._nodeModulePaths(path.dirname(filename));
|
|
514
|
-
const extension = filename.includes('.') ? '.' + filename.split('.').slice(-1)[0] : '';
|
|
515
|
-
Module._extensions[extension](this, filename);
|
|
516
|
-
this.loaded = true;
|
|
517
|
-
};
|
|
518
|
-
Module.prototype.require = function(id) {
|
|
519
|
-
return wrapModuleLoad(id, this, false);
|
|
520
|
-
};
|
|
521
|
-
Module.prototype.require.main = null;
|
|
522
|
-
Object.assign(Module._extensions, {
|
|
523
|
-
".js": function(module, filename) {
|
|
524
|
-
function require(path) {
|
|
525
|
-
return module.require(path);
|
|
526
|
-
}
|
|
527
|
-
require.main = mainModule;
|
|
528
|
-
require.extensions = Module._extensions;
|
|
529
|
-
require.cache = Module._cache;
|
|
530
|
-
const factory = moduleDict[filename];
|
|
531
|
-
const oldworkdir = proc.workdir;
|
|
532
|
-
proc.workdir = path.dirname(filename);
|
|
533
|
-
factory(require, module.exports, module);
|
|
534
|
-
proc.workdir = oldworkdir;
|
|
535
|
-
},
|
|
536
|
-
".json": function(module, filename) {
|
|
537
|
-
module.exports = moduleDict[filename];
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
Module.prototype.$build$ = true;
|
|
542
|
-
|
|
543
|
-
module.exports = Module;
|
|
544
|
-
},"/modules/path.js"(require,exports,module){const proc = require('[build]');
|
|
545
|
-
|
|
546
|
-
module.exports = {
|
|
547
|
-
// 常量
|
|
548
|
-
sep: '/',
|
|
549
|
-
delimiter: ':',
|
|
550
|
-
// 路径规范化
|
|
551
|
-
normalize(path) {
|
|
552
|
-
if (!path) return '.';
|
|
553
|
-
// 替换多个斜杠为单个斜杠
|
|
554
|
-
let result = path.replace(/\/+/g, '/');
|
|
555
|
-
// 移除开头的 ./
|
|
556
|
-
if (result.startsWith('./')) {
|
|
557
|
-
result = result.slice(2);
|
|
558
|
-
}
|
|
559
|
-
// 移除中间的 ./
|
|
560
|
-
result = result.replace(/\/\.\//g, '/');
|
|
561
|
-
// 移除末尾的 .
|
|
562
|
-
if (result.endsWith('/.')) {
|
|
563
|
-
result = result.slice(0, -2);
|
|
564
|
-
}
|
|
565
|
-
// 处理 .. 向上目录
|
|
566
|
-
const parts = result.split('/');
|
|
567
|
-
const newParts = [];
|
|
568
|
-
for (const part of parts) {
|
|
569
|
-
if (part === '..') {
|
|
570
|
-
if (newParts.length > 0) {
|
|
571
|
-
newParts.pop();
|
|
572
|
-
}
|
|
573
|
-
} else if (part !== '' && part !== '.') {
|
|
574
|
-
newParts.push(part);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
result = newParts.join('/');
|
|
578
|
-
// 处理绝对路径
|
|
579
|
-
if (path.startsWith('/')) {
|
|
580
|
-
result = '/' + result;
|
|
581
|
-
} else if (path.startsWith('./')) {
|
|
582
|
-
result = './' + result;
|
|
583
|
-
}
|
|
584
|
-
// 处理空结果
|
|
585
|
-
if (result === '') return '.';
|
|
586
|
-
// 保留原始路径的末尾斜杠(如果是目录)
|
|
587
|
-
if (path.endsWith('/') && !result.endsWith('/') && result !== '.') {
|
|
588
|
-
result += '/';
|
|
589
|
-
}
|
|
590
|
-
return result;
|
|
591
|
-
},
|
|
592
|
-
// 连接路径
|
|
593
|
-
join(...paths) {
|
|
594
|
-
if (paths.length === 0) return '.';
|
|
595
|
-
let result = '';
|
|
596
|
-
for (const segment of paths) {
|
|
597
|
-
if (segment) {
|
|
598
|
-
if (result === '') {
|
|
599
|
-
result = segment;
|
|
600
|
-
} else {
|
|
601
|
-
result += '/' + segment;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return this.normalize(result);
|
|
606
|
-
},
|
|
607
|
-
// 解析为绝对路径
|
|
608
|
-
resolve(...paths) {
|
|
609
|
-
// 如果没有参数,使用工作目录
|
|
610
|
-
if (paths.length === 0) {
|
|
611
|
-
return proc.workdir || '/';
|
|
612
|
-
}
|
|
613
|
-
let result = '';
|
|
614
|
-
let isAbsolute = false;
|
|
615
|
-
// 从最后一个参数开始处理
|
|
616
|
-
for (let i = paths.length - 1; i >= 0; i--) {
|
|
617
|
-
const path = paths[i];
|
|
618
|
-
if (!path) continue;
|
|
619
|
-
// 如果是绝对路径,重置结果
|
|
620
|
-
if (path.startsWith('/')) {
|
|
621
|
-
result = path;
|
|
622
|
-
isAbsolute = true;
|
|
623
|
-
} else {
|
|
624
|
-
if (result === '') {
|
|
625
|
-
result = path;
|
|
626
|
-
} else {
|
|
627
|
-
result = path + '/' + result;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
// 如果没有绝对路径,添加工作目录
|
|
632
|
-
if (!isAbsolute) {
|
|
633
|
-
result = (proc.workdir || '/') + '/' + result;
|
|
634
|
-
}
|
|
635
|
-
// 规范化路径
|
|
636
|
-
return this.normalize(result);
|
|
637
|
-
},
|
|
638
|
-
// 获取目录名
|
|
639
|
-
dirname(path) {
|
|
640
|
-
if (!path || path === '.' || path === '..') return '.';
|
|
641
|
-
if (path === '/') return '/';
|
|
642
|
-
// 移除末尾的斜杠
|
|
643
|
-
let cleanPath = path;
|
|
644
|
-
while (cleanPath.endsWith('/') && cleanPath.length > 1) {
|
|
645
|
-
cleanPath = cleanPath.slice(0, -1);
|
|
646
|
-
}
|
|
647
|
-
// 找到最后一个斜杠
|
|
648
|
-
const lastSlash = cleanPath.lastIndexOf('/');
|
|
649
|
-
if (lastSlash === -1) return '.';
|
|
650
|
-
if (lastSlash === 0) return '/';
|
|
651
|
-
const result = cleanPath.slice(0, lastSlash);
|
|
652
|
-
return result || '/';
|
|
653
|
-
},
|
|
654
|
-
// 获取文件名
|
|
655
|
-
basename(path, ext) {
|
|
656
|
-
if (!path) return '';
|
|
657
|
-
// 找到最后一个斜杠
|
|
658
|
-
const lastSlash = path.lastIndexOf('/');
|
|
659
|
-
let filename = lastSlash === -1 ? path : path.slice(lastSlash + 1);
|
|
660
|
-
// 处理空文件名(路径以斜杠结尾)
|
|
661
|
-
if (filename === '') return '';
|
|
662
|
-
// 如果指定了扩展名,移除它
|
|
663
|
-
if (ext && typeof ext === 'string' && filename.endsWith(ext)) {
|
|
664
|
-
filename = filename.slice(0, -ext.length);
|
|
665
|
-
}
|
|
666
|
-
return filename;
|
|
667
|
-
},
|
|
668
|
-
// 获取扩展名
|
|
669
|
-
extname(path) {
|
|
670
|
-
if (!path) return '';
|
|
671
|
-
// 找到最后一个斜杠
|
|
672
|
-
const lastSlash = path.lastIndexOf('/');
|
|
673
|
-
const filename = lastSlash === -1 ? path : path.slice(lastSlash + 1);
|
|
674
|
-
// 找到最后一个点
|
|
675
|
-
const lastDot = filename.lastIndexOf('.');
|
|
676
|
-
// 如果没有点,或者点是第一个字符,返回空字符串
|
|
677
|
-
if (lastDot <= 0) return '';
|
|
678
|
-
return filename.slice(lastDot);
|
|
679
|
-
},
|
|
680
|
-
|
|
681
|
-
// 判断是否绝对路径
|
|
682
|
-
isAbsolute(path) {
|
|
683
|
-
return path && path.startsWith('/');
|
|
684
|
-
},
|
|
685
|
-
// 计算相对路径
|
|
686
|
-
relative(from, to) {
|
|
687
|
-
if (!from || !to) return '';
|
|
688
|
-
// 规范化两个路径
|
|
689
|
-
const fromPath = this.normalize(from);
|
|
690
|
-
const toPath = this.normalize(to);
|
|
691
|
-
// 如果相同,返回空字符串
|
|
692
|
-
if (fromPath === toPath) return '';
|
|
693
|
-
// 分割路径部分
|
|
694
|
-
const fromParts = fromPath.split('/').filter(part => part && part !== '.');
|
|
695
|
-
const toParts = toPath.split('/').filter(part => part && part !== '.');
|
|
696
|
-
// 找到共同前缀
|
|
697
|
-
let commonLength = 0;
|
|
698
|
-
const minLength = Math.min(fromParts.length, toParts.length);
|
|
699
|
-
for (let i = 0; i < minLength; i++) {
|
|
700
|
-
if (fromParts[i] !== toParts[i]) break;
|
|
701
|
-
commonLength++;
|
|
702
|
-
}
|
|
703
|
-
// 计算需要向上走的层级
|
|
704
|
-
const upLevels = fromParts.length - commonLength;
|
|
705
|
-
// 获取目标路径的剩余部分
|
|
706
|
-
const remainingParts = toParts.slice(commonLength);
|
|
707
|
-
// 构建相对路径
|
|
708
|
-
let result = '';
|
|
709
|
-
// 添加向上走的层级
|
|
710
|
-
for (let i = 0; i < upLevels; i++) {
|
|
711
|
-
result += '../';
|
|
712
|
-
}
|
|
713
|
-
// 添加目标路径的剩余部分
|
|
714
|
-
result += remainingParts.join('/');
|
|
715
|
-
return result || '.';
|
|
716
|
-
},
|
|
717
|
-
// 解析路径为对象
|
|
718
|
-
parse(path) {
|
|
719
|
-
if (!path) {
|
|
720
|
-
return {
|
|
721
|
-
root: '',
|
|
722
|
-
dir: '',
|
|
723
|
-
base: '',
|
|
724
|
-
ext: '',
|
|
725
|
-
name: ''
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
const root = path.startsWith('/') ? '/' : '';
|
|
729
|
-
const dir = this.dirname(path);
|
|
730
|
-
const base = this.basename(path);
|
|
731
|
-
const ext = this.extname(path);
|
|
732
|
-
const name = ext ? base.slice(0, -ext.length) : base;
|
|
733
|
-
return { root, dir, base, ext, name };
|
|
734
|
-
},
|
|
735
|
-
// 格式化对象为路径
|
|
736
|
-
format(pathObject) {
|
|
737
|
-
if (!pathObject || typeof pathObject !== 'object') {
|
|
738
|
-
throw new TypeError('pathObject must be an object');
|
|
739
|
-
}
|
|
740
|
-
const { root = '', dir = '', base = '', name = '', ext = '' } = pathObject;
|
|
741
|
-
// 如果有 dir,优先使用 dir + base
|
|
742
|
-
if (dir) {
|
|
743
|
-
const joined = this.join(dir, base || name + ext);
|
|
744
|
-
return joined;
|
|
745
|
-
}
|
|
746
|
-
// 否则使用 root + name + ext
|
|
747
|
-
return root + (name || base) + ext;
|
|
748
|
-
},
|
|
749
|
-
// 添加 posix 和 win32 引用(简化版)
|
|
750
|
-
get posix() {
|
|
751
|
-
return this;
|
|
752
|
-
},
|
|
753
|
-
get win32() {
|
|
754
|
-
// 简化的 Windows 版本,只是替换了分隔符
|
|
755
|
-
return {
|
|
756
|
-
...this,
|
|
757
|
-
sep: '\\',
|
|
758
|
-
delimiter: ';',
|
|
759
|
-
normalize: (path) => this.normalize(path.replace(/\\/g, '/')).replace(/\//g, '\\'),
|
|
760
|
-
isAbsolute: (path) => /^[A-Za-z]:\\/.test(path) || /^\\\\/.test(path) || path.startsWith('\\')
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
};}},"/packitup/src/index.js","packitup","PackItUp");
|
|
1
|
+
(moduleDict=>{const caches={__proto__:null},proc={moduleDict:moduleDict,workdir:"/packitup"},simpRequire=moduleId=>{if(moduleId in caches)return caches[moduleId];const module={exports:{}};return(0,moduleDict["/modules/"+moduleId+".js"])(simpRequire,module.exports,module,proc),caches[moduleId]=module.exports,module.exports};simpRequire.original="function"==typeof require?require:simpRequire,proc.isMain="object"==typeof module&&simpRequire.original.main===module;const Module=simpRequire("module"),factory=()=>{new Module("/packitup/src/index.js");return Module._load("/packitup/src/index.js",void 0,!0)};"object"==typeof exports?module.exports=factory():"function"==typeof define?define("packitup",[],factory):globalThis.PackItUp=factory()})({"/packitup/src/index.js"(require,exports,module){const build=require("./lib/build.js"),builder=require("./lib/builder.js"),cli=require("./lib/cli.js");module.exports={...build,...builder},require.main===module&&cli.main()},"/packitup/src/lib/build-template.js"(require,exports,module){module.exports=(moduleDict,mainfile,projectName,globalExport,isesm)=>{const caches={__proto__:null},proc={moduleDict:moduleDict,workdir:"/"+projectName},simpRequire=moduleId=>{if(moduleId in caches)return caches[moduleId];const module={exports:{}};return(0,moduleDict["/modules/"+moduleId+".js"])(simpRequire,module.exports,module,proc),caches[moduleId]=module.exports,module.exports};simpRequire.original="function"==typeof require?require:simpRequire,proc.isMain="object"==typeof module&&simpRequire.original.main===module;const Module=simpRequire("module"),factory=()=>{new Module(mainfile);return Module._load(mainfile,void 0,!0)};if(isesm)return factory();"object"==typeof exports?module.exports=factory():"function"==typeof define?define(projectName,[],factory):globalThis[globalExport]=factory()}},"/packitup/src/lib/build.js"(require,exports,module){const fs=require("fs"),{sep:pathSep,join:pathJoin,resolve:resolve}=require("path"),templateFunction=require("./build-template.js"),{moduleDict:mdict}=module.$build$?require("[build]"):{},search=(path,rule)=>{const listdir=fs.readdirSync(path),result=[];for(const filename of listdir){const file=path+pathSep+filename;if(fs.statSync(file).isDirectory()){let subfiles=search(file,rule);subfiles=subfiles.filter(filePath=>rule.test(filePath)),result.push(...subfiles);continue}rule.test(file)&&result.push(file)}return result},build=(allJS,main,options={})=>{const{projectName:projectName="project",globalExportName:globalExportName=projectName,esmExport:esmExport="export default module;",dontPack:dontPack=[],move:move=path=>path}=options,moduleMap={};for(let filePath of allJS){if(filePath.startsWith("./")&&(filePath=filePath.slice(2)),dontPack.some(dont=>dont.test(filePath)))continue;const saveFilePath=move(pathSep+projectName+pathSep+filePath);filePath&&(moduleMap[saveFilePath]=fs.readFileSync(filePath))}mdict&&Object.entries(mdict).forEach(([key,value])=>{key.startsWith("/modules/")&&(value=String(value).match(/\{([\S\s]*)\}/)[1],moduleMap[key]=value)});const moduleDict=(()=>{const mapping=[];for(const[key,value]of Object.entries(moduleMap)){const pathKey=JSON.stringify(key);key.endsWith(".js")?mapping.push(`${pathKey}(require,exports,module){${value}}`):key.endsWith(".json")?mapping.push(`${pathKey}:${value}`):mapping.push(`${pathKey}:${JSON.stringify(value)}`)}return`{${mapping}}`})(),template=`(${templateFunction})`,esmTemplate=esmExport,projectNameStr=JSON.stringify(projectName),globalExportNameStr=JSON.stringify(globalExportName);return{umd:`${template}(${moduleDict},${JSON.stringify(main)},${projectNameStr},${globalExportNameStr});`,esm:`const module=${`${template}(${moduleDict},${JSON.stringify(main)},${projectNameStr},${globalExportNameStr},1)`};${esmTemplate}`,options:options}};module.exports={build:build,buildDirectory:(directory,options={})=>{if(!options.projectName){let projectName=resolve(directory);const paths=projectName.split(pathSep);let index=1;do{projectName=paths[paths.length-index],index++}while(["src","lib"].includes(projectName)&&index<paths.length);options.projectName=projectName}options.extensions||(options.extensions=[".js",".json",".txt",".svg",".xml",".html"]);const test=path=>options.extensions.some(ext=>path.endsWith(ext)),allJS=search(directory,{test:test}),parent=fs.readdirSync(resolve(directory).split(pathSep).slice(0,-1).join(pathSep));if(parent.includes("node_modules")){const node_modules=search(parent,{test:test});allJS.push(...node_modules)}return build(allJS,pathSep+pathJoin(options.projectName,directory,"index.js"),options)}}},"/packitup/src/lib/builder.js"(require,exports,module){const fs=require("fs"),path=require("path"),{buildDirectory:buildDirectory}=require("./build.js");exports.outputBundle=options=>{let{sourcePath:sourcePath,umdFile:umdFile,esmFile:esmFile,distPath:distPath,esmTemplate:esmTemplate}=options;esmTemplate&&(options.esmExport=fs.readFileSync(esmTemplate));const dist=buildDirectory(sourcePath,options),projectName=dist.options.projectName;distPath.endsWith(path.sep)||(distPath+=path.sep),umdFile??=distPath+projectName+".js",esmFile??=distPath+projectName+".mjs",fs.writeFileSync(umdFile,dist.umd),fs.writeFileSync(esmFile,dist.esm)}},"/packitup/src/lib/cli.js"(require,exports,module){require("path"),require("fs");const{outputBundle:outputBundle}=require("./builder.js");function parseArgs(){const args=process.argv.slice(2),options={},positional=[];return{index:0,curr:args[0],next(){this.index++,this.curr=args[this.index]},peek(n=1){return args[this.index+n]},parse(){for(;this.curr;)this.parseArgument()},parseArgument(){if(this.curr.startsWith("--")){const key=this.curr.slice(2),nextArg=this.peek();return nextArg&&!nextArg.startsWith("--")?(this.next(),void(options[key]=nextArg)):void(options[key]=!0)}this.curr.startsWith("-")?options[this.curr.slice(1)]=!0:(positional.push(this.curr),this.next())}}.parse(),{options:options,positional:positional}}function showHelp(){console.log('\n📦 PackItUp - JavaScript Packager\n\nATTENTION: If you\'re running for the first time, please cd to module path and run "npm run install".\n\nUsage: packitup [command] [options]\n\nCommands:\n build <input-directory> [output-directory] Pack a directory\n\nOptions:\n --name <projectName> Specify project name\n --umd <fileName> Specify UMD output file name\n --esm <fileName> Specify ESM output file name\n --esm-template <template> Specify ESM output template\n --help Show this help message\n\n')}module.exports={parseArgs:parseArgs,main:async function(){const{options:options,positional:positional}=parseArgs();(options.help||0===positional.length)&&(showHelp(),process.exit(0));const command=positional[0];switch(command){case"build":{const input=positional[1],output=positional[2]||".";input||(console.error("❌ Error: Please specify input directory"),showHelp(),process.exit(1)),console.log(`🚀 Starting pack: ${input} → ${output}`),outputBundle({sourcePath:input,projectName:options.name,distPath:output,umdFile:options.umd,esmFile:options.esm,move:options.move?pth=>options["move-from"]&&pth.startsWith(options["move-from"])?pth.replace(options["move-from"],options["move-to"]||options["move-from"]):pth:void 0,dontExport:(options["dont-export"]??"").split(" "),esmTemplate:options["esm-template"]}),console.log("✅ Pack complete!");break}default:console.error(`❌ Unknown command: ${command}`),showHelp(),process.exit(1)}}}},"/modules/[build].js"(require,exports,module){module.exports=arguments[3]},"/modules/module.js"(require,exports,module){const proc=require("[build]"),{moduleDict:moduleDict}=proc,path=require("path");let mainModule;function updateChildren(parent,child,scan){const children=parent?.children;!children||scan&&children.includes(child)||children.push(child)}function raiseModuleNotFound(request){const modname=request.replaceAll("'","\\'");throw new Error("Cannot find module '"+modname+"'")}function Module(id="",parent){this.id=id,this.path=path.dirname(id),this.exports={},updateChildren(parent,this,!1),this.filename=null,this.loaded=!1,this.children=[]}Module.Module=Module,Module._nodeModulePaths=function(from){const paths=[];for(let current=from=path.resolve(from);current!==path.dirname(current);current=path.dirname(current))paths.push(path.join(current,"node_modules"));return paths.push("/node_modules"),paths},Module._cache=Object.create(null),Module._extensions=Object.create(null),Module.builtinModules=["_http_agent","_http_client","_http_common","_http_incoming","_http_outgoing","_http_server","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_wrap","_stream_writable","_tls_common","_tls_wrap","assert","assert/strict","async_hooks","buffer","child_process","cluster","console","constants","crypto","dgram","diagnostics_channel","dns","dns/promises","domain","events","fs","fs/promises","http","http2","https","inspector","inspector/promises","module","net","os","path","path/posix","path/win32","perf_hooks","process","punycode","querystring","readline","readline/promises","repl","stream","stream/consumers","stream/promises","stream/web","string_decoder","sys","timers","timers/promises","tls","trace_events","tty","url","util","util/types","v8","vm","wasi","worker_threads","zlib","node:sea","node:sqlite","node:test","node:test/reporters"];const SpecialModules=["module","[build]"];Module._load=function(request,parent,isMain){if(Module.builtinModules.includes(request))return require.original(request);if(SpecialModules.includes(request))return require(request);const filename=function(request,parent){if([".","..",""].some(start=>request.startsWith(start+path.sep))){const requestPath=request.startsWith(path.sep)?request:path.resolve(request);if(requestPath in moduleDict)return requestPath;const extensions=Object.keys(Module._extensions);for(const extension of extensions){const withext=requestPath+extension;if(withext in moduleDict)return withext}const indexPath=path.join(requestPath,"index");for(const extension of extensions){const withext=indexPath+extension;if(withext in moduleDict)return withext}raiseModuleNotFound(request)}if(parent)for(const maybeNm of parent.paths){const[moduleName,...subdirs]=request.split(path.sep),subdir=subdirs.length?path.join(...subdirs):".",maybe=path.join(maybeNm,moduleName),packageJSON=moduleDict[path.join(maybe,"package.json")];if(packageJSON){if(packageJSON.exports){const{exports:exports}=packageJSON;if("string"==typeof exports)return path.join(maybe,exports);if("object"==typeof exports&&exports[subdir]){const entry=exports[subdir];if("string"==typeof entry)return path.join(maybe,entry);if("object"==typeof entry){if(entry.require)return path.join(maybe,entry.require);if(entry.default)return path.join(maybe,entry.default)}}}if(packageJSON.main)return path.join(maybe,packageJSON.main)}const indexPath=path.join(maybe,request,"index.js");if(indexPath in moduleDict)return indexPath}raiseModuleNotFound(request)}(request,parent),cachedModule=Module._cache[filename];if(void 0!==cachedModule){if(updateChildren(parent,cachedModule,!0),cachedModule.loaded)return cachedModule.exports;if(!cachedModule[kIsCachedByESMLoader])return getExportsForCircularRequire(cachedModule);if(cachedModule[kModuleCircularVisited])return getExportsForCircularRequire(cachedModule);cachedModule[kModuleCircularVisited]=!0}const module=cachedModule||new Module(filename,parent);return cachedModule||(isMain&&(proc.isMain&&(mainModule=module,Module.prototype.require.main=null),module.id="."),Module._cache[filename]=module,module.load(filename)),module.exports},Module.prototype.load=function(filename){this.filename??=filename,this.paths??=Module._nodeModulePaths(path.dirname(filename));const extension=filename.includes(".")?"."+filename.split(".").slice(-1)[0]:"";Module._extensions[extension](this,filename),this.loaded=!0},Module.prototype.require=function(id){return request=id,parent=this,isMain=!1,Module._load.call({__proto__:null,parentFilename:parent?.filename,id:request},request,parent,isMain);var request,parent,isMain},Module.prototype.require.main=null,Object.assign(Module._extensions,{".js":function(module,filename){function require(path){return module.require(path)}require.main=mainModule,require.extensions=Module._extensions,require.cache=Module._cache;const factory=moduleDict[filename],oldworkdir=proc.workdir;proc.workdir=path.dirname(filename),factory(require,module.exports,module),proc.workdir=oldworkdir},".json":function(module,filename){module.exports=moduleDict[filename]}}),Module.prototype.$build$=!0,module.exports=Module},"/modules/path.js"(require,exports,module){const proc=require("[build]");module.exports={sep:"/",delimiter:":",normalize(path){if(!path)return".";let result=path.replace(/\/+/g,"/");result.startsWith("./")&&(result=result.slice(2)),result=result.replace(/\/\.\//g,"/"),result.endsWith("/.")&&(result=result.slice(0,-2));const parts=result.split("/"),newParts=[];for(const part of parts)".."===part?newParts.length>0&&newParts.pop():""!==part&&"."!==part&&newParts.push(part);return result=newParts.join("/"),path.startsWith("/")?result="/"+result:path.startsWith("./")&&(result="./"+result),""===result?".":(path.endsWith("/")&&!result.endsWith("/")&&"."!==result&&(result+="/"),result)},join(...paths){if(0===paths.length)return".";let result="";for(const segment of paths)segment&&(""===result?result=segment:result+="/"+segment);return this.normalize(result)},resolve(...paths){if(0===paths.length)return proc.workdir||"/";let result="",isAbsolute=!1;for(let i=paths.length-1;i>=0;i--){const path=paths[i];path&&(path.startsWith("/")?(result=path,isAbsolute=!0):result=""===result?path:path+"/"+result)}return isAbsolute||(result=(proc.workdir||"/")+"/"+result),this.normalize(result)},dirname(path){if(!path||"."===path||".."===path)return".";if("/"===path)return"/";let cleanPath=path;for(;cleanPath.endsWith("/")&&cleanPath.length>1;)cleanPath=cleanPath.slice(0,-1);const lastSlash=cleanPath.lastIndexOf("/");if(-1===lastSlash)return".";if(0===lastSlash)return"/";return cleanPath.slice(0,lastSlash)||"/"},basename(path,ext){if(!path)return"";const lastSlash=path.lastIndexOf("/");let filename=-1===lastSlash?path:path.slice(lastSlash+1);return""===filename?"":(ext&&"string"==typeof ext&&filename.endsWith(ext)&&(filename=filename.slice(0,-ext.length)),filename)},extname(path){if(!path)return"";const lastSlash=path.lastIndexOf("/"),filename=-1===lastSlash?path:path.slice(lastSlash+1),lastDot=filename.lastIndexOf(".");return lastDot<=0?"":filename.slice(lastDot)},isAbsolute:path=>path&&path.startsWith("/"),relative(from,to){if(!from||!to)return"";const fromPath=this.normalize(from),toPath=this.normalize(to);if(fromPath===toPath)return"";const fromParts=fromPath.split("/").filter(part=>part&&"."!==part),toParts=toPath.split("/").filter(part=>part&&"."!==part);let commonLength=0;const minLength=Math.min(fromParts.length,toParts.length);for(let i=0;i<minLength&&fromParts[i]===toParts[i];i++)commonLength++;const upLevels=fromParts.length-commonLength,remainingParts=toParts.slice(commonLength);let result="";for(let i=0;i<upLevels;i++)result+="../";return result+=remainingParts.join("/"),result||"."},parse(path){if(!path)return{root:"",dir:"",base:"",ext:"",name:""};const root=path.startsWith("/")?"/":"",dir=this.dirname(path),base=this.basename(path),ext=this.extname(path),name=ext?base.slice(0,-ext.length):base;return{root:root,dir:dir,base:base,ext:ext,name:name}},format(pathObject){if(!pathObject||"object"!=typeof pathObject)throw new TypeError("pathObject must be an object");const{root:root="",dir:dir="",base:base="",name:name="",ext:ext=""}=pathObject;if(dir){return this.join(dir,base||name+ext)}return root+(name||base)+ext},get posix(){return this},get win32(){return{...this,sep:"\\",delimiter:";",normalize:path=>this.normalize(path.replace(/\\/g,"/")).replace(/\//g,"\\"),isAbsolute:path=>/^[A-Za-z]:\\/.test(path)||/^\\\\/.test(path)||path.startsWith("\\")}}}}});
|