Skip to content

Commit b0c33de

Browse files
committed
expand hot reload to cwd
1 parent ec69300 commit b0c33de

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

Diff for: .changeset/fuzzy-hotels-burn.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"htmldocs": patch
3+
"htmldocs-starter": patch
4+
---
5+
6+
expand hot refresh to cwd

Diff for: apps/examples/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
]
1010
}
1111
},
12-
"include": ["src/**/*", "documents/**/*", "index.ts"],
12+
"include": ["**/*"],
1313
"exclude": ["node_modules", "dist"]
1414
}
1515

Diff for: packages/htmldocs/public/template/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"esModuleInterop": true
1212
},
13-
"include": ["src/**/*", "documents/**/*", "index.ts"],
13+
"include": ["**/*"],
1414
"exclude": ["node_modules", "dist"]
1515
}

Diff for: packages/htmldocs/src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts

+36-18
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@ export const setupHotreloading = async (
2323
});
2424
});
2525

26+
const projectRoot = process.cwd();
2627
const absolutePathToDocumentsDirectory = path.resolve(
27-
process.cwd(),
28+
projectRoot,
2829
emailDirRelativePath,
2930
);
3031

31-
logger.info(`Watching ${absolutePathToDocumentsDirectory}`);
32+
logger.info(`Watching project root at ${projectRoot}`);
3233

33-
const watcher = watch('', {
34+
const watcher = watch('**/*', {
3435
ignoreInitial: true,
35-
cwd: absolutePathToDocumentsDirectory,
36+
cwd: projectRoot,
37+
ignored: [
38+
'**/node_modules/**',
39+
'**/.git/**',
40+
'**/dist/**',
41+
'**/build/**',
42+
'**/.next/**',
43+
'**/coverage/**',
44+
],
3645
});
3746

3847
const exit = () => {
@@ -96,25 +105,34 @@ export const setupHotreloading = async (
96105

97106
logger.debug(`Detected ${event} in ${relativePathToChangeTarget}`);
98107

99-
const pathToChangeTarget = path.resolve(
100-
absolutePathToDocumentsDirectory,
101-
relativePathToChangeTarget,
102-
);
103-
await updateDependencyGraph(event, pathToChangeTarget);
108+
// Convert the path to be relative to the documents directory if it's within it
109+
const absolutePathToChangeTarget = path.resolve(projectRoot, relativePathToChangeTarget);
110+
const isInDocumentsDirectory = absolutePathToChangeTarget.startsWith(absolutePathToDocumentsDirectory);
111+
112+
if (isInDocumentsDirectory) {
113+
const pathRelativeToDocuments = path.relative(absolutePathToDocumentsDirectory, absolutePathToChangeTarget);
114+
115+
await updateDependencyGraph(event, absolutePathToChangeTarget);
104116

105-
changes.push({
106-
event,
107-
filename: relativePathToChangeTarget,
108-
});
117+
changes.push({
118+
event,
119+
filename: pathRelativeToDocuments,
120+
});
109121

110-
// These dependents are dependents resolved recursively, so even dependents of dependents
111-
// will be notified of this change so that we ensure that things are updated in the preview.
112-
for (const dependentPath of resolveDependentsOf(pathToChangeTarget)) {
122+
for (const dependentPath of resolveDependentsOf(absolutePathToChangeTarget)) {
123+
changes.push({
124+
event: 'change' as const,
125+
filename: path.relative(absolutePathToDocumentsDirectory, dependentPath),
126+
});
127+
}
128+
} else {
129+
// For files outside documents directory, just notify of the change relative to project root
113130
changes.push({
114-
event: 'change' as const,
115-
filename: path.relative(absolutePathToDocumentsDirectory, dependentPath),
131+
event,
132+
filename: relativePathToChangeTarget,
116133
});
117134
}
135+
118136
reload();
119137
});
120138

0 commit comments

Comments
 (0)