From 41f618a1df6bb8c66d7968ac64456139b9f4c197 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 17 May 2023 17:38:50 -0400 Subject: fix(npm): improved optional dependency support (#19135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: If the package information has already been cached, then this requires running with `--reload` or for the registry information to be fetched some other way (ex. the cache busting). Closes #15544 --------- Co-authored-by: Bartek IwaƄczuk --- .../npm/registry/@denotest/binary-package/1.0.0/index.js | 13 +++++++++++++ .../registry/@denotest/binary-package/1.0.0/package.json | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/index.js create mode 100644 cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/package.json (limited to 'cli/tests/testdata/npm/registry/@denotest/binary-package') diff --git a/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/index.js b/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/index.js new file mode 100644 index 000000000..5870118e7 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/index.js @@ -0,0 +1,13 @@ +const packageByOs = { + "darwin": "@denotest/binary-package-mac", + "linux": "@denotest/binary-package-linux", + "win32": "@denotest/binary-package-windows", +} + +const selectedPackage = packageByOs[process.platform]; + +if (!selectedPackage) { + throw new Error("trying to run on unsupported platform"); +} + +require(selectedPackage); \ No newline at end of file diff --git a/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/package.json new file mode 100644 index 000000000..dc8859bb4 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/binary-package/1.0.0/package.json @@ -0,0 +1,10 @@ +{ + "name": "@denotest/binary-package", + "version": "1.0.0", + "main": "index.js", + "optionalDependencies": { + "@denotest/binary-package-linux": "1.0.0", + "@denotest/binary-package-mac": "1.0.0", + "@denotest/binary-package-windows": "1.0.0" + } +} -- cgit v1.2.3