From 0814af947cb46b1738d35db522717a31ae7cdc33 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Wed, 22 Jun 2022 15:02:42 +0900 Subject: [PATCH] test: add cjs browser field bare import test --- .../optimize-deps/__tests__/optimize-deps.spec.ts | 4 ++++ .../dep-cjs-browser-field-bare/events-shim.js | 3 +++ .../optimize-deps/dep-cjs-browser-field-bare/index.js | 5 +++++ .../dep-cjs-browser-field-bare/internal.js | 5 +++++ .../dep-cjs-browser-field-bare/package.json | 9 +++++++++ playground/optimize-deps/index.html | 6 ++++++ playground/optimize-deps/package.json | 1 + pnpm-lock.yaml | 11 +++++++++++ 8 files changed, 44 insertions(+) create mode 100644 playground/optimize-deps/dep-cjs-browser-field-bare/events-shim.js create mode 100644 playground/optimize-deps/dep-cjs-browser-field-bare/index.js create mode 100644 playground/optimize-deps/dep-cjs-browser-field-bare/internal.js create mode 100644 playground/optimize-deps/dep-cjs-browser-field-bare/package.json diff --git a/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts index cc712fbbdc4a09..99a1d97031ec4a 100644 --- a/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -57,6 +57,10 @@ test('cjs browser field (axios)', async () => { expect(await page.textContent('.cjs-browser-field')).toBe('pong') }) +test('cjs browser field bare', async () => { + expect(await page.textContent('.cjs-browser-field-bare')).toBe('pong') +}) + test('dep from linked dep (lodash-es)', async () => { expect(await page.textContent('.deps-linked')).toBe('fooBarBaz') }) diff --git a/playground/optimize-deps/dep-cjs-browser-field-bare/events-shim.js b/playground/optimize-deps/dep-cjs-browser-field-bare/events-shim.js new file mode 100644 index 00000000000000..fb5ce844858a55 --- /dev/null +++ b/playground/optimize-deps/dep-cjs-browser-field-bare/events-shim.js @@ -0,0 +1,3 @@ +module.exports = { + foo: 'foo' +} diff --git a/playground/optimize-deps/dep-cjs-browser-field-bare/index.js b/playground/optimize-deps/dep-cjs-browser-field-bare/index.js new file mode 100644 index 00000000000000..5ea984fdc8a39c --- /dev/null +++ b/playground/optimize-deps/dep-cjs-browser-field-bare/index.js @@ -0,0 +1,5 @@ +'use strict' + +const internal = require('./internal') + +module.exports = internal diff --git a/playground/optimize-deps/dep-cjs-browser-field-bare/internal.js b/playground/optimize-deps/dep-cjs-browser-field-bare/internal.js new file mode 100644 index 00000000000000..739645348bd6c3 --- /dev/null +++ b/playground/optimize-deps/dep-cjs-browser-field-bare/internal.js @@ -0,0 +1,5 @@ +'use strict' + +const events = require('events') + +module.exports = 'foo' in events ? 'pong' : '' diff --git a/playground/optimize-deps/dep-cjs-browser-field-bare/package.json b/playground/optimize-deps/dep-cjs-browser-field-bare/package.json new file mode 100644 index 00000000000000..87a42018c9b419 --- /dev/null +++ b/playground/optimize-deps/dep-cjs-browser-field-bare/package.json @@ -0,0 +1,9 @@ +{ + "name": "dep-cjs-browser-field-bare", + "private": true, + "version": "0.0.0", + "main": "index.js", + "browser": { + "events": "./events-shim.js" + } +} diff --git a/playground/optimize-deps/index.html b/playground/optimize-deps/index.html index 00cf4c48e6e9e6..6f76ca52094546 100644 --- a/playground/optimize-deps/index.html +++ b/playground/optimize-deps/index.html @@ -29,6 +29,9 @@

Dedupe (dep in linked & optimized package)

CommonJS w/ browser field mapping (axios)

This should show pong:
+

CommonJS w/ bare id browser field mapping

+
This should show pong:
+

Detecting linked src package and optimizing its deps (lodash-es)

This should show fooBarBaz:
@@ -88,6 +91,9 @@

Flatten Id

// test dep detection in globbed files const globbed = import.meta.glob('./glob/*.js', { eager: true }) + import cjsBrowerFieldBare from 'dep-cjs-browser-field-bare' + text('.cjs-browser-field-bare', cjsBrowerFieldBare) + import { camelCase } from 'dep-linked' text('.deps-linked', camelCase('foo-bar-baz')) diff --git a/playground/optimize-deps/package.json b/playground/optimize-deps/package.json index 9470641620b4a3..066bd5c3763dbb 100644 --- a/playground/optimize-deps/package.json +++ b/playground/optimize-deps/package.json @@ -11,6 +11,7 @@ "dependencies": { "axios": "^0.27.2", "clipboard": "^2.0.11", + "dep-cjs-browser-field-bare": "file:./dep-cjs-browser-field-bare", "dep-cjs-compiled-from-cjs": "file:./dep-cjs-compiled-from-cjs", "dep-cjs-compiled-from-esm": "file:./dep-cjs-compiled-from-esm", "dep-cjs-with-assets": "file:./dep-cjs-with-assets", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5f3a9c1313adfb..302a1c10efb27f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -574,6 +574,7 @@ importers: added-in-entries: file:./added-in-entries axios: ^0.27.2 clipboard: ^2.0.11 + dep-cjs-browser-field-bare: file:./dep-cjs-browser-field-bare dep-cjs-compiled-from-cjs: file:./dep-cjs-compiled-from-cjs dep-cjs-compiled-from-esm: file:./dep-cjs-compiled-from-esm dep-cjs-with-assets: file:./dep-cjs-with-assets @@ -600,6 +601,7 @@ importers: added-in-entries: file:playground/optimize-deps/added-in-entries axios: 0.27.2 clipboard: 2.0.11 + dep-cjs-browser-field-bare: file:playground/optimize-deps/dep-cjs-browser-field-bare dep-cjs-compiled-from-cjs: file:playground/optimize-deps/dep-cjs-compiled-from-cjs dep-cjs-compiled-from-esm: file:playground/optimize-deps/dep-cjs-compiled-from-esm dep-cjs-with-assets: file:playground/optimize-deps/dep-cjs-with-assets @@ -628,6 +630,9 @@ importers: playground/optimize-deps/added-in-entries: specifiers: {} + playground/optimize-deps/dep-cjs-browser-field-bare: + specifiers: {} + playground/optimize-deps/dep-cjs-compiled-from-cjs: specifiers: {} @@ -8706,6 +8711,12 @@ packages: version: 1.0.0 dev: false + file:playground/optimize-deps/dep-cjs-browser-field-bare: + resolution: {directory: playground/optimize-deps/dep-cjs-browser-field-bare, type: directory} + name: dep-cjs-browser-field-bare + version: 0.0.0 + dev: false + file:playground/optimize-deps/dep-cjs-compiled-from-cjs: resolution: {directory: playground/optimize-deps/dep-cjs-compiled-from-cjs, type: directory} name: dep-cjs-compiled-from-cjs