Giter VIP home page Giter VIP logo

schematics-utilities's People

Contributors

dependabot[bot] avatar nitayneeman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

schematics-utilities's Issues

addDeclarationToModule says "UPDATE" but the update does not occur

I have written the following code by peeking into the angular/schematics/component/index.js code

const declarationChanges = addDeclarationToModule(sourceFile, newLocal, `List${strings.classify(_options.name)}Component`, `./components/general-configuration/${dasherize(_options.name)}/list/list-${dasherize(_options.name)}.component`);
    const declarationRecorder = tree.beginUpdate(newLocal);
    for (const change of declarationChanges) {
        if (change instanceof InsertChange) {
            _context.logger.info(change.toAdd);
            declarationRecorder.insertLeft(change.pos, change.toAdd);
        }
    }
    tree.commitUpdate(declarationRecorder);

I get the following output
UPDATE src/app/app.module.ts (1959 bytes)
but the file still has no changes in it. Any idea what's going wrong here ?

Depending on @angular/cdk causes issues

I just wanted to give you a heads up that depending upon the Angular CDK

"@angular/cdk": "^8.2.2",

in order to pull in the schematics, is not ideal and causes problems like angular/components#18020.

I think that it would be safer to copy the schematic code from the CDK over into this repo just like you do with Angular Material.

We're going to try to put some checks in place in Angular Material's schematics, so that this conflict doesn't break someone's project. But the reality is that projects shouldn't be pulling in @angular/cdk in order to use the private schematic helpers. They need to copy them into their own project (and take over maintenance of them in their project) instead.

Update @angular-devkit/schematics dependency

The version for @angular-devkit/schematics is currently fixed, which pulls in a version of @angular-devkit/core that is broken and doesn't compile due to a typing error. It would be good to update the dependency and republish.

addModuleImportToRootModule does not work with module initialization

I use the the function addModuleImportToRootModule in the following way:

addModuleImportToRootModule(
   host,
   `MyModule.forRoot(
     {
       option1: '<value of option1>',
       option2: '<value of option2>',
     })`,
   '@mycompany/my-module',
   project
);

As result, I get an invalid import statement in my app.module.ts. The module will be added correctly to the NgModule, but create an invalid import statement:

import { MyModule.forRoot(
   {
       option1: '<value of option1>',
       option2: '<value of option2>',
   }) } from '@mycompany/my-module';

Is there a way to to solve this problem?

Thanks!

addProviderToModule bugs with { provide: '', useValue: '' }

When the providers key of NgModule ends with a provider object (like {provide: '', useValue: ''}) the method addProviderToModule has an unexpected result :

@NgModule({
  providers: [
    { provide: '', useValue: '', providers: [{ provide: TOKEN, useValue: 'someValue' }] }
  ]
})

I've run some tests :

  • works : providers: [SomeProvider]
  • works : providers: [{ provide: '', useValue: '' } as Provider]
  • works : providers: [{ provide: '', useValue: '' }, SomeProvider]
  • fails: providers: [{ provide: '', useValue: '' }]
  • fails: providers: [SomeProvider, { provide: '', useValue: '' }]

Angular 10: Cannot find module '@schematics/angular/utility/project'

I'm using this library as part of @oktadev/schematics. Today, I tried upgrading to Angular 10 and now I get the following stack trace when I try to install my schematic. It seems like the error is caused by this project, but I'm not sure.

Cannot find module '@schematics/angular/utility/project'
Require stack:
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/utils/build-component.js
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/utils/index.js
- /Users/mraible/ng10/node_modules/@angular/cdk/schematics/index.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/material/ast/ng-module-imports.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/material/index.js
- /Users/mraible/ng10/node_modules/schematics-utilities/dist/index.js
- /Users/mraible/ng10/node_modules/@oktadev/schematics/src/add-auth/index.js
- /Users/mraible/ng10/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /Users/mraible/ng10/node_modules/@angular-devkit/schematics/tools/index.js
- /Users/mraible/ng10/node_modules/@angular/cli/utilities/json-schema.js
- /Users/mraible/ng10/node_modules/@angular/cli/models/command-runner.js
- /Users/mraible/ng10/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng

Can we mention registry while installing NodeDependencies?

for eg
if this is my code

import { NodeDependency, NodeDependencyType } from 'schematics-utilities';

const dependencies: NodeDependency[] = [
{ type: NodeDependencyType.Dev, version: '^23.6.0', name: 'jest' },
{ type: NodeDependencyType.Dev, version: '^3.0.0', name: '@angular/material' }
];

can I add the registry for that dependency like this?

{ type: NodeDependencyType.Dev, version: '^3.0.0', name: '@angular/material' , registry: 'www.google.com/material'}

Or is there any other way to do this?

Update @schematics/update to remove the vulnerability introduced in schematics-utilities

Hi, @nitayneeman, I'd like to report a vulnerability introduced by package [email protected]:

Issue Description

I noticed that a vulnerability is introduced in [email protected] _:
Vulnerability CVE-2020-7788 (high severity) affects package ini (versions:<1.3.6): https://snyk.io/vuln/SNYK-JS-INI-1048974
The above vulnerable package is referenced by [email protected] via:
[email protected] โž” @schematics/[email protected] โž” [email protected]

Since [email protected] (20,943 downloads per week) is referenced by 37 downstream projects (e.g., @datorama/akita 6.2.3 (latest version), @scullyio/init 1.1.4 (latest version), @sentinel-one/mgmt-schematics 2.0.10 (latest version), @flarehr/apollo-benefits 2.2.19 (latest version), @flarehr/cars-calculator 2.2.19 (latest version)), the vulnerability CVE-2020-7788 can be propagated into these downstream projects and expose security threats to them via the following package dependency paths:
(1)@datorama/[email protected] โž” [email protected] โž” @schematics/[email protected] โž” [email protected]
(2)@flarehr/[email protected] โž” @datorama/[email protected] โž” [email protected] โž” @schematics/[email protected] โž” [email protected]
......

If [email protected].* removes the vulnerable package from the above version, then its fixed version can help downstream users decrease their pain.

Given the large number of downstream users, could you help update your package to remove the vulnerability from [email protected] ?

Fixing suggestions

In [email protected], maybe you can kindly try to perform the following upgrade(not crossing major version) :
@schematics/update ^0.803.8 โž” ^0.1100.5;

Note:
@schematics/[email protected](>=0.1100.5) directly depends on [email protected] which has fixed the vulnerability CVE-2020-7788.
Of course, you are welcome to share other ways to resolve the issue.

Thank you for your attention to this issue.

Best regards,
^_^

New version

Hi dude,
Can you update @angular/cdk (@angular/components) package and release new version?
There are some nice changes there

add new function 'getJSON'

When trying to edit file '/tsconfig.json', there found no suitable functions.
Considering add the follow function(from here):

export function getJSON(host: Tree, jsonFile: string, type?: string): any {
  if (!host.exists(jsonFile)) return null;

  const sourceText = host.read(jsonFile)!.toString('utf-8');
  const json = JSON.parse(sourceText);
  if (type && !json[type]) {
    json[type] = {};
  }
  return json;
}

Maybe it's should be classified as 'third-lib'

Cannot find module 'schematics-utilities' when using ng add

I've recently added ng add support to angular-datatables project and my PR for it had been merged recently but I'm getting the following error when trying to install the package to clean Angular project.

Error:
An unhandled exception occurred: Cannot find module 'schematics-utilities'

Stack Trace:

[error] Error: Cannot find module 'schematics-utilities'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/suryateja/myproject/node_modules/angular-datatables/schematics/src/ng-add/index.js:4:32)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at new ExportStringRef (/home/suryateja/myproject/node_modules/@angular-devkit/schematics/tools/export-ref.js:18:25)
    at NodeModulesEngineHost._resolveReferenceString (/home/suryateja/myproject/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:94:21)
    at NodeModulesEngineHost.createSchematicDescription (/home/suryateja/myproject/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:179:34)
    at SchematicEngine.createSchematic (/home/suryateja/myproject/node_modules/@angular-devkit/schematics/src/engine/engine.js:219:38)

Steps to Reproduce:

  1. Create a empty Angular project:
    ng new myproject
  2. Run the ng add command:
cd myproject
ng add angular-datatables

addPackageJsonDependency / NodeDependencyType don't work

If I try to call this function or use the mentioned type, I get this error:

Cannot find module 'chalk'
Error: Cannot find module 'chalk'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)

Even if the function doesn't get called but it's part of the code, I'm getting the same error. It only works if I comment the function call.

I tried
npm cache verify
npm ci
npm i chalk

No change. Is this a bug? It seems the error is generated by @angular/cdk/schematics/ng-update/upgrade-rules/class-inheritance-rule.js:10:17

Is it possible to fix this?

addModuleImportToRootModule doesn't affect the appModule

KO in 2.0.0 and 2.0.1
OK in 1.1.3

Here is my rule factory function

import {
  Rule, Tree/*, SchematicContext*/
} from '@angular-devkit/schematics';
import { addModuleImportToRootModule, getProjectFromWorkspace } from 'schematics-utilities';
import { getWorkspace } from '@schematics/angular/utility/config';

export function ngAdd(options: any): Rule {
  return (host: Tree/*, context: SchematicContext*/) => {
      // get the workspace config of the consuming project
      // i.e. angular.json file
      const workspace = getWorkspace(host);

      // identify the project config which is using our library
      // or default to the default project in consumer workspace
      const project = getProjectFromWorkspace(
        workspace,
        options.project || workspace.defaultProject
      );
      // inject our module into the current main module of the selected project
      addModuleImportToRootModule(
        // tree to modify
        host,
        // Module name to insert
        'AngularCoreModule',
        // project name for import statement
        '@corp/angular-core',
        // project to be modified
        project
      );

      // return updated tree
      return host;
  };
}

Here is what I got in console

Installing packages for tooling via npm.
Installed packages for tooling via npm.
UPDATE src/app/app.module.ts (1333 bytes)

But my app.module.ts is absolutely the same as before.

I could downgrade to 1.1.3 but I need to set configuration for my modules, but then I got this issue:

#7

What am I supposed to do?

P.S. Where I can find a comprehensive list of the API your package expoes? Thank you?

type script exception after upgrade to "typescript": "~3.8.2"

After I upgrade from "typescript": "~3.5.3" to "typescript": "~3.8.2" I start to get
the following error:

src/schematics-utils/schematics.utils.ts:39:33 - error TS2345: Argument of type 'import("/../node_modules/typescript/lib/typescript").SourceFile' is not assignable to parameter of type 'import("/../node_modules/schematics-utilities/node_modules/@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript").SourceFile'.
  Types of property 'kind' are incompatible.
    Type 'import("/../node_modules/typescript/lib/typescript").SyntaxKind.SourceFile' is not assignable to type 'import("/../node_modules/schematics-utilities/node_modules/@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript").SyntaxKind.SourceFile'.

39     const change = insertImport(sourceFile, pathFileToEdit, importSymbolName, importPath, isDefault) as InsertChange;
                                   ~~~~~~~~~~

I have a utils imports in my code

import * as ts from 'typescript';
import { InsertChange, insertImport } from 'schematics-utilities';
}

in case I'm replace the type ts.SourceFile to any the build work but I want to keep the type
I think it happen since the

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.