@graphcommerce/next-config 4.31.0-canary.1 → 4.31.0-canary.2

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.
@@ -1,6 +1,7 @@
1
1
  import { Compiler } from 'webpack';
2
2
  export declare class InterceptorPlugin {
3
3
  private interceptors;
4
+ private interceptorByDepependency;
4
5
  private resolveDependency;
5
6
  constructor();
6
7
  private watched;
@@ -15,6 +15,7 @@ class InterceptorPlugin {
15
15
  this.resolveDependency = (0, resolveDependency_1.resolveDependency)();
16
16
  this.watched = this.watchList();
17
17
  this.interceptors = (0, generateInterceptors_1.generateInterceptors)((0, findPlugins_1.findPlugins)(), this.resolveDependency);
18
+ this.interceptorByDepependency = Object.fromEntries(Object.values(this.interceptors).map((i) => [i.dependency, i]));
18
19
  (0, writeInterceptors_1.writeInterceptors)(this.interceptors);
19
20
  }
20
21
  watchList() {
@@ -40,6 +41,7 @@ class InterceptorPlugin {
40
41
  }
41
42
  if (added.length > 0 || removed.length > 0) {
42
43
  this.interceptors = (0, generateInterceptors_1.generateInterceptors)((0, findPlugins_1.findPlugins)(), this.resolveDependency);
44
+ this.interceptorByDepependency = Object.fromEntries(Object.values(this.interceptors).map((i) => [i.dependency, i]));
43
45
  (0, writeInterceptors_1.writeInterceptors)(this.interceptors);
44
46
  }
45
47
  });
@@ -51,8 +53,14 @@ class InterceptorPlugin {
51
53
  logger.log(`Interceptor ${issuer} is requesting the original ${requestPath}`);
52
54
  return;
53
55
  }
54
- if (this.interceptors[requestPath]) {
55
- logger.log(`Intercepting... ${this.interceptors[requestPath].fromRoot}}`);
56
+ const interceptorForRequest = this.interceptorByDepependency[resource.request];
57
+ if (interceptorForRequest) {
58
+ logger.log(`Intercepting... ${interceptorForRequest.dependency}`);
59
+ resource.request = `${interceptorForRequest.denormalized}.interceptor.tsx`;
60
+ }
61
+ const interceptorForPath = this.interceptors[requestPath];
62
+ if (interceptorForPath) {
63
+ logger.log(`Intercepting... ${interceptorForPath.fromRoot}`);
56
64
  resource.request = `${resource.request}.interceptor.tsx`;
57
65
  }
58
66
  });
@@ -1,5 +1,6 @@
1
1
  export declare type ResolveDependencyReturn = {
2
2
  dependency: string;
3
+ denormalized: string;
3
4
  root: string;
4
5
  fromRoot: string;
5
6
  fromModule: string;
@@ -1,18 +1,33 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.resolveDependency = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
4
8
  const resolveDependenciesSync_1 = require("./resolveDependenciesSync");
5
9
  const resolveDependency = (cwd = process.cwd()) => {
6
10
  const dependencies = (0, resolveDependenciesSync_1.resolveDependenciesSync)(cwd);
7
11
  return (dependency) => {
8
- let dependencyPaths = { root: '.', dependency, fromRoot: dependency, fromModule: dependency };
12
+ let dependencyPaths = {
13
+ root: '.',
14
+ dependency,
15
+ fromRoot: dependency,
16
+ fromModule: dependency,
17
+ denormalized: dependency,
18
+ };
9
19
  dependencies.forEach((root, depCandidate) => {
10
20
  if (dependency.startsWith(depCandidate)) {
11
21
  const relative = dependency.replace(depCandidate, '');
12
- const fromRoot = dependency.replace(depCandidate, root);
22
+ const rootCandidate = dependency.replace(depCandidate, root);
23
+ const fromRoot = [`${rootCandidate}`, `${rootCandidate}/index`].find((location) => ['ts', 'tsx'].find((extension) => node_fs_1.default.existsSync(`${location}.${extension}`)));
24
+ if (!fromRoot)
25
+ throw Error("Can't find plugin target");
26
+ const denormalized = fromRoot.replace(root, depCandidate);
13
27
  dependencyPaths = {
14
28
  root,
15
29
  dependency,
30
+ denormalized,
16
31
  fromRoot,
17
32
  fromModule: !relative ? '.' : `./${relative.split('/')[relative.split('/').length - 1]}`,
18
33
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-config",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.31.0-canary.1",
5
+ "version": "4.31.0-canary.2",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
8
8
  "typings": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "prepack": "yarn build"
14
14
  },
15
15
  "dependencies": {
16
- "@graphcommerce/cli": "4.31.0-canary.1",
16
+ "@graphcommerce/cli": "4.31.0-canary.2",
17
17
  "@lingui/loader": "^3.14.0",
18
18
  "@swc/core": "^1.3.10",
19
19
  "js-yaml-loader": "^1.2.2",
@@ -8,6 +8,8 @@ import { writeInterceptors } from './writeInterceptors'
8
8
  export class InterceptorPlugin {
9
9
  private interceptors: GenerateInterceptorsReturn
10
10
 
11
+ private interceptorByDepependency: GenerateInterceptorsReturn
12
+
11
13
  private resolveDependency: ResolveDependency
12
14
 
13
15
  constructor() {
@@ -15,6 +17,10 @@ export class InterceptorPlugin {
15
17
 
16
18
  this.watched = this.watchList()
17
19
  this.interceptors = generateInterceptors(findPlugins(), this.resolveDependency)
20
+ this.interceptorByDepependency = Object.fromEntries(
21
+ Object.values(this.interceptors).map((i) => [i.dependency, i]),
22
+ )
23
+
18
24
  writeInterceptors(this.interceptors)
19
25
  }
20
26
 
@@ -48,6 +54,9 @@ export class InterceptorPlugin {
48
54
  }
49
55
  if (added.length > 0 || removed.length > 0) {
50
56
  this.interceptors = generateInterceptors(findPlugins(), this.resolveDependency)
57
+ this.interceptorByDepependency = Object.fromEntries(
58
+ Object.values(this.interceptors).map((i) => [i.dependency, i]),
59
+ )
51
60
  writeInterceptors(this.interceptors)
52
61
  }
53
62
  })
@@ -66,8 +75,15 @@ export class InterceptorPlugin {
66
75
  return
67
76
  }
68
77
 
69
- if (this.interceptors[requestPath]) {
70
- logger.log(`Intercepting... ${this.interceptors[requestPath].fromRoot}}`)
78
+ const interceptorForRequest = this.interceptorByDepependency[resource.request]
79
+ if (interceptorForRequest) {
80
+ logger.log(`Intercepting... ${interceptorForRequest.dependency}`)
81
+ resource.request = `${interceptorForRequest.denormalized}.interceptor.tsx`
82
+ }
83
+
84
+ const interceptorForPath = this.interceptors[requestPath]
85
+ if (interceptorForPath) {
86
+ logger.log(`Intercepting... ${interceptorForPath.fromRoot}`)
71
87
  resource.request = `${resource.request}.interceptor.tsx`
72
88
  }
73
89
  })
@@ -1,7 +1,9 @@
1
+ import fs from 'node:fs'
1
2
  import { resolveDependenciesSync } from './resolveDependenciesSync'
2
3
 
3
4
  export type ResolveDependencyReturn = {
4
5
  dependency: string
6
+ denormalized: string
5
7
  root: string
6
8
  fromRoot: string
7
9
  fromModule: string
@@ -12,16 +14,29 @@ export type ResolveDependency = (req: string) => ResolveDependencyReturn
12
14
  export const resolveDependency = (cwd: string = process.cwd()) => {
13
15
  const dependencies = resolveDependenciesSync(cwd)
14
16
  return (dependency: string): ResolveDependencyReturn => {
15
- let dependencyPaths = { root: '.', dependency, fromRoot: dependency, fromModule: dependency }
17
+ let dependencyPaths = {
18
+ root: '.',
19
+ dependency,
20
+ fromRoot: dependency,
21
+ fromModule: dependency,
22
+ denormalized: dependency,
23
+ }
16
24
 
17
25
  dependencies.forEach((root, depCandidate) => {
18
26
  if (dependency.startsWith(depCandidate)) {
19
27
  const relative = dependency.replace(depCandidate, '')
20
- const fromRoot = dependency.replace(depCandidate, root)
28
+
29
+ const rootCandidate = dependency.replace(depCandidate, root)
30
+ const fromRoot = [`${rootCandidate}`, `${rootCandidate}/index`].find((location) =>
31
+ ['ts', 'tsx'].find((extension) => fs.existsSync(`${location}.${extension}`)),
32
+ )
33
+ if (!fromRoot) throw Error("Can't find plugin target")
34
+ const denormalized = fromRoot.replace(root, depCandidate)
21
35
 
22
36
  dependencyPaths = {
23
37
  root,
24
38
  dependency,
39
+ denormalized,
25
40
  fromRoot,
26
41
  fromModule: !relative ? '.' : `./${relative.split('/')[relative.split('/').length - 1]}`,
27
42
  }