Skip to content

Commit 83f4174

Browse files
authored
Merge pull request #2144 from cprussin/fix-lazer-build
fix(lazer): fix package build
2 parents 628e5ee + 4c907a3 commit 83f4174

File tree

6 files changed

+83
-35
lines changed

6 files changed

+83
-35
lines changed

.github/workflows/ci-lazer-sdk-js.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,52 @@ after `--`, for instance you could run `pnpm test -- --concurrency 2`.
112112
- `pnpm start:prod`: Run production builds and start production mode servers in
113113
parallel.
114114

115+
#### Building a new package
116+
117+
New packages should be configured with a few requirements in mind:
118+
119+
1. You need to make sure `package.json` scripts are named such that that
120+
turborepo will hook into them at the expected times.
121+
122+
- See [turbo.json](./turbo.json) to see the base configuration and ensure you
123+
use script names that match the tasks that turborepo is configured to run.
124+
- You don't need to define scripts for all the tasks that are in the root
125+
`turbo.json` config, just define the ones that make sense for your project.
126+
- You shouldn't define scripts for tasks that just trigger other tasks;
127+
instead configure turborepo dependencies to trigger the tasks. This will
128+
allow turborepo to cache and parallelize things more effectively.
129+
- In general, `build`, `fix`, and `test` are the main turborepo task graph
130+
entry points, and any sub-tasks that apply to your package should be
131+
configured as dependencies somewhere in the graph rooted at one of those.
132+
- If you need sub-tasks or a task configuration that only apply to your or a
133+
small few packages, add a package-scoped `turbo.json`, see [the one in the
134+
insights app](./apps/insights/turbo.json) as an example.
135+
136+
2. Make sure to configure the tools you need and hook up the relevant checks to
137+
turborepo via the `test` root task so they run on CI. The most common tools
138+
(eslint, prettier, jest, and typescript) are trivial to configure correctly
139+
using shared configs, see the relevant config files [in the insights
140+
app](./apps/insights) as a starting point.
141+
142+
3. If you are writing a package that will be published:
143+
144+
- Make sure you are dual-exporting cjs and esm correctly, see [how the lazer
145+
sdk package builds](./lazer/sdk/js/package.json) (in particular look at the
146+
`build:cjs` and `build:esm` tasks) for an example for how to do this
147+
148+
- Ensure you have properly configured [subpath
149+
exports](https://nodejs.org/api/packages.html#subpath-exports) to reference
150+
the esm and cjs outputs so that your package can be consumed correctly in
151+
both environments. Again, see [the lazer sdk](./lazer/sdk/js/package.json)
152+
as an example for doing this correctly.
153+
154+
- Ensure you have set a `main` and `types` property on your `package.json`
155+
pointing to your cjs entrypoint for use in older javascript environments.
156+
157+
- Ensure you configure the `files` property on your `package.json` to include
158+
all output files and to exclude source files & tooling configuration. This
159+
will result in smaller package sizes.
160+
115161
## Audit / Feature Status
116162

117163
**This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or

lazer/sdk/js/package.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
{
22
"name": "@pythnetwork/pyth-lazer-sdk",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Pyth Lazer SDK",
55
"publishConfig": {
66
"access": "public"
77
},
88
"files": [
9-
"lib/**/*"
9+
"dist/**/*"
1010
],
11+
"main": "./dist/cjs/index.js",
12+
"types": "./dist/cjs/index.d.ts",
13+
"exports": {
14+
"import": {
15+
"types": "./dist/esm/index.d.ts",
16+
"default": "./dist/esm/index.js"
17+
},
18+
"require": {
19+
"types": "./dist/cjs/index.d.ts",
20+
"default": "./dist/cjs/index.js"
21+
}
22+
},
1123
"scripts": {
12-
"build:cjs": "tsc --project tsconfig.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
13-
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
24+
"build:cjs": "tsc --project tsconfig.build.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
25+
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json",
26+
"fix:lint": "eslint --fix .",
27+
"test:lint": "eslint .",
28+
"test:types": "tsc",
1429
"example": "node --loader ts-node/esm examples/index.js",
15-
"test": "pnpm run test:lint && pnpm run build:cjs && pnpm run build:esm",
1630
"doc": "typedoc --out docs/typedoc src",
17-
"test:lint": "eslint .",
18-
"fix:lint": "eslint --fix .",
1931
"publish": "pnpm run script -- publish"
2032
},
2133
"devDependencies": {

lazer/sdk/js/tsconfig.build.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"incremental": false,
6+
"declaration": true
7+
},
8+
"exclude": ["node_modules", "dist", "examples/"]
9+
}

lazer/sdk/js/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "@cprussin/tsconfig/base.json"
2+
"extends": "@cprussin/tsconfig/base.json",
3+
"exclude": ["node_modules", "dist"]
34
}

turbo.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ui": "tui",
55
"tasks": {
66
"build": {
7-
"dependsOn": ["^build"],
7+
"dependsOn": ["^build", "build:cjs", "build:esm"],
88
"inputs": [
99
"$TURBO_DEFAULT$",
1010
"!README.md",
@@ -16,6 +16,12 @@
1616
],
1717
"outputs": ["dist/**", "lib/**"]
1818
},
19+
"build:cjs": {
20+
"outputs": ["dist/cjs/**"]
21+
},
22+
"build:esm": {
23+
"outputs": ["dist/esm/**"]
24+
},
1925
"fix": {
2026
"dependsOn": ["fix:lint", "fix:format"],
2127
"cache": false

0 commit comments

Comments
 (0)