Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ESM module types #1889

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
19ed47d
chore: upgraded tsup version to 8.0.0+
petertonysmith94 Mar 15, 2024
13333ed
chore: removed types from abi-typegen package.json
petertonysmith94 Mar 15, 2024
253e64b
chore: refactored postbuild to use tsup and emit declarations
petertonysmith94 Mar 15, 2024
94288d4
chore: refactored handlebars import to use the default export
petertonysmith94 Mar 15, 2024
75b0a18
chore: linting
petertonysmith94 Mar 18, 2024
c96c00b
chore: added changeset
petertonysmith94 Mar 18, 2024
ec77c6f
feat: added tsupDts configurations
petertonysmith94 Mar 19, 2024
40d713f
feat: emit typescript types via tsup
petertonysmith94 Mar 19, 2024
1b26c46
chore: removed postbuild.ts
petertonysmith94 Mar 20, 2024
938a315
feat: added verify-package-distro command
petertonysmith94 Mar 20, 2024
08be472
feat: added distribution node runner
petertonysmith94 Mar 20, 2024
4302f07
Merge branch 'master' into ps/bug/import-esm-abi-typegen
petertonysmith94 Mar 22, 2024
853141b
Merge branch 'master' into ps/bug/import-esm-abi-typegen
petertonysmith94 Mar 25, 2024
23c96a1
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into ps…
petertonysmith94 Mar 25, 2024
fb553ab
chore: linting
petertonysmith94 Mar 25, 2024
f803e1d
chore: synced the changeset with PR title
petertonysmith94 Mar 25, 2024
dfec259
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into ps…
petertonysmith94 Mar 25, 2024
2585937
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into ps…
petertonysmith94 Apr 3, 2024
279fdf8
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into ps…
petertonysmith94 Apr 4, 2024
666e19a
chore: publish preview pls
petertonysmith94 Apr 4, 2024
1c80bb4
chore: fixed lint rule "@typescript-eslint/require-await"
petertonysmith94 Apr 5, 2024
c9d44a7
fix: issue with normalize not identifying the constructor
petertonysmith94 Apr 5, 2024
a8fac0c
chore: lint
petertonysmith94 Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-cherries-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-typegen": minor
---

fix: ESM module types
2 changes: 1 addition & 1 deletion .github/workflows/pr-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: "Release PR to npm"
runs-on: ubuntu-latest
# comment out if:false to enable release PR to npm
if: false
# if: false
permissions: write-all
steps:
- name: Checkout
Expand Down
6 changes: 2 additions & 4 deletions internal/tsup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"name": "@internal/tsup",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
}
},
"files": [
Expand All @@ -18,7 +16,7 @@
"preinstall": "pnpm build",
"build": "tsup",
"build:watch": "tsup --watch",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0"
}
7 changes: 7 additions & 0 deletions internal/tsup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ export const binAndCli: Options = {
cli: 'src/cli.ts',
},
};

export const tsupDtsDefaults: Options = {
tsconfig: 'tsconfig.dts.json',
sourcemap: true,
dts: true,
clean: false,
}
9 changes: 9 additions & 0 deletions internal/tsup/tsconfig.dts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"],
"exclude": ["**/*.test.ts"]
}
11 changes: 11 additions & 0 deletions internal/tsup/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Options } from 'tsup';

import { tsupDtsDefaults } from './src';
import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults
};

export default configs;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"lint:package-jsons": "tsx ./scripts/lint-package-jsons",
"prettier:check": "prettier --check packages",
"prettier:format": "prettier --write packages",
"verify:package-distro": "tsx ./scripts/verify-package-distro",
"changeset:publish": "tsx ./scripts/changeset/changeset-publish",
"changeset:next": "tsx ./scripts/changeset/changeset-next",
"changeset:version-with-docs": "tsx ./scripts/changeset/changeset-version-with-docs",
Expand Down Expand Up @@ -99,7 +100,7 @@
"textlint": "^13.3.2",
"textlint-rule-no-dead-link": "^5.1.2",
"ts-generator": "^0.1.1",
"tsup": "^6.7.0",
"tsup": "^8.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgraded tsup to 8.0.0. We could go to 7.1.0 to allow for the following change, which enables the correct type files to be generated.

"tsx": "^4.7.0",
"turbo": "^1.8.8",
"typescript": "~5.2.2",
Expand Down
6 changes: 2 additions & 4 deletions packages/abi-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"engines": {
"node": "^18.18.2 || ^20.0.0"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
}
},
"files": [
Expand All @@ -23,7 +21,7 @@
"pretest": "pnpm build:forc",
"build:forc": "pnpm fuels-forc build -p test/fixtures/forc-projects --release",
"build": "tsup",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/abi-coder/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tsupDtsDefaults } from '@internal/tsup';
import type { Options } from 'tsup';

import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults,
};

export default configs;
12 changes: 4 additions & 8 deletions packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"engines": {
"node": "^18.18.2 || ^20.0.0"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
},
"./cli": {
"require": "./dist/cli.js",
"import": "./dist/cli.mjs",
"types": "./dist/cli.d.ts"
"import": "./dist/cli.mjs"
},
"./runTypegen": {
"require": "./dist/runTypegen.js",
"import": "./dist/runTypegen.mjs",
"types": "./dist/runTypegen.d.ts"
"import": "./dist/runTypegen.mjs"
}
},
"typesVersions": {
Expand All @@ -46,7 +42,7 @@
"pretest": "pnpm build:forc",
"build": "tsup",
"build:forc": "pnpm fuels-forc build -p test/fixtures/forc-projects --release",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/templates/renderHbsTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { versions } from '@fuel-ts/versions';
import { compile } from 'handlebars';
import Handlebars from 'handlebars';

import headerTemplate from './common/_header.hbs';

Expand All @@ -15,8 +15,8 @@ export function renderHbsTemplate(params: { template: string; data?: Record<stri
noEscape: true,
};

const renderTemplate = compile(template, options);
const renderHeaderTemplate = compile(headerTemplate, options);
const renderTemplate = Handlebars.compile(template, options);
const renderHeaderTemplate = Handlebars.compile(headerTemplate, options);

const text = renderTemplate({
...data,
Expand Down
11 changes: 11 additions & 0 deletions packages/abi-typegen/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tsupDtsDefaults } from '@internal/tsup';
import type { Options } from 'tsup';

import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults,
};

export default configs;
14 changes: 5 additions & 9 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"engines": {
"node": "^18.18.2 || ^20.0.0"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
},
"./configs": {
"require": "./dist/configs.js",
"import": "./dist/configs.mjs",
"types": "./dist/configs.d.ts"
"import": "./dist/configs.mjs"
},
"./test-utils": {
"require": "./dist/test-utils.js",
"import": "./dist/test-utils.mjs",
"types": "./dist/test-utils.d.ts"
"import": "./dist/test-utils.mjs"
}
},
"typesVersions": {
Expand All @@ -32,7 +28,7 @@
"./dist/configs.d.ts"
],
"test-utils": [
"./dist/test-utils/index.d.ts"
"./dist/test-utils.d.ts"
]
}
},
Expand All @@ -44,7 +40,7 @@
"prebuild": "pnpm build:operations",
"build:schema": "get-graphql-schema http://localhost:4000/graphql > src/providers/fuel-core-schema.graphql && prettier --write src/providers/fuel-core-schema.graphql",
"build:operations": "pnpm graphql-codegen",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ describe('Provider', () => {
test('custom fetch works with requestMiddleware', async () => {
let requestHeaders: HeadersInit | undefined;
await Provider.create(FUEL_NETWORK_URL, {
fetch: async (url, requestInit) => {
fetch: (url, requestInit): Promise<Response> => {
requestHeaders = requestInit?.headers;
return fetch(url, requestInit);
},
Expand All @@ -1192,7 +1192,7 @@ describe('Provider', () => {
test('custom fetch works with timeout', async () => {
const timeout = 500;
const provider = await Provider.create(FUEL_NETWORK_URL, {
fetch: async (url, requestInit) => fetch(url, requestInit),
fetch: (url, requestInit): Promise<Response> => fetch(url, requestInit),
timeout,
});
vi.spyOn(global, 'fetch').mockImplementationOnce((...args: unknown[]) =>
Expand Down
26 changes: 15 additions & 11 deletions packages/account/src/providers/utils/json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-param-reassign */
import { Address } from '@fuel-ts/address';
import { BN } from '@fuel-ts/math';
import { hexlify } from '@fuel-ts/utils';
import { clone } from 'ramda';

Expand All @@ -10,21 +12,23 @@ import { clone } from 'ramda';
/** @hidden */
function normalize(object: any) {
Object.keys(object).forEach((key) => {
switch (object[key]?.constructor.name) {
case 'Uint8Array':
object[key] = hexlify(object[key]);
const obj = object[key];

switch (true) {
case obj instanceof BN:
object[key] = obj.toHex();
break;
case 'Array':
object[key] = normalize(object[key]);
case obj instanceof Address:
object[key] = obj.toB256();
break;
case 'BN':
object[key] = object[key].toHex();
case obj instanceof Uint8Array:
object[key] = hexlify(obj);
break;
case 'Address':
object[key] = object[key].toB256();
case Array.isArray(obj):
object[key] = normalize(obj);
break;
case 'Object':
object[key] = normalize(object[key]);
case obj instanceof Object:
object[key] = normalize(obj);
break;
default:
break;
Expand Down
11 changes: 11 additions & 0 deletions packages/account/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tsupDtsDefaults } from '@internal/tsup';
import type { Options } from 'tsup';

import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults,
};

export default configs;
9 changes: 3 additions & 6 deletions packages/address/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"engines": {
"node": "^18.18.2 || ^20.0.0"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
},
"./configs": {
"require": "./dist/configs.js",
"import": "./dist/configs.mjs",
"types": "./dist/configs.d.ts"
"import": "./dist/configs.mjs"
}
},
"typesVersions": {
Expand All @@ -33,7 +30,7 @@
],
"scripts": {
"build": "tsup",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/address/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tsupDtsDefaults } from '@internal/tsup';
import type { Options } from 'tsup';

import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults,
};

export default configs;
6 changes: 2 additions & 4 deletions packages/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"engines": {
"node": "^18.18.2 || ^20.0.0"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
"import": "./dist/index.mjs"
}
},
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"postbuild": "tsx ../../scripts/postbuild.ts"
"postbuild": "tsup --config tsup.config.dts.ts"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/contract/tsup.config.dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tsupDtsDefaults } from '@internal/tsup';
import type { Options } from 'tsup';

import tsupPkg from './tsup.config';

const configs: Options = {
...tsupPkg,
...tsupDtsDefaults,
};

export default configs;
Loading
Loading