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

support cjs/esm building #5

Merged
merged 2 commits into from
Sep 19, 2023
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
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