From f1992a5f6ef0d02cc165a69b6fd264d38311a87b Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Fri, 6 Jan 2023 16:53:30 -0600 Subject: [PATCH] fix(tempy): upgraded to the latest version of tempy --- index.js | 4 +- package-lock.json | 140 ++++++++++++++++++++++++++++-------- package.json | 2 +- test/get-pkg.test.js | 12 ++-- test/get-registry.test.js | 14 ++-- test/integration.test.js | 56 +++++++-------- test/prepare.test.js | 36 +++++----- test/set-npmrc-auth.test.js | 62 ++++------------ 8 files changed, 184 insertions(+), 142 deletions(-) diff --git a/index.js b/index.js index cbf3bcfa..f0901505 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ import { castArray, defaultTo } from 'lodash-es'; import AggregateError from 'aggregate-error'; -import tempy from 'tempy'; +import {temporaryFile} from 'tempy'; import setLegacyToken from './lib/set-legacy-token.js'; import getPkg from './lib/get-pkg.js'; import verifyNpmConfig from './lib/verify-config.js'; @@ -11,7 +11,7 @@ import publishNpm from './lib/publish.js'; let verified; let prepared; -const npmrc = tempy.file({name: '.npmrc'}); +const npmrc = temporaryFile({name: '.npmrc'}); export async function verifyConditions(pluginConfig, context) { // If the npm publish plugin is used and has `npmPublish`, `tarballDir` or `pkgRoot` configured, validate them now in order to prevent any release if the configuration is wrong diff --git a/package-lock.json b/package-lock.json index d60fd365..308a60cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "read-pkg": "^7.0.0", "registry-auth-token": "^5.0.0", "semver": "^7.1.2", - "tempy": "^2.0.0" + "tempy": "^3.0.0" }, "devDependencies": { "ava": "5.1.0", @@ -660,6 +660,7 @@ }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", + "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "2.0.5", @@ -671,6 +672,7 @@ }, "node_modules/@nodelib/fs.stat": { "version": "2.0.5", + "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -678,6 +680,7 @@ }, "node_modules/@nodelib/fs.walk": { "version": "1.2.8", + "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.scandir": "2.1.5", @@ -1937,6 +1940,7 @@ }, "node_modules/array-union": { "version": "2.1.0", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -2221,6 +2225,7 @@ }, "node_modules/balanced-match": { "version": "1.0.2", + "dev": true, "license": "MIT" }, "node_modules/base": { @@ -2460,6 +2465,7 @@ }, "node_modules/brace-expansion": { "version": "1.1.11", + "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", @@ -2468,6 +2474,7 @@ }, "node_modules/braces": { "version": "3.0.2", + "dev": true, "license": "MIT", "dependencies": { "fill-range": "^7.0.1" @@ -3261,6 +3268,7 @@ }, "node_modules/concat-map": { "version": "0.0.1", + "dev": true, "license": "MIT" }, "node_modules/concordance": { @@ -3720,6 +3728,7 @@ }, "node_modules/del": { "version": "6.1.1", + "dev": true, "license": "MIT", "dependencies": { "globby": "^11.0.1", @@ -3740,6 +3749,7 @@ }, "node_modules/del/node_modules/globby": { "version": "11.1.0", + "dev": true, "license": "MIT", "dependencies": { "array-union": "^2.1.0", @@ -3758,6 +3768,7 @@ }, "node_modules/del/node_modules/p-map": { "version": "4.0.0", + "dev": true, "license": "MIT", "dependencies": { "aggregate-error": "^3.0.0" @@ -3795,6 +3806,7 @@ }, "node_modules/dir-glob": { "version": "3.0.1", + "dev": true, "license": "MIT", "dependencies": { "path-type": "^4.0.0" @@ -5483,6 +5495,7 @@ }, "node_modules/fast-glob": { "version": "3.2.12", + "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", @@ -5517,6 +5530,7 @@ }, "node_modules/fastq": { "version": "1.15.0", + "dev": true, "license": "ISC", "dependencies": { "reusify": "^1.0.4" @@ -5552,6 +5566,7 @@ }, "node_modules/fill-range": { "version": "7.0.1", + "dev": true, "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" @@ -5735,6 +5750,7 @@ }, "node_modules/fs.realpath": { "version": "1.0.0", + "dev": true, "license": "ISC" }, "node_modules/fsevents": { @@ -5937,6 +5953,7 @@ }, "node_modules/glob": { "version": "7.2.3", + "dev": true, "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", @@ -5955,6 +5972,7 @@ }, "node_modules/glob-parent": { "version": "5.1.2", + "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -6380,6 +6398,7 @@ }, "node_modules/ignore": { "version": "5.2.4", + "dev": true, "license": "MIT", "engines": { "node": ">= 4" @@ -6476,6 +6495,7 @@ }, "node_modules/inflight": { "version": "1.0.6", + "dev": true, "license": "ISC", "dependencies": { "once": "^1.3.0", @@ -6484,6 +6504,7 @@ }, "node_modules/inherits": { "version": "2.0.4", + "dev": true, "license": "ISC" }, "node_modules/ini": { @@ -6736,6 +6757,7 @@ }, "node_modules/is-extglob": { "version": "2.1.1", + "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -6773,6 +6795,7 @@ }, "node_modules/is-glob": { "version": "4.0.3", + "dev": true, "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" @@ -6841,6 +6864,7 @@ }, "node_modules/is-number": { "version": "7.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=0.12.0" @@ -6890,6 +6914,7 @@ }, "node_modules/is-path-cwd": { "version": "2.2.0", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -6897,6 +6922,7 @@ }, "node_modules/is-path-inside": { "version": "3.0.3", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -7790,6 +7816,7 @@ }, "node_modules/merge2": { "version": "1.4.1", + "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -7803,6 +7830,7 @@ }, "node_modules/micromatch": { "version": "4.0.5", + "dev": true, "license": "MIT", "dependencies": { "braces": "^3.0.2", @@ -7875,6 +7903,7 @@ }, "node_modules/minimatch": { "version": "3.1.2", + "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" @@ -10617,6 +10646,7 @@ }, "node_modules/once": { "version": "1.4.0", + "dev": true, "license": "ISC", "dependencies": { "wrappy": "1" @@ -11155,6 +11185,7 @@ }, "node_modules/path-is-absolute": { "version": "1.0.1", + "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -11182,6 +11213,7 @@ }, "node_modules/path-type": { "version": "4.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -11195,6 +11227,7 @@ }, "node_modules/picomatch": { "version": "2.3.1", + "dev": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -11522,6 +11555,7 @@ }, "node_modules/queue-microtask": { "version": "1.2.3", + "dev": true, "funding": [ { "type": "github", @@ -11951,6 +11985,7 @@ }, "node_modules/reusify": { "version": "1.0.4", + "dev": true, "license": "MIT", "engines": { "iojs": ">=1.0.0", @@ -11959,6 +11994,7 @@ }, "node_modules/rimraf": { "version": "3.0.2", + "dev": true, "license": "ISC", "dependencies": { "glob": "^7.1.3" @@ -11972,6 +12008,7 @@ }, "node_modules/run-parallel": { "version": "1.2.0", + "dev": true, "funding": [ { "type": "github", @@ -12712,6 +12749,7 @@ }, "node_modules/slash": { "version": "3.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -13607,18 +13645,17 @@ } }, "node_modules/tempy": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/tempy/-/tempy-2.0.0.tgz", - "integrity": "sha512-m+QReZVhpa0Y56fmfoLFRZN4aDFdd3qVd8a9k3RfyTw/1utVYNg+Ar4BY6l4/TlkhYCCJFfhYWt9uy0127buJg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tempy/-/tempy-3.0.0.tgz", + "integrity": "sha512-B2I9X7+o2wOaW4r/CWMkpOO9mdiTRCxXNgob6iGvPmfPWgH/KyUD6Uy5crtWBxIBe3YrNZKR2lSzv1JJKWD4vA==", "dependencies": { - "del": "^6.0.0", "is-stream": "^3.0.0", "temp-dir": "^2.0.0", - "type-fest": "^2.0.0", + "type-fest": "^2.12.2", "unique-string": "^3.0.0" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=14.16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -13808,6 +13845,7 @@ }, "node_modules/to-regex-range": { "version": "5.0.1", + "dev": true, "license": "MIT", "dependencies": { "is-number": "^7.0.0" @@ -14675,6 +14713,7 @@ }, "node_modules/wrappy": { "version": "1.0.2", + "dev": true, "license": "ISC" }, "node_modules/write-file-atomic": { @@ -15670,16 +15709,19 @@ }, "@nodelib/fs.scandir": { "version": "2.1.5", + "dev": true, "requires": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "@nodelib/fs.stat": { - "version": "2.0.5" + "version": "2.0.5", + "dev": true }, "@nodelib/fs.walk": { "version": "1.2.8", + "dev": true, "requires": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -16605,7 +16647,8 @@ } }, "array-union": { - "version": "2.1.0" + "version": "2.1.0", + "dev": true }, "array-uniq": { "version": "1.0.3", @@ -16790,7 +16833,8 @@ "dev": true }, "balanced-match": { - "version": "1.0.2" + "version": "1.0.2", + "dev": true }, "base": { "version": "0.11.2", @@ -16958,6 +17002,7 @@ }, "brace-expansion": { "version": "1.1.11", + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -16965,6 +17010,7 @@ }, "braces": { "version": "3.0.2", + "dev": true, "requires": { "fill-range": "^7.0.1" } @@ -17492,7 +17538,8 @@ "dev": true }, "concat-map": { - "version": "0.0.1" + "version": "0.0.1", + "dev": true }, "concordance": { "version": "5.0.4", @@ -17812,6 +17859,7 @@ }, "del": { "version": "6.1.1", + "dev": true, "requires": { "globby": "^11.0.1", "graceful-fs": "^4.2.4", @@ -17825,6 +17873,7 @@ "dependencies": { "globby": { "version": "11.1.0", + "dev": true, "requires": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -17836,6 +17885,7 @@ }, "p-map": { "version": "4.0.0", + "dev": true, "requires": { "aggregate-error": "^3.0.0" } @@ -17856,6 +17906,7 @@ }, "dir-glob": { "version": "3.0.1", + "dev": true, "requires": { "path-type": "^4.0.0" } @@ -19095,6 +19146,7 @@ }, "fast-glob": { "version": "3.2.12", + "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -19124,6 +19176,7 @@ }, "fastq": { "version": "1.15.0", + "dev": true, "requires": { "reusify": "^1.0.4" } @@ -19149,6 +19202,7 @@ }, "fill-range": { "version": "7.0.1", + "dev": true, "requires": { "to-regex-range": "^5.0.1" } @@ -19288,7 +19342,8 @@ } }, "fs.realpath": { - "version": "1.0.0" + "version": "1.0.0", + "dev": true }, "fsevents": { "version": "2.3.2", @@ -19433,6 +19488,7 @@ }, "glob": { "version": "7.2.3", + "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -19444,6 +19500,7 @@ }, "glob-parent": { "version": "5.1.2", + "dev": true, "requires": { "is-glob": "^4.0.1" } @@ -19716,7 +19773,8 @@ "dev": true }, "ignore": { - "version": "5.2.4" + "version": "5.2.4", + "dev": true }, "ignore-by-default": { "version": "2.1.0", @@ -19774,13 +19832,15 @@ }, "inflight": { "version": "1.0.6", + "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" } }, "inherits": { - "version": "2.0.4" + "version": "2.0.4", + "dev": true }, "ini": { "version": "1.3.8" @@ -19962,7 +20022,8 @@ } }, "is-extglob": { - "version": "2.1.1" + "version": "2.1.1", + "dev": true }, "is-fullwidth-code-point": { "version": "4.0.0", @@ -19988,6 +20049,7 @@ }, "is-glob": { "version": "4.0.3", + "dev": true, "requires": { "is-extglob": "^2.1.1" } @@ -20030,7 +20092,8 @@ "dev": true }, "is-number": { - "version": "7.0.0" + "version": "7.0.0", + "dev": true }, "is-number-object": { "version": "1.0.7", @@ -20064,10 +20127,12 @@ } }, "is-path-cwd": { - "version": "2.2.0" + "version": "2.2.0", + "dev": true }, "is-path-inside": { - "version": "3.0.3" + "version": "3.0.3", + "dev": true }, "is-plain-obj": { "version": "1.1.0", @@ -20667,7 +20732,8 @@ "version": "2.0.0" }, "merge2": { - "version": "1.4.1" + "version": "1.4.1", + "dev": true }, "micro-spelling-correcter": { "version": "1.1.1", @@ -20677,6 +20743,7 @@ }, "micromatch": { "version": "4.0.5", + "dev": true, "requires": { "braces": "^3.0.2", "picomatch": "^2.3.1" @@ -20717,6 +20784,7 @@ }, "minimatch": { "version": "3.1.2", + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -22566,6 +22634,7 @@ }, "once": { "version": "1.4.0", + "dev": true, "requires": { "wrappy": "1" } @@ -22931,7 +23000,8 @@ "dev": true }, "path-is-absolute": { - "version": "1.0.1" + "version": "1.0.1", + "dev": true }, "path-key": { "version": "3.1.1" @@ -22948,7 +23018,8 @@ } }, "path-type": { - "version": "4.0.0" + "version": "4.0.0", + "dev": true }, "picocolors": { "version": "1.0.0", @@ -22957,7 +23028,8 @@ "dev": true }, "picomatch": { - "version": "2.3.1" + "version": "2.3.1", + "dev": true }, "pify": { "version": "3.0.0", @@ -23158,7 +23230,8 @@ "dev": true }, "queue-microtask": { - "version": "1.2.3" + "version": "1.2.3", + "dev": true }, "quick-lru": { "version": "5.1.1", @@ -23438,16 +23511,19 @@ "dev": true }, "reusify": { - "version": "1.0.4" + "version": "1.0.4", + "dev": true }, "rimraf": { "version": "3.0.2", + "dev": true, "requires": { "glob": "^7.1.3" } }, "run-parallel": { "version": "1.2.0", + "dev": true, "requires": { "queue-microtask": "^1.2.2" } @@ -23921,7 +23997,8 @@ } }, "slash": { - "version": "3.0.0" + "version": "3.0.0", + "dev": true }, "slice-ansi": { "version": "5.0.0", @@ -24596,14 +24673,13 @@ "version": "2.0.0" }, "tempy": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/tempy/-/tempy-2.0.0.tgz", - "integrity": "sha512-m+QReZVhpa0Y56fmfoLFRZN4aDFdd3qVd8a9k3RfyTw/1utVYNg+Ar4BY6l4/TlkhYCCJFfhYWt9uy0127buJg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tempy/-/tempy-3.0.0.tgz", + "integrity": "sha512-B2I9X7+o2wOaW4r/CWMkpOO9mdiTRCxXNgob6iGvPmfPWgH/KyUD6Uy5crtWBxIBe3YrNZKR2lSzv1JJKWD4vA==", "requires": { - "del": "^6.0.0", "is-stream": "^3.0.0", "temp-dir": "^2.0.0", - "type-fest": "^2.0.0", + "type-fest": "^2.12.2", "unique-string": "^3.0.0" }, "dependencies": { @@ -24740,6 +24816,7 @@ }, "to-regex-range": { "version": "5.0.1", + "dev": true, "requires": { "is-number": "^7.0.0" } @@ -25356,7 +25433,8 @@ } }, "wrappy": { - "version": "1.0.2" + "version": "1.0.2", + "dev": true }, "write-file-atomic": { "version": "5.0.0", diff --git a/package.json b/package.json index 511ea063..2347a11b 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "read-pkg": "^7.0.0", "registry-auth-token": "^5.0.0", "semver": "^7.1.2", - "tempy": "^2.0.0" + "tempy": "^3.0.0" }, "devDependencies": { "ava": "5.1.0", diff --git a/test/get-pkg.test.js b/test/get-pkg.test.js index 70c2d74c..0fb31234 100644 --- a/test/get-pkg.test.js +++ b/test/get-pkg.test.js @@ -1,11 +1,11 @@ import path from 'path'; import test from 'ava'; import fs from 'fs-extra'; -import tempy from 'tempy'; +import {temporaryDirectory} from 'tempy'; import getPkg from '../lib/get-pkg.js'; test('Verify name and version then return parsed package.json', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'package', version: '0.0.0'}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -15,7 +15,7 @@ test('Verify name and version then return parsed package.json', async (t) => { }); test('Verify name and version then return parsed package.json from a sub-directory', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkgRoot = 'dist'; const pkg = {name: 'package', version: '0.0.0'}; await fs.outputJson(path.resolve(cwd, pkgRoot, 'package.json'), pkg); @@ -26,7 +26,7 @@ test('Verify name and version then return parsed package.json from a sub-directo }); test('Throw error if missing package.json', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const [error] = await t.throwsAsync(getPkg({}, {cwd})); t.is(error.name, 'SemanticReleaseError'); @@ -34,7 +34,7 @@ test('Throw error if missing package.json', async (t) => { }); test('Throw error if missing package name', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.outputJson(path.resolve(cwd, 'package.json'), {version: '0.0.0'}); const [error] = await t.throwsAsync(getPkg({}, {cwd})); @@ -44,7 +44,7 @@ test('Throw error if missing package name', async (t) => { }); test('Throw error if package.json is malformed', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.writeFile(path.resolve(cwd, 'package.json'), "{name: 'package',}"); const [error] = await t.throwsAsync(getPkg({}, {cwd})); diff --git a/test/get-registry.test.js b/test/get-registry.test.js index c942d6d3..1f255073 100644 --- a/test/get-registry.test.js +++ b/test/get-registry.test.js @@ -1,24 +1,24 @@ import path from 'path'; import test from 'ava'; import fs from 'fs-extra'; -import tempy from 'tempy'; +import {temporaryDirectory} from 'tempy'; import getRegistry from '../lib/get-registry.js'; test('Get default registry', (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); t.is(getRegistry({name: 'package-name'}, {cwd, env: {}}), 'https://registry.npmjs.org/'); t.is(getRegistry({name: 'package-name', publishConfig: {}}, {cwd, env: {}}), 'https://registry.npmjs.org/'); }); test('Get the registry configured in ".npmrc" and normalize trailing slash', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.appendFile(path.resolve(cwd, '.npmrc'), 'registry = https://custom1.registry.com'); t.is(getRegistry({name: 'package-name'}, {cwd, env: {}}), 'https://custom1.registry.com/'); }); test('Get the registry configured from "publishConfig"', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.appendFile(path.resolve(cwd, '.npmrc'), 'registry = https://custom2.registry.com'); t.is( @@ -28,7 +28,7 @@ test('Get the registry configured from "publishConfig"', async (t) => { }); test('Get the registry configured in "NPM_CONFIG_REGISTRY"', (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); t.is( getRegistry({name: 'package-name'}, {cwd, env: {NPM_CONFIG_REGISTRY: 'https://custom1.registry.com/'}}), @@ -37,14 +37,14 @@ test('Get the registry configured in "NPM_CONFIG_REGISTRY"', (t) => { }); test('Get the registry configured in ".npmrc" for scoped package', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.appendFile(path.resolve(cwd, '.npmrc'), '@scope:registry = https://custom3.registry.com'); t.is(getRegistry({name: '@scope/package-name'}, {cwd, env: {}}), 'https://custom3.registry.com/'); }); test.serial('Get the registry configured via "NPM_CONFIG_USERCONFIG" for scoped package', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); await fs.appendFile(path.resolve(cwd, '.custom-npmrc'), '@scope:registry = https://custom4.registry.com'); t.is( diff --git a/test/integration.test.js b/test/integration.test.js index ce38654a..6efdb8ab 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -3,7 +3,7 @@ import test from 'ava'; import fs from 'fs-extra'; import execa from 'execa'; import { spy } from 'sinon'; -import tempy from 'tempy'; +import {temporaryDirectory} from 'tempy'; import { WritableStreamBuffer } from 'stream-buffers'; import * as npmRegistry from './helpers/npm-registry.js'; @@ -39,7 +39,7 @@ test.beforeEach(async (t) => { }); test('Skip npm auth verification if "npmPublish" is false', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = {NPM_TOKEN: 'wrong_token'}; const pkg = {name: 'published', version: '1.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -53,7 +53,7 @@ test('Skip npm auth verification if "npmPublish" is false', async (t) => { }); test('Skip npm auth verification if "package.private" is true', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'published', version: '1.0.0', publishConfig: {registry: npmRegistry.url}, private: true}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -73,7 +73,7 @@ test('Skip npm auth verification if "package.private" is true', async (t) => { }); test('Skip npm token verification if "package.private" is true', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'published', version: '1.0.0', publishConfig: {registry: npmRegistry.url}, private: true}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); await t.notThrowsAsync( @@ -92,7 +92,7 @@ test('Skip npm token verification if "package.private" is true', async (t) => { }); test('Throws error if NPM token is invalid', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = {NPM_TOKEN: 'wrong_token', DEFAULT_NPM_REGISTRY: npmRegistry.url}; const pkg = {name: 'published', version: '1.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -110,7 +110,7 @@ test('Throws error if NPM token is invalid', async (t) => { }); test('Skip Token validation if the registry configured is not the default one', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = {NPM_TOKEN: 'wrong_token'}; const pkg = {name: 'published', version: '1.0.0', publishConfig: {registry: 'http://custom-registry.com/'}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -123,7 +123,7 @@ test('Skip Token validation if the registry configured is not the default one', }); test('Verify npm auth and package', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'valid-token', version: '0.0.0-dev', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); await t.notThrowsAsync( @@ -142,7 +142,7 @@ test('Verify npm auth and package', async (t) => { }); test('Verify npm auth and package from a sub-directory', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'valid-token', version: '0.0.0-dev', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'dist/package.json'), pkg); await t.notThrowsAsync( @@ -161,7 +161,7 @@ test('Verify npm auth and package from a sub-directory', async (t) => { }); test('Verify npm auth and package with "npm_config_registry" env var set by yarn', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {name: 'valid-token', version: '0.0.0-dev', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); await t.notThrowsAsync( @@ -180,7 +180,7 @@ test('Verify npm auth and package with "npm_config_registry" env var set by yarn }); test('Throw SemanticReleaseError Array if config option are not valid in verifyConditions', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); const npmPublish = 42; @@ -215,7 +215,7 @@ test('Throw SemanticReleaseError Array if config option are not valid in verifyC }); test('Publish the package', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'publish', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -240,7 +240,7 @@ test('Publish the package', async (t) => { }); test('Publish the package on a dist-tag', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = {...npmRegistry.authEnv, DEFAULT_NPM_REGISTRY: npmRegistry.url}; const pkg = {name: 'publish-tag', version: '0.0.0', publishConfig: {registry: npmRegistry.url, tag: 'next'}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -269,7 +269,7 @@ test('Publish the package on a dist-tag', async (t) => { }); test('Publish the package from a sub-directory', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'publish-sub-dir', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'dist/package.json'), pkg); @@ -294,7 +294,7 @@ test('Publish the package from a sub-directory', async (t) => { }); test('Create the package and skip publish ("npmPublish" is false)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'skip-publish', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -319,7 +319,7 @@ test('Create the package and skip publish ("npmPublish" is false)', async (t) => }); test('Create the package and skip publish ("package.private" is true)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = { name: 'skip-publish-private', @@ -349,7 +349,7 @@ test('Create the package and skip publish ("package.private" is true)', async (t }); test('Create the package and skip publish from a sub-directory ("npmPublish" is false)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'skip-publish-sub-dir', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'dist/package.json'), pkg); @@ -374,7 +374,7 @@ test('Create the package and skip publish from a sub-directory ("npmPublish" is }); test('Create the package and skip publish from a sub-directory ("package.private" is true)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = { name: 'skip-publish-sub-dir-private', @@ -404,7 +404,7 @@ test('Create the package and skip publish from a sub-directory ("package.private }); test('Throw SemanticReleaseError Array if config option are not valid in publish', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); const npmPublish = 42; @@ -439,7 +439,7 @@ test('Throw SemanticReleaseError Array if config option are not valid in publish }); test('Prepare the package', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'prepare', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -462,7 +462,7 @@ test('Prepare the package', async (t) => { }); test('Prepare the package from a sub-directory', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'prepare-sub-dir', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'dist/package.json'), pkg); @@ -485,7 +485,7 @@ test('Prepare the package from a sub-directory', async (t) => { }); test('Throw SemanticReleaseError Array if config option are not valid in prepare', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const pkg = {publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); const npmPublish = 42; @@ -520,7 +520,7 @@ test('Throw SemanticReleaseError Array if config option are not valid in prepare }); test('Publish the package and add to default dist-tag', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'add-channel', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -556,7 +556,7 @@ test('Publish the package and add to default dist-tag', async (t) => { }); test('Publish the package and add to lts dist-tag', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'add-channel-legacy', version: '1.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -595,7 +595,7 @@ test('Publish the package and add to lts dist-tag', async (t) => { }); test('Skip adding the package to a channel ("npmPublish" is false)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'skip-add-channel', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -618,7 +618,7 @@ test('Skip adding the package to a channel ("npmPublish" is false)', async (t) = }); test('Skip adding the package to a channel ("package.private" is true)', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = { name: 'skip-add-channel-private', @@ -646,7 +646,7 @@ test('Skip adding the package to a channel ("package.private" is true)', async ( }); test('Create the package in addChannel step', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'add-channel-pkg', version: '0.0.0', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -669,7 +669,7 @@ test('Create the package in addChannel step', async (t) => { }); test('Throw SemanticReleaseError Array if config option are not valid in addChannel', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); @@ -705,7 +705,7 @@ test('Throw SemanticReleaseError Array if config option are not valid in addChan }); test('Verify token and set up auth only on the fist call, then prepare on prepare call only', async (t) => { - const cwd = tempy.directory(); + const cwd = temporaryDirectory(); const env = npmRegistry.authEnv; const pkg = {name: 'test-module', version: '0.0.0-dev', publishConfig: {registry: npmRegistry.url}}; await fs.outputJson(path.resolve(cwd, 'package.json'), pkg); diff --git a/test/prepare.test.js b/test/prepare.test.js index bfdbe20a..d3be8f47 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -1,7 +1,7 @@ import path from 'path'; import test from 'ava'; import fs from 'fs-extra'; -import tempy from 'tempy'; +import {temporaryDirectory, temporaryFile} from 'tempy'; import execa from 'execa'; import { stub } from 'sinon'; import { WritableStreamBuffer } from 'stream-buffers'; @@ -14,9 +14,9 @@ test.beforeEach((t) => { t.context.stderr = new WritableStreamBuffer(); }); -test('Updade package.json', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); +test('Update package.json', async (t) => { + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); await fs.outputJson(packagePath, {version: '0.0.0-dev'}); @@ -41,8 +41,8 @@ test('Updade package.json', async (t) => { }); test('Updade package.json and npm-shrinkwrap.json', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); const shrinkwrapPath = path.resolve(cwd, 'npm-shrinkwrap.json'); await fs.outputJson(packagePath, {version: '0.0.0-dev'}); @@ -70,8 +70,8 @@ test('Updade package.json and npm-shrinkwrap.json', async (t) => { }); test('Updade package.json and package-lock.json', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); const packageLockPath = path.resolve(cwd, 'package-lock.json'); await fs.outputJson(packagePath, {version: '0.0.0-dev'}); @@ -100,8 +100,8 @@ test('Updade package.json and package-lock.json', async (t) => { }); test('Updade package.json and npm-shrinkwrap.json in a sub-directory', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const pkgRoot = 'dist'; const packagePath = path.resolve(cwd, pkgRoot, 'package.json'); const shrinkwrapPath = path.resolve(cwd, pkgRoot, 'npm-shrinkwrap.json'); @@ -130,8 +130,8 @@ test('Updade package.json and npm-shrinkwrap.json in a sub-directory', async (t) }); test('Updade package.json and package-lock.json in a sub-directory', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const pkgRoot = 'dist'; const packagePath = path.resolve(cwd, pkgRoot, 'package.json'); const packageLockPath = path.resolve(cwd, pkgRoot, 'package-lock.json'); @@ -161,8 +161,8 @@ test('Updade package.json and package-lock.json in a sub-directory', async (t) = }); test('Preserve indentation and newline', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); await fs.outputFile(packagePath, `{\r\n "name": "package-name",\r\n "version": "0.0.0-dev"\r\n}\r\n`); @@ -190,8 +190,8 @@ test('Preserve indentation and newline', async (t) => { }); test('Create the package in the "tarballDir" directory', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); const pkg = {name: 'my-pkg', version: '0.0.0-dev'}; await fs.outputJson(packagePath, pkg); @@ -218,8 +218,8 @@ test('Create the package in the "tarballDir" directory', async (t) => { }); test('Only move the created tarball if the "tarballDir" directory is not the CWD', async (t) => { - const cwd = tempy.directory(); - const npmrc = tempy.file({name: '.npmrc'}); + const cwd = temporaryDirectory(); + const npmrc = temporaryFile({name: '.npmrc'}); const packagePath = path.resolve(cwd, 'package.json'); const pkg = {name: 'my-pkg', version: '0.0.0-dev'}; await fs.outputJson(packagePath, pkg); diff --git a/test/set-npmrc-auth.test.js b/test/set-npmrc-auth.test.js index 1823fed1..6126e34e 100644 --- a/test/set-npmrc-auth.test.js +++ b/test/set-npmrc-auth.test.js @@ -2,7 +2,7 @@ import path from 'path'; import test from 'ava'; import fs from 'fs-extra'; import { stub } from 'sinon'; -import tempy from 'tempy'; +import {temporaryFile, temporaryDirectory} from 'tempy'; const {HOME} = process.env; const cwd = process.cwd(); @@ -19,10 +19,7 @@ test.afterEach.always(() => { }); test.serial('Set auth with "NPM_TOKEN"', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_TOKEN: 'npm_token'}; const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; @@ -33,10 +30,7 @@ test.serial('Set auth with "NPM_TOKEN"', async (t) => { }); test.serial('Set auth with "NPM_USERNAME", "NPM_PASSWORD" and "NPM_EMAIL"', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_USERNAME: 'npm_username', NPM_PASSWORD: 'npm_pasword', NPM_EMAIL: 'npm_email'}; const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; @@ -47,10 +41,7 @@ test.serial('Set auth with "NPM_USERNAME", "NPM_PASSWORD" and "NPM_EMAIL"', asyn }); test.serial('Preserve home ".npmrc"', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_TOKEN: 'npm_token'}; await fs.appendFile(path.resolve(process.env.HOME, '.npmrc'), 'home_config = test'); @@ -67,10 +58,7 @@ test.serial('Preserve home ".npmrc"', async (t) => { }); test.serial('Preserve home and local ".npmrc"', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_TOKEN: 'npm_token'}; await fs.appendFile(path.resolve(cwd, '.npmrc'), 'cwd_config = test'); @@ -91,10 +79,7 @@ test.serial('Preserve home and local ".npmrc"', async (t) => { }); test.serial('Preserve all ".npmrc" if auth is already configured', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); await fs.appendFile(path.resolve(cwd, '.npmrc'), `//custom.registry.com/:_authToken = \${NPM_TOKEN}`); await fs.appendFile(path.resolve(process.env.HOME, '.npmrc'), 'home_config = test'); @@ -110,10 +95,7 @@ test.serial('Preserve all ".npmrc" if auth is already configured', async (t) => }); test.serial('Preserve ".npmrc" if auth is already configured for a scoped package', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); await fs.appendFile( path.resolve(cwd, '.npmrc'), @@ -135,10 +117,7 @@ test.serial('Preserve ".npmrc" if auth is already configured for a scoped packag }); test.serial('Throw error if "NPM_TOKEN" is missing', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; const [error] = await t.throwsAsync( @@ -151,10 +130,7 @@ test.serial('Throw error if "NPM_TOKEN" is missing', async (t) => { }); test.serial('Emulate npm config resolution if "NPM_CONFIG_USERCONFIG" is set', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); await fs.appendFile(path.resolve(cwd, '.custom-npmrc'), `//custom.registry.com/:_authToken = \${NPM_TOKEN}`); @@ -170,10 +146,7 @@ test.serial('Emulate npm config resolution if "NPM_CONFIG_USERCONFIG" is set', a }); test.serial('Throw error if "NPM_USERNAME" is missing', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_PASSWORD: 'npm_pasword', NPM_EMAIL: 'npm_email'}; const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; @@ -187,10 +160,7 @@ test.serial('Throw error if "NPM_USERNAME" is missing', async (t) => { }); test.serial('Throw error if "NPM_PASSWORD" is missing', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_USERNAME: 'npm_username', NPM_EMAIL: 'npm_email'}; const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; @@ -204,10 +174,7 @@ test.serial('Throw error if "NPM_PASSWORD" is missing', async (t) => { }); test.serial('Throw error if "NPM_EMAIL" is missing', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); const env = {NPM_USERNAME: 'npm_username', NPM_PASSWORD: 'npm_password'}; const setNpmrcAuth = (await import('../lib/set-npmrc-auth.js')).default; @@ -221,10 +188,7 @@ test.serial('Throw error if "NPM_EMAIL" is missing', async (t) => { }); test.serial('Prefer .npmrc over environment variables', async (t) => { - process.env.HOME = tempy.directory(); - const cwd = tempy.directory(); - process.chdir(cwd); - const npmrc = tempy.file({name: '.npmrc'}); + const npmrc = temporaryFile({name: '.npmrc'}); // Specify an NPM token environment variable const env = {NPM_TOKEN: 'env_npm_token'};