Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for extendedPublishConfig, apply to workspace resolver #2146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is directory names. I figured that having a hardcoded static list of packages to apply this to, is fine for the scope of this project.


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);
});