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