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

Fixing WASM-NPM packaging and publishing #835

Merged
merged 10 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ jobs:
git push
export PAGES_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$BRANCH_B64/index.html"
echo "$PAGES_URL"
echo "Codecov report $PAGES_URL" >> $GITHUB_STEP_SUMMARY
echo "Codecov report $PAGES_URL" >> $GITHUB_STEP_SUMMARY


rustfmt:
runs-on: buildjet-4vcpu-ubuntu-2204
Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 8.6.9
version: ^9.4.0

- name: Setup Node
uses: actions/setup-node@v3
Expand Down Expand Up @@ -298,7 +298,7 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 8.6.9
version: ^9.4.0

- name: Setup Node
uses: actions/setup-node@v3
Expand Down
5 changes: 3 additions & 2 deletions .npm/.scripts/prepare-wasm-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ build_wasm_npm_pkg_for ()
write_template ${NAME_DASHED} ${NAME_UNDERSCORED} src/index.js

# commenting out all `new URL()` and `fetch()` calls for great compatibility with JS bundlers
sed -i.bkp -r 's;(input = new URL.+);//\1;g' ${PKG_DIR}/src/${NAME_UNDERSCORED}.js
sed -i.bkp -r 's;(input = fetch.+);//\1;g' ${PKG_DIR}/src/${NAME_UNDERSCORED}.js
sed -i.bkp -r 's;(.+= new URL.+);//\1;g' ${PKG_DIR}/src/${NAME_UNDERSCORED}.js
sed -i.bkp -r 's;(.+= fetch.+);//\1;g' ${PKG_DIR}/src/${NAME_UNDERSCORED}.js

rm ${PKG_DIR}/src/${NAME_UNDERSCORED}.js.bkp
}

Expand Down
7 changes: 4 additions & 3 deletions .npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"engines": {
"node": ">= 18.14.1",
"pnpm": ">= 8.1.1"
"pnpm": "^9.4.0"
},
"packageManager": "pnpm@8.1.1",
"scripts": {
"wasm": ".scripts/prepare-wasm-packages.sh",
"build": "turbo run build",
"test": "turbo run test",
"pack:all": "pnpm run-s wasm build test"
"pack:all": "run-s wasm build test"
},
"license": "Apache-2.0",
"devDependencies": {
Expand All @@ -23,6 +23,7 @@
"npm-run-all": "^4.1.5",
"rollup": "^3.29.4",
"rollup-plugin-dts": "^5.3.1",
"turbo": "^1.10.16"
"turbo": "^2.1.2"
}

}
11 changes: 11 additions & 0 deletions .npm/packages/fuel-asm/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect } from 'chai'
import { join } from 'path'
import { readFileSync } from 'fs'
import * as asm from './dist/web/index.mjs'

/*
Expand All @@ -13,6 +15,15 @@ Top-level usage:

describe('fuel-asm [esm]', () => {

it('should ensure URL/fetch patching was succesful', async () => {
const cjsContents = readFileSync('./dist/node/index.cjs', 'utf-8')
const mjsContents = readFileSync('./dist/web/index.mjs', 'utf-8')

const reg = /(new URL|fetch)\(.+\)/
expect(mjsContents).to.not.match(reg);
expect(cjsContents).to.not.match(reg);
})

it('should compose simple script', async () => {

await asm.initWasm();
Expand Down
11 changes: 11 additions & 0 deletions .npm/packages/fuel-tx/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import * as tx from './dist/web/index.mjs'

describe('fuel-tx [mjs]', () => {

it('should ensure URL/fetch patching was succesful', async () => {
console.log('import.meta', import.meta);

const mjsContents = fs.readFileSync('./dist/web/index.mjs', 'utf-8')
const cjsContents = fs.readFileSync('./dist/node/index.cjs', 'utf-8')

const reg = /(new URL|fetch)\(.+\)/
expect(mjsContents).to.not.match(reg);
expect(cjsContents).to.not.match(reg);
})

it('should export all types', () => {
expect(tx.UtxoId).to.be.ok
expect(tx.TxPointer).to.be.ok
Expand Down
11 changes: 11 additions & 0 deletions .npm/packages/fuel-types/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { expect } from 'chai'
import { join } from 'path'
import { readFileSync } from 'fs'
import * as types from './dist/web/index.mjs'

describe('fuel-types [esm]', () => {

it('should ensure URL/fetch patching was succesful', async () => {
const cjsContents = readFileSync('./dist/node/index.cjs', 'utf-8')
const mjsContents = readFileSync('./dist/web/index.mjs', 'utf-8')

const reg = /(new URL|fetch)\(.+\)/
expect(mjsContents).to.not.match(reg);
expect(cjsContents).to.not.match(reg);
})

it('should export all types', () => {

expect(types.Address).to.be.ok
Expand Down
58 changes: 29 additions & 29 deletions .npm/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions .npm/turbo.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": ["src/**"],
"outputs": ["dist/**"],
"outputMode": "new-only"
"outputLogs": "new-only"
},
"test": {
"outputMode": "new-only"
"dependsOn": ["^test", "build"],
"inputs": ["src/**"],
"outputs": ["dist/**"],
"outputLogs": "new-only"
}
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed
- [#835](https://github.com/FuelLabs/fuel-vm/pull/835): Fixing WASM-NPM packaging and publishing

## [Version 0.57.0]

### Added
Expand Down
Loading