@graphcommerce/next-config 9.0.4-canary.0 → 9.0.4-canary.10

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +28 -8
  2. package/__tests__/commands/copyFiles.ts +8 -5
  3. package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +0 -905
  4. package/__tests__/config/utils/mergeEnvIntoConfig.ts +21 -3
  5. package/__tests__/config/utils/replaceConfigInString.ts +0 -1
  6. package/__tests__/interceptors/findPlugins.ts +270 -272
  7. package/__tests__/interceptors/generateInterceptors.ts +1 -0
  8. package/__tests__/utils/resolveDependenciesSync.ts +45 -44
  9. package/dist/generated/config.js +110 -116
  10. package/dist/index.js +3359 -26
  11. package/package.json +34 -8
  12. package/src/commands/codegen.ts +3 -3
  13. package/src/commands/copyFiles.ts +14 -7
  14. package/src/config/commands/generateConfig.ts +17 -6
  15. package/src/config/demoConfig.ts +0 -1
  16. package/src/config/loadConfig.ts +3 -9
  17. package/src/config/utils/mergeEnvIntoConfig.ts +9 -9
  18. package/src/generated/config.ts +305 -245
  19. package/src/interceptors/Visitor.ts +1 -1
  20. package/src/interceptors/findOriginalSource.ts +1 -1
  21. package/src/interceptors/generateInterceptor.ts +0 -2
  22. package/src/interceptors/parseStructure.ts +3 -3
  23. package/src/interceptors/writeInterceptors.ts +1 -1
  24. package/src/utils/resolveDependenciesSync.ts +44 -7
  25. package/src/withGraphCommerce.ts +30 -42
  26. package/tsconfig.json +1 -1
  27. package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -78
  28. package/dist/commands/codegen.js +0 -18
  29. package/dist/commands/copyFiles.js +0 -292
  30. package/dist/config/commands/exportConfig.js +0 -16
  31. package/dist/config/commands/generateConfig.js +0 -57
  32. package/dist/config/demoConfig.js +0 -52
  33. package/dist/config/index.js +0 -19
  34. package/dist/config/loadConfig.js +0 -62
  35. package/dist/config/utils/configToImportMeta.js +0 -39
  36. package/dist/config/utils/diff.js +0 -33
  37. package/dist/config/utils/exportConfigToEnv.js +0 -31
  38. package/dist/config/utils/mergeEnvIntoConfig.js +0 -184
  39. package/dist/config/utils/replaceConfigInString.js +0 -12
  40. package/dist/config/utils/rewriteLegacyEnv.js +0 -115
  41. package/dist/interceptors/InterceptorPlugin.js +0 -108
  42. package/dist/interceptors/RenameVisitor.js +0 -19
  43. package/dist/interceptors/Visitor.js +0 -1414
  44. package/dist/interceptors/commands/codegenInterceptors.js +0 -22
  45. package/dist/interceptors/extractExports.js +0 -159
  46. package/dist/interceptors/findOriginalSource.js +0 -103
  47. package/dist/interceptors/findPlugins.js +0 -68
  48. package/dist/interceptors/generateInterceptor.js +0 -219
  49. package/dist/interceptors/generateInterceptors.js +0 -56
  50. package/dist/interceptors/parseStructure.js +0 -84
  51. package/dist/interceptors/swc.js +0 -15
  52. package/dist/interceptors/writeInterceptors.js +0 -44
  53. package/dist/utils/PackagesSort.js +0 -7
  54. package/dist/utils/TopologicalSort.js +0 -87
  55. package/dist/utils/isMonorepo.js +0 -47
  56. package/dist/utils/packageRoots.js +0 -31
  57. package/dist/utils/resolveDependenciesSync.js +0 -78
  58. package/dist/utils/resolveDependency.js +0 -70
  59. package/dist/utils/sig.js +0 -34
  60. package/dist/withGraphCommerce.js +0 -162
  61. package/src/config/utils/rewriteLegacyEnv.ts +0 -125
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InterceptorPlugin = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const resolveDependency_1 = require("../utils/resolveDependency");
9
- const findPlugins_1 = require("./findPlugins");
10
- const generateInterceptors_1 = require("./generateInterceptors");
11
- const writeInterceptors_1 = require("./writeInterceptors");
12
- let interceptors;
13
- let interceptorByDepependency;
14
- let generating = false;
15
- // let totalGenerationTime = 0
16
- class InterceptorPlugin {
17
- config;
18
- regenerate;
19
- resolveDependency;
20
- constructor(config, regenerate = false) {
21
- this.config = config;
22
- this.regenerate = regenerate;
23
- this.resolveDependency = (0, resolveDependency_1.resolveDependency)();
24
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
25
- if (regenerate)
26
- this.#generateInterceptors();
27
- }
28
- #generateInterceptors = async () => {
29
- if (generating)
30
- return {};
31
- generating = true;
32
- // const start = Date.now()
33
- // console.log('Generating interceptors...')
34
- const [plugins] = (0, findPlugins_1.findPlugins)(this.config);
35
- // console.log(errors)
36
- // const found = Date.now()
37
- // console.log('Found plugins in', found - start, 'ms')
38
- const generatedInterceptors = await (0, generateInterceptors_1.generateInterceptors)(plugins, this.resolveDependency, this.config.debug);
39
- // const generated = Date.now()
40
- // console.log('Generated interceptors in', generated - found, 'ms')
41
- await (0, writeInterceptors_1.writeInterceptors)(generatedInterceptors);
42
- // const wrote = Date.now()
43
- // console.log('Wrote interceptors in', wrote - generated, 'ms')
44
- interceptors = generatedInterceptors;
45
- interceptorByDepependency = Object.fromEntries(Object.values(interceptors).map((i) => [i.dependency, i]));
46
- // totalGenerationTime += Date.now() - start
47
- generating = false;
48
- return generatedInterceptors;
49
- };
50
- /** @public */
51
- apply(compiler) {
52
- const logger = compiler.getInfrastructureLogger('InterceptorPlugin');
53
- // After the compilation has succeeded we watch all possible plugin locations.
54
- if (this.regenerate) {
55
- compiler.hooks.afterCompile.tap('InterceptorPlugin', (compilation) => {
56
- // console.log('generate interceptors after compile')
57
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
- const [plugins, errors] = (0, findPlugins_1.findPlugins)(this.config);
59
- plugins.forEach((p) => {
60
- const source = this.resolveDependency(p.sourceModule);
61
- if (source) {
62
- const absoluteFilePath = `${path_1.default.join(process.cwd(), source.fromRoot)}.tsx`;
63
- compilation.fileDependencies.add(absoluteFilePath);
64
- }
65
- });
66
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
67
- this.#generateInterceptors().then((i) => {
68
- Object.entries(i).forEach(([, { sourcePath }]) => {
69
- const absoluteFilePath = path_1.default.join(process.cwd(), sourcePath);
70
- compilation.fileDependencies.add(absoluteFilePath);
71
- });
72
- });
73
- });
74
- }
75
- compiler.hooks.normalModuleFactory.tap('InterceptorPlugin', (nmf) => {
76
- nmf.hooks.beforeResolve.tap('InterceptorPlugin', (resource) => {
77
- const issuer = resource.contextInfo.issuer ?? '';
78
- const requestPath = path_1.default.relative(process.cwd(), path_1.default.resolve(resource.context, resource.request));
79
- if (!interceptors || !interceptorByDepependency) {
80
- // console.log('interceptors not ready')
81
- return;
82
- }
83
- const split = requestPath.split('/');
84
- const targets = [
85
- `${split[split.length - 1]}.interceptor.tsx`,
86
- `${split[split.length - 1]}.interceptor.ts`,
87
- ];
88
- if (targets.some((target) => issuer.endsWith(target)) && interceptors[requestPath]) {
89
- logger.log(`Interceptor ${issuer} is requesting the original ${requestPath}`);
90
- return;
91
- }
92
- const interceptorForRequest = interceptorByDepependency[resource.request];
93
- if (interceptorForRequest) {
94
- const extension = interceptorForRequest.sourcePath.endsWith('.tsx') ? '.tsx' : '.ts';
95
- resource.request = `${interceptorForRequest.denormalized}.interceptor${extension}`;
96
- logger.log(`Intercepting dep... ${interceptorForRequest.dependency}`, resource.request);
97
- }
98
- const interceptorForPath = interceptors[requestPath];
99
- if (interceptorForPath) {
100
- const extension = interceptorForPath.sourcePath.endsWith('.tsx') ? '.tsx' : '.ts';
101
- resource.request = `${resource.request}.interceptor${extension}`;
102
- logger.log(`Intercepting fromRoot... ${interceptorForPath.dependency}`, resource.request);
103
- }
104
- });
105
- });
106
- }
107
- }
108
- exports.InterceptorPlugin = InterceptorPlugin;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenameVisitor = void 0;
4
- const Visitor_1 = require("./Visitor");
5
- class RenameVisitor extends Visitor_1.Visitor {
6
- replace;
7
- suffix;
8
- constructor(replace, suffix) {
9
- super();
10
- this.replace = replace;
11
- this.suffix = suffix;
12
- }
13
- visitIdentifier(n) {
14
- if (this.replace.includes(n.value))
15
- n.value = this.suffix(n.value);
16
- return n;
17
- }
18
- }
19
- exports.RenameVisitor = RenameVisitor;