@akinon/next 1.21.0-rc.4 → 1.21.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.21.0-rc.6
4
+
5
+ ### Minor Changes
6
+
7
+ - b4452e9d: ZERO-2463: Refactor Sentry initialization and add Sentry DSN option to settings
8
+
9
+ ## 1.21.0-rc.5
10
+
11
+ ### Patch Changes
12
+
13
+ - ZERO-2296: Fix ROUTES import
14
+
3
15
  ## 1.21.0-rc.4
4
16
 
5
17
  ### Minor Changes
@@ -1,39 +1,71 @@
1
- #!/usr/bin/env node
2
-
3
1
  const fs = require('fs');
4
2
  const path = require('path');
5
- const rootDir = path.resolve(process.cwd());
6
- const spawn = require('cross-spawn');
7
- const availablePlugins = require('../plugins');
3
+ const { execSync } = require('child_process');
4
+
5
+ function findBaseDir() {
6
+ const insideNodeModules = __dirname.includes('node_modules');
7
+ return insideNodeModules
8
+ ? process.cwd()
9
+ : path.resolve(__dirname, '../../../apps/projectzeronext');
10
+ }
8
11
 
9
- let plugins;
12
+ const BASE_DIR = findBaseDir();
13
+ const getFullPath = (relativePath) => path.join(BASE_DIR, relativePath);
14
+
15
+ const packageJsonPath = getFullPath('package.json');
16
+ let packageJson;
10
17
 
11
18
  try {
12
- plugins = require(path.resolve(rootDir, './src/plugins.js'));
19
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
13
20
  } catch (error) {
14
- console.error('No plugins.js file found, skipping plugin installation.');
15
- process.exit(0);
21
+ console.error('Error reading package.json:', error);
22
+ process.exit(1);
16
23
  }
17
24
 
18
- let installCmd = [];
25
+ const pluginsJsPath = getFullPath('src/plugins.js');
26
+ let installedPlugins;
27
+
28
+ try {
29
+ installedPlugins = require(pluginsJsPath);
30
+ } catch (error) {
31
+ console.error('Error loading installed plugins:', error);
32
+ process.exit(1);
33
+ }
19
34
 
20
- availablePlugins
21
- .filter((p) => plugins?.includes(p))
22
- .forEach((name) => {
23
- installCmd.push(`@akinon/${name}`);
24
- });
35
+ const protectedPackages = ['@akinon/next', 'next'];
25
36
 
26
- spawn.sync('yarn', ['cache clean']);
37
+ const pluginsToRemove = Object.keys(packageJson.dependencies || {}).filter(
38
+ (dep) =>
39
+ dep.startsWith('@akinon/') &&
40
+ installedPlugins.includes(dep.replace('@akinon/', '')) &&
41
+ !protectedPackages.includes(dep)
42
+ );
27
43
 
28
- for (const plugin of availablePlugins) {
29
- spawn.sync('yarn', ['remove', `@akinon/${plugin}`]);
30
- }
44
+ pluginsToRemove.forEach((plugin) => {
45
+ try {
46
+ execSync(`yarn remove ${plugin}`, { stdio: 'inherit', cwd: BASE_DIR });
47
+ } catch (error) {
48
+ console.warn(
49
+ `Warning: Could not remove ${plugin}. It may not have been installed.`
50
+ );
51
+ }
52
+ });
31
53
 
32
- if (
33
- installCmd.length > 0 &&
34
- !fs.existsSync(path.resolve(rootDir, '../../turbo.json'))
35
- ) {
36
- spawn.sync('yarn', ['add', ...installCmd, '--ignore-scripts'], {
37
- stdio: 'inherit'
38
- });
39
- }
54
+ installedPlugins.forEach((plugin) => {
55
+ const packageName = `@akinon/${plugin}`;
56
+ if (
57
+ !Object.keys(packageJson.dependencies || {}).includes(packageName) &&
58
+ !protectedPackages.includes(packageName)
59
+ ) {
60
+ try {
61
+ const version = packageJson.dependencies['@akinon/next'].replace('^', '');
62
+ const command = `yarn add ${packageName}@${version} --exact --ignore-scripts`;
63
+ execSync(command, { stdio: 'inherit', cwd: BASE_DIR });
64
+ } catch (error) {
65
+ console.warn(
66
+ '\n\x1b[33m%s\x1b[0m',
67
+ `Error adding ${packageName}: ${error}`
68
+ );
69
+ }
70
+ }
71
+ });
@@ -1,5 +1,6 @@
1
1
  import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
2
2
  import Settings from 'settings';
3
+ import { ROUTES } from 'routes';
3
4
  import {
4
5
  PzNextRequest,
5
6
  withCheckoutProvider,
@@ -17,7 +18,6 @@ import withLocale from './locale';
17
18
  import logger from '../utils/log';
18
19
  import { user } from '../data/urls';
19
20
  import { getUrlPathWithLocale } from '../utils/localization';
20
- import { ROUTES } from 'projectzeronext/src/routes';
21
21
 
22
22
  const withPzDefault =
23
23
  (middleware: NextMiddleware) =>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.21.0-rc.4",
4
+ "version": "1.21.0-rc.6",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -32,7 +32,7 @@
32
32
  "@typescript-eslint/eslint-plugin": "6.7.4",
33
33
  "@typescript-eslint/parser": "6.7.4",
34
34
  "eslint": "^8.14.0",
35
- "@akinon/eslint-plugin-projectzero": "1.21.0-rc.4",
35
+ "@akinon/eslint-plugin-projectzero": "1.21.0-rc.6",
36
36
  "eslint-config-prettier": "8.5.0"
37
37
  }
38
38
  }
package/sentry/index.ts CHANGED
@@ -1,27 +1,33 @@
1
1
  import * as Sentry from '@sentry/nextjs';
2
+ import settings from 'settings';
2
3
 
3
4
  const SENTRY_DSN: string =
4
- process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
5
+ settings.sentryDsn ||
6
+ process.env.SENTRY_DSN ||
7
+ process.env.NEXT_PUBLIC_SENTRY_DSN;
5
8
 
6
9
  export const initSentry = (
7
10
  type: 'Server' | 'Client' | 'Edge',
8
- options: Sentry.BrowserOptions | Sentry.NodeOptions | Sentry.EdgeOptions = {}
11
+ options: Sentry.BrowserOptions | Sentry.NodeOptions | Sentry.EdgeOptions = {
12
+ dsn: SENTRY_DSN,
13
+ integrations: [],
14
+ tracesSampleRate: 1.0
15
+ }
9
16
  ) => {
10
- // TODO: Handle options with ESLint rules
11
-
12
- // TODO: Remove Zero Project DSN
13
-
14
- Sentry.init({
15
- dsn:
16
- SENTRY_DSN ||
17
- 'https://d8558ef8997543deacf376c7d8d7cf4b@o64293.ingest.sentry.io/4504338423742464',
17
+ const initOptions = {
18
+ ...options,
18
19
  initialScope: {
19
20
  tags: {
21
+ ...((
22
+ options.initialScope as {
23
+ tags?: Record<string, string>;
24
+ }
25
+ )?.tags ?? {}),
20
26
  APP_TYPE: 'ProjectZeroNext',
21
27
  TYPE: type
22
28
  }
23
- },
24
- tracesSampleRate: 1.0,
25
- integrations: []
26
- });
29
+ }
30
+ };
31
+
32
+ Sentry.init(initOptions);
27
33
  };
package/types/index.ts CHANGED
@@ -71,6 +71,12 @@ export interface Currency {
71
71
 
72
72
  export interface Settings {
73
73
  commerceUrl: string;
74
+ /**
75
+ * This option allows you to track Sentry events on the client side, in addition to server and edge environments.
76
+ *
77
+ * It overrides process.env.NEXT_PUBLIC_SENTRY_DSN and process.env.SENTRY_DSN.
78
+ */
79
+ sentryDsn?: string;
74
80
  redis: {
75
81
  defaultExpirationTime: number;
76
82
  };