@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,2 @@
1
+ export declare function exec(argv2: string[]): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,541 @@
1
+ "use strict";
2
+ /* eslint-disable require-atomic-updates */
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
+ exports.exec = void 0;
8
+ const assert_1 = __importDefault(require("assert"));
9
+ const fs_extra_1 = require("fs-extra");
10
+ const minimist_1 = __importDefault(require("minimist"));
11
+ const pkg_fetch_1 = require("@yao-pkg/pkg-fetch");
12
+ const path_1 = __importDefault(require("path"));
13
+ const log_1 = require("./log");
14
+ const help_1 = __importDefault(require("./help"));
15
+ const common_1 = require("./common");
16
+ const packer_1 = __importDefault(require("./packer"));
17
+ const chmod_1 = require("./chmod");
18
+ const producer_1 = __importDefault(require("./producer"));
19
+ const refiner_1 = __importDefault(require("./refiner"));
20
+ const fabricator_1 = require("./fabricator");
21
+ const walker_1 = __importDefault(require("./walker"));
22
+ const compress_type_1 = require("./compress_type");
23
+ const mach_o_1 = require("./mach-o");
24
+ const { version } = JSON.parse((0, fs_extra_1.readFileSync)(path_1.default.join(__dirname, '../package.json'), 'utf-8'));
25
+ function isConfiguration(file) {
26
+ return (0, common_1.isPackageJson)(file) || file.endsWith('.config.json');
27
+ }
28
+ // http://www.openwall.com/lists/musl/2012/12/08/4
29
+ const { hostArch, hostPlatform, isValidNodeRange, knownArchs, knownPlatforms, toFancyArch, toFancyPlatform, } = pkg_fetch_1.system;
30
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
31
+ const hostNodeRange = `node${process.version.match(/^v(\d+)/)[1]}`;
32
+ function parseTargets(items) {
33
+ // [ 'node6-macos-x64', 'node6-linux-x64' ]
34
+ const targets = [];
35
+ for (const item of items) {
36
+ const target = {
37
+ nodeRange: hostNodeRange,
38
+ platform: hostPlatform,
39
+ arch: hostArch,
40
+ };
41
+ if (item !== 'host') {
42
+ for (const token of item.split('-')) {
43
+ if (!token) {
44
+ continue;
45
+ }
46
+ if (isValidNodeRange(token)) {
47
+ target.nodeRange = token;
48
+ continue;
49
+ }
50
+ const p = toFancyPlatform(token);
51
+ if (knownPlatforms.indexOf(p) >= 0) {
52
+ target.platform = p;
53
+ continue;
54
+ }
55
+ const a = toFancyArch(token);
56
+ if (knownArchs.indexOf(a) >= 0) {
57
+ target.arch = a;
58
+ continue;
59
+ }
60
+ throw (0, log_1.wasReported)(`Unknown token '${token}' in '${item}'`);
61
+ }
62
+ }
63
+ targets.push(target);
64
+ }
65
+ return targets;
66
+ }
67
+ function stringifyTarget(target) {
68
+ const { nodeRange, platform, arch } = target;
69
+ return `${nodeRange}-${platform}-${arch}`;
70
+ }
71
+ function differentParts(targets) {
72
+ const nodeRanges = {};
73
+ const platforms = {};
74
+ const archs = {};
75
+ for (const target of targets) {
76
+ nodeRanges[target.nodeRange] = true;
77
+ platforms[target.platform] = true;
78
+ archs[target.arch] = true;
79
+ }
80
+ const result = {};
81
+ if (Object.keys(nodeRanges).length > 1) {
82
+ result.nodeRange = true;
83
+ }
84
+ if (Object.keys(platforms).length > 1) {
85
+ result.platform = true;
86
+ }
87
+ if (Object.keys(archs).length > 1) {
88
+ result.arch = true;
89
+ }
90
+ return result;
91
+ }
92
+ function stringifyTargetForOutput(output, target, different) {
93
+ const a = [output];
94
+ if (different.nodeRange) {
95
+ a.push(target.nodeRange);
96
+ }
97
+ if (different.platform) {
98
+ a.push(target.platform);
99
+ }
100
+ if (different.arch) {
101
+ a.push(target.arch);
102
+ }
103
+ return a.join('-');
104
+ }
105
+ function fabricatorForTarget({ nodeRange, arch }) {
106
+ let fabPlatform = hostPlatform;
107
+ if (hostArch !== arch &&
108
+ (hostPlatform === 'linux' || hostPlatform === 'alpine')) {
109
+ // With linuxstatic, it is possible to generate bytecode for different
110
+ // arch with simple QEMU configuration instead of the entire sysroot.
111
+ fabPlatform = 'linuxstatic';
112
+ }
113
+ return {
114
+ nodeRange,
115
+ platform: fabPlatform,
116
+ arch,
117
+ };
118
+ }
119
+ const dryRunResults = {};
120
+ async function needWithDryRun({ forceBuild, nodeRange, platform, arch, }) {
121
+ const result = await (0, pkg_fetch_1.need)({
122
+ dryRun: true,
123
+ forceBuild,
124
+ nodeRange,
125
+ platform,
126
+ arch,
127
+ });
128
+ (0, assert_1.default)(['exists', 'fetched', 'built'].indexOf(result) >= 0);
129
+ dryRunResults[result] = true;
130
+ }
131
+ const targetsCache = {};
132
+ async function needViaCache(target) {
133
+ const s = stringifyTarget(target);
134
+ let c = targetsCache[s];
135
+ if (c) {
136
+ return c;
137
+ }
138
+ const { forceBuild, nodeRange, platform, arch } = target;
139
+ c = await (0, pkg_fetch_1.need)({
140
+ forceBuild,
141
+ nodeRange,
142
+ platform,
143
+ arch,
144
+ });
145
+ targetsCache[s] = c;
146
+ return c;
147
+ }
148
+ async function exec(argv2) {
149
+ var _a, _b;
150
+ const argv = (0, minimist_1.default)(argv2, {
151
+ boolean: [
152
+ 'b',
153
+ 'build',
154
+ 'bytecode',
155
+ 'native-build',
156
+ 'd',
157
+ 'debug',
158
+ 'h',
159
+ 'help',
160
+ 'public',
161
+ 'v',
162
+ 'version',
163
+ 'signature',
164
+ ],
165
+ string: [
166
+ '_',
167
+ 'c',
168
+ 'config',
169
+ 'o',
170
+ 'options',
171
+ 'output',
172
+ 'outdir',
173
+ 'out-dir',
174
+ 'out-path',
175
+ 'public-packages',
176
+ 'no-dict',
177
+ 't',
178
+ 'target',
179
+ 'targets',
180
+ 'C',
181
+ 'compress',
182
+ ],
183
+ default: { bytecode: true, 'native-build': true, signature: true },
184
+ });
185
+ if (argv.h || argv.help) {
186
+ (0, help_1.default)();
187
+ return;
188
+ }
189
+ // version
190
+ if (argv.v || argv.version) {
191
+ // eslint-disable-next-line no-console
192
+ console.log(version);
193
+ return;
194
+ }
195
+ log_1.log.info(`pkg@${version}`);
196
+ // debug
197
+ log_1.log.debugMode = argv.d || argv.debug;
198
+ // forceBuild
199
+ const forceBuild = argv.b || argv.build;
200
+ // doCompress
201
+ const algo = argv.C || argv.compress || 'None';
202
+ let doCompress = compress_type_1.CompressType.None;
203
+ switch (algo.toLowerCase()) {
204
+ case 'brotli':
205
+ case 'br':
206
+ doCompress = compress_type_1.CompressType.Brotli;
207
+ break;
208
+ case 'gzip':
209
+ case 'gz':
210
+ doCompress = compress_type_1.CompressType.GZip;
211
+ break;
212
+ case 'none':
213
+ break;
214
+ default:
215
+ throw (0, log_1.wasReported)(`Invalid compression algorithm ${algo} ( should be None, Brotli or Gzip)`);
216
+ }
217
+ if (doCompress !== compress_type_1.CompressType.None) {
218
+ // eslint-disable-next-line no-console
219
+ console.log('compression: ', compress_type_1.CompressType[doCompress]);
220
+ }
221
+ // _
222
+ if (!argv._.length) {
223
+ throw (0, log_1.wasReported)('Entry file/directory is expected', [
224
+ 'Pass --help to see usage information',
225
+ ]);
226
+ }
227
+ if (argv._.length > 1) {
228
+ throw (0, log_1.wasReported)('Not more than one entry file/directory is expected');
229
+ }
230
+ // input
231
+ let input = path_1.default.resolve(argv._[0]);
232
+ if (!(0, fs_extra_1.existsSync)(input)) {
233
+ throw (0, log_1.wasReported)('Input file does not exist', [input]);
234
+ }
235
+ if ((await (0, fs_extra_1.stat)(input)).isDirectory()) {
236
+ input = path_1.default.join(input, 'package.json');
237
+ if (!(0, fs_extra_1.existsSync)(input)) {
238
+ throw (0, log_1.wasReported)('Input file does not exist', [input]);
239
+ }
240
+ }
241
+ // inputJson
242
+ let inputJson;
243
+ let inputJsonName;
244
+ if (isConfiguration(input)) {
245
+ inputJson = JSON.parse(await (0, fs_extra_1.readFile)(input, 'utf-8'));
246
+ inputJsonName = inputJson.name;
247
+ if (inputJsonName) {
248
+ inputJsonName = inputJsonName.split('/').pop(); // @org/foo
249
+ }
250
+ }
251
+ // inputBin
252
+ let inputBin;
253
+ if (inputJson) {
254
+ let { bin } = inputJson;
255
+ if (bin) {
256
+ if (typeof bin === 'object') {
257
+ if (bin[inputJsonName]) {
258
+ bin = bin[inputJsonName];
259
+ }
260
+ else {
261
+ bin = bin[Object.keys(bin)[0]]; // TODO multiple inputs to pkg them all?
262
+ }
263
+ }
264
+ inputBin = path_1.default.resolve(path_1.default.dirname(input), bin);
265
+ if (!(0, fs_extra_1.existsSync)(inputBin)) {
266
+ throw (0, log_1.wasReported)('Bin file does not exist (taken from package.json ' +
267
+ "'bin' property)", [inputBin]);
268
+ }
269
+ }
270
+ }
271
+ if (inputJson && !inputBin) {
272
+ throw (0, log_1.wasReported)("Property 'bin' does not exist in", [input]);
273
+ }
274
+ // inputFin
275
+ const inputFin = inputBin || input;
276
+ // config
277
+ let config = argv.c || argv.config;
278
+ if (inputJson && config) {
279
+ throw (0, log_1.wasReported)("Specify either 'package.json' or config. Not both");
280
+ }
281
+ // configJson
282
+ let configJson;
283
+ if (config) {
284
+ config = path_1.default.resolve(config);
285
+ if (!(0, fs_extra_1.existsSync)(config)) {
286
+ throw (0, log_1.wasReported)('Config file does not exist', [config]);
287
+ }
288
+ // eslint-disable-next-line import/no-dynamic-require, global-require
289
+ configJson = require(config); // may be either json or js
290
+ if (!configJson.name &&
291
+ !configJson.files &&
292
+ !configJson.dependencies &&
293
+ !configJson.pkg) {
294
+ // package.json not detected
295
+ configJson = { pkg: configJson };
296
+ }
297
+ }
298
+ // output, outputPath
299
+ let output = argv.o || argv.output;
300
+ let outputPath = argv['out-path'] || argv.outdir || argv['out-dir'];
301
+ let autoOutput = false;
302
+ if (output && outputPath) {
303
+ throw (0, log_1.wasReported)("Specify either 'output' or 'out-path'. Not both");
304
+ }
305
+ if (!output) {
306
+ let name;
307
+ if (inputJson) {
308
+ name = inputJsonName;
309
+ if (!name) {
310
+ throw (0, log_1.wasReported)("Property 'name' does not exist in", [argv._[0]]);
311
+ }
312
+ }
313
+ else if (configJson) {
314
+ name = configJson.name;
315
+ }
316
+ if (!name) {
317
+ name = path_1.default.basename(inputFin);
318
+ }
319
+ if (!outputPath) {
320
+ if (inputJson && inputJson.pkg) {
321
+ outputPath = inputJson.pkg.outputPath;
322
+ }
323
+ else if (configJson && configJson.pkg) {
324
+ outputPath = configJson.pkg.outputPath;
325
+ }
326
+ outputPath = outputPath || '';
327
+ }
328
+ autoOutput = true;
329
+ const ext = path_1.default.extname(name);
330
+ output = name.slice(0, -ext.length || undefined);
331
+ output = path_1.default.resolve(outputPath || '', output);
332
+ }
333
+ else {
334
+ output = path_1.default.resolve(output);
335
+ }
336
+ // targets
337
+ const sTargets = argv.t || argv.target || argv.targets || '';
338
+ if (typeof sTargets !== 'string') {
339
+ throw (0, log_1.wasReported)(`Something is wrong near ${JSON.stringify(sTargets)}`);
340
+ }
341
+ let targets = parseTargets(sTargets.split(',').filter((t) => t));
342
+ if (!targets.length) {
343
+ let jsonTargets;
344
+ if (inputJson && inputJson.pkg) {
345
+ jsonTargets = inputJson.pkg.targets;
346
+ }
347
+ else if (configJson && configJson.pkg) {
348
+ jsonTargets = configJson.pkg.targets;
349
+ }
350
+ if (jsonTargets) {
351
+ targets = parseTargets(jsonTargets);
352
+ }
353
+ }
354
+ if (!targets.length) {
355
+ if (!autoOutput) {
356
+ targets = parseTargets(['host']);
357
+ (0, assert_1.default)(targets.length === 1);
358
+ }
359
+ else {
360
+ targets = parseTargets(['linux', 'macos', 'win']);
361
+ }
362
+ log_1.log.info('Targets not specified. Assuming:', `${targets.map((t) => stringifyTarget(t)).join(', ')}`);
363
+ }
364
+ // differentParts
365
+ const different = differentParts(targets);
366
+ // targets[].output
367
+ for (const target of targets) {
368
+ let file;
369
+ if (targets.length === 1) {
370
+ file = output;
371
+ }
372
+ else {
373
+ file = stringifyTargetForOutput(output, target, different);
374
+ }
375
+ if (target.platform === 'win' && path_1.default.extname(file) !== '.exe') {
376
+ file += '.exe';
377
+ }
378
+ target.output = file;
379
+ }
380
+ // bakes
381
+ const bakes = (argv.options || '')
382
+ .split(',')
383
+ .filter((bake) => bake)
384
+ .map((bake) => `--${bake}`);
385
+ // check if input is going
386
+ // to be overwritten by output
387
+ for (const target of targets) {
388
+ if (target.output === inputFin) {
389
+ if (autoOutput) {
390
+ target.output += `-${target.platform}`;
391
+ }
392
+ else {
393
+ throw (0, log_1.wasReported)('Refusing to overwrite input file', [inputFin]);
394
+ }
395
+ }
396
+ }
397
+ // fetch targets
398
+ const { bytecode } = argv;
399
+ const nativeBuild = argv['native-build'];
400
+ for (const target of targets) {
401
+ target.forceBuild = forceBuild;
402
+ await needWithDryRun(target);
403
+ target.fabricator = fabricatorForTarget(target);
404
+ if (bytecode) {
405
+ await needWithDryRun(Object.assign(Object.assign({}, target.fabricator), { forceBuild }));
406
+ }
407
+ }
408
+ if (dryRunResults.fetched && !dryRunResults.built) {
409
+ log_1.log.info('Fetching base Node.js binaries to PKG_CACHE_PATH');
410
+ }
411
+ for (const target of targets) {
412
+ target.binaryPath = await needViaCache(target);
413
+ const f = target.fabricator;
414
+ if (f && bytecode) {
415
+ f.binaryPath = await needViaCache(f);
416
+ if (f.platform === 'macos') {
417
+ // ad-hoc sign the base binary temporarily to generate bytecode
418
+ // due to the new mandatory signing requirement
419
+ const signedBinaryPath = `${f.binaryPath}-signed`;
420
+ await (0, fs_extra_1.remove)(signedBinaryPath);
421
+ (0, fs_extra_1.copyFileSync)(f.binaryPath, signedBinaryPath);
422
+ try {
423
+ (0, mach_o_1.signMachOExecutable)(signedBinaryPath);
424
+ }
425
+ catch (_c) {
426
+ throw (0, log_1.wasReported)('Cannot generate bytecode', [
427
+ 'pkg fails to run "codesign" utility. Due to the mandatory signing',
428
+ 'requirement of macOS, executables must be signed. Please ensure the',
429
+ 'utility is installed and properly configured.',
430
+ ]);
431
+ }
432
+ f.binaryPath = signedBinaryPath;
433
+ }
434
+ if (f.platform !== 'win') {
435
+ await (0, chmod_1.plusx)(f.binaryPath);
436
+ }
437
+ }
438
+ }
439
+ // marker
440
+ let marker;
441
+ if (configJson) {
442
+ marker = {
443
+ config: configJson,
444
+ base: path_1.default.dirname(config),
445
+ configPath: config,
446
+ };
447
+ }
448
+ else {
449
+ marker = {
450
+ config: inputJson || {},
451
+ base: path_1.default.dirname(input),
452
+ configPath: input,
453
+ };
454
+ }
455
+ marker.toplevel = true;
456
+ // public
457
+ const params = {};
458
+ if (argv.public) {
459
+ params.publicToplevel = true;
460
+ }
461
+ if (argv['public-packages']) {
462
+ params.publicPackages = argv['public-packages'].split(',');
463
+ if (((_a = params.publicPackages) === null || _a === void 0 ? void 0 : _a.indexOf('*')) !== -1) {
464
+ params.publicPackages = ['*'];
465
+ }
466
+ }
467
+ if (argv['no-dict']) {
468
+ params.noDictionary = argv['no-dict'].split(',');
469
+ if (((_b = params.noDictionary) === null || _b === void 0 ? void 0 : _b.indexOf('*')) !== -1) {
470
+ params.noDictionary = ['*'];
471
+ }
472
+ }
473
+ // records
474
+ let records;
475
+ let entrypoint = inputFin;
476
+ let symLinks;
477
+ const addition = isConfiguration(input) ? input : undefined;
478
+ const walkResult = await (0, walker_1.default)(marker, entrypoint, addition, params);
479
+ entrypoint = walkResult.entrypoint;
480
+ records = walkResult.records;
481
+ symLinks = walkResult.symLinks;
482
+ const refineResult = (0, refiner_1.default)(records, entrypoint, symLinks);
483
+ entrypoint = refineResult.entrypoint;
484
+ records = refineResult.records;
485
+ symLinks = refineResult.symLinks;
486
+ const backpack = (0, packer_1.default)({ records, entrypoint, bytecode, symLinks });
487
+ log_1.log.debug('Targets:', JSON.stringify(targets, null, 2));
488
+ for (const target of targets) {
489
+ if (target.output && (0, fs_extra_1.existsSync)(target.output)) {
490
+ if ((await (0, fs_extra_1.stat)(target.output)).isFile()) {
491
+ await (0, fs_extra_1.remove)(target.output);
492
+ }
493
+ else {
494
+ throw (0, log_1.wasReported)('Refusing to overwrite non-file output', [
495
+ target.output,
496
+ ]);
497
+ }
498
+ }
499
+ else if (target.output) {
500
+ await (0, fs_extra_1.mkdirp)(path_1.default.dirname(target.output));
501
+ }
502
+ await (0, producer_1.default)({
503
+ backpack,
504
+ bakes,
505
+ slash: target.platform === 'win' ? '\\' : '/',
506
+ target: target,
507
+ symLinks,
508
+ doCompress,
509
+ nativeBuild,
510
+ });
511
+ if (target.platform !== 'win' && target.output) {
512
+ if (argv.signature && target.platform === 'macos') {
513
+ // patch executable to allow code signing
514
+ const buf = (0, mach_o_1.patchMachOExecutable)((0, fs_extra_1.readFileSync)(target.output));
515
+ (0, fs_extra_1.writeFileSync)(target.output, buf);
516
+ try {
517
+ // sign executable ad-hoc to workaround the new mandatory signing requirement
518
+ // users can always replace the signature if necessary
519
+ (0, mach_o_1.signMachOExecutable)(target.output);
520
+ }
521
+ catch (_d) {
522
+ if (target.arch === 'arm64') {
523
+ log_1.log.warn('Unable to sign the macOS executable', [
524
+ 'Due to the mandatory code signing requirement, before the',
525
+ 'executable is distributed to end users, it must be signed.',
526
+ 'Otherwise, it will be immediately killed by kernel on launch.',
527
+ 'An ad-hoc signature is sufficient.',
528
+ 'To do that, run pkg on a Mac, or transfer the executable to a Mac',
529
+ 'and run "codesign --sign - <executable>", or (if you use Linux)',
530
+ 'install "ldid" utility to PATH and then run pkg again',
531
+ ]);
532
+ }
533
+ }
534
+ }
535
+ await (0, chmod_1.plusx)(target.output);
536
+ }
537
+ }
538
+ (0, fabricator_1.shutdown)();
539
+ }
540
+ exports.exec = exec;
541
+ //# sourceMappingURL=index.js.map
package/lib-es5/log.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wasReported = exports.log = void 0;
4
+ var log_1 = require("@yao-pkg/pkg-fetch/lib-es5/log");
5
+ Object.defineProperty(exports, "log", { enumerable: true, get: function () { return log_1.log; } });
6
+ Object.defineProperty(exports, "wasReported", { enumerable: true, get: function () { return log_1.wasReported; } });
7
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signMachOExecutable = exports.patchMachOExecutable = void 0;
4
+ const child_process_1 = require("child_process");
5
+ function parseCStr(buf) {
6
+ for (let i = 0; i < buf.length; i += 1) {
7
+ if (buf[i] === 0) {
8
+ return buf.slice(0, i).toString();
9
+ }
10
+ }
11
+ }
12
+ function patchCommand(type, buf, file) {
13
+ // segment_64
14
+ if (type === 0x19) {
15
+ const name = parseCStr(buf.slice(0, 16));
16
+ if (name === '__LINKEDIT') {
17
+ const fileoff = buf.readBigUInt64LE(32);
18
+ const vmsizePatched = BigInt(file.length) - fileoff;
19
+ const filesizePatched = vmsizePatched;
20
+ buf.writeBigUInt64LE(vmsizePatched, 24);
21
+ buf.writeBigUInt64LE(filesizePatched, 40);
22
+ }
23
+ }
24
+ // symtab
25
+ if (type === 0x2) {
26
+ const stroff = buf.readUInt32LE(8);
27
+ const strsizePatched = file.length - stroff;
28
+ buf.writeUInt32LE(strsizePatched, 12);
29
+ }
30
+ }
31
+ function patchMachOExecutable(file) {
32
+ const align = 8;
33
+ const hsize = 32;
34
+ const ncmds = file.readUInt32LE(16);
35
+ const buf = file.slice(hsize);
36
+ for (let offset = 0, i = 0; i < ncmds; i += 1) {
37
+ const type = buf.readUInt32LE(offset);
38
+ offset += 4;
39
+ const size = buf.readUInt32LE(offset) - 8;
40
+ offset += 4;
41
+ patchCommand(type, buf.slice(offset, offset + size), file);
42
+ offset += size;
43
+ if (offset & align) {
44
+ offset += align - (offset & align);
45
+ }
46
+ }
47
+ return file;
48
+ }
49
+ exports.patchMachOExecutable = patchMachOExecutable;
50
+ function signMachOExecutable(executable) {
51
+ try {
52
+ (0, child_process_1.execFileSync)('codesign', ['-f', '--sign', '-', executable], {
53
+ stdio: 'inherit',
54
+ });
55
+ }
56
+ catch (_a) {
57
+ (0, child_process_1.execFileSync)('ldid', ['-Cadhoc', '-S', executable], { stdio: 'inherit' });
58
+ }
59
+ }
60
+ exports.signMachOExecutable = signMachOExecutable;
61
+ //# sourceMappingURL=mach-o.js.map