Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active September 15, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/b29d60ef633fce24af13656072903bcf to your computer and use it in GitHub Desktop.
Save isaacs/b29d60ef633fce24af13656072903bcf to your computer and use it in GitHub Desktop.
diff --git a/index.js b/index.js
new file mode 100644
index 000000000..5447643e0
--- /dev/null
+++ b/index.js
@@ -0,0 +1,5 @@
+if (require.main === module) {
+ require('./lib/cli.js')(process)
+} else {
+ throw new Error('The programmatic API was removed in npm v8.0.0')
+}
diff --git a/lib/npm.js b/lib/npm.js
index 966d11210..1a7b06a34 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -355,6 +355,3 @@ const npm = module.exports = new class extends EventEmitter {
this.log.showProgress()
}
}()
-
-if (require.main === module)
- require('./cli.js')(process)
diff --git a/package.json b/package.json
index 8011f238a..96f96ad25 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
"lib": "./lib",
"man": "./man"
},
- "main": "./lib/npm.js",
+ "main": "./index.js",
"bin": {
"npm": "bin/npm-cli.js",
"npx": "bin/npx-cli.js"
@@ -46,9 +46,9 @@
"exports": {
".": [
{
- "default": "./lib/npm.js"
+ "default": "./index.js"
},
- "./lib/npm.js"
+ "./index.js"
],
"./package.json": "./package.json"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment