Skip to content

Commit

Permalink
Add support for extendedPublishConfig, apply to workspace resolver (#…
Browse files Browse the repository at this point in the history
…2146)

* Remove the need to build the workspace resolver in local dev

* Add changeset
  • Loading branch information
sgb-io authored Sep 20, 2022
1 parent a17e9df commit db7acd0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-rice-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modular-scripts/workspace-resolver': patch
---

Remove requirement to build the package in local dev
11 changes: 8 additions & 3 deletions packages/workspace-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@modular-scripts/workspace-resolver",
"version": "1.1.0",
"license": "Apache-2.0",
"main": "dist-cjs/index.js",
"main": "src/index.ts",
"dependencies": {
"fs-extra": "^10.1.0",
"globby": "11.0.4",
Expand All @@ -14,13 +14,18 @@
},
"scripts": {
"build": "tsc && babel --source-maps --root-mode upward src --out-dir dist-cjs --extensions .ts --ignore **/__tests__",
"clean": "rimraf dist-cjs"
"clean": "rimraf dist-cjs",
"prepublishOnly": "node ../../scripts/extend-publish-config.js"
},
"files": [
"dist-cjs"
],
"types": "dist-cjs/index.d.ts",
"types": "src/index.ts",
"publishConfig": {
"access": "public"
},
"extendedPublishConfig": {
"main": "dist-cjs/index.js",
"types": "dist-cjs/index.d.ts"
}
}
30 changes: 30 additions & 0 deletions scripts/extend-publish-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const { writeFileSync } = require('fs');
const { resolve } = require('path');

// This script applies the contents of any `extendedPublishConfig` blocks
// to the root package.json of affected packages in PACKAGES_TO_EXTEND.
//
// It also removes `scripts` on the assumption none are needed when installing npm libraries.

const PACKAGES_TO_EXTEND = ['workspace-resolver'];

function writeNewPackageJson(src, content) {
writeFileSync(src, JSON.stringify(content, null, 2));
}

function updatePackageJson(src) {
const { extendedPublishConfig, scripts, ...pkg } = require(src);

return {
...pkg,
...extendedPublishConfig,
};
}

PACKAGES_TO_EXTEND.forEach((dirName) => {
const src = resolve(__dirname, `../packages/${dirName}`, 'package.json');
const content = updatePackageJson(src);
writeNewPackageJson(src, content);
});

0 comments on commit db7acd0

Please sign in to comment.