Skip to content

Commit

Permalink
(fix): publish template resolver as a cjs package (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Jun 19, 2024
1 parent 593b63e commit 5dcce54
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 101 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/publish-template-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- name: 📥 Install
uses: ./.github/actions/install

- name: 🧪 Build and test
run: pnpm turbo codegen build test --filter=${{ env.PACKAGE_NAME }}
- name: 🧪 Build CJS and test
run: pnpm compile:cjs --filter=${{ env.PACKAGE_NAME }}

- name: Publish Template Resolver Package
env:
Expand All @@ -39,9 +39,5 @@ jobs:
VERSION="${tag#$prefix}"
cd packages/template-resolver
mv package.json package.json.tmp
version_replace="s/0.0.0/${VERSION}/"
cat package.json.tmp| sed "${version_replace}" > package.json
rm -rf package.json.tmp
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
node scripts/preparePackageJson.cjs $VERSION
npm publish --access public
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"stylelint-config-tailwindcss": "^0.0.7",
"stylelint-scss": "^6.0.0",
"tailwindcss": "^3.4.3",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"turbo": "^2.0.1",
"typescript": "5.4.3",
Expand Down
1 change: 1 addition & 0 deletions packages/template-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"scripts": {
"compile": "tsc --build",
"compile:cjs": "tsc --build -f tsconfig.cjs.json",
"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 Down
49 changes: 49 additions & 0 deletions packages/template-resolver/scripts/preparePackageJson.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require("fs");

// Function to update the version in package.json and remove "type": "module"
function preparePackageJson(newVersion) {
const packagePath = "./package.json";

// Read the package.json file
fs.readFile(packagePath, "utf8", (err, data) => {
if (err) {
console.error(`Error reading package.json: ${err}`);
return;
}

// Parse the JSON data
let packageJson = JSON.parse(data);

// Update the version
packageJson.version = newVersion;

// Remove the "type": "module" field if it exists
if (packageJson.type === "module") {
delete packageJson.type;
}

// Remove the "module" key if it exists
if (packageJson["module"] != null) {
delete packageJson.module;
}

// Write the updated package.json back to the file
fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2), (err) => {
if (err) {
console.error(`Error writing package.json: ${err}`);
return;
}

console.log("package.json has been updated successfully.");
});
});
}

// Example usage: pass the new version as a command line argument
const newVersion = process.argv[2];
if (!newVersion) {
console.error("Please provide a version number as an argument.");
process.exit(1);
}

preparePackageJson(newVersion);
Loading

0 comments on commit 5dcce54

Please sign in to comment.