diff --git a/.gitignore b/.gitignore index 21c7597e93..0fe167cd37 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ e2e/**/.yarn/* !e2e/**/.yarn/releases !e2e/**/.yarn/sdks !e2e/**/.yarn/versions +!/e2e/ng-lib-import/node_modules src/transformers/downlevel_decorators_transform src/ngtsc diff --git a/e2e/__tests__/ng-lib-import.test.ts b/e2e/__tests__/ng-lib-import.test.ts new file mode 100644 index 0000000000..10807a1d69 --- /dev/null +++ b/e2e/__tests__/ng-lib-import.test.ts @@ -0,0 +1,15 @@ +import { json as runWithJson } from '../run-jest'; + +const DIR = 'ng-lib-import'; + +test(`successfully runs the tests inside ${DIR} with isolatedModules: false`, () => { + const { json } = runWithJson(DIR); + + expect(json.success).toBe(true); +}); + +test(`successfully runs the tests inside ${DIR} with isolatedModules: true`, () => { + const { json } = runWithJson(DIR, ['-c=jest-isolated.config.js']); + + expect(json.success).toBe(true); +}); diff --git a/e2e/ast-transformers/ng-jit-transformers/jest.config.js b/e2e/ast-transformers/ng-jit-transformers/jest.config.js index 9ab9f75beb..4fb8643027 100644 --- a/e2e/ast-transformers/ng-jit-transformers/jest.config.js +++ b/e2e/ast-transformers/ng-jit-transformers/jest.config.js @@ -10,5 +10,5 @@ module.exports = { transform: { '^.+\\.(ts|js|mjs|html)$': '/../../../build/index.js', }, - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/async/jest.config.js b/e2e/async/jest.config.js index 880767333d..d8e6b0385b 100644 --- a/e2e/async/jest.config.js +++ b/e2e/async/jest.config.js @@ -14,5 +14,5 @@ module.exports = { testEnvironment: 'jsdom', setupFilesAfterEnv: ['/../../setup-jest.js'], transform: { '^.+\\.(ts|mjs|js|html)$': '/../../build/index.js' }, - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/ng-deep-import/jest.config.js b/e2e/ng-deep-import/jest.config.js index e408a10242..ef63f47793 100644 --- a/e2e/ng-deep-import/jest.config.js +++ b/e2e/ng-deep-import/jest.config.js @@ -4,5 +4,5 @@ module.exports = { transform: { '^.+\\.(ts|js|mjs|html)$': '/../../build/index.js', }, - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/e2e/ng-lib-import/__tests__/ng-lib-import.spec.ts b/e2e/ng-lib-import/__tests__/ng-lib-import.spec.ts new file mode 100644 index 0000000000..bf99068837 --- /dev/null +++ b/e2e/ng-lib-import/__tests__/ng-lib-import.spec.ts @@ -0,0 +1,5 @@ +import { MyLibService } from 'my-lib'; + +test('should pass', () => { + expect(new MyLibService()).toBeInstanceOf(MyLibService); +}); diff --git a/e2e/ng-lib-import/jest-isolated.config.js b/e2e/ng-lib-import/jest-isolated.config.js new file mode 100644 index 0000000000..307dd460ab --- /dev/null +++ b/e2e/ng-lib-import/jest-isolated.config.js @@ -0,0 +1,10 @@ +const baseCfg = require('./jest.config'); + +module.exports = { + ...baseCfg, + globals: { + 'ts-jest': { + isolatedModules: true, + }, + }, +}; diff --git a/e2e/ng-lib-import/jest.config.js b/e2e/ng-lib-import/jest.config.js new file mode 100644 index 0000000000..51308cb32a --- /dev/null +++ b/e2e/ng-lib-import/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'], + resolver: '/../../build/resolvers/ng-jest-resolver.js', + setupFilesAfterEnv: ['/../../setup-jest.js'], + testEnvironment: 'jsdom', + transform: { + '^.+\\.(ts|js|mjs|html)$': '/../../build/index.js', + }, + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], +}; diff --git a/e2e/ng-lib-import/node_modules/my-lib/README.md b/e2e/ng-lib-import/node_modules/my-lib/README.md new file mode 100644 index 0000000000..79269ccd97 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/README.md @@ -0,0 +1,24 @@ +# MyLib + +This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.0.0. + +## Code scaffolding + +Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`. +> Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file. + +## Build + +Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Publishing + +After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`. + +## Running unit tests + +Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. diff --git a/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.component.mjs b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.component.mjs new file mode 100644 index 0000000000..36e062f18b --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.component.mjs @@ -0,0 +1,26 @@ +import { Component } from '@angular/core'; +import * as i0 from "@angular/core"; +export class MyLibComponent { + constructor() { } + ngOnInit() { + } +} +MyLibComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); +MyLibComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: MyLibComponent, selector: "lib-my-lib", ngImport: i0, template: ` +

+ my-lib works! +

+ `, isInline: true }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, decorators: [{ + type: Component, + args: [{ + selector: 'lib-my-lib', + template: ` +

+ my-lib works! +

+ `, + styles: [] + }] + }], ctorParameters: function () { return []; } }); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXktbGliLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL215LWxpYi9zcmMvbGliL215LWxpYi5jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBVSxNQUFNLGVBQWUsQ0FBQzs7QUFZbEQsTUFBTSxPQUFPLGNBQWM7SUFFekIsZ0JBQWdCLENBQUM7SUFFakIsUUFBUTtJQUNSLENBQUM7OzJHQUxVLGNBQWM7K0ZBQWQsY0FBYyxrREFSZjs7OztHQUlUOzJGQUlVLGNBQWM7a0JBVjFCLFNBQVM7bUJBQUM7b0JBQ1QsUUFBUSxFQUFFLFlBQVk7b0JBQ3RCLFFBQVEsRUFBRTs7OztHQUlUO29CQUNELE1BQU0sRUFBRSxFQUNQO2lCQUNGIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgQ29tcG9uZW50LCBPbkluaXQgfSBmcm9tICdAYW5ndWxhci9jb3JlJztcblxuQENvbXBvbmVudCh7XG4gIHNlbGVjdG9yOiAnbGliLW15LWxpYicsXG4gIHRlbXBsYXRlOiBgXG4gICAgPHA+XG4gICAgICBteS1saWIgd29ya3MhXG4gICAgPC9wPlxuICBgLFxuICBzdHlsZXM6IFtcbiAgXVxufSlcbmV4cG9ydCBjbGFzcyBNeUxpYkNvbXBvbmVudCBpbXBsZW1lbnRzIE9uSW5pdCB7XG5cbiAgY29uc3RydWN0b3IoKSB7IH1cblxuICBuZ09uSW5pdCgpOiB2b2lkIHtcbiAgfVxuXG59XG4iXX0= \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.module.mjs b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.module.mjs new file mode 100644 index 0000000000..18fbf6a9ea --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.module.mjs @@ -0,0 +1,21 @@ +import { NgModule } from '@angular/core'; +import { MyLibComponent } from 'my-lib/esm2020/lib/my-lib.component.mjs'; +import * as i0 from "@angular/core"; +export class MyLibModule { +} +MyLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); +MyLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, declarations: [MyLibComponent], exports: [MyLibComponent] }); +MyLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, imports: [[]] }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, decorators: [{ + type: NgModule, + args: [{ + declarations: [ + MyLibComponent + ], + imports: [], + exports: [ + MyLibComponent + ] + }] + }] }); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXktbGliLm1vZHVsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL215LWxpYi9zcmMvbGliL215LWxpYi5tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUN6QyxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sb0JBQW9CLENBQUM7O0FBY3BELE1BQU0sT0FBTyxXQUFXOzt3R0FBWCxXQUFXO3lHQUFYLFdBQVcsaUJBUnBCLGNBQWMsYUFLZCxjQUFjO3lHQUdMLFdBQVcsWUFOYixFQUNSOzJGQUtVLFdBQVc7a0JBVnZCLFFBQVE7bUJBQUM7b0JBQ1IsWUFBWSxFQUFFO3dCQUNaLGNBQWM7cUJBQ2Y7b0JBQ0QsT0FBTyxFQUFFLEVBQ1I7b0JBQ0QsT0FBTyxFQUFFO3dCQUNQLGNBQWM7cUJBQ2Y7aUJBQ0YiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBOZ01vZHVsZSB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuaW1wb3J0IHsgTXlMaWJDb21wb25lbnQgfSBmcm9tICcuL215LWxpYi5jb21wb25lbnQnO1xuXG5cblxuQE5nTW9kdWxlKHtcbiAgZGVjbGFyYXRpb25zOiBbXG4gICAgTXlMaWJDb21wb25lbnRcbiAgXSxcbiAgaW1wb3J0czogW1xuICBdLFxuICBleHBvcnRzOiBbXG4gICAgTXlMaWJDb21wb25lbnRcbiAgXVxufSlcbmV4cG9ydCBjbGFzcyBNeUxpYk1vZHVsZSB7IH1cbiJdfQ== \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.service.mjs b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.service.mjs new file mode 100644 index 0000000000..fb7bfeaf39 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/esm2020/lib/my-lib.service.mjs @@ -0,0 +1,14 @@ +import { Injectable } from '@angular/core'; +import * as i0 from "@angular/core"; +export class MyLibService { + constructor() { } +} +MyLibService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); +MyLibService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, providedIn: 'root' }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, decorators: [{ + type: Injectable, + args: [{ + providedIn: 'root' + }] + }], ctorParameters: function () { return []; } }); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXktbGliLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9teS1saWIvc3JjL2xpYi9teS1saWIuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDOztBQUszQyxNQUFNLE9BQU8sWUFBWTtJQUV2QixnQkFBZ0IsQ0FBQzs7eUdBRk4sWUFBWTs2R0FBWixZQUFZLGNBRlgsTUFBTTsyRkFFUCxZQUFZO2tCQUh4QixVQUFVO21CQUFDO29CQUNWLFVBQVUsRUFBRSxNQUFNO2lCQUNuQiIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IEluamVjdGFibGUgfSBmcm9tICdAYW5ndWxhci9jb3JlJztcblxuQEluamVjdGFibGUoe1xuICBwcm92aWRlZEluOiAncm9vdCdcbn0pXG5leHBvcnQgY2xhc3MgTXlMaWJTZXJ2aWNlIHtcblxuICBjb25zdHJ1Y3RvcigpIHsgfVxufVxuIl19 \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/esm2020/my-lib.mjs b/e2e/ng-lib-import/node_modules/my-lib/esm2020/my-lib.mjs new file mode 100644 index 0000000000..3c7cf1d0af --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/esm2020/my-lib.mjs @@ -0,0 +1,5 @@ +/** + * Generated bundle index. Do not edit. + */ +export * from 'my-lib/esm2020/public-api.mjs'; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXktbGliLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vcHJvamVjdHMvbXktbGliL3NyYy9teS1saWIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ== \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/esm2020/public-api.mjs b/e2e/ng-lib-import/node_modules/my-lib/esm2020/public-api.mjs new file mode 100644 index 0000000000..fb10293c42 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/esm2020/public-api.mjs @@ -0,0 +1,7 @@ +/* + * Public API Surface of my-lib + */ +export * from 'my-lib/esm2020/lib/my-lib.service.mjs'; +export * from 'my-lib/esm2020/lib/my-lib.component.mjs'; +export * from 'my-lib/esm2020/lib/my-lib.module.mjs'; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL215LWxpYi9zcmMvcHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsc0JBQXNCLENBQUM7QUFDckMsY0FBYyx3QkFBd0IsQ0FBQztBQUN2QyxjQUFjLHFCQUFxQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLypcbiAqIFB1YmxpYyBBUEkgU3VyZmFjZSBvZiBteS1saWJcbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL2xpYi9teS1saWIuc2VydmljZSc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9teS1saWIuY29tcG9uZW50JztcbmV4cG9ydCAqIGZyb20gJy4vbGliL215LWxpYi5tb2R1bGUnO1xuIl19 \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs b/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs new file mode 100644 index 0000000000..3ed9912d46 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs @@ -0,0 +1,66 @@ +import * as i0 from '@angular/core'; +import { Injectable, Component, NgModule } from '@angular/core'; + +class MyLibService { + constructor() { } +} +MyLibService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); +MyLibService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, providedIn: 'root' }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, decorators: [{ + type: Injectable, + args: [{ + providedIn: 'root' + }] + }], ctorParameters: function () { return []; } }); + +class MyLibComponent { + constructor() { } + ngOnInit() { + } +} +MyLibComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); +MyLibComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: MyLibComponent, selector: "lib-my-lib", ngImport: i0, template: ` +

+ my-lib works! +

+ `, isInline: true }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, decorators: [{ + type: Component, + args: [{ + selector: 'lib-my-lib', + template: ` +

+ my-lib works! +

+ `, + styles: [] + }] + }], ctorParameters: function () { return []; } }); + +class MyLibModule { +} +MyLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); +MyLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, declarations: [MyLibComponent], exports: [MyLibComponent] }); +MyLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, imports: [[]] }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, decorators: [{ + type: NgModule, + args: [{ + declarations: [ + MyLibComponent + ], + imports: [], + exports: [ + MyLibComponent + ] + }] + }] }); + +/* + * Public API Surface of my-lib + */ + +/** + * Generated bundle index. Do not edit. + */ + +export { MyLibComponent, MyLibModule, MyLibService }; diff --git a/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs.map b/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs.map new file mode 100644 index 0000000000..cd338fbc3e --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/fesm2015/my-lib.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"my-lib.mjs","sources":["../../../projects/my-lib/src/lib/my-lib.service.ts","../../../projects/my-lib/src/lib/my-lib.component.ts","../../../projects/my-lib/src/lib/my-lib.module.ts","../../../projects/my-lib/src/public-api.ts","../../../projects/my-lib/src/my-lib.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MyLibService {\n\n constructor() { }\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'lib-my-lib',\n template: `\n

\n my-lib works!\n

\n `,\n styles: [\n ]\n})\nexport class MyLibComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit(): void {\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { MyLibComponent } from './my-lib.component';\n\n\n\n@NgModule({\n declarations: [\n MyLibComponent\n ],\n imports: [\n ],\n exports: [\n MyLibComponent\n ]\n})\nexport class MyLibModule { }\n","/*\n * Public API Surface of my-lib\n */\n\nexport * from './lib/my-lib.service';\nexport * from './lib/my-lib.component';\nexport * from './lib/my-lib.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAKa,YAAY;IAEvB,iBAAiB;;yGAFN,YAAY;6GAAZ,YAAY,cAFX,MAAM;2FAEP,YAAY;kBAHxB,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB;;;MCQY,cAAc;IAEzB,iBAAiB;IAEjB,QAAQ;KACP;;2GALU,cAAc;+FAAd,cAAc,kDARf;;;;GAIT;2FAIU,cAAc;kBAV1B,SAAS;mBAAC;oBACT,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE;;;;GAIT;oBACD,MAAM,EAAE,EACP;iBACF;;;MCIY,WAAW;;wGAAX,WAAW;yGAAX,WAAW,iBARpB,cAAc,aAKd,cAAc;yGAGL,WAAW,YANb,EACR;2FAKU,WAAW;kBAVvB,QAAQ;mBAAC;oBACR,YAAY,EAAE;wBACZ,cAAc;qBACf;oBACD,OAAO,EAAE,EACR;oBACD,OAAO,EAAE;wBACP,cAAc;qBACf;iBACF;;;ACdD;;;;ACAA;;;;;;"} \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs b/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs new file mode 100644 index 0000000000..3ed9912d46 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs @@ -0,0 +1,66 @@ +import * as i0 from '@angular/core'; +import { Injectable, Component, NgModule } from '@angular/core'; + +class MyLibService { + constructor() { } +} +MyLibService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); +MyLibService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, providedIn: 'root' }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibService, decorators: [{ + type: Injectable, + args: [{ + providedIn: 'root' + }] + }], ctorParameters: function () { return []; } }); + +class MyLibComponent { + constructor() { } + ngOnInit() { + } +} +MyLibComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); +MyLibComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: MyLibComponent, selector: "lib-my-lib", ngImport: i0, template: ` +

+ my-lib works! +

+ `, isInline: true }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibComponent, decorators: [{ + type: Component, + args: [{ + selector: 'lib-my-lib', + template: ` +

+ my-lib works! +

+ `, + styles: [] + }] + }], ctorParameters: function () { return []; } }); + +class MyLibModule { +} +MyLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); +MyLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, declarations: [MyLibComponent], exports: [MyLibComponent] }); +MyLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, imports: [[]] }); +i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MyLibModule, decorators: [{ + type: NgModule, + args: [{ + declarations: [ + MyLibComponent + ], + imports: [], + exports: [ + MyLibComponent + ] + }] + }] }); + +/* + * Public API Surface of my-lib + */ + +/** + * Generated bundle index. Do not edit. + */ + +export { MyLibComponent, MyLibModule, MyLibService }; diff --git a/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs.map b/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs.map new file mode 100644 index 0000000000..cd338fbc3e --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/fesm2020/my-lib.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"my-lib.mjs","sources":["../../../projects/my-lib/src/lib/my-lib.service.ts","../../../projects/my-lib/src/lib/my-lib.component.ts","../../../projects/my-lib/src/lib/my-lib.module.ts","../../../projects/my-lib/src/public-api.ts","../../../projects/my-lib/src/my-lib.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MyLibService {\n\n constructor() { }\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'lib-my-lib',\n template: `\n

\n my-lib works!\n

\n `,\n styles: [\n ]\n})\nexport class MyLibComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit(): void {\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { MyLibComponent } from './my-lib.component';\n\n\n\n@NgModule({\n declarations: [\n MyLibComponent\n ],\n imports: [\n ],\n exports: [\n MyLibComponent\n ]\n})\nexport class MyLibModule { }\n","/*\n * Public API Surface of my-lib\n */\n\nexport * from './lib/my-lib.service';\nexport * from './lib/my-lib.component';\nexport * from './lib/my-lib.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAKa,YAAY;IAEvB,iBAAiB;;yGAFN,YAAY;6GAAZ,YAAY,cAFX,MAAM;2FAEP,YAAY;kBAHxB,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB;;;MCQY,cAAc;IAEzB,iBAAiB;IAEjB,QAAQ;KACP;;2GALU,cAAc;+FAAd,cAAc,kDARf;;;;GAIT;2FAIU,cAAc;kBAV1B,SAAS;mBAAC;oBACT,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE;;;;GAIT;oBACD,MAAM,EAAE,EACP;iBACF;;;MCIY,WAAW;;wGAAX,WAAW;yGAAX,WAAW,iBARpB,cAAc,aAKd,cAAc;yGAGL,WAAW,YANb,EACR;2FAKU,WAAW;kBAVvB,QAAQ;mBAAC;oBACR,YAAY,EAAE;wBACZ,cAAc;qBACf;oBACD,OAAO,EAAE,EACR;oBACD,OAAO,EAAE;wBACP,cAAc;qBACf;iBACF;;;ACdD;;;;ACAA;;;;;;"} \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.component.d.ts b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.component.d.ts new file mode 100644 index 0000000000..108f6150fd --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.component.d.ts @@ -0,0 +1,8 @@ +import { OnInit } from '@angular/core'; +import * as i0 from "@angular/core"; +export declare class MyLibComponent implements OnInit { + constructor(); + ngOnInit(): void; + static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵcmp: i0.ɵɵComponentDeclaration; +} diff --git a/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.module.d.ts b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.module.d.ts new file mode 100644 index 0000000000..6bf36a2342 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.module.d.ts @@ -0,0 +1,7 @@ +import * as i0 from "@angular/core"; +import * as i1 from "my-lib/lib/my-lib.component"; +export declare class MyLibModule { + static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵinj: i0.ɵɵInjectorDeclaration; +} diff --git a/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.service.d.ts b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.service.d.ts new file mode 100644 index 0000000000..9baa658d7b --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/lib/my-lib.service.d.ts @@ -0,0 +1,6 @@ +import * as i0 from "@angular/core"; +export declare class MyLibService { + constructor(); + static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵprov: i0.ɵɵInjectableDeclaration; +} diff --git a/e2e/ng-lib-import/node_modules/my-lib/my-lib.d.ts b/e2e/ng-lib-import/node_modules/my-lib/my-lib.d.ts new file mode 100644 index 0000000000..0493423ead --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/my-lib.d.ts @@ -0,0 +1,5 @@ +/** + * Generated bundle index. Do not edit. + */ +/// +export * from 'my-lib/public-api'; diff --git a/e2e/ng-lib-import/node_modules/my-lib/package.json b/e2e/ng-lib-import/node_modules/my-lib/package.json new file mode 100644 index 0000000000..c3ac2f0463 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/package.json @@ -0,0 +1,31 @@ +{ + "name": "my-lib", + "version": "0.0.1", + "peerDependencies": { + "@angular/common": "^13.0.0", + "@angular/core": "^13.0.0" + }, + "dependencies": { + "tslib": "^2.3.0" + }, + "module": "fesm2015/my-lib.mjs", + "es2020": "fesm2020/my-lib.mjs", + "esm2020": "esm2020/my-lib.mjs", + "fesm2020": "fesm2020/my-lib.mjs", + "fesm2015": "fesm2015/my-lib.mjs", + "typings": "my-lib.d.ts", + "exports": { + "./package.json": { + "default": "./package.json" + }, + ".": { + "types": "./my-lib.d.ts", + "esm2020": "./esm2020/my-lib.mjs", + "es2020": "./fesm2020/my-lib.mjs", + "es2015": "./fesm2015/my-lib.mjs", + "node": "./fesm2015/my-lib.mjs", + "default": "./fesm2020/my-lib.mjs" + } + }, + "sideEffects": false +} \ No newline at end of file diff --git a/e2e/ng-lib-import/node_modules/my-lib/public-api.d.ts b/e2e/ng-lib-import/node_modules/my-lib/public-api.d.ts new file mode 100644 index 0000000000..a7923db8a9 --- /dev/null +++ b/e2e/ng-lib-import/node_modules/my-lib/public-api.d.ts @@ -0,0 +1,3 @@ +export * from 'my-lib/lib/my-lib.service'; +export * from 'my-lib/lib/my-lib.component'; +export * from 'my-lib/lib/my-lib.module'; diff --git a/e2e/ng-lib-import/package.json b/e2e/ng-lib-import/package.json new file mode 100644 index 0000000000..1fa72bc12d --- /dev/null +++ b/e2e/ng-lib-import/package.json @@ -0,0 +1,3 @@ +{ + "name": "ng-lib-import" +} diff --git a/e2e/snapshot-serializers/jest.config.js b/e2e/snapshot-serializers/jest.config.js index 9e7db93aa7..5912820ef6 100644 --- a/e2e/snapshot-serializers/jest.config.js +++ b/e2e/snapshot-serializers/jest.config.js @@ -15,5 +15,5 @@ module.exports = { transform: { '^.+\\.(ts|js|mjs|html)$': '/../../build/index.js', }, - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], }; diff --git a/presets/index.js b/presets/index.js index 099af0836a..5075e53e9e 100644 --- a/presets/index.js +++ b/presets/index.js @@ -16,7 +16,7 @@ const basePreset = { module.exports = { defaults: { ...basePreset, - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', }, diff --git a/src/__tests__/__snapshots__/jest-preset.spec.ts.snap b/src/__tests__/__snapshots__/jest-preset.spec.ts.snap index e31f7def50..bad7d59da4 100644 --- a/src/__tests__/__snapshots__/jest-preset.spec.ts.snap +++ b/src/__tests__/__snapshots__/jest-preset.spec.ts.snap @@ -26,7 +26,7 @@ Object { "^.+\\\\.(ts|js|mjs|html|svg)$": "jest-preset-angular", }, "transformIgnorePatterns": Array [ - "node_modules/(?!@angular)", + "node_modules/(?!.*\\\\.mjs$)", ], } `; diff --git a/website/docs/getting-started/options.md b/website/docs/getting-started/options.md index 4d4c51edd5..c287ac3243 100644 --- a/website/docs/getting-started/options.md +++ b/website/docs/getting-started/options.md @@ -40,7 +40,7 @@ module.exports = { resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js', snapshotSerializers, testEnvironment: 'jsdom', - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', }, @@ -65,5 +65,5 @@ Jest runs with `jest-preset-angular` neither in browser nor through dev server. This package provides serializer to remove such attributes. This makes snapshots cleaner and more human-readable. To remove such specific attributes use `no-ng-attributes` serializer. You need to add `no-ng-attributes` serializer manually. - `"testEnvironment"` – the test environment to run on. -- `"transformIgnorePatterns"`: instruct Jest to transform certain packages which don't contain in `CommonJS` codes. +- `"transformIgnorePatterns"`: instruct Jest to transform any `.mjs` files which come from `node_modules`. - `"transform"` – run every `TS`, `JS`, `MJS`, or `HTML` file through so called _Jest transformer_; this lets Jest understand non-JS syntax. diff --git a/website/docs/guides/angular-13+.md b/website/docs/guides/angular-13+.md index 96c750c3b5..5d1375c299 100644 --- a/website/docs/guides/angular-13+.md +++ b/website/docs/guides/angular-13+.md @@ -41,7 +41,7 @@ module.exports = { // ...other options moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'], resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js', - transformIgnorePatterns: ['node_modules/(?!@angular)'], + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: { '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular', }, @@ -78,4 +78,12 @@ Besides, the changes in Angular packages themselves, **Angular** libraries which ESM package format. Similar to Angular packages, Jest doesn't understand `.mjs` files which are in these new format libraries in Jest **CommonJS** mode. -To fix this issue, one should follow our [troubleshooting instruction](troubleshooting.md#unexpected-token-importexportother) +To fix this issue, one should modify `transformIgnorePatterns` to be as following: + +```js +// jest.config.js +module.exports = { + // ...other options + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], +}; +```