Skip to content

Commit

Permalink
support cjs/esm building
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Leos committed Sep 18, 2023
1 parent 7c452b8 commit cb7a617
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 1,859 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrity-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
- name: Run audit checks
run: npm audit

- name: Test compilation
run: npm run compile
- name: Test build
run: npm run build

- name: start containerized dbs
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:

- name: Build all workspace packages
if: env.IS_LATEST == 'true'
run: npm run compile
run: npm run build

- name: Publish @tbd54566975/dwn-sql-store@${{ env.REPO_VERSION }}
if: env.IS_LATEST == 'true'
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# The format is described: https://github.blog/2017-07-06-introducing-code-owners/

# These owners will be the default owners for everything in the repo.
* @amika-sq @mistermoe
* @amika-sq @mistermoe @adam4leos


# -----------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ Docker is used to spin up a local containerized DBs for testing purposes. Docker

| Script | Description |
| ----------------------- | ------------------------------------------- |
| `npm run compile` | compiles typescript into ESM JS |
| `npm run clean` | deletes compiled JS |
| `npm run build:esm` | compiles typescript into ESM JS |
| `npm run build:cjs` | compiles typescript into CommonJS |
| `npm run build` | compiles typescript into ESM JS & CommonJS |
| `npm run clean` | deletes compiled JS |
| `npm run test` | runs tests. |
| `npm run test-coverage` | runs tests and includes coverage |
| `npm run lint` | runs linter |
Expand Down
40 changes: 40 additions & 0 deletions build/create-cjs-bundle.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const esbuild = require('esbuild');
const packageJson = require('../package.json');

// list of dependencies that _dont_ ship cjs
const includeList = new Set([
'@ipld/dag-cbor',
'@noble/ed25519',
'@noble/secp256k1',
'blockstore-core',
'ipfs-unixfs-exporter',
'ipfs-unixfs-importer',
'multiformats',
'pg',
]);

// create list of dependencies that we _do not_ want to include in our bundle
const excludeList = [];
for (const dependency in packageJson.dependencies) {
if (includeList.has(dependency)) {
continue;
} else {
excludeList.push(dependency);
}
}

/** @type {import('esbuild').BuildOptions} */
const baseConfig = {
platform: 'node',
format: 'cjs',
bundle: true,
external: excludeList,
};

const indexConfig = {
...baseConfig,
entryPoints: ['./dist/esm/src/main.js'],
outfile: './dist/cjs/main.js',
};

esbuild.buildSync(indexConfig);
Loading

0 comments on commit cb7a617

Please sign in to comment.