Skip to content

Commit

Permalink
chore: address comments on pr
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 20, 2024
1 parent 0bddfba commit 76ee795
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 71 deletions.
59 changes: 0 additions & 59 deletions handlebars.ts

This file was deleted.

57 changes: 55 additions & 2 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,63 @@ import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import handlebars from 'handlebars';
import type { RollupOptions } from 'rollup';
import { defineConfig } from 'rollup';
import { defineConfig, type Plugin } from 'rollup';

import { handlebarsPlugin } from './handlebars';
/**
* Custom plugin to parse handlebar imports and precompile
* the template on the fly. This reduces runtime by about
* half on large projects.
*/
export function handlebarsPlugin(): Plugin {
return {
name: 'handlebars',
resolveId: (file: any, importer: any) => {
if (path.extname(file) === '.hbs') {
return path.resolve(path.dirname(importer), file);
}
return null;
},
load: (file: any) => {
if (path.extname(file) === '.hbs') {
const template = readFileSync(file, 'utf8').toString().trim();
const templateSpec = handlebars.precompile(template, {
knownHelpers: {
camelCase: true,
dataParameters: true,
debugThis: true,
enumKey: true,
enumName: true,
enumUnionType: true,
enumValue: true,
equals: true,
escapeComment: true,
escapeDescription: true,
escapeNewline: true,
exactArray: true,
ifdef: true,
ifOperationDataOptional: true,
intersection: true,
modelImports: true,
modelsExports: true,
modelUnionType: true,
nameOperationDataType: true,
notEquals: true,
operationDataType: true,
useDateType: true,
},
knownHelpersOnly: true,
noEscape: true,
preventIndent: true,
strict: true,
});
return `export default ${templateSpec};`;
}
return null;
},
};
}

const __dirname = fileURLToPath(new URL('.', import.meta.url));

Expand Down
8 changes: 0 additions & 8 deletions src/utils/__mocks__/fileSystem.ts

This file was deleted.

2 changes: 1 addition & 1 deletion vitest.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';

import { defineConfig } from 'vitest/config';

import { handlebarsPlugin } from './handlebars';
import { handlebarsPlugin } from './rollup.config';

export default defineConfig({
plugins: [handlebarsPlugin()],
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';

import { configDefaults, defineConfig } from 'vitest/config';

import { handlebarsPlugin } from './handlebars';
import { handlebarsPlugin } from './rollup.config';

export default defineConfig({
plugins: [handlebarsPlugin()],
Expand Down

0 comments on commit 76ee795

Please sign in to comment.