• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marekdedic / rollup-plugin-htaccess / 12674136002

08 Jan 2025 03:50PM UTC coverage: 96.46% (-1.5%) from 97.935%
12674136002

Pull #204

github

marekdedic
Added basic vitest tests
Pull Request #204: Switched to vitest

289 of 304 branches covered (95.07%)

327 of 339 relevant lines covered (96.46%)

470.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/plugin.ts
1
import type { PluginContext, Plugin as RollupPlugin } from "rollup";
2
import type { Plugin as VitePlugin } from "vite";
3

4
import { extractMetaCSP, type ExtractMetaCSPOptions } from "./extractMetaCSP";
5
import { buildSpec, type Spec } from "./spec";
6
import { readTemplate } from "./template";
7

8
/**
9
 * @public
10
 */
11
export interface Options {
12
  extractMetaCSP: ExtractMetaCSPOptions;
13
  fileName: string;
14
  spec: Spec;
15
  template: string | undefined;
16
}
17

18
/**
19
 * @public
20
 */
21
export function htaccess(opts?: Partial<Options>): RollupPlugin & VitePlugin {
22
  const options: Options = {
1,998✔
23
    extractMetaCSP: { enabled: false },
24
    fileName: ".htaccess",
25
    spec: {},
26
    template: undefined,
27
    ...opts,
28
  };
29
  let root = "";
1,998✔
30

31
  const rollupPlugin: RollupPlugin & VitePlugin = {
1,998✔
32
    configResolved: (config: { root: string }): void => {
33
      root = config.root;
936✔
34
    },
35
    async generateBundle(): Promise<void> {
36
      this.emitFile({
1,938✔
37
        fileName: options.fileName,
38
        source: await buildHtaccessFile(this, options, root),
39
        type: "asset",
40
      });
41
    },
42
    name: "htaccess",
43
    ...extractMetaCSP(options),
44
  };
45
  return rollupPlugin;
1,998✔
46
}
47

48
async function buildHtaccessFile(
49
  context: PluginContext,
50
  options: Options,
51
  root: string,
52
): Promise<string> {
53
  let output = "";
1,938✔
54
  if (options.template !== undefined) {
1,938!
55
    output += await readTemplate(context, root, options.template);
×
56
  }
57
  output += buildSpec(context, options.spec);
1,938✔
58
  return output;
1,914✔
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc