@graphcommerce/next-config 11.0.0-canary.47 → 11.0.0-canary.49

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
+ ## 11.0.0-canary.49
4
+
5
+ ## 11.0.0-canary.48
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2686](https://github.com/graphcommerce-org/graphcommerce/pull/2686) [`d40589e`](https://github.com/graphcommerce-org/graphcommerce/commit/d40589ee79bd51040845ce8894493de8ff3b1625) - `loadConfig` gives each worker thread its own temporary config file. Worker threads of one process have the same pid, so two threads that loaded the config at the same time wrote and removed the same file, and `yarn lingui` stopped responding. ([@bramvanderholst](https://github.com/bramvanderholst))
10
+
3
11
  ## 11.0.0-canary.47
4
12
 
5
13
  ## 11.0.0-canary.46
@@ -0,0 +1,57 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { Worker } from 'node:worker_threads'
5
+ import { demoConfig } from '../../src/config/demoConfig'
6
+
7
+ const loadConfigUrl = new URL('../../dist/config/loadConfig.js', import.meta.url).href
8
+
9
+ // Loads the config in a worker thread and posts the path of the temporary config file.
10
+ const workerCode = `
11
+ const fs = require('node:fs')
12
+ const { syncBuiltinESMExports } = require('node:module')
13
+ const { parentPort, workerData } = require('node:worker_threads')
14
+ const writeFileSync = fs.writeFileSync
15
+ fs.writeFileSync = (file, ...args) => {
16
+ if (String(file).includes('.graphcommerce.tmp.')) parentPort.postMessage(String(file))
17
+ return writeFileSync(file, ...args)
18
+ }
19
+ syncBuiltinESMExports()
20
+ import(workerData.loadConfigUrl).then(({ loadConfig }) => loadConfig(workerData.cwd))
21
+ `
22
+
23
+ function temporaryConfigFile(cwd: string) {
24
+ return new Promise<string>((resolve, reject) => {
25
+ const worker = new Worker(workerCode, {
26
+ eval: true,
27
+ workerData: { loadConfigUrl, cwd },
28
+ stdout: true,
29
+ stderr: true,
30
+ })
31
+ worker.once('message', (file: string) => {
32
+ resolve(file)
33
+ void worker.terminate()
34
+ })
35
+ worker.once('error', reject)
36
+ })
37
+ }
38
+
39
+ describe('loadConfig', () => {
40
+ it('gives each worker thread its own temporary config file', async () => {
41
+ const cwd = mkdtempSync(join(tmpdir(), 'gc-load-config-'))
42
+ writeFileSync(
43
+ join(cwd, 'graphcommerce.config.ts'),
44
+ `export default ${JSON.stringify(demoConfig)}\n`,
45
+ )
46
+
47
+ try {
48
+ const [first, second] = await Promise.all([
49
+ temporaryConfigFile(cwd),
50
+ temporaryConfigFile(cwd),
51
+ ])
52
+ expect(first).not.toBe(second)
53
+ } finally {
54
+ rmSync(cwd, { recursive: true, force: true })
55
+ }
56
+ })
57
+ })
@@ -3,8 +3,9 @@ import 'cosmiconfig';
3
3
  import 'node:fs';
4
4
  import 'node:module';
5
5
  import 'node:path';
6
+ import 'node:worker_threads';
6
7
  import '../generated/config.js';
7
- export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-B6AF2Z1i.js';
8
+ export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-S8JJz4LU.js';
8
9
  import 'zod';
9
10
  import '@apollo/client/utilities/internal';
10
11
  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-B6AF2Z1i.js';
8
- export { r as replaceConfigInString } from './loadConfig-B6AF2Z1i.js';
7
+ import { l as loadConfig, t as toEnvStr } from './loadConfig-S8JJz4LU.js';
8
+ export { r as replaceConfigInString } from './loadConfig-S8JJz4LU.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';
@@ -23,6 +23,7 @@ import 'cosmiconfig';
23
23
  import 'node:fs';
24
24
  import 'node:module';
25
25
  import 'node:path';
26
+ import 'node:worker_threads';
26
27
  import '@apollo/client/utilities/internal';
27
28
  import 'chalk';
28
29
 
@@ -367,7 +368,7 @@ function isRegExpLiteral(node) {
367
368
  function isTemplateLiteral(node) {
368
369
  return node.type === "TemplateLiteral";
369
370
  }
370
- const RUNTIME_VALUE = Symbol("RUNTIME_VALUE");
371
+ const RUNTIME_VALUE = /* @__PURE__ */ Symbol("RUNTIME_VALUE");
371
372
  function extractValue(node, path, optional = false) {
372
373
  if (isNullLiteral(node)) {
373
374
  return null;
@@ -3,6 +3,7 @@ import { cosmiconfigSync } from 'cosmiconfig';
3
3
  import { writeFileSync, existsSync, rmSync } from 'node:fs';
4
4
  import { createRequire } from 'node:module';
5
5
  import { join, dirname } from 'node:path';
6
+ import { threadId } from 'node:worker_threads';
6
7
  import { GraphCommerceConfigSchema } from './generated/config.js';
7
8
  import { cloneDeep, mergeDeep } from '@apollo/client/utilities/internal';
8
9
  import chalk from 'chalk';
@@ -289,7 +290,7 @@ function loadTsConfig(filepath) {
289
290
  });
290
291
  const tmpFile = join(
291
292
  dirname(filepath),
292
- `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`
293
+ `.${moduleName}.tmp.${process.pid}-${threadId}-${tmpCounter++}.cjs`
293
294
  );
294
295
  try {
295
296
  writeFileSync(tmpFile, code);
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": "11.0.0-canary.47",
5
+ "version": "11.0.0-canary.49",
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": "^11.0.0-canary.47",
66
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.49",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -4,6 +4,7 @@ import { cosmiconfigSync } from 'cosmiconfig'
4
4
  import { existsSync, rmSync, writeFileSync } from 'node:fs'
5
5
  import { createRequire } from 'node:module'
6
6
  import { dirname, join } from 'node:path'
7
+ import { threadId } from 'node:worker_threads'
7
8
  import type { GraphCommerceConfig } from '../generated/config'
8
9
  import { GraphCommerceConfigSchema } from '../generated/config'
9
10
  import { demoConfig } from './demoConfig'
@@ -19,7 +20,7 @@ let tmpCounter = 0
19
20
  // fixed `.cjs` path on disk and removes it again — that races between
20
21
  // Next.js worker processes (especially under Turbopack), producing
21
22
  // "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
+ // per-thread unique filename so concurrent loads never collide. The temp
23
24
  // file lives next to the source so relative `require()` calls in the
24
25
  // config still resolve.
25
26
  function loadTsConfig(filepath: string): Record<string, unknown> {
@@ -30,7 +31,7 @@ function loadTsConfig(filepath: string): Record<string, unknown> {
30
31
 
31
32
  const tmpFile = join(
32
33
  dirname(filepath),
33
- `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`,
34
+ `.${moduleName}.tmp.${process.pid}-${threadId}-${tmpCounter++}.cjs`,
34
35
  )
35
36
 
36
37
  try {