diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/compiler-plugin-options.d.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/models/compiler-plugin-options.d.ts similarity index 96% rename from packages/rsbuild-plugin-angular/src/lib/plugin/utils/compiler-plugin-options.d.ts rename to packages/rsbuild-plugin-angular/src/lib/plugin/models/compiler-plugin-options.d.ts index a519841..baf3097 100644 --- a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/compiler-plugin-options.d.ts +++ b/packages/rsbuild-plugin-angular/src/lib/plugin/models/compiler-plugin-options.d.ts @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import { SourceFileCache } from './source-file-cache'; +import { SourceFileCache } from '../utils/source-file-cache'; export interface CompilerPluginOptions { sourcemap: boolean; tsconfig: string; diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-16.unit.test.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-16.unit.test.ts new file mode 100644 index 0000000..c5f2a48 --- /dev/null +++ b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-16.unit.test.ts @@ -0,0 +1,22 @@ +import { describe, expect } from 'vitest'; + +vi.mock('@angular/compiler-cli', async () => { + const actual = await vi.importActual('@angular/compiler-cli'); + return { + ...actual, + VERSION: { + major: 16, + minor: 4, + patch: 2, + }, + }; +}); + +describe('devkit importing an angular version >=16 & <18', async () => { + // @TODO fins a way to mock require calls instead of testing the error + it('should return the exports', async () => { + expect(import('./devkit.ts')).rejects.toThrow( + '@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js' + ); + }); +}); diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-next.unit.test.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-next.unit.test.ts new file mode 100644 index 0000000..4a98301 --- /dev/null +++ b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng-next.unit.test.ts @@ -0,0 +1,28 @@ +import { describe, expect } from 'vitest'; + +vi.mock('@angular/compiler-cli', async () => { + const actual = await vi.importActual('@angular/compiler-cli'); + return { + ...actual, + VERSION: { + major: 19, + minor: 4, + patch: 2, + }, + }; +}); + +describe('devkit importing an angular version >=19', async () => { + it('should return the exports', async () => { + expect(import('./devkit.ts')).resolves.toStrictEqual( + expect.objectContaining({ + JavaScriptTransformer: expect.any(Function), + SourceFileCache: expect.any(Function), + angularMajor: 19, + angularMinor: 4, + angularPatch: 2, + createJitResourceTransformer: expect.any(Function), + }) + ); + }); +}); diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-failing-import.unit.test.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng14.unit.test.ts similarity index 100% rename from packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-failing-import.unit.test.ts rename to packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng14.unit.test.ts diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng15.unit.test.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng15.unit.test.ts new file mode 100644 index 0000000..ba8c2a4 --- /dev/null +++ b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/devkit-import-ng15.unit.test.ts @@ -0,0 +1,22 @@ +import { describe, expect } from 'vitest'; + +vi.mock('@angular/compiler-cli', async () => { + const actual = await vi.importActual('@angular/compiler-cli'); + return { + ...actual, + VERSION: { + major: 15, + minor: 4, + patch: 2, + }, + }; +}); + +describe('devkit importing an angular version >=15 & <16', async () => { + // @TODO fins a way to mock require calls instead of testing the error + it('should return the exports', async () => { + expect(import('./devkit.ts')).rejects.toThrow( + '@angular-devkit/build-angular/src/builders/browser-esbuild/compiler-plugin.js' + ); + }); +}); diff --git a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/utils.unit.test.ts b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/utils.unit.test.ts index 8bf7073..363bc06 100644 --- a/packages/rsbuild-plugin-angular/src/lib/plugin/utils/utils.unit.test.ts +++ b/packages/rsbuild-plugin-angular/src/lib/plugin/utils/utils.unit.test.ts @@ -7,7 +7,7 @@ import { normalizeQuotes, } from './utils'; import { SyntaxKind } from 'ts-morph'; -import { sourceFileFromCode } from 'testing-utils'; +import { sourceFileFromCode } from '@ng-rspack/testing-utils'; vi.mock('node:os', async (importOriginal) => { const actual = await importOriginal();