Skip to content

Commit

Permalink
Switch to nodejs export conditions from TS project references (#67)
Browse files Browse the repository at this point in the history
* build: Switch to nodejs export conditions from TS project references

Previously, typescript project references were used to wire imports
between workspace packages. Now this is done by package.json export
conditions. This nodejs feature has already been used to support
consuming packages in both esm and cjs format. We add an artificial
condition "_bundle", and use the respective bundler's export conditions
feature https://esbuild.github.io/api/#conditions and https://www.typescriptlang.org/tsconfig#customConditions
to achieve that IDE and TS compiler resolve any workspace package
imports to their respective Typescript source file, not their build
output .d.ts files.

This has an additional benefit of reducing bundle size of cjs build.
Previously, CJS build operated on ESM build output; They fed
dist/index.js files to esbuild. This changes this so that esbuild
directly operates on Typescript source files even in CJS build. As
esbuild will have more information, it will be able to better tree-shake
unused codes.

* build: use _bundle export condition on esm bundle as well

* chore: make prettier format json

also used double quotes for interoparabilities with Windows

* build: set forceConsistentCasingInFileNames

* build: use import instead of _bundle

Since package.json is re-written before publishing, we are free to point
`import` condition to `.ts` source files. However, CLI tests need to be
able to resolve to `dist/*.js` files, so a custom condition `prebuilt`
pointing to those are kept in every package.json.
  • Loading branch information
theseanl authored Jan 24, 2024
1 parent e3f1dc1 commit 4811a0b
Show file tree
Hide file tree
Showing 78 changed files with 2,251 additions and 3,042 deletions.
1,328 changes: 1,254 additions & 74 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
],
"scripts": {
"build": "npm run build -ws",
"clean": "npm run clean -ws",
"package": "npm run package -ws",
"publish": "npm run publish -ws",
"test": "vitest ./packages",
"test:ci": "vitest ./packages --maxWorkers=1",
"prettier": "prettier '**/*.ts' --write",
"eslint": "eslint '**/*.ts' --ignore-pattern dist"
"prettier": "prettier \"**/*.ts\" \"**/*.json\" --write",
"eslint": "eslint \"**/*.ts\" --ignore-pattern dist"
},
"prettier": {
"tabWidth": 4,
Expand All @@ -31,11 +32,13 @@
"mdast-builder": "^1.1.1",
"mdast-util-inject": "^1.1.0",
"mkdirp": "^3.0.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"prettier-plugin-pegjs": "^0.5.4",
"remark-gfm": "^3.0.1",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"rimraf": "^5.0.5",
"ts-morph": "^19.0.0",
"typescript": "^5.2.2",
"vitest": "^0.34.3"
Expand Down
12 changes: 8 additions & 4 deletions packages/structured-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
],
"exports": {
".": {
"import": "./dist/index.js",
"prebuilt": "./dist/index.js",
"import": "./index.ts",
"require": "./dist/index.cjs"
},
"./*js": "./dist/*js",
"./*": {
"import": "./dist/*.js",
"prebuilt": "./dist/*.js",
"import": "./*.ts",
"require": "./dist/*.cjs"
}
},
"scripts": {
"build": "npm run clean && mkdirp ./dist && npm run compile",
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
"compile": "tsc -b tsconfig.json & node build.js & for job in `jobs -p`; do wait ${job}; done",
"clean": "rimraf ./dist",
"compile:tsc": "tsc",
"compile:esm_and_cjs": "node build.js",
"compile": "run-p compile:tsc compile:esm_and_cjs",
"test": "vitest"
},
"repository": {
Expand Down
3 changes: 1 addition & 2 deletions packages/structured-clone/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"outDir": "./dist/",
"rootDir": "."
},
"include": ["./**/*.ts"],
"references": [{ "path": "../unified-latex-types" }]
"include": ["./**/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/support-tables/katex-support.json
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,4 @@
"Vmatrix*",
"vmatrix*"
]
}
}
Loading

0 comments on commit 4811a0b

Please sign in to comment.