next 16.0.2-canary.10 → 16.0.2-canary.12

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 (114) hide show
  1. package/dist/bin/next +1 -1
  2. package/dist/build/babel/loader/get-config.js +5 -0
  3. package/dist/build/babel/loader/get-config.js.map +1 -1
  4. package/dist/build/index.js +7 -4
  5. package/dist/build/index.js.map +1 -1
  6. package/dist/build/jest/jest.js +2 -1
  7. package/dist/build/jest/jest.js.map +1 -1
  8. package/dist/build/load-entrypoint.js +1 -2
  9. package/dist/build/load-entrypoint.js.map +1 -1
  10. package/dist/build/lockfile.d.ts +1 -1
  11. package/dist/build/lockfile.js +5 -9
  12. package/dist/build/lockfile.js.map +1 -1
  13. package/dist/build/next-config-ts/transpile-config.js +13 -3
  14. package/dist/build/next-config-ts/transpile-config.js.map +1 -1
  15. package/dist/build/swc/index.d.ts +4 -2
  16. package/dist/build/swc/index.js +54 -51
  17. package/dist/build/swc/index.js.map +1 -1
  18. package/dist/build/swc/install-bindings.d.ts +15 -0
  19. package/dist/build/swc/install-bindings.js +30 -0
  20. package/dist/build/swc/install-bindings.js.map +1 -0
  21. package/dist/build/templates/app-page.js +7 -1
  22. package/dist/build/templates/app-page.js.map +1 -1
  23. package/dist/build/turbopack-build/impl.js +9 -4
  24. package/dist/build/turbopack-build/impl.js.map +1 -1
  25. package/dist/build/webpack/loaders/lightningcss-loader/src/loader.js +7 -2
  26. package/dist/build/webpack/loaders/lightningcss-loader/src/loader.js.map +1 -1
  27. package/dist/build/webpack/loaders/lightningcss-loader/src/minify.js +2 -2
  28. package/dist/build/webpack/loaders/lightningcss-loader/src/minify.js.map +1 -1
  29. package/dist/build/webpack/loaders/next-app-loader/index.js +6 -0
  30. package/dist/build/webpack/loaders/next-app-loader/index.js.map +1 -1
  31. package/dist/build/webpack/loaders/next-barrel-loader.js +5 -0
  32. package/dist/build/webpack/loaders/next-barrel-loader.js.map +1 -1
  33. package/dist/build/webpack/loaders/next-metadata-image-loader.js +5 -0
  34. package/dist/build/webpack/loaders/next-metadata-image-loader.js.map +1 -1
  35. package/dist/build/webpack/loaders/next-metadata-route-loader.js +5 -0
  36. package/dist/build/webpack/loaders/next-metadata-route-loader.js.map +1 -1
  37. package/dist/build/webpack/loaders/next-swc-loader.js +10 -6
  38. package/dist/build/webpack/loaders/next-swc-loader.js.map +1 -1
  39. package/dist/build/webpack-build/impl.js +4 -1
  40. package/dist/build/webpack-build/impl.js.map +1 -1
  41. package/dist/build/webpack-config.js +2 -7
  42. package/dist/build/webpack-config.js.map +1 -1
  43. package/dist/cli/next-typegen.js +3 -0
  44. package/dist/cli/next-typegen.js.map +1 -1
  45. package/dist/client/app-bootstrap.js +1 -1
  46. package/dist/client/index.js +1 -1
  47. package/dist/compiled/@next/font/dist/google/font-data.json +63 -0
  48. package/dist/compiled/@next/font/dist/google/index.d.ts +40 -0
  49. package/dist/esm/build/babel/loader/get-config.js +5 -0
  50. package/dist/esm/build/babel/loader/get-config.js.map +1 -1
  51. package/dist/esm/build/index.js +7 -4
  52. package/dist/esm/build/index.js.map +1 -1
  53. package/dist/esm/build/load-entrypoint.js +2 -3
  54. package/dist/esm/build/load-entrypoint.js.map +1 -1
  55. package/dist/esm/build/lockfile.js +5 -9
  56. package/dist/esm/build/lockfile.js.map +1 -1
  57. package/dist/esm/build/next-config-ts/transpile-config.js +13 -3
  58. package/dist/esm/build/next-config-ts/transpile-config.js.map +1 -1
  59. package/dist/esm/build/swc/index.js +52 -49
  60. package/dist/esm/build/swc/index.js.map +1 -1
  61. package/dist/esm/build/swc/install-bindings.js +20 -0
  62. package/dist/esm/build/swc/install-bindings.js.map +1 -0
  63. package/dist/esm/build/templates/app-page.js +7 -1
  64. package/dist/esm/build/templates/app-page.js.map +1 -1
  65. package/dist/esm/build/turbopack-build/impl.js +10 -5
  66. package/dist/esm/build/turbopack-build/impl.js.map +1 -1
  67. package/dist/esm/build/webpack/loaders/lightningcss-loader/src/loader.js +7 -2
  68. package/dist/esm/build/webpack/loaders/lightningcss-loader/src/loader.js.map +1 -1
  69. package/dist/esm/build/webpack/loaders/lightningcss-loader/src/minify.js +2 -2
  70. package/dist/esm/build/webpack/loaders/lightningcss-loader/src/minify.js.map +1 -1
  71. package/dist/esm/build/webpack/loaders/next-app-loader/index.js +6 -0
  72. package/dist/esm/build/webpack/loaders/next-app-loader/index.js.map +1 -1
  73. package/dist/esm/build/webpack/loaders/next-barrel-loader.js +5 -0
  74. package/dist/esm/build/webpack/loaders/next-barrel-loader.js.map +1 -1
  75. package/dist/esm/build/webpack/loaders/next-metadata-image-loader.js +5 -0
  76. package/dist/esm/build/webpack/loaders/next-metadata-image-loader.js.map +1 -1
  77. package/dist/esm/build/webpack/loaders/next-metadata-route-loader.js +5 -0
  78. package/dist/esm/build/webpack/loaders/next-metadata-route-loader.js.map +1 -1
  79. package/dist/esm/build/webpack/loaders/next-swc-loader.js +11 -7
  80. package/dist/esm/build/webpack/loaders/next-swc-loader.js.map +1 -1
  81. package/dist/esm/build/webpack-build/impl.js +4 -1
  82. package/dist/esm/build/webpack-build/impl.js.map +1 -1
  83. package/dist/esm/build/webpack-config.js +2 -7
  84. package/dist/esm/build/webpack-config.js.map +1 -1
  85. package/dist/esm/client/app-bootstrap.js +1 -1
  86. package/dist/esm/client/index.js +1 -1
  87. package/dist/esm/server/config.js +2 -2
  88. package/dist/esm/server/config.js.map +1 -1
  89. package/dist/esm/server/dev/hot-reloader-turbopack.js +3 -4
  90. package/dist/esm/server/dev/hot-reloader-turbopack.js.map +1 -1
  91. package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
  92. package/dist/esm/server/lib/app-info-log.js +1 -1
  93. package/dist/esm/server/lib/router-utils/setup-dev-bundler.js +3 -0
  94. package/dist/esm/server/lib/router-utils/setup-dev-bundler.js.map +1 -1
  95. package/dist/esm/server/lib/start-server.js +1 -1
  96. package/dist/esm/server/lib/trace/tracer.js +6 -5
  97. package/dist/esm/server/lib/trace/tracer.js.map +1 -1
  98. package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
  99. package/dist/server/config.js +2 -2
  100. package/dist/server/config.js.map +1 -1
  101. package/dist/server/dev/hot-reloader-turbopack.js +2 -3
  102. package/dist/server/dev/hot-reloader-turbopack.js.map +1 -1
  103. package/dist/server/dev/hot-reloader-webpack.js +1 -1
  104. package/dist/server/lib/app-info-log.js +1 -1
  105. package/dist/server/lib/router-utils/setup-dev-bundler.js +3 -0
  106. package/dist/server/lib/router-utils/setup-dev-bundler.js.map +1 -1
  107. package/dist/server/lib/start-server.js +1 -1
  108. package/dist/server/lib/trace/tracer.js +6 -5
  109. package/dist/server/lib/trace/tracer.js.map +1 -1
  110. package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
  111. package/dist/telemetry/anonymous-meta.js +1 -1
  112. package/dist/telemetry/events/session-stopped.js +2 -2
  113. package/dist/telemetry/events/version.js +2 -2
  114. package/package.json +15 -15
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
- import { loadBindings } from './swc';
3
+ import { getBindingsSync } from './swc';
4
4
  // NOTE: this should be updated if this loader file is moved.
5
5
  const PACKAGE_ROOT = path.normalize(path.join(__dirname, '../..'));
6
6
  const TEMPLATE_SRC_FOLDER = path.normalize(path.join(__dirname, './templates'));
@@ -21,10 +21,9 @@ const TEMPLATES_ESM_FOLDER = path.normalize(path.join(__dirname, '../../dist/esm
21
21
  * @param imports optional imports to insert or set to null
22
22
  * @returns the loaded file with the replacements
23
23
  */ export async function loadEntrypoint(entrypoint, replacements, injections, imports) {
24
- let bindings = await loadBindings();
25
24
  const templatePath = path.resolve(path.join(TEMPLATES_ESM_FOLDER, `${entrypoint}.js`));
26
25
  let content = await fs.readFile(templatePath);
27
- return bindings.expandNextJsTemplate(content, // Ensure that we use unix-style path separators for the import paths
26
+ return getBindingsSync().expandNextJsTemplate(content, // Ensure that we use unix-style path separators for the import paths
28
27
  path.join(TEMPLATE_SRC_FOLDER, `${entrypoint}.js`).replace(/\\/g, '/'), PACKAGE_ROOT.replace(/\\/g, '/'), replacements, injections ?? {}, imports ?? {});
29
28
  }
30
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/build/load-entrypoint.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { loadBindings } from './swc'\n\n// NOTE: this should be updated if this loader file is moved.\nconst PACKAGE_ROOT = path.normalize(path.join(__dirname, '../..'))\nconst TEMPLATE_SRC_FOLDER = path.normalize(path.join(__dirname, './templates'))\nconst TEMPLATES_ESM_FOLDER = path.normalize(\n path.join(__dirname, '../../dist/esm/build/templates')\n)\n\n/**\n * Load the entrypoint file from the ESM directory and performs string\n * replacements of the template variables specified in the `replacements`\n * argument.\n *\n * For non-string replacements, the template should use the\n * `declare const ${key}: ${type}` syntax. to ensure that the type is correct\n * and the typescript can compile. You may have to use `@ts-expect-error` to\n * handle replacement values that are related to imports.\n *\n * @param entrypoint the entrypoint to load\n * @param replacements string replacements to perform\n * @param injections code injections to perform\n * @param imports optional imports to insert or set to null\n * @returns the loaded file with the replacements\n */\nexport async function loadEntrypoint(\n entrypoint:\n | 'app-page'\n | 'app-route'\n | 'edge-app-route'\n | 'edge-ssr'\n | 'edge-ssr-app'\n | 'middleware'\n | 'pages'\n | 'pages-api',\n replacements: Record<`VAR_${string}`, string>,\n injections?: Record<string, string>,\n imports?: Record<string, string | null>\n): Promise<string> {\n let bindings = await loadBindings()\n\n const templatePath = path.resolve(\n path.join(TEMPLATES_ESM_FOLDER, `${entrypoint}.js`)\n )\n let content = await fs.readFile(templatePath)\n\n return bindings.expandNextJsTemplate(\n content,\n // Ensure that we use unix-style path separators for the import paths\n path.join(TEMPLATE_SRC_FOLDER, `${entrypoint}.js`).replace(/\\\\/g, '/'),\n PACKAGE_ROOT.replace(/\\\\/g, '/'),\n replacements,\n injections ?? {},\n imports ?? {}\n )\n}\n"],"names":["fs","path","loadBindings","PACKAGE_ROOT","normalize","join","__dirname","TEMPLATE_SRC_FOLDER","TEMPLATES_ESM_FOLDER","loadEntrypoint","entrypoint","replacements","injections","imports","bindings","templatePath","resolve","content","readFile","expandNextJsTemplate","replace"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,YAAY,QAAQ,QAAO;AAEpC,6DAA6D;AAC7D,MAAMC,eAAeF,KAAKG,SAAS,CAACH,KAAKI,IAAI,CAACC,WAAW;AACzD,MAAMC,sBAAsBN,KAAKG,SAAS,CAACH,KAAKI,IAAI,CAACC,WAAW;AAChE,MAAME,uBAAuBP,KAAKG,SAAS,CACzCH,KAAKI,IAAI,CAACC,WAAW;AAGvB;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeG,eACpBC,UAQe,EACfC,YAA6C,EAC7CC,UAAmC,EACnCC,OAAuC;IAEvC,IAAIC,WAAW,MAAMZ;IAErB,MAAMa,eAAed,KAAKe,OAAO,CAC/Bf,KAAKI,IAAI,CAACG,sBAAsB,GAAGE,WAAW,GAAG,CAAC;IAEpD,IAAIO,UAAU,MAAMjB,GAAGkB,QAAQ,CAACH;IAEhC,OAAOD,SAASK,oBAAoB,CAClCF,SACA,qEAAqE;IACrEhB,KAAKI,IAAI,CAACE,qBAAqB,GAAGG,WAAW,GAAG,CAAC,EAAEU,OAAO,CAAC,OAAO,MAClEjB,aAAaiB,OAAO,CAAC,OAAO,MAC5BT,cACAC,cAAc,CAAC,GACfC,WAAW,CAAC;AAEhB","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../src/build/load-entrypoint.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { getBindingsSync } from './swc'\n\n// NOTE: this should be updated if this loader file is moved.\nconst PACKAGE_ROOT = path.normalize(path.join(__dirname, '../..'))\nconst TEMPLATE_SRC_FOLDER = path.normalize(path.join(__dirname, './templates'))\nconst TEMPLATES_ESM_FOLDER = path.normalize(\n path.join(__dirname, '../../dist/esm/build/templates')\n)\n\n/**\n * Load the entrypoint file from the ESM directory and performs string\n * replacements of the template variables specified in the `replacements`\n * argument.\n *\n * For non-string replacements, the template should use the\n * `declare const ${key}: ${type}` syntax. to ensure that the type is correct\n * and the typescript can compile. You may have to use `@ts-expect-error` to\n * handle replacement values that are related to imports.\n *\n * @param entrypoint the entrypoint to load\n * @param replacements string replacements to perform\n * @param injections code injections to perform\n * @param imports optional imports to insert or set to null\n * @returns the loaded file with the replacements\n */\nexport async function loadEntrypoint(\n entrypoint:\n | 'app-page'\n | 'app-route'\n | 'edge-app-route'\n | 'edge-ssr'\n | 'edge-ssr-app'\n | 'middleware'\n | 'pages'\n | 'pages-api',\n replacements: Record<`VAR_${string}`, string>,\n injections?: Record<string, string>,\n imports?: Record<string, string | null>\n): Promise<string> {\n const templatePath = path.resolve(\n path.join(TEMPLATES_ESM_FOLDER, `${entrypoint}.js`)\n )\n let content = await fs.readFile(templatePath)\n\n return getBindingsSync().expandNextJsTemplate(\n content,\n // Ensure that we use unix-style path separators for the import paths\n path.join(TEMPLATE_SRC_FOLDER, `${entrypoint}.js`).replace(/\\\\/g, '/'),\n PACKAGE_ROOT.replace(/\\\\/g, '/'),\n replacements,\n injections ?? {},\n imports ?? {}\n )\n}\n"],"names":["fs","path","getBindingsSync","PACKAGE_ROOT","normalize","join","__dirname","TEMPLATE_SRC_FOLDER","TEMPLATES_ESM_FOLDER","loadEntrypoint","entrypoint","replacements","injections","imports","templatePath","resolve","content","readFile","expandNextJsTemplate","replace"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,eAAe,QAAQ,QAAO;AAEvC,6DAA6D;AAC7D,MAAMC,eAAeF,KAAKG,SAAS,CAACH,KAAKI,IAAI,CAACC,WAAW;AACzD,MAAMC,sBAAsBN,KAAKG,SAAS,CAACH,KAAKI,IAAI,CAACC,WAAW;AAChE,MAAME,uBAAuBP,KAAKG,SAAS,CACzCH,KAAKI,IAAI,CAACC,WAAW;AAGvB;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeG,eACpBC,UAQe,EACfC,YAA6C,EAC7CC,UAAmC,EACnCC,OAAuC;IAEvC,MAAMC,eAAeb,KAAKc,OAAO,CAC/Bd,KAAKI,IAAI,CAACG,sBAAsB,GAAGE,WAAW,GAAG,CAAC;IAEpD,IAAIM,UAAU,MAAMhB,GAAGiB,QAAQ,CAACH;IAEhC,OAAOZ,kBAAkBgB,oBAAoB,CAC3CF,SACA,qEAAqE;IACrEf,KAAKI,IAAI,CAACE,qBAAqB,GAAGG,WAAW,GAAG,CAAC,EAAES,OAAO,CAAC,OAAO,MAClEhB,aAAagB,OAAO,CAAC,OAAO,MAC5BR,cACAC,cAAc,CAAC,GACfC,WAAW,CAAC;AAEhB","ignoreList":[0]}
@@ -1,5 +1,6 @@
1
1
  import { bold, cyan } from '../lib/picocolors';
2
2
  import * as Log from './output/log';
3
+ import { getBindingsSync } from './swc';
3
4
  const RETRY_DELAY_MS = 10;
4
5
  const MAX_RETRY_MS = 1000;
5
6
  /**
@@ -37,20 +38,15 @@ const MAX_RETRY_MS = 1000;
37
38
  *
38
39
  * - If we fail to acquire the lock, we return `undefined`.
39
40
  * - If we're on wasm, this always returns a dummy `Lockfile` object.
40
- */ static async tryAcquire(path, unlockOnExit = true) {
41
- const { loadBindings } = require('./swc');
42
- // Ideally we could provide a sync version of `tryAcquire`, but
43
- // `loadBindings` is async. We're okay with skipping async-loaded wasm
44
- // bindings and the internal `loadNative` function is synchronous, but it
45
- // lacks some checks that `loadBindings` has.
46
- const bindings = await loadBindings();
41
+ */ static tryAcquire(path, unlockOnExit = true) {
42
+ const bindings = getBindingsSync();
47
43
  if (bindings.isWasm) {
48
44
  Log.info(`Skipping creating a lockfile at ${cyan(path)} because we're using WASM bindings`);
49
45
  return new Lockfile(bindings, undefined);
50
46
  } else {
51
47
  let nativeLockfile;
52
48
  try {
53
- nativeLockfile = await bindings.lockfileTryAcquire(path);
49
+ nativeLockfile = bindings.lockfileTryAcquireSync(path);
54
50
  } catch (e) {
55
51
  // this happens if there's an IO error (e.g. `ENOENT`), which is
56
52
  // different than if we just didn't acquire the lock
@@ -96,7 +92,7 @@ const MAX_RETRY_MS = 1000;
96
92
  const startMs = Date.now();
97
93
  let lockfile;
98
94
  while(Date.now() - startMs < MAX_RETRY_MS){
99
- lockfile = await Lockfile.tryAcquire(path, unlockOnExit);
95
+ lockfile = Lockfile.tryAcquire(path, unlockOnExit);
100
96
  if (lockfile !== undefined) break;
101
97
  await new Promise((resolve)=>setTimeout(resolve, RETRY_DELAY_MS));
102
98
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/build/lockfile.ts"],"sourcesContent":["import { bold, cyan } from '../lib/picocolors'\nimport * as Log from './output/log'\n\nimport type { Binding, Lockfile as NativeLockfile } from './swc/types'\n\nconst RETRY_DELAY_MS = 10\nconst MAX_RETRY_MS = 1000\n\n/**\n * A cross-platform on-disk best-effort advisory exclusive lockfile\n * implementation.\n *\n * On Windows, this opens a file in write mode with the `FILE_SHARE_WRITE` flag\n * unset, so it still allows reading the lockfile. This avoids breaking tools\n * that read the contents of `.next`.\n *\n * On POSIX platforms, this uses `flock()` via `std::fs::File::try_lock`:\n * https://doc.rust-lang.org/std/fs/struct.File.html#method.try_lock\n *\n * On WASM, a dummy implementation is used which always \"succeeds\" in acquiring\n * the lock.\n *\n * This provides a more idiomatic wrapper around the lockfile APIs exposed on\n * the native bindings object.\n *\n * If this lock is not explicitly closed with `unlock`, we will:\n * - If `unlockOnExit` is set (the default), it will make a best-effort attempt\n * to unlock the lockfile using `process.on('exit', ...)`. This is preferrable\n * on Windows where it may take some time after process exit for the operating\n * system to clean up locks that are not explicitly released by the process.\n * - If we fail to ever release the lockfile, the operating system will clean up\n * the lock and file descriptor upon process exit.\n */\nexport class Lockfile {\n /**\n * The underlying `Lockfile` object returned by the native bindings.\n *\n * This can be `undefined` on wasm, where we don't acquire a real lockfile.\n */\n private bindings: Binding\n private nativeLockfile: NativeLockfile | undefined\n private listener: NodeJS.ExitListener | undefined\n\n private constructor(\n bindings: Binding,\n nativeLockfile: NativeLockfile | undefined\n ) {\n this.bindings = bindings\n this.nativeLockfile = nativeLockfile\n }\n\n /**\n * Attempts to create or acquire an exclusive lockfile on disk. Lockfiles are\n * best-effort, depending on the platform.\n *\n * - If we fail to acquire the lock, we return `undefined`.\n * - If we're on wasm, this always returns a dummy `Lockfile` object.\n */\n static async tryAcquire(\n path: string,\n unlockOnExit: boolean = true\n ): Promise<Lockfile | undefined> {\n const { loadBindings } = require('./swc') as typeof import('./swc')\n // Ideally we could provide a sync version of `tryAcquire`, but\n // `loadBindings` is async. We're okay with skipping async-loaded wasm\n // bindings and the internal `loadNative` function is synchronous, but it\n // lacks some checks that `loadBindings` has.\n const bindings = await loadBindings()\n if (bindings.isWasm) {\n Log.info(\n `Skipping creating a lockfile at ${cyan(path)} because we're using WASM bindings`\n )\n return new Lockfile(bindings, undefined)\n } else {\n let nativeLockfile\n try {\n nativeLockfile = await bindings.lockfileTryAcquire(path)\n } catch (e) {\n // this happens if there's an IO error (e.g. `ENOENT`), which is\n // different than if we just didn't acquire the lock\n throw new Error(\n 'An IO error occurred while attempting to create and acquire the lockfile',\n { cause: e }\n )\n }\n if (nativeLockfile != null) {\n const jsLockfile = new Lockfile(bindings, nativeLockfile)\n if (unlockOnExit) {\n const exitListener = () => {\n // Best-Effort: If we don't do this, the operating system will\n // release the lock for us. This gives an opportunity to delete the\n // unlocked lockfile (which is not otherwise deleted on POSIX).\n //\n // This must be synchronous because `process.on('exit', ...)` is\n // synchronous.\n jsLockfile.unlockSync()\n }\n process.on('exit', exitListener)\n jsLockfile.listener = exitListener\n }\n return jsLockfile\n } else {\n return undefined\n }\n }\n }\n\n /**\n * Attempts to create or acquire a lockfile using `Lockfile.tryAcquire`. If\n * that returns `undefined`, indicating that another process or caller has the\n * lockfile, then this will output an error message and exit the process with\n * a non-zero exit code.\n *\n * This will retry a small number of times. This can be useful when running\n * processes in a loop, e.g. if cleanup isn't fully synchronous due to child\n * parent/processes.\n */\n static async acquireWithRetriesOrExit(\n path: string,\n processName: string,\n unlockOnExit: boolean = true\n ): Promise<Lockfile> {\n const startMs = Date.now()\n let lockfile\n while (Date.now() - startMs < MAX_RETRY_MS) {\n lockfile = await Lockfile.tryAcquire(path, unlockOnExit)\n if (lockfile !== undefined) break\n await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS))\n }\n if (lockfile === undefined) {\n Log.error(\n `Unable to acquire lock at ${cyan(path)}, is another instance of ${cyan(processName)} running?`\n )\n Log.info(\n `${bold('Suggestion:')} If you intended to restart ${cyan(processName)}, terminate the other process, and then try again.`\n )\n process.exit(1)\n }\n return lockfile\n }\n\n /**\n * Releases the lockfile and closes the file descriptor.\n *\n * If this is not called, the lock will be released by the operating system\n * when the file handle is closed during process exit.\n */\n async unlock(): Promise<void> {\n const { nativeLockfile, listener } = this\n if (nativeLockfile !== undefined) {\n await this.bindings.lockfileUnlock(nativeLockfile)\n }\n if (listener !== undefined) {\n process.off('exit', listener)\n }\n }\n\n /**\n * A blocking version of `unlock`.\n */\n unlockSync(): void {\n const { nativeLockfile, listener } = this\n if (nativeLockfile !== undefined) {\n this.bindings.lockfileUnlockSync(nativeLockfile)\n }\n if (listener !== undefined) {\n process.off('exit', listener)\n }\n }\n}\n"],"names":["bold","cyan","Log","RETRY_DELAY_MS","MAX_RETRY_MS","Lockfile","bindings","nativeLockfile","tryAcquire","path","unlockOnExit","loadBindings","require","isWasm","info","undefined","lockfileTryAcquire","e","Error","cause","jsLockfile","exitListener","unlockSync","process","on","listener","acquireWithRetriesOrExit","processName","startMs","Date","now","lockfile","Promise","resolve","setTimeout","error","exit","unlock","lockfileUnlock","off","lockfileUnlockSync"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,oBAAmB;AAC9C,YAAYC,SAAS,eAAc;AAInC,MAAMC,iBAAiB;AACvB,MAAMC,eAAe;AAErB;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,G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,KAAKF,UAAUxB,aAAc;YAC1C2B,WAAW,MAAM1B,SAASG,UAAU,CAACC,MAAMC;YAC3C,IAAIqB,aAAahB,WAAW;YAC5B,MAAM,IAAIiB,QAAQ,CAACC,UAAYC,WAAWD,SAAS9B;QACrD;QACA,IAAI4B,aAAahB,WAAW;YAC1Bb,IAAIiC,KAAK,CACP,CAAC,0BAA0B,EAAElC,KAAKQ,MAAM,yBAAyB,EAAER,KAAK0B,aAAa,SAAS,CAAC;YAEjGzB,IAAIY,IAAI,CACN,GAAGd,KAAK,eAAe,4BAA4B,EAAEC,KAAK0B,aAAa,kDAAkD,CAAC;YAE5HJ,QAAQa,IAAI,CAAC;QACf;QACA,OAAOL;IACT;IAEA;;;;;GAKC,GACD,MAAMM,SAAwB;QAC5B,MAAM,EAAE9B,cAAc,EAAEkB,QAAQ,EAAE,GAAG,IAAI;QACzC,IAAIlB,mBAAmBQ,WAAW;YAChC,MAAM,IAAI,CAACT,QAAQ,CAACgC,cAAc,CAAC/B;QACrC;QACA,IAAIkB,aAAaV,WAAW;YAC1BQ,QAAQgB,GAAG,CAAC,QAAQd;QACtB;IACF;IAEA;;GAEC,GACDH,aAAmB;QACjB,MAAM,EAAEf,cAAc,EAAEkB,QAAQ,EAAE,GAAG,IAAI;QACzC,IAAIlB,mBAAmBQ,WAAW;YAChC,IAAI,CAACT,QAAQ,CAACkC,kBAAkB,CAACjC;QACnC;QACA,IAAIkB,aAAaV,WAAW;YAC1BQ,QAAQgB,GAAG,CAAC,QAAQd;QACtB;IACF;AACF","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../src/build/lockfile.ts"],"sourcesContent":["import { bold, cyan } from '../lib/picocolors'\nimport * as Log from './output/log'\nimport { getBindingsSync } from './swc'\n\nimport type { Binding, Lockfile as NativeLockfile } from './swc/types'\n\nconst RETRY_DELAY_MS = 10\nconst MAX_RETRY_MS = 1000\n\n/**\n * A cross-platform on-disk best-effort advisory exclusive lockfile\n * implementation.\n *\n * On Windows, this opens a file in write mode with the `FILE_SHARE_WRITE` flag\n * unset, so it still allows reading the lockfile. This avoids breaking tools\n * that read the contents of `.next`.\n *\n * On POSIX platforms, this uses `flock()` via `std::fs::File::try_lock`:\n * https://doc.rust-lang.org/std/fs/struct.File.html#method.try_lock\n *\n * On WASM, a dummy implementation is used which always \"succeeds\" in acquiring\n * the lock.\n *\n * This provides a more idiomatic wrapper around the lockfile APIs exposed on\n * the native bindings object.\n *\n * If this lock is not explicitly closed with `unlock`, we will:\n * - If `unlockOnExit` is set (the default), it will make a best-effort attempt\n * to unlock the lockfile using `process.on('exit', ...)`. This is preferrable\n * on Windows where it may take some time after process exit for the operating\n * system to clean up locks that are not explicitly released by the process.\n * - If we fail to ever release the lockfile, the operating system will clean up\n * the lock and file descriptor upon process exit.\n */\nexport class Lockfile {\n /**\n * The underlying `Lockfile` object returned by the native bindings.\n *\n * This can be `undefined` on wasm, where we don't acquire a real lockfile.\n */\n private bindings: Binding\n private nativeLockfile: NativeLockfile | undefined\n private listener: NodeJS.ExitListener | undefined\n\n private constructor(\n bindings: Binding,\n nativeLockfile: NativeLockfile | undefined\n ) {\n this.bindings = bindings\n this.nativeLockfile = nativeLockfile\n }\n\n /**\n * Attempts to create or acquire an exclusive lockfile on disk. Lockfiles are\n * best-effort, depending on the platform.\n *\n * - If we fail to acquire the lock, we return `undefined`.\n * - If we're on wasm, this always returns a dummy `Lockfile` object.\n */\n static tryAcquire(\n path: string,\n unlockOnExit: boolean = true\n ): Lockfile | undefined {\n const bindings = getBindingsSync()\n if (bindings.isWasm) {\n Log.info(\n `Skipping creating a lockfile at ${cyan(path)} because we're using WASM bindings`\n )\n return new Lockfile(bindings, undefined)\n } else {\n let nativeLockfile\n try {\n nativeLockfile = bindings.lockfileTryAcquireSync(path)\n } catch (e) {\n // this happens if there's an IO error (e.g. `ENOENT`), which is\n // different than if we just didn't acquire the lock\n throw new Error(\n 'An IO error occurred while attempting to create and acquire the lockfile',\n { cause: e }\n )\n }\n if (nativeLockfile != null) {\n const jsLockfile = new Lockfile(bindings, nativeLockfile)\n if (unlockOnExit) {\n const exitListener = () => {\n // Best-Effort: If we don't do this, the operating system will\n // release the lock for us. This gives an opportunity to delete the\n // unlocked lockfile (which is not otherwise deleted on POSIX).\n //\n // This must be synchronous because `process.on('exit', ...)` is\n // synchronous.\n jsLockfile.unlockSync()\n }\n process.on('exit', exitListener)\n jsLockfile.listener = exitListener\n }\n return jsLockfile\n } else {\n return undefined\n }\n }\n }\n\n /**\n * Attempts to create or acquire a lockfile using `Lockfile.tryAcquire`. If\n * that returns `undefined`, indicating that another process or caller has the\n * lockfile, then this will output an error message and exit the process with\n * a non-zero exit code.\n *\n * This will retry a small number of times. This can be useful when running\n * processes in a loop, e.g. if cleanup isn't fully synchronous due to child\n * parent/processes.\n */\n static async acquireWithRetriesOrExit(\n path: string,\n processName: string,\n unlockOnExit: boolean = true\n ): Promise<Lockfile> {\n const startMs = Date.now()\n let lockfile\n while (Date.now() - startMs < MAX_RETRY_MS) {\n lockfile = Lockfile.tryAcquire(path, unlockOnExit)\n if (lockfile !== undefined) break\n await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS))\n }\n if (lockfile === undefined) {\n Log.error(\n `Unable to acquire lock at ${cyan(path)}, is another instance of ${cyan(processName)} running?`\n )\n Log.info(\n `${bold('Suggestion:')} If you intended to restart ${cyan(processName)}, terminate the other process, and then try again.`\n )\n process.exit(1)\n }\n return lockfile\n }\n\n /**\n * Releases the lockfile and closes the file descriptor.\n *\n * If this is not called, the lock will be released by the operating system\n * when the file handle is closed during process exit.\n */\n async unlock(): Promise<void> {\n const { nativeLockfile, listener } = this\n if (nativeLockfile !== undefined) {\n await this.bindings.lockfileUnlock(nativeLockfile)\n }\n if (listener !== undefined) {\n process.off('exit', listener)\n }\n }\n\n /**\n * A blocking version of `unlock`.\n */\n unlockSync(): void {\n const { nativeLockfile, listener } = this\n if (nativeLockfile !== undefined) {\n this.bindings.lockfileUnlockSync(nativeLockfile)\n }\n if (listener !== undefined) {\n process.off('exit', listener)\n }\n }\n}\n"],"names":["bold","cyan","Log","getBindingsSync","RETRY_DELAY_MS","MAX_RETRY_MS","Lockfile","bindings","nativeLockfile","tryAcquire","path","unlockOnExit","isWasm","info","undefined","lockfileTryAcquireSync","e","Error","cause","jsLockfile","exitListener","unlockSync","process","on","listener","acquireWithRetriesOrExit","processName","startMs","Date","now","lockfile","Promise","resolve","setTimeout","error","exit","unlock","lockfileUnlock","off","lockfileUnlockSync"],"mappings":"AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,oBAAmB;AAC9C,YAAYC,SAAS,eAAc;AACnC,SAASC,eAAe,QAAQ,QAAO;AAIvC,MAAMC,iBAAiB;AACvB,MAAMC,eAAe;AAErB;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAMC;IAUX,YACEC,QAAiB,EACjBC,cAA0C,CAC1C;QACA,IAAI,CAACD,QAAQ,GAAGA;QAChB,IAAI,CAACC,cAAc,GAAGA;IACxB;IAEA;;;;;;GAMC,GACD,OAAOC,WACLC,IAAY,EACZC,eAAwB,IAAI,EACN;QACtB,MAAMJ,WAAWJ;QACjB,IAAII,SAASK,MAAM,EAAE;YACnBV,IAAIW,IAAI,CACN,CAAC,gCAAgC,EAAEZ,KAAKS,MAAM,kCAAkC,CAAC;YAEnF,OAAO,IAAIJ,SAASC,UAAUO;QAChC,OAAO;YACL,IAAIN;YACJ,IAAI;gBACFA,iBAAiBD,SAASQ,sBAAsB,CAACL;YACnD,EAAE,OAAOM,GAAG;gBACV,gEAAgE;gBAChE,oDAAoD;gBACpD,MAAM,qBAGL,CAHK,IAAIC,MACR,4EACA;oBAAEC,OAAOF;gBAAE,IAFP,qBAAA;2BAAA;gCAAA;kCAAA;gBAGN;YACF;YACA,IAAIR,kBAAkB,MAAM;gBAC1B,MAAMW,aAAa,IAAIb,SAASC,UAAUC;gBAC1C,IAAIG,cAAc;oBAChB,MAAMS,eAAe;wBACnB,8DAA8D;wBAC9D,mEA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ACnC;QACA,IAAIgB,aAAaV,WAAW;YAC1BQ,QAAQgB,GAAG,CAAC,QAAQd;QACtB;IACF;AACF","ignoreList":[0]}
@@ -128,18 +128,28 @@ async function handleCJS({ cwd, nextConfigPath, compilerOptions }) {
128
128
  const swcOptions = resolveSWCOptions(cwd, compilerOptions);
129
129
  let hasRequire = false;
130
130
  try {
131
+ var _config_experimental;
131
132
  const nextConfigString = await readFile(nextConfigPath, 'utf8');
132
133
  // lazy require swc since it loads React before even setting NODE_ENV
133
134
  // resulting loading Development React on Production
134
- const { transform } = require('../swc');
135
- const { code } = await transform(nextConfigString, swcOptions);
135
+ const { loadBindings } = require('../swc');
136
+ const bindings = await loadBindings();
137
+ const { code } = await bindings.transform(nextConfigString, swcOptions);
136
138
  // register require hook only if require exists
137
139
  if (code.includes('require(')) {
138
140
  registerHook(swcOptions);
139
141
  hasRequire = true;
140
142
  }
141
143
  // filename & extension don't matter here
142
- return requireFromString(code, resolve(cwd, 'next.config.compiled.js'));
144
+ const config = requireFromString(code, resolve(cwd, 'next.config.compiled.js'));
145
+ // At this point we have already loaded the bindings without this configuration setting due to the `transform` call above.
146
+ // Possibly we fell back to wasm in which case, it all works out but if not we need to warn
147
+ // that the configuration was ignored.
148
+ if ((config == null ? void 0 : (_config_experimental = config.experimental) == null ? void 0 : _config_experimental.useWasmBinary) && !bindings.isWasm) {
149
+ warn('Using a next.config.ts file is incompatible with `experimental.useWasmBinary` unless ' + '`--experimental-next-config-strip-types` is also passed.\nSetting `useWasmBinary` to `false');
150
+ config.experimental.useWasmBinary = false;
151
+ }
152
+ return config;
143
153
  } catch (error) {
144
154
  throw error;
145
155
  } finally{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/build/next-config-ts/transpile-config.ts"],"sourcesContent":["import type { Options as SWCOptions } from '@swc/core'\nimport type { CompilerOptions } from 'typescript'\n\nimport { resolve } from 'node:path'\nimport { readFile } from 'node:fs/promises'\nimport { pathToFileURL } from 'node:url'\nimport { deregisterHook, registerHook, requireFromString } from './require-hook'\nimport { warn, warnOnce } from '../output/log'\nimport { installDependencies } from '../../lib/install-dependencies'\nimport { getNodeOptionsArgs } from '../../server/lib/utils'\n\nfunction resolveSWCOptions(\n cwd: string,\n compilerOptions: CompilerOptions\n): SWCOptions {\n return {\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n ...(compilerOptions.paths ? { paths: compilerOptions.paths } : {}),\n ...(compilerOptions.baseUrl\n ? // Needs to be an absolute path.\n { baseUrl: resolve(cwd, compilerOptions.baseUrl) }\n : compilerOptions.paths\n ? // If paths is given, baseUrl is required.\n { baseUrl: cwd }\n : {}),\n },\n module: {\n type: 'commonjs',\n },\n isModule: 'unknown',\n env: {\n targets: {\n // Setting the Node.js version can reduce unnecessary code generation.\n node: process?.versions?.node ?? '20.19.0',\n },\n },\n } satisfies SWCOptions\n}\n\n// Ported from next/src/lib/verify-typescript-setup.ts\n// Although this overlaps with the later `verifyTypeScriptSetup`,\n// it is acceptable since the time difference in the worst case is trivial,\n// as we are only preparing to install the dependencies once more.\nasync function verifyTypeScriptSetup(cwd: string, configFileName: string) {\n try {\n // Quick module check.\n require.resolve('typescript', { paths: [cwd] })\n } catch (error) {\n if (\n error &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n ) {\n warn(\n `Installing TypeScript as it was not found while loading \"${configFileName}\".`\n )\n\n await installDependencies(cwd, [{ pkg: 'typescript' }], true).catch(\n (err) => {\n if (err && typeof err === 'object' && 'command' in err) {\n console.error(\n `Failed to install TypeScript, please install it manually to continue:\\n` +\n (err as any).command +\n '\\n'\n )\n }\n throw err\n }\n )\n }\n }\n}\n\nasync function getTsConfig(cwd: string): Promise<CompilerOptions> {\n const ts: typeof import('typescript') = require(\n require.resolve('typescript', { paths: [cwd] })\n )\n\n // NOTE: This doesn't fully cover the edge case for setting\n // \"typescript.tsconfigPath\" in next config which is currently\n // a restriction.\n const tsConfigPath = ts.findConfigFile(\n cwd,\n ts.sys.fileExists,\n 'tsconfig.json'\n )\n\n if (!tsConfigPath) {\n // It is ok to not return ts.getDefaultCompilerOptions() because\n // we are only looking for paths and baseUrl from tsConfig.\n return {}\n }\n\n const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile)\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n cwd\n )\n\n return parsedCommandLine.options\n}\n\nexport async function transpileConfig({\n nextConfigPath,\n configFileName,\n cwd,\n}: {\n nextConfigPath: string\n configFileName: string\n cwd: string\n}) {\n try {\n // envs are passed to the workers and preserve the flag\n if (process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED === 'true') {\n try {\n // Node.js v22.10.0+\n // Value is 'strip' or 'transform' based on how the feature is enabled.\n // https://nodejs.org/api/process.html#processfeaturestypescript\n // TODO: Remove `as any` once we bump @types/node to v22.10.0+\n if ((process.features as any).typescript) {\n // Run import() here to catch errors and fallback to legacy resolution.\n return (await import(pathToFileURL(nextConfigPath).href)).default\n }\n\n if (\n getNodeOptionsArgs().includes('--no-experimental-strip-types') ||\n process.execArgv.includes('--no-experimental-strip-types')\n ) {\n warnOnce(\n `Skipped resolving \"${configFileName}\" using Node.js native TypeScript resolution because it was disabled by the \"--no-experimental-strip-types\" flag.` +\n ' Falling back to legacy resolution.' +\n ' Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#using-nodejs-native-typescript-resolver-for-nextconfigts'\n )\n }\n\n // Feature is not enabled, fallback to legacy resolution for current session.\n process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED = 'false'\n } catch (cause) {\n warnOnce(\n `Failed to import \"${configFileName}\" using Node.js native TypeScript resolution.` +\n ' Falling back to legacy resolution.' +\n ' Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#using-nodejs-native-typescript-resolver-for-nextconfigts',\n { cause }\n )\n // Once failed, fallback to legacy resolution for current session.\n process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED = 'false'\n }\n }\n\n // Ensure TypeScript is installed to use the API.\n await verifyTypeScriptSetup(cwd, configFileName)\n const compilerOptions = await getTsConfig(cwd)\n\n return handleCJS({ cwd, nextConfigPath, compilerOptions })\n } catch (cause) {\n throw new Error(`Failed to transpile \"${configFileName}\".`, { cause })\n }\n}\n\nasync function handleCJS({\n cwd,\n nextConfigPath,\n compilerOptions,\n}: {\n cwd: string\n nextConfigPath: string\n compilerOptions: CompilerOptions\n}) {\n const swcOptions = resolveSWCOptions(cwd, compilerOptions)\n let hasRequire = false\n try {\n const nextConfigString = await readFile(nextConfigPath, 'utf8')\n // lazy require swc since it loads React before even setting NODE_ENV\n // resulting loading Development React on Production\n const { transform } = require('../swc') as typeof import('../swc')\n const { code } = await transform(nextConfigString, swcOptions)\n\n // register require hook only if require exists\n if (code.includes('require(')) {\n registerHook(swcOptions)\n hasRequire = true\n }\n\n // filename & extension don't matter here\n return requireFromString(code, resolve(cwd, 'next.config.compiled.js'))\n } catch (error) {\n throw error\n } finally {\n if (hasRequire) {\n deregisterHook()\n }\n }\n}\n"],"names":["resolve","readFile","pathToFileURL","deregisterHook","registerHook","requireFromString","warn","warnOnce","installDependencies","getNodeOptionsArgs","resolveSWCOptions","cwd","compilerOptions","process","jsc","parser","syntax","paths","baseUrl","module","type","isModule","env","targets","node","versions","verifyTypeScriptSetup","configFileName","require","error","code","pkg","catch","err","console","command","getTsConfig","ts","tsConfigPath","findConfigFile","sys","fileExists","configFile","readConfigFile","parsedCommandLine","parseJsonConfigFileContent","config","options","transpileConfig","nextConfigPath","__NEXT_NODE_NATIVE_TS_LOADER_ENABLED","features","typescript","href","default","includes","execArgv","cause","handleCJS","Error","swcOptions","hasRequire","nextConfigString","transform"],"mappings":"AAGA,SAASA,OAAO,QAAQ,YAAW;AACnC,SAASC,QAAQ,QAAQ,mBAAkB;AAC3C,SAASC,aAAa,QAAQ,WAAU;AACxC,SAASC,cAAc,EAAEC,YAAY,EAAEC,iBAAiB,QAAQ,iBAAgB;AAChF,SAASC,IAAI,EAAEC,QAA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E,CAAC,kBAAkB,EAAEoB,eAAe,6CAA6C,CAAC,GAChF,wCACA,qIACF;oBAAE8B;gBAAM;gBAEV,kEAAkE;gBAClE5C,QAAQS,GAAG,CAAC4B,oCAAoC,GAAG;YACrD;QACF;QAEA,iDAAiD;QACjD,MAAMxB,sBAAsBf,KAAKgB;QACjC,MAAMf,kBAAkB,MAAMwB,YAAYzB;QAE1C,OAAO+C,UAAU;YAAE/C;YAAKsC;YAAgBrC;QAAgB;IAC1D,EAAE,OAAO6C,OAAO;QACd,MAAM,qBAAgE,CAAhE,IAAIE,MAAM,CAAC,qBAAqB,EAAEhC,eAAe,EAAE,CAAC,EAAE;YAAE8B;QAAM,IAA9D,qBAAA;mBAAA;wBAAA;0BAAA;QAA+D;IACvE;AACF;AAEA,eAAeC,UAAU,EACvB/C,GAAG,EACHsC,cAAc,EACdrC,eAAe,EAKhB;IACC,MAAMgD,aAAalD,kBAAkBC,KAAKC;IAC1C,IAAIiD,aAAa;IACjB,IAAI;QACF,MAAMC,mBAAmB,MAAM7D,SAASgD,gBAAgB;QACxD,qEAAqE;QACrE,oDAAoD;QACpD,MAAM,EAAEc,SAAS,EAAE,GAAGnC,QAAQ;QAC9B,MAAM,EAAEE,IAAI,EAAE,GAAG,MAAMiC,UAAUD,kBAAkBF;QAEnD,+CAA+C;QAC/C,IAAI9B,KAAKyB,QAAQ,CAAC,aAAa;YAC7BnD,aAAawD;YACbC,aAAa;QACf;QAEA,yCAAyC;QACzC,OAAOxD,kBAAkByB,MAAM9B,QAAQW,KAAK;IAC9C,EAAE,OAAOkB,OAAO;QACd,MAAMA;IACR,SAAU;QACR,IAAIgC,YAAY;YACd1D;QACF;IACF;AACF","ignoreList":[0]}
1
+ {"version":3,"sources":["../../../../src/build/next-config-ts/transpile-config.ts"],"sourcesContent":["import type { Options as SWCOptions } from '@swc/core'\nimport type { CompilerOptions } from 'typescript'\n\nimport { resolve } from 'node:path'\nimport { readFile } from 'node:fs/promises'\nimport { pathToFileURL } from 'node:url'\nimport { deregisterHook, registerHook, requireFromString } from './require-hook'\nimport { warn, warnOnce } from '../output/log'\nimport { installDependencies } from '../../lib/install-dependencies'\nimport { getNodeOptionsArgs } from '../../server/lib/utils'\n\nfunction resolveSWCOptions(\n cwd: string,\n compilerOptions: CompilerOptions\n): SWCOptions {\n return {\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n ...(compilerOptions.paths ? { paths: compilerOptions.paths } : {}),\n ...(compilerOptions.baseUrl\n ? // Needs to be an absolute path.\n { baseUrl: resolve(cwd, compilerOptions.baseUrl) }\n : compilerOptions.paths\n ? // If paths is given, baseUrl is required.\n { baseUrl: cwd }\n : {}),\n },\n module: {\n type: 'commonjs',\n },\n isModule: 'unknown',\n env: {\n targets: {\n // Setting the Node.js version can reduce unnecessary code generation.\n node: process?.versions?.node ?? '20.19.0',\n },\n },\n } satisfies SWCOptions\n}\n\n// Ported from next/src/lib/verify-typescript-setup.ts\n// Although this overlaps with the later `verifyTypeScriptSetup`,\n// it is acceptable since the time difference in the worst case is trivial,\n// as we are only preparing to install the dependencies once more.\nasync function verifyTypeScriptSetup(cwd: string, configFileName: string) {\n try {\n // Quick module check.\n require.resolve('typescript', { paths: [cwd] })\n } catch (error) {\n if (\n error &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n ) {\n warn(\n `Installing TypeScript as it was not found while loading \"${configFileName}\".`\n )\n\n await installDependencies(cwd, [{ pkg: 'typescript' }], true).catch(\n (err) => {\n if (err && typeof err === 'object' && 'command' in err) {\n console.error(\n `Failed to install TypeScript, please install it manually to continue:\\n` +\n (err as any).command +\n '\\n'\n )\n }\n throw err\n }\n )\n }\n }\n}\n\nasync function getTsConfig(cwd: string): Promise<CompilerOptions> {\n const ts: typeof import('typescript') = require(\n require.resolve('typescript', { paths: [cwd] })\n )\n\n // NOTE: This doesn't fully cover the edge case for setting\n // \"typescript.tsconfigPath\" in next config which is currently\n // a restriction.\n const tsConfigPath = ts.findConfigFile(\n cwd,\n ts.sys.fileExists,\n 'tsconfig.json'\n )\n\n if (!tsConfigPath) {\n // It is ok to not return ts.getDefaultCompilerOptions() because\n // we are only looking for paths and baseUrl from tsConfig.\n return {}\n }\n\n const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile)\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n cwd\n )\n\n return parsedCommandLine.options\n}\n\nexport async function transpileConfig({\n nextConfigPath,\n configFileName,\n cwd,\n}: {\n nextConfigPath: string\n configFileName: string\n cwd: string\n}) {\n try {\n // envs are passed to the workers and preserve the flag\n if (process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED === 'true') {\n try {\n // Node.js v22.10.0+\n // Value is 'strip' or 'transform' based on how the feature is enabled.\n // https://nodejs.org/api/process.html#processfeaturestypescript\n // TODO: Remove `as any` once we bump @types/node to v22.10.0+\n if ((process.features as any).typescript) {\n // Run import() here to catch errors and fallback to legacy resolution.\n return (await import(pathToFileURL(nextConfigPath).href)).default\n }\n\n if (\n getNodeOptionsArgs().includes('--no-experimental-strip-types') ||\n process.execArgv.includes('--no-experimental-strip-types')\n ) {\n warnOnce(\n `Skipped resolving \"${configFileName}\" using Node.js native TypeScript resolution because it was disabled by the \"--no-experimental-strip-types\" flag.` +\n ' Falling back to legacy resolution.' +\n ' Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#using-nodejs-native-typescript-resolver-for-nextconfigts'\n )\n }\n\n // Feature is not enabled, fallback to legacy resolution for current session.\n process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED = 'false'\n } catch (cause) {\n warnOnce(\n `Failed to import \"${configFileName}\" using Node.js native TypeScript resolution.` +\n ' Falling back to legacy resolution.' +\n ' Learn more: https://nextjs.org/docs/app/api-reference/config/typescript#using-nodejs-native-typescript-resolver-for-nextconfigts',\n { cause }\n )\n // Once failed, fallback to legacy resolution for current session.\n process.env.__NEXT_NODE_NATIVE_TS_LOADER_ENABLED = 'false'\n }\n }\n\n // Ensure TypeScript is installed to use the API.\n await verifyTypeScriptSetup(cwd, configFileName)\n const compilerOptions = await getTsConfig(cwd)\n\n return handleCJS({ cwd, nextConfigPath, compilerOptions })\n } catch (cause) {\n throw new Error(`Failed to transpile \"${configFileName}\".`, { cause })\n }\n}\n\nasync function handleCJS({\n cwd,\n nextConfigPath,\n compilerOptions,\n}: {\n cwd: string\n nextConfigPath: string\n compilerOptions: CompilerOptions\n}) {\n const swcOptions = resolveSWCOptions(cwd, compilerOptions)\n let hasRequire = false\n try {\n const nextConfigString = await readFile(nextConfigPath, 'utf8')\n // lazy require swc since it loads React before even setting NODE_ENV\n // resulting loading Development React on Production\n const { loadBindings } = require('../swc') as typeof import('../swc')\n const bindings = await loadBindings()\n const { code } = await bindings.transform(nextConfigString, swcOptions)\n\n // register require hook only if require exists\n if (code.includes('require(')) {\n registerHook(swcOptions)\n hasRequire = true\n }\n\n // filename & extension don't matter here\n const config = requireFromString(\n code,\n resolve(cwd, 'next.config.compiled.js')\n )\n // At this point we have already loaded the bindings without this configuration setting due to the `transform` call above.\n // Possibly we fell back to wasm in which case, it all works out but if not we need to warn\n // that the configuration was ignored.\n if (config?.experimental?.useWasmBinary && !bindings.isWasm) {\n warn(\n 'Using a next.config.ts file is incompatible with `experimental.useWasmBinary` unless ' +\n '`--experimental-next-config-strip-types` is also passed.\\nSetting `useWasmBinary` to `false'\n )\n config.experimental.useWasmBinary = false\n }\n return config\n } catch (error) {\n throw error\n } finally {\n if (hasRequire) {\n deregisterHook()\n }\n }\n}\n"],"names":["resolve","readFile","pathToFileURL","deregisterHook","registerHook","requireFromString","warn","warnOnce","installDependencies","getNodeOptionsArgs","resolveSWCOptions","cwd","compilerOptions","process","jsc","parser","syntax","paths","baseUrl","module","type","isModule","env","targets","node","versions","verifyTypeScriptSetup","configFileName","require","error","code","pkg","catch","err","console","command","getTsConfig","ts","tsConfigPath","findConfigFile","sys","fileExists","configFile","readConfigFile","parsedCommandLine","parseJsonConfigFileContent","config","options","transpileConfig","nextConfigPath","__NEXT_NODE_NATIVE_TS_LOADER_ENABLED","features","typescript","href","default","includes","execArgv","cause","handleCJS","Error","swcOptions","hasRequire","nextConfigString","loadBindings","bindings","transform","experimental","useWasmBinary","isWasm"],"mappings":"AAGA,SAASA,OAAO,QAAQ,YAAW;AACnC,SAASC,QAAQ,QAAQ,mBAAkB;AAC3C,SAASC,aAAa,QAAQ,WAAU;AACxC,SAASC,cAAc,EAAEC,YAAY,EAAEC,iBAAiB,QAAQ,iBAAgB;AAChF,SAASC,IAAI,EAAEC,QAAQ,QAAQ,gBAAe;AAC9C,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,kBAAkB,QAAQ,yBAAwB;AAE3D,SAASC,kBACPC,GAAW,EACXC,eAAgC;QAuBpBC,mBAAAA;IArBZ,OAAO;QACLC,KAAK;YACHC,QAAQ;gBACNC,QAAQ;YACV;YACA,GAAIJ,gBAAgBK,KAAK,GAAG;gBAAEA,OAAOL,gBAAgBK,KAAK;YAAC,IAAI,CAAC,CAAC;YACjE,GAAIL,gBAAgBM,OAAO,GAEvB;gBAAEA,SAASlB,QAAQW,KAAKC,gBAAgBM,OAAO;YAAE,IACjDN,gBAAgBK,KAAK,GAEnB;gBAAEC,SAASP;YAAI,IACf,CAAC,CAAC;QACV;QACAQ,QAAQ;YACNC,MAAM;QACR;QACAC,UAAU;QACVC,KAAK;YACHC,SAAS;gBACP,sEAAsE;gBACtEC,MAAMX,EAAAA,WAAAA,6BAAAA,oBAAAA,SAASY,QAAQ,qBAAjBZ,kBAAmBW,IAAI,KAAI;YACnC;QACF;IACF;AACF;AAEA,sDAAsD;AACtD,iEAAiE;AACjE,2EAA2E;AAC3E,kEAAkE;AAClE,eAAeE,sBAAsBf,GAAW,EAAEgB,cAAsB;IACtE,IAAI;QACF,sBAAsB;QACtBC,QAAQ5B,OAAO,CAAC,cAAc;YAAEiB,OAAO;gBAACN;aAAI;QAAC;IAC/C,EAAE,OAAOkB,OAAO;QACd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KAAKyB,QAAQ,CAAC,aAAa;YAC7BnD,aAAawD;YACbC,aAAa;QACf;QAEA,yCAAyC;QACzC,MAAMf,SAASzC,kBACbyB,MACA9B,QAAQW,KAAK;QAEf,0HAA0H;QAC1H,2FAA2F;QAC3F,sCAAsC;QACtC,IAAImC,CAAAA,2BAAAA,uBAAAA,OAAQoB,YAAY,qBAApBpB,qBAAsBqB,aAAa,KAAI,CAACH,SAASI,MAAM,EAAE;YAC3D9D,KACE,0FACE;YAEJwC,OAAOoB,YAAY,CAACC,aAAa,GAAG;QACtC;QACA,OAAOrB;IACT,EAAE,OAAOjB,OAAO;QACd,MAAMA;IACR,SAAU;QACR,IAAIgC,YAAY;YACd1D;QACF;IACF;AACF","ignoreList":[0]}
@@ -10,7 +10,7 @@ import { downloadNativeNextSwc, downloadWasmSwc } from '../../lib/download-swc';
10
10
  import { isDeepStrictEqual } from 'util';
11
11
  import { getDefineEnv } from '../define-env';
12
12
  import { throwTurbopackInternalError } from '../../shared/lib/turbopack/internal-error';
13
- const nextVersion = "16.0.2-canary.10";
13
+ const nextVersion = "16.0.2-canary.12";
14
14
  const ArchName = arch();
15
15
  const PlatformName = platform();
16
16
  function infoLog(...args) {
@@ -96,25 +96,42 @@ const knownDefaultWasmFallbackTriples = [
96
96
  // If node.js throws an error without error code, this should be `unknown` instead of undefined.
97
97
  // For the wasm-first targets (`knownDefaultWasmFallbackTriples`) this will be `unsupported_target`.
98
98
  let lastNativeBindingsLoadErrorCode = undefined;
99
- // Used to cache calls to `loadBindings`
99
+ // Used to cache racing calls to `loadBindings`
100
100
  let pendingBindings;
101
- // some things call `loadNative` directly instead of `loadBindings`... Cache calls to that
102
- // separately.
103
- let nativeBindings;
104
- // can allow hacky sync access to bindings for loadBindingsSync
105
- let wasmBindings;
101
+ // The cached loaded bindings
102
+ let loadedBindings = undefined;
106
103
  let downloadWasmPromise;
107
104
  let swcTraceFlushGuard;
108
105
  let downloadNativeBindingsPromise = undefined;
109
106
  export const lockfilePatchPromise = {};
107
+ /** Access the native bindings which should already have been loaded via `installBindings. Throws if they are not available. */ export function getBindingsSync() {
108
+ if (!loadedBindings) {
109
+ if (pendingBindings) {
110
+ throw Object.defineProperty(new Error('Bindings not loaded yet, but they are being loaded, did you forget to await?'), "__NEXT_ERROR_CODE", {
111
+ value: "E906",
112
+ enumerable: false,
113
+ configurable: true
114
+ });
115
+ }
116
+ throw Object.defineProperty(new Error('bindings not loaded yet. Either call `loadBindings` to wait for them to be available or ensure that `installBindings` has already been called.'), "__NEXT_ERROR_CODE", {
117
+ value: "E907",
118
+ enumerable: false,
119
+ configurable: true
120
+ });
121
+ }
122
+ return loadedBindings;
123
+ }
110
124
  /**
111
- * Attempts to load a native or wasm binding.
125
+ * Loads the native or wasm binding.
112
126
  *
113
127
  * By default, this first tries to use a native binding, falling back to a wasm binding if that
114
128
  * fails.
115
129
  *
116
130
  * This function is `async` as wasm requires an asynchronous import in browsers.
117
131
  */ export async function loadBindings(useWasmBinary = false) {
132
+ if (loadedBindings) {
133
+ return loadedBindings;
134
+ }
118
135
  if (pendingBindings) {
119
136
  return pendingBindings;
120
137
  }
@@ -187,7 +204,9 @@ export const lockfilePatchPromise = {};
187
204
  }
188
205
  logLoadFailure(attempts, true);
189
206
  });
190
- return pendingBindings;
207
+ loadedBindings = await pendingBindings;
208
+ pendingBindings = undefined;
209
+ return loadedBindings;
191
210
  }
192
211
  async function tryLoadNativeWithFallback(attempts) {
193
212
  const nativeBindingsDirectory = path.join(path.dirname(require.resolve('next/package.json')), 'next-swc-fallback');
@@ -248,11 +267,6 @@ function loadBindingsSync() {
248
267
  } catch (a) {
249
268
  attempts = attempts.concat(a);
250
269
  }
251
- // HACK: we can leverage the wasm bindings if they are already loaded
252
- // this may introduce race conditions
253
- if (wasmBindings) {
254
- return wasmBindings;
255
- }
256
270
  logLoadFailure(attempts);
257
271
  throw Object.defineProperty(new Error('Failed to load bindings', {
258
272
  cause: attempts
@@ -779,7 +793,7 @@ async function loadWasm(importPath = '') {
779
793
  }
780
794
  // Note wasm binary does not support async intefaces yet, all async
781
795
  // interface coereces to sync interfaces.
782
- wasmBindings = {
796
+ let wasmBindings = {
783
797
  css: {
784
798
  lightning: {
785
799
  transform: function(_options) {
@@ -900,8 +914,8 @@ async function loadWasm(importPath = '') {
900
914
  * Loads the native (non-wasm) bindings. Prefer `loadBindings` over this API, as that includes a
901
915
  * wasm fallback.
902
916
  */ function loadNative(importPath) {
903
- if (nativeBindings) {
904
- return nativeBindings;
917
+ if (loadedBindings) {
918
+ return loadedBindings;
905
919
  }
906
920
  if (process.env.NEXT_TEST_WASM) {
907
921
  throw Object.defineProperty(new Error('cannot run loadNative when `NEXT_TEST_WASM` is set'), "__NEXT_ERROR_CODE", {
@@ -950,7 +964,7 @@ async function loadWasm(importPath = '') {
950
964
  }
951
965
  }
952
966
  if (bindings) {
953
- nativeBindings = {
967
+ loadedBindings = {
954
968
  isWasm: false,
955
969
  transform (src, options) {
956
970
  var _options_jsc;
@@ -1049,7 +1063,7 @@ async function loadWasm(importPath = '') {
1049
1063
  return bindings.lockfileUnlockSync(lockfile);
1050
1064
  }
1051
1065
  };
1052
- return nativeBindings;
1066
+ return loadedBindings;
1053
1067
  }
1054
1068
  throw attempts;
1055
1069
  }
@@ -1066,41 +1080,32 @@ function getMdxOptions(options = {}) {
1066
1080
  function toBuffer(t) {
1067
1081
  return Buffer.from(JSON.stringify(t));
1068
1082
  }
1069
- export async function isWasm() {
1070
- let bindings = await loadBindings();
1071
- return bindings.isWasm;
1072
- }
1073
1083
  export async function transform(src, options) {
1074
- let bindings = await loadBindings();
1084
+ let bindings = getBindingsSync();
1075
1085
  return bindings.transform(src, options);
1076
1086
  }
1077
- export function transformSync(src, options) {
1078
- let bindings = loadBindingsSync();
1087
+ /** Synchronously transforms the source and loads the native bindings. */ export function transformSync(src, options) {
1088
+ const bindings = loadBindingsSync();
1079
1089
  return bindings.transformSync(src, options);
1080
1090
  }
1081
- export async function minify(src, options) {
1082
- let bindings = await loadBindings();
1091
+ export function minify(src, options) {
1092
+ const bindings = getBindingsSync();
1083
1093
  return bindings.minify(src, options);
1084
1094
  }
1085
- export async function isReactCompilerRequired(filename) {
1086
- let bindings = await loadBindings();
1095
+ export function isReactCompilerRequired(filename) {
1096
+ const bindings = getBindingsSync();
1087
1097
  return bindings.reactCompiler.isReactCompilerRequired(filename);
1088
1098
  }
1089
1099
  export async function parse(src, options) {
1090
- let bindings = await loadBindings();
1091
- let parserOptions = getParserOptions(options);
1092
- return bindings.parse(src, parserOptions).then((astStr)=>JSON.parse(astStr));
1100
+ const bindings = getBindingsSync();
1101
+ const parserOptions = getParserOptions(options);
1102
+ const parsed = await bindings.parse(src, parserOptions);
1103
+ return JSON.parse(parsed);
1093
1104
  }
1094
1105
  export function getBinaryMetadata() {
1095
- var _bindings_getTargetTriple;
1096
- let bindings;
1097
- try {
1098
- bindings = loadNative();
1099
- } catch (e) {
1100
- // Suppress exceptions, this fn allows to fail to load native bindings
1101
- }
1106
+ var _loadedBindings_getTargetTriple;
1102
1107
  return {
1103
- target: bindings == null ? void 0 : (_bindings_getTargetTriple = bindings.getTargetTriple) == null ? void 0 : _bindings_getTargetTriple.call(bindings)
1108
+ target: loadedBindings == null ? void 0 : (_loadedBindings_getTargetTriple = loadedBindings.getTargetTriple) == null ? void 0 : _loadedBindings_getTargetTriple.call(loadedBindings)
1104
1109
  };
1105
1110
  }
1106
1111
  /**
@@ -1108,9 +1113,9 @@ export function getBinaryMetadata() {
1108
1113
  *
1109
1114
  */ export function initCustomTraceSubscriber(traceFileName) {
1110
1115
  if (!swcTraceFlushGuard) {
1116
+ var _getBindingsSync_initCustomTraceSubscriber, _getBindingsSync;
1111
1117
  // Wasm binary doesn't support trace emission
1112
- let bindings = loadNative();
1113
- swcTraceFlushGuard = bindings.initCustomTraceSubscriber == null ? void 0 : bindings.initCustomTraceSubscriber.call(bindings, traceFileName);
1118
+ swcTraceFlushGuard = (_getBindingsSync_initCustomTraceSubscriber = (_getBindingsSync = getBindingsSync()).initCustomTraceSubscriber) == null ? void 0 : _getBindingsSync_initCustomTraceSubscriber.call(_getBindingsSync, traceFileName);
1114
1119
  }
1115
1120
  }
1116
1121
  function once(fn) {
@@ -1132,21 +1137,19 @@ function once(fn) {
1132
1137
  * instead parent process manually drops guard when process gets signal to exit.
1133
1138
  */ export const teardownTraceSubscriber = once(()=>{
1134
1139
  try {
1135
- let bindings = loadNative();
1136
1140
  if (swcTraceFlushGuard) {
1137
- bindings.teardownTraceSubscriber == null ? void 0 : bindings.teardownTraceSubscriber.call(bindings, swcTraceFlushGuard);
1141
+ var _getBindingsSync_teardownTraceSubscriber, _getBindingsSync;
1142
+ (_getBindingsSync_teardownTraceSubscriber = (_getBindingsSync = getBindingsSync()).teardownTraceSubscriber) == null ? void 0 : _getBindingsSync_teardownTraceSubscriber.call(_getBindingsSync, swcTraceFlushGuard);
1138
1143
  }
1139
1144
  } catch (e) {
1140
1145
  // Suppress exceptions, this fn allows to fail to load native bindings
1141
1146
  }
1142
1147
  });
1143
1148
  export async function getModuleNamedExports(resourcePath) {
1144
- const bindings = await loadBindings();
1145
- return bindings.rspack.getModuleNamedExports(resourcePath);
1149
+ return getBindingsSync().rspack.getModuleNamedExports(resourcePath);
1146
1150
  }
1147
1151
  export async function warnForEdgeRuntime(source, isProduction) {
1148
- const bindings = await loadBindings();
1149
- return bindings.rspack.warnForEdgeRuntime(source, isProduction);
1152
+ return getBindingsSync().rspack.warnForEdgeRuntime(source, isProduction);
1150
1153
  }
1151
1154
 
1152
1155
  //# sourceMappingURL=index.js.map