Skip to content

Commit

Permalink
refactor(lib)!: remove standalone path module import
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Jan 16, 2024
1 parent cdeb2ae commit 4f9edae
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 39 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions projects/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 6 additions & 11 deletions projects/lib/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions projects/lib/schematics/ng-add/ng-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\';');
}
Expand All @@ -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()');
});
}
Expand Down
3 changes: 2 additions & 1 deletion projects/lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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));
4 changes: 0 additions & 4 deletions projects/lib/standalone/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions projects/lib/standalone/ng-package.json

This file was deleted.

0 comments on commit 4f9edae

Please sign in to comment.