Skip to content

Commit

Permalink
correctly copy over package.json file in the explorer-helpers package (
Browse files Browse the repository at this point in the history
  • Loading branch information
mayakoneval authored Apr 13, 2023
1 parent 0ed9997 commit 3a8e666
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/explorer-helpers/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/explorer-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions packages/explorer-helpers/prepareDist.js
Original file line number Diff line number Diff line change
@@ -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`);

0 comments on commit 3a8e666

Please sign in to comment.