Skip to content

arc.static() with fingerprinted assets doesn't work with typescript #19

@karlmolina

Description

@karlmolina

Describe the issue
Using fingerprinted static assets, the static.json file isn't deployed with typescript.

Steps to reproduce

  1. Checkout https://github.com/karlmolina/arc-typescript-fingerprint-bug/tree/main
  2. npm i
  3. arc deploy
  4. Open the deployed site
  5. See that the style.css file does not have a fingerprint suffix.

Expected behavior
The css file should be fingerprinted.

Additional context
I figured that the problem exists because the arc.static() function pulls the static.json file using a readFile and not an import which typescript doesn't know about.

I fixed the problem by making a plugin that copies the static.json file to the .build folder on hydrate.copy. A better workaround might be to rewrite arc.static() since this workaround isn't generalized for multiple lambdas.
See https://github.com/karlmolina/arc-typescript-fingerprint-bug/tree/fix

module.exports = {
  hydrate: {
    copy: async ({ arc, inventory, copy }) => {
      // Copy static.json to build
      const fs = require("fs").promises;
      const path = require("path");
      await fs.cp(
        path.join(process.cwd(), "public", "static.json"),
        path.join(
          process.cwd(),
          ".build",
          "http",
          "get-index",
          "node_modules",
          "@architect",
          "shared",
          "static.json",
        ),
      );
      console.log("Copied static.json to build");
    },
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions