diff --git a/.changeset/cool-rice-grin.md b/.changeset/cool-rice-grin.md new file mode 100644 index 000000000..f76b09a02 --- /dev/null +++ b/.changeset/cool-rice-grin.md @@ -0,0 +1,5 @@ +--- +'@modular-scripts/workspace-resolver': patch +--- + +Remove requirement to build the package in local dev diff --git a/packages/workspace-resolver/package.json b/packages/workspace-resolver/package.json index 9ae719691..763682632 100644 --- a/packages/workspace-resolver/package.json +++ b/packages/workspace-resolver/package.json @@ -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", @@ -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" } } diff --git a/scripts/extend-publish-config.js b/scripts/extend-publish-config.js new file mode 100644 index 000000000..4d878594f --- /dev/null +++ b/scripts/extend-publish-config.js @@ -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); +});