From cd381fa603436ece157972db3348cfca656fd230 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sun, 7 Mar 2021 21:22:36 -0800 Subject: [PATCH] some more "exports" tests --- internal/bundler/bundler_packagejson_test.go | 44 +++++++++++++++++++ .../snapshots/snapshots_packagejson.txt | 9 ++++ scripts/end-to-end-tests.js | 28 ++++++++++++ 3 files changed, 81 insertions(+) diff --git a/internal/bundler/bundler_packagejson_test.go b/internal/bundler/bundler_packagejson_test.go index 47a0fe2737a..e4ad5a2e8ea 100644 --- a/internal/bundler/bundler_packagejson_test.go +++ b/internal/bundler/bundler_packagejson_test.go @@ -1569,3 +1569,47 @@ func TestPackageJsonExportsNeutral(t *testing.T) { }, }) } + +func TestPackageJsonExportsOrderIndependent(t *testing.T) { + packagejson_suite.expectBundled(t, bundled{ + files: map[string]string{ + "/Users/user/project/src/entry.js": ` + import 'pkg1/foo/bar.js' + import 'pkg2/foo/bar.js' + `, + "/Users/user/project/node_modules/pkg1/package.json": ` + { + "exports": { + "./": "./1/", + "./foo/": "./2/" + } + } + `, + "/Users/user/project/node_modules/pkg1/1/foo/bar.js": ` + console.log('FAILURE') + `, + "/Users/user/project/node_modules/pkg1/2/bar.js": ` + console.log('SUCCESS') + `, + "/Users/user/project/node_modules/pkg2/package.json": ` + { + "exports": { + "./foo/": "./1/", + "./": "./2/" + } + } + `, + "/Users/user/project/node_modules/pkg2/1/bar.js": ` + console.log('SUCCESS') + `, + "/Users/user/project/node_modules/pkg2/2/foo/bar.js": ` + console.log('FAILURE') + `, + }, + entryPaths: []string{"/Users/user/project/src/entry.js"}, + options: config.Options{ + Mode: config.ModeBundle, + AbsOutputFile: "/Users/user/project/out.js", + }, + }) +} diff --git a/internal/bundler/snapshots/snapshots_packagejson.txt b/internal/bundler/snapshots/snapshots_packagejson.txt index 941ef534115..daa6e51c59f 100644 --- a/internal/bundler/snapshots/snapshots_packagejson.txt +++ b/internal/bundler/snapshots/snapshots_packagejson.txt @@ -446,6 +446,15 @@ TestPackageJsonExportsNode // Users/user/project/node_modules/pkg/node.js console.log("SUCCESS"); +================================================================================ +TestPackageJsonExportsOrderIndependent +---------- /Users/user/project/out.js ---------- +// Users/user/project/node_modules/pkg1/2/bar.js +console.log("SUCCESS"); + +// Users/user/project/node_modules/pkg2/1/bar.js +console.log("SUCCESS"); + ================================================================================ TestPackageJsonExportsRequireOverImport ---------- /Users/user/project/out.js ---------- diff --git a/scripts/end-to-end-tests.js b/scripts/end-to-end-tests.js index 13a679b7d6b..09d0996d55a 100644 --- a/scripts/end-to-end-tests.js +++ b/scripts/end-to-end-tests.js @@ -2808,6 +2808,34 @@ } }`, }), + test(['in.js', '--outfile=node.js', '--format=esm'].concat(flags), { + 'in.js': `import abc from 'pkg/foo'; if (abc !== 123) throw 'fail'`, + 'package.json': `{ "type": "module" }`, + 'node_modules/pkg/yes.js': `export default 123`, + 'node_modules/pkg/package.json': `{ + "type": "module", + "exports": { + "./foo": [ + { "unused": "./no.js" }, + "./yes.js" + ] + } + }`, + }), + test(['in.js', '--outfile=node.js', '--format=esm'].concat(flags), { + 'in.js': `import abc from 'pkg/foo'; if (abc !== 123) throw 'fail'`, + 'package.json': `{ "type": "module" }`, + 'node_modules/pkg/yes.js': `export default 123`, + 'node_modules/pkg/package.json': `{ + "type": "module", + "exports": { + "./foo": [ + { "default": "./yes.js" }, + "./no.js" + ] + } + }`, + }), ) }