diff --git a/packages/explorer-helpers/LICENSE b/packages/explorer-helpers/LICENSE new file mode 100644 index 00000000..01dccfff --- /dev/null +++ b/packages/explorer-helpers/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 mayakoneval + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/explorer-helpers/package.json b/packages/explorer-helpers/package.json index d5e0ab05..3199b0a1 100644 --- a/packages/explorer-helpers/package.json +++ b/packages/explorer-helpers/package.json @@ -21,7 +21,7 @@ }, "scripts": { "build": "npm run build:cjs-esm", - "build:cjs-esm": "rm -rf dist && rollup -c rollup.cjs-esm.config.js && cp src/index.cjs dist/index.cjs", + "build:cjs-esm": "rm -rf dist && rollup -c rollup.cjs-esm.config.js && cp src/index.cjs dist/index.cjs && node ./prepareDist.js", "lint": "eslint --ext .js,.jsx,.ts,.tsx .", "size": "size-limit", "analyze": "size-limit --why", diff --git a/packages/explorer-helpers/prepareDist.js b/packages/explorer-helpers/prepareDist.js new file mode 100644 index 00000000..1add511b --- /dev/null +++ b/packages/explorer-helpers/prepareDist.js @@ -0,0 +1,37 @@ +const fs = require('fs-extra'); + +// We copy the package.json to the dist folder, since when we publish we +// publish from inside the dist folder (see prepareForPublish node script). +const packageJson = require('./package.json'); +packageJson.type = 'module'; + +// Remove package.json items that we don't need to publish +delete packageJson.scripts; +delete packageJson.bundlesize; +delete packageJson.engines; + +// The root package.json points to the CJS/ESM source in "dist", to support +// on-going package development (e.g. running tests, supporting npm link, etc.). +// When publishing from "dist" however, we need to update the package.json +// to point to the files within the same directory. +const distPackageJson = + JSON.stringify( + packageJson, + (_key, value) => { + if (typeof value === 'string' && value.startsWith('dist/')) { + const parts = value.split('/'); + parts.splice(0, 1); // remove dist + return './' + parts.join('/'); + } + return value; + }, + 2 + ) + '\n'; + +// Save the modified package.json to "dist" +fs.writeFileSync(`./dist/package.json`, distPackageJson); + +// Copy supporting files into "dist" +const destDir = `dist`; +fs.copyFileSync(`README.md`, `${destDir}/README.md`); +fs.copyFileSync(`LICENSE`, `${destDir}/LICENSE`);