From 849a6628f1651cc34d8cc2656c06faaa3411b705 Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Wed, 4 Oct 2023 16:43:50 +0300 Subject: [PATCH 1/4] Configure Jest for unit tests in the vite package --- .eslintignore | 4 ++-- packages/vite/jest.config.js | 4 ++++ packages/vite/package.json | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 packages/vite/jest.config.js diff --git a/.eslintignore b/.eslintignore index 569b8e3ba..e26596181 100644 --- a/.eslintignore +++ b/.eslintignore @@ -28,8 +28,8 @@ /tests/vite-app/ /packages/vite/index.mjs /packages/vite/index.d.ts -/packages/vite/src/**/*.js -/packages/vite/src/**/*.d.ts +/packages/vite/**/*.js +/packages/vite/**/*.d.ts # unconventional js diff --git a/packages/vite/jest.config.js b/packages/vite/jest.config.js new file mode 100644 index 000000000..cdaa1f960 --- /dev/null +++ b/packages/vite/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + testEnvironment: 'node', + testMatch: ['/tests/**/*.test.js'], +}; diff --git a/packages/vite/package.json b/packages/vite/package.json index 40acd0b0e..b6bb43c0c 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -6,6 +6,9 @@ "@embroider/core": "workspace:^", "vite": "^4.3.9" }, + "scripts": { + "test": "jest" + }, "dependencies": { "@rollup/pluginutils": "^4.1.1", "assert-never": "^1.2.1", From 05ce3f7a4cee9d174a54833b2bf83742489ca3fa Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Wed, 4 Oct 2023 16:44:40 +0300 Subject: [PATCH 2/4] Implement basic optimizeDeps() that returns default options --- packages/vite/src/optimize-deps.ts | 10 ++++++++++ packages/vite/tests/optimize-deps.test.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 packages/vite/src/optimize-deps.ts create mode 100644 packages/vite/tests/optimize-deps.test.ts diff --git a/packages/vite/src/optimize-deps.ts b/packages/vite/src/optimize-deps.ts new file mode 100644 index 000000000..91cb6cc16 --- /dev/null +++ b/packages/vite/src/optimize-deps.ts @@ -0,0 +1,10 @@ +export interface OptimizeDeps { + exclude?: string[]; + [key: string]: unknown; +} + +export function optimizeDeps(): OptimizeDeps { + return { + exclude: ['@embroider/macros'], + }; +} diff --git a/packages/vite/tests/optimize-deps.test.ts b/packages/vite/tests/optimize-deps.test.ts new file mode 100644 index 000000000..a43c3c516 --- /dev/null +++ b/packages/vite/tests/optimize-deps.test.ts @@ -0,0 +1,13 @@ +import { optimizeDeps } from '../src/optimize-deps'; + +describe('optimizeDeps', function () { + test('should produce default output when invoked without arguments', function () { + const actual = optimizeDeps(); + + const expected = { + exclude: ['@embroider/macros'], + }; + + expect(actual).toEqual(expected); + }); +}); From 58a2603de2fe4d6f05cd6bc30f0c0eb18357c7b7 Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Thu, 5 Oct 2023 12:37:08 +0300 Subject: [PATCH 3/4] Fix .gitignore and .prettierignore for vite package --- .prettierignore | 8 +++----- packages/vite/.gitignore | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.prettierignore b/.prettierignore index 685ae88e3..cac4a26a7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,5 @@ # No need to run prettier here -*.md +*.md *.yml *.yaml *.html @@ -35,10 +35,8 @@ /packages/addon-dev/**/*.d.ts /tests/fixtures/ /packages/vite/index.mjs -/packages/vite/index.d.ts -/packages/vite/src/**/*.js -/packages/vite/src/**/*.d.ts - +/packages/vite/**/*.js +/packages/vite/**/*.d.ts # unconventional js /blueprints/*/files/ diff --git a/packages/vite/.gitignore b/packages/vite/.gitignore index 68c2b31d0..ee7918ebe 100644 --- a/packages/vite/.gitignore +++ b/packages/vite/.gitignore @@ -2,6 +2,6 @@ /src/**/*.js /src/**/*.d.ts /src/**/*.map -/*/tests/**/*.js -/*/tests/**/*.d.ts -/*/tests/**/*.map +/tests/**/*.js +/tests/**/*.d.ts +/tests/**/*.map From 2f5317f11ff4489b671a369cd9db9d9dc94abc0a Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Mon, 9 Oct 2023 11:34:10 +0300 Subject: [PATCH 4/4] optimizeDeps: reexport from index and use it for test app --- packages/vite/index.d.ts | 3 ++- packages/vite/index.mjs | 3 ++- tests/vite-app/vite.config.mts | 13 +++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/vite/index.d.ts b/packages/vite/index.d.ts index f0ebe93c4..550edc816 100644 --- a/packages/vite/index.d.ts +++ b/packages/vite/index.d.ts @@ -2,4 +2,5 @@ export * from './src/resolver.js'; export * from './src/hbs.js'; export * from './src/scripts.js'; export * from './src/template-tag.js'; -export * from './src/addons.js'; \ No newline at end of file +export * from './src/addons.js'; +export * from './src/optimize-deps.js'; diff --git a/packages/vite/index.mjs b/packages/vite/index.mjs index f0ebe93c4..550edc816 100644 --- a/packages/vite/index.mjs +++ b/packages/vite/index.mjs @@ -2,4 +2,5 @@ export * from './src/resolver.js'; export * from './src/hbs.js'; export * from './src/scripts.js'; export * from './src/template-tag.js'; -export * from './src/addons.js'; \ No newline at end of file +export * from './src/addons.js'; +export * from './src/optimize-deps.js'; diff --git a/tests/vite-app/vite.config.mts b/tests/vite-app/vite.config.mts index e61ae1094..dd5985900 100644 --- a/tests/vite-app/vite.config.mts +++ b/tests/vite-app/vite.config.mts @@ -1,5 +1,12 @@ import { defineConfig } from "vite"; -import { resolver, hbs, scripts, templateTag, addons } from "@embroider/vite"; +import { + resolver, + hbs, + scripts, + templateTag, + addons, + optimizeDeps, +} from "@embroider/vite"; import { resolve } from "path"; import { babel } from "@rollup/plugin-babel"; @@ -23,9 +30,7 @@ export default defineConfig({ extensions: [".gjs", ".js", ".hbs"], }), ], - optimizeDeps: { - exclude: addons(__dirname), - }, + optimizeDeps: optimizeDeps(), server: { watch: { ignored: ["!**/node_modules/.embroider/rewritten-app/**"],