Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from inliner to web-resource-inliner #4266

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

w00000dy
Copy link
Contributor

@w00000dy w00000dy commented Nov 9, 2024

This migrates from the old inliner package to the web-resource-inliner package.

Now we don't get this warning anymore:

(node:29032) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

If you are wondering why the flash size increased, it is because the old inline package did not respect /*! these comments */ with exclamation marks.
Now, if you look at the source code, you can see the iro.js license.

Before:

RAM:   [=         ]  14.8% (used 48472 bytes from 327680 bytes)
Flash: [========= ]  86.8% (used 1365765 bytes from 1572864 bytes)

grafik

Now:

RAM:   [=         ]  14.8% (used 48472 bytes from 327680 bytes)
Flash: [========= ]  86.8% (used 1365845 bytes from 1572864 bytes)

grafik

This fixes #4166.

Summary by CodeRabbit

  • Chores
    • Enhanced internal asset processing by replacing an older inlining method with a more efficient approach, ensuring smoother HTML compression and improved page delivery.
    • Upgraded critical dependency versions to boost system stability and maintain a reliable performance environment for a better overall experience.

@softhack007 softhack007 added dependencies Pull requests that update a dependency file good job labels Dec 1, 2024
@softhack007 softhack007 added this to the 0.16.0 candidate milestone Dec 1, 2024
@netmindz netmindz changed the base branch from 0_15 to main December 16, 2024 13:26
@w00000dy
Copy link
Contributor Author

w00000dy commented Feb 9, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Feb 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Feb 9, 2025

Walkthrough

The changes update the dependencies and related inlining code. In package.json, the dependency "inliner" has been removed and replaced with "web-resource-inliner", and the nodemon version has been bumped. In tools/cdata.js, the HTML inlining process has been modified to use the new library’s inline.html method while the overall control flow remains largely unchanged.

Changes

File(s) Change Summary
package.json Removed dependency "inliner", added "web-resource-inliner" (v7.0.0), and updated "nodemon" version from "^3.1.7" to "^3.1.9".
tools/cdata.js Replaced inliner module with web-resource-inliner in the writeHtmlGzipped function; updated the inlining call to inline.html using fileContent and relativeTo.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant WG as writeHtmlGzipped
    participant I as inline.html
    participant M as Minifier
    participant G as GZIP
    participant F as File System

    C ->> WG: Invoke writeHtmlGzipped(file, relativeTo)
    WG ->> I: Call inline.html(fileContent, relativeTo)
    I -->> WG: Return inlined HTML
    WG ->> M: Minify HTML content
    M -->> WG: Return minified HTML
    WG ->> G: Compress minified HTML
    G -->> WG: Return gzipped data
    WG ->> F: Write gzipped output to file
    F -->> WG: File write confirmation
    WG -->> C: Return success
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove deprecated punycode usage (#4166) No changes addressing the punycode deprecation were made.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b64cd36 and 58962f8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tools/cdata.js (2 hunks)
🔇 Additional comments (2)
package.json (1)

28-29: Verify the status of web-resource-inliner package.

Let's check if the new package is actively maintained and secure.

✅ Verification successful

🌐 Web query:

What is the latest version of web-resource-inliner? When was it last updated? Is it actively maintained?

💡 Result:

The latest version of **web-resource-inliner** is **7.0.0**, last updated on **August 17, 2024** according to its npm registry entry[5][9]. This represents a major update from previous versions like v5.x (July 2020)[9] and v4.x (November 2023)[1].

Key maintenance indicators:
- The package received TypeScript definition updates through **@types/web-resource-inliner@4.2.5** in November 2023[1]
- Recent documentation changes include security updates (XSS vulnerability fixes) and expanded database integration features[4]
- The GitHub repository shows ongoing development with recent additions like service worker support and Postgres JDBC driver compatibility[6][4]

However, there are no commits or releases documented in the search results after August 2024[5], suggesting development activity has slowed in the last 6 months (as of February 2025). For critical production use, verify compatibility with current Node.js versions and security requirements[6][9].

Citations:

- 1: https://classic.yarnpkg.com/en/package/@types/web-resource-inliner
- 2: https://carldesouza.com/refreshing-a-web-resource-in-unified-interface-with-javascript-the-new-way/
- 3: https://support.uptime.com/hc/en-us/articles/360016256840-Status-Page-Forms-and-Fields
- 4: https://secure.croydon.gov.uk/eforms/doc/Changes_in_this_release.htm
- 5: https://www.npmjs.com/package/web-resource-inliner
- 6: https://github.com/remy/inliner/
- 7: https://html.spec.whatwg.org/multipage/webappapis.html
- 8: https://developers.google.com/apps-script/docs/release-notes?hl=en
- 9: https://classic.yarnpkg.com/en/package/web-resource-inliner
- 10: https://community.dynamics.com/forums/thread/details/?threadid=8a7e148d-c2e4-47ff-966a-2ca1899b0732

Web-resource-inliner package status verified

  • The latest version is 7.0.0, and it was last updated on August 17, 2024.
  • Maintenance indicators such as recent TypeScript definition updates (November 2023), security documentation changes (including XSS vulnerability fixes), and new features in the GitHub repository confirm active support.
  • Although there have been no commits or releases after August 2024, the overall evidence supports that the package is maintained and secure for production use, with the caveat to verify compatibility with your current Node.js environment.
tools/cdata.js (1)

20-20: LGTM!

The module import has been updated to use the new package.

Comment on lines +131 to +150
inline.html({
fileContent: fs.readFileSync(sourceFile, "utf8"),
relativeTo: path.dirname(sourceFile),
strict: true,
},
async function (error, html) {
if (error) throw error;

html = adoptVersionAndRepo(html);
const originalLength = html.length;
html = await minify(html, "html-minify");
const result = zlib.gzipSync(html, { level: zlib.constants.Z_BEST_COMPRESSION });
console.info("Minified and compressed " + sourceFile + " from " + originalLength + " to " + result.length + " bytes");
const array = hexdump(result);
let src = singleHeader;
src += `const uint16_t PAGE_${page}_L = ${result.length};\n`;
src += `const uint8_t PAGE_${page}[] PROGMEM = {\n${array}\n};\n\n`;
console.info("Writing " + resultFile);
fs.writeFileSync(resultFile, src);
});
html = adoptVersionAndRepo(html);
const originalLength = html.length;
html = await minify(html, "html-minify");
const result = zlib.gzipSync(html, { level: zlib.constants.Z_BEST_COMPRESSION });
console.info("Minified and compressed " + sourceFile + " from " + originalLength + " to " + result.length + " bytes");
const array = hexdump(result);
let src = singleHeader;
src += `const uint16_t PAGE_${page}_L = ${result.length};\n`;
src += `const uint8_t PAGE_${page}[] PROGMEM = {\n${array}\n};\n\n`;
console.info("Writing " + resultFile);
fs.writeFileSync(resultFile, src);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify error handling and options configuration.

The migration to web-resource-inliner looks good, but a few suggestions to improve the implementation:

  1. Consider adding error handling for the file read operation
  2. The 'strict' option is set but other potentially useful options like 'images', 'svgs' might be worth considering

Consider this improved implementation:

-  inline.html({
-    fileContent: fs.readFileSync(sourceFile, "utf8"),
-    relativeTo: path.dirname(sourceFile),
-    strict: true,
-  },
+  try {
+    const fileContent = fs.readFileSync(sourceFile, "utf8");
+    inline.html({
+      fileContent,
+      relativeTo: path.dirname(sourceFile),
+      strict: true,
+      images: true,
+      svgs: true,
+    },
     async function (error, html) {
       if (error) throw error;
       // ... rest of the code ...
     });
+  } catch (error) {
+    console.error(`Error reading file ${sourceFile}:`, error);
+    throw error;
+  }

🏁 Script executed:

#!/bin/bash
# Print lines 120-160 of tools/cdata.js to verify error handling and option configuration
sed -n '120,160p' tools/cdata.js

Length of output: 1579


Inline HTML error handling and option configuration need improvement.

  • The file read operation via fs.readFileSync is not wrapped within a try-catch block, meaning any file read errors aren't caught before passing data to inline.html.
  • The current inline.html options only include strict mode. Additional options like images and svgs—which could enhance behavior—are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file good job
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dev problem] The punycode module is deprecated
2 participants