@content-collections/core 0.14.0 → 0.14.1

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.
Files changed (2) hide show
  1. package/dist/index.js +25 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23,10 +23,8 @@ import chokidar from "chokidar";
23
23
  function createKey(config$1, input, key) {
24
24
  return createHash("sha256").update(config$1).update(JSON.stringify(input)).update(key).digest("hex");
25
25
  }
26
- async function createCacheDirectory(directory) {
27
- const cacheDirectory = path.join(directory, ".content-collections", "cache");
26
+ async function createCacheDirectory(cacheDirectory) {
28
27
  if (!existsSync(cacheDirectory)) await mkdir(cacheDirectory, { recursive: true });
29
- return cacheDirectory;
30
28
  }
31
29
  function fileName(input) {
32
30
  return input.replace(/[^a-z0-9]/gi, "_").toLowerCase();
@@ -39,8 +37,8 @@ async function readMapping(mappingPath) {
39
37
  }
40
38
  return {};
41
39
  }
42
- async function createCacheManager(baseDirectory, configChecksum) {
43
- const cacheDirectory = await createCacheDirectory(baseDirectory);
40
+ async function createCacheManager(cacheDirectory, configChecksum) {
41
+ await createCacheDirectory(cacheDirectory);
44
42
  const mappingPath = join(cacheDirectory, "mapping.json");
45
43
  const mapping = await readMapping(mappingPath);
46
44
  async function flush() {
@@ -363,14 +361,14 @@ var ConfigurationError = class extends Error {
363
361
  }
364
362
  };
365
363
  const defaultConfigName = "content-collection-config.mjs";
366
- function resolveCacheDir(config$1, options) {
364
+ function resolveCacheDir$1(config$1, options) {
367
365
  if (options.cacheDir) return options.cacheDir;
368
366
  return path.join(path.dirname(config$1), ".content-collections", "cache");
369
367
  }
370
368
  function createConfigurationReader() {
371
369
  return async (configurationPath, options = { configName: defaultConfigName }) => {
372
370
  if (!existsSync(configurationPath)) throw new ConfigurationError("Read", `configuration file ${configurationPath} does not exist`);
373
- const cacheDir = resolveCacheDir(configurationPath, options);
371
+ const cacheDir = resolveCacheDir$1(configurationPath, options);
374
372
  await fs.mkdir(cacheDir, { recursive: true });
375
373
  const outfile = path.join(cacheDir, options.configName);
376
374
  try {
@@ -1933,19 +1931,21 @@ function createImport(imp, variableName) {
1933
1931
  function serialize(value) {
1934
1932
  let serializedValue = "";
1935
1933
  let counter = 0;
1936
- function handleImports(item) {
1934
+ function handleImports(item, parent, key) {
1937
1935
  if (!item || typeof item !== "object") return;
1936
+ if (isImport(item)) {
1937
+ counter++;
1938
+ const variableName = `__v_${counter}`;
1939
+ serializedValue += createImport(item, variableName);
1940
+ if (parent !== void 0 && key !== void 0) parent[key] = variableName;
1941
+ return;
1942
+ }
1938
1943
  if (Array.isArray(item)) {
1939
- item.forEach(handleImports);
1944
+ item.forEach((entry, index) => handleImports(entry, item, index));
1940
1945
  return;
1941
1946
  }
1942
- Object.entries(item).forEach(([key, value$1]) => {
1943
- if (isImport(value$1)) {
1944
- counter++;
1945
- const variableName = `__v_${counter}`;
1946
- serializedValue += createImport(value$1, variableName);
1947
- item[key] = variableName;
1948
- } else handleImports(value$1);
1947
+ Object.entries(item).forEach(([entryKey, entryValue]) => {
1948
+ handleImports(entryValue, item, entryKey);
1949
1949
  });
1950
1950
  }
1951
1951
  handleImports(value);
@@ -2187,12 +2187,12 @@ async function createWriter(directory) {
2187
2187
 
2188
2188
  //#endregion
2189
2189
  //#region src/build.ts
2190
- async function createBuildContext({ emitter, outputDirectory, baseDirectory, configuration }) {
2190
+ async function createBuildContext({ emitter, outputDirectory, cacheDirectory, baseDirectory, configuration }) {
2191
2191
  const collector = createCollector(emitter, baseDirectory);
2192
2192
  const [writer, resolved, cacheManager] = await Promise.all([
2193
2193
  createWriter(outputDirectory),
2194
2194
  collector.collect(configuration.collections),
2195
- createCacheManager(baseDirectory, configuration.checksum)
2195
+ createCacheManager(cacheDirectory, configuration.checksum)
2196
2196
  ]);
2197
2197
  return {
2198
2198
  resolved,
@@ -2307,6 +2307,10 @@ function resolveOutputDir(baseDirectory, options) {
2307
2307
  if (options.outputDir) return options.outputDir;
2308
2308
  return path.join(baseDirectory, ".content-collections", "generated");
2309
2309
  }
2310
+ function resolveCacheDir(baseDirectory, options) {
2311
+ if (options.cacheDir) return options.cacheDir;
2312
+ return path.join(baseDirectory, ".content-collections", "cache");
2313
+ }
2310
2314
  var ConfigurationReloadError = class extends Error {
2311
2315
  constructor(message) {
2312
2316
  super(message);
@@ -2321,6 +2325,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
2321
2325
  const readConfiguration = createConfigurationReader();
2322
2326
  const configurationPath = initialConfiguration.path;
2323
2327
  const outputDirectory = resolveOutputDir(baseDirectory, options);
2328
+ const cacheDirectory = resolveCacheDir(baseDirectory, options);
2324
2329
  emitter.emit("builder:created", {
2325
2330
  createdAt: Date.now(),
2326
2331
  configurationPath,
@@ -2332,6 +2337,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
2332
2337
  emitter,
2333
2338
  baseDirectory,
2334
2339
  outputDirectory,
2340
+ cacheDirectory,
2335
2341
  configuration
2336
2342
  });
2337
2343
  async function sync(modification, filePath) {
@@ -2369,6 +2375,7 @@ async function createInternalBuilder(initialConfiguration, baseDirectory, option
2369
2375
  emitter,
2370
2376
  baseDirectory,
2371
2377
  outputDirectory,
2378
+ cacheDirectory,
2372
2379
  configuration
2373
2380
  });
2374
2381
  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.0",
4
+ "version": "0.14.1",
5
5
  "description": "Core of Content Collections",
6
6
  "author": "Sebastian Sdorra <s.sdorra@gmail.com>",
7
7
  "license": "MIT",