mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-14 09:37:18 +08:00
fix(@angular/build): invalidate com.chrome.devtools.json
if project is moved
Ensure that when a project is relocated, the `com.chrome.devtools.json` file is properly invalidated by checking the `root` path.
This commit is contained in:
parent
5ff4c28e7b
commit
5bea3de4cb
@ -6,18 +6,26 @@
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import assert from 'node:assert';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import type { Connect } from 'vite';
|
||||
|
||||
type DevToolsJson = {
|
||||
workspace: {
|
||||
root: string;
|
||||
uuid: string;
|
||||
};
|
||||
};
|
||||
|
||||
const CHROME_DEVTOOLS_ROUTE = '/.well-known/appspecific/com.chrome.devtools.json';
|
||||
|
||||
export function createChromeDevtoolsMiddleware(
|
||||
cacheDir: string,
|
||||
projectRoot: string,
|
||||
): Connect.NextHandleFunction {
|
||||
let devtoolsConfig: string;
|
||||
let devtoolsConfig: string | undefined;
|
||||
const devtoolsConfigPath = join(cacheDir, 'com.chrome.devtools.json');
|
||||
|
||||
return function chromeDevtoolsMiddleware(req, res, next) {
|
||||
@ -27,22 +35,27 @@ export function createChromeDevtoolsMiddleware(
|
||||
return;
|
||||
}
|
||||
|
||||
// We store the UUID and re-use it to ensure Chrome does not repeatedly ask for permissions when restarting the dev server.
|
||||
try {
|
||||
devtoolsConfig ??= readFileSync(devtoolsConfigPath, 'utf-8');
|
||||
} catch {
|
||||
const devtoolsConfigJson = {
|
||||
workspace: {
|
||||
root: projectRoot,
|
||||
uuid: randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
devtoolsConfig = JSON.stringify(devtoolsConfigJson, undefined, 2);
|
||||
if (!devtoolsConfig) {
|
||||
// We store the UUID and re-use it to ensure Chrome does not repeatedly ask for permissions when restarting the dev server.
|
||||
try {
|
||||
mkdirSync(cacheDir, { recursive: true });
|
||||
writeFileSync(devtoolsConfigPath, devtoolsConfig);
|
||||
} catch {}
|
||||
const devtoolsConfig = readFileSync(devtoolsConfigPath, 'utf-8');
|
||||
const devtoolsConfigJson: DevToolsJson = JSON.parse(devtoolsConfig);
|
||||
assert.equal(projectRoot, devtoolsConfigJson?.workspace.root);
|
||||
} catch {
|
||||
const devtoolsConfigJson: DevToolsJson = {
|
||||
workspace: {
|
||||
root: projectRoot,
|
||||
uuid: randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
devtoolsConfig = JSON.stringify(devtoolsConfigJson, undefined, 2);
|
||||
|
||||
try {
|
||||
mkdirSync(cacheDir, { recursive: true });
|
||||
writeFileSync(devtoolsConfigPath, devtoolsConfig);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
Loading…
x
Reference in New Issue
Block a user