Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clean-publish

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-publish - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

jest.config.cjs

115

clean-publish.js
#!/usr/bin/env node
const {
import {
createTempDirectory,

@@ -13,5 +13,6 @@ readSrcDirectory,

removeTempDirectory,
runScript
} = require('./core')
const getConfig = require('./get-config')
runScript,
cleanDocs
} from './core.js'
import { getConfig } from './get-config.js'

@@ -24,2 +25,3 @@ const HELP =

' --version Show version number\n' +
' --cleanDocs keep only main section of README.md' +
' --files One or more exclude files\n' +

@@ -35,6 +37,4 @@ ' --fields One or more exclude package.json fields\n' +

const options = {}
let tempDirectoryName
function handleOptions () {
async function handleOptions () {
let options = {}
options.packageManager = 'npm'

@@ -62,2 +62,5 @@ for (let i = 2; i < process.argv.length; i++) {

i += 1
} else if (process.argv[i] === '--clean-docs') {
options.cleanDocs = true
i += 1
} else if (process.argv[i] === '--tag') {

@@ -74,52 +77,54 @@ options.tag = process.argv[i + 1].split(/,\s*/)

if (!options._) {
return getConfig().then(config => {
Object.assign(options, config)
})
let config = await getConfig()
return { ...config, ...options }
} else {
return options
}
return Promise.resolve()
}
handleOptions()
.then(() => createTempDirectory())
.then(directoryName => {
tempDirectoryName = directoryName
return readSrcDirectory()
})
.then(files => {
const filteredFiles = clearFilesList(
files,
[tempDirectoryName].concat(options.files)
async function run () {
const options = await handleOptions()
const tempDirectoryName = await createTempDirectory()
const files = await readSrcDirectory()
const filteredFiles = clearFilesList(
files,
[tempDirectoryName].concat(options.files)
)
await copyFiles(filteredFiles, tempDirectoryName)
const packageJson = await readPackageJSON()
if (options.cleanDocs) {
await cleanDocs(tempDirectoryName, packageJson.repository)
}
const cleanPackageJSON = clearPackageJSON(packageJson, options.fields)
await writePackageJSON(tempDirectoryName, cleanPackageJSON)
let prepublishSuccess = true
if (options.beforeScript) {
prepublishSuccess = await runScript(options.beforeScript, tempDirectoryName)
}
if (!options.withoutPublish && prepublishSuccess) {
await publish(
tempDirectoryName,
options.packageManager,
options.access,
options.tag
)
return copyFiles(filteredFiles, tempDirectoryName)
})
.then(() => readPackageJSON())
.then(packageJson => {
const cleanPackageJSON = clearPackageJSON(packageJson, options.fields)
return writePackageJSON(tempDirectoryName, cleanPackageJSON)
})
.then(() => {
if (options.beforeScript) {
return runScript(options.beforeScript, tempDirectoryName)
} else {
return true
}
})
.then(isPrepublishSuccess => {
if (!options.withoutPublish && isPrepublishSuccess) {
return publish(
tempDirectoryName,
options.packageManager,
options.access,
options.tag
)
}
})
.then(() => {
if (!options.withoutPublish) {
return removeTempDirectory(tempDirectoryName)
}
})
.catch(error => {
process.stderr.write(error.stack + '\n')
process.exit(1)
})
}
if (!options.withoutPublish) {
await removeTempDirectory(tempDirectoryName)
}
}
run().catch(error => {
process.stderr.write(error.stack + '\n')
process.exit(1)
})
#!/usr/bin/env node
const { clearPackageJSON } = require('./core')
const { readJson, readJsonFromStdin, writeJson } = require('./utils')
const getConfig = require('./get-config')
import { readJson, readJsonFromStdin, writeJson } from './utils.js'
import { clearPackageJSON } from './core.js'
import { getConfig } from './get-config.js'

@@ -16,6 +16,6 @@ const HELP =

const options = {}
let input, output
async function handleOptions () {
const options = {}
let input, output
function handleOptions () {
for (let i = 2; i < process.argv.length; i++) {

@@ -38,2 +38,3 @@ if (process.argv[i] === '--help') {

}
if (!input) {

@@ -45,22 +46,24 @@ process.stderr.write(

}
if (!options.fields) {
return getConfig().then(config => {
options.fields = config.fields
})
let config = await getConfig()
options.fields = config.fields
}
return Promise.resolve()
return [input, output, options]
}
handleOptions()
.then(() => (input ? readJson(input) : readJsonFromStdin()))
.then(packageJson => {
const cleanPackageJSON = clearPackageJSON(packageJson, options.fields)
if (output) {
return writeJson(output, cleanPackageJSON, { spaces: 2 })
}
async function run () {
const [input, output, options] = await handleOptions()
const packageJson = await (input ? readJson(input) : readJsonFromStdin())
const cleanPackageJSON = clearPackageJSON(packageJson, options.fields)
if (output) {
await writeJson(output, cleanPackageJSON, { spaces: 2 })
} else {
process.stdout.write(`${JSON.stringify(cleanPackageJSON, null, ' ')}\n`)
})
.catch(error => {
process.stderr.write(error.stack + '\n')
process.exit()
})
}
}
run().catch(error => {
process.stderr.write(error.stack + '\n')
process.exit(1)
})

@@ -1,5 +0,6 @@

const path = require('path')
const spawn = require('cross-spawn')
import { writeFile, readFile } from 'fs'
import spawn from 'cross-spawn'
import { join } from 'path'
const {
import {
regExpIndexOf,

@@ -12,13 +13,13 @@ multiCp,

remove
} = require('./utils')
const IGNORE_FILES = require('./exception/ignore-files')
const IGNORE_FIELDS = require('./exception/ignore-fields')
const NPM_SCRIPTS = require('./exception/npm-scripts')
} from './utils.js'
import IGNORE_FILES from './exception/ignore-files.js'
import IGNORE_FIELDS from './exception/ignore-fields.js'
import NPM_SCRIPTS from './exception/npm-scripts.js'
function readPackageJSON () {
export function readPackageJSON () {
return readJson('package.json')
}
function writePackageJSON (directoryName, packageJSON) {
return writeJson(path.join(directoryName, 'package.json'), packageJSON, {
export function writePackageJSON (directoryName, packageJSON) {
return writeJson(join(directoryName, 'package.json'), packageJSON, {
spaces: 2

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

function clearPackageJSON (packageJson, inputIgnoreFields) {
export function clearPackageJSON (packageJson, inputIgnoreFields) {
const ignoreFields = inputIgnoreFields

@@ -58,3 +59,3 @@ ? IGNORE_FIELDS.concat(inputIgnoreFields)

function clearFilesList (files, inputIgnoreFiles) {
export function clearFilesList (files, inputIgnoreFiles) {
const ignoreFiles = inputIgnoreFiles

@@ -69,3 +70,3 @@ ? IGNORE_FILES.concat(inputIgnoreFiles)

function publish (cwd, packageManager, access, tag) {
export function publish (cwd, packageManager, access, tag) {
return new Promise((resolve, reject) => {

@@ -89,19 +90,19 @@ const args = ['publish']

function readSrcDirectory () {
export function readSrcDirectory () {
return readdir('./')
}
function createTempDirectory () {
export function createTempDirectory () {
return mkdtemp('tmp')
}
function removeTempDirectory (directoryName) {
export function removeTempDirectory (directoryName) {
return remove(directoryName)
}
function copyFiles (files, drectoryName) {
export function copyFiles (files, drectoryName) {
return multiCp(
files.map(file => ({
from: path.join('./', file),
to: path.join(drectoryName, file)
from: join('./', file),
to: join(drectoryName, file)
}))

@@ -111,3 +112,3 @@ )

function runScript (script, ...args) {
export function runScript (script, ...args) {
return new Promise((resolve, reject) => {

@@ -122,13 +123,11 @@ spawn(script, args, { stdio: 'inherit' })

module.exports = {
readPackageJSON,
writePackageJSON,
clearPackageJSON,
clearFilesList,
publish,
readSrcDirectory,
createTempDirectory,
removeTempDirectory,
copyFiles,
runScript
export function cleanDocs (drectoryName, repository) {
let readmePath = join(drectoryName, 'README.md')
return readFile(readmePath).then(readme => {
let name = repository.match(/[^/]+\/[^/]+$/)
const cleaned = readme.toString().split(/\n##\s*\w/m)[0] +
'\n## Docs\n' +
`Read **[full docs](https://github.com/${name}#readme)** on GitHub.\n`
return writeFile(readmePath, cleaned)
})
}

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

module.exports = [
export default [
'eslintConfig',

@@ -3,0 +3,0 @@ 'eslintIgnore',

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

module.exports = [
export default [
'.circleci',

@@ -3,0 +3,0 @@ '.github',

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

module.exports = [
export default [
'version',

@@ -3,0 +3,0 @@ 'postversion',

@@ -6,4 +6,4 @@ /**

const path = require('path')
const { lilconfig } = require('lilconfig')
import { lilconfig } from 'lilconfig'
import { relative } from 'path'

@@ -83,3 +83,3 @@ const PACKAGE_ERRORS = {

function getConfig () {
export function getConfig () {
const explorer = lilconfig('clean-publish', {

@@ -106,3 +106,3 @@ searchPlaces: ['package.json', '.clean-publish', '.clean-publish.js']

} else if (err.reason && err.mark && err.mark.name) {
const file = path.relative(process.cwd(), err.mark.name)
const file = relative(process.cwd(), err.mark.name)
const position = err.mark.line + ':' + err.mark.column

@@ -151,3 +151,1 @@ throw new Error(

}
module.exports = getConfig
{
"name": "clean-publish",
"version": "2.2.0",
"version": "3.0.0",
"description": "Clean your package before publish",

@@ -14,2 +14,3 @@ "keywords": [

"repository": "shashkovdanil/clean-publish",
"type": "module",
"bin": {

@@ -20,9 +21,9 @@ "clean-publish": "clean-publish.js",

"engines": {
"node": "^10.17.0 || ^12.0.0 || >=14.0.0"
"node": "^12.0.0 || ^14.0.0 || >= 16.0.0"
},
"dependencies": {
"cross-spawn": "^7.0.3",
"fs-extra": "^9.1.0",
"lilconfig": "^2.0.2"
"fs-extra": "^10.0.0",
"lilconfig": "^2.0.3"
}
}

@@ -43,3 +43,3 @@ # Clean Publish

`node_modules`, `.eslintrc`, `.prettierrc`, `lint` script and `devDependecies` field was removed (empty objects will also be deleted).
`node_modules`, `.eslintrc`, `.prettierrc`, `lint` script and `devDependecies` field was removed (empty objects will also be deleted).

@@ -84,2 +84,3 @@ ```

- `cleanDocs` - keep only main section of `README.md`.
- `files` - list of files that you want to delete before publishing

@@ -90,3 +91,3 @@ - `fields` - list of fields in the `package.json` file that you want to delete before publishing

- `access` - whether the npm registry publishes this package as a public package, or restricted
- `before-script` - Run script on the to-release dir before `npm publish`.
- `before-script` - run script on the to-release dir before `npm publish`.

@@ -93,0 +94,0 @@ ```sh

@@ -1,5 +0,6 @@

const { mkdtemp, readdir } = require('fs').promises
const { copy, remove, readJson, writeJson } = require('fs-extra')
import fse from 'fs-extra'
function regExpIndexOf (array, item) {
export { mkdtemp, readdir } from 'fs/promises'
export function regExpIndexOf (array, item) {
for (const i in array) {

@@ -16,7 +17,12 @@ if (typeof array[i] === 'string' && item === array[i]) {

function multiCp (files) {
return Promise.all(files.map(({ from, to }) => copy(from, to)))
export const remove = fse.remove
export const readJson = fse.readJSON
export const writeJson = fse.writeJSON
export const copy = fse.copy
export function multiCp (files) {
return Promise.all(files.map(({ from, to }) => fse.copy(from, to)))
}
function readJsonFromStdin () {
export function readJsonFromStdin () {
process.stdin.setEncoding('utf8')

@@ -43,13 +49,1 @@ return new Promise((resolve, reject) => {

}
module.exports = {
mkdtemp,
readdir,
copy,
remove,
readJson,
readJsonFromStdin,
writeJson,
regExpIndexOf,
multiCp
}
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