mirror of
https://github.com/vee1e/flatbuffers.git
synced 2026-09-02 18:27:46 +00:00
[TS] Fix relative import paths of generated TypeScript code (#8880)
* Refactor logic that generates import paths in AddImport * Add new tests to validate relative import path fix * Generate goldens * Generate example code * Format TS generator file * Revert "Format TS generator file" This reverts commit 0f0b24aee9762b5ebac492af1560ab1e2a190581. * Fix merge conflicts --------- Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com>
This commit is contained in:
parent
d71c0ab4ac
commit
b8e3d215b8
15 changed files with 177 additions and 58 deletions
28
tests/ts/JavaScriptRelativeImportPathTest.js
Normal file
28
tests/ts/JavaScriptRelativeImportPathTest.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const headerPath = resolve(here, "relative_imports/transit/three/header.ts");
|
||||
|
||||
const contents = readFileSync(headerPath, "utf8");
|
||||
|
||||
const expectedImports = [
|
||||
"from '../one/info.js';",
|
||||
"from '../two/identity.js';",
|
||||
];
|
||||
|
||||
for (const expected of expectedImports) {
|
||||
if (!contents.includes(expected)) {
|
||||
throw new Error(`Missing relative import "${expected}" in ${headerPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
const forbidden = "../transit/";
|
||||
if (contents.includes(forbidden)) {
|
||||
throw new Error(
|
||||
`Found unexpected namespace segment in import path within ${headerPath}`
|
||||
);
|
||||
}
|
||||
|
||||
console.log("JavaScriptRelativeImportPathTest: OK");
|
||||
Loading…
Add table
Add a link
Reference in a new issue