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

Skipped page (file content is empty) warning is not useful for type-only TypeScript files with esbuild #707

Closed
domenic opened this issue Dec 18, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@domenic
Copy link

domenic commented Dec 18, 2024

Version

2.4.3

Platform

Windows

What steps will reproduce the bug?

I have a TypeScript file which just centralizes some type definitions.

Whenever I build my Lume site, I get an unhelpful warning telling me that the corresponding .js file is empty and will be skipped. But this should not be a warning; this is expected.

How often does it reproduce? Is there a required condition?

Full repro:

deno.json

{
  "imports": {
    "lume/": "https://deno.land/x/lume@v2.4.3/"
  },
  "tasks": {
    "lume": "echo \"import 'lume/cli.ts'\" | deno run -A -",
    "build": "deno task lume",
    "serve": "deno task lume -s"
  },
  "compilerOptions": {
    "types": [
      "lume/types.ts"
    ]
  }
}

_config.ts

import lume from "lume/mod.ts";
import esbuild from "lume/plugins/esbuild.ts";

const site = lume({
  src: "./src",
});

site.copy([".html"]);

site.use(esbuild({
  extensions: [".ts"],
  options: {
    bundle: false,
    minify: false,
    treeShaking: false,
    keepNames: false,
  },
}));

export default site;

src/types.ts

export type StringAlias = string;

src/test.ts

import { StringAlias } from "./types.ts";

const string: StringAlias = "Hello, world!";

document.body.innerHTML = string;

src/index.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>Test</title>

<script type="module" src="test.js"></script>

What is the expected behavior?

When running deno run build, I'd get something like

$ deno run build
Task build deno task lume
Task lume echo "import 'lume/cli.ts'" | deno run -A -
Loading config file file:///C:/Users/d/OneDrive%20-%20domenic.me/Code/WIP/lume-test/_config.ts
🔥 /test.js <- /test.ts
🔥 /index.html <- /index.html
🍾 Site built into ./_site
  3 files generated in 0.03 seconds

What do you see instead?

I get

$ deno run build
Task build deno task lume
Task lume echo "import 'lume/cli.ts'" | deno run -A -
Loading config file file:///C:/Users/d/OneDrive%20-%20domenic.me/Code/WIP/lume-test/_config.ts
WARN [Lume] Skipped page /types.js (file content is empty)
🔥 /test.js <- /test.ts
🔥 /index.html <- /index.html
🍾 Site built into ./_site
  3 files generated in 0.03 seconds

Additional information

  • It'd be ideal if this situation could be detected and handled without me having to manually annotate the files in _config.ts.

  • It's a little strange the message says "Skipped page" because a JavaScript file is not a page.

  • /cc @bryophyta who seems to have originally implemented this warning in Warn user when empty files are skipped #221.

@domenic domenic added the bug Something isn't working label Dec 18, 2024
@oscarotero
Copy link
Member

That's not a bug. Lume pages are not only html pages. Learn about html pages and asset pages. It's just the way to tell you that Lume won't save a file with no content.

I understand the issue but I don't know if it's easy to fix. It's like if you have a javascript file with all code commented (and removed by a minifier). The best way to do this is ignoring the file renaming it to _types.ts or in the _config.ts file adding the site.ignore("types.ts").

Maybe, due it's only a file with types declarations, you can rename it to types.d.ts. I'm not sure if Lume ignored the .d.ts files but definitely it should. I can make Lume to ignore this extension by default. What do you think?

oscarotero added a commit that referenced this issue Dec 18, 2024
@domenic
Copy link
Author

domenic commented Dec 19, 2024

I'd never used personally-written .d.ts files before, and the documentation doesn't make it seem like it would work. But I just tested renaming my file to use that extension, and it seems to work well! So I think this is a pretty good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants