@driveflux/vercel 1.0.3 → 1.0.5

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.
@@ -1,540 +0,0 @@
1
- // @ts-check
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- copyDeploymentLockfile: function() {
14
- return copyDeploymentLockfile;
15
- },
16
- makeDeploymentLockfile: function() {
17
- return makeDeploymentLockfile;
18
- },
19
- removePackagesFromWorkspace: function() {
20
- return removePackagesFromWorkspace;
21
- },
22
- restoreLockfile: function() {
23
- return restoreLockfile;
24
- },
25
- runCommand: function() {
26
- return runCommand;
27
- }
28
- });
29
- var _nodechild_process = require("node:child_process");
30
- var _nodecrypto = /*#__PURE__*/ _interop_require_default(require("node:crypto"));
31
- var _promises = /*#__PURE__*/ _interop_require_default(require("node:fs/promises"));
32
- var _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
33
- var _yaml = require("yaml");
34
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
35
- try {
36
- var info = gen[key](arg);
37
- var value = info.value;
38
- } catch (error) {
39
- reject(error);
40
- return;
41
- }
42
- if (info.done) {
43
- resolve(value);
44
- } else {
45
- Promise.resolve(value).then(_next, _throw);
46
- }
47
- }
48
- function _async_to_generator(fn) {
49
- return function() {
50
- var self = this, args = arguments;
51
- return new Promise(function(resolve, reject) {
52
- var gen = fn.apply(self, args);
53
- function _next(value) {
54
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
55
- }
56
- function _throw(err) {
57
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
58
- }
59
- _next(undefined);
60
- });
61
- };
62
- }
63
- function _interop_require_default(obj) {
64
- return obj && obj.__esModule ? obj : {
65
- default: obj
66
- };
67
- }
68
- function _ts_generator(thisArg, body) {
69
- var f, y, t, g, _ = {
70
- label: 0,
71
- sent: function() {
72
- if (t[0] & 1) throw t[1];
73
- return t[1];
74
- },
75
- trys: [],
76
- ops: []
77
- };
78
- return g = {
79
- next: verb(0),
80
- "throw": verb(1),
81
- "return": verb(2)
82
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
83
- return this;
84
- }), g;
85
- function verb(n) {
86
- return function(v) {
87
- return step([
88
- n,
89
- v
90
- ]);
91
- };
92
- }
93
- function step(op) {
94
- if (f) throw new TypeError("Generator is already executing.");
95
- while(_)try {
96
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
97
- if (y = 0, t) op = [
98
- op[0] & 2,
99
- t.value
100
- ];
101
- switch(op[0]){
102
- case 0:
103
- case 1:
104
- t = op;
105
- break;
106
- case 4:
107
- _.label++;
108
- return {
109
- value: op[1],
110
- done: false
111
- };
112
- case 5:
113
- _.label++;
114
- y = op[1];
115
- op = [
116
- 0
117
- ];
118
- continue;
119
- case 7:
120
- op = _.ops.pop();
121
- _.trys.pop();
122
- continue;
123
- default:
124
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
125
- _ = 0;
126
- continue;
127
- }
128
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
129
- _.label = op[1];
130
- break;
131
- }
132
- if (op[0] === 6 && _.label < t[1]) {
133
- _.label = t[1];
134
- t = op;
135
- break;
136
- }
137
- if (t && _.label < t[2]) {
138
- _.label = t[2];
139
- _.ops.push(op);
140
- break;
141
- }
142
- if (t[2]) _.ops.pop();
143
- _.trys.pop();
144
- continue;
145
- }
146
- op = body.call(thisArg, _);
147
- } catch (e) {
148
- op = [
149
- 6,
150
- e
151
- ];
152
- y = 0;
153
- } finally{
154
- f = t = 0;
155
- }
156
- if (op[0] & 5) throw op[1];
157
- return {
158
- value: op[0] ? op[1] : void 0,
159
- done: true
160
- };
161
- }
162
- }
163
- var basePath = process.cwd();
164
- var copyDeploymentLockfile = function() {
165
- var _ref = _async_to_generator(function() {
166
- var stat;
167
- return _ts_generator(this, function(_state) {
168
- switch(_state.label){
169
- case 0:
170
- return [
171
- 4,
172
- _promises.default.stat("".concat(basePath, "/pnpm-lock-production.yaml"))
173
- ];
174
- case 1:
175
- stat = _state.sent();
176
- if (!stat.isFile()) return [
177
- 3,
178
- 3
179
- ];
180
- // If there is, copy it to pnpm-lock.yaml
181
- return [
182
- 4,
183
- _promises.default.copyFile("".concat(basePath, "/pnpm-lock-production.yaml"), "".concat(basePath, "/pnpm-lock.yaml"))
184
- ];
185
- case 2:
186
- _state.sent();
187
- _state.label = 3;
188
- case 3:
189
- return [
190
- 2
191
- ];
192
- }
193
- });
194
- });
195
- return function copyDeploymentLockfile() {
196
- return _ref.apply(this, arguments);
197
- };
198
- }();
199
- var removePackagesFromWorkspace = function() {
200
- var _ref = _async_to_generator(function() {
201
- var workspacePath, workspaceContent;
202
- return _ts_generator(this, function(_state) {
203
- switch(_state.label){
204
- case 0:
205
- workspacePath = _nodepath.default.resolve(basePath, "./pnpm-workspace.yaml");
206
- // Make a copy of the workspace
207
- return [
208
- 4,
209
- _promises.default.copyFile(workspacePath, "".concat(basePath, "/pnpm-workspace.yaml.bak"))
210
- ];
211
- case 1:
212
- _state.sent();
213
- return [
214
- 4,
215
- _promises.default.readFile(workspacePath, "utf8")
216
- ];
217
- case 2:
218
- workspaceContent = _yaml.parse.apply(void 0, [
219
- _state.sent()
220
- ]);
221
- workspaceContent.packages = [
222
- "apps/*"
223
- ];
224
- // Write the workspace without packages/*
225
- return [
226
- 4,
227
- _promises.default.writeFile(workspacePath, (0, _yaml.stringify)(workspaceContent))
228
- ];
229
- case 3:
230
- _state.sent();
231
- return [
232
- 2
233
- ];
234
- }
235
- });
236
- });
237
- return function removePackagesFromWorkspace() {
238
- return _ref.apply(this, arguments);
239
- };
240
- }();
241
- var makeDeploymentLockfile = function() {
242
- var _ref = _async_to_generator(function() {
243
- var lockfileChanged, error, output, e;
244
- return _ts_generator(this, function(_state) {
245
- switch(_state.label){
246
- case 0:
247
- return [
248
- 4,
249
- hasLockfileChanged()
250
- ];
251
- case 1:
252
- lockfileChanged = _state.sent();
253
- if (!lockfileChanged) {
254
- return [
255
- 2
256
- ];
257
- }
258
- console.log("Lockfile changed, generating production lockfile...");
259
- return [
260
- 4,
261
- removePackagesFromWorkspace()
262
- ];
263
- case 2:
264
- _state.sent();
265
- // Backup the lockfile
266
- return [
267
- 4,
268
- _promises.default.rename("".concat(basePath, "/pnpm-lock.yaml"), "".concat(basePath, "/pnpm-lock.yaml.bak"))
269
- ];
270
- case 3:
271
- _state.sent();
272
- _state.label = 4;
273
- case 4:
274
- _state.trys.push([
275
- 4,
276
- 6,
277
- ,
278
- 7
279
- ]);
280
- return [
281
- 4,
282
- copyDeploymentLockfile()
283
- ];
284
- case 5:
285
- _state.sent();
286
- return [
287
- 3,
288
- 7
289
- ];
290
- case 6:
291
- error = _state.sent();
292
- return [
293
- 3,
294
- 7
295
- ];
296
- case 7:
297
- _state.trys.push([
298
- 7,
299
- 12,
300
- ,
301
- 13
302
- ]);
303
- // Now we run pnpm i --lockfile-only to generate the lockfile without installing
304
- return [
305
- 4,
306
- runCommand("pnpm i --lockfile-only")
307
- ];
308
- case 8:
309
- _state.sent();
310
- // Let's copy the lockfile to pnpm-lock-production.yaml
311
- output = "".concat(basePath, "/pnpm-lock-production.yaml");
312
- return [
313
- 4,
314
- _promises.default.rename("".concat(basePath, "/pnpm-lock.yaml"), output)
315
- ];
316
- case 9:
317
- _state.sent();
318
- if (!lockfileChanged) return [
319
- 3,
320
- 11
321
- ];
322
- // Now write the hash
323
- return [
324
- 4,
325
- _promises.default.writeFile("".concat(basePath, "/pnpm-lock.yaml.hash"), lockfileChanged)
326
- ];
327
- case 10:
328
- _state.sent();
329
- _state.label = 11;
330
- case 11:
331
- console.log("Generated production lockfile at ".concat(output));
332
- return [
333
- 3,
334
- 13
335
- ];
336
- case 12:
337
- e = _state.sent();
338
- if (e.output) {
339
- console.log(e.output);
340
- console.log("\uD83D\uDEA8 You might have upgraded packages but did not publish them yet. If it's the case, then:");
341
- console.log("1. Run build:workspace and make sure there are no errors");
342
- console.log('2. Run "PNPM_PUBLISH_FLAGS="--no-git-checks" pnpm run publish:all". You must have the NPM_TOKEN with publish rights');
343
- console.log("3. Run make-deployment-lockfile again (or commit and let the hook run it for you)");
344
- } else {
345
- console.error(e);
346
- }
347
- return [
348
- 3,
349
- 13
350
- ];
351
- case 13:
352
- //
353
- return [
354
- 4,
355
- restoreLockfile()
356
- ];
357
- case 14:
358
- _state.sent();
359
- return [
360
- 2
361
- ];
362
- }
363
- });
364
- });
365
- return function makeDeploymentLockfile() {
366
- return _ref.apply(this, arguments);
367
- };
368
- }();
369
- /**
370
- *
371
- * @returns {Promise<string | false>}
372
- */ var hasLockfileChanged = function() {
373
- var _ref = _async_to_generator(function() {
374
- var newHash, _, _1, previousHash, error;
375
- return _ts_generator(this, function(_state) {
376
- switch(_state.label){
377
- case 0:
378
- _1 = (_ = _nodecrypto.default.createHash("sha256")).update;
379
- return [
380
- 4,
381
- _promises.default.readFile("".concat(basePath, "/pnpm-lock.yaml"), "utf8")
382
- ];
383
- case 1:
384
- newHash = _1.apply(_, [
385
- _state.sent()
386
- ]).digest("hex");
387
- _state.label = 2;
388
- case 2:
389
- _state.trys.push([
390
- 2,
391
- 4,
392
- ,
393
- 5
394
- ]);
395
- return [
396
- 4,
397
- _promises.default.readFile("".concat(basePath, "/pnpm-lock.yaml.hash"), "utf8")
398
- ];
399
- case 3:
400
- previousHash = _state.sent();
401
- return [
402
- 2,
403
- previousHash !== newHash ? newHash : false
404
- ];
405
- case 4:
406
- error = _state.sent();
407
- // If the command fails, assume the lockfile has changed to be on the safe side
408
- return [
409
- 2,
410
- newHash
411
- ];
412
- case 5:
413
- return [
414
- 2
415
- ];
416
- }
417
- });
418
- });
419
- return function hasLockfileChanged() {
420
- return _ref.apply(this, arguments);
421
- };
422
- }();
423
- var runCommand = function(command) {
424
- return new Promise(function(resolve, reject) {
425
- var output = "";
426
- var finalCommand = command.split(" ");
427
- var commandName = finalCommand.shift();
428
- if (!commandName) {
429
- return reject("No command to run");
430
- }
431
- var c = (0, _nodechild_process.spawn)(commandName, finalCommand);
432
- c.stdout.on("data", function(data) {
433
- output += data.toString();
434
- });
435
- c.stderr.on("error", function(error) {
436
- output += error.toString();
437
- });
438
- c.on("error", function(error) {
439
- reject(error.toString());
440
- });
441
- c.on("exit", function(code) {
442
- if (code) {
443
- var error = new Error("Command ".concat(command, " exited with code ").concat(code));
444
- // @ts-expect-error
445
- error.output = output;
446
- reject(error);
447
- } else {
448
- resolve(0);
449
- }
450
- });
451
- });
452
- };
453
- var restoreLockfile = function() {
454
- var _ref = _async_to_generator(function() {
455
- var lockStat, e, workspaceStat, e1;
456
- return _ts_generator(this, function(_state) {
457
- switch(_state.label){
458
- case 0:
459
- _state.trys.push([
460
- 0,
461
- 4,
462
- ,
463
- 5
464
- ]);
465
- return [
466
- 4,
467
- _promises.default.stat("".concat(basePath, "/pnpm-lock.yaml.bak"))
468
- ];
469
- case 1:
470
- lockStat = _state.sent();
471
- if (!lockStat.isFile()) return [
472
- 3,
473
- 3
474
- ];
475
- // Now we restore lockfile
476
- return [
477
- 4,
478
- _promises.default.rename("".concat(basePath, "/pnpm-lock.yaml.bak"), "".concat(basePath, "/pnpm-lock.yaml"))
479
- ];
480
- case 2:
481
- _state.sent();
482
- _state.label = 3;
483
- case 3:
484
- return [
485
- 3,
486
- 5
487
- ];
488
- case 4:
489
- e = _state.sent();
490
- return [
491
- 3,
492
- 5
493
- ];
494
- case 5:
495
- _state.trys.push([
496
- 5,
497
- 9,
498
- ,
499
- 10
500
- ]);
501
- return [
502
- 4,
503
- _promises.default.stat("".concat(basePath, "/pnpm-workspace.yaml.bak"))
504
- ];
505
- case 6:
506
- workspaceStat = _state.sent();
507
- if (!workspaceStat.isFile()) return [
508
- 3,
509
- 8
510
- ];
511
- // Restore the workspace
512
- return [
513
- 4,
514
- _promises.default.rename("".concat(basePath, "/pnpm-workspace.yaml.bak"), "".concat(basePath, "/pnpm-workspace.yaml"))
515
- ];
516
- case 7:
517
- _state.sent();
518
- _state.label = 8;
519
- case 8:
520
- return [
521
- 3,
522
- 10
523
- ];
524
- case 9:
525
- e1 = _state.sent();
526
- return [
527
- 3,
528
- 10
529
- ];
530
- case 10:
531
- return [
532
- 2
533
- ];
534
- }
535
- });
536
- });
537
- return function restoreLockfile() {
538
- return _ref.apply(this, arguments);
539
- };
540
- }();