@graphcommerce/next-config 10.1.0-canary.22 → 10.1.0-canary.24

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,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.1.0-canary.24
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2636](https://github.com/graphcommerce-org/graphcommerce/pull/2636) [`78f9803`](https://github.com/graphcommerce-org/graphcommerce/commit/78f980311d4f8db0d99fe301c62553b4e0bce098) - Fix Turbopack panic ("Cannot find module …graphcommerce.config.cjs") when loading `graphcommerce.config.ts`. cosmiconfig's sync TypeScript loader transpiles the config to a fixed temp `.cjs` path on disk and deletes it again, which races between Next.js worker processes. The `.ts` loader now transpiles via SWC and writes to a per-process unique filename next to the source so concurrent loads never collide. ([@bramvanderholst](https://github.com/bramvanderholst))
8
+
9
+ ## 10.1.0-canary.23
10
+
3
11
  ## 10.1.0-canary.22
4
12
 
5
13
  ## 10.1.0-canary.21
@@ -1,6 +1,10 @@
1
+ import '@swc/core';
1
2
  import 'cosmiconfig';
3
+ import 'node:fs';
4
+ import 'node:module';
5
+ import 'node:path';
2
6
  import '../generated/config.js';
3
- export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-DFvwanrZ.js';
7
+ export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-B6AF2Z1i.js';
4
8
  import 'zod';
5
9
  import '@apollo/client/utilities/internal';
6
10
  import 'chalk';
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ import path from 'path';
4
4
  import { glob, sync } from 'glob';
5
5
  import { findParentPath } from './utils/findParentPath.js';
6
6
  import { spawn } from 'child_process';
7
- import { l as loadConfig, t as toEnvStr } from './loadConfig-DFvwanrZ.js';
8
- export { r as replaceConfigInString } from './loadConfig-DFvwanrZ.js';
7
+ import { l as loadConfig, t as toEnvStr } from './loadConfig-B6AF2Z1i.js';
8
+ export { r as replaceConfigInString } from './loadConfig-B6AF2Z1i.js';
9
9
  import { parseFileSync, parseSync as parseSync$1, transformFileSync } from '@swc/core';
10
10
  import fs$1, { writeFileSync, readFileSync, existsSync, rmSync, mkdirSync } from 'fs';
11
11
  import { resolve as resolve$2 } from 'import-meta-resolve';
@@ -20,6 +20,9 @@ import { generate } from '@graphql-codegen/cli';
20
20
  import { GraphCommerceConfigSchema } from './generated/config.js';
21
21
  export { GraphCommerceDebugConfigSchema, GraphCommerceStorefrontConfigSchema } from './generated/config.js';
22
22
  import 'cosmiconfig';
23
+ import 'node:fs';
24
+ import 'node:module';
25
+ import 'node:path';
23
26
  import '@apollo/client/utilities/internal';
24
27
  import 'chalk';
25
28
 
@@ -1,4 +1,8 @@
1
+ import { transformFileSync } from '@swc/core';
1
2
  import { cosmiconfigSync } from 'cosmiconfig';
3
+ import { writeFileSync, existsSync, rmSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { join, dirname } from 'node:path';
2
6
  import { GraphCommerceConfigSchema } from './generated/config.js';
3
7
  import { cloneDeep, mergeDeep } from '@apollo/client/utilities/internal';
4
8
  import chalk from 'chalk';
@@ -276,7 +280,29 @@ function replaceConfigInString(str, config) {
276
280
  }
277
281
 
278
282
  const moduleName = "graphcommerce";
279
- const loader = cosmiconfigSync(moduleName);
283
+ const requireFromHere = createRequire(import.meta.url);
284
+ let tmpCounter = 0;
285
+ function loadTsConfig(filepath) {
286
+ const { code } = transformFileSync(filepath, {
287
+ jsc: { parser: { syntax: "typescript" }, target: "es2022" },
288
+ module: { type: "commonjs" }
289
+ });
290
+ const tmpFile = join(
291
+ dirname(filepath),
292
+ `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`
293
+ );
294
+ try {
295
+ writeFileSync(tmpFile, code);
296
+ delete requireFromHere.cache[tmpFile];
297
+ const mod = requireFromHere(tmpFile);
298
+ return mod.default ?? mod;
299
+ } finally {
300
+ if (existsSync(tmpFile)) rmSync(tmpFile, { force: true });
301
+ }
302
+ }
303
+ const loader = cosmiconfigSync(moduleName, {
304
+ loaders: { ".ts": loadTsConfig }
305
+ });
280
306
  function loadConfig(cwd) {
281
307
  const isMainProcess = !process.send;
282
308
  try {
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": "10.1.0-canary.22",
5
+ "version": "10.1.0-canary.24",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@apollo/client": "*",
66
- "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.22",
66
+ "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.24",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -1,5 +1,9 @@
1
1
  /* eslint-disable no-console */
2
+ import { transformFileSync } from '@swc/core'
2
3
  import { cosmiconfigSync } from 'cosmiconfig'
4
+ import { existsSync, rmSync, writeFileSync } from 'node:fs'
5
+ import { createRequire } from 'node:module'
6
+ import { dirname, join } from 'node:path'
3
7
  import type { GraphCommerceConfig } from '../generated/config'
4
8
  import { GraphCommerceConfigSchema } from '../generated/config'
5
9
  import { demoConfig } from './demoConfig'
@@ -8,7 +12,42 @@ import { formatAppliedEnv, mergeEnvIntoConfig } from './utils/mergeEnvIntoConfig
8
12
  export * from './utils/replaceConfigInString'
9
13
 
10
14
  const moduleName = 'graphcommerce'
11
- const loader = cosmiconfigSync(moduleName)
15
+ const requireFromHere = createRequire(import.meta.url)
16
+ let tmpCounter = 0
17
+
18
+ // cosmiconfig's built-in sync TypeScript loader transpiles the config to a
19
+ // fixed `.cjs` path on disk and removes it again — that races between
20
+ // Next.js worker processes (especially under Turbopack), producing
21
+ // "Cannot find module" panics. We transpile via SWC and write to a
22
+ // per-process unique filename so concurrent loads never collide. The temp
23
+ // file lives next to the source so relative `require()` calls in the
24
+ // config still resolve.
25
+ function loadTsConfig(filepath: string): Record<string, unknown> {
26
+ const { code } = transformFileSync(filepath, {
27
+ jsc: { parser: { syntax: 'typescript' }, target: 'es2022' },
28
+ module: { type: 'commonjs' },
29
+ })
30
+
31
+ const tmpFile = join(
32
+ dirname(filepath),
33
+ `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`,
34
+ )
35
+
36
+ try {
37
+ writeFileSync(tmpFile, code)
38
+ delete requireFromHere.cache[tmpFile]
39
+ const mod = requireFromHere(tmpFile) as
40
+ | { default?: Record<string, unknown> }
41
+ | Record<string, unknown>
42
+ return (mod as { default?: Record<string, unknown> }).default ?? mod
43
+ } finally {
44
+ if (existsSync(tmpFile)) rmSync(tmpFile, { force: true })
45
+ }
46
+ }
47
+
48
+ const loader = cosmiconfigSync(moduleName, {
49
+ loaders: { '.ts': loadTsConfig },
50
+ })
12
51
 
13
52
  export function loadConfig(cwd: string): GraphCommerceConfig {
14
53
  const isMainProcess = !process.send