Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): default project schematic resolution #17785

Open
wants to merge 1 commit into
base: master
from

Conversation

@juristr
Copy link
Contributor

@juristr juristr commented May 24, 2020

The current Angular CLI doesn't properly resolve project specific schematic defaults if the project is not passed to the command, but rather the default project is just being used.

Several users reported this for Nx when they had SCSS configured for a given app, but still plain css files were generated.

Example angular.json:

{
  "version": 1,
  "projects": {
    "demoapp": {
      "projectType": "application",
      "schematics": {
        "@nrwl/angular:component": {
          "style": "scss"
        }
      },
      "root": "apps/demoapp",
      "sourceRoot": "apps/demoapp/src",
      "prefix": "ngdefaultschematics",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/apps/demoapp",
            "index": "apps/demoapp/src/index.html",
            "main": "apps/demoapp/src/main.ts",
            "polyfills": "apps/demoapp/src/polyfills.ts",
            "tsConfig": "apps/demoapp/tsconfig.app.json",
            "aot": true,
            "assets": [
              "apps/demoapp/src/favicon.ico",
              "apps/demoapp/src/assets"
            ],
            "styles": ["apps/demoapp/src/styles.scss"],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "apps/demoapp/src/environments/environment.ts",
                  "with": "apps/demoapp/src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "demoapp:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "demoapp:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "demoapp:build"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "apps/demoapp/tsconfig.app.json",
              "apps/demoapp/tsconfig.spec.json"
            ],
            "exclude": ["**/node_modules/**", "!apps/demoapp/**"]
          }
        },
        "test": {
          "builder": "@nrwl/jest:jest",
          "options": {
            "jestConfig": "apps/demoapp/jest.config.js",
            "tsConfig": "apps/demoapp/tsconfig.spec.json",
            "passWithNoTests": true,
            "setupFile": "apps/demoapp/src/test-setup.ts"
          }
        }
      }
    },
    "demoapp-e2e": {
      "root": "apps/demoapp-e2e",
      "sourceRoot": "apps/demoapp-e2e/src",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@nrwl/cypress:cypress",
          "options": {
            "cypressConfig": "apps/demoapp-e2e/cypress.json",
            "tsConfig": "apps/demoapp-e2e/tsconfig.e2e.json",
            "devServerTarget": "demoapp:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "demoapp:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["apps/demoapp-e2e/tsconfig.e2e.json"],
            "exclude": ["**/node_modules/**", "!apps/demoapp-e2e/**"]
          }
        }
      }
    }
  },
  "cli": {
    "defaultCollection": "@nrwl/angular"
  },
  "schematics": {
    "@nrwl/angular:application": {
      "unitTestRunner": "jest",
      "e2eTestRunner": "cypress"
    },
    "@nrwl/angular:library": {
      "unitTestRunner": "jest"
    }
  },
  "defaultProject": "demoapp"
}

As can be seen, the demoapp uses

"schematics": {
  "@nrwl/angular:component": {
      "style": "scss"
  }
},

If you use ng g c test --project=demoapp, everything works just fine and a scss file will be generated. Instead if you run ng g c test, then the schematic defaults are not being used.

@googlebot googlebot added the cla: yes label May 24, 2020
@filipesilva filipesilva requested a review from clydin May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.