Skip to content

Commit

Permalink
(fix, template-resolver): publish ESM + CJS compatible lib
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed May 28, 2024
1 parent 5bf0fc7 commit c31cfc8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/template-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"files": [
"dist"
],
"type": "module",
"module": "dist/src/index.js",
"source": "src/index.ts",
"scripts": {
"compile": "tsc --build",
"compile": "tsc --build ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && node ./scripts/writePackageJson.js ",
"clean": "rm -rf ./dist && tsc --build --clean",
"format": "prettier --write --ignore-unknown --ignore-path ../../shared/.prettierignore \"**\"",
"format:check": "prettier --check --ignore-unknown --ignore-path ../../shared/.prettierignore \"**\"",
Expand All @@ -36,5 +34,13 @@
"organize-imports-cli": "^0.10.0",
"prettier": "^2.7.1",
"typescript": "5.4.3"
},
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
}
}
}
25 changes: 25 additions & 0 deletions packages/template-resolver/scripts/writePackageJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs");
const path = require("path");

const buildDir = "./dist";
function createEsmModulePackageJson() {
fs.readdir(buildDir, function (err, dirs) {
if (err) {
throw err;
}
dirs.forEach(function (dir) {
if (dir === "esm") {
var packageJsonFile = path.join(buildDir, dir, "/package.json");
if (!fs.existsSync(packageJsonFile)) {
fs.writeFile(packageJsonFile, new Uint8Array(Buffer.from('{"type": "module"}')), function (err) {
if (err) {
throw err;
}
});
}
}
});
});
}

createEsmModulePackageJson();
6 changes: 6 additions & 0 deletions packages/template-resolver/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist/cjs", "rootDir": ".", "module": "commonjs", "moduleResolution": "node" },
"include": ["./src/**/*"],
"references": [{ "path": "../commons/core-utils" }]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist", "rootDir": "." },
"compilerOptions": { "outDir": "./dist/esm", "rootDir": "." },
"include": ["./src/**/*"],
"references": [{ "path": "../commons/core-utils" }]
}
6 changes: 6 additions & 0 deletions packages/template-resolver/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist/types", "declaration": true, "emitDeclarationOnly": true },
"include": ["./src/**/*"],
"references": [{ "path": "../commons/core-utils" }]
}

0 comments on commit c31cfc8

Please sign in to comment.