From 4f9edaecdd4c1a89673e7da55c1e592814bec2e5 Mon Sep 17 00:00:00 2001 From: Badisi Date: Tue, 16 Jan 2024 18:42:39 +0100 Subject: [PATCH] refactor(lib)!: remove standalone path module import --- package-lock.json | 22 +++++++++---------- projects/lib/package.json | 8 +++---- projects/lib/schematics/ng-add/index.ts | 17 +++++--------- projects/lib/schematics/ng-add/ng-add.spec.ts | 4 ++-- projects/lib/src/index.ts | 3 ++- .../ngx-sentry.provider.ts | 3 ++- projects/lib/standalone/index.ts | 4 ---- projects/lib/standalone/ng-package.json | 5 ----- 8 files changed, 27 insertions(+), 39 deletions(-) rename projects/lib/{standalone => src}/ngx-sentry.provider.ts (83%) delete mode 100644 projects/lib/standalone/index.ts delete mode 100644 projects/lib/standalone/ng-package.json diff --git a/package-lock.json b/package-lock.json index 84029e6..80f1017 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3367,9 +3367,9 @@ } }, "node_modules/@hug/ngx-schematics-utilities": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@hug/ngx-schematics-utilities/-/ngx-schematics-utilities-7.1.0.tgz", - "integrity": "sha512-wFB0lAkEaJmrjrlNfStEgp09jyXxZUqBiAYQlhXiVEl9DijGch5rsisEJqPVF734ida08HvQgbV1PsLbnqHPEA==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@hug/ngx-schematics-utilities/-/ngx-schematics-utilities-8.0.0.tgz", + "integrity": "sha512-Yso2YvPqUCsuG5cBH7bZU0w6itI+rjFUG/1urvrQxRyTDLEYSXYNfPQawbFRmXI1EnJXk1rPgaewNn8YUZXODg==", "dependencies": { "@badisi/latest-version": "^7.0.1", "@colors/colors": "^1.6.0", @@ -3380,10 +3380,10 @@ "node": ">= 18.12.0" }, "peerDependencies": { - "@angular-devkit/core": ">= 14", - "@angular-devkit/schematics": ">= 14", - "@angular/cli": ">= 14", - "@schematics/angular": ">= 14" + "@angular-devkit/core": ">= 17", + "@angular-devkit/schematics": ">= 17", + "@angular/cli": ">= 17", + "@schematics/angular": ">= 17" } }, "node_modules/@hug/ngx-sentry": { @@ -20211,7 +20211,7 @@ "version": "5.0.0", "license": "GPL-3.0-only", "dependencies": { - "@hug/ngx-schematics-utilities": "^7.1.0", + "@hug/ngx-schematics-utilities": "^8.0.0", "@sentry/angular-ivy": "^7.93.0", "@sentry/cli": "2.25.0", "tslib": "^2.6.2" @@ -20223,9 +20223,9 @@ "node": ">= 18.12.0" }, "peerDependencies": { - "@angular/common": ">= 14", - "@angular/core": ">= 14", - "@angular/router": ">= 14" + "@angular/common": ">= 15", + "@angular/core": ">= 15", + "@angular/router": ">= 15" } } } diff --git a/projects/lib/package.json b/projects/lib/package.json index d1b3c9d..3358034 100644 --- a/projects/lib/package.json +++ b/projects/lib/package.json @@ -42,12 +42,12 @@ "build:global": "node ./make.mjs build-global" }, "peerDependencies": { - "@angular/common": ">= 14", - "@angular/core": ">= 14", - "@angular/router": ">= 14" + "@angular/common": ">= 15", + "@angular/core": ">= 15", + "@angular/router": ">= 15" }, "dependencies": { - "@hug/ngx-schematics-utilities": "^7.1.0", + "@hug/ngx-schematics-utilities": "^8.0.0", "@sentry/angular-ivy": "^7.93.0", "@sentry/cli": "2.25.0", "tslib": "^2.6.2" diff --git a/projects/lib/schematics/ng-add/index.ts b/projects/lib/schematics/ng-add/index.ts index a952e66..a9a0f3a 100644 --- a/projects/lib/schematics/ng-add/index.ts +++ b/projects/lib/schematics/ng-add/index.ts @@ -2,13 +2,13 @@ import { tags } from '@angular-devkit/core'; import { chain, Rule } from '@angular-devkit/schematics'; import { addImportToFile, addImportToNgModule, addProviderToBootstrapApplication, application, - ChainableProjectContext, createOrUpdateFile, logAction, schematic, workspace + ChainableProjectContext, createOrUpdateFile, getProjectMainPath, isProjectStandalone, logAction, schematic, workspace } from '@hug/ngx-schematics-utilities'; import { NgAddOptions } from './ng-add-options'; export const initSentry = (context: ChainableProjectContext, options: NgAddOptions): Rule => { - const mainTsPath = context.project.pathFromSourceRoot('main.ts'); + const mainTsPath = getProjectMainPath(context.tree, context.project.name); const mainTsContent = context.tree.read(mainTsPath)?.toString('utf-8') ?? ''; const rules: Rule[] = []; @@ -43,17 +43,12 @@ export const initSentry = (context: ChainableProjectContext, options: NgAddOptio ); // Provide library - if (mainTsContent.includes('bootstrapApplication(')) { - rules.push( - addImportToFile(mainTsPath, 'initSentry', '@hug/ngx-sentry/standalone'), - addProviderToBootstrapApplication(mainTsPath, 'provideSentry()', '@hug/ngx-sentry/standalone') - ); + rules.push(addImportToFile(mainTsPath, 'initSentry', '@hug/ngx-sentry')); + if (isProjectStandalone(context.tree, context.project.name)) { + rules.push(addProviderToBootstrapApplication(mainTsPath, 'provideSentry()', '@hug/ngx-sentry')); } else { const appModulePath = context.project.pathFromSourceRoot('app/app.module.ts'); - rules.push( - addImportToFile(mainTsPath, 'initSentry', '@hug/ngx-sentry'), - addImportToNgModule(appModulePath, 'NgxSentryModule.forRoot()', '@hug/ngx-sentry') - ); + rules.push(addImportToNgModule(appModulePath, 'NgxSentryModule.forRoot()', '@hug/ngx-sentry')); } return chain(rules); diff --git a/projects/lib/schematics/ng-add/ng-add.spec.ts b/projects/lib/schematics/ng-add/ng-add.spec.ts index 1a9c683..fc1942d 100644 --- a/projects/lib/schematics/ng-add/ng-add.spec.ts +++ b/projects/lib/schematics/ng-add/ng-add.spec.ts @@ -57,7 +57,7 @@ const joc = jasmine.objectContaining; await runner.runSchematic('ng-add', defaultOptions, tree); const mainTsContent = tree.readContent(project.pathFromSourceRoot('main.ts')); if (useStandalone) { - expect(mainTsContent).toContain('import { initSentry } from \'@hug/ngx-sentry/standalone\';'); + expect(mainTsContent).toContain('import { initSentry } from \'@hug/ngx-sentry\';'); } else { expect(mainTsContent).toContain('import { initSentry } from \'@hug/ngx-sentry\';'); } @@ -77,7 +77,7 @@ const joc = jasmine.objectContaining; await runner.runSchematic('ng-add', defaultOptions, tree); const configTsContent = tree.readContent(configTsPath); - expect(configTsContent).toContain('import { provideSentry } from \'@hug/ngx-sentry/standalone\';'); + expect(configTsContent).toContain('import { provideSentry } from \'@hug/ngx-sentry\';'); expect(configTsContent).toContain('provideSentry()'); }); } diff --git a/projects/lib/src/index.ts b/projects/lib/src/index.ts index b2cf535..243c1ac 100644 --- a/projects/lib/src/index.ts +++ b/projects/lib/src/index.ts @@ -1,4 +1,5 @@ export type { BrowserOptions, User } from '@sentry/angular-ivy'; export type { SentryOptions } from './ngx-sentry'; -export { NGX_SENTRY_PROVIDERS, setSentryUser, initSentry } from './ngx-sentry'; +export { setSentryUser, initSentry } from './ngx-sentry'; export { NgxSentryModule } from './ngx-sentry.module'; +export { provideSentry } from './ngx-sentry.provider'; diff --git a/projects/lib/standalone/ngx-sentry.provider.ts b/projects/lib/src/ngx-sentry.provider.ts similarity index 83% rename from projects/lib/standalone/ngx-sentry.provider.ts rename to projects/lib/src/ngx-sentry.provider.ts index b9bf0de..6e71ef2 100644 --- a/projects/lib/standalone/ngx-sentry.provider.ts +++ b/projects/lib/src/ngx-sentry.provider.ts @@ -1,6 +1,7 @@ import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core'; -import { NGX_SENTRY_PROVIDERS } from '@hug/ngx-sentry'; import { ErrorHandlerOptions } from '@sentry/angular-ivy'; +import { NGX_SENTRY_PROVIDERS } from './ngx-sentry'; + export const provideSentry = (options?: ErrorHandlerOptions): EnvironmentProviders => makeEnvironmentProviders(NGX_SENTRY_PROVIDERS(options)); diff --git a/projects/lib/standalone/index.ts b/projects/lib/standalone/index.ts deleted file mode 100644 index 8844dc4..0000000 --- a/projects/lib/standalone/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type { BrowserOptions, User } from '@sentry/angular-ivy'; -export type { SentryOptions } from '@hug/ngx-sentry'; -export { setSentryUser, initSentry } from '@hug/ngx-sentry'; -export { provideSentry } from './ngx-sentry.provider'; diff --git a/projects/lib/standalone/ng-package.json b/projects/lib/standalone/ng-package.json deleted file mode 100644 index 7a0f6fc..0000000 --- a/projects/lib/standalone/ng-package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "lib": { - "entryFile": "./index.ts" - } -}