@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.
Files changed (284) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +673 -0
  3. package/dictionary/angular-bridge.js +3 -0
  4. package/dictionary/any-promise.js +3 -0
  5. package/dictionary/async.js +3 -0
  6. package/dictionary/aws-sdk.js +7 -0
  7. package/dictionary/babel-core.js +3 -0
  8. package/dictionary/batch.js +3 -0
  9. package/dictionary/bcrypt.js +3 -0
  10. package/dictionary/better-sqlite3.js +3 -0
  11. package/dictionary/bignum.js +3 -0
  12. package/dictionary/bindings.js +3 -0
  13. package/dictionary/blessed.js +8 -0
  14. package/dictionary/body-parser.js +9 -0
  15. package/dictionary/browserify.js +7 -0
  16. package/dictionary/bson.js +3 -0
  17. package/dictionary/buffermaker.js +7 -0
  18. package/dictionary/bunyan.js +9 -0
  19. package/dictionary/busboy.js +7 -0
  20. package/dictionary/bytes.js +3 -0
  21. package/dictionary/callsites.js +3 -0
  22. package/dictionary/chokidar.js +3 -0
  23. package/dictionary/coffee-script.js +7 -0
  24. package/dictionary/colors.js +3 -0
  25. package/dictionary/compression.js +3 -0
  26. package/dictionary/compressjs.js +7 -0
  27. package/dictionary/connect-mongo.js +3 -0
  28. package/dictionary/connect-mongodb.js +3 -0
  29. package/dictionary/connect-redis.js +3 -0
  30. package/dictionary/connect.js +10 -0
  31. package/dictionary/consolidate.js +3 -0
  32. package/dictionary/cookie-parser.js +3 -0
  33. package/dictionary/cookie.js +3 -0
  34. package/dictionary/cors.js +3 -0
  35. package/dictionary/cron.js +3 -0
  36. package/dictionary/cross-env.js +11 -0
  37. package/dictionary/cross-spawn-async.js +3 -0
  38. package/dictionary/curve25519.js +3 -0
  39. package/dictionary/data-preflight.js +7 -0
  40. package/dictionary/debug.js +3 -0
  41. package/dictionary/denymount.js +3 -0
  42. package/dictionary/diff.js +3 -0
  43. package/dictionary/drivelist.js +22 -0
  44. package/dictionary/ed25519.js +3 -0
  45. package/dictionary/ejs.js +3 -0
  46. package/dictionary/elasticsearch.js +3 -0
  47. package/dictionary/electron.js +17 -0
  48. package/dictionary/emailjs.js +3 -0
  49. package/dictionary/engine.io.js +3 -0
  50. package/dictionary/epoll.js +3 -0
  51. package/dictionary/errorhandler.js +7 -0
  52. package/dictionary/errors.js +7 -0
  53. package/dictionary/eslint.js +7 -0
  54. package/dictionary/etcher-image-write.js +3 -0
  55. package/dictionary/exceljs.js +21 -0
  56. package/dictionary/exiftool.exe.js +13 -0
  57. package/dictionary/exiftool.pl.js +13 -0
  58. package/dictionary/express-load.js +12 -0
  59. package/dictionary/express-session.js +3 -0
  60. package/dictionary/express.js +14 -0
  61. package/dictionary/extender.js +11 -0
  62. package/dictionary/extsprintf.js +3 -0
  63. package/dictionary/faye-websocket.js +3 -0
  64. package/dictionary/feathers.js +3 -0
  65. package/dictionary/findup-sync.js +3 -0
  66. package/dictionary/floordate.js +3 -0
  67. package/dictionary/fmt.js +3 -0
  68. package/dictionary/formidable.js +3 -0
  69. package/dictionary/fs-extra.js +3 -0
  70. package/dictionary/fsevents.js +3 -0
  71. package/dictionary/geoip-lite.js +7 -0
  72. package/dictionary/github.js +7 -0
  73. package/dictionary/gm.js +3 -0
  74. package/dictionary/google-closure-compiler-java.js +13 -0
  75. package/dictionary/google-closure-compiler.js +13 -0
  76. package/dictionary/googleapis.js +7 -0
  77. package/dictionary/got.js +3 -0
  78. package/dictionary/graceful-fs.js +19 -0
  79. package/dictionary/grpc.js +11 -0
  80. package/dictionary/gulp.js +3 -0
  81. package/dictionary/hap-nodejs.js +3 -0
  82. package/dictionary/heapdump.js +3 -0
  83. package/dictionary/hoek.js +3 -0
  84. package/dictionary/homebridge.js +3 -0
  85. package/dictionary/http-proxy.js +3 -0
  86. package/dictionary/http-server.js +3 -0
  87. package/dictionary/image-size.js +3 -0
  88. package/dictionary/indexof.js +3 -0
  89. package/dictionary/inquirer.js +3 -0
  90. package/dictionary/j.js +16 -0
  91. package/dictionary/jade.js +3 -0
  92. package/dictionary/jsdom.js +3 -0
  93. package/dictionary/json-stringify-date.js +3 -0
  94. package/dictionary/json-stringify-safe.js +3 -0
  95. package/dictionary/jsonwebtoken.js +3 -0
  96. package/dictionary/kerberos.js +3 -0
  97. package/dictionary/knex.js +7 -0
  98. package/dictionary/later.js +7 -0
  99. package/dictionary/level.js +3 -0
  100. package/dictionary/leveldown.js +10 -0
  101. package/dictionary/levelup.js +3 -0
  102. package/dictionary/liftoff.js +12 -0
  103. package/dictionary/lodash.js +3 -0
  104. package/dictionary/log4js.js +7 -0
  105. package/dictionary/logform.js +7 -0
  106. package/dictionary/machinepack-urls.js +7 -0
  107. package/dictionary/markdown.js +3 -0
  108. package/dictionary/mdns.js +6 -0
  109. package/dictionary/method-override.js +3 -0
  110. package/dictionary/microjob.js +16 -0
  111. package/dictionary/mime-types.js +3 -0
  112. package/dictionary/mime.js +3 -0
  113. package/dictionary/minimatch.js +3 -0
  114. package/dictionary/minstache.js +3 -0
  115. package/dictionary/module-deps.js +3 -0
  116. package/dictionary/moment-timezone.js +3 -0
  117. package/dictionary/moment.js +7 -0
  118. package/dictionary/mongodb-core.js +22 -0
  119. package/dictionary/mongodb.js +7 -0
  120. package/dictionary/mongoose.js +7 -0
  121. package/dictionary/mongoskin.js +7 -0
  122. package/dictionary/ms.js +3 -0
  123. package/dictionary/msgpack.js +3 -0
  124. package/dictionary/multer.js +3 -0
  125. package/dictionary/muri.js +3 -0
  126. package/dictionary/native-or-bluebird.js +3 -0
  127. package/dictionary/natives.js +3 -0
  128. package/dictionary/nconf.js +7 -0
  129. package/dictionary/nedb.js +3 -0
  130. package/dictionary/negotiator.js +7 -0
  131. package/dictionary/newrelic.js +3 -0
  132. package/dictionary/nib.js +3 -0
  133. package/dictionary/nightmare.js +18 -0
  134. package/dictionary/node-forge.js +7 -0
  135. package/dictionary/node-libcurl.js +3 -0
  136. package/dictionary/node-notifier.js +30 -0
  137. package/dictionary/node-pre-gyp.js +7 -0
  138. package/dictionary/node-redis-pubsub.js +3 -0
  139. package/dictionary/node-sass.js +3 -0
  140. package/dictionary/node-uuid.js +3 -0
  141. package/dictionary/node-xlsx.js +3 -0
  142. package/dictionary/node-zookeeper-client.js +7 -0
  143. package/dictionary/nodegit.js +7 -0
  144. package/dictionary/nodemailer-sendmail-transport.js +3 -0
  145. package/dictionary/nodemailer.js +3 -0
  146. package/dictionary/npm-registry-client.js +7 -0
  147. package/dictionary/npm.js +7 -0
  148. package/dictionary/nssocket.js +3 -0
  149. package/dictionary/oauth2orize.js +7 -0
  150. package/dictionary/octobat.js +3 -0
  151. package/dictionary/open.js +13 -0
  152. package/dictionary/opn.js +4 -0
  153. package/dictionary/optimist.js +3 -0
  154. package/dictionary/passport-local.js +3 -0
  155. package/dictionary/passport.js +3 -0
  156. package/dictionary/pg-cursor.js +3 -0
  157. package/dictionary/pg-query-stream.js +3 -0
  158. package/dictionary/pg-types.js +7 -0
  159. package/dictionary/pg.js +7 -0
  160. package/dictionary/pg.js.js +7 -0
  161. package/dictionary/pgpass.js +7 -0
  162. package/dictionary/phantom.js +19 -0
  163. package/dictionary/phantomjs-prebuilt.js +16 -0
  164. package/dictionary/pkginfo.js +3 -0
  165. package/dictionary/pm2.js +7 -0
  166. package/dictionary/pmx.js +3 -0
  167. package/dictionary/pouchdb.js +3 -0
  168. package/dictionary/primus-emitter.js +3 -0
  169. package/dictionary/primus-spark-latency.js +3 -0
  170. package/dictionary/primus.js +3 -0
  171. package/dictionary/publicsuffixlist.js +15 -0
  172. package/dictionary/pug.js +3 -0
  173. package/dictionary/punt.js +3 -0
  174. package/dictionary/puppeteer.js +13 -0
  175. package/dictionary/pwd.js +3 -0
  176. package/dictionary/q.js +3 -0
  177. package/dictionary/raven.js +3 -0
  178. package/dictionary/rc.js +12 -0
  179. package/dictionary/readable-stream.js +3 -0
  180. package/dictionary/rechoir.js +3 -0
  181. package/dictionary/redis-parser.js +3 -0
  182. package/dictionary/redis.js +3 -0
  183. package/dictionary/regression.js +3 -0
  184. package/dictionary/reload.js +7 -0
  185. package/dictionary/request.js +3 -0
  186. package/dictionary/require-uncached.js +3 -0
  187. package/dictionary/require_optional.js +3 -0
  188. package/dictionary/s3.js +3 -0
  189. package/dictionary/safe_datejs.js +3 -0
  190. package/dictionary/sails.js +33 -0
  191. package/dictionary/sax.js +3 -0
  192. package/dictionary/scrypt.js +3 -0
  193. package/dictionary/semver.js +3 -0
  194. package/dictionary/sequelize.js +7 -0
  195. package/dictionary/serialport.js +3 -0
  196. package/dictionary/sha3.js +3 -0
  197. package/dictionary/sharp.js +11 -0
  198. package/dictionary/shelljs.js +7 -0
  199. package/dictionary/sinon.js +3 -0
  200. package/dictionary/socket.io-client.js +13 -0
  201. package/dictionary/socket.io.js +12 -0
  202. package/dictionary/sqip.js +7 -0
  203. package/dictionary/sqlite3.js +7 -0
  204. package/dictionary/steam-crypto.js +7 -0
  205. package/dictionary/steam-resources.js +19 -0
  206. package/dictionary/steam.js +3 -0
  207. package/dictionary/stripe-webhook-middleware.js +3 -0
  208. package/dictionary/stripe.js +3 -0
  209. package/dictionary/strong-globalize.js +3 -0
  210. package/dictionary/stylus.js +14 -0
  211. package/dictionary/supervisor.js +3 -0
  212. package/dictionary/svgo.js +8 -0
  213. package/dictionary/tabtab.js +3 -0
  214. package/dictionary/tesseract.js.js +7 -0
  215. package/dictionary/thread-stream.js +7 -0
  216. package/dictionary/throng.js +3 -0
  217. package/dictionary/time.js +3 -0
  218. package/dictionary/tinify.js +7 -0
  219. package/dictionary/tiny-worker.js +7 -0
  220. package/dictionary/tmp.js +3 -0
  221. package/dictionary/transformers.js +3 -0
  222. package/dictionary/uglify-js.js +9 -0
  223. package/dictionary/umd.js +19 -0
  224. package/dictionary/underscore.js +3 -0
  225. package/dictionary/union.js +3 -0
  226. package/dictionary/update-notifier.js +3 -0
  227. package/dictionary/usage.js +7 -0
  228. package/dictionary/v8flags.js +13 -0
  229. package/dictionary/verror.js +3 -0
  230. package/dictionary/voc.js +3 -0
  231. package/dictionary/webdriverio.js +7 -0
  232. package/dictionary/winston-uber.js +7 -0
  233. package/dictionary/winston.js +7 -0
  234. package/dictionary/ws.js +3 -0
  235. package/dictionary/xlsx.js +16 -0
  236. package/dictionary/xml2js.js +3 -0
  237. package/dictionary/yargs.js +3 -0
  238. package/dictionary/zeromq.js +13 -0
  239. package/lib-es5/addon-extract.js +164 -0
  240. package/lib-es5/analyzer.js +687 -0
  241. package/lib-es5/app-bundle.js +133 -0
  242. package/lib-es5/appdir.js +265 -0
  243. package/lib-es5/bin.js +304 -0
  244. package/lib-es5/bootstrap.js +179 -0
  245. package/lib-es5/bundler.js +496 -0
  246. package/lib-es5/chmod.js +15 -0
  247. package/lib-es5/colors.js +12 -0
  248. package/lib-es5/commands.js +376 -0
  249. package/lib-es5/common.js +328 -0
  250. package/lib-es5/compress_type.js +10 -0
  251. package/lib-es5/config.js +291 -0
  252. package/lib-es5/detector.js +421 -0
  253. package/lib-es5/esm-hooks.js +366 -0
  254. package/lib-es5/esm-resolver.js +292 -0
  255. package/lib-es5/esm-transformer.js +378 -0
  256. package/lib-es5/exports-resolver.js +184 -0
  257. package/lib-es5/external-artifacts.js +170 -0
  258. package/lib-es5/fabricator.js +137 -0
  259. package/lib-es5/follow.js +190 -0
  260. package/lib-es5/help.js +52 -0
  261. package/lib-es5/index.d.ts +2 -0
  262. package/lib-es5/index.js +552 -0
  263. package/lib-es5/log.js +7 -0
  264. package/lib-es5/mach-o.js +262 -0
  265. package/lib-es5/manifest.js +21 -0
  266. package/lib-es5/options.js +19 -0
  267. package/lib-es5/packager.js +1036 -0
  268. package/lib-es5/packer.js +137 -0
  269. package/lib-es5/pe-metadata.js +130 -0
  270. package/lib-es5/producer.js +378 -0
  271. package/lib-es5/refiner.js +87 -0
  272. package/lib-es5/resolver.js +142 -0
  273. package/lib-es5/runtime-diagnostics.js +172 -0
  274. package/lib-es5/sea.js +307 -0
  275. package/lib-es5/snapshot-fs-patch.js +396 -0
  276. package/lib-es5/snapshot-fs.js +255 -0
  277. package/lib-es5/snapshot-index.js +135 -0
  278. package/lib-es5/snapshot-path.js +168 -0
  279. package/lib-es5/types.js +9 -0
  280. package/lib-es5/walker.js +1019 -0
  281. package/lib-es5/windows-sign.js +139 -0
  282. package/package.json +99 -0
  283. package/prelude/bootstrap.js +2263 -0
  284. package/prelude/diagnostic.js +147 -0
@@ -0,0 +1,1019 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const assert_1 = __importDefault(require("assert"));
30
+ const promises_1 = __importDefault(require("fs/promises"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const module_1 = __importStar(require("module"));
33
+ const picomatch_1 = __importDefault(require("picomatch"));
34
+ const tinyglobby_1 = require("tinyglobby");
35
+ const common_1 = require("./common");
36
+ const colors_1 = require("./colors");
37
+ const follow_1 = require("./follow");
38
+ const log_1 = require("./log");
39
+ const detector = __importStar(require("./detector"));
40
+ const esm_transformer_1 = require("./esm-transformer");
41
+ const options_1 = __importDefault(require("./options"));
42
+ // Note: as a developer, you can set the PKG_STRICT_VER variable.
43
+ // this will turn on some assertion in the walker code below
44
+ // to assert that each file content/state that we appending
45
+ // to the virtual file system applies to a real file,
46
+ // not a symlink.
47
+ // By default assertion are disabled as they can have a
48
+ // performance hit.
49
+ const strictVerify = Boolean(process.env.PKG_STRICT_VER);
50
+ const win32 = process.platform === 'win32';
51
+ // Extensions to try when resolving modules
52
+ // Includes .mjs to support ESM files that get transformed to .js
53
+ const MODULE_RESOLVE_EXTENSIONS = ['.js', '.json', '.node', '.mjs'];
54
+ /**
55
+ * Checks if a module is a core module
56
+ * module.isBuiltin is available in Node.js 16.17.0 or later. Use that if available
57
+ * as prefix-only modules (those starting with 'node:') can only be checked that way.
58
+ */
59
+ function isBuiltin(moduleName) {
60
+ if (Reflect.has(module_1.default, 'isBuiltin') &&
61
+ typeof module_1.default.isBuiltin === 'function') {
62
+ return module_1.default.isBuiltin(moduleName);
63
+ }
64
+ const moduleNameWithoutPrefix = moduleName.startsWith('node:')
65
+ ? moduleName.slice(5)
66
+ : moduleName;
67
+ return module_1.builtinModules.includes(moduleNameWithoutPrefix);
68
+ }
69
+ function isPublic(config) {
70
+ if (config.private) {
71
+ return false;
72
+ }
73
+ const { licenses } = config;
74
+ let { license } = config;
75
+ if (licenses) {
76
+ license = licenses;
77
+ }
78
+ if (license && !Array.isArray(license)) {
79
+ license = typeof license === 'string' ? license : license.type;
80
+ }
81
+ if (Array.isArray(license)) {
82
+ license = license.map((c) => String(c.type || c)).join(',');
83
+ }
84
+ if (!license) {
85
+ return false;
86
+ }
87
+ if (/^\(/.test(license)) {
88
+ license = license.slice(1);
89
+ }
90
+ if (/\)$/.test(license)) {
91
+ license = license.slice(0, -1);
92
+ }
93
+ license = license.toLowerCase();
94
+ const allLicenses = Array.prototype.concat(license.split(' or '), license.split(' and '), license.split('/'), license.split(','));
95
+ let result = false;
96
+ const foss = [
97
+ 'isc',
98
+ 'mit',
99
+ 'apache-2.0',
100
+ 'apache 2.0',
101
+ 'public domain',
102
+ 'bsd',
103
+ 'bsd-2-clause',
104
+ 'bsd-3-clause',
105
+ 'wtfpl',
106
+ 'cc-by-3.0',
107
+ 'x11',
108
+ 'artistic-2.0',
109
+ 'gplv3',
110
+ 'mpl',
111
+ 'mplv2.0',
112
+ 'unlicense',
113
+ 'apache license 2.0',
114
+ 'zlib',
115
+ 'mpl-2.0',
116
+ 'nasa-1.3',
117
+ 'apache license, version 2.0',
118
+ 'lgpl-2.1+',
119
+ 'cc0-1.0',
120
+ ];
121
+ for (const c of allLicenses) {
122
+ result = foss.indexOf(c) >= 0;
123
+ if (result) {
124
+ break;
125
+ }
126
+ }
127
+ return result;
128
+ }
129
+ function upon(p, base) {
130
+ if (typeof p !== 'string') {
131
+ throw (0, log_1.wasReported)('Config items must be strings. See examples');
132
+ }
133
+ let negate = false;
134
+ if (p[0] === '!') {
135
+ p = p.slice(1);
136
+ negate = true;
137
+ }
138
+ p = path_1.default.join(base, p);
139
+ if (win32) {
140
+ p = p.replace(/\\/g, '/');
141
+ }
142
+ if (negate) {
143
+ p = `!${p}`;
144
+ }
145
+ return p;
146
+ }
147
+ function collect(ps) {
148
+ return (0, tinyglobby_1.globSync)(ps, { absolute: true, dot: true });
149
+ }
150
+ function expandFiles(efs, base) {
151
+ if (!Array.isArray(efs)) {
152
+ efs = [efs];
153
+ }
154
+ efs = collect(efs.map((p) => upon(p, base)));
155
+ return efs;
156
+ }
157
+ async function stepRead(record) {
158
+ if (strictVerify) {
159
+ (0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file));
160
+ }
161
+ let body;
162
+ try {
163
+ body = await promises_1.default.readFile(record.file);
164
+ }
165
+ catch (error) {
166
+ const exception = error;
167
+ log_1.log.error(`Cannot read file, ${exception.code}`, record.file);
168
+ throw (0, log_1.wasReported)(exception.message);
169
+ }
170
+ record.body = body;
171
+ }
172
+ function stepStrip(record) {
173
+ let body = (record.body || '').toString('utf8');
174
+ if (/^\ufeff/.test(body)) {
175
+ body = body.replace(/^\ufeff/, '');
176
+ }
177
+ if (/^#!/.test(body)) {
178
+ body = body.replace(/^#![^\n]*\n/, '\n');
179
+ }
180
+ record.body = body;
181
+ }
182
+ function stepDetect(record, marker, derivatives) {
183
+ let { body = '' } = record;
184
+ if (body instanceof Buffer) {
185
+ body = body.toString();
186
+ }
187
+ try {
188
+ detector.detect(body, (node, trying) => {
189
+ const { toplevel } = marker;
190
+ let d = detector.visitorSuccessful(node);
191
+ if (d) {
192
+ if (d.mustExclude) {
193
+ return false;
194
+ }
195
+ d.mayExclude = d.mayExclude || trying;
196
+ derivatives.push(d);
197
+ return false;
198
+ }
199
+ d = detector.visitorNonLiteral(node);
200
+ if (d) {
201
+ if (typeof d === 'object' && d.mustExclude) {
202
+ return false;
203
+ }
204
+ const debug = !toplevel || d.mayExclude || trying;
205
+ const level = debug ? 'debug' : 'warn';
206
+ log_1.log[level](`Cannot resolve '${d.alias}'`, [
207
+ record.file,
208
+ 'Dynamic require may fail at run time, because the requested file',
209
+ 'is unknown at compilation time and not included into executable.',
210
+ "Use a string literal as an argument for 'require', or leave it",
211
+ "as is and specify the resolved file name in 'scripts' option.",
212
+ ]);
213
+ return false;
214
+ }
215
+ d = detector.visitorMalformed(node);
216
+ if (d) {
217
+ // there is no 'mustExclude'
218
+ const debug = !toplevel || trying;
219
+ const level = debug ? 'debug' : 'warn'; // there is no 'mayExclude'
220
+ log_1.log[level](`Malformed requirement for '${d.alias}'`, [record.file]);
221
+ return false;
222
+ }
223
+ d = detector.visitorUseSCWD(node);
224
+ if (d) {
225
+ // there is no 'mustExclude'
226
+ const level = 'debug'; // there is no 'mayExclude'
227
+ log_1.log[level](`Path.resolve(${d.alias}) is ambiguous`, [
228
+ record.file,
229
+ "It resolves relatively to 'process.cwd' by default, however",
230
+ "you may want to use 'path.dirname(require.main.filename)'",
231
+ ]);
232
+ return false;
233
+ }
234
+ return true; // can i go inside?
235
+ }, record.file);
236
+ }
237
+ catch (error) {
238
+ log_1.log.error(error.message, record.file);
239
+ throw (0, log_1.wasReported)(error.message);
240
+ }
241
+ }
242
+ /**
243
+ * Find a common junction point between a symlink and the real file path.
244
+ *
245
+ * @param {string} file The file path, including symlink(s).
246
+ * @param {string} realFile The real path to the file.
247
+ *
248
+ * @throws {Error} If no common junction point is found prior to hitting the
249
+ * filesystem root.
250
+ */
251
+ async function findCommonJunctionPoint(file, realFile) {
252
+ // find common denominator => where the link changes
253
+ while (true) {
254
+ const stats = await promises_1.default.lstat(file);
255
+ if (stats.isSymbolicLink()) {
256
+ return { file, realFile };
257
+ }
258
+ file = path_1.default.dirname(file);
259
+ realFile = path_1.default.dirname(realFile);
260
+ // If the directory is /, break out of the loop and log an error.
261
+ if (file === path_1.default.parse(file).root ||
262
+ realFile === path_1.default.parse(realFile).root) {
263
+ throw new Error('Reached root directory without finding a common junction point');
264
+ }
265
+ }
266
+ }
267
+ class Walker {
268
+ params;
269
+ symLinks;
270
+ patches;
271
+ tasks;
272
+ records;
273
+ dictionary;
274
+ constructor() {
275
+ this.tasks = [];
276
+ this.records = {};
277
+ this.dictionary = {};
278
+ this.patches = {};
279
+ this.params = {};
280
+ this.symLinks = {};
281
+ }
282
+ appendRecord({ file, store }) {
283
+ if (this.records[file]) {
284
+ return;
285
+ }
286
+ if (store === common_1.STORE_BLOB ||
287
+ store === common_1.STORE_CONTENT ||
288
+ store === common_1.STORE_LINKS) {
289
+ // make sure we have a real file
290
+ if (strictVerify) {
291
+ (0, assert_1.default)(file === (0, common_1.toNormalizedRealPath)(file));
292
+ }
293
+ }
294
+ this.records[file] = { file };
295
+ }
296
+ append(task) {
297
+ if (strictVerify) {
298
+ (0, assert_1.default)(typeof task.file === 'string');
299
+ (0, assert_1.default)(task.file === (0, common_1.normalizePath)(task.file));
300
+ }
301
+ this.appendRecord(task);
302
+ this.tasks.push(task);
303
+ const what = {
304
+ [common_1.STORE_BLOB]: 'Bytecode of',
305
+ [common_1.STORE_CONTENT]: 'Content of',
306
+ [common_1.STORE_LINKS]: 'Directory',
307
+ [common_1.STORE_STAT]: 'Stat info of',
308
+ }[task.store];
309
+ if (task.reason) {
310
+ log_1.log.debug(`${what} ${task.file} is added to queue. It was required from ${task.reason}`);
311
+ }
312
+ else {
313
+ log_1.log.debug(`${what} ${task.file} is added to queue.`);
314
+ }
315
+ }
316
+ async appendSymlink(file, realFile) {
317
+ const a = await findCommonJunctionPoint(file, realFile);
318
+ file = a.file;
319
+ realFile = a.realFile;
320
+ if (!this.symLinks[file]) {
321
+ const dn = path_1.default.dirname(file);
322
+ this.appendFileInFolder({
323
+ file: dn,
324
+ store: common_1.STORE_LINKS,
325
+ data: path_1.default.basename(file),
326
+ });
327
+ log_1.log.debug(`adding symlink ${file} => ${path_1.default.relative(file, realFile)}`);
328
+ this.symLinks[file] = realFile;
329
+ this.appendStat({
330
+ file: realFile,
331
+ store: common_1.STORE_STAT,
332
+ });
333
+ this.appendStat({
334
+ file: dn,
335
+ store: common_1.STORE_STAT,
336
+ });
337
+ this.appendStat({
338
+ file,
339
+ store: common_1.STORE_STAT,
340
+ });
341
+ }
342
+ }
343
+ appendStat(task) {
344
+ (0, assert_1.default)(task.store === common_1.STORE_STAT);
345
+ this.append(task);
346
+ }
347
+ appendFileInFolder(task) {
348
+ if (strictVerify) {
349
+ (0, assert_1.default)(task.store === common_1.STORE_LINKS);
350
+ (0, assert_1.default)(typeof task.file === 'string');
351
+ }
352
+ const realFile = (0, common_1.toNormalizedRealPath)(task.file);
353
+ if (realFile === task.file) {
354
+ this.append(task);
355
+ return;
356
+ }
357
+ this.append({ ...task, file: realFile });
358
+ this.appendStat({
359
+ file: task.file,
360
+ store: common_1.STORE_STAT,
361
+ });
362
+ this.appendStat({
363
+ file: path_1.default.dirname(task.file),
364
+ store: common_1.STORE_STAT,
365
+ });
366
+ }
367
+ async appendBlobOrContent(task) {
368
+ if (strictVerify) {
369
+ (0, assert_1.default)(task.file === (0, common_1.normalizePath)(task.file));
370
+ }
371
+ (0, assert_1.default)(task.store === common_1.STORE_BLOB || task.store === common_1.STORE_CONTENT);
372
+ (0, assert_1.default)(typeof task.file === 'string');
373
+ const realFile = (0, common_1.toNormalizedRealPath)(task.file);
374
+ const { ignore } = options_1.default.get();
375
+ if (ignore) {
376
+ // check if the file matches one of the ignore regex patterns
377
+ const match = picomatch_1.default.isMatch(realFile, ignore, {
378
+ windows: win32,
379
+ });
380
+ if (match) {
381
+ log_1.log.debug(`Ignoring file: ${realFile} due to top level config ignore pattern`);
382
+ return;
383
+ }
384
+ }
385
+ if (realFile === task.file) {
386
+ this.append(task);
387
+ return;
388
+ }
389
+ this.append({ ...task, file: realFile });
390
+ await this.appendSymlink(task.file, realFile);
391
+ this.appendStat({
392
+ file: task.file,
393
+ store: common_1.STORE_STAT,
394
+ });
395
+ }
396
+ async appendFilesFromConfig(marker) {
397
+ const { config, configPath, base } = marker;
398
+ const pkgConfig = config?.pkg;
399
+ if (pkgConfig) {
400
+ let { scripts } = pkgConfig;
401
+ if (scripts) {
402
+ scripts = expandFiles(scripts, base);
403
+ for (const script of scripts) {
404
+ const stat = await promises_1.default.stat(script);
405
+ if (stat.isFile()) {
406
+ if (!(0, common_1.isDotJS)(script) && !(0, common_1.isDotJSON)(script) && !(0, common_1.isDotNODE)(script)) {
407
+ log_1.log.warn("Non-javascript file is specified in 'scripts'.", [
408
+ 'Pkg will probably fail to parse. Specify *.js in glob.',
409
+ script,
410
+ ]);
411
+ }
412
+ await this.appendBlobOrContent({
413
+ file: (0, common_1.normalizePath)(script),
414
+ marker,
415
+ store: common_1.STORE_BLOB,
416
+ reason: configPath,
417
+ });
418
+ }
419
+ }
420
+ }
421
+ let { assets } = pkgConfig;
422
+ if (assets) {
423
+ assets = expandFiles(assets, base);
424
+ for (const asset of assets) {
425
+ log_1.log.debug(' Adding asset : .... ', asset);
426
+ const stat = await promises_1.default.stat(asset);
427
+ if (stat.isFile()) {
428
+ await this.appendBlobOrContent({
429
+ file: (0, common_1.normalizePath)(asset),
430
+ marker,
431
+ store: common_1.STORE_CONTENT,
432
+ reason: configPath,
433
+ });
434
+ }
435
+ }
436
+ }
437
+ }
438
+ else if (config) {
439
+ let { files } = config;
440
+ if (files) {
441
+ files = expandFiles(files, base);
442
+ for (let file of files) {
443
+ file = (0, common_1.normalizePath)(file);
444
+ const stat = await promises_1.default.stat(file);
445
+ if (stat.isFile()) {
446
+ // 1) remove sources of top-level(!) package 'files' i.e. ship as BLOB
447
+ // 2) non-source (non-js) files of top-level package are shipped as CONTENT
448
+ // 3) parsing some js 'files' of non-top-level packages fails, hence all CONTENT
449
+ if (marker.toplevel) {
450
+ await this.appendBlobOrContent({
451
+ file,
452
+ marker,
453
+ store: (0, common_1.isDotJS)(file) ? common_1.STORE_BLOB : common_1.STORE_CONTENT,
454
+ reason: configPath,
455
+ });
456
+ }
457
+ else {
458
+ await this.appendBlobOrContent({
459
+ file,
460
+ marker,
461
+ store: common_1.STORE_CONTENT,
462
+ reason: configPath,
463
+ });
464
+ }
465
+ }
466
+ }
467
+ }
468
+ }
469
+ }
470
+ async stepActivate(marker, derivatives) {
471
+ if (!marker) {
472
+ (0, assert_1.default)(false);
473
+ }
474
+ if (marker.activated) {
475
+ return;
476
+ }
477
+ const { config, base } = marker;
478
+ if (!config) {
479
+ (0, assert_1.default)(false);
480
+ }
481
+ const { name } = config;
482
+ if (name) {
483
+ const d = this.dictionary[name];
484
+ if (d) {
485
+ if (typeof config.dependencies === 'object' &&
486
+ typeof d.dependencies === 'object') {
487
+ Object.assign(config.dependencies, d.dependencies);
488
+ delete d.dependencies;
489
+ }
490
+ Object.assign(config, d);
491
+ marker.hasDictionary = true;
492
+ }
493
+ }
494
+ const { dependencies } = config;
495
+ if (typeof dependencies === 'object') {
496
+ for (const dependency in dependencies) {
497
+ // it may be `undefined` - overridden
498
+ // in dictionary (see publicsuffixlist)
499
+ if (dependencies[dependency]) {
500
+ derivatives.push({
501
+ alias: dependency,
502
+ aliasType: common_1.ALIAS_AS_RESOLVABLE,
503
+ fromDependencies: true,
504
+ });
505
+ derivatives.push({
506
+ alias: `${dependency}/package.json`,
507
+ aliasType: common_1.ALIAS_AS_RESOLVABLE,
508
+ fromDependencies: true,
509
+ });
510
+ }
511
+ }
512
+ }
513
+ const pkgConfig = config.pkg;
514
+ if (pkgConfig) {
515
+ const { patches } = pkgConfig;
516
+ if (patches) {
517
+ for (const key in patches) {
518
+ if (patches[key]) {
519
+ const p = path_1.default.join(base, key);
520
+ this.patches[p] = patches[key];
521
+ }
522
+ }
523
+ }
524
+ const { deployFiles } = pkgConfig;
525
+ if (deployFiles) {
526
+ marker.hasDeployFiles = true;
527
+ for (const deployFile of deployFiles) {
528
+ const type = deployFile[2] || 'file';
529
+ log_1.log.warn(`Cannot include ${type} %1 into executable.`, [
530
+ `The ${type} must be distributed with executable as %2.`,
531
+ `%1: ${path_1.default.relative(process.cwd(), path_1.default.join(base, deployFile[0]))}`,
532
+ `%2: path-to-executable/${deployFile[1]}`,
533
+ ]);
534
+ }
535
+ }
536
+ if (pkgConfig.log) {
537
+ pkgConfig.log(log_1.log, { packagePath: base });
538
+ }
539
+ }
540
+ await this.appendFilesFromConfig(marker);
541
+ marker.public = isPublic(config);
542
+ if (!marker.public && marker.toplevel) {
543
+ marker.public = this.params.publicToplevel;
544
+ }
545
+ if (!marker.public && !marker.toplevel && this.params.publicPackages) {
546
+ marker.public =
547
+ this.params.publicPackages[0] === '*' ||
548
+ (!!name && this.params.publicPackages.indexOf(name) !== -1);
549
+ }
550
+ marker.activated = true;
551
+ // assert no further work with config
552
+ delete marker.config;
553
+ }
554
+ hasPatch(record) {
555
+ const patch = this.patches[record.file];
556
+ if (!patch) {
557
+ return;
558
+ }
559
+ return true;
560
+ }
561
+ stepPatch(record) {
562
+ const patch = this.patches[record.file];
563
+ if (!patch) {
564
+ return;
565
+ }
566
+ let body = (record.body || '').toString('utf8');
567
+ for (let i = 0; i < patch.length; i += 2) {
568
+ if (typeof patch[i] === 'object') {
569
+ if (patch[i].do === 'erase') {
570
+ body = patch[i + 1];
571
+ }
572
+ else if (patch[i].do === 'prepend') {
573
+ body = patch[i + 1] + body;
574
+ }
575
+ else if (patch[i].do === 'append') {
576
+ body += patch[i + 1];
577
+ }
578
+ }
579
+ else if (typeof patch[i] === 'string') {
580
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
581
+ // function escapeRegExp
582
+ const esc = patch[i].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
583
+ const regexp = new RegExp(esc, 'g');
584
+ body = body.replace(regexp, patch[i + 1]);
585
+ }
586
+ }
587
+ record.body = body;
588
+ }
589
+ async stepDerivatives_ALIAS_AS_RELATIVE(record, marker, derivative) {
590
+ const file = (0, common_1.normalizePath)(path_1.default.join(path_1.default.dirname(record.file), derivative.alias));
591
+ let stat;
592
+ try {
593
+ stat = await promises_1.default.stat(file);
594
+ }
595
+ catch (error) {
596
+ const { toplevel } = marker;
597
+ const exception = error;
598
+ const debug = !toplevel && exception.code === 'ENOENT';
599
+ const level = debug ? 'debug' : 'warn';
600
+ log_1.log[level](`Cannot stat, ${exception.code}`, [
601
+ file,
602
+ `The file was required from '${record.file}'`,
603
+ ]);
604
+ }
605
+ if (stat && stat.isFile()) {
606
+ await this.appendBlobOrContent({
607
+ file,
608
+ marker,
609
+ store: common_1.STORE_CONTENT,
610
+ reason: record.file,
611
+ });
612
+ }
613
+ }
614
+ async stepDerivatives_ALIAS_AS_RESOLVABLE(record, marker, derivative) {
615
+ const newPackages = [];
616
+ const catchReadFile = (file) => {
617
+ (0, assert_1.default)((0, common_1.isPackageJson)(file), `walker: ${file} must be package.json`);
618
+ newPackages.push({ packageJson: file });
619
+ };
620
+ const catchPackageFilter = (config, base) => {
621
+ const newPackage = newPackages[newPackages.length - 1];
622
+ newPackage.marker = {
623
+ config,
624
+ configPath: newPackage.packageJson,
625
+ base,
626
+ };
627
+ };
628
+ let newFile = '';
629
+ let failure;
630
+ const basedir = path_1.default.dirname(record.file);
631
+ try {
632
+ newFile = await (0, follow_1.follow)(derivative.alias, {
633
+ basedir,
634
+ // default is extensions: ['.js'], but
635
+ // it is not enough because 'typos.json'
636
+ // is not taken in require('./typos')
637
+ // in 'normalize-package-data/lib/fixer.js'
638
+ // Also include .mjs to support ESM files that get transformed to .js
639
+ extensions: MODULE_RESOLVE_EXTENSIONS,
640
+ catchReadFile,
641
+ catchPackageFilter,
642
+ });
643
+ }
644
+ catch (error) {
645
+ failure = error;
646
+ }
647
+ if (failure) {
648
+ const { toplevel } = marker;
649
+ const mainNotFound = newPackages.length > 0 && !newPackages[0].marker?.config?.main;
650
+ const debug = !toplevel ||
651
+ derivative.mayExclude ||
652
+ (mainNotFound && derivative.fromDependencies);
653
+ const level = debug ? 'debug' : 'warn';
654
+ if (mainNotFound) {
655
+ const message = "Entry 'main' not found in %1";
656
+ log_1.log[level](message, [
657
+ `%1: ${newPackages[0].packageJson}`,
658
+ `%2: ${record.file}`,
659
+ ]);
660
+ }
661
+ else {
662
+ log_1.log[level](`${colors_1.pc.yellow(failure.message)} in ${record.file}`);
663
+ }
664
+ return;
665
+ }
666
+ let newPackageForNewRecords;
667
+ for (const newPackage of newPackages) {
668
+ let newFile2;
669
+ try {
670
+ newFile2 = await (0, follow_1.follow)(derivative.alias, {
671
+ basedir: path_1.default.dirname(record.file),
672
+ extensions: MODULE_RESOLVE_EXTENSIONS,
673
+ ignoreFile: newPackage.packageJson,
674
+ });
675
+ if (strictVerify) {
676
+ (0, assert_1.default)(newFile2 === (0, common_1.normalizePath)(newFile2));
677
+ }
678
+ }
679
+ catch (_) {
680
+ // not setting is enough
681
+ }
682
+ if (newFile2 !== newFile) {
683
+ newPackageForNewRecords = newPackage;
684
+ break;
685
+ }
686
+ }
687
+ // Add all discovered package.json files, not just the one determined by the double-resolution logic
688
+ // This is necessary because ESM resolution may bypass the standard packageFilter mechanism
689
+ // However, only include package.json files that are either:
690
+ // 1. Inside node_modules (dependencies)
691
+ // 2. Inside the base directory of the current marker (application being packaged)
692
+ // This prevents including pkg's own package.json when used from source
693
+ for (const newPackage of newPackages) {
694
+ if (newPackage.marker) {
695
+ const file = newPackage.packageJson;
696
+ const isInNodeModules = file.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`);
697
+ const isInMarkerBase = marker.base && file.startsWith(marker.base);
698
+ if (isInNodeModules || isInMarkerBase) {
699
+ await this.appendBlobOrContent({
700
+ file,
701
+ marker: newPackage.marker,
702
+ store: common_1.STORE_CONTENT,
703
+ reason: record.file,
704
+ });
705
+ }
706
+ }
707
+ }
708
+ // Keep the original logic for determining the marker for the resolved file
709
+ if (newPackageForNewRecords) {
710
+ if (strictVerify) {
711
+ (0, assert_1.default)(newPackageForNewRecords.packageJson ===
712
+ (0, common_1.normalizePath)(newPackageForNewRecords.packageJson));
713
+ }
714
+ }
715
+ await this.appendBlobOrContent({
716
+ file: newFile,
717
+ marker: newPackageForNewRecords ? newPackageForNewRecords.marker : marker,
718
+ store: common_1.STORE_BLOB,
719
+ reason: record.file,
720
+ });
721
+ }
722
+ async stepDerivatives(record, marker, derivatives) {
723
+ for (const derivative of derivatives) {
724
+ // TODO: actually use the target node version
725
+ if (isBuiltin(derivative.alias))
726
+ continue;
727
+ switch (derivative.aliasType) {
728
+ case common_1.ALIAS_AS_RELATIVE:
729
+ await this.stepDerivatives_ALIAS_AS_RELATIVE(record, marker, derivative);
730
+ break;
731
+ case common_1.ALIAS_AS_RESOLVABLE:
732
+ await this.stepDerivatives_ALIAS_AS_RESOLVABLE(record, marker, derivative);
733
+ break;
734
+ default:
735
+ (0, assert_1.default)(false, `walker: unknown aliasType ${derivative.aliasType}`);
736
+ }
737
+ }
738
+ }
739
+ async step_STORE_ANY(record, marker, store) {
740
+ if (strictVerify) {
741
+ (0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file));
742
+ }
743
+ if (record[store] !== undefined)
744
+ return;
745
+ record[store] = false; // default is discard
746
+ this.appendStat({
747
+ file: record.file,
748
+ store: common_1.STORE_STAT,
749
+ });
750
+ const derivatives1 = [];
751
+ await this.stepActivate(marker, derivatives1);
752
+ await this.stepDerivatives(record, marker, derivatives1);
753
+ if (store === common_1.STORE_BLOB) {
754
+ if ((0, common_1.unlikelyJavascript)(record.file) || (0, common_1.isDotNODE)(record.file)) {
755
+ await this.appendBlobOrContent({
756
+ file: record.file,
757
+ marker,
758
+ store: common_1.STORE_CONTENT,
759
+ });
760
+ return; // discard
761
+ }
762
+ if (marker.public || marker.hasDictionary) {
763
+ await this.appendBlobOrContent({
764
+ file: record.file,
765
+ marker,
766
+ store: common_1.STORE_CONTENT,
767
+ });
768
+ }
769
+ }
770
+ if (store === common_1.STORE_BLOB ||
771
+ (store === common_1.STORE_CONTENT && (0, common_1.isPackageJson)(record.file)) ||
772
+ this.hasPatch(record)) {
773
+ if (!record.body) {
774
+ await stepRead(record);
775
+ this.stepPatch(record);
776
+ if (store === common_1.STORE_BLOB) {
777
+ stepStrip(record);
778
+ }
779
+ }
780
+ // Patch package.json files to add synthetic main field if needed
781
+ if (store === common_1.STORE_CONTENT &&
782
+ (0, common_1.isPackageJson)(record.file) &&
783
+ record.body) {
784
+ try {
785
+ const pkgContent = JSON.parse(record.body.toString('utf8'));
786
+ let modified = false;
787
+ // If package has exports but no main, add a synthetic main field
788
+ if (pkgContent.exports && !pkgContent.main) {
789
+ // Try to get main from marker.config first (set by catchPackageFilter in follow.ts)
790
+ if (marker.config?.main) {
791
+ pkgContent.main = marker.config.main;
792
+ modified = true;
793
+ }
794
+ else {
795
+ // Fallback: try to infer main from exports field
796
+ const { exports } = pkgContent;
797
+ if (typeof exports === 'string') {
798
+ pkgContent.main = exports;
799
+ modified = true;
800
+ }
801
+ else if (exports && typeof exports === 'object') {
802
+ // Handle conditional exports
803
+ if (exports['.']) {
804
+ if (typeof exports['.'] === 'string') {
805
+ pkgContent.main = exports['.'];
806
+ modified = true;
807
+ }
808
+ else if (typeof exports['.'] === 'object') {
809
+ // Try to get the best entry point for CJS
810
+ // Prefer: require > node > default
811
+ let mainEntry;
812
+ if (typeof exports['.'].require === 'string' &&
813
+ exports['.'].require) {
814
+ mainEntry = exports['.'].require;
815
+ }
816
+ else if (typeof exports['.'].node === 'string' &&
817
+ exports['.'].node) {
818
+ mainEntry = exports['.'].node;
819
+ }
820
+ else if (typeof exports['.'].default === 'string' &&
821
+ exports['.'].default) {
822
+ mainEntry = exports['.'].default;
823
+ }
824
+ if (mainEntry) {
825
+ pkgContent.main = mainEntry;
826
+ modified = true;
827
+ }
828
+ }
829
+ }
830
+ }
831
+ }
832
+ }
833
+ // If package has "type": "module", we need to change it to "commonjs"
834
+ // because we transform all ESM files to CJS before bytecode compilation
835
+ if (pkgContent.type === 'module') {
836
+ pkgContent.type = 'commonjs';
837
+ modified = true;
838
+ }
839
+ // Only rewrite if we made changes
840
+ if (modified) {
841
+ record.body = Buffer.from(JSON.stringify(pkgContent, null, 2), 'utf8');
842
+ }
843
+ }
844
+ catch (_error) {
845
+ // Ignore JSON parsing errors
846
+ }
847
+ }
848
+ // Transform ESM to CJS before bytecode compilation
849
+ // Check all JS-like files (.js, .mjs, .cjs) but only transform ESM ones
850
+ if (store === common_1.STORE_BLOB &&
851
+ record.body &&
852
+ ((0, common_1.isDotJS)(record.file) || record.file.endsWith('.mjs'))) {
853
+ if ((0, common_1.isESMFile)(record.file)) {
854
+ try {
855
+ const result = (0, esm_transformer_1.transformESMtoCJS)(record.body.toString('utf8'), record.file);
856
+ if (result.isTransformed) {
857
+ record.body = Buffer.from(result.code, 'utf8');
858
+ // Mark .mjs files as transformed so packer can rename them to .js
859
+ if (record.file.endsWith('.mjs')) {
860
+ record.wasTransformed = true;
861
+ }
862
+ }
863
+ }
864
+ catch (error) {
865
+ const message = error instanceof Error ? error.message : String(error);
866
+ throw new Error(`Failed to transform ESM module to CJS for file "${record.file}": ${message}`);
867
+ }
868
+ }
869
+ }
870
+ if (store === common_1.STORE_BLOB) {
871
+ const derivatives2 = [];
872
+ stepDetect(record, marker, derivatives2);
873
+ await this.stepDerivatives(record, marker, derivatives2);
874
+ // After dependencies are resolved, rewrite .mjs require paths to .js
875
+ // since the packer renames .mjs files to .js in the snapshot
876
+ if (record.wasTransformed && record.body) {
877
+ record.body = Buffer.from((0, esm_transformer_1.rewriteMjsRequirePaths)(record.body.toString('utf8')), 'utf8');
878
+ }
879
+ }
880
+ }
881
+ record[store] = true;
882
+ }
883
+ step_STORE_LINKS(record, data) {
884
+ if (strictVerify) {
885
+ (0, assert_1.default)(record.file === (0, common_1.toNormalizedRealPath)(record.file), ' expecting real file !!!');
886
+ }
887
+ if (record[common_1.STORE_LINKS]) {
888
+ record[common_1.STORE_LINKS].push(data);
889
+ return;
890
+ }
891
+ record[common_1.STORE_LINKS] = [data];
892
+ if (record[common_1.STORE_STAT]) {
893
+ return;
894
+ }
895
+ this.appendStat({
896
+ file: record.file,
897
+ store: common_1.STORE_STAT,
898
+ });
899
+ }
900
+ async step_STORE_STAT(record) {
901
+ if (record[common_1.STORE_STAT])
902
+ return;
903
+ const realPath = (0, common_1.toNormalizedRealPath)(record.file);
904
+ if (realPath !== record.file) {
905
+ this.appendStat({
906
+ file: realPath,
907
+ store: common_1.STORE_STAT,
908
+ });
909
+ }
910
+ try {
911
+ const valueStat = await promises_1.default.stat(record.file);
912
+ const value = {
913
+ mode: valueStat.mode,
914
+ size: valueStat.isFile() ? valueStat.size : 0,
915
+ isFileValue: valueStat.isFile(),
916
+ isDirectoryValue: valueStat.isDirectory(),
917
+ isSocketValue: valueStat.isSocket(),
918
+ isSymbolicLinkValue: valueStat.isSymbolicLink(),
919
+ };
920
+ record[common_1.STORE_STAT] = value;
921
+ }
922
+ catch (error) {
923
+ const exception = error;
924
+ log_1.log.error(`Cannot stat, ${exception.code}`, record.file);
925
+ throw (0, log_1.wasReported)(exception.message);
926
+ }
927
+ if (path_1.default.dirname(record.file) !== record.file) {
928
+ // root directory
929
+ this.appendFileInFolder({
930
+ file: path_1.default.dirname(record.file),
931
+ store: common_1.STORE_LINKS,
932
+ data: path_1.default.basename(record.file),
933
+ });
934
+ }
935
+ }
936
+ async step(task) {
937
+ const { file, store, data } = task;
938
+ const record = this.records[file];
939
+ switch (store) {
940
+ case common_1.STORE_BLOB:
941
+ case common_1.STORE_CONTENT:
942
+ await this.step_STORE_ANY(record, task.marker, store);
943
+ break;
944
+ case common_1.STORE_LINKS:
945
+ this.step_STORE_LINKS(record, data);
946
+ break;
947
+ case common_1.STORE_STAT:
948
+ await this.step_STORE_STAT(record);
949
+ break;
950
+ default:
951
+ (0, assert_1.default)(false, `walker: unknown store ${store}`);
952
+ }
953
+ }
954
+ async readDictionary(marker) {
955
+ if (this.params.noDictionary?.[0] === '*') {
956
+ return;
957
+ }
958
+ const dd = path_1.default.join(__dirname, '../dictionary');
959
+ const files = await promises_1.default.readdir(dd);
960
+ for (const file of files) {
961
+ if (/\.js$/.test(file)) {
962
+ const name = file.slice(0, -3);
963
+ if (this.params.noDictionary?.includes(file)) {
964
+ continue;
965
+ }
966
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
967
+ const config = require(path_1.default.join(dd, file));
968
+ this.dictionary[name] = config;
969
+ }
970
+ }
971
+ const pkgConfig = marker.config?.pkg;
972
+ if (pkgConfig) {
973
+ const { dictionary } = pkgConfig;
974
+ if (dictionary) {
975
+ for (const name in dictionary) {
976
+ if (dictionary[name]) {
977
+ this.dictionary[name] = { pkg: dictionary[name] };
978
+ }
979
+ }
980
+ }
981
+ }
982
+ }
983
+ async start(marker, entrypoint, addition, params) {
984
+ this.params = params;
985
+ this.symLinks = {};
986
+ await this.readDictionary(marker);
987
+ entrypoint = (0, common_1.normalizePath)(entrypoint);
988
+ await this.appendBlobOrContent({
989
+ file: entrypoint,
990
+ marker,
991
+ store: common_1.STORE_BLOB,
992
+ });
993
+ if (addition) {
994
+ addition = (0, common_1.normalizePath)(addition);
995
+ await this.appendBlobOrContent({
996
+ file: addition,
997
+ marker,
998
+ store: common_1.STORE_CONTENT,
999
+ });
1000
+ }
1001
+ const { tasks } = this;
1002
+ for (let i = 0; i < tasks.length; i += 1) {
1003
+ // NO MULTIPLE WORKERS! THIS WILL LEAD TO NON-DETERMINISTIC
1004
+ // ORDER. one-by-one fifo is the only way to iterate tasks
1005
+ await this.step(tasks[i]);
1006
+ }
1007
+ return {
1008
+ symLinks: this.symLinks,
1009
+ records: this.records,
1010
+ entrypoint: (0, common_1.normalizePath)(entrypoint),
1011
+ };
1012
+ }
1013
+ }
1014
+ async function walker(...args) {
1015
+ const w = new Walker();
1016
+ return w.start(...args);
1017
+ }
1018
+ exports.default = walker;
1019
+ //# sourceMappingURL=walker.js.map