From e619bc403b2f7918716c9663d7f8e49e2e457728 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 2 Jan 2024 09:51:18 +0100 Subject: [PATCH] feat: challenge 42 --- README.md | 2 +- apps/nx/static-dynamic-import/.eslintrc.json | 36 +++ apps/nx/static-dynamic-import/README.md | 13 ++ apps/nx/static-dynamic-import/project.json | 73 ++++++ .../src/app/app.component.ts | 26 +++ .../src/app/app.config.ts | 14 ++ .../static-dynamic-import/src/assets/.gitkeep | 0 apps/nx/static-dynamic-import/src/favicon.ico | Bin 0 -> 15086 bytes apps/nx/static-dynamic-import/src/index.html | 13 ++ apps/nx/static-dynamic-import/src/main.ts | 7 + apps/nx/static-dynamic-import/src/styles.scss | 5 + .../static-dynamic-import/tailwind.config.js | 14 ++ .../static-dynamic-import/tsconfig.app.json | 10 + .../tsconfig.editor.json | 7 + apps/nx/static-dynamic-import/tsconfig.json | 30 +++ challenge-number.json | 4 +- .../forms/41-control-value-accessor.md | 1 - .../challenges/nx/42-static-dynamic-import.md | 30 +++ docs/src/content/docs/index.mdx | 6 +- .../users/.eslintrc.json | 36 +++ libs/static-dynamic-import/users/README.md | 3 + libs/static-dynamic-import/users/project.json | 14 ++ libs/static-dynamic-import/users/src/index.ts | 3 + .../users/src/lib/user.model.ts | 5 + .../users/src/lib/user.pipe.ts | 12 + .../users/src/lib/users.component.ts | 36 +++ .../static-dynamic-import/users/tsconfig.json | 26 +++ .../users/tsconfig.lib.json | 12 + package-lock.json | 221 ++++++++++++++++++ package.json | 1 + tsconfig.base.json | 3 + 31 files changed, 656 insertions(+), 7 deletions(-) create mode 100644 apps/nx/static-dynamic-import/.eslintrc.json create mode 100644 apps/nx/static-dynamic-import/README.md create mode 100644 apps/nx/static-dynamic-import/project.json create mode 100644 apps/nx/static-dynamic-import/src/app/app.component.ts create mode 100644 apps/nx/static-dynamic-import/src/app/app.config.ts create mode 100644 apps/nx/static-dynamic-import/src/assets/.gitkeep create mode 100644 apps/nx/static-dynamic-import/src/favicon.ico create mode 100644 apps/nx/static-dynamic-import/src/index.html create mode 100644 apps/nx/static-dynamic-import/src/main.ts create mode 100644 apps/nx/static-dynamic-import/src/styles.scss create mode 100644 apps/nx/static-dynamic-import/tailwind.config.js create mode 100644 apps/nx/static-dynamic-import/tsconfig.app.json create mode 100644 apps/nx/static-dynamic-import/tsconfig.editor.json create mode 100644 apps/nx/static-dynamic-import/tsconfig.json create mode 100644 docs/src/content/docs/challenges/nx/42-static-dynamic-import.md create mode 100644 libs/static-dynamic-import/users/.eslintrc.json create mode 100644 libs/static-dynamic-import/users/README.md create mode 100644 libs/static-dynamic-import/users/project.json create mode 100644 libs/static-dynamic-import/users/src/index.ts create mode 100644 libs/static-dynamic-import/users/src/lib/user.model.ts create mode 100644 libs/static-dynamic-import/users/src/lib/user.pipe.ts create mode 100644 libs/static-dynamic-import/users/src/lib/users.component.ts create mode 100644 libs/static-dynamic-import/users/tsconfig.json create mode 100644 libs/static-dynamic-import/users/tsconfig.lib.json diff --git a/README.md b/README.md index 0d4ea01..bd75ec7 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ If you would like to propose a challenge, this project is open source, so feel f ## Challenges -Check [all 41 challenges](https://angular-challenges.vercel.app/) +Check [all 42 challenges](https://angular-challenges.vercel.app/) ## Contributors ✨ diff --git a/apps/nx/static-dynamic-import/.eslintrc.json b/apps/nx/static-dynamic-import/.eslintrc.json new file mode 100644 index 0000000..8ebcbfd --- /dev/null +++ b/apps/nx/static-dynamic-import/.eslintrc.json @@ -0,0 +1,36 @@ +{ + "extends": ["../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "extends": [ + "plugin:@nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ], + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "app", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "app", + "style": "kebab-case" + } + ] + } + }, + { + "files": ["*.html"], + "extends": ["plugin:@nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/nx/static-dynamic-import/README.md b/apps/nx/static-dynamic-import/README.md new file mode 100644 index 0000000..54691c7 --- /dev/null +++ b/apps/nx/static-dynamic-import/README.md @@ -0,0 +1,13 @@ +# Static vs Dynamic Import + +> author: thomas-laforge + +### Run Application + +```bash +npx nx serve nx-static-dynamic-import +``` + +### Documentation and Instruction + +Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/nx/42-static-dynamic-import/). diff --git a/apps/nx/static-dynamic-import/project.json b/apps/nx/static-dynamic-import/project.json new file mode 100644 index 0000000..2359641 --- /dev/null +++ b/apps/nx/static-dynamic-import/project.json @@ -0,0 +1,73 @@ +{ + "name": "nx-static-dynamic-import", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "prefix": "app", + "sourceRoot": "apps/nx/static-dynamic-import/src", + "tags": [], + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:application", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/nx/static-dynamic-import", + "index": "apps/nx/static-dynamic-import/src/index.html", + "browser": "apps/nx/static-dynamic-import/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/nx/static-dynamic-import/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/nx/static-dynamic-import/src/favicon.ico", + "apps/nx/static-dynamic-import/src/assets" + ], + "styles": ["apps/nx/static-dynamic-import/src/styles.scss"], + "scripts": [] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "outputHashing": "all" + }, + "development": { + "optimization": false, + "extractLicenses": false, + "sourceMap": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "executor": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "buildTarget": "nx-static-dynamic-import:build:production" + }, + "development": { + "buildTarget": "nx-static-dynamic-import:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "buildTarget": "nx-static-dynamic-import:build" + } + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + } + } +} diff --git a/apps/nx/static-dynamic-import/src/app/app.component.ts b/apps/nx/static-dynamic-import/src/app/app.component.ts new file mode 100644 index 0000000..b4b1db0 --- /dev/null +++ b/apps/nx/static-dynamic-import/src/app/app.component.ts @@ -0,0 +1,26 @@ +import { + UserPipe, + type User, +} from '@angular-challenges/static-dynamic-import/users'; +import { Component } from '@angular/core'; +import { RouterOutlet } from '@angular/router'; + +@Component({ + standalone: true, + imports: [UserPipe, RouterOutlet], + selector: 'app-root', + template: ` + Author: {{ author | user }} + + `, + host: { + class: 'flex flex-col', + }, +}) +export class AppComponent { + author: User = { + name: 'Thomas', + lastname: 'Laforge', + country: 'France', + }; +} diff --git a/apps/nx/static-dynamic-import/src/app/app.config.ts b/apps/nx/static-dynamic-import/src/app/app.config.ts new file mode 100644 index 0000000..e058094 --- /dev/null +++ b/apps/nx/static-dynamic-import/src/app/app.config.ts @@ -0,0 +1,14 @@ +import { ApplicationConfig } from '@angular/core'; +import { provideRouter } from '@angular/router'; + +export const appConfig: ApplicationConfig = { + providers: [ + provideRouter([ + { + path: '', + loadComponent: () => + import('@angular-challenges/static-dynamic-import/users'), + }, + ]), + ], +}; diff --git a/apps/nx/static-dynamic-import/src/assets/.gitkeep b/apps/nx/static-dynamic-import/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/nx/static-dynamic-import/src/favicon.ico b/apps/nx/static-dynamic-import/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..317ebcb2336e0833a22dddf0ab287849f26fda57 GIT binary patch literal 15086 zcmeI332;U^%p|z7g|#(P)qFEA@4f!_@qOK2 z_lJl}!lhL!VT_U|uN7%8B2iKH??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P==i3hEwK%|>fZ)c&@kgKO1~5<5xBSk?iZV?KI6&i72H6S9A* z=U(*e)EqEs?Oc04)V-~K5AUmh|62H4*`UAtItO$O(q5?6jj+K^oD!04r=6#dsxp?~}{`?&sXn#q2 zGuY~7>O2=!u@@Kfu7q=W*4egu@qPMRM>(eyYyaIE<|j%d=iWNdGsx%c!902v#ngNg z@#U-O_4xN$s_9?(`{>{>7~-6FgWpBpqXb`Ydc3OFL#&I}Irse9F_8R@4zSS*Y*o*B zXL?6*Aw!AfkNCgcr#*yj&p3ZDe2y>v$>FUdKIy_2N~}6AbHc7gA3`6$g@1o|dE>vz z4pl(j9;kyMsjaw}lO?(?Xg%4k!5%^t#@5n=WVc&JRa+XT$~#@rldvN3S1rEpU$;XgxVny7mki3 z-Hh|jUCHrUXuLr!)`w>wgO0N%KTB-1di>cj(x3Bav`7v z3G7EIbU$z>`Nad7Rk_&OT-W{;qg)-GXV-aJT#(ozdmnA~Rq3GQ_3mby(>q6Ocb-RgTUhTN)))x>m&eD;$J5Bg zo&DhY36Yg=J=$Z>t}RJ>o|@hAcwWzN#r(WJ52^g$lh^!63@hh+dR$&_dEGu&^CR*< z!oFqSqO@>xZ*nC2oiOd0eS*F^IL~W-rsrO`J`ej{=ou_q^_(<$&-3f^J z&L^MSYWIe{&pYq&9eGaArA~*kA + + + + nx-static-dynamic-import + + + + + + + + diff --git a/apps/nx/static-dynamic-import/src/main.ts b/apps/nx/static-dynamic-import/src/main.ts new file mode 100644 index 0000000..f3a7223 --- /dev/null +++ b/apps/nx/static-dynamic-import/src/main.ts @@ -0,0 +1,7 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; +import { appConfig } from './app/app.config'; + +bootstrapApplication(AppComponent, appConfig).catch((err) => + console.error(err), +); diff --git a/apps/nx/static-dynamic-import/src/styles.scss b/apps/nx/static-dynamic-import/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/nx/static-dynamic-import/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/nx/static-dynamic-import/tailwind.config.js b/apps/nx/static-dynamic-import/tailwind.config.js new file mode 100644 index 0000000..38183db --- /dev/null +++ b/apps/nx/static-dynamic-import/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); +const { join } = require('path'); + +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: [ + join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), + ...createGlobPatternsForDependencies(__dirname), + ], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/apps/nx/static-dynamic-import/tsconfig.app.json b/apps/nx/static-dynamic-import/tsconfig.app.json new file mode 100644 index 0000000..5822042 --- /dev/null +++ b/apps/nx/static-dynamic-import/tsconfig.app.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [] + }, + "files": ["src/main.ts"], + "include": ["src/**/*.d.ts"], + "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"] +} diff --git a/apps/nx/static-dynamic-import/tsconfig.editor.json b/apps/nx/static-dynamic-import/tsconfig.editor.json new file mode 100644 index 0000000..4ee6393 --- /dev/null +++ b/apps/nx/static-dynamic-import/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": [] + } +} diff --git a/apps/nx/static-dynamic-import/tsconfig.json b/apps/nx/static-dynamic-import/tsconfig.json new file mode 100644 index 0000000..b94f883 --- /dev/null +++ b/apps/nx/static-dynamic-import/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "target": "es2022", + "useDefineForClassFields": false, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.editor.json" + } + ], + "extends": "../../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/challenge-number.json b/challenge-number.json index e4f0d37..ac1eeb8 100644 --- a/challenge-number.json +++ b/challenge-number.json @@ -1,6 +1,6 @@ { - "total": 41, - "🟢": 14, + "total": 42, + "🟢": 15, "🟠": 120, "🔴": 207 } diff --git a/docs/src/content/docs/challenges/forms/41-control-value-accessor.md b/docs/src/content/docs/challenges/forms/41-control-value-accessor.md index 54aa1cc..aa4c6b5 100644 --- a/docs/src/content/docs/challenges/forms/41-control-value-accessor.md +++ b/docs/src/content/docs/challenges/forms/41-control-value-accessor.md @@ -6,7 +6,6 @@ challengeNumber: 41 command: forms-control-value-accessor sidebar: order: 1 - badge: New --- ## Information diff --git a/docs/src/content/docs/challenges/nx/42-static-dynamic-import.md b/docs/src/content/docs/challenges/nx/42-static-dynamic-import.md new file mode 100644 index 0000000..dff79d4 --- /dev/null +++ b/docs/src/content/docs/challenges/nx/42-static-dynamic-import.md @@ -0,0 +1,30 @@ +--- +title: 🟢 Static vs Dynamic Import +description: Challenge 42 is about understanding and fixing the eslint rule - Static imports of lazy-loaded libraries are forbidden. +author: thomas-laforge +challengeNumber: 42 +command: nx-static-dynamic-import +sidebar: + order: 15 + badge: New +--- + +## Information + +If you are using **Nx**, you might have encountered this error: + +```ts +Static imports of lazy-loaded libraries are forbidden. + +Library "users" is lazy-loaded in these files: + +- apps/nx/static-dynamic-import/src/app/app.config.ts eslint@nx/enforce-module-boundaries +``` + +This error is part of the ESLint rule embedded by Nx to prevent people from mixing lazy-loading and eagerly-loading code from the same library. Although this error will not break at runtime or build time, it can lead to consequences for bundle size. The lazy-loaded code will end up in the main bundle, nullifying all the benefits of lazy-loading a library. + +## Statement + +The goal of this challenge is to improve the code architecture to eliminate this ESLint error. + +You will learn how to create a library and how to rearrange code. diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index aadce35..f094067 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -13,7 +13,7 @@ hero: icon: right-arrow variant: primary - text: Go to the latest Challenge - link: /challenges/forms/41-control-value-accessor/ + link: /challenges/nx/42-static-dynamic-import/ icon: rocket - text: Give a star link: https://github.com/tomalaforge/angular-challenges @@ -25,8 +25,8 @@ import { Card, CardGrid } from '@astrojs/starlight/components'; import MyIcon from '../../components/MyIcon.astro'; - - This repository gathers 41 Challenges related to Angular, Nx, RxJS, Ngrx and Typescript. + + This repository gathers 42 Challenges related to Angular, Nx, RxJS, Ngrx and Typescript. These challenges resolve around real-life issues or specific features to elevate your skills. diff --git a/libs/static-dynamic-import/users/.eslintrc.json b/libs/static-dynamic-import/users/.eslintrc.json new file mode 100644 index 0000000..2dd6f81 --- /dev/null +++ b/libs/static-dynamic-import/users/.eslintrc.json @@ -0,0 +1,36 @@ +{ + "extends": ["../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "extends": [ + "plugin:@nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ], + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "sdi", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "sdi", + "style": "kebab-case" + } + ] + } + }, + { + "files": ["*.html"], + "extends": ["plugin:@nx/angular-template"], + "rules": {} + } + ] +} diff --git a/libs/static-dynamic-import/users/README.md b/libs/static-dynamic-import/users/README.md new file mode 100644 index 0000000..8315f1b --- /dev/null +++ b/libs/static-dynamic-import/users/README.md @@ -0,0 +1,3 @@ +# users + +This library was generated with [Nx](https://nx.dev). diff --git a/libs/static-dynamic-import/users/project.json b/libs/static-dynamic-import/users/project.json new file mode 100644 index 0000000..8b5e0b7 --- /dev/null +++ b/libs/static-dynamic-import/users/project.json @@ -0,0 +1,14 @@ +{ + "name": "users", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/static-dynamic-import/users/src", + "prefix": "sdi", + "tags": [], + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + } + } +} diff --git a/libs/static-dynamic-import/users/src/index.ts b/libs/static-dynamic-import/users/src/index.ts new file mode 100644 index 0000000..786abee --- /dev/null +++ b/libs/static-dynamic-import/users/src/index.ts @@ -0,0 +1,3 @@ +export type { User } from './lib/user.model'; +export { UserPipe } from './lib/user.pipe'; +export { default } from './lib/users.component'; diff --git a/libs/static-dynamic-import/users/src/lib/user.model.ts b/libs/static-dynamic-import/users/src/lib/user.model.ts new file mode 100644 index 0000000..4da2247 --- /dev/null +++ b/libs/static-dynamic-import/users/src/lib/user.model.ts @@ -0,0 +1,5 @@ +export interface User { + name: string; + lastname: string; + country: string; +} diff --git a/libs/static-dynamic-import/users/src/lib/user.pipe.ts b/libs/static-dynamic-import/users/src/lib/user.pipe.ts new file mode 100644 index 0000000..ff28f77 --- /dev/null +++ b/libs/static-dynamic-import/users/src/lib/user.pipe.ts @@ -0,0 +1,12 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { User } from './user.model'; + +@Pipe({ + name: 'user', + standalone: true, +}) +export class UserPipe implements PipeTransform { + transform(user: User): string { + return `${user.name} ${user.lastname} - ${user.country}`; + } +} diff --git a/libs/static-dynamic-import/users/src/lib/users.component.ts b/libs/static-dynamic-import/users/src/lib/users.component.ts new file mode 100644 index 0000000..1967096 --- /dev/null +++ b/libs/static-dynamic-import/users/src/lib/users.component.ts @@ -0,0 +1,36 @@ +import { Component } from '@angular/core'; + +import { randCountry, randFirstName, randLastName } from '@ngneat/falso'; +import type { User } from './user.model'; +import { UserPipe } from './user.pipe'; + +export const randUser = (): User => ({ + name: randFirstName(), + lastname: randLastName(), + country: randCountry(), +}); + +@Component({ + selector: 'sdi-users', + standalone: true, + imports: [UserPipe], + template: ` +

List of Users

+ @for (user of users; track user) { +
{{ user | user }}
+ } + `, + host: { + class: 'flex flex-col', + }, +}) +export default class UsersComponent { + users = [ + randUser(), + randUser(), + randUser(), + randUser(), + randUser(), + randUser(), + ]; +} diff --git a/libs/static-dynamic-import/users/tsconfig.json b/libs/static-dynamic-import/users/tsconfig.json new file mode 100644 index 0000000..8e62d6d --- /dev/null +++ b/libs/static-dynamic-import/users/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "es2022", + "useDefineForClassFields": false, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ], + "extends": "../../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/libs/static-dynamic-import/users/tsconfig.lib.json b/libs/static-dynamic-import/users/tsconfig.lib.json new file mode 100644 index 0000000..f68063a --- /dev/null +++ b/libs/static-dynamic-import/users/tsconfig.lib.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [] + }, + "exclude": ["src/**/*.spec.ts", "jest.config.ts", "src/**/*.test.ts"], + "include": ["src/**/*.ts"] +} diff --git a/package-lock.json b/package-lock.json index 9c687ab..c0835f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,6 +94,7 @@ "prettier": "^3.1.0", "prettier-plugin-organize-imports": "^3.2.4", "prettier-plugin-tailwindcss": "^0.5.9", + "source-map-explorer": "^2.5.3", "testing-library-selector": "^0.3.1", "ts-jest": "29.1.0", "ts-node": "10.9.1", @@ -11438,6 +11439,18 @@ "node-int64": "^0.4.0" } }, + "node_modules/btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==", + "dev": true, + "bin": { + "btoa": "bin/btoa.js" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -15900,6 +15913,21 @@ "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==" }, + "node_modules/gzip-size": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-6.0.0.tgz", + "integrity": "sha512-ax7ZYomf6jqPTQ4+XCpUGyXKHk5WweS+e05MBO4/y3WJ5RkmPXNKvX+bx1behVILVwr6JSQvZAku021CHPXG3Q==", + "dev": true, + "dependencies": { + "duplexer": "^0.1.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -26463,6 +26491,174 @@ "node": ">= 8" } }, + "node_modules/source-map-explorer": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/source-map-explorer/-/source-map-explorer-2.5.3.tgz", + "integrity": "sha512-qfUGs7UHsOBE5p/lGfQdaAj/5U/GWYBw2imEpD6UQNkqElYonkow8t+HBL1qqIl3CuGZx7n8/CQo4x1HwSHhsg==", + "dev": true, + "dependencies": { + "btoa": "^1.2.1", + "chalk": "^4.1.0", + "convert-source-map": "^1.7.0", + "ejs": "^3.1.5", + "escape-html": "^1.0.3", + "glob": "^7.1.6", + "gzip-size": "^6.0.0", + "lodash": "^4.17.20", + "open": "^7.3.1", + "source-map": "^0.7.4", + "temp": "^0.9.4", + "yargs": "^16.2.0" + }, + "bin": { + "sme": "bin/cli.js", + "source-map-explorer": "bin/cli.js" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/source-map-explorer/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/source-map-explorer/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/source-map-explorer/node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/source-map-explorer/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/source-map-explorer/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/source-map-explorer/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/source-map-explorer/node_modules/open": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/source-map-explorer/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/source-map-explorer/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/source-map-explorer/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/source-map-explorer/node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/source-map-js": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", @@ -27367,6 +27563,31 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "devOptional": true }, + "node_modules/temp": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/temp/-/temp-0.9.4.tgz", + "integrity": "sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==", + "dev": true, + "dependencies": { + "mkdirp": "^0.5.1", + "rimraf": "~2.6.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/temp/node_modules/rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, "node_modules/terser": { "version": "5.24.0", "resolved": "https://registry.npmjs.org/terser/-/terser-5.24.0.tgz", diff --git a/package.json b/package.json index 239bd0d..172d882 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "prettier": "^3.1.0", "prettier-plugin-organize-imports": "^3.2.4", "prettier-plugin-tailwindcss": "^0.5.9", + "source-map-explorer": "^2.5.3", "testing-library-selector": "^0.3.1", "ts-jest": "29.1.0", "ts-node": "10.9.1", diff --git a/tsconfig.base.json b/tsconfig.base.json index b65917d..9f30ed8 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -76,6 +76,9 @@ ], "@tomalaforge/ngrx-callstate-store": [ "libs/shared/ngrx-callstate-store/src/index.ts" + ], + "@angular-challenges/static-dynamic-import/users": [ + "libs/static-dynamic-import/users/src/index.ts" ] } },