Skip to content

🐛 webpack.config.js stub treats .d.ts files as entries #80

Description

@gfazioli

Repro

  1. Generate a v2 plugin (fresh boilerplate or php bones migrate:to-v2).
  2. Place a TypeScript declaration file in resources/assets/apps/, for example global.d.ts with the usual:
    declare module '*.png' {
      const value: string;
      export default value;
    }
  3. yarn build

Observed

public/apps/global.d.js and public/apps/global.d.asset.php are emitted as if global.d.ts were a real entry, polluting the output and (if they get enqueued by name) producing an empty/broken script.

The webpack compilation itself succeeds — the bug is purely in entry discovery.

Expected

.d.ts files are TypeScript-only declarations. They should be ignored by the auto-discovery glob.

Root cause

In the stub generated by migrate:to-v2 (and shipped in all boilerplates) we do:

// webpack.config.js (stub) — single-file apps branch
glob.sync('resources/assets/apps/*.{ts,tsx,js,jsx}').forEach((file) => {
  const name = path.basename(file).replace(/\.(ts|tsx|js|jsx)$/, '');
  entries[`apps/${name}`] = `./${file}`;
});

*.ts matches *.d.ts, and the .replace(...) trims only the outer .ts, leaving global.d as the entry name. A file named components.d.ts, types.d.ts, etc. all fall into the same trap.

Suggested fix

Filter .d.ts out of the glob result. One-line change:

glob.sync('resources/assets/apps/*.{ts,tsx,js,jsx}')
  .filter((file) => !file.endsWith('.d.ts'))
  .forEach((file) => {
    const name = path.basename(file).replace(/\.(ts|tsx|js|jsx)$/, '');
    entries[`apps/${name}`] = `./${file}`;
  });

(Or the equivalent glob.sync(..., { ignore: '**/*.d.ts' }).)

This has to land in two places:

  1. src/Console/stubs/webpack-config.stub — so fresh migrate:to-v2 runs pick it up.
  2. Documented as a manual patch for plugins that already migrated before the fix.

Workaround (for already-migrated plugins)

Move .d.ts files out of resources/assets/apps/ (e.g. to resources/assets/types/) and extend tsconfig.json include accordingly. That's what I did on Scotty during its v2 alignment.

Impact

Low. Purely cosmetic — spurious public/apps/<name>.d.js files and their asset PHP. Only hits projects that keep their declaration files inside the apps folder. But confusing when you stumble across it, and the fix is a one-liner.

Target

Good candidate for v2.0.4 alongside any other small follow-ups.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions