@hakobu/hakobu 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +673 -0
- package/dictionary/angular-bridge.js +3 -0
- package/dictionary/any-promise.js +3 -0
- package/dictionary/async.js +3 -0
- package/dictionary/aws-sdk.js +7 -0
- package/dictionary/babel-core.js +3 -0
- package/dictionary/batch.js +3 -0
- package/dictionary/bcrypt.js +3 -0
- package/dictionary/better-sqlite3.js +3 -0
- package/dictionary/bignum.js +3 -0
- package/dictionary/bindings.js +3 -0
- package/dictionary/blessed.js +8 -0
- package/dictionary/body-parser.js +9 -0
- package/dictionary/browserify.js +7 -0
- package/dictionary/bson.js +3 -0
- package/dictionary/buffermaker.js +7 -0
- package/dictionary/bunyan.js +9 -0
- package/dictionary/busboy.js +7 -0
- package/dictionary/bytes.js +3 -0
- package/dictionary/callsites.js +3 -0
- package/dictionary/chokidar.js +3 -0
- package/dictionary/coffee-script.js +7 -0
- package/dictionary/colors.js +3 -0
- package/dictionary/compression.js +3 -0
- package/dictionary/compressjs.js +7 -0
- package/dictionary/connect-mongo.js +3 -0
- package/dictionary/connect-mongodb.js +3 -0
- package/dictionary/connect-redis.js +3 -0
- package/dictionary/connect.js +10 -0
- package/dictionary/consolidate.js +3 -0
- package/dictionary/cookie-parser.js +3 -0
- package/dictionary/cookie.js +3 -0
- package/dictionary/cors.js +3 -0
- package/dictionary/cron.js +3 -0
- package/dictionary/cross-env.js +11 -0
- package/dictionary/cross-spawn-async.js +3 -0
- package/dictionary/curve25519.js +3 -0
- package/dictionary/data-preflight.js +7 -0
- package/dictionary/debug.js +3 -0
- package/dictionary/denymount.js +3 -0
- package/dictionary/diff.js +3 -0
- package/dictionary/drivelist.js +22 -0
- package/dictionary/ed25519.js +3 -0
- package/dictionary/ejs.js +3 -0
- package/dictionary/elasticsearch.js +3 -0
- package/dictionary/electron.js +17 -0
- package/dictionary/emailjs.js +3 -0
- package/dictionary/engine.io.js +3 -0
- package/dictionary/epoll.js +3 -0
- package/dictionary/errorhandler.js +7 -0
- package/dictionary/errors.js +7 -0
- package/dictionary/eslint.js +7 -0
- package/dictionary/etcher-image-write.js +3 -0
- package/dictionary/exceljs.js +21 -0
- package/dictionary/exiftool.exe.js +13 -0
- package/dictionary/exiftool.pl.js +13 -0
- package/dictionary/express-load.js +12 -0
- package/dictionary/express-session.js +3 -0
- package/dictionary/express.js +14 -0
- package/dictionary/extender.js +11 -0
- package/dictionary/extsprintf.js +3 -0
- package/dictionary/faye-websocket.js +3 -0
- package/dictionary/feathers.js +3 -0
- package/dictionary/findup-sync.js +3 -0
- package/dictionary/floordate.js +3 -0
- package/dictionary/fmt.js +3 -0
- package/dictionary/formidable.js +3 -0
- package/dictionary/fs-extra.js +3 -0
- package/dictionary/fsevents.js +3 -0
- package/dictionary/geoip-lite.js +7 -0
- package/dictionary/github.js +7 -0
- package/dictionary/gm.js +3 -0
- package/dictionary/google-closure-compiler-java.js +13 -0
- package/dictionary/google-closure-compiler.js +13 -0
- package/dictionary/googleapis.js +7 -0
- package/dictionary/got.js +3 -0
- package/dictionary/graceful-fs.js +19 -0
- package/dictionary/grpc.js +11 -0
- package/dictionary/gulp.js +3 -0
- package/dictionary/hap-nodejs.js +3 -0
- package/dictionary/heapdump.js +3 -0
- package/dictionary/hoek.js +3 -0
- package/dictionary/homebridge.js +3 -0
- package/dictionary/http-proxy.js +3 -0
- package/dictionary/http-server.js +3 -0
- package/dictionary/image-size.js +3 -0
- package/dictionary/indexof.js +3 -0
- package/dictionary/inquirer.js +3 -0
- package/dictionary/j.js +16 -0
- package/dictionary/jade.js +3 -0
- package/dictionary/jsdom.js +3 -0
- package/dictionary/json-stringify-date.js +3 -0
- package/dictionary/json-stringify-safe.js +3 -0
- package/dictionary/jsonwebtoken.js +3 -0
- package/dictionary/kerberos.js +3 -0
- package/dictionary/knex.js +7 -0
- package/dictionary/later.js +7 -0
- package/dictionary/level.js +3 -0
- package/dictionary/leveldown.js +10 -0
- package/dictionary/levelup.js +3 -0
- package/dictionary/liftoff.js +12 -0
- package/dictionary/lodash.js +3 -0
- package/dictionary/log4js.js +7 -0
- package/dictionary/logform.js +7 -0
- package/dictionary/machinepack-urls.js +7 -0
- package/dictionary/markdown.js +3 -0
- package/dictionary/mdns.js +6 -0
- package/dictionary/method-override.js +3 -0
- package/dictionary/microjob.js +16 -0
- package/dictionary/mime-types.js +3 -0
- package/dictionary/mime.js +3 -0
- package/dictionary/minimatch.js +3 -0
- package/dictionary/minstache.js +3 -0
- package/dictionary/module-deps.js +3 -0
- package/dictionary/moment-timezone.js +3 -0
- package/dictionary/moment.js +7 -0
- package/dictionary/mongodb-core.js +22 -0
- package/dictionary/mongodb.js +7 -0
- package/dictionary/mongoose.js +7 -0
- package/dictionary/mongoskin.js +7 -0
- package/dictionary/ms.js +3 -0
- package/dictionary/msgpack.js +3 -0
- package/dictionary/multer.js +3 -0
- package/dictionary/muri.js +3 -0
- package/dictionary/native-or-bluebird.js +3 -0
- package/dictionary/natives.js +3 -0
- package/dictionary/nconf.js +7 -0
- package/dictionary/nedb.js +3 -0
- package/dictionary/negotiator.js +7 -0
- package/dictionary/newrelic.js +3 -0
- package/dictionary/nib.js +3 -0
- package/dictionary/nightmare.js +18 -0
- package/dictionary/node-forge.js +7 -0
- package/dictionary/node-libcurl.js +3 -0
- package/dictionary/node-notifier.js +30 -0
- package/dictionary/node-pre-gyp.js +7 -0
- package/dictionary/node-redis-pubsub.js +3 -0
- package/dictionary/node-sass.js +3 -0
- package/dictionary/node-uuid.js +3 -0
- package/dictionary/node-xlsx.js +3 -0
- package/dictionary/node-zookeeper-client.js +7 -0
- package/dictionary/nodegit.js +7 -0
- package/dictionary/nodemailer-sendmail-transport.js +3 -0
- package/dictionary/nodemailer.js +3 -0
- package/dictionary/npm-registry-client.js +7 -0
- package/dictionary/npm.js +7 -0
- package/dictionary/nssocket.js +3 -0
- package/dictionary/oauth2orize.js +7 -0
- package/dictionary/octobat.js +3 -0
- package/dictionary/open.js +13 -0
- package/dictionary/opn.js +4 -0
- package/dictionary/optimist.js +3 -0
- package/dictionary/passport-local.js +3 -0
- package/dictionary/passport.js +3 -0
- package/dictionary/pg-cursor.js +3 -0
- package/dictionary/pg-query-stream.js +3 -0
- package/dictionary/pg-types.js +7 -0
- package/dictionary/pg.js +7 -0
- package/dictionary/pg.js.js +7 -0
- package/dictionary/pgpass.js +7 -0
- package/dictionary/phantom.js +19 -0
- package/dictionary/phantomjs-prebuilt.js +16 -0
- package/dictionary/pkginfo.js +3 -0
- package/dictionary/pm2.js +7 -0
- package/dictionary/pmx.js +3 -0
- package/dictionary/pouchdb.js +3 -0
- package/dictionary/primus-emitter.js +3 -0
- package/dictionary/primus-spark-latency.js +3 -0
- package/dictionary/primus.js +3 -0
- package/dictionary/publicsuffixlist.js +15 -0
- package/dictionary/pug.js +3 -0
- package/dictionary/punt.js +3 -0
- package/dictionary/puppeteer.js +13 -0
- package/dictionary/pwd.js +3 -0
- package/dictionary/q.js +3 -0
- package/dictionary/raven.js +3 -0
- package/dictionary/rc.js +12 -0
- package/dictionary/readable-stream.js +3 -0
- package/dictionary/rechoir.js +3 -0
- package/dictionary/redis-parser.js +3 -0
- package/dictionary/redis.js +3 -0
- package/dictionary/regression.js +3 -0
- package/dictionary/reload.js +7 -0
- package/dictionary/request.js +3 -0
- package/dictionary/require-uncached.js +3 -0
- package/dictionary/require_optional.js +3 -0
- package/dictionary/s3.js +3 -0
- package/dictionary/safe_datejs.js +3 -0
- package/dictionary/sails.js +33 -0
- package/dictionary/sax.js +3 -0
- package/dictionary/scrypt.js +3 -0
- package/dictionary/semver.js +3 -0
- package/dictionary/sequelize.js +7 -0
- package/dictionary/serialport.js +3 -0
- package/dictionary/sha3.js +3 -0
- package/dictionary/sharp.js +11 -0
- package/dictionary/shelljs.js +7 -0
- package/dictionary/sinon.js +3 -0
- package/dictionary/socket.io-client.js +13 -0
- package/dictionary/socket.io.js +12 -0
- package/dictionary/sqip.js +7 -0
- package/dictionary/sqlite3.js +7 -0
- package/dictionary/steam-crypto.js +7 -0
- package/dictionary/steam-resources.js +19 -0
- package/dictionary/steam.js +3 -0
- package/dictionary/stripe-webhook-middleware.js +3 -0
- package/dictionary/stripe.js +3 -0
- package/dictionary/strong-globalize.js +3 -0
- package/dictionary/stylus.js +14 -0
- package/dictionary/supervisor.js +3 -0
- package/dictionary/svgo.js +8 -0
- package/dictionary/tabtab.js +3 -0
- package/dictionary/tesseract.js.js +7 -0
- package/dictionary/thread-stream.js +7 -0
- package/dictionary/throng.js +3 -0
- package/dictionary/time.js +3 -0
- package/dictionary/tinify.js +7 -0
- package/dictionary/tiny-worker.js +7 -0
- package/dictionary/tmp.js +3 -0
- package/dictionary/transformers.js +3 -0
- package/dictionary/uglify-js.js +9 -0
- package/dictionary/umd.js +19 -0
- package/dictionary/underscore.js +3 -0
- package/dictionary/union.js +3 -0
- package/dictionary/update-notifier.js +3 -0
- package/dictionary/usage.js +7 -0
- package/dictionary/v8flags.js +13 -0
- package/dictionary/verror.js +3 -0
- package/dictionary/voc.js +3 -0
- package/dictionary/webdriverio.js +7 -0
- package/dictionary/winston-uber.js +7 -0
- package/dictionary/winston.js +7 -0
- package/dictionary/ws.js +3 -0
- package/dictionary/xlsx.js +16 -0
- package/dictionary/xml2js.js +3 -0
- package/dictionary/yargs.js +3 -0
- package/dictionary/zeromq.js +13 -0
- package/lib-es5/addon-extract.js +164 -0
- package/lib-es5/analyzer.js +687 -0
- package/lib-es5/app-bundle.js +133 -0
- package/lib-es5/appdir.js +265 -0
- package/lib-es5/bin.js +304 -0
- package/lib-es5/bootstrap.js +179 -0
- package/lib-es5/bundler.js +496 -0
- package/lib-es5/chmod.js +15 -0
- package/lib-es5/colors.js +12 -0
- package/lib-es5/commands.js +376 -0
- package/lib-es5/common.js +328 -0
- package/lib-es5/compress_type.js +10 -0
- package/lib-es5/config.js +291 -0
- package/lib-es5/detector.js +421 -0
- package/lib-es5/esm-hooks.js +366 -0
- package/lib-es5/esm-resolver.js +292 -0
- package/lib-es5/esm-transformer.js +378 -0
- package/lib-es5/exports-resolver.js +184 -0
- package/lib-es5/external-artifacts.js +170 -0
- package/lib-es5/fabricator.js +137 -0
- package/lib-es5/follow.js +190 -0
- package/lib-es5/help.js +52 -0
- package/lib-es5/index.d.ts +2 -0
- package/lib-es5/index.js +552 -0
- package/lib-es5/log.js +7 -0
- package/lib-es5/mach-o.js +262 -0
- package/lib-es5/manifest.js +21 -0
- package/lib-es5/options.js +19 -0
- package/lib-es5/packager.js +1036 -0
- package/lib-es5/packer.js +137 -0
- package/lib-es5/pe-metadata.js +130 -0
- package/lib-es5/producer.js +378 -0
- package/lib-es5/refiner.js +87 -0
- package/lib-es5/resolver.js +142 -0
- package/lib-es5/runtime-diagnostics.js +172 -0
- package/lib-es5/sea.js +307 -0
- package/lib-es5/snapshot-fs-patch.js +396 -0
- package/lib-es5/snapshot-fs.js +255 -0
- package/lib-es5/snapshot-index.js +135 -0
- package/lib-es5/snapshot-path.js +168 -0
- package/lib-es5/types.js +9 -0
- package/lib-es5/walker.js +1019 -0
- package/lib-es5/windows-sign.js +139 -0
- package/package.json +99 -0
- package/prelude/bootstrap.js +2263 -0
- package/prelude/diagnostic.js +147 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hakobu Bundle Mode
|
|
4
|
+
*
|
|
5
|
+
* Optional pre-processing step that bundles a project before packaging.
|
|
6
|
+
* This is useful for:
|
|
7
|
+
* - TypeScript projects (compiled to JS)
|
|
8
|
+
* - Workspace monorepos (resolved to a single bundle)
|
|
9
|
+
* - Projects with complex dependency graphs (tree-shaken)
|
|
10
|
+
*
|
|
11
|
+
* Bundle mode is NOT the default. Native mode (direct packaging of JS files)
|
|
12
|
+
* remains the primary path. Bundle mode is an opt-in adapter that produces
|
|
13
|
+
* a self-contained JS project that the existing packaging pipeline can consume.
|
|
14
|
+
*
|
|
15
|
+
* Architecture:
|
|
16
|
+
* 1. BundleAdapter receives project root + entry + options
|
|
17
|
+
* 2. Adapter produces a bundled project in a temp directory
|
|
18
|
+
* 3. Packager runs on the temp directory as if it were a normal JS project
|
|
19
|
+
* 4. Temp directory is cleaned up after packaging
|
|
20
|
+
*/
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.getAdapter = exports.RolldownAdapter = void 0;
|
|
26
|
+
const fs_1 = __importDefault(require("fs"));
|
|
27
|
+
const path_1 = __importDefault(require("path"));
|
|
28
|
+
const os_1 = __importDefault(require("os"));
|
|
29
|
+
const parser_1 = require("@babel/parser");
|
|
30
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
31
|
+
const log_1 = require("./log");
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
33
|
+
// Rolldown adapter
|
|
34
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
35
|
+
class RolldownAdapter {
|
|
36
|
+
name = 'rolldown';
|
|
37
|
+
async bundle(input) {
|
|
38
|
+
// Dynamic import — rolldown is ESM-only and optional
|
|
39
|
+
let rolldown;
|
|
40
|
+
try {
|
|
41
|
+
rolldown = await loadRolldown();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new Error('Rolldown is required for bundle mode but could not be loaded.\n' +
|
|
45
|
+
'Install it with: pnpm add rolldown');
|
|
46
|
+
}
|
|
47
|
+
const { projectRoot, entry, external = [], appName } = input;
|
|
48
|
+
const entryPath = path_1.default.isAbsolute(entry)
|
|
49
|
+
? entry
|
|
50
|
+
: path_1.default.resolve(projectRoot, entry);
|
|
51
|
+
if (!fs_1.default.existsSync(entryPath)) {
|
|
52
|
+
throw new Error(`Bundle entry not found: ${entryPath}`);
|
|
53
|
+
}
|
|
54
|
+
// Create temp output directory
|
|
55
|
+
const tmpDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'hakobu-bundle-'));
|
|
56
|
+
const outFile = 'index.js';
|
|
57
|
+
const warnings = [];
|
|
58
|
+
try {
|
|
59
|
+
log_1.log.info(` bundler: rolldown`);
|
|
60
|
+
log_1.log.info(` entry: ${path_1.default.relative(projectRoot, entryPath)}`);
|
|
61
|
+
// Default externals: node builtins + runtime-specific protocols + user-specified
|
|
62
|
+
const allExternal = [
|
|
63
|
+
/^node:/,
|
|
64
|
+
/^bun:/,
|
|
65
|
+
/^electron$/,
|
|
66
|
+
/^chromium-bidi/,
|
|
67
|
+
...external.map(e => {
|
|
68
|
+
if (e.includes('*')) {
|
|
69
|
+
return new RegExp('^' + e.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*') + '$');
|
|
70
|
+
}
|
|
71
|
+
return e;
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
const build = await rolldown.rolldown({
|
|
75
|
+
input: entryPath,
|
|
76
|
+
platform: 'node',
|
|
77
|
+
resolve: {
|
|
78
|
+
conditionNames: ['node', 'import', 'require', 'default'],
|
|
79
|
+
mainFields: ['module', 'main'],
|
|
80
|
+
},
|
|
81
|
+
external: allExternal,
|
|
82
|
+
onwarn: (warning) => {
|
|
83
|
+
warnings.push({
|
|
84
|
+
message: warning.message || String(warning),
|
|
85
|
+
file: warning.loc?.file,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const writeResult = await writeBundleOutput(build, tmpDir, outFile);
|
|
90
|
+
// Post-bundle: apply compatibility patches for bundler-hostile packages
|
|
91
|
+
const applied = [];
|
|
92
|
+
for (const file of writeResult.jsFiles) {
|
|
93
|
+
applied.push(...applyBundlePatches(file));
|
|
94
|
+
}
|
|
95
|
+
// Create a minimal package.json for the bundled output
|
|
96
|
+
const bundledPkg = {
|
|
97
|
+
name: appName,
|
|
98
|
+
version: '0.0.0',
|
|
99
|
+
type: 'module',
|
|
100
|
+
main: outFile,
|
|
101
|
+
};
|
|
102
|
+
fs_1.default.writeFileSync(path_1.default.join(tmpDir, 'package.json'), JSON.stringify(bundledPkg, null, 2));
|
|
103
|
+
const outSize = writeResult.jsFiles.reduce((sum, file) => sum + fs_1.default.statSync(file).size, 0);
|
|
104
|
+
log_1.log.info(` output: ${(outSize / 1024).toFixed(0)}KB bundled ` +
|
|
105
|
+
`(${writeResult.strategy}, ${writeResult.chunkCount} chunk${writeResult.chunkCount === 1 ? '' : 's'})`);
|
|
106
|
+
if (writeResult.fallbackReason) {
|
|
107
|
+
log_1.log.info(` fallback: ${writeResult.fallbackReason}`);
|
|
108
|
+
}
|
|
109
|
+
if (writeResult.injectedChunks && writeResult.injectedChunks.length > 0) {
|
|
110
|
+
log_1.log.info(` injected __dirname/__filename into ${writeResult.injectedChunks.length} chunk(s)`);
|
|
111
|
+
}
|
|
112
|
+
// Post-bundle diagnostics: classify warnings and scan for unhandled patterns
|
|
113
|
+
const diagnostics = analyzeBundleDiagnostics(warnings, writeResult, applied, external);
|
|
114
|
+
for (const d of diagnostics) {
|
|
115
|
+
if (d.severity === 'info') {
|
|
116
|
+
log_1.log.info(` ${d.message}`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
log_1.log.warn(` ${d.message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Collect map file paths relative to tmpDir for asset inclusion
|
|
123
|
+
const relativeMapFiles = writeResult.mapFiles.map(f => path_1.default.relative(tmpDir, f));
|
|
124
|
+
return {
|
|
125
|
+
projectRoot: tmpDir,
|
|
126
|
+
entry: outFile,
|
|
127
|
+
warnings,
|
|
128
|
+
strategy: writeResult.strategy,
|
|
129
|
+
chunkCount: writeResult.chunkCount,
|
|
130
|
+
fallbackReason: writeResult.fallbackReason,
|
|
131
|
+
injectedChunks: writeResult.injectedChunks,
|
|
132
|
+
mapFiles: relativeMapFiles,
|
|
133
|
+
cleanup: () => {
|
|
134
|
+
try {
|
|
135
|
+
fs_1.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
catch { /* best effort */ }
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// Clean up on failure
|
|
143
|
+
try {
|
|
144
|
+
fs_1.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
catch { }
|
|
147
|
+
throw new Error(`Rolldown bundle failed: ${err.message}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.RolldownAdapter = RolldownAdapter;
|
|
152
|
+
const CHUNK_BANNER = [
|
|
153
|
+
`import{fileURLToPath as _hk_f}from'node:url';`,
|
|
154
|
+
`import{dirname as _hk_d}from'node:path';`,
|
|
155
|
+
].join('');
|
|
156
|
+
const PATH_GLOBALS_POLYFILL = `var __filename=_hk_f(import.meta.url),__dirname=_hk_d(__filename);`;
|
|
157
|
+
async function writeBundleOutput(build, tmpDir, outFile) {
|
|
158
|
+
// Always try code-splitting first
|
|
159
|
+
const result = await writeBundle(build, tmpDir, outFile, true);
|
|
160
|
+
// Inject __dirname/__filename polyfill into only the chunks that need it.
|
|
161
|
+
// Each chunk is scanned for bare __dirname/__filename references; if found,
|
|
162
|
+
// the polyfill is prepended. Chunks without these globals are left untouched.
|
|
163
|
+
const injectedChunks = injectPathGlobalsPerChunk(result.jsFiles);
|
|
164
|
+
const isSplit = result.jsFiles.length > 1;
|
|
165
|
+
return {
|
|
166
|
+
strategy: isSplit ? 'code-split' : 'single-chunk',
|
|
167
|
+
chunkCount: result.jsFiles.length,
|
|
168
|
+
jsFiles: result.jsFiles,
|
|
169
|
+
mapFiles: result.mapFiles,
|
|
170
|
+
...(injectedChunks.length > 0 ? {
|
|
171
|
+
injectedChunks: injectedChunks.map(f => path_1.default.basename(f)),
|
|
172
|
+
} : {}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function writeBundle(build, tmpDir, outFile, codeSplitting) {
|
|
176
|
+
await build.write({
|
|
177
|
+
dir: tmpDir,
|
|
178
|
+
format: 'esm',
|
|
179
|
+
entryFileNames: outFile,
|
|
180
|
+
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
181
|
+
sourcemap: true,
|
|
182
|
+
codeSplitting,
|
|
183
|
+
banner: CHUNK_BANNER,
|
|
184
|
+
});
|
|
185
|
+
return listBundleFiles(tmpDir);
|
|
186
|
+
}
|
|
187
|
+
function listBundleFiles(rootDir) {
|
|
188
|
+
const jsFiles = [];
|
|
189
|
+
const mapFiles = [];
|
|
190
|
+
function walk(dir) {
|
|
191
|
+
for (const entry of fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
192
|
+
const fullPath = path_1.default.join(dir, entry.name);
|
|
193
|
+
if (entry.isDirectory()) {
|
|
194
|
+
walk(fullPath);
|
|
195
|
+
}
|
|
196
|
+
else if (entry.isFile()) {
|
|
197
|
+
if (/\.(?:m?js|cjs)$/.test(entry.name)) {
|
|
198
|
+
jsFiles.push(fullPath);
|
|
199
|
+
}
|
|
200
|
+
else if (entry.name.endsWith('.map')) {
|
|
201
|
+
mapFiles.push(fullPath);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
walk(rootDir);
|
|
207
|
+
jsFiles.sort();
|
|
208
|
+
mapFiles.sort();
|
|
209
|
+
return { jsFiles, mapFiles };
|
|
210
|
+
}
|
|
211
|
+
function resetBundleDir(tmpDir) {
|
|
212
|
+
fs_1.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
213
|
+
fs_1.default.mkdirSync(tmpDir, { recursive: true });
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Inject __dirname/__filename polyfill into specific chunks that use
|
|
217
|
+
* those globals. Returns the list of files that were injected.
|
|
218
|
+
*
|
|
219
|
+
* This replaces the old single-chunk fallback: instead of abandoning
|
|
220
|
+
* code-splitting when any chunk uses __dirname, we inject the polyfill
|
|
221
|
+
* into only the chunks that need it.
|
|
222
|
+
*/
|
|
223
|
+
function injectPathGlobalsPerChunk(jsFiles) {
|
|
224
|
+
const injected = [];
|
|
225
|
+
for (const file of jsFiles) {
|
|
226
|
+
const globals = findUnsafeNodePathGlobals(file);
|
|
227
|
+
if (globals.length > 0) {
|
|
228
|
+
injectPolyfillIntoFile(file);
|
|
229
|
+
injected.push(file);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return injected;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Prepend the __dirname/__filename polyfill to a JS file.
|
|
236
|
+
* Inserts after the CHUNK_BANNER (import statements) if present.
|
|
237
|
+
*/
|
|
238
|
+
function injectPolyfillIntoFile(filePath) {
|
|
239
|
+
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
240
|
+
// The banner is at the top of the file. Insert the polyfill right after it.
|
|
241
|
+
// The banner ends with the last import statement's semicolon.
|
|
242
|
+
const bannerEnd = code.indexOf(`from'node:path';`);
|
|
243
|
+
if (bannerEnd >= 0) {
|
|
244
|
+
const insertPos = bannerEnd + `from'node:path';`.length;
|
|
245
|
+
const patched = code.slice(0, insertPos) + PATH_GLOBALS_POLYFILL + code.slice(insertPos);
|
|
246
|
+
fs_1.default.writeFileSync(filePath, patched);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// No banner found — prepend the full polyfill with imports
|
|
250
|
+
fs_1.default.writeFileSync(filePath, CHUNK_BANNER + PATH_GLOBALS_POLYFILL + code);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function detectSingleChunkFallback(jsFiles) {
|
|
254
|
+
for (const file of jsFiles) {
|
|
255
|
+
const globals = findUnsafeNodePathGlobals(file);
|
|
256
|
+
if (globals.length > 0) {
|
|
257
|
+
return `${path_1.default.relative(path_1.default.dirname(file), file)} requires ${globals.join('/')} globals`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
function findUnsafeNodePathGlobals(filePath) {
|
|
263
|
+
const code = fs_1.default.readFileSync(filePath, 'utf8');
|
|
264
|
+
const ast = (0, parser_1.parse)(code, {
|
|
265
|
+
sourceType: 'module',
|
|
266
|
+
plugins: ['importMeta', 'topLevelAwait'],
|
|
267
|
+
});
|
|
268
|
+
const found = new Set();
|
|
269
|
+
(0, traverse_1.default)(ast, {
|
|
270
|
+
Identifier(p) {
|
|
271
|
+
const name = p.node.name;
|
|
272
|
+
if (name !== '__dirname' && name !== '__filename')
|
|
273
|
+
return;
|
|
274
|
+
if (!p.isReferencedIdentifier())
|
|
275
|
+
return;
|
|
276
|
+
if (p.scope.hasBinding(name))
|
|
277
|
+
return;
|
|
278
|
+
found.add(name);
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
return Array.from(found);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Analyze bundle warnings and post-bundle state to produce actionable
|
|
285
|
+
* diagnostics for the user.
|
|
286
|
+
*
|
|
287
|
+
* Classifies Rolldown warnings into categories and suggests concrete
|
|
288
|
+
* actions (externalization, patch rules, etc.) where appropriate.
|
|
289
|
+
*/
|
|
290
|
+
function analyzeBundleDiagnostics(warnings, writeResult, appliedPatches, userExternals) {
|
|
291
|
+
const diagnostics = [];
|
|
292
|
+
// ── Classify warnings ──
|
|
293
|
+
const unresolvedImports = [];
|
|
294
|
+
const dynamicImports = [];
|
|
295
|
+
const otherWarnings = [];
|
|
296
|
+
for (const w of warnings) {
|
|
297
|
+
const msg = w.message;
|
|
298
|
+
if (/unresolved|not found|Could not resolve/i.test(msg)) {
|
|
299
|
+
// Extract package name from common warning formats
|
|
300
|
+
const pkgMatch = msg.match(/['"]([^'"]+)['"]/);
|
|
301
|
+
if (pkgMatch)
|
|
302
|
+
unresolvedImports.push(pkgMatch[1]);
|
|
303
|
+
}
|
|
304
|
+
else if (/dynamic/i.test(msg) && /import/i.test(msg)) {
|
|
305
|
+
dynamicImports.push(w.file ? path_1.default.basename(w.file) : 'unknown');
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
otherWarnings.push(msg);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Deduplicate
|
|
312
|
+
const uniqueUnresolved = [...new Set(unresolvedImports)];
|
|
313
|
+
const uniqueDynamic = [...new Set(dynamicImports)];
|
|
314
|
+
// ── Unresolved imports ──
|
|
315
|
+
if (uniqueUnresolved.length > 0) {
|
|
316
|
+
// Separate bun:* and other runtime-specific from real missing packages
|
|
317
|
+
const runtimeSpecific = uniqueUnresolved.filter(p => p.startsWith('bun:') || p.startsWith('deno:'));
|
|
318
|
+
const realMissing = uniqueUnresolved.filter(p => !p.startsWith('bun:') && !p.startsWith('deno:') && !p.startsWith('node:'));
|
|
319
|
+
if (runtimeSpecific.length > 0) {
|
|
320
|
+
diagnostics.push({
|
|
321
|
+
severity: 'info',
|
|
322
|
+
message: `[bundle] Runtime-specific imports skipped: ${runtimeSpecific.join(', ')} (stubbed at runtime)`,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (realMissing.length > 0) {
|
|
326
|
+
diagnostics.push({
|
|
327
|
+
severity: 'warn',
|
|
328
|
+
message: `[bundle] Unresolved packages: ${realMissing.join(', ')}. ` +
|
|
329
|
+
`If these are optional, use --external ${realMissing.map(p => `"${p}"`).join(' --external ')}`,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// ── Dynamic imports ──
|
|
334
|
+
if (uniqueDynamic.length > 0) {
|
|
335
|
+
diagnostics.push({
|
|
336
|
+
severity: 'warn',
|
|
337
|
+
message: `[bundle] Dynamic import() with variable arguments in ${uniqueDynamic.length} location(s). ` +
|
|
338
|
+
`Hakobu cannot trace these statically — the imported modules must be available at runtime.`,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// ── Applied patches summary ──
|
|
342
|
+
if (appliedPatches.length > 0) {
|
|
343
|
+
const scopes = [...new Set(appliedPatches.map(p => p.split(':')[0].trim()))];
|
|
344
|
+
diagnostics.push({
|
|
345
|
+
severity: 'info',
|
|
346
|
+
message: `[bundle] Compatibility patches applied for: ${scopes.join(', ')} (handled automatically)`,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// ── Per-chunk injection summary ──
|
|
350
|
+
if (writeResult.injectedChunks && writeResult.injectedChunks.length > 0) {
|
|
351
|
+
diagnostics.push({
|
|
352
|
+
severity: 'info',
|
|
353
|
+
message: `[bundle] __dirname/__filename polyfill injected into: ${writeResult.injectedChunks.join(', ')} (CJS-origin code)`,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
// ── Other unclassified warnings ──
|
|
357
|
+
for (const msg of otherWarnings) {
|
|
358
|
+
diagnostics.push({
|
|
359
|
+
severity: 'warn',
|
|
360
|
+
message: `[bundle] ${msg}`,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
// ── Summary line ──
|
|
364
|
+
const issueCount = diagnostics.filter(d => d.severity === 'warn').length;
|
|
365
|
+
if (issueCount === 0 && diagnostics.length > 0) {
|
|
366
|
+
diagnostics.push({
|
|
367
|
+
severity: 'info',
|
|
368
|
+
message: `[bundle] All detected patterns handled — no user action needed`,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return diagnostics;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Registry of known bundler-hostile patterns and their fixes.
|
|
375
|
+
*
|
|
376
|
+
* These packages use runtime introspection patterns (require.resolve to
|
|
377
|
+
* their own package.json, dirname-based path discovery, etc.) that produce
|
|
378
|
+
* build-time absolute paths after bundling. The paths don't exist at runtime
|
|
379
|
+
* in a packaged executable, so we replace them with safe stubs.
|
|
380
|
+
*
|
|
381
|
+
* Order matters: dirname(resolve(...)) rules must come before resolve(...)
|
|
382
|
+
* rules, because the latter is a substring of the former.
|
|
383
|
+
*
|
|
384
|
+
* To add a new package: append rules to the array below. Each rule is
|
|
385
|
+
* independent and self-documenting.
|
|
386
|
+
*/
|
|
387
|
+
const BUNDLE_PATCH_RULES = [
|
|
388
|
+
// ── playwright-core ──
|
|
389
|
+
// Playwright resolves its own package.json at runtime to find its
|
|
390
|
+
// installation directory. After bundling, these become absolute build-time
|
|
391
|
+
// paths that don't exist in the packaged snapshot.
|
|
392
|
+
{
|
|
393
|
+
name: 'dirname(resolve(playwright/package.json))',
|
|
394
|
+
scope: 'playwright-core',
|
|
395
|
+
pattern: /(?:dirname|_hk_d)\(\s*(?:__require\.resolve|require\.resolve)\(\s*"[^"]*playwright[^"]*package\.json"\s*\)\s*\)/g,
|
|
396
|
+
replacement: 'process.cwd()',
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
name: 'resolve(playwright/package.json)',
|
|
400
|
+
scope: 'playwright-core',
|
|
401
|
+
pattern: /(?:__require\.resolve|require\.resolve)\(\s*"[^"]*playwright[^"]*package\.json"\s*\)/g,
|
|
402
|
+
replacement: '"playwright-core-stub"',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
name: 'require(playwright/package.json)',
|
|
406
|
+
scope: 'playwright-core',
|
|
407
|
+
pattern: /(?:__require|require)\(\s*"[^"]*playwright[^"]*package\.json"\s*\)/g,
|
|
408
|
+
replacement: '({name:"playwright-core",version:"0.0.0"})',
|
|
409
|
+
},
|
|
410
|
+
// ── Generic: relative package.json traversals ──
|
|
411
|
+
// Many packages use dirname(require.resolve('../../package.json')) to find
|
|
412
|
+
// their own root. After bundling, relative paths resolve to the bundler's
|
|
413
|
+
// working directory at build time, not the runtime location.
|
|
414
|
+
{
|
|
415
|
+
name: 'dirname(resolve(../package.json))',
|
|
416
|
+
scope: 'relative-package-json',
|
|
417
|
+
pattern: /[\w$.]+\.dirname\(\s*(?:__require\.resolve|require\.resolve)\(\s*"(?:\.\.\/)+package\.json"\s*\)\s*\)/g,
|
|
418
|
+
replacement: 'process.cwd()',
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: 'resolve(../package.json)',
|
|
422
|
+
scope: 'relative-package-json',
|
|
423
|
+
pattern: /(?:__require\.resolve|require\.resolve)\(\s*"(?:\.\.\/)+package\.json"\s*\)/g,
|
|
424
|
+
replacement: '"package-json-stub"',
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: 'require(../package.json)',
|
|
428
|
+
scope: 'relative-package-json',
|
|
429
|
+
pattern: /(?:__require|require)\(\s*"(?:\.\.\/)+package\.json"\s*\)/g,
|
|
430
|
+
replacement: '({name:"unknown",version:"0.0.0"})',
|
|
431
|
+
},
|
|
432
|
+
];
|
|
433
|
+
/**
|
|
434
|
+
* Apply all bundle compatibility patches to a file.
|
|
435
|
+
* Returns the list of rules that matched (for diagnostics).
|
|
436
|
+
*/
|
|
437
|
+
function applyBundlePatches(filePath) {
|
|
438
|
+
const original = fs_1.default.readFileSync(filePath, 'utf8');
|
|
439
|
+
let code = original;
|
|
440
|
+
const applied = [];
|
|
441
|
+
for (const rule of BUNDLE_PATCH_RULES) {
|
|
442
|
+
const before = code;
|
|
443
|
+
code = code.replace(rule.pattern, rule.replacement);
|
|
444
|
+
if (code !== before) {
|
|
445
|
+
applied.push(`${rule.scope}: ${rule.name}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (code !== original) {
|
|
449
|
+
fs_1.default.writeFileSync(filePath, code);
|
|
450
|
+
for (const desc of applied) {
|
|
451
|
+
log_1.log.info(` patched: ${desc}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return applied;
|
|
455
|
+
}
|
|
456
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
457
|
+
// Rolldown loader (handles ESM-only package from CJS context)
|
|
458
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
459
|
+
let _rolldownCache = null;
|
|
460
|
+
async function loadRolldown() {
|
|
461
|
+
if (_rolldownCache)
|
|
462
|
+
return _rolldownCache;
|
|
463
|
+
const { pathToFileURL } = require('url');
|
|
464
|
+
// rolldown is ESM-only, so we need dynamic import with a file:// URL
|
|
465
|
+
// (bare paths fail on Windows where import() expects URL format)
|
|
466
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
467
|
+
// Try to find rolldown in the local node_modules first
|
|
468
|
+
const localPath = path_1.default.resolve(__dirname, '../node_modules/rolldown/dist/index.mjs');
|
|
469
|
+
if (fs_1.default.existsSync(localPath)) {
|
|
470
|
+
_rolldownCache = await dynamicImport(pathToFileURL(localPath).href);
|
|
471
|
+
return _rolldownCache;
|
|
472
|
+
}
|
|
473
|
+
// Fallback: try bare specifier (might work if hoisted)
|
|
474
|
+
try {
|
|
475
|
+
_rolldownCache = await dynamicImport('rolldown');
|
|
476
|
+
return _rolldownCache;
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
throw new Error('rolldown not found');
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
483
|
+
// Adapter registry
|
|
484
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
485
|
+
const adapters = {
|
|
486
|
+
rolldown: () => new RolldownAdapter(),
|
|
487
|
+
};
|
|
488
|
+
function getAdapter(name) {
|
|
489
|
+
const factory = adapters[name];
|
|
490
|
+
if (!factory) {
|
|
491
|
+
throw new Error(`Unknown bundler: ${name}. Available: ${Object.keys(adapters).join(', ')}`);
|
|
492
|
+
}
|
|
493
|
+
return factory();
|
|
494
|
+
}
|
|
495
|
+
exports.getAdapter = getAdapter;
|
|
496
|
+
//# sourceMappingURL=bundler.js.map
|
package/lib-es5/chmod.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plusx = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
async function plusx(file) {
|
|
6
|
+
const s = await (0, promises_1.stat)(file);
|
|
7
|
+
const newMode = s.mode | 64 | 8 | 1;
|
|
8
|
+
if (s.mode === newMode) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const base8 = newMode.toString(8).slice(-3);
|
|
12
|
+
await (0, promises_1.chmod)(file, base8);
|
|
13
|
+
}
|
|
14
|
+
exports.plusx = plusx;
|
|
15
|
+
//# sourceMappingURL=chmod.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pc = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
|
+
const tty_1 = require("tty");
|
|
9
|
+
// makes color detection more accurate using node's own API for it
|
|
10
|
+
// https://github.com/alexeyraspopov/picocolors/issues/85
|
|
11
|
+
exports.pc = picocolors_1.default.createColors(tty_1.WriteStream.prototype.hasColors());
|
|
12
|
+
//# sourceMappingURL=colors.js.map
|