Skip to content

Commit

Permalink
Merge pull request #4 from codibre/fix/relative-path
Browse files Browse the repository at this point in the history
fix: require relative path handling
  • Loading branch information
Farenheith authored Sep 23, 2024
2 parents 1bdece3 + 4cc87da commit b5fcb1d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function before() {
};
const processImports = (node: ts.Node) => {
try {
if (tsBinary.isImportClause(node) && mustImport.has(node) && moduleExists((node.parent.moduleSpecifier as any).text)) {
if (tsBinary.isImportClause(node) && mustImport.has(node) && moduleExists(sf, (node.parent.moduleSpecifier as any).text)) {
const { namedBindings } = node;
if (namedBindings) {
// Hack: if a import is flagged as transient and has links.referenced = true,
Expand Down
9 changes: 7 additions & 2 deletions src/module-exists.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { existsSync } from 'fs';
import { dirname } from 'path';
import { getModuleRealPath } from './ts-loader';
import ts from 'typescript';

export function moduleExists(moduleName: string) {
export function moduleExists(sf: ts.SourceFile, moduleName: string) {
try {
const tsConfigTreatedModuleName = getModuleRealPath(moduleName);
let tsConfigTreatedModuleName = getModuleRealPath(moduleName);
if (!tsConfigTreatedModuleName && moduleName.startsWith('.')) {
tsConfigTreatedModuleName = `${dirname(sf.fileName)}/${moduleName}`;
}
if (tsConfigTreatedModuleName
&& (existsSync(tsConfigTreatedModuleName)
|| existsSync(`${tsConfigTreatedModuleName}.ts`)
Expand Down

0 comments on commit b5fcb1d

Please sign in to comment.