Socket
Socket
Sign inDemoInstall

write-pkg

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

write-pkg - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

90

index.d.ts
import {JsonObject} from 'type-fest';
declare namespace writePackage {
interface Options {
/**
Remove empty `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` objects.
export interface Options {
/**
Remove empty `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` objects.
@default true
*/
readonly normalize?: boolean;
}
@default true
*/
readonly normalize?: boolean;
}
declare const writePackage: {
/**
Write a `package.json` file.
/**
Write a `package.json` file.
Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
@param path - Path to where the `package.json` file should be written or its directory.
@param path - The path to where the `package.json` file should be written or its directory.
@example
```
import * as path from 'path';
import writePackage = require('write-pkg');
@example
```
import path from 'node:path';
import {writePackage} from 'write-pkg';
(async () => {
await writePackage({foo: true});
console.log('done');
await writePackage({foo: true});
console.log('done');
await writePackage(__dirname, {foo: true});
console.log('done');
await writePackage(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
```
*/
export function writePackage(path: string, data: JsonObject, options?: Options): Promise<void>;
export function writePackage(data: JsonObject, options?: Options): Promise<void>;
await writePackage(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
})();
```
*/
(path: string, data: JsonObject, options?: writePackage.Options): Promise<void>;
(data: JsonObject, options?: writePackage.Options): Promise<void>;
/**
Synchronously write a `package.json` file.
/**
Synchronously write a `package.json` file.
Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
@param path - The path to where the `package.json` file should be written or its directory.
@param path - Path to where the `package.json` file should be written or its directory.
@example
```
import path from 'node:path';
import {writePackageSync} from 'write-pkg';
@example
```
import * as path from 'path';
import writePackage = require('write-pkg');
writePackageSync({foo: true});
console.log('done');
writePackage.sync({foo: true});
console.log('done');
writePackage.sync(__dirname, {foo: true});
console.log('done');
writePackage.sync(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
```
*/
sync(path: string, data: JsonObject, options?: writePackage.Options): void;
sync(data: JsonObject, options?: writePackage.Options): void;
};
export = writePackage;
writePackageSync(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
```
*/
export function writePackageSync(path: string, data: JsonObject, options?: Options): void;
export function writePackageSync(data: JsonObject, options?: Options): void;

@@ -1,5 +0,4 @@

'use strict';
const path = require('path');
const writeJsonFile = require('write-json-file');
const sortKeys = require('sort-keys');
import path from 'node:path';
import {writeJsonFile, writeJsonFileSync} from 'write-json-file';
import sortKeys from 'sort-keys';

@@ -10,3 +9,3 @@ const dependencyKeys = new Set([

'optionalDependencies',
'peerDependencies'
'peerDependencies',
]);

@@ -20,3 +19,3 @@

result[key] = packageJson[key];
} else if (Object.keys(packageJson[key]).length !== 0) {
} else if (Object.keys(packageJson[key]).length > 0) {
result[key] = sortKeys(packageJson[key]);

@@ -29,3 +28,3 @@ }

module.exports = async (filePath, data, options) => {
export async function writePackage(filePath, data, options) {
if (typeof filePath !== 'string') {

@@ -40,3 +39,3 @@ options = data;

...options,
detectIndent: true
detectIndent: true,
};

@@ -49,5 +48,5 @@

return writeJsonFile(filePath, data, options);
};
}
module.exports.sync = (filePath, data, options) => {
export function writePackageSync(filePath, data, options) {
if (typeof filePath !== 'string') {

@@ -62,3 +61,3 @@ options = data;

...options,
detectIndent: true
detectIndent: true,
};

@@ -70,3 +69,3 @@

writeJsonFile.sync(filePath, data, options);
};
writeJsonFileSync(filePath, data, options);
}
{
"name": "write-pkg",
"version": "4.0.0",
"version": "5.0.0",
"description": "Write a package.json file",
"license": "MIT",
"repository": "sindresorhus/write-pkg",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -32,13 +35,13 @@ "scripts": {

"dependencies": {
"sort-keys": "^2.0.0",
"type-fest": "^0.4.1",
"write-json-file": "^3.2.0"
"sort-keys": "^5.0.0",
"type-fest": "^2.0.0",
"write-json-file": "^5.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"read-pkg": "^5.1.1",
"tempfile": "^3.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"read-pkg": "^7.0.0",
"tempfile": "^4.0.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}

@@ -1,2 +0,2 @@

# write-pkg [![Build Status](https://travis-ci.org/sindresorhus/write-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/write-pkg)
# write-pkg

@@ -7,3 +7,2 @@ > Write a `package.json` file

## Install

@@ -15,36 +14,29 @@

## Usage
```js
const path = require('path');
const writePackage = require('write-pkg');
import path from 'node:path';
import {writePackage} from 'write-pkg';
(async () => {
await writePackage({foo: true});
console.log('done');
await writePackage({foo: true});
console.log('done');
await writePackage(__dirname, {foo: true});
console.log('done');
await writePackage(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
})();
await writePackage(path.join('unicorn', 'package.json'), {foo: true});
console.log('done');
```
## API
### writePackage([path], data, [options])
### writePackage(path?, data, options?)
Returns a `Promise`.
### writePackage.sync([path], data, [options])
### writePackageSync(path?, data, options?)
#### path
Type: `string`<br>
Type: `string`\
Default: `process.cwd()`
Path to where the `package.json` file should be written or its directory.
The path to where the `package.json` file should be written or its directory.

@@ -57,3 +49,3 @@ #### options

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

@@ -63,3 +55,9 @@

## write-pkg for enterprise
Available as part of the Tidelift Subscription.
The maintainers of write-pkg and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-write-pkg?utm_source=npm-write-pkg&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
## Related

@@ -70,5 +68,1 @@

## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc