Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumontjonathan committed Jan 5, 2025
1 parent 4a7ce53 commit f884cef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,16 @@ describe('Evaluation of imported values works based on configuration', () => {
});

describe('Module resolution commonJS', () => {
afterEach(() => {
moduleResolve.mockReset();
});

test('Recognizes .ts stylex imports when resolving .js relative imports', () => {
moduleResolve.mockReturnValue({
pathname: '/project/otherFile.stylex.ts',
moduleResolve.mockImplementation((value) => {
if (!value.endsWith('/otherFile.stylex.ts')) {
throw new Error('File not found');
}
return new URL('file:///project/otherFile.stylex.ts');
});

const transformation = transform(
Expand Down
20 changes: 9 additions & 11 deletions packages/babel-plugin/src/utils/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,18 +657,16 @@ function possibleAliasedPaths(
return result;
}

// Try importing without adding any extension
// and then every supported extension
const getPossibleFilePaths = (filePath: string) => {
const extension = path.extname(filePath);
const filePathWithoutSourceExtension =
extension === '' || !EXTENSIONS.includes(extension)
? filePath
: filePath.slice(0, -extension.length);
// Try importing without adding any extension
// and then every supported extension
return [
filePath,
...EXTENSIONS.map((ext) => filePathWithoutSourceExtension + ext),
];
const filePathHasCodeExtension = EXTENSIONS.includes(extension);
const filePathNoCodeExtension = filePathHasCodeExtension
? filePath.slice(0, -extension.length)
: filePath;

return [filePath, ...EXTENSIONS.map((ext) => filePathNoCodeExtension + ext)];
};

// a function that resolves the absolute path of a file when given the
Expand All @@ -695,7 +693,7 @@ const filePathResolver = (
try {
return moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath))
.pathname;
} catch (error) {
} catch {
continue;
}
}
Expand Down

0 comments on commit f884cef

Please sign in to comment.