@content-collections/core 0.9.1 → 0.10.0
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/index.js +52 -30
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -519,6 +519,9 @@ function posixToNativePath(pathName) {
|
|
|
519
519
|
}
|
|
520
520
|
return pathName;
|
|
521
521
|
}
|
|
522
|
+
function toError(error) {
|
|
523
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
524
|
+
}
|
|
522
525
|
|
|
523
526
|
// src/collector.ts
|
|
524
527
|
var CollectError = class extends Error {
|
|
@@ -636,6 +639,8 @@ function createSynchronizer(readCollectionFile, collections, baseDirectory = "."
|
|
|
636
639
|
};
|
|
637
640
|
}).filter(({ collection, relativePath }) => {
|
|
638
641
|
return picomatch.isMatch(relativePath, collection.include, {
|
|
642
|
+
// @see https://github.com/sdorra/content-collections/issues/602
|
|
643
|
+
windows: process.platform === "win32",
|
|
639
644
|
ignore: collection.exclude
|
|
640
645
|
});
|
|
641
646
|
});
|
|
@@ -1113,41 +1118,58 @@ function createEmitter() {
|
|
|
1113
1118
|
}
|
|
1114
1119
|
|
|
1115
1120
|
// src/watcher.ts
|
|
1116
|
-
import
|
|
1121
|
+
import chokidar from "chokidar";
|
|
1117
1122
|
import path8, { dirname as dirname3, resolve } from "node:path";
|
|
1118
1123
|
async function createWatcher(emitter, baseDirectory, configuration, sync) {
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1124
|
+
const paths = removeChildPaths([
|
|
1125
|
+
...configuration.collections.map((collection) => path8.join(baseDirectory, collection.directory)).map((p) => resolve(p)),
|
|
1126
|
+
...configuration.inputPaths.map((p) => dirname3(p))
|
|
1127
|
+
]);
|
|
1128
|
+
const watcher = chokidar.watch(paths, {
|
|
1129
|
+
ignored: [
|
|
1130
|
+
/(^|[\/\\])\../,
|
|
1131
|
+
// ignore dotfiles
|
|
1132
|
+
/(^|[\/\\])node_modules([\/\\]|$)/
|
|
1133
|
+
// ignore node_modules
|
|
1134
|
+
],
|
|
1135
|
+
persistent: true,
|
|
1136
|
+
ignoreInitial: true
|
|
1137
|
+
// ignore initial add events
|
|
1138
|
+
});
|
|
1139
|
+
const handleEvent = async (modification, filePath) => {
|
|
1140
|
+
try {
|
|
1141
|
+
await sync(modification, filePath);
|
|
1142
|
+
} catch (error) {
|
|
1121
1143
|
emitter.emit("watcher:subscribe-error", {
|
|
1122
1144
|
paths,
|
|
1123
|
-
error
|
|
1145
|
+
error: toError(error)
|
|
1124
1146
|
});
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
for (const event of events) {
|
|
1128
|
-
await sync(event.type, event.path);
|
|
1129
1147
|
}
|
|
1130
1148
|
};
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1149
|
+
watcher.on("add", (filePath) => handleEvent("create", filePath));
|
|
1150
|
+
watcher.on("change", (filePath) => handleEvent("update", filePath));
|
|
1151
|
+
watcher.on("unlink", (filePath) => handleEvent("delete", filePath));
|
|
1152
|
+
watcher.on("error", (error) => {
|
|
1153
|
+
emitter.emit("watcher:subscribe-error", {
|
|
1154
|
+
paths,
|
|
1155
|
+
error: toError(error)
|
|
1156
|
+
});
|
|
1157
|
+
});
|
|
1158
|
+
await new Promise((resolve2, reject) => {
|
|
1159
|
+
watcher.on("ready", () => {
|
|
1160
|
+
emitter.emit("watcher:subscribed", {
|
|
1161
|
+
paths
|
|
1162
|
+
});
|
|
1163
|
+
resolve2();
|
|
1164
|
+
});
|
|
1165
|
+
watcher.on("error", reject);
|
|
1138
1166
|
});
|
|
1139
1167
|
return {
|
|
1140
1168
|
unsubscribe: async () => {
|
|
1141
|
-
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
await Promise.all(
|
|
1145
|
-
subscriptions.map((subscription) => subscription.unsubscribe())
|
|
1146
|
-
);
|
|
1169
|
+
await watcher.close();
|
|
1147
1170
|
emitter.emit("watcher:unsubscribed", {
|
|
1148
1171
|
paths
|
|
1149
1172
|
});
|
|
1150
|
-
return;
|
|
1151
1173
|
}
|
|
1152
1174
|
};
|
|
1153
1175
|
}
|
|
@@ -1176,7 +1198,7 @@ async function createBuilder(configurationPath, options = {
|
|
|
1176
1198
|
outputDirectory
|
|
1177
1199
|
});
|
|
1178
1200
|
let configuration = await readConfiguration(configurationPath, options);
|
|
1179
|
-
let
|
|
1201
|
+
let watcher = null;
|
|
1180
1202
|
let context2 = await createBuildContext({
|
|
1181
1203
|
emitter,
|
|
1182
1204
|
baseDirectory,
|
|
@@ -1217,8 +1239,8 @@ async function createBuilder(configurationPath, options = {
|
|
|
1217
1239
|
});
|
|
1218
1240
|
return false;
|
|
1219
1241
|
}
|
|
1220
|
-
if (
|
|
1221
|
-
await
|
|
1242
|
+
if (watcher) {
|
|
1243
|
+
await watcher.unsubscribe();
|
|
1222
1244
|
}
|
|
1223
1245
|
context2 = await createBuildContext({
|
|
1224
1246
|
emitter,
|
|
@@ -1226,8 +1248,8 @@ async function createBuilder(configurationPath, options = {
|
|
|
1226
1248
|
outputDirectory,
|
|
1227
1249
|
configuration
|
|
1228
1250
|
});
|
|
1229
|
-
if (
|
|
1230
|
-
|
|
1251
|
+
if (watcher) {
|
|
1252
|
+
watcher = await createWatcher(
|
|
1231
1253
|
emitter,
|
|
1232
1254
|
baseDirectory,
|
|
1233
1255
|
configuration,
|
|
@@ -1245,11 +1267,11 @@ async function createBuilder(configurationPath, options = {
|
|
|
1245
1267
|
}
|
|
1246
1268
|
}
|
|
1247
1269
|
async function watch() {
|
|
1248
|
-
|
|
1270
|
+
watcher = await createWatcher(emitter, baseDirectory, configuration, sync);
|
|
1249
1271
|
return {
|
|
1250
1272
|
unsubscribe: async () => {
|
|
1251
|
-
if (
|
|
1252
|
-
await
|
|
1273
|
+
if (watcher) {
|
|
1274
|
+
await watcher.unsubscribe();
|
|
1253
1275
|
}
|
|
1254
1276
|
}
|
|
1255
1277
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-collections/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "Core of Content Collections",
|
|
6
6
|
"author": "Sebastian Sdorra <s.sdorra@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"vitest": "^3.1.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@parcel/watcher": "^2.4.1",
|
|
45
44
|
"@standard-schema/spec": "^1.0.0",
|
|
46
45
|
"camelcase": "^8.0.0",
|
|
46
|
+
"chokidar": "^4.0.3",
|
|
47
47
|
"esbuild": "^0.25.0",
|
|
48
48
|
"gray-matter": "^4.0.3",
|
|
49
49
|
"p-limit": "^6.1.0",
|