@clerk/dev-cli 0.0.11 → 0.0.12-canary.v20250625143934

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerk/dev-cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12-canary.v20250625143934",
4
4
  "description": "CLI tool designed to simplify the process of iterating on packages within the clerk/javascript repository",
5
5
  "homepage": "https://clerk.com/",
6
6
  "bugs": {
@@ -1,15 +1,16 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { readFile, writeFile } from 'node:fs/promises';
4
- import { join } from 'node:path';
4
+ import path, { join } from 'node:path';
5
5
 
6
6
  import { parse } from 'dotenv';
7
7
 
8
8
  import { applyCodemod } from '../codemods/index.js';
9
- import { INVALID_INSTANCE_KEYS_ERROR } from '../utils/errors.js';
9
+ import { INVALID_INSTANCE_KEYS_ERROR, NULL_ROOT_ERROR } from '../utils/errors.js';
10
10
  import { getClerkPackages } from '../utils/getClerkPackages.js';
11
11
  import { getConfiguration } from '../utils/getConfiguration.js';
12
- import { getDependencies } from '../utils/getDependencies.js';
12
+ import { getMonorepoRoot } from '../utils/getMonorepoRoot.js';
13
+ import { getPackageJSON } from '../utils/getPackageJSON.js';
13
14
 
14
15
  /**
15
16
  * Returns `true` if the cwd contains a file named `filename`, otherwise returns `false`.
@@ -35,11 +36,11 @@ function hasPackage(packages, dependency) {
35
36
 
36
37
  /**
37
38
  * Returns a string corresponding to the framework detected in the cwd.
38
- * @returns {Promise<string>}
39
+ * @param {{ dependencies?: Record<string, string>, devDependencies?: Record<string, string>}} pkgJSON
40
+ * @returns {string}
39
41
  */
40
- async function detectFramework() {
41
- const { dependencies, devDependencies } = await getDependencies(join(process.cwd(), 'package.json'));
42
-
42
+ function detectFramework(pkgJSON) {
43
+ const { dependencies, devDependencies } = pkgJSON;
43
44
  const IS_NEXT = hasPackage(dependencies, 'next');
44
45
  if (IS_NEXT) {
45
46
  return 'nextjs';
@@ -58,6 +59,36 @@ async function detectFramework() {
58
59
  throw new Error('unable to determine framework');
59
60
  }
60
61
 
62
+ /**
63
+ * Returns the output file tracing root for the current working directory.
64
+ * @returns {Promise<string | null>}
65
+ */
66
+ async function getOutputFileTracingRoot() {
67
+ const monorepoRoot = await getMonorepoRoot();
68
+ if (!monorepoRoot) {
69
+ throw new Error(NULL_ROOT_ERROR);
70
+ }
71
+ const p1 = path.resolve(monorepoRoot);
72
+ const p2 = path.resolve(process.cwd());
73
+
74
+ const root1 = path.parse(p1).root;
75
+ const root2 = path.parse(p2).root;
76
+
77
+ if (root1 !== root2) return null;
78
+
79
+ const parts1 = p1.slice(root1.length).split(path.sep);
80
+ const parts2 = p2.slice(root2.length).split(path.sep);
81
+
82
+ const len = Math.min(parts1.length, parts2.length);
83
+ const common = [];
84
+ for (let i = 0; i < len; i++) {
85
+ if (parts1[i] === parts2[i]) common.push(parts1[i]);
86
+ else break;
87
+ }
88
+
89
+ return common.length ? path.join(root1, ...common) : root1;
90
+ }
91
+
61
92
  /**
62
93
  * Returns the active instance of the provided `configuration`.
63
94
  * @param {import('../utils/getConfiguration.js').Configuration} configuration
@@ -161,7 +192,7 @@ async function importPackageLock() {
161
192
  * @returns {Promise<void>}
162
193
  */
163
194
  async function linkDependencies() {
164
- const { dependencies } = await getDependencies(join(process.cwd(), 'package.json'));
195
+ const { dependencies } = await getPackageJSON(join(process.cwd(), 'package.json'));
165
196
  if (!dependencies) {
166
197
  throw new Error('you have no dependencies');
167
198
  }
@@ -208,7 +239,9 @@ export async function setup({ js = true, skipInstall = false }) {
208
239
  const config = await getConfiguration();
209
240
  const instance = await getInstanceConfiguration(config);
210
241
 
211
- const framework = await detectFramework();
242
+ const pkgJSON = await getPackageJSON(join(process.cwd(), 'package.json'));
243
+
244
+ const framework = detectFramework(pkgJSON);
212
245
  switch (framework) {
213
246
  case 'nextjs': {
214
247
  console.log('Next.js detected, writing environment variables to .env.local...');
@@ -217,6 +250,13 @@ export async function setup({ js = true, skipInstall = false }) {
217
250
  CLERK_SECRET_KEY: instance.secretKey,
218
251
  ...(js ? { NEXT_PUBLIC_CLERK_JS_URL: 'http://localhost:4000/npm/clerk.browser.js' } : {}),
219
252
  });
253
+
254
+ if (pkgJSON.scripts?.dev && pkgJSON.scripts.dev.includes('--turbo')) {
255
+ const outputFileTracingRoot = await getOutputFileTracingRoot();
256
+ console.warn(
257
+ `\n\x1b[43m\x1b[30m Heads up! \x1b[0m Your \`dev\` script is using Turbopack. You will need to set the \`outputFileTracingRoot\` in your \`next.config.mjs\` file to "${outputFileTracingRoot}".\n`,
258
+ );
259
+ }
220
260
  break;
221
261
  }
222
262
  case 'remix': {
@@ -4,8 +4,8 @@ import concurrently from 'concurrently';
4
4
 
5
5
  import { NULL_ROOT_ERROR } from '../utils/errors.js';
6
6
  import { getClerkPackages } from '../utils/getClerkPackages.js';
7
- import { getDependencies } from '../utils/getDependencies.js';
8
7
  import { getMonorepoRoot } from '../utils/getMonorepoRoot.js';
8
+ import { getPackageJSON } from '../utils/getPackageJSON.js';
9
9
 
10
10
  /**
11
11
  * Starts long-running watchers for Clerk dependencies.
@@ -14,7 +14,7 @@ import { getMonorepoRoot } from '../utils/getMonorepoRoot.js';
14
14
  * @returns {Promise<import('concurrently').CloseEvent[]>}
15
15
  */
16
16
  export async function watch({ js }) {
17
- const { dependencies, devDependencies } = await getDependencies(join(process.cwd(), 'package.json'));
17
+ const { dependencies, devDependencies } = await getPackageJSON(join(process.cwd(), 'package.json'));
18
18
  const clerkPackages = Object.keys(await getClerkPackages());
19
19
 
20
20
  const packagesInPackageJSON = [...Object.keys(dependencies ?? {}), ...Object.keys(devDependencies ?? {})];
@@ -0,0 +1,11 @@
1
+ import { readFile } from 'node:fs/promises';
2
+
3
+ /**
4
+ * Gets the contents of the provided package.json.
5
+ * @param {string} pathToPackageJSON
6
+ * @returns {Promise<{ scripts?: Record<string, string>, dependencies?: Record<string, string>, devDependencies?: Record<string, string>}>}
7
+ */
8
+ export async function getPackageJSON(pathToPackageJSON) {
9
+ const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
10
+ return JSON.parse(packageJSON);
11
+ }
@@ -1,12 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
-
3
- /**
4
- * Gets the `dependencies` and `devDependencies` entries of the provided package.json.
5
- * @param {string} pathToPackageJSON
6
- * @returns {Promise<{ dependencies?: Record<string, string>, devDependencies?: Record<string, string>}>}
7
- */
8
- export async function getDependencies(pathToPackageJSON) {
9
- const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
10
- const { dependencies, devDependencies } = JSON.parse(packageJSON);
11
- return { dependencies, devDependencies };
12
- }