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