Skip to content

Commit

Permalink
fix(template): update template for @ctix-declaration
Browse files Browse the repository at this point in the history
- update template for `@ctix-declaration`
  - fixed issue where semicolon was not added at the end of lines
  - fixed issue where newline character was not applied correctly
  • Loading branch information
imjuni committed Aug 21, 2024
1 parent 998e3be commit 6090359
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/modules/commands/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export async function bundling(buildOptions: TCommandBuildOptions, bundleOption:
const inlineDeclarationsRendered = await TemplateContainer.evaluate(
CE_TEMPLATE_NAME.DECLARATION_FILE_TEMPLATE,
{
options: { quote: bundleOption.quote },
options: { quote: bundleOption.quote, useSemicolon: bundleOption.useSemicolon },
declarations: getInlineDeclarationRenderData(inlineDeclarations, bundleOption),
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('getInlineDeclarationRenderData', () => {
tag: '@ctix-declaration',
pos: { line: 0, column: 0, start: 0 },
workspaces: undefined,
relativePath: '../c/d/a',
importPath: '../c/d/a',
extname: { origin: '.ts', render: '.js' },
},
{
Expand All @@ -52,7 +52,7 @@ describe('getInlineDeclarationRenderData', () => {
tag: '@ctix-declaration',
pos: { line: 0, column: 0, start: 0 },
workspaces: undefined,
relativePath: '../c/e/b',
importPath: '../c/e/b',
extname: { origin: '.ts', render: '.js' },
},
]);
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('getInlineDeclarationRenderData', () => {
tag: '@ctix-declaration',
pos: { line: 0, column: 0, start: 0 },
workspaces: undefined,
relativePath: `./${pathe.join(process.cwd(), '/a/b/c/d/a')}`,
importPath: `./${pathe.join(process.cwd(), '/a/b/c/d/a')}`,
extname: { origin: '.ts', render: '.js' },
},
{
Expand All @@ -104,7 +104,7 @@ describe('getInlineDeclarationRenderData', () => {
tag: '@ctix-declaration',
pos: { line: 0, column: 0, start: 0 },
workspaces: undefined,
relativePath: `./${pathe.join(process.cwd(), '/a/b/c/e/b')}`,
importPath: `./${pathe.join(process.cwd(), '/a/b/c/e/b')}`,
extname: { origin: '.ts', render: '.js' },
},
]);
Expand Down
4 changes: 2 additions & 2 deletions src/templates/modules/getInlineDeclarationRenderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export function getInlineDeclarationRenderData(
const dirname = pathe.dirname(declaration.filePath);
const basename = pathe.basename(declaration.filePath, extname);

const relativePath =
const importPath =
options.output != null
? addCurrentDirPrefix(posixRelative(options.output, pathe.join(dirname, basename)))
: replaceSepToPosix(`.${path.posix.sep}${pathe.join(dirname, basename)}`);

return {
...declaration,
relativePath,
importPath,
extname: {
origin: extname,
render: renderExtname,
Expand Down
3 changes: 1 addition & 2 deletions src/templates/templates/declarationFileTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const declarationFileTemplate = `
<%- it.declarations.forEach((declaration) => { -%>
import <%-= it.options.quote %><%= declaration.relativePath %><%= declaration.extname.render %><%= it.options.quote -%>
import <%-= it.options.quote %><%= declaration.importPath %><%= declaration.extname.render %><%= it.options.quote -%><%- if (it.options.useSemicolon) { -%><%-= ";" -%><%- } -%><%= "\\n" %>
<%- }) %>
`;

0 comments on commit 6090359

Please sign in to comment.