Skip to content

Commit eb1ed1c

Browse files
authored
[Api-Augment] Add js extensions to imports to support esm fully (#1635)
# Goal To make sure that the generated api-augment javascript can be used directly with node 16+ and in browsers when using es modules, we needed to use the full path See: https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_resolution_algorithm # Discussion - Added the `.js` - Added the linter to enforce it
1 parent d3914e4 commit eb1ed1c

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

js/api-augment/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"avoidEscape": true
2828
}
2929
],
30-
"import/extensions": "off",
30+
"import/extensions": ["error", "always", { "ignorePackages": true } ],
3131
"mocha/no-setup-in-describe": "off",
3232
"prettier/prettier": "error",
3333
"no-use-before-define": "off",

js/api-augment/definitions/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Add a default export here for each definition
22
// export { default as pallet } from "./pallet";
33

4-
export { default as msa } from "./msa";
5-
export { default as messages } from "./messages";
6-
export { default as schemas } from "./schemas";
7-
export { default as statefulStorage } from "./statefulStorage";
8-
export { default as handles } from "./handles";
9-
export { default as frequency } from "./frequency";
4+
export { default as msa } from "./msa.js";
5+
export { default as messages } from "./messages.js";
6+
export { default as schemas } from "./schemas.js";
7+
export { default as statefulStorage } from "./statefulStorage.js";
8+
export { default as handles } from "./handles.js";
9+
export { default as frequency } from "./frequency.js";

js/api-augment/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ExtDef } from "@polkadot/types/extrinsic/signedExtensions/types";
2-
import "./interfaces/types-lookup";
3-
import "./interfaces/augment-api";
4-
import "./interfaces/augment-types";
5-
import "./interfaces/index";
6-
import * as definitions from "./interfaces/definitions";
2+
import "./interfaces/types-lookup.js";
3+
import "./interfaces/augment-api.js";
4+
import "./interfaces/augment-types.js";
5+
import "./interfaces/index.js";
6+
import * as definitions from "./interfaces/definitions.js";
77

88
/**
99
* Build up the types for ApiPromise.create
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "../definitions";
1+
export * from "../definitions/index.js";

js/api-augment/scripts/pre-gen.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ files.forEach(file => {
2222

2323
// Pipe over the exports into the interfaces
2424
const definitionsExportFile = path.join(interfacePath, "definitions.ts");
25-
fs.writeFileSync(definitionsExportFile, `export * from "../definitions";\n`);
25+
fs.writeFileSync(definitionsExportFile, `export * from "../definitions/index.js";\n`);

js/api-augment/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "assert";
2-
import { options } from "../index";
2+
import { options } from "../index.js";
33
import { ApiPromise } from "@polkadot/api";
44
import { MockProvider } from "@polkadot/rpc-provider/mock";
55
import { TypeRegistry } from "@polkadot/types";

js/api-augment/test/types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import { TypeRegistry } from "@polkadot/types";
3-
import { types } from "../index";
3+
import { types } from "../index.js";
44

55
describe("types", function () {
66
it("should be able to successfully register", function () {

0 commit comments

Comments
 (0)