@yao-pkg/pkg 5.9.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 (257) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +433 -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 +3 -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/throng.js +3 -0
  216. package/dictionary/time.js +3 -0
  217. package/dictionary/tinify.js +7 -0
  218. package/dictionary/tiny-worker.js +7 -0
  219. package/dictionary/tmp.js +3 -0
  220. package/dictionary/transformers.js +3 -0
  221. package/dictionary/uglify-js.js +9 -0
  222. package/dictionary/umd.js +19 -0
  223. package/dictionary/underscore.js +3 -0
  224. package/dictionary/union.js +3 -0
  225. package/dictionary/update-notifier.js +3 -0
  226. package/dictionary/usage.js +7 -0
  227. package/dictionary/v8flags.js +13 -0
  228. package/dictionary/verror.js +3 -0
  229. package/dictionary/voc.js +3 -0
  230. package/dictionary/webdriverio.js +7 -0
  231. package/dictionary/winston-uber.js +7 -0
  232. package/dictionary/winston.js +7 -0
  233. package/dictionary/ws.js +3 -0
  234. package/dictionary/xlsx.js +16 -0
  235. package/dictionary/xml2js.js +3 -0
  236. package/dictionary/yargs.js +3 -0
  237. package/dictionary/zeromq.js +13 -0
  238. package/lib-es5/bin.js +19 -0
  239. package/lib-es5/chmod.js +15 -0
  240. package/lib-es5/common.js +235 -0
  241. package/lib-es5/compress_type.js +10 -0
  242. package/lib-es5/detector.js +420 -0
  243. package/lib-es5/fabricator.js +141 -0
  244. package/lib-es5/follow.js +91 -0
  245. package/lib-es5/help.js +53 -0
  246. package/lib-es5/index.d.ts +2 -0
  247. package/lib-es5/index.js +541 -0
  248. package/lib-es5/log.js +7 -0
  249. package/lib-es5/mach-o.js +61 -0
  250. package/lib-es5/packer.js +131 -0
  251. package/lib-es5/producer.js +343 -0
  252. package/lib-es5/refiner.js +87 -0
  253. package/lib-es5/types.js +9 -0
  254. package/lib-es5/walker.js +853 -0
  255. package/package.json +143 -0
  256. package/prelude/bootstrap.js +2256 -0
  257. package/prelude/diagnostic.js +136 -0
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /* eslint-disable complexity */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const common_1 = require("./common");
11
+ const log_1 = require("./log");
12
+ const { version } = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../package.json'), 'utf-8'));
13
+ const bootstrapText = fs_extra_1.default
14
+ .readFileSync(require.resolve('../prelude/bootstrap.js'), 'utf8')
15
+ .replace('%VERSION%', version);
16
+ const commonText = fs_extra_1.default.readFileSync(require.resolve('./common'), 'utf8');
17
+ const diagnosticText = fs_extra_1.default.readFileSync(require.resolve('../prelude/diagnostic.js'), 'utf8');
18
+ function itemsToText(items) {
19
+ const len = items.length;
20
+ return len.toString() + (len % 10 === 1 ? ' item' : ' items');
21
+ }
22
+ function hasAnyStore(record) {
23
+ // discarded records like native addons
24
+ for (const store of [common_1.STORE_BLOB, common_1.STORE_CONTENT, common_1.STORE_LINKS, common_1.STORE_STAT]) {
25
+ if (record[store])
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+ function packer({ records, entrypoint, bytecode, }) {
31
+ const stripes = [];
32
+ for (const snap in records) {
33
+ if (records[snap]) {
34
+ const record = records[snap];
35
+ const { file } = record;
36
+ if (!hasAnyStore(record)) {
37
+ continue;
38
+ }
39
+ (0, assert_1.default)(record[common_1.STORE_STAT], 'packer: no STORE_STAT');
40
+ (0, assert_1.default)(record[common_1.STORE_BLOB] ||
41
+ record[common_1.STORE_CONTENT] ||
42
+ record[common_1.STORE_LINKS] ||
43
+ record[common_1.STORE_STAT]);
44
+ if (record[common_1.STORE_BLOB] && !bytecode) {
45
+ delete record[common_1.STORE_BLOB];
46
+ if (!record[common_1.STORE_CONTENT]) {
47
+ // TODO make a test for it?
48
+ throw (0, log_1.wasReported)('--no-bytecode and no source breaks final executable', [
49
+ file,
50
+ 'Please run with "-d" and without "--no-bytecode" first, and make',
51
+ 'sure that debug log does not contain "was included as bytecode".',
52
+ ]);
53
+ }
54
+ }
55
+ for (const store of [
56
+ common_1.STORE_BLOB,
57
+ common_1.STORE_CONTENT,
58
+ common_1.STORE_LINKS,
59
+ common_1.STORE_STAT,
60
+ ]) {
61
+ const value = record[store];
62
+ if (!value) {
63
+ continue;
64
+ }
65
+ if (store === common_1.STORE_BLOB || store === common_1.STORE_CONTENT) {
66
+ if (record.body === undefined) {
67
+ stripes.push({ snap, store, file });
68
+ }
69
+ else if (Buffer.isBuffer(record.body)) {
70
+ stripes.push({ snap, store, buffer: record.body });
71
+ }
72
+ else if (typeof record.body === 'string') {
73
+ stripes.push({ snap, store, buffer: Buffer.from(record.body) });
74
+ }
75
+ else {
76
+ (0, assert_1.default)(false, 'packer: bad STORE_BLOB/STORE_CONTENT');
77
+ }
78
+ }
79
+ else if (store === common_1.STORE_LINKS) {
80
+ if (Array.isArray(value)) {
81
+ const dedupedValue = [...new Set(value)];
82
+ log_1.log.debug('files & folders deduped = ', dedupedValue);
83
+ const buffer = Buffer.from(JSON.stringify(dedupedValue));
84
+ stripes.push({ snap, store, buffer });
85
+ }
86
+ else {
87
+ (0, assert_1.default)(false, 'packer: bad STORE_LINKS');
88
+ }
89
+ }
90
+ else if (store === common_1.STORE_STAT) {
91
+ if (typeof value === 'object') {
92
+ const newStat = Object.assign({}, value);
93
+ const buffer = Buffer.from(JSON.stringify(newStat));
94
+ stripes.push({ snap, store, buffer });
95
+ }
96
+ else {
97
+ (0, assert_1.default)(false, 'packer: unknown store');
98
+ }
99
+ }
100
+ if (record[common_1.STORE_CONTENT]) {
101
+ const disclosed = (0, common_1.isDotJS)(file) || (0, common_1.isDotJSON)(file);
102
+ log_1.log.debug(disclosed
103
+ ? 'The file was included as DISCLOSED code (with sources)'
104
+ : 'The file was included as asset content', file);
105
+ }
106
+ else if (record[common_1.STORE_BLOB]) {
107
+ log_1.log.debug('The file was included as bytecode (no sources)', file);
108
+ }
109
+ else if (record[common_1.STORE_LINKS]) {
110
+ const link = record[common_1.STORE_LINKS];
111
+ log_1.log.debug(`The directory files list was included (${itemsToText(link)})`, file);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ const prelude = `return (function (REQUIRE_COMMON, VIRTUAL_FILESYSTEM, DEFAULT_ENTRYPOINT, SYMLINKS, DICT, DOCOMPRESS) {
117
+ ${bootstrapText}${log_1.log.debugMode ? diagnosticText : ''}\n})(function (exports) {\n${commonText}\n},\n` +
118
+ `%VIRTUAL_FILESYSTEM%` +
119
+ `\n,\n` +
120
+ `%DEFAULT_ENTRYPOINT%` +
121
+ `\n,\n` +
122
+ `%SYMLINKS%` +
123
+ '\n,\n' +
124
+ '%DICT%' +
125
+ '\n,\n' +
126
+ '%DOCOMPRESS%' +
127
+ `\n);`;
128
+ return { prelude, entrypoint, stripes };
129
+ }
130
+ exports.default = packer;
131
+ //# sourceMappingURL=packer.js.map
@@ -0,0 +1,343 @@
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
+ const zlib_1 = require("zlib");
7
+ const multistream_1 = __importDefault(require("multistream"));
8
+ const assert_1 = __importDefault(require("assert"));
9
+ const child_process_1 = require("child_process");
10
+ const fs_extra_1 = __importDefault(require("fs-extra"));
11
+ const into_stream_1 = __importDefault(require("into-stream"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const stream_meter_1 = __importDefault(require("stream-meter"));
14
+ const common_1 = require("./common");
15
+ const log_1 = require("./log");
16
+ const fabricator_1 = require("./fabricator");
17
+ const types_1 = require("./types");
18
+ const compress_type_1 = require("./compress_type");
19
+ function discoverPlaceholder(binaryBuffer, searchString, padder) {
20
+ const placeholder = Buffer.from(searchString);
21
+ const position = binaryBuffer.indexOf(placeholder);
22
+ if (position === -1) {
23
+ return { notFound: true };
24
+ }
25
+ return { position, size: placeholder.length, padder };
26
+ }
27
+ function injectPlaceholder(fd, placeholder, value, cb) {
28
+ if ('notFound' in placeholder) {
29
+ (0, assert_1.default)(false, 'Placeholder for not found');
30
+ }
31
+ const { position, size, padder } = placeholder;
32
+ let stringValue = Buffer.from('');
33
+ if (typeof value === 'number') {
34
+ stringValue = Buffer.from(value.toString());
35
+ }
36
+ else if (typeof value === 'string') {
37
+ stringValue = Buffer.from(value);
38
+ }
39
+ else {
40
+ stringValue = value;
41
+ }
42
+ const padding = Buffer.from(padder.repeat(size - stringValue.length));
43
+ stringValue = Buffer.concat([stringValue, padding]);
44
+ fs_extra_1.default.write(fd, stringValue, 0, stringValue.length, position, cb);
45
+ }
46
+ function discoverPlaceholders(binaryBuffer) {
47
+ return {
48
+ BAKERY: discoverPlaceholder(binaryBuffer, `\0${'// BAKERY '.repeat(20)}`, '\0'),
49
+ PAYLOAD_POSITION: discoverPlaceholder(binaryBuffer, '// PAYLOAD_POSITION //', ' '),
50
+ PAYLOAD_SIZE: discoverPlaceholder(binaryBuffer, '// PAYLOAD_SIZE //', ' '),
51
+ PRELUDE_POSITION: discoverPlaceholder(binaryBuffer, '// PRELUDE_POSITION //', ' '),
52
+ PRELUDE_SIZE: discoverPlaceholder(binaryBuffer, '// PRELUDE_SIZE //', ' '),
53
+ };
54
+ }
55
+ function injectPlaceholders(fd, placeholders, values, cb) {
56
+ injectPlaceholder(fd, placeholders.BAKERY, values.BAKERY, (error) => {
57
+ if (error) {
58
+ return cb(error);
59
+ }
60
+ injectPlaceholder(fd, placeholders.PAYLOAD_POSITION, values.PAYLOAD_POSITION, (error2) => {
61
+ if (error2) {
62
+ return cb(error2);
63
+ }
64
+ injectPlaceholder(fd, placeholders.PAYLOAD_SIZE, values.PAYLOAD_SIZE, (error3) => {
65
+ if (error3) {
66
+ return cb(error3);
67
+ }
68
+ injectPlaceholder(fd, placeholders.PRELUDE_POSITION, values.PRELUDE_POSITION, (error4) => {
69
+ if (error4) {
70
+ return cb(error4);
71
+ }
72
+ injectPlaceholder(fd, placeholders.PRELUDE_SIZE, values.PRELUDE_SIZE, cb);
73
+ });
74
+ });
75
+ });
76
+ });
77
+ }
78
+ function makeBakeryValueFromBakes(bakes) {
79
+ const parts = [];
80
+ if (bakes.length) {
81
+ for (let i = 0; i < bakes.length; i += 1) {
82
+ parts.push(Buffer.from(bakes[i]));
83
+ parts.push(Buffer.alloc(1));
84
+ }
85
+ parts.push(Buffer.alloc(1));
86
+ }
87
+ return Buffer.concat(parts);
88
+ }
89
+ function replaceDollarWise(s, sf, st) {
90
+ return s.replace(sf, () => st);
91
+ }
92
+ function makePreludeBufferFromPrelude(prelude) {
93
+ return Buffer.from(`(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) { ${prelude}\n})`);
94
+ }
95
+ function findPackageJson(nodeFile) {
96
+ let dir = nodeFile;
97
+ while (dir !== '/') {
98
+ dir = path_1.default.dirname(dir);
99
+ if (fs_extra_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
100
+ break;
101
+ }
102
+ }
103
+ if (dir === '/') {
104
+ throw new Error(`package.json not found for "${nodeFile}"`);
105
+ }
106
+ return dir;
107
+ }
108
+ function nativePrebuildInstall(target, nodeFile) {
109
+ var _a, _b;
110
+ const prebuildInstall = path_1.default.join(__dirname, '../node_modules/.bin/prebuild-install');
111
+ const dir = findPackageJson(nodeFile);
112
+ // parse the target node version from the binaryPath
113
+ const nodeVersion = path_1.default.basename(target.binaryPath).split('-')[1];
114
+ if (!/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(nodeVersion)) {
115
+ throw new Error(`Couldn't find node version, instead got: ${nodeVersion}`);
116
+ }
117
+ const nativeFile = `${nodeFile}.${target.platform}.${nodeVersion}`;
118
+ if (fs_extra_1.default.existsSync(nativeFile)) {
119
+ return nativeFile;
120
+ }
121
+ // prebuild-install will overwrite the target .node file, so take a backup
122
+ if (!fs_extra_1.default.existsSync(`${nodeFile}.bak`)) {
123
+ fs_extra_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
124
+ }
125
+ const napiVersions = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(dir, 'package.json'), { encoding: 'utf-8' }))) === null || _a === void 0 ? void 0 : _a.binary) === null || _b === void 0 ? void 0 : _b.napi_versions;
126
+ const options = [
127
+ '--platform',
128
+ types_1.platform[target.platform],
129
+ '--arch',
130
+ target.arch,
131
+ ];
132
+ if (napiVersions == null) {
133
+ // TODO: consider target node version and supported n-api version
134
+ options.push('--target', nodeVersion);
135
+ }
136
+ // run prebuild
137
+ (0, child_process_1.execFileSync)(prebuildInstall, options, { cwd: dir });
138
+ // move the prebuild to a new name with a platform/version extension
139
+ fs_extra_1.default.copyFileSync(nodeFile, nativeFile);
140
+ // put the backed up file back
141
+ fs_extra_1.default.moveSync(`${nodeFile}.bak`, nodeFile, { overwrite: true });
142
+ return nativeFile;
143
+ }
144
+ /**
145
+ * instead of creating a vfs dicionnary with actual path as key
146
+ * we use a compression mechanism that can reduce significantly
147
+ * the memory footprint of the vfs in the code.
148
+ *
149
+ * without vfs compression:
150
+ *
151
+ * vfs = {
152
+ * "/folder1/folder2/file1.js": {};
153
+ * "/folder1/folder2/folder3/file2.js": {};
154
+ * "/folder1/folder2/folder3/file3.js": {};
155
+ * }
156
+ *
157
+ * with compression :
158
+ *
159
+ * fileDictionary = {
160
+ * "folder1": "1",
161
+ * "folder2": "2",
162
+ * "file1": "3",
163
+ * "folder3": "4",
164
+ * "file2": "5",
165
+ * "file3": "6",
166
+ * }
167
+ * vfs = {
168
+ * "/1/2/3": {};
169
+ * "/1/2/4/5": {};
170
+ * "/1/2/4/6": {};
171
+ * }
172
+ *
173
+ * note: the key is computed in base36 for further compression.
174
+ */
175
+ const fileDictionary = {};
176
+ let counter = 0;
177
+ function getOrCreateHash(fileOrFolderName) {
178
+ let existingKey = fileDictionary[fileOrFolderName];
179
+ if (!existingKey) {
180
+ const newkey = counter;
181
+ counter += 1;
182
+ existingKey = newkey.toString(36);
183
+ fileDictionary[fileOrFolderName] = existingKey;
184
+ }
185
+ return existingKey;
186
+ }
187
+ const separator = '/';
188
+ function makeKey(doCompression, fullpath, slash) {
189
+ if (doCompression === compress_type_1.CompressType.None)
190
+ return fullpath;
191
+ return fullpath.split(slash).map(getOrCreateHash).join(separator);
192
+ }
193
+ function producer({ backpack, bakes, slash, target, symLinks, doCompress, nativeBuild, }) {
194
+ return new Promise((resolve, reject) => {
195
+ if (!Buffer.alloc) {
196
+ throw (0, log_1.wasReported)('Your node.js does not have Buffer.alloc. Please upgrade!');
197
+ }
198
+ const { prelude } = backpack;
199
+ let { entrypoint, stripes } = backpack;
200
+ entrypoint = (0, common_1.snapshotify)(entrypoint, slash);
201
+ stripes = stripes.slice();
202
+ const vfs = {};
203
+ for (const stripe of stripes) {
204
+ let { snap } = stripe;
205
+ snap = (0, common_1.snapshotify)(snap, slash);
206
+ const vfsKey = makeKey(doCompress, snap, slash);
207
+ if (!vfs[vfsKey])
208
+ vfs[vfsKey] = {};
209
+ }
210
+ const snapshotSymLinks = {};
211
+ for (const [key, value] of Object.entries(symLinks)) {
212
+ const k = (0, common_1.snapshotify)(key, slash);
213
+ const v = (0, common_1.snapshotify)(value, slash);
214
+ const vfsKey = makeKey(doCompress, k, slash);
215
+ snapshotSymLinks[vfsKey] = makeKey(doCompress, v, slash);
216
+ }
217
+ let meter;
218
+ let count = 0;
219
+ function pipeToNewMeter(s) {
220
+ meter = (0, stream_meter_1.default)();
221
+ return s.pipe(meter);
222
+ }
223
+ function pipeMayCompressToNewMeter(s) {
224
+ if (doCompress === compress_type_1.CompressType.GZip) {
225
+ return pipeToNewMeter(s.pipe((0, zlib_1.createGzip)()));
226
+ }
227
+ if (doCompress === compress_type_1.CompressType.Brotli) {
228
+ return pipeToNewMeter(s.pipe((0, zlib_1.createBrotliCompress)()));
229
+ }
230
+ return pipeToNewMeter(s);
231
+ }
232
+ function next(s) {
233
+ count += 1;
234
+ return pipeToNewMeter(s);
235
+ }
236
+ const binaryBuffer = fs_extra_1.default.readFileSync(target.binaryPath);
237
+ const placeholders = discoverPlaceholders(binaryBuffer);
238
+ let track = 0;
239
+ let prevStripe;
240
+ let payloadPosition;
241
+ let payloadSize;
242
+ let preludePosition;
243
+ let preludeSize;
244
+ new multistream_1.default((cb) => {
245
+ if (count === 0) {
246
+ return cb(null, next((0, into_stream_1.default)(binaryBuffer)));
247
+ }
248
+ if (count === 1) {
249
+ payloadPosition = meter.bytes;
250
+ return cb(null, next((0, into_stream_1.default)(Buffer.alloc(0))));
251
+ }
252
+ if (count === 2) {
253
+ if (prevStripe && !prevStripe.skip) {
254
+ const { store } = prevStripe;
255
+ let { snap } = prevStripe;
256
+ snap = (0, common_1.snapshotify)(snap, slash);
257
+ const vfsKey = makeKey(doCompress, snap, slash);
258
+ vfs[vfsKey][store] = [track, meter.bytes];
259
+ track += meter.bytes;
260
+ }
261
+ if (stripes.length) {
262
+ // clone to prevent 'skip' propagate
263
+ // to other targets, since same stripe
264
+ // is used for several targets
265
+ const stripe = Object.assign({}, stripes.shift());
266
+ prevStripe = stripe;
267
+ if (stripe.buffer) {
268
+ if (stripe.store === common_1.STORE_BLOB) {
269
+ const snap = (0, common_1.snapshotify)(stripe.snap, slash);
270
+ return (0, fabricator_1.fabricateTwice)(bakes, target.fabricator, snap, stripe.buffer, (error, buffer) => {
271
+ if (error) {
272
+ log_1.log.warn(error.message);
273
+ stripe.skip = true;
274
+ return cb(null, (0, into_stream_1.default)(Buffer.alloc(0)));
275
+ }
276
+ cb(null, pipeMayCompressToNewMeter((0, into_stream_1.default)(buffer || Buffer.from(''))));
277
+ });
278
+ }
279
+ return cb(null, pipeMayCompressToNewMeter((0, into_stream_1.default)(stripe.buffer)));
280
+ }
281
+ if (stripe.file) {
282
+ if (stripe.file === target.output) {
283
+ return cb((0, log_1.wasReported)('Trying to take executable into executable', stripe.file), null);
284
+ }
285
+ assert_1.default.strictEqual(stripe.store, common_1.STORE_CONTENT); // others must be buffers from walker
286
+ if ((0, common_1.isDotNODE)(stripe.file) && nativeBuild) {
287
+ try {
288
+ const platformFile = nativePrebuildInstall(target, stripe.file);
289
+ if (fs_extra_1.default.existsSync(platformFile)) {
290
+ return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(platformFile)));
291
+ }
292
+ }
293
+ catch (err) {
294
+ log_1.log.debug(`prebuild-install failed[${stripe.file}]:`, err.message);
295
+ }
296
+ }
297
+ return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(stripe.file)));
298
+ }
299
+ (0, assert_1.default)(false, 'producer: bad stripe');
300
+ }
301
+ else {
302
+ payloadSize = track;
303
+ preludePosition = payloadPosition + payloadSize;
304
+ return cb(null, next((0, into_stream_1.default)(makePreludeBufferFromPrelude(replaceDollarWise(replaceDollarWise(replaceDollarWise(replaceDollarWise(replaceDollarWise(prelude, '%VIRTUAL_FILESYSTEM%', JSON.stringify(vfs)), '%DEFAULT_ENTRYPOINT%', JSON.stringify(entrypoint)), '%SYMLINKS%', JSON.stringify(snapshotSymLinks)), '%DICT%', JSON.stringify(fileDictionary)), '%DOCOMPRESS%', JSON.stringify(doCompress))))));
305
+ }
306
+ }
307
+ else {
308
+ return cb(null, null);
309
+ }
310
+ })
311
+ .on('error', (error) => {
312
+ reject(error);
313
+ })
314
+ .pipe(fs_extra_1.default.createWriteStream(target.output))
315
+ .on('error', (error) => {
316
+ reject(error);
317
+ })
318
+ .on('close', () => {
319
+ preludeSize = meter.bytes;
320
+ fs_extra_1.default.open(target.output, 'r+', (error, fd) => {
321
+ if (error)
322
+ return reject(error);
323
+ injectPlaceholders(fd, placeholders, {
324
+ BAKERY: makeBakeryValueFromBakes(bakes),
325
+ PAYLOAD_POSITION: payloadPosition,
326
+ PAYLOAD_SIZE: payloadSize,
327
+ PRELUDE_POSITION: preludePosition,
328
+ PRELUDE_SIZE: preludeSize,
329
+ }, (error2) => {
330
+ if (error2)
331
+ return reject(error2);
332
+ fs_extra_1.default.close(fd, (error3) => {
333
+ if (error3)
334
+ return reject(error3);
335
+ resolve();
336
+ });
337
+ });
338
+ });
339
+ });
340
+ });
341
+ }
342
+ exports.default = producer;
343
+ //# sourceMappingURL=producer.js.map
@@ -0,0 +1,87 @@
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
+ const path_1 = __importDefault(require("path"));
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const common_1 = require("./common");
9
+ const log_1 = require("./log");
10
+ const win32 = process.platform === 'win32';
11
+ function hasParent(file, records) {
12
+ const dirname = path_1.default.dirname(file);
13
+ // root directory
14
+ if (dirname === file) {
15
+ return false;
16
+ }
17
+ return Boolean(records[dirname]);
18
+ }
19
+ function purgeTopDirectories(records) {
20
+ while (true) {
21
+ let found = false;
22
+ for (const file in records) {
23
+ if (records[file]) {
24
+ const record = records[file];
25
+ const links = record[common_1.STORE_LINKS];
26
+ if (links && links.length === 1) {
27
+ if (!hasParent(file, records)) {
28
+ const file2 = path_1.default.join(file, links[0]);
29
+ const record2 = records[file2];
30
+ const links2 = record2[common_1.STORE_LINKS];
31
+ if (links2 && links2.length === 1) {
32
+ const file3 = path_1.default.join(file2, links2[0]);
33
+ const record3 = records[file3];
34
+ const links3 = record3[common_1.STORE_LINKS];
35
+ if (links3) {
36
+ delete records[file];
37
+ log_1.log.debug(chalk_1.default.cyan('Deleting record file :', file));
38
+ found = true;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ if (!found)
46
+ break;
47
+ }
48
+ }
49
+ function denominate(records, entrypoint, denominator, symLinks) {
50
+ const newRecords = {};
51
+ const makeSnap = (file) => {
52
+ let snap = (0, common_1.substituteDenominator)(file, denominator);
53
+ if (win32) {
54
+ if (snap.slice(1) === ':')
55
+ snap += '\\';
56
+ }
57
+ else if (snap === '') {
58
+ snap = '/';
59
+ }
60
+ return snap;
61
+ };
62
+ for (const file in records) {
63
+ if (records[file]) {
64
+ const snap = makeSnap(file);
65
+ newRecords[snap] = records[file];
66
+ }
67
+ }
68
+ const tmpSymLinks = symLinks;
69
+ symLinks = {};
70
+ for (const [key, value] of Object.entries(tmpSymLinks)) {
71
+ const key1 = makeSnap(key);
72
+ const value1 = makeSnap(value);
73
+ symLinks[key1] = value1;
74
+ }
75
+ return {
76
+ records: newRecords,
77
+ entrypoint: (0, common_1.substituteDenominator)(entrypoint, denominator),
78
+ symLinks,
79
+ };
80
+ }
81
+ function refiner(records, entrypoint, symLinks) {
82
+ purgeTopDirectories(records);
83
+ const denominator = (0, common_1.retrieveDenominator)(Object.keys(records));
84
+ return denominate(records, entrypoint, denominator, symLinks);
85
+ }
86
+ exports.default = refiner;
87
+ //# sourceMappingURL=refiner.js.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.platform = void 0;
4
+ exports.platform = {
5
+ macos: 'darwin',
6
+ win: 'win32',
7
+ linux: 'linux',
8
+ };
9
+ //# sourceMappingURL=types.js.map