@content-collections/core 0.7.1 → 0.7.3

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 +66 -54
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/builder.ts
2
- import path8 from "node:path";
2
+ import path9 from "node:path";
3
3
 
4
4
  // src/cache.ts
5
5
  import { createHash } from "node:crypto";
@@ -102,7 +102,7 @@ async function createCacheManager(baseDirectory, configChecksum) {
102
102
 
103
103
  // src/collector.ts
104
104
  import { readFile as readFile2 } from "fs/promises";
105
- import path2 from "path";
105
+ import path3 from "node:path";
106
106
  import { glob } from "tinyglobby";
107
107
 
108
108
  // src/parser.ts
@@ -143,6 +143,7 @@ var parsers = {
143
143
  // src/utils.ts
144
144
  import camelcase from "camelcase";
145
145
  import pluralize from "pluralize";
146
+ import path2 from "node:path";
146
147
  function generateTypeName(name) {
147
148
  const singularName = pluralize.singular(name);
148
149
  return camelcase(singularName, { pascalCase: true });
@@ -156,17 +157,23 @@ function orderByPath(a, b) {
156
157
  function removeChildPaths(paths) {
157
158
  return Array.from(
158
159
  new Set(
159
- paths.filter((path9) => {
160
+ paths.filter((path10) => {
160
161
  return !paths.some((otherPath) => {
161
- if (path9 === otherPath) {
162
+ if (path10 === otherPath) {
162
163
  return false;
163
164
  }
164
- return path9.startsWith(otherPath);
165
+ return path10.startsWith(otherPath);
165
166
  });
166
167
  })
167
168
  )
168
169
  );
169
170
  }
171
+ function posixToNativePath(pathName) {
172
+ if (path2.sep !== path2.posix.sep) {
173
+ return pathName.replaceAll(path2.posix.sep, path2.sep);
174
+ }
175
+ return pathName;
176
+ }
170
177
 
171
178
  // src/collector.ts
172
179
  var CollectError = class extends Error {
@@ -189,7 +196,7 @@ function createCollector(emitter, baseDirectory = ".") {
189
196
  }
190
197
  }
191
198
  async function collectFile(collection, filePath) {
192
- const absolutePath = path2.join(
199
+ const absolutePath = path3.join(
193
200
  baseDirectory,
194
201
  collection.directory,
195
202
  filePath
@@ -206,7 +213,7 @@ function createCollector(emitter, baseDirectory = ".") {
206
213
  };
207
214
  } catch (error) {
208
215
  emitter.emit("collector:parse-error", {
209
- filePath: path2.join(collection.directory, filePath),
216
+ filePath: path3.join(collection.directory, filePath),
210
217
  error: new CollectError("Parse", String(error))
211
218
  });
212
219
  return null;
@@ -223,7 +230,7 @@ function createCollector(emitter, baseDirectory = ".") {
223
230
  return void 0;
224
231
  }
225
232
  async function resolveCollection(collection) {
226
- const collectionDirectory = path2.join(baseDirectory, collection.directory);
233
+ const collectionDirectory = path3.join(baseDirectory, collection.directory);
227
234
  const include = Array.isArray(collection.include) ? collection.include : [collection.include];
228
235
  const filePaths = await glob(include, {
229
236
  cwd: collectionDirectory,
@@ -232,7 +239,7 @@ function createCollector(emitter, baseDirectory = ".") {
232
239
  ignore: createIgnorePattern(collection)
233
240
  });
234
241
  const promises = filePaths.map(
235
- (filePath) => collectFile(collection, filePath)
242
+ (filePath) => collectFile(collection, posixToNativePath(filePath))
236
243
  );
237
244
  const files = await Promise.all(promises);
238
245
  return {
@@ -253,23 +260,23 @@ function createCollector(emitter, baseDirectory = ".") {
253
260
  }
254
261
 
255
262
  // src/synchronizer.ts
256
- import path3 from "node:path";
263
+ import path4 from "node:path";
257
264
  import picomatch from "picomatch";
258
265
  function createSynchronizer(readCollectionFile, collections, baseDirectory = ".") {
259
266
  function findCollections(filePath) {
260
- const resolvedFilePath = path3.resolve(filePath);
267
+ const resolvedFilePath = path4.resolve(filePath);
261
268
  return collections.filter((collection) => {
262
269
  return resolvedFilePath.startsWith(
263
- path3.resolve(baseDirectory, collection.directory)
270
+ path4.resolve(baseDirectory, collection.directory)
264
271
  );
265
272
  });
266
273
  }
267
274
  function createRelativePath(collectionPath, filePath) {
268
- const resolvedCollectionPath = path3.resolve(baseDirectory, collectionPath);
269
- const resolvedFilePath = path3.resolve(filePath);
275
+ const resolvedCollectionPath = path4.resolve(baseDirectory, collectionPath);
276
+ const resolvedFilePath = path4.resolve(filePath);
270
277
  let relativePath = resolvedFilePath.slice(resolvedCollectionPath.length);
271
- if (relativePath.startsWith(path3.sep)) {
272
- relativePath = relativePath.slice(path3.sep.length);
278
+ if (relativePath.startsWith(path4.sep)) {
279
+ relativePath = relativePath.slice(path4.sep.length);
273
280
  }
274
281
  return relativePath;
275
282
  }
@@ -377,8 +384,8 @@ var TransformError = class extends Error {
377
384
  this.type = type;
378
385
  }
379
386
  };
380
- function createPath(path9, ext) {
381
- let p = path9.slice(0, -ext.length);
387
+ function createPath(path10, ext) {
388
+ let p = path10.slice(0, -ext.length);
382
389
  if (p.endsWith("/index")) {
383
390
  p = p.slice(0, -6);
384
391
  }
@@ -396,7 +403,7 @@ function createTransformer(emitter, cacheManager) {
396
403
  });
397
404
  }
398
405
  async function parseFile(collection, file) {
399
- const { data, path: path9 } = file;
406
+ const { data, path: path10 } = file;
400
407
  const schema2 = createSchema(collection.parser, collection.schema);
401
408
  let parsedData = await schema2.safeParseAsync(data);
402
409
  if (!parsedData.success) {
@@ -407,7 +414,7 @@ function createTransformer(emitter, cacheManager) {
407
414
  });
408
415
  return null;
409
416
  }
410
- const ext = extname(path9);
417
+ const ext = extname(path10);
411
418
  let extension2 = ext;
412
419
  if (extension2.startsWith(".")) {
413
420
  extension2 = extension2.slice(1);
@@ -415,11 +422,11 @@ function createTransformer(emitter, cacheManager) {
415
422
  const document = {
416
423
  ...parsedData.data,
417
424
  _meta: {
418
- filePath: path9,
419
- fileName: basename(path9),
420
- directory: dirname(path9),
425
+ filePath: path10,
426
+ fileName: basename(path10),
427
+ directory: dirname(path10),
421
428
  extension: extension2,
422
- path: createPath(path9, ext)
429
+ path: createPath(path10, ext)
423
430
  }
424
431
  };
425
432
  return {
@@ -525,14 +532,14 @@ function createTransformer(emitter, cacheManager) {
525
532
 
526
533
  // src/writer.ts
527
534
  import fs from "node:fs/promises";
528
- import path4 from "node:path";
535
+ import path5 from "node:path";
529
536
  import pluralize2 from "pluralize";
530
537
  function createArrayConstName(name) {
531
538
  let suffix = name.charAt(0).toUpperCase() + name.slice(1);
532
539
  return "all" + pluralize2(suffix);
533
540
  }
534
541
  async function createDataFile(directory, collection) {
535
- const dataPath = path4.join(
542
+ const dataPath = path5.join(
536
543
  directory,
537
544
  `${createArrayConstName(collection.name)}.${extension}`
538
545
  );
@@ -559,11 +566,11 @@ async function createJavaScriptFile(directory, configuration) {
559
566
  }
560
567
  content += "\n";
561
568
  content += "export { " + collections.join(", ") + " };\n";
562
- await fs.writeFile(path4.join(directory, "index.js"), content, "utf-8");
569
+ await fs.writeFile(path5.join(directory, "index.js"), content, "utf-8");
563
570
  }
564
571
  function createImportPath(directory, target) {
565
- let importPath = path4.posix.join(
566
- ...path4.relative(directory, target).split(path4.sep)
572
+ let importPath = path5.posix.join(
573
+ ...path5.relative(directory, target).split(path5.sep)
567
574
  );
568
575
  if (!importPath.startsWith(".")) {
569
576
  importPath = "./" + importPath;
@@ -591,7 +598,7 @@ import { GetTypeByName } from "@content-collections/core";
591
598
  }
592
599
  content += "\n";
593
600
  content += "export {};\n";
594
- await fs.writeFile(path4.join(directory, "index.d.ts"), content, "utf-8");
601
+ await fs.writeFile(path5.join(directory, "index.d.ts"), content, "utf-8");
595
602
  }
596
603
  async function createWriter(directory) {
597
604
  await fs.mkdir(directory, { recursive: true });
@@ -674,7 +681,7 @@ async function build({
674
681
  import { createHash as createHash2 } from "node:crypto";
675
682
  import { existsSync as existsSync2 } from "node:fs";
676
683
  import fs3 from "node:fs/promises";
677
- import path6 from "node:path";
684
+ import path7 from "node:path";
678
685
 
679
686
  // ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.21.4/node_modules/bundle-require/dist/index.js
680
687
  import {
@@ -683,7 +690,7 @@ import {
683
690
  } from "esbuild";
684
691
 
685
692
  // ../../node_modules/.pnpm/load-tsconfig@0.2.5/node_modules/load-tsconfig/dist/index.js
686
- import path5 from "path";
693
+ import path6 from "path";
687
694
  import fs2 from "fs";
688
695
  import { createRequire } from "module";
689
696
  var singleComment = Symbol("singleComment");
@@ -780,10 +787,10 @@ function jsoncParse(data) {
780
787
  }
781
788
  }
782
789
  var req = true ? createRequire(import.meta.url) : __require;
783
- var findUp = (name, startDir, stopDir = path5.parse(startDir).root) => {
790
+ var findUp = (name, startDir, stopDir = path6.parse(startDir).root) => {
784
791
  let dir = startDir;
785
792
  while (dir !== stopDir) {
786
- const file = path5.join(dir, name);
793
+ const file = path6.join(dir, name);
787
794
  if (fs2.existsSync(file))
788
795
  return file;
789
796
  if (!file.endsWith(".json")) {
@@ -791,17 +798,17 @@ var findUp = (name, startDir, stopDir = path5.parse(startDir).root) => {
791
798
  if (fs2.existsSync(fileWithExt))
792
799
  return fileWithExt;
793
800
  }
794
- dir = path5.dirname(dir);
801
+ dir = path6.dirname(dir);
795
802
  }
796
803
  return null;
797
804
  };
798
805
  var resolveTsConfigFromFile = (cwd, filename) => {
799
- if (path5.isAbsolute(filename))
806
+ if (path6.isAbsolute(filename))
800
807
  return fs2.existsSync(filename) ? filename : null;
801
808
  return findUp(filename, cwd);
802
809
  };
803
810
  var resolveTsConfigFromExtends = (cwd, name) => {
804
- if (path5.isAbsolute(name))
811
+ if (path6.isAbsolute(name))
805
812
  return fs2.existsSync(name) ? name : null;
806
813
  if (name.startsWith("."))
807
814
  return findUp(name, cwd);
@@ -810,14 +817,14 @@ var resolveTsConfigFromExtends = (cwd, name) => {
810
817
  };
811
818
  var loadTsConfigInternal = (dir = process.cwd(), name = "tsconfig.json", isExtends = false) => {
812
819
  var _a, _b;
813
- dir = path5.resolve(dir);
820
+ dir = path6.resolve(dir);
814
821
  const id = isExtends ? resolveTsConfigFromExtends(dir, name) : resolveTsConfigFromFile(dir, name);
815
822
  if (!id)
816
823
  return null;
817
824
  const data = jsoncParse(fs2.readFileSync(id, "utf-8"));
818
- const configDir = path5.dirname(id);
825
+ const configDir = path6.dirname(id);
819
826
  if ((_a = data.compilerOptions) == null ? void 0 : _a.baseUrl) {
820
- data.compilerOptions.baseUrl = path5.join(
827
+ data.compilerOptions.baseUrl = path6.join(
821
828
  configDir,
822
829
  data.compilerOptions.baseUrl
823
830
  );
@@ -880,21 +887,26 @@ function tsconfigResolvePaths(configPath) {
880
887
  }
881
888
  return tsconfig?.data?.compilerOptions?.paths || {};
882
889
  }
890
+ var NON_NODE_MODULE_RE = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
883
891
  function createExternalsPlugin(configPath) {
884
892
  const resolvedPaths = tsconfigResolvePaths(configPath);
885
893
  const resolvePatterns = tsconfigPathsToRegExp(resolvedPaths);
886
894
  return {
887
895
  name: "external-packages",
888
896
  setup: (build4) => {
889
- const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
890
- build4.onResolve({ filter }, ({ path: path9, kind }) => {
891
- if (match(path9, resolvePatterns)) {
897
+ build4.onResolve({ filter: /.*/ }, ({ path: path10, kind }) => {
898
+ if (match(path10, resolvePatterns)) {
892
899
  if (kind === "dynamic-import") {
893
- return { path: path9, external: true };
900
+ return { path: path10, external: true };
894
901
  }
895
902
  return;
896
903
  }
897
- return { path: path9, external: true };
904
+ if (!NON_NODE_MODULE_RE.test(path10)) {
905
+ return {
906
+ path: path10,
907
+ external: true
908
+ };
909
+ }
898
910
  });
899
911
  }
900
912
  };
@@ -938,7 +950,7 @@ function resolveCacheDir(config, options) {
938
950
  if (options.cacheDir) {
939
951
  return options.cacheDir;
940
952
  }
941
- return path6.join(path6.dirname(config), ".content-collections", "cache");
953
+ return path7.join(path7.dirname(config), ".content-collections", "cache");
942
954
  }
943
955
  function createConfigurationReader() {
944
956
  return async (configurationPath, options = {
@@ -952,17 +964,17 @@ function createConfigurationReader() {
952
964
  }
953
965
  const cacheDir = resolveCacheDir(configurationPath, options);
954
966
  await fs3.mkdir(cacheDir, { recursive: true });
955
- const outfile = path6.join(cacheDir, options.configName);
967
+ const outfile = path7.join(cacheDir, options.configName);
956
968
  try {
957
969
  const configurationPaths = await compile(configurationPath, outfile);
958
- const module = await import(`file://${path6.resolve(outfile)}?x=${Date.now()}`);
970
+ const module = await import(`file://${path7.resolve(outfile)}?x=${Date.now()}`);
959
971
  const hash = createHash2("sha256");
960
972
  hash.update(await fs3.readFile(outfile, "utf-8"));
961
973
  const checksum = hash.digest("hex");
962
974
  return {
963
975
  ...module.default,
964
976
  path: configurationPath,
965
- inputPaths: configurationPaths.map((p) => path6.resolve(p)),
977
+ inputPaths: configurationPaths.map((p) => path7.resolve(p)),
966
978
  generateTypes: true,
967
979
  checksum
968
980
  };
@@ -1006,7 +1018,7 @@ function createEmitter() {
1006
1018
 
1007
1019
  // src/watcher.ts
1008
1020
  import * as watcher from "@parcel/watcher";
1009
- import path7, { dirname as dirname3, resolve } from "node:path";
1021
+ import path8, { dirname as dirname3, resolve } from "node:path";
1010
1022
  async function createWatcher(emitter, baseDirectory, configuration, sync) {
1011
1023
  const onChange = async (error, events) => {
1012
1024
  if (error) {
@@ -1021,10 +1033,10 @@ async function createWatcher(emitter, baseDirectory, configuration, sync) {
1021
1033
  }
1022
1034
  };
1023
1035
  const paths = removeChildPaths([
1024
- ...configuration.collections.map((collection) => path7.join(baseDirectory, collection.directory)).map((p) => resolve(p)),
1036
+ ...configuration.collections.map((collection) => path8.join(baseDirectory, collection.directory)).map((p) => resolve(p)),
1025
1037
  ...configuration.inputPaths.map((p) => dirname3(p))
1026
1038
  ]);
1027
- const subscriptions = (await Promise.all(paths.map((path9) => watcher.subscribe(path9, onChange)))).filter(isDefined);
1039
+ const subscriptions = (await Promise.all(paths.map((path10) => watcher.subscribe(path10, onChange)))).filter(isDefined);
1028
1040
  emitter.emit("watcher:subscribed", {
1029
1041
  paths
1030
1042
  });
@@ -1049,7 +1061,7 @@ function resolveOutputDir(baseDirectory, options) {
1049
1061
  if (options.outputDir) {
1050
1062
  return options.outputDir;
1051
1063
  }
1052
- return path8.join(baseDirectory, ".content-collections", "generated");
1064
+ return path9.join(baseDirectory, ".content-collections", "generated");
1053
1065
  }
1054
1066
  var ConfigurationReloadError = class extends Error {
1055
1067
  constructor(message) {
@@ -1060,7 +1072,7 @@ async function createBuilder(configurationPath, options = {
1060
1072
  configName: defaultConfigName
1061
1073
  }, emitter = createEmitter()) {
1062
1074
  const readConfiguration = createConfigurationReader();
1063
- const baseDirectory = path8.dirname(configurationPath);
1075
+ const baseDirectory = path9.dirname(configurationPath);
1064
1076
  const outputDirectory = resolveOutputDir(baseDirectory, options);
1065
1077
  emitter.emit("builder:created", {
1066
1078
  createdAt: Date.now(),
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@content-collections/core",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
8
8
  "./package.json": "./package.json",
9
9
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
12
  }
13
13
  },
14
14
  "files": [
@@ -24,11 +24,11 @@
24
24
  "@types/picomatch": "^3.0.1",
25
25
  "@types/pluralize": "^0.0.33",
26
26
  "@types/serialize-javascript": "^5.0.4",
27
- "@vitest/coverage-v8": "^2.0.5",
27
+ "@vitest/coverage-v8": "^2.1.3",
28
28
  "tsup": "^8.2.4",
29
29
  "tsx": "^4.1.1",
30
30
  "typescript": "^5.5.4",
31
- "vitest": "^2.0.5"
31
+ "vitest": "^2.1.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "@parcel/watcher": "^2.4.1",