Skip to content

Commit

Permalink
chore: Add node10 entrypoint to Foundation (#2706)
Browse files Browse the repository at this point in the history
Using node10 module resolution fails when importing Foundation, since
the `exports` entry with multiple entrypoints is ignored. This PR adds a
`main` fallback with an index that re-exports every submodule as a named
object.

So a user with node10 module resolution and targetting a commonjs module
can do:
```ts
import { sleep } from '@aztec/foundation';

async function main() {
  await sleep.sleep(1);
}
```

While a user targetting node16 and up can do:
```ts
import { sleep } from '@aztec/foundation/sleep';

async function main() {
  await sleep(1);
}
```

Note that importing `@aztec/foundation` under node16 fails, since there
is no `.` entrypoint under exports.
  • Loading branch information
spalladino authored Oct 6, 2023
1 parent c4796ac commit 30c7935
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion yarn-project/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"packageManager": "yarn@3.4.1",
"type": "module",
"main": "./dest/index.js",
"types": "./dest/index.d.ts",
"exports": {
"./eslint": "./.eslintrc.cjs",
"./prettier": "./.prettierrc.json",
Expand Down Expand Up @@ -106,7 +108,6 @@
"src",
"!*.test.*"
],
"types": "./dest/index.d.ts",
"engines": {
"node": ">=18"
}
Expand Down
27 changes: 27 additions & 0 deletions yarn-project/foundation/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Reexport all folders at the root for packages targeting CommonJS
export * as abi from './abi/index.js';
export * as asyncMap from './async-map/index.js';
export * as aztecAddress from './aztec-address/index.js';
export * as bigintBuffer from './bigint-buffer/index.js';
export * as collection from './collection/index.js';
export * as committable from './committable/index.js';
export * as crypto from './crypto/index.js';
export * as errors from './errors/index.js';
export * as ethAddress from './eth-address/index.js';
export * as fields from './fields/index.js';
export * as fifo from './fifo/index.js';
export * as jsonRpc from './json-rpc/index.js';
export * as jsonRpcClient from './json-rpc/client/index.js';
export * as jsonRpcServer from './json-rpc/server/index.js';
export * as log from './log/index.js';
export * as mutex from './mutex/index.js';
export * as retry from './retry/index.js';
export * as runningPromise from './running-promise/index.js';
export * as serialize from './serialize/index.js';
export * as sleep from './sleep/index.js';
export * as timer from './timer/index.js';
export * as transport from './transport/index.js';
export * as types from './types/index.js';
export * as url from './url/index.js';
export * as wasm from './wasm/index.js';
export * as worker from './worker/index.js';

0 comments on commit 30c7935

Please sign in to comment.