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

feat(compiler): enhance support for declare statements #150

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
"yargs": "^17.7.2"
},
"peerDependencies": {
"prettier": "^3",
"prettier-plugin-organize-imports": "^3",
"typescript": "^5"
"prettier": ">=3",
"prettier-plugin-organize-imports": ">=3",
"typescript": ">=5"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
1 change: 0 additions & 1 deletion src/compilers/isDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as tsm from 'ts-morph';

const declarationKindMap: Map<tsm.SyntaxKind, boolean> = new Map([
[tsm.SyntaxKind.ImportDeclaration, true],
[tsm.SyntaxKind.ModuleDeclaration, true],
]);

Expand Down
2 changes: 1 addition & 1 deletion src/compilers/isDeclarationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function isDeclarationFile(sourceFile: tsm.SourceFile) {
};
});

return statements.every((statement) => statement.isDeclaration);
return statements.some((statement) => statement.isDeclaration);
}
42 changes: 22 additions & 20 deletions src/modules/commands/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,31 +190,33 @@ export async function bundling(buildOptions: TCommandBuildOptions, bundleOption:
return { renderData, ...style };
});

const importsRendered = await TemplateContainer.evaluate(
const inlineDeclarationsRendered = await TemplateContainer.evaluate(
CE_TEMPLATE_NAME.DECLARATION_FILE_TEMPLATE,
{
options: { quote: bundleOption.quote },
declarations: await Promise.all(
inlineDeclarations.map((declaration) => {
const relativePath =
bundleOption.output != null
? addCurrentDirPrefix(
posixRelative(
bundleOption.output,
path.join(
inlineDeclarations
.filter((inlineDeclaration) => statementMap.get(inlineDeclaration.filePath) == null)
.map((declaration) => {
const relativePath =
bundleOption.output != null
? addCurrentDirPrefix(
posixRelative(
bundleOption.output,
path.join(
path.dirname(declaration.filePath),
path.basename(declaration.filePath, path.extname(declaration.filePath)),
),
),
)
: replaceSepToPosix(
`.${path.posix.sep}${path.join(
path.dirname(declaration.filePath),
path.basename(declaration.filePath, path.extname(declaration.filePath)),
),
),
)
: replaceSepToPosix(
`.${path.posix.sep}${path.join(
path.dirname(declaration.filePath),
path.basename(declaration.filePath, path.extname(declaration.filePath)),
)}`,
);
return { ...declaration, relativePath };
}),
)}`,
);
return { ...declaration, relativePath };
}),
),
},
);
Expand All @@ -232,7 +234,7 @@ export async function bundling(buildOptions: TCommandBuildOptions, bundleOption:
Spinner.it.start('output file exists check, ...');

const outputMap = new Map<string, string>();
outputMap.set(output, [importsRendered, ...exportsRendered].join('\n'));
outputMap.set(output, [inlineDeclarationsRendered, ...exportsRendered].join('\n'));
const fileExistReason = await checkOutputFile(outputMap);

if (!bundleOption.overwrite && !bundleOption.backup && fileExistReason.length > 0) {
Expand Down
Loading