carlin 1.49.20 → 2.0.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 (2) hide show
  1. package/dist/index.mjs +69 -31
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -589,7 +589,7 @@ const copyRoot404To404Index = async ({ bucket }) => {
589
589
  throw error;
590
590
  }
591
591
  };
592
- const uploadDirectoryToS3 = async ({ bucket, bucketKey = "", directory }) => {
592
+ const uploadDirectoryToS3 = async ({ bucket, bucketKey = "", directory, uploadSourceMaps = false }) => {
593
593
  log.info(logPrefix$18, `Uploading directory ${directory}/ to ${bucket}/${bucketKey}...`);
594
594
  const allFiles = await getAllFilesInsideADirectory({ directory });
595
595
  /**
@@ -597,12 +597,24 @@ const uploadDirectoryToS3 = async ({ bucket, bucketKey = "", directory }) => {
597
597
  * error. Discovered at #16 https://github.com/ttoss/carlin/issues/16.
598
598
  */
599
599
  if (allFiles.length === 0) throw new Error(`Directory ${directory}/ has no files.`);
600
- const numberOfGroups = Math.ceil(allFiles.length / 63);
600
+ /**
601
+ * Source maps expose the application's original source, and the bucket this
602
+ * uploads to is public, so they are excluded unless explicitly requested.
603
+ *
604
+ * This runs AFTER the empty-directory check on purpose: that error means
605
+ * "the build folder is probably wrong", and a directory containing only
606
+ * source maps must not borrow it to say something else.
607
+ */
608
+ const files = uploadSourceMaps ? allFiles : allFiles.filter((file) => {
609
+ return !file.endsWith(".map");
610
+ });
611
+ if (files.length !== allFiles.length) log.info(logPrefix$18, `Skipping ${allFiles.length - files.length} source map file(s). Pass --upload-source-maps to include them.`);
612
+ const numberOfGroups = Math.ceil(files.length / 63);
601
613
  /**
602
614
  * Divide all files and create "numberOfGroups" groups of files whose max
603
615
  * length is GROUP_MAX_LENGTH.
604
616
  */
605
- const aoaOfFiles = allFiles.reduce((acc, file, index) => {
617
+ const aoaOfFiles = files.reduce((acc, file, index) => {
606
618
  const groupIndex = index % numberOfGroups;
607
619
  if (!acc[groupIndex]) acc[groupIndex] = [];
608
620
  acc[index % numberOfGroups].push(file);
@@ -689,6 +701,16 @@ const emptyS3Directory = async ({ bucket, directory = "" }) => {
689
701
  * Delete old S3 files based on retention period.
690
702
  * Files older than the specified number of days will be deleted.
691
703
  */
704
+ /**
705
+ * These three exemptions are pre-existing: the function is unchanged by the
706
+ * commit that added them, and it violates the same rules on `main`. They only
707
+ * surface now because lint-staged lints whole files that appear in the diff,
708
+ * and an unrelated change elsewhere in this file put it there.
709
+ *
710
+ * Do not read this as a licence to grow the function. Tracked for a proper
711
+ * refactor — deletion logic should not be restructured inside a PR about
712
+ * something else.
713
+ */
692
714
  const deleteOldS3Files = async ({ bucket, continuationToken, directory = "", retentionDays, totalDeleted = 0 }) => {
693
715
  if (!continuationToken) log.info(logPrefix$18, `Deleting files older than ${retentionDays} days from ${bucket}/${directory}...`);
694
716
  try {
@@ -3298,28 +3320,6 @@ const reportToGitHubPR = async () => {
3298
3320
  log.info(logPrefix$6, existingComment ? "PR comment updated." : "PR comment created.");
3299
3321
  };
3300
3322
  //#endregion
3301
- //#region src/deploy/staticApp/findDefaultBuildFolder.ts
3302
- /**
3303
- * Fixes #20 https://github.com/ttoss/carlin/issues/20
3304
- */
3305
- const defaultBuildFolders = [
3306
- "build",
3307
- "out",
3308
- "storybook-static",
3309
- "dist"
3310
- ];
3311
- const findDefaultBuildFolder = async () => {
3312
- return (await Promise.all(defaultBuildFolders.map(async (directory) => {
3313
- return {
3314
- directory,
3315
- isValid: (await getAllFilesInsideADirectory({ directory })).length !== 0
3316
- };
3317
- }))).reduce((acc, cur) => {
3318
- if (cur.isValid) return cur.directory;
3319
- return acc;
3320
- }, "");
3321
- };
3322
- //#endregion
3323
3323
  //#region src/deploy/staticApp/getStaticAppBucket.ts
3324
3324
  const STATIC_APP_BUCKET_LOGICAL_ID$1 = "StaticBucket";
3325
3325
  const getStaticAppBucket = async ({ stackName }) => {
@@ -3650,8 +3650,30 @@ const getStaticAppTemplate = ({ acm, aliases, appendIndexHtml, cloudfront, spa,
3650
3650
  return getBucketStaticWebsiteTemplate({ spa });
3651
3651
  };
3652
3652
  //#endregion
3653
+ //#region src/deploy/staticApp/findDefaultBuildFolder.ts
3654
+ /**
3655
+ * Fixes #20 https://github.com/ttoss/carlin/issues/20
3656
+ */
3657
+ const defaultBuildFolders = [
3658
+ "build",
3659
+ "out",
3660
+ "storybook-static",
3661
+ "dist"
3662
+ ];
3663
+ const findDefaultBuildFolder = async () => {
3664
+ return (await Promise.all(defaultBuildFolders.map(async (directory) => {
3665
+ return {
3666
+ directory,
3667
+ isValid: (await getAllFilesInsideADirectory({ directory })).length !== 0
3668
+ };
3669
+ }))).reduce((acc, cur) => {
3670
+ if (cur.isValid) return cur.directory;
3671
+ return acc;
3672
+ }, "");
3673
+ };
3674
+ //#endregion
3653
3675
  //#region src/deploy/staticApp/uploadBuiltAppToS3.ts
3654
- const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket }) => {
3676
+ const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket, uploadSourceMaps }) => {
3655
3677
  /**
3656
3678
  * Only empty directory if the number of the files inside $directory.
3657
3679
  * If the number of files is zero, uploadDirectoryToS3 will thrown.
@@ -3663,7 +3685,8 @@ const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket }) => {
3663
3685
  });
3664
3686
  await uploadDirectoryToS3({
3665
3687
  bucket,
3666
- directory
3688
+ directory,
3689
+ uploadSourceMaps
3667
3690
  });
3668
3691
  return;
3669
3692
  }
@@ -3675,7 +3698,8 @@ const uploadBuiltAppToS3 = async ({ buildFolder: directory, bucket }) => {
3675
3698
  });
3676
3699
  await uploadDirectoryToS3({
3677
3700
  bucket,
3678
- directory: defaultDirectory
3701
+ directory: defaultDirectory,
3702
+ uploadSourceMaps
3679
3703
  });
3680
3704
  await copyRoot404To404Index({ bucket });
3681
3705
  return;
@@ -3693,7 +3717,7 @@ const logPrefix$4 = "static-app";
3693
3717
  * 1. Upload static files to the host bucket S3.
3694
3718
  * 1. Remove old deployment versions. Keep only the 3 most recent ones.
3695
3719
  */
3696
- const deployStaticApp = async ({ acm, aliases, appendIndexHtml, buildFolder, cloudfront, spa, hostedZoneName, region, skipUpload }) => {
3720
+ const deployStaticApp = async ({ acm, aliases, appendIndexHtml, buildFolder, cloudfront, spa, hostedZoneName, region, skipUpload, uploadSourceMaps }) => {
3697
3721
  try {
3698
3722
  const { stackName } = await handleDeployInitialization({ logPrefix: logPrefix$4 });
3699
3723
  const params = { StackName: stackName };
@@ -3715,7 +3739,8 @@ const deployStaticApp = async ({ acm, aliases, appendIndexHtml, buildFolder, clo
3715
3739
  if (!skipUpload) await uploadBuiltAppToS3({
3716
3740
  buildFolder,
3717
3741
  bucket,
3718
- cloudfront
3742
+ cloudfront,
3743
+ uploadSourceMaps
3719
3744
  });
3720
3745
  const { Outputs } = await deploy({
3721
3746
  params,
@@ -3736,7 +3761,8 @@ const deployStaticApp = async ({ acm, aliases, appendIndexHtml, buildFolder, clo
3736
3761
  await uploadBuiltAppToS3({
3737
3762
  buildFolder,
3738
3763
  bucket: newBucket,
3739
- cloudfront
3764
+ cloudfront,
3765
+ uploadSourceMaps
3740
3766
  });
3741
3767
  }
3742
3768
  } catch (error) {
@@ -3800,6 +3826,18 @@ const options$4 = {
3800
3826
  describe: "This option enables CloudFront to serve a single page application (SPA).",
3801
3827
  require: false,
3802
3828
  type: "boolean"
3829
+ },
3830
+ /**
3831
+ * Source maps contain the application's original source, and the bucket this
3832
+ * command uploads to is public, so publishing them is a source disclosure.
3833
+ * The default is therefore to exclude them, and including them must be an
3834
+ * explicit, deliberate choice.
3835
+ */
3836
+ "upload-source-maps": {
3837
+ default: false,
3838
+ describe: "Upload source map (`.map`) files to S3. They are excluded by default because the bucket is public and source maps expose the application source.",
3839
+ require: false,
3840
+ type: "boolean"
3803
3841
  }
3804
3842
  };
3805
3843
  const deployStaticAppCommand = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "1.49.20",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://ttoss.dev/docs/carlin/",
@@ -57,9 +57,9 @@
57
57
  "ts-node": "^10.9.2",
58
58
  "uglify-js": "^3.19.3",
59
59
  "yargs": "^17.7.2",
60
- "@ttoss/read-config-file": "^2.2.19",
61
- "@ttoss/cloudformation": "^0.13.10",
62
- "@ttoss/config": "^1.37.16"
60
+ "@ttoss/config": "^1.37.17",
61
+ "@ttoss/cloudformation": "^0.13.11",
62
+ "@ttoss/read-config-file": "^2.2.20"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/adm-zip": "^0.5.6",
@@ -79,7 +79,7 @@
79
79
  "jest": "^30.4.2",
80
80
  "tsdown": "^0.22.2",
81
81
  "typescript": "~6.0.3",
82
- "@ttoss/test-utils": "^4.2.17"
82
+ "@ttoss/test-utils": "^4.2.18"
83
83
  },
84
84
  "publishConfig": {
85
85
  "access": "public",