@jsenv/core 39.9.0 → 39.9.2
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/dist/jsenv_core.js
CHANGED
|
@@ -11516,44 +11516,94 @@ const watchSourceFiles = (
|
|
|
11516
11516
|
// But some project might want to use their root directory as source directory
|
|
11517
11517
|
// In that case source directory might contain files matching "node_modules/*" or ".git/*"
|
|
11518
11518
|
// And jsenv should not consider these as source files and watch them (to not hurt performances)
|
|
11519
|
-
const watchPatterns = {
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11519
|
+
const watchPatterns = {};
|
|
11520
|
+
const addDirectoryToWatch = (directoryUrlRelativeToRoot) => {
|
|
11521
|
+
Object.assign(watchPatterns, {
|
|
11522
|
+
[`${directoryUrlRelativeToRoot}**/*`]: true, // by default watch everything inside the source directory
|
|
11523
|
+
// line below is commented until @jsenv/url-meta fixes the fact that is matches
|
|
11524
|
+
// any file with an extension
|
|
11525
|
+
[`${directoryUrlRelativeToRoot}**/.*`]: false, // file starting with a dot -> do not watch
|
|
11526
|
+
[`${directoryUrlRelativeToRoot}**/.*/`]: false, // directory starting with a dot -> do not watch
|
|
11527
|
+
[`${directoryUrlRelativeToRoot}**/node_modules/`]: false, // node_modules directory -> do not watch
|
|
11528
|
+
});
|
|
11529
|
+
for (const key of Object.keys(sourceFileConfig)) {
|
|
11530
|
+
watchPatterns[`${directoryUrlRelativeToRoot}${key}`] =
|
|
11531
|
+
sourceFileConfig[key];
|
|
11532
|
+
}
|
|
11533
|
+
};
|
|
11534
|
+
const watch = (rootDirectoryUrl) => {
|
|
11535
|
+
const stopWatchingSourceFiles = registerDirectoryLifecycle(
|
|
11536
|
+
rootDirectoryUrl,
|
|
11537
|
+
{
|
|
11538
|
+
watchPatterns,
|
|
11539
|
+
cooldownBetweenFileEvents,
|
|
11540
|
+
keepProcessAlive,
|
|
11541
|
+
recursive: true,
|
|
11542
|
+
added: ({ relativeUrl }) => {
|
|
11543
|
+
callback({
|
|
11544
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
11545
|
+
event: "added",
|
|
11546
|
+
});
|
|
11547
|
+
},
|
|
11548
|
+
updated: ({ relativeUrl }) => {
|
|
11549
|
+
callback({
|
|
11550
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
11551
|
+
event: "modified",
|
|
11552
|
+
});
|
|
11553
|
+
},
|
|
11554
|
+
removed: ({ relativeUrl }) => {
|
|
11555
|
+
callback({
|
|
11556
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
11557
|
+
event: "removed",
|
|
11558
|
+
});
|
|
11559
|
+
},
|
|
11552
11560
|
},
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11561
|
+
);
|
|
11562
|
+
stopWatchingSourceFiles.watchPatterns = watchPatterns;
|
|
11563
|
+
return stopWatchingSourceFiles;
|
|
11564
|
+
};
|
|
11565
|
+
|
|
11566
|
+
npm_workspaces: {
|
|
11567
|
+
const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
|
|
11568
|
+
let packageContent;
|
|
11569
|
+
try {
|
|
11570
|
+
packageContent = JSON.parse(
|
|
11571
|
+
readFileSync(new URL("package.json", packageDirectoryUrl), "utf8"),
|
|
11572
|
+
);
|
|
11573
|
+
} catch {
|
|
11574
|
+
break npm_workspaces;
|
|
11575
|
+
}
|
|
11576
|
+
const { workspaces } = packageContent;
|
|
11577
|
+
if (!workspaces || !Array.isArray(workspaces) || workspaces.length === 0) {
|
|
11578
|
+
break npm_workspaces;
|
|
11579
|
+
}
|
|
11580
|
+
for (const workspace of workspaces) {
|
|
11581
|
+
if (workspace.endsWith("*")) {
|
|
11582
|
+
const workspaceRelativeUrl = urlToRelativeUrl(
|
|
11583
|
+
new URL(workspace.slice(0, -1), packageDirectoryUrl),
|
|
11584
|
+
packageDirectoryUrl,
|
|
11585
|
+
);
|
|
11586
|
+
addDirectoryToWatch(workspaceRelativeUrl);
|
|
11587
|
+
} else {
|
|
11588
|
+
const workspaceRelativeUrl = urlToRelativeUrl(
|
|
11589
|
+
new URL(workspace, packageDirectoryUrl),
|
|
11590
|
+
packageDirectoryUrl,
|
|
11591
|
+
);
|
|
11592
|
+
addDirectoryToWatch(workspaceRelativeUrl);
|
|
11593
|
+
}
|
|
11594
|
+
}
|
|
11595
|
+
// we are updating the root directory
|
|
11596
|
+
// we must make the patterns relative to source directory relative to the new root directory
|
|
11597
|
+
const sourceRelativeToPackage = urlToRelativeUrl(
|
|
11598
|
+
sourceDirectoryUrl,
|
|
11599
|
+
packageDirectoryUrl,
|
|
11600
|
+
);
|
|
11601
|
+
addDirectoryToWatch(sourceRelativeToPackage);
|
|
11602
|
+
return watch(packageDirectoryUrl);
|
|
11603
|
+
}
|
|
11604
|
+
|
|
11605
|
+
addDirectoryToWatch("");
|
|
11606
|
+
return watch(sourceDirectoryUrl);
|
|
11557
11607
|
};
|
|
11558
11608
|
|
|
11559
11609
|
const jsenvCoreDirectoryUrl = new URL("../", import.meta.url);
|
|
@@ -17634,10 +17684,17 @@ const jsenvPluginInlineContentFetcher = () => {
|
|
|
17634
17684
|
}
|
|
17635
17685
|
let isDirectRequestToFile;
|
|
17636
17686
|
if (urlInfo.context.request) {
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17687
|
+
let requestResource = urlInfo.context.request.resource;
|
|
17688
|
+
let requestedUrl;
|
|
17689
|
+
if (requestResource.startsWith("/@fs/")) {
|
|
17690
|
+
const fsRootRelativeUrl = requestResource.slice("/@fs/".length);
|
|
17691
|
+
requestedUrl = `file:///${fsRootRelativeUrl}`;
|
|
17692
|
+
} else {
|
|
17693
|
+
requestedUrl = new URL(
|
|
17694
|
+
requestResource.slice(1),
|
|
17695
|
+
urlInfo.context.rootDirectoryUrl,
|
|
17696
|
+
).href;
|
|
17697
|
+
}
|
|
17641
17698
|
isDirectRequestToFile = requestedUrl === urlInfo.url;
|
|
17642
17699
|
}
|
|
17643
17700
|
/*
|
package/package.json
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { registerDirectoryLifecycle } from "@jsenv/filesystem";
|
|
2
|
+
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { lookupPackageDirectory } from "./lookup_package_directory.js";
|
|
2
5
|
|
|
3
6
|
export const watchSourceFiles = (
|
|
4
7
|
sourceDirectoryUrl,
|
|
@@ -11,42 +14,92 @@ export const watchSourceFiles = (
|
|
|
11
14
|
// But some project might want to use their root directory as source directory
|
|
12
15
|
// In that case source directory might contain files matching "node_modules/*" or ".git/*"
|
|
13
16
|
// And jsenv should not consider these as source files and watch them (to not hurt performances)
|
|
14
|
-
const watchPatterns = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const watchPatterns = {};
|
|
18
|
+
const addDirectoryToWatch = (directoryUrlRelativeToRoot) => {
|
|
19
|
+
Object.assign(watchPatterns, {
|
|
20
|
+
[`${directoryUrlRelativeToRoot}**/*`]: true, // by default watch everything inside the source directory
|
|
21
|
+
// line below is commented until @jsenv/url-meta fixes the fact that is matches
|
|
22
|
+
// any file with an extension
|
|
23
|
+
[`${directoryUrlRelativeToRoot}**/.*`]: false, // file starting with a dot -> do not watch
|
|
24
|
+
[`${directoryUrlRelativeToRoot}**/.*/`]: false, // directory starting with a dot -> do not watch
|
|
25
|
+
[`${directoryUrlRelativeToRoot}**/node_modules/`]: false, // node_modules directory -> do not watch
|
|
26
|
+
});
|
|
27
|
+
for (const key of Object.keys(sourceFileConfig)) {
|
|
28
|
+
watchPatterns[`${directoryUrlRelativeToRoot}${key}`] =
|
|
29
|
+
sourceFileConfig[key];
|
|
30
|
+
}
|
|
22
31
|
};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const watch = (rootDirectoryUrl) => {
|
|
33
|
+
const stopWatchingSourceFiles = registerDirectoryLifecycle(
|
|
34
|
+
rootDirectoryUrl,
|
|
35
|
+
{
|
|
36
|
+
watchPatterns,
|
|
37
|
+
cooldownBetweenFileEvents,
|
|
38
|
+
keepProcessAlive,
|
|
39
|
+
recursive: true,
|
|
40
|
+
added: ({ relativeUrl }) => {
|
|
41
|
+
callback({
|
|
42
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
43
|
+
event: "added",
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
updated: ({ relativeUrl }) => {
|
|
47
|
+
callback({
|
|
48
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
49
|
+
event: "modified",
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
removed: ({ relativeUrl }) => {
|
|
53
|
+
callback({
|
|
54
|
+
url: new URL(relativeUrl, rootDirectoryUrl).href,
|
|
55
|
+
event: "removed",
|
|
56
|
+
});
|
|
57
|
+
},
|
|
35
58
|
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
);
|
|
60
|
+
stopWatchingSourceFiles.watchPatterns = watchPatterns;
|
|
61
|
+
return stopWatchingSourceFiles;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
npm_workspaces: {
|
|
65
|
+
const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
|
|
66
|
+
let packageContent;
|
|
67
|
+
try {
|
|
68
|
+
packageContent = JSON.parse(
|
|
69
|
+
readFileSync(new URL("package.json", packageDirectoryUrl), "utf8"),
|
|
70
|
+
);
|
|
71
|
+
} catch {
|
|
72
|
+
break npm_workspaces;
|
|
73
|
+
}
|
|
74
|
+
const { workspaces } = packageContent;
|
|
75
|
+
if (!workspaces || !Array.isArray(workspaces) || workspaces.length === 0) {
|
|
76
|
+
break npm_workspaces;
|
|
77
|
+
}
|
|
78
|
+
for (const workspace of workspaces) {
|
|
79
|
+
if (workspace.endsWith("*")) {
|
|
80
|
+
const workspaceRelativeUrl = urlToRelativeUrl(
|
|
81
|
+
new URL(workspace.slice(0, -1), packageDirectoryUrl),
|
|
82
|
+
packageDirectoryUrl,
|
|
83
|
+
);
|
|
84
|
+
addDirectoryToWatch(workspaceRelativeUrl);
|
|
85
|
+
} else {
|
|
86
|
+
const workspaceRelativeUrl = urlToRelativeUrl(
|
|
87
|
+
new URL(workspace, packageDirectoryUrl),
|
|
88
|
+
packageDirectoryUrl,
|
|
89
|
+
);
|
|
90
|
+
addDirectoryToWatch(workspaceRelativeUrl);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// we are updating the root directory
|
|
94
|
+
// we must make the patterns relative to source directory relative to the new root directory
|
|
95
|
+
const sourceRelativeToPackage = urlToRelativeUrl(
|
|
96
|
+
sourceDirectoryUrl,
|
|
97
|
+
packageDirectoryUrl,
|
|
98
|
+
);
|
|
99
|
+
addDirectoryToWatch(sourceRelativeToPackage);
|
|
100
|
+
return watch(packageDirectoryUrl);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
addDirectoryToWatch("");
|
|
104
|
+
return watch(sourceDirectoryUrl);
|
|
52
105
|
};
|
|
@@ -43,10 +43,17 @@ const jsenvPluginInlineContentFetcher = () => {
|
|
|
43
43
|
}
|
|
44
44
|
let isDirectRequestToFile;
|
|
45
45
|
if (urlInfo.context.request) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
let requestResource = urlInfo.context.request.resource;
|
|
47
|
+
let requestedUrl;
|
|
48
|
+
if (requestResource.startsWith("/@fs/")) {
|
|
49
|
+
const fsRootRelativeUrl = requestResource.slice("/@fs/".length);
|
|
50
|
+
requestedUrl = `file:///${fsRootRelativeUrl}`;
|
|
51
|
+
} else {
|
|
52
|
+
requestedUrl = new URL(
|
|
53
|
+
requestResource.slice(1),
|
|
54
|
+
urlInfo.context.rootDirectoryUrl,
|
|
55
|
+
).href;
|
|
56
|
+
}
|
|
50
57
|
isDirectRequestToFile = requestedUrl === urlInfo.url;
|
|
51
58
|
}
|
|
52
59
|
/*
|