Socket
Socket
Sign inDemoInstall

@pnpm/meta-updater

Package Overview
Dependencies
181
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.0.1

lib/cli.js.map

20

lib/cli.js
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const meow = require("meow");
const _1 = require(".");
const path = require("path");
_1.default(path.resolve(process.argv[2])).catch((err) => {
const cli = meow(`
Usage
$ meta-updater <path to js>
Options
--test Do not update the files. Fail if updates are needed.
Examples
$ meta-updater update.js
$ meta-updater update.js --test
`, {
flags: {
test: {
type: 'boolean',
},
},
});
_1.default(path.resolve(cli.input[0]), cli.flags).catch((err) => {
console.error(err);

@@ -8,0 +26,0 @@ process.exit(1);

4

lib/index.d.ts

@@ -1,1 +0,3 @@

export default function (updaterFilePath: string): Promise<void>;
export default function (updaterFilePath: string, opts: {
test?: boolean;
}): Promise<void>;

@@ -8,13 +8,17 @@ "use strict";

const exists = require("path-exists");
const R = require("ramda");
const writeJsonFile = require("write-json-file");
async function default_1(updaterFilePath) {
const printDiff = require("print-diff");
async function default_1(updaterFilePath, opts) {
var _a;
const workspaceDir = await find_workspace_dir_1.default(updaterFilePath);
if (!workspaceDir)
throw new Error(`${updaterFilePath} is not inside a workspace`);
const { default: updater } = await Promise.resolve().then(() => require(updaterFilePath));
const updaterLib = await Promise.resolve().then(() => require(updaterFilePath));
const updater = (_a = updaterLib.default) !== null && _a !== void 0 ? _a : updaterLib;
const updateOptions = await updater(workspaceDir);
await performUpdates(workspaceDir, updateOptions);
await performUpdates(workspaceDir, updateOptions, opts);
}
exports.default = default_1;
async function performUpdates(workspaceDir, update) {
async function performUpdates(workspaceDir, update, opts) {
let pkgs = await find_workspace_packages_1.default(workspaceDir, { engineStrict: false });

@@ -24,4 +28,13 @@ for (const { dir, manifest, writeProjectManifest } of pkgs) {

if (p === 'package.json') {
await writeProjectManifest(await updateFn(manifest, dir, manifest));
continue;
const updatedManifest = await updateFn(manifest, dir, manifest);
const needsUpdate = !R.equals(manifest, updatedManifest);
if (!needsUpdate)
continue;
if (!opts.test) {
await writeProjectManifest(updatedManifest);
continue;
}
console.log(`ERROR: package.json file in ${dir} is not up-to-date`);
printJsonDiff(manifest, updatedManifest);
process.exit(1);
}

@@ -35,6 +48,19 @@ if (!p.endsWith('.json'))

const obj = await loadJsonFile(fp);
await writeJsonFile(fp, await updateFn(obj, dir, manifest), { detectIndent: true });
const updatedObj = await updateFn(obj, dir, manifest);
const needsUpdate = !R.equals(obj, updatedObj);
if (!needsUpdate)
continue;
if (!opts.test) {
await writeJsonFile(fp, updatedObj, { detectIndent: true });
continue;
}
console.log(`ERROR: ${fp} is not up-to-date`);
printJsonDiff(obj, updatedObj);
process.exit(1);
}
}
}
function printJsonDiff(actual, expected) {
printDiff(JSON.stringify(actual, null, 2), JSON.stringify(expected, null, 2));
}
//# sourceMappingURL=index.js.map
{
"name": "@pnpm/meta-updater",
"version": "0.0.0",
"description": "Keeps meta files up-to-date in a monorepo",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"bin": "lib/cli.js",
"files": [
"lib",
"!*.map"
],
"scripts": {
"prepublishOnly": "npm run tsc",
"tsc": "rimraf lib && tsc",
"test": "pnpm run tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pnpm/meta-updater.git"
},
"keywords": [],
"engines": {
"node": ">=10.12"
},
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/meta-updater/issues"
},
"homepage": "https://github.com/pnpm/meta-updater#readme",
"dependencies": {
"@pnpm/find-workspace-dir": "^2.0.0",
"@pnpm/find-workspace-packages": "^2.3.30",
"@pnpm/logger": "^3.2.3",
"@pnpm/types": "^6.3.1",
"load-json-file": "^6.2.0",
"path-exists": "^4.0.0",
"write-json-file": "^4.3.0"
},
"devDependencies": {
"@types/node": "^14.14.19",
"rimraf": "^3.0.2",
"typescript": "^4.1.3"
}
"name": "@pnpm/meta-updater",
"version": "0.0.1",
"description": "Keeps meta files up-to-date in a monorepo",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"bin": "lib/cli.js",
"files": [
"lib",
"!*.map"
],
"repository": {
"type": "git",
"url": "git+https://github.com/pnpm/meta-updater.git"
},
"keywords": [],
"engines": {
"node": ">=10.12"
},
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/meta-updater/issues"
},
"homepage": "https://github.com/pnpm/meta-updater#readme",
"dependencies": {
"@pnpm/find-workspace-dir": "^2.0.0",
"@pnpm/find-workspace-packages": "^2.3.30",
"@pnpm/logger": "^3.2.3",
"@pnpm/types": "^6.3.1",
"load-json-file": "^6.2.0",
"meow": "9",
"path-exists": "^4.0.0",
"print-diff": "^1.0.0",
"ramda": "^0.27.1",
"write-json-file": "^4.3.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.11",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.19",
"@types/ramda": "^0.27.41",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"jest": "^27.0.5",
"rimraf": "^3.0.2",
"tempy": "^1.0.1",
"ts-jest": "^27.0.3",
"typescript": "^4.1.3"
},
"scripts": {
"compile": "rimraf lib && tsc",
"test": "pnpm run compile && jest"
}
}

@@ -5,5 +5,3 @@ # @pnpm/meta-updater

<!--@shields('npm', 'travis')-->
[![npm version](https://img.shields.io/npm/v/@pnpm/meta-updater.svg)](https://www.npmjs.com/package/@pnpm/meta-updater)
<!--/@-->

@@ -16,4 +14,32 @@ ## Installation

## Usage
Create a JavaScript file that contains the updater functions. For instance, the next file will have updaters for `package.json` and `tsconfig.json` files:
```js
module.exports = (workspaceDir) => {
return {
'package.json': (manifest, dir) => {
return {
...manifest,
author: 'Foo Bar',
}
},
'tsconfig.json': (tsConfig, dir) => {
return {
...tsConfig,
compilerOptions: {
outDir: 'lib',
rootDir: 'src',
},
}
},
}
}
```
To perform the update on the affected config files, pass the path to the updater file to the CLI. For instance: `meta-updater ./update.js`
## License
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io/)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc