npx-import
Advanced tools
Comparing version 1.0.3-0 to 1.0.3
@@ -105,4 +105,4 @@ import semver from 'semver'; | ||
} | ||
if (!semver.gte(npmVersion, '8.0.0')) { | ||
throw new Error(`Require npm version 8+. Got '${npmVersion}' when running '${versionCmd}'`); | ||
if (!semver.gte(npmVersion, '7.0.0')) { | ||
throw new Error(`Require npm version 7+. Got '${npmVersion}' when running '${versionCmd}'`); | ||
} | ||
@@ -125,3 +125,3 @@ } | ||
const paths = stdout.split(':'); | ||
const tempPath = paths.find((p) => /\/\.npm\/_npx\/|\\npm-cache\\_npx\\/.exec(p)); | ||
const tempPath = paths.find((p) => /\/\.npm\/_npx\//.exec(p)); | ||
if (!tempPath) | ||
@@ -128,0 +128,0 @@ throw new Error(`Failed to find temporary install directory. Looking for paths matching '/.npm/_npx/' in:\n${JSON.stringify(paths)}`); |
{ | ||
"name": "npx-import", | ||
"version": "1.0.3-0", | ||
"version": "1.0.3", | ||
"description": "Runtime dependencies, installed as if by magic ✨", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -139,4 +139,4 @@ import semver from 'semver' | ||
if (!semver.gte(npmVersion, '8.0.0')) { | ||
throw new Error(`Require npm version 8+. Got '${npmVersion}' when running '${versionCmd}'`) | ||
if (!semver.gte(npmVersion, '7.0.0')) { | ||
throw new Error(`Require npm version 7+. Got '${npmVersion}' when running '${versionCmd}'`) | ||
} | ||
@@ -162,3 +162,3 @@ } | ||
const paths = stdout.split(':') | ||
const tempPath = paths.find((p) => /\/\.npm\/_npx\/|\\npm-cache\\_npx\\/.exec(p)) | ||
const tempPath = paths.find((p) => /\/\.npm\/_npx\//.exec(p)) | ||
@@ -165,0 +165,0 @@ if (!tempPath) |
@@ -16,3 +16,2 @@ import { afterEach, describe, expect, test, vi } from 'vitest' | ||
pkgParseFailed, | ||
getWindowsNpxPath, | ||
} from './utils' | ||
@@ -156,28 +155,10 @@ import { npxImport, npxResolve } from '../lib' | ||
test(`Should fail if NPX is old`, async () => { | ||
expectExecaCommand('npx --version').returning({ stdout: '7.1.2' }) | ||
expectExecaCommand('npx --version').returning({ stdout: '6.1.2' }) | ||
await npxImportFailed( | ||
'npm-too-old', | ||
`Require npm version 8+. Got '7.1.2' when running 'npx --version'` | ||
`Require npm version 7+. Got '6.1.2' when running 'npx --version'` | ||
) | ||
}) | ||
test(`Should fail if NPX returns weirdness`, async () => { | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-online -y -p bad-npx-paths@latest node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: '/lol:/wtf:/is/going/on' }) | ||
await npxImportFailed( | ||
'bad-npx-paths', | ||
matchesAllLines( | ||
`Failed to find temporary install directory. Looking for paths matching '/.npm/_npx/' in:`, | ||
`["/lol","/wtf","/is/going/on"]` | ||
) | ||
) | ||
}) | ||
test(`Should attempt to install, passing through whatever happens`, async () => { | ||
@@ -222,8 +203,5 @@ expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-online -y -p @org/pkg@my-tag node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectExecaCommand(`npx --prefer-online -y -p @org/pkg@my-tag node -e 'console.log(process.env.PATH)'`, { | ||
shell: true, | ||
}).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, '@org/pkg/weird-path.js').returning( | ||
@@ -250,8 +228,5 @@ new Error(`Error [ERR_MODULE_NOT_FOUND]: Cannot find module '${basePath}/weird-path.js'`) | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-online -y -p @org/pkg@my-tag node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectExecaCommand(`npx --prefer-online -y -p @org/pkg@my-tag node -e 'console.log(process.env.PATH)'`, { | ||
shell: true, | ||
}).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, '@org/pkg/lib/index.js').returning({ foo: 1, bar: 2 }) | ||
@@ -271,28 +246,2 @@ | ||
// TODO: run this on a windows env, otherwise `path.resolve` clobbers the windows like path... | ||
test.skip(`Should call relative import and return`, async () => { | ||
const npxDirectoryHash = randomString(12) | ||
const basePath = `\\Users\\glen\\AppData\\Local\\npm-cache\\_npx\\${npxDirectoryHash}\\node_modules` | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-online -y -p @org/pkg@my-tag node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getWindowsNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, '@org/pkg/lib/index.js').returning({ foo: 1, bar: 2 }) | ||
const imported = await npxImportSucceeded( | ||
'@org/pkg@my-tag/lib/index.js', | ||
matchesAllLines( | ||
`@org/pkg/lib/index.js not available locally. Attempting to use npx to install temporarily.`, | ||
`Installing... (npx --prefer-online -y -p @org/pkg@my-tag)`, | ||
`Installed into ${basePath}.`, | ||
`To skip this step in future, run: pnpm add -D @org/pkg@my-tag` | ||
) | ||
) | ||
expect(imported).toStrictEqual({ foo: 1, bar: 2 }) | ||
}) | ||
test(`Should prefer offline for exact versions`, async () => { | ||
@@ -303,8 +252,5 @@ const npxDirectoryHash = randomString(12) | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-offline -y -p @org/pkg@3.0.1 node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectExecaCommand(`npx --prefer-offline -y -p @org/pkg@3.0.1 node -e 'console.log(process.env.PATH)'`, { | ||
shell: true, | ||
}).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, '@org/pkg/lib/index.js').returning({ foo: 1, bar: 2 }) | ||
@@ -361,8 +307,5 @@ | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-offline -y -p pkg-b@1.2.3 node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectExecaCommand(`npx --prefer-offline -y -p pkg-b@1.2.3 node -e 'console.log(process.env.PATH)'`, { | ||
shell: true, | ||
}).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, 'pkg-b').returning({ name: 'pkg-b', bar: 2, local: false }) | ||
@@ -433,8 +376,5 @@ | ||
expectExecaCommand('npx --version').returning({ stdout: '8.1.2' }) | ||
expectExecaCommand( | ||
`npx --prefer-online -y -p pkg-b@latest node -e 'console.log(process.env.PATH)'`, | ||
{ | ||
shell: true, | ||
} | ||
).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectExecaCommand(`npx --prefer-online -y -p pkg-b@latest node -e 'console.log(process.env.PATH)'`, { | ||
shell: true, | ||
}).returning({ stdout: getNpxPath(npxDirectoryHash) }) | ||
expectRelativeImport(basePath, 'pkg-b').returning({ name: 'pkg-b', bar: 2, local: false }) | ||
@@ -441,0 +381,0 @@ |
@@ -117,49 +117,1 @@ import { expect, MockedFunction } from 'vitest' | ||
} | ||
export function getWindowsNpxPath(npxDirectoryHash: string) { | ||
// https://github.com/geelen/npx-import/issues/5 | ||
return [ | ||
'C', | ||
'\\Users\\glen\\node_modules\\.bin;C', | ||
'\\Users\\node_modules\\.bin;C', | ||
'\\node_modules\\.bin;C', | ||
'\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\run-script\\lib\\node-gyp-bin;C', | ||
'\\Program Files\\Eclipse Foundation\\jdk-11.0.12.7-hotspot\\bin;C', | ||
'\\Windows\\system32;C', | ||
'\\Windows;C', | ||
'\\Windows\\System32\\Wbem;C', | ||
'\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C', | ||
'\\Windows\\System32\\OpenSSH\\;C', | ||
'\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C', | ||
'\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C', | ||
'\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C', | ||
'\\WINDOWS\\system32;C', | ||
'\\WINDOWS;C', | ||
'\\WINDOWS\\System32\\Wbem;C', | ||
'\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C', | ||
'\\WINDOWS\\System32\\OpenSSH\\;C', | ||
'\\Program Files\\dotnet\\;C', | ||
'\\Program Files\\nodejs\\;C', | ||
'\\Program Files\\PuTTY\\;C', | ||
'\\Program Files\\wooting-analog-sdk\\;C', | ||
'\\ProgramData\\ComposerSetup\\bin;C', | ||
'\\Program Files\\GitHub CLI\\;C', | ||
'\\Program Files\\Git\\cmd;C', | ||
'\\Program Files\\Docker\\Docker\\resources\\bin;C', | ||
'\\ProgramData\\DockerDesktop\\version-bin;C', | ||
'\\Users\\glen\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\;C', | ||
'\\Users\\glen\\AppData\\Local\\Programs\\Python\\Python310\\;C', | ||
'\\Ruby31-x64\\bin;C', | ||
'\\vips-dev-8.13\\bin;C', | ||
'\\php-8.1.7-Win32-vs16-x64;C', | ||
'\\Users\\glen\\AppData\\Local\\Microsoft\\WindowsApps;C', | ||
'\\Users\\glen\\AppData\\Local\\GitHubDesktop\\bin;C', | ||
'\\Users\\glen\\AppData\\Roaming\\npm;C', | ||
'\\Users\\glen\\.dotnet\\tools;C', | ||
'\\ProgramData\\ComposerSetup\\bin;C', | ||
'\\Users\\glen\\AppData\\Roaming\\Composer\\vendor\\bin;C', | ||
'\\Users\\glen\\AppData\\Local\\JetBrains\\Toolbox\\scripts;C', | ||
'\\Users\\glen\\.dotnet\\tools;C', | ||
`\\Users\\glen\\AppData\\Local\\npm-cache\\_npx\\${npxDirectoryHash}\\node_modules\\.bin` | ||
].join(':') | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
58017
876