@content-collections/core 0.14.0 → 0.14.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/index.js +36 -21
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import fs2 from "fs";
|
|
|
8
8
|
import path2 from "path";
|
|
9
9
|
import { build } from "esbuild";
|
|
10
10
|
import { createRequire } from "module";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
11
12
|
import matter from "gray-matter";
|
|
12
13
|
import { parse, stringify } from "yaml";
|
|
13
14
|
import camelcase from "camelcase";
|
|
@@ -23,10 +24,8 @@ import chokidar from "chokidar";
|
|
|
23
24
|
function createKey(config$1, input, key) {
|
|
24
25
|
return createHash("sha256").update(config$1).update(JSON.stringify(input)).update(key).digest("hex");
|
|
25
26
|
}
|
|
26
|
-
async function createCacheDirectory(
|
|
27
|
-
const cacheDirectory = path.join(directory, ".content-collections", "cache");
|
|
27
|
+
async function createCacheDirectory(cacheDirectory) {
|
|
28
28
|
if (!existsSync(cacheDirectory)) await mkdir(cacheDirectory, { recursive: true });
|
|
29
|
-
return cacheDirectory;
|
|
30
29
|
}
|
|
31
30
|
function fileName(input) {
|
|
32
31
|
return input.replace(/[^a-z0-9]/gi, "_").toLowerCase();
|
|
@@ -39,8 +38,8 @@ async function readMapping(mappingPath) {
|
|
|
39
38
|
}
|
|
40
39
|
return {};
|
|
41
40
|
}
|
|
42
|
-
async function createCacheManager(
|
|
43
|
-
|
|
41
|
+
async function createCacheManager(cacheDirectory, configChecksum) {
|
|
42
|
+
await createCacheDirectory(cacheDirectory);
|
|
44
43
|
const mappingPath = join(cacheDirectory, "mapping.json");
|
|
45
44
|
const mapping = await readMapping(mappingPath);
|
|
46
45
|
async function flush() {
|
|
@@ -249,7 +248,7 @@ var loadTsConfigInternal = (dir = process.cwd(), name = "tsconfig.json", isExten
|
|
|
249
248
|
var loadTsConfig = (dir, name) => loadTsConfigInternal(dir, name);
|
|
250
249
|
|
|
251
250
|
//#endregion
|
|
252
|
-
//#region ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.
|
|
251
|
+
//#region ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.12/node_modules/bundle-require/dist/index.js
|
|
253
252
|
var tsconfigPathsToRegExp = (paths) => {
|
|
254
253
|
return Object.keys(paths || {}).map((key) => {
|
|
255
254
|
return /* @__PURE__ */ new RegExp(`^${key.replace(/\*/, ".*")}$`);
|
|
@@ -274,14 +273,21 @@ const NON_NODE_MODULE_RE = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
|
274
273
|
function isCoreImport(path$1, kind) {
|
|
275
274
|
return path$1 === "@content-collections/core" && kind === "import-statement";
|
|
276
275
|
}
|
|
276
|
+
function resolveDirname() {
|
|
277
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
278
|
+
}
|
|
279
|
+
function isInternalTest() {
|
|
280
|
+
return process.env.CC_TEST_INDICATOR === "__yes";
|
|
281
|
+
}
|
|
277
282
|
function createExternalsPlugin(configPath) {
|
|
278
283
|
const resolvePatterns = tsconfigPathsToRegExp(tsconfigResolvePaths(configPath));
|
|
284
|
+
const currentDir = resolveDirname();
|
|
279
285
|
return {
|
|
280
286
|
name: "external-packages",
|
|
281
287
|
setup: (build$2) => {
|
|
282
288
|
build$2.onResolve({ filter: /.*/ }, ({ path: path$1, kind }) => {
|
|
283
|
-
if (
|
|
284
|
-
path: join(
|
|
289
|
+
if (isInternalTest() && isCoreImport(path$1, kind)) return {
|
|
290
|
+
path: join(currentDir, "index.ts"),
|
|
285
291
|
external: true
|
|
286
292
|
};
|
|
287
293
|
if (match(path$1, resolvePatterns)) {
|
|
@@ -363,14 +369,14 @@ var ConfigurationError = class extends Error {
|
|
|
363
369
|
}
|
|
364
370
|
};
|
|
365
371
|
const defaultConfigName = "content-collection-config.mjs";
|
|
366
|
-
function resolveCacheDir(config$1, options) {
|
|
372
|
+
function resolveCacheDir$1(config$1, options) {
|
|
367
373
|
if (options.cacheDir) return options.cacheDir;
|
|
368
374
|
return path.join(path.dirname(config$1), ".content-collections", "cache");
|
|
369
375
|
}
|
|
370
376
|
function createConfigurationReader() {
|
|
371
377
|
return async (configurationPath, options = { configName: defaultConfigName }) => {
|
|
372
378
|
if (!existsSync(configurationPath)) throw new ConfigurationError("Read", `configuration file ${configurationPath} does not exist`);
|
|
373
|
-
const cacheDir = resolveCacheDir(configurationPath, options);
|
|
379
|
+
const cacheDir = resolveCacheDir$1(configurationPath, options);
|
|
374
380
|
await fs.mkdir(cacheDir, { recursive: true });
|
|
375
381
|
const outfile = path.join(cacheDir, options.configName);
|
|
376
382
|
try {
|
|
@@ -1933,19 +1939,21 @@ function createImport(imp, variableName) {
|
|
|
1933
1939
|
function serialize(value) {
|
|
1934
1940
|
let serializedValue = "";
|
|
1935
1941
|
let counter = 0;
|
|
1936
|
-
function handleImports(item) {
|
|
1942
|
+
function handleImports(item, parent, key) {
|
|
1937
1943
|
if (!item || typeof item !== "object") return;
|
|
1944
|
+
if (isImport(item)) {
|
|
1945
|
+
counter++;
|
|
1946
|
+
const variableName = `__v_${counter}`;
|
|
1947
|
+
serializedValue += createImport(item, variableName);
|
|
1948
|
+
if (parent !== void 0 && key !== void 0) parent[key] = variableName;
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1938
1951
|
if (Array.isArray(item)) {
|
|
1939
|
-
item.forEach(handleImports);
|
|
1952
|
+
item.forEach((entry, index) => handleImports(entry, item, index));
|
|
1940
1953
|
return;
|
|
1941
1954
|
}
|
|
1942
|
-
Object.entries(item).forEach(([
|
|
1943
|
-
|
|
1944
|
-
counter++;
|
|
1945
|
-
const variableName = `__v_${counter}`;
|
|
1946
|
-
serializedValue += createImport(value$1, variableName);
|
|
1947
|
-
item[key] = variableName;
|
|
1948
|
-
} else handleImports(value$1);
|
|
1955
|
+
Object.entries(item).forEach(([entryKey, entryValue]) => {
|
|
1956
|
+
handleImports(entryValue, item, entryKey);
|
|
1949
1957
|
});
|
|
1950
1958
|
}
|
|
1951
1959
|
handleImports(value);
|
|
@@ -2187,12 +2195,12 @@ async function createWriter(directory) {
|
|
|
2187
2195
|
|
|
2188
2196
|
//#endregion
|
|
2189
2197
|
//#region src/build.ts
|
|
2190
|
-
async function createBuildContext({ emitter, outputDirectory, baseDirectory, configuration }) {
|
|
2198
|
+
async function createBuildContext({ emitter, outputDirectory, cacheDirectory, baseDirectory, configuration }) {
|
|
2191
2199
|
const collector = createCollector(emitter, baseDirectory);
|
|
2192
2200
|
const [writer, resolved, cacheManager] = await Promise.all([
|
|
2193
2201
|
createWriter(outputDirectory),
|
|
2194
2202
|
collector.collect(configuration.collections),
|
|
2195
|
-
createCacheManager(
|
|
2203
|
+
createCacheManager(cacheDirectory, configuration.checksum)
|
|
2196
2204
|
]);
|
|
2197
2205
|
return {
|
|
2198
2206
|
resolved,
|
|
@@ -2307,6 +2315,10 @@ function resolveOutputDir(baseDirectory, options) {
|
|
|
2307
2315
|
if (options.outputDir) return options.outputDir;
|
|
2308
2316
|
return path.join(baseDirectory, ".content-collections", "generated");
|
|
2309
2317
|
}
|
|
2318
|
+
function resolveCacheDir(baseDirectory, options) {
|
|
2319
|
+
if (options.cacheDir) return options.cacheDir;
|
|
2320
|
+
return path.join(baseDirectory, ".content-collections", "cache");
|
|
2321
|
+
}
|
|
2310
2322
|
var ConfigurationReloadError = class extends Error {
|
|
2311
2323
|
constructor(message) {
|
|
2312
2324
|
super(message);
|
|
@@ -2321,6 +2333,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
|
|
|
2321
2333
|
const readConfiguration = createConfigurationReader();
|
|
2322
2334
|
const configurationPath = initialConfiguration.path;
|
|
2323
2335
|
const outputDirectory = resolveOutputDir(baseDirectory, options);
|
|
2336
|
+
const cacheDirectory = resolveCacheDir(baseDirectory, options);
|
|
2324
2337
|
emitter.emit("builder:created", {
|
|
2325
2338
|
createdAt: Date.now(),
|
|
2326
2339
|
configurationPath,
|
|
@@ -2332,6 +2345,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
|
|
|
2332
2345
|
emitter,
|
|
2333
2346
|
baseDirectory,
|
|
2334
2347
|
outputDirectory,
|
|
2348
|
+
cacheDirectory,
|
|
2335
2349
|
configuration
|
|
2336
2350
|
});
|
|
2337
2351
|
async function sync(modification, filePath) {
|
|
@@ -2369,6 +2383,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
|
|
|
2369
2383
|
emitter,
|
|
2370
2384
|
baseDirectory,
|
|
2371
2385
|
outputDirectory,
|
|
2386
|
+
cacheDirectory,
|
|
2372
2387
|
configuration
|
|
2373
2388
|
});
|
|
2374
2389
|
if (watcher) watcher = await createWatcher(emitter, baseDirectory, configuration, sync);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-collections/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.2",
|
|
5
5
|
"description": "Core of Content Collections",
|
|
6
6
|
"author": "Sebastian Sdorra <s.sdorra@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"p-limit": "^6.1.0",
|
|
50
50
|
"picomatch": "^4.0.2",
|
|
51
51
|
"pluralize": "^8.0.0",
|
|
52
|
-
"serialize-javascript": "^
|
|
52
|
+
"serialize-javascript": "^7.0.3",
|
|
53
53
|
"tinyglobby": "^0.2.5",
|
|
54
54
|
"yaml": "^2.4.5"
|
|
55
55
|
},
|