Skip to content

Commit

Permalink
Merge pull request #4815 from microsoft/bugifx/ts-es6-imports
Browse files Browse the repository at this point in the history
fix: TS imports are now es6 imports
  • Loading branch information
baywet authored Jun 12, 2024
2 parents b3912c0 + ac9e11a commit 4e584d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- TypeScript imports are now using ES6 imports with the .js extension.

## [1.15.0] - 2024-06-06

### Added
Expand Down Expand Up @@ -56,7 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761)
- Fix scalar member composed type serialization in PHP [#2827](https://github.com/microsoft/kiota/issues/2827)
- Trims unused components from output openApi document when generating plugins [#4672](https://github.com/microsoft/kiota/issues/4672)
- Fixes missing imports for UntypedNode when backingstore is enabled in Java.
- Fixes missing imports for UntypedNode when backingstore is enabled in Java.
- Renames `name_to_be_defined` plugin type to `apiplugin` [#4713](https://github.com/microsoft/kiota/issues/4713)

## [1.14.0] - 2024-05-02
Expand Down Expand Up @@ -620,7 +622,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed unused generated import for PHP Generation.
- Fixed a bug where long namespaces would make Ruby packaging fail.
- Fixed a bug where classes with namespace names are generated outside namespace in Python. [#2188](https://github.com/microsoft/kiota/issues/2188)
- Changed signature of escaped reserved names from {x}_escaped to {x}_ in line with Python style guides.
- Changed signature of escaped reserved names from {x}*escaped to {x}* in line with Python style guides.
- Add null checks in generated Shell language code.
- Fixed a bug where Go indexers would fail to pass the index parameter.
- Fixed a bug where path segments with parameters could be missing words. [#2209](https://github.com/microsoft/kiota/issues/2209)
Expand Down Expand Up @@ -1369,4 +1371,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Initial GitHub release

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
using Kiota.Builder.Extensions;

namespace Kiota.Builder.Writers.TypeScript;
public class TypescriptRelativeImportManager : RelativeImportManager

public class TypescriptRelativeImportManager(string namespacePrefix, char namespaceSeparator) : RelativeImportManager(namespacePrefix, namespaceSeparator)
{
public TypescriptRelativeImportManager(string namespacePrefix, char namespaceSeparator) : base(namespacePrefix, namespaceSeparator)
{
}
/// <summary>
/// Returns the relative import path for the given using and import context namespace.
/// </summary>
Expand All @@ -26,9 +22,14 @@ public override (string, string, string) GetRelativeImportPathForUsing(CodeUsing
} : (codeUsing.Name, null);

if (typeDef == null)
return (importSymbol, codeUsing.Alias, "./"); // it's relative to the folder, with no declaration (default failsafe)
return (importSymbol, codeUsing.Alias, $"./{IndexFileName}"); // it's relative to the folder, with no declaration (default failsafe)
var importNamespace = typeDef.GetImmediateParentOfType<CodeNamespace>();
var importPath = GetImportRelativePathFromNamespaces(currentNamespace, importNamespace);
if (importPath.EndsWith('/'))
importPath += IndexFileName;
else
importPath += ".js";
return (importSymbol, codeUsing.Alias, importPath);
}
private const string IndexFileName = "index.js";
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ReplacesImportsSubNamespace()
};
declaration.AddUsings(nUsing);
var result = importManager.GetRelativeImportPathForUsing(nUsing, graphNS);
Assert.Equal("./messages/", result.Item3);
Assert.Equal("./messages/index.js", result.Item3);
}
[Fact]
public void ReplacesImportsParentNamespace()
Expand All @@ -70,7 +70,7 @@ public void ReplacesImportsParentNamespace()
};
declaration.AddUsings(nUsing);
var result = importManager.GetRelativeImportPathForUsing(nUsing, modelsNS);
Assert.Equal("../messages/", result.Item3);
Assert.Equal("../messages/index.js", result.Item3);
}
[Fact]
public void ReplacesImportsInOtherTrunk()
Expand Down Expand Up @@ -118,8 +118,8 @@ public void ReplacesImportsInOtherTrunk()
declaration2.AddUsings(nUsing2);
var result = importManager.GetRelativeImportPathForUsing(nUsing, usedRangeNS1);
var result2 = importManager.GetRelativeImportPathForUsing(nUsing2, usedRangeNS2);
Assert.Equal("../../../../", result.Item3);
Assert.Equal("../../", result2.Item3);
Assert.Equal("../../../../index.js", result.Item3);
Assert.Equal("../../index.js", result2.Item3);
}
[Fact]
public void ReplacesImportsSameNamespace()
Expand All @@ -141,7 +141,7 @@ public void ReplacesImportsSameNamespace()
};
declaration.AddUsings(nUsing);
var result = importManager.GetRelativeImportPathForUsing(nUsing, graphNS);
Assert.Equal("./", result.Item3);
Assert.Equal("./index.js", result.Item3);
}

[Fact]
Expand All @@ -165,6 +165,6 @@ public void ReplacesImportsSameNamespaceIndex()
};
declaration.AddUsings(nUsing);
var result = importManager.GetRelativeImportPathForUsing(nUsing, graphNS);
Assert.Equal("./", result.Item3);
Assert.Equal("./index.js", result.Item3);
}
}

0 comments on commit 4e584d2

Please sign in to comment.