fuma-content 1.0.1 → 1.0.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.
Files changed (147) hide show
  1. package/dist/async-cache-BM9Yf4Nw.js +29 -0
  2. package/dist/async-cache-BM9Yf4Nw.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -14
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-D8A5ByFk.js +42 -0
  7. package/dist/build-D8A5ByFk.js.map +1 -0
  8. package/dist/build-mdx-C1PZsGp2.js +395 -0
  9. package/dist/build-mdx-C1PZsGp2.js.map +1 -0
  10. package/dist/build-mdx-DFndaVbS.js +4 -0
  11. package/dist/bun/index.d.ts +6 -13
  12. package/dist/bun/index.d.ts.map +1 -0
  13. package/dist/bun/index.js +23 -34
  14. package/dist/bun/index.js.map +1 -0
  15. package/dist/bun-QKQnqgIi.js +35 -0
  16. package/dist/bun-QKQnqgIi.js.map +1 -0
  17. package/dist/code-generator-gPtrfZ6Q.js +133 -0
  18. package/dist/code-generator-gPtrfZ6Q.js.map +1 -0
  19. package/dist/collections/handlers/fs.d.ts +2 -10
  20. package/dist/collections/handlers/fs.js +28 -6
  21. package/dist/collections/handlers/fs.js.map +1 -0
  22. package/dist/collections/index.d.ts +2 -10
  23. package/dist/collections/index.js +16 -6
  24. package/dist/collections/index.js.map +1 -0
  25. package/dist/collections/mdx/loader-webpack.d.ts +6 -14
  26. package/dist/collections/mdx/loader-webpack.d.ts.map +1 -0
  27. package/dist/collections/mdx/loader-webpack.js +23 -36
  28. package/dist/collections/mdx/loader-webpack.js.map +1 -0
  29. package/dist/collections/mdx/runtime-browser.d.ts +27 -37
  30. package/dist/collections/mdx/runtime-browser.d.ts.map +1 -0
  31. package/dist/collections/mdx/runtime-browser.js +57 -70
  32. package/dist/collections/mdx/runtime-browser.js.map +1 -0
  33. package/dist/collections/mdx/runtime-dynamic.d.ts +22 -30
  34. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -0
  35. package/dist/collections/mdx/runtime-dynamic.js +63 -85
  36. package/dist/collections/mdx/runtime-dynamic.js.map +1 -0
  37. package/dist/collections/mdx/runtime.d.ts +31 -52
  38. package/dist/collections/mdx/runtime.d.ts.map +1 -0
  39. package/dist/collections/mdx/runtime.js +24 -34
  40. package/dist/collections/mdx/runtime.js.map +1 -0
  41. package/dist/collections/mdx.d.ts +2 -10
  42. package/dist/collections/mdx.js +240 -284
  43. package/dist/collections/mdx.js.map +1 -0
  44. package/dist/collections/meta/loader-webpack.d.ts +6 -14
  45. package/dist/collections/meta/loader-webpack.d.ts.map +1 -0
  46. package/dist/collections/meta/loader-webpack.js +25 -39
  47. package/dist/collections/meta/loader-webpack.js.map +1 -0
  48. package/dist/collections/meta/runtime.d.ts +7 -15
  49. package/dist/collections/meta/runtime.d.ts.map +1 -0
  50. package/dist/collections/meta/runtime.js +9 -15
  51. package/dist/collections/meta/runtime.js.map +1 -0
  52. package/dist/collections/meta.d.ts +2 -10
  53. package/dist/collections/meta.js +128 -164
  54. package/dist/collections/meta.js.map +1 -0
  55. package/dist/collections/runtime/file-store.d.ts +17 -14
  56. package/dist/collections/runtime/file-store.d.ts.map +1 -0
  57. package/dist/collections/runtime/file-store.js +30 -6
  58. package/dist/collections/runtime/file-store.js.map +1 -0
  59. package/dist/collections/runtime/store.d.ts +3 -28
  60. package/dist/collections/runtime/store.js +3 -6
  61. package/dist/config/index.d.ts +2 -10
  62. package/dist/config/index.js +6 -5
  63. package/dist/config/index.js.map +1 -0
  64. package/dist/core-Bkh-SI_3.d.ts +561 -0
  65. package/dist/core-Bkh-SI_3.d.ts.map +1 -0
  66. package/dist/core-ZuoVBkeg.js +170 -0
  67. package/dist/core-ZuoVBkeg.js.map +1 -0
  68. package/dist/dynamic-B40uAtdo.js +28 -0
  69. package/dist/dynamic-B40uAtdo.js.map +1 -0
  70. package/dist/fuma-matter-O4fA6nSx.js +27 -0
  71. package/dist/fuma-matter-O4fA6nSx.js.map +1 -0
  72. package/dist/index.d.ts +13 -16
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -8
  75. package/dist/load-from-file-1f4WaHsf.js +38 -0
  76. package/dist/load-from-file-1f4WaHsf.js.map +1 -0
  77. package/dist/load-from-file-BTNnBu6f.js +3 -0
  78. package/dist/loader-80abXEHx.js +4 -0
  79. package/dist/loader-BFhPyg3z.js +4 -0
  80. package/dist/loader-CXnMFuyE.js +80 -0
  81. package/dist/loader-CXnMFuyE.js.map +1 -0
  82. package/dist/loader-gk94iHf5.js +66 -0
  83. package/dist/loader-gk94iHf5.js.map +1 -0
  84. package/dist/next/index.cjs +459 -551
  85. package/dist/next/index.d.ts +16 -22
  86. package/dist/next/index.d.ts.map +1 -0
  87. package/dist/next/index.js +71 -89
  88. package/dist/next/index.js.map +1 -0
  89. package/dist/node/loader.d.ts +4 -2
  90. package/dist/node/loader.d.ts.map +1 -0
  91. package/dist/node/loader.js +32 -44
  92. package/dist/node/loader.js.map +1 -0
  93. package/dist/node-CGIIJIcs.js +31 -0
  94. package/dist/node-CGIIJIcs.js.map +1 -0
  95. package/dist/pipe-5cnvE6KY.js +31 -0
  96. package/dist/pipe-5cnvE6KY.js.map +1 -0
  97. package/dist/plugins/git.d.ts +2 -10
  98. package/dist/plugins/git.js +57 -65
  99. package/dist/plugins/git.js.map +1 -0
  100. package/dist/plugins/json-schema.d.ts +2 -10
  101. package/dist/plugins/json-schema.js +60 -58
  102. package/dist/plugins/json-schema.js.map +1 -0
  103. package/dist/plugins/with-loader/index.d.ts +2 -61
  104. package/dist/plugins/with-loader/index.js +28 -6
  105. package/dist/plugins/with-loader/index.js.map +1 -0
  106. package/dist/plugins/with-loader/webpack.d.ts +10 -18
  107. package/dist/plugins/with-loader/webpack.d.ts.map +1 -0
  108. package/dist/plugins/with-loader/webpack.js +43 -12
  109. package/dist/plugins/with-loader/webpack.js.map +1 -0
  110. package/dist/store-0LQ2PlH6.js +37 -0
  111. package/dist/store-0LQ2PlH6.js.map +1 -0
  112. package/dist/store-DEjYYF6a.d.ts +31 -0
  113. package/dist/store-DEjYYF6a.d.ts.map +1 -0
  114. package/dist/validation-BOJKRAp5.js +28 -0
  115. package/dist/validation-BOJKRAp5.js.map +1 -0
  116. package/dist/vite/index.d.ts +22 -28
  117. package/dist/vite/index.d.ts.map +1 -0
  118. package/dist/vite/index.js +37 -52
  119. package/dist/vite/index.js.map +1 -0
  120. package/dist/vite-X-2Al8fq.js +32 -0
  121. package/dist/vite-X-2Al8fq.js.map +1 -0
  122. package/package.json +7 -6
  123. package/dist/build-mdx-I4NROXCF.js +0 -8
  124. package/dist/bun-DMNX4PBC.js +0 -40
  125. package/dist/chunk-3VQS3KSP.js +0 -39
  126. package/dist/chunk-BTRE6MOX.js +0 -16
  127. package/dist/chunk-E4HRKSP4.js +0 -24
  128. package/dist/chunk-ERBMAQYP.js +0 -33
  129. package/dist/chunk-GGL4EF6H.js +0 -38
  130. package/dist/chunk-JBZTQ55D.js +0 -30
  131. package/dist/chunk-KH5GT2Y5.js +0 -104
  132. package/dist/chunk-LUM7SIZN.js +0 -40
  133. package/dist/chunk-MT7RY65Y.js +0 -167
  134. package/dist/chunk-NRZ4GE5O.js +0 -207
  135. package/dist/chunk-OQQNA7L7.js +0 -412
  136. package/dist/chunk-OUJENWQ4.js +0 -45
  137. package/dist/chunk-RMSV4HP6.js +0 -85
  138. package/dist/chunk-RXR7OL76.js +0 -37
  139. package/dist/chunk-VWJKRQZR.js +0 -19
  140. package/dist/chunk-W6HENTK7.js +0 -44
  141. package/dist/chunk-XR5N6ZXJ.js +0 -50
  142. package/dist/core-Bo8KaWQz.d.ts +0 -411
  143. package/dist/load-from-file-HL2VEY3M.js +0 -7
  144. package/dist/loader-NFSL6P5I.js +0 -7
  145. package/dist/loader-T756NSCS.js +0 -7
  146. package/dist/node-DCMYL4DL.js +0 -34
  147. package/dist/vite-QCUPZHHB.js +0 -32
@@ -0,0 +1,32 @@
1
+ import { parse } from "node:querystring";
2
+
3
+ //#region src/plugins/with-loader/vite.ts
4
+ function toVite(name, test, loader) {
5
+ return {
6
+ name: `fuma-content:${name}`,
7
+ async transform(value, id) {
8
+ if (test && !test.test(id)) return;
9
+ const [file, query = ""] = id.split("?", 2);
10
+ const result = await loader.load({
11
+ filePath: file,
12
+ query: parse(query),
13
+ getSource() {
14
+ return value;
15
+ },
16
+ development: this.environment.mode === "dev",
17
+ compiler: { addDependency: (file$1) => {
18
+ this.addWatchFile(file$1);
19
+ } }
20
+ });
21
+ if (result === null) return null;
22
+ return {
23
+ code: result.code,
24
+ map: result.map
25
+ };
26
+ }
27
+ };
28
+ }
29
+
30
+ //#endregion
31
+ export { toVite };
32
+ //# sourceMappingURL=vite-X-2Al8fq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-X-2Al8fq.js","names":["file"],"sources":["../src/plugins/with-loader/vite.ts"],"sourcesContent":["import type { SourceMap } from \"rollup\";\nimport type { PluginOption } from \"vite\";\nimport { parse } from \"node:querystring\";\nimport type { Loader } from \"@/plugins/with-loader\";\n\nexport function toVite(\n name: string,\n test: RegExp | undefined,\n loader: Loader,\n): PluginOption {\n return {\n name: `fuma-content:${name}`,\n async transform(value, id) {\n if (test && !test.test(id)) return;\n\n const [file, query = \"\"] = id.split(\"?\", 2);\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === \"dev\",\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n };\n },\n };\n}\n"],"mappings":";;;AAKA,SAAgB,OACd,MACA,MACA,QACc;AACd,QAAO;EACL,MAAM,gBAAgB;EACtB,MAAM,UAAU,OAAO,IAAI;AACzB,OAAI,QAAQ,CAAC,KAAK,KAAK,GAAG,CAAE;GAE5B,MAAM,CAAC,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,EAAE;GAC3C,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B,UAAU;IACV,OAAO,MAAM,MAAM;IACnB,YAAY;AACV,YAAO;;IAET,aAAa,KAAK,YAAY,SAAS;IACvC,UAAU,EACR,gBAAgB,WAAS;AACvB,UAAK,aAAaA,OAAK;OAE1B;IACF,CAAC;AAEF,OAAI,WAAW,KAAM,QAAO;AAC5B,UAAO;IACL,MAAM,OAAO;IACb,KAAK,OAAO;IACb;;EAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fuma-content",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "The content processing layer for your app.",
5
5
  "keywords": [
6
6
  "Docs",
@@ -87,10 +87,10 @@
87
87
  "@types/js-yaml": "^4.0.9",
88
88
  "@types/mdast": "^4.0.4",
89
89
  "@types/mdx": "^2.0.13",
90
- "@types/node": "^24.10.2",
90
+ "@types/node": "^24.10.4",
91
91
  "@types/picomatch": "^4.0.2",
92
92
  "@types/react": "^19.2.7",
93
- "fumadocs-core": "^16.3.0",
93
+ "fumadocs-core": "^16.3.2",
94
94
  "mdast-util-directive": "^3.1.0",
95
95
  "mdast-util-mdx-jsx": "^3.2.0",
96
96
  "next": "16.1.0",
@@ -98,7 +98,8 @@
98
98
  "remark": "^15.0.1",
99
99
  "remark-directive": "^4.0.0",
100
100
  "remark-stringify": "^11.0.0",
101
- "rollup": "^4.53.5",
101
+ "rollup": "^4.54.0",
102
+ "tsdown": "^0.18.2",
102
103
  "typescript": "^5.9.3",
103
104
  "vite": "^7.3.0",
104
105
  "webpack": "^5.104.1",
@@ -124,9 +125,9 @@
124
125
  "access": "public"
125
126
  },
126
127
  "scripts": {
127
- "build": "tsup",
128
+ "build": "tsdown",
128
129
  "clean": "rimraf dist",
129
- "dev": "tsup --watch",
130
+ "dev": "tsdown --watch",
130
131
  "types:check": "tsc --noEmit"
131
132
  }
132
133
  }
@@ -1,8 +0,0 @@
1
- import {
2
- buildMDX
3
- } from "./chunk-OQQNA7L7.js";
4
- import "./chunk-VWJKRQZR.js";
5
- import "./chunk-JBZTQ55D.js";
6
- export {
7
- buildMDX
8
- };
@@ -1,40 +0,0 @@
1
- // src/plugins/with-loader/bun.ts
2
- import { parse } from "querystring";
3
- import { readFileSync } from "fs";
4
- function toBun(test = /.+/, loader) {
5
- function toResult(output) {
6
- if (!output) return;
7
- return {
8
- contents: output.code,
9
- loader: "js"
10
- };
11
- }
12
- return (build) => {
13
- build.onLoad({ filter: test }, (args) => {
14
- const [filePath, query = ""] = args.path.split("?", 2);
15
- const input = {
16
- async getSource() {
17
- return Bun.file(filePath).text();
18
- },
19
- query: parse(query),
20
- filePath,
21
- development: false,
22
- compiler: {
23
- addDependency() {
24
- }
25
- }
26
- };
27
- if (loader.bun?.load) {
28
- return loader.bun.load(readFileSync(filePath).toString(), input);
29
- }
30
- const result = loader.load(input);
31
- if (result instanceof Promise) {
32
- return result.then(toResult);
33
- }
34
- return toResult(result);
35
- });
36
- };
37
- }
38
- export {
39
- toBun
40
- };
@@ -1,39 +0,0 @@
1
- // src/collections/runtime/store.ts
2
- var SimpleCollectionStore = class {
3
- dataMap;
4
- dataList;
5
- constructor(input) {
6
- this.dataMap = input;
7
- this.dataList = Array.from(input.values());
8
- }
9
- get(id) {
10
- return this.dataMap.get(id);
11
- }
12
- list() {
13
- return this.dataList;
14
- }
15
- $data(_cast) {
16
- return this;
17
- }
18
- /**
19
- * in-place transformation on all data
20
- */
21
- transform(fn) {
22
- this.dataList.length = 0;
23
- const dataMap = this.dataMap;
24
- const dataList = this.dataList;
25
- for (const [k, v] of this.dataMap) {
26
- const updated = fn(v);
27
- dataMap.set(k, updated);
28
- dataList.push(updated);
29
- }
30
- return this;
31
- }
32
- get $inferData() {
33
- return void 0;
34
- }
35
- };
36
-
37
- export {
38
- SimpleCollectionStore
39
- };
@@ -1,16 +0,0 @@
1
- // src/collections/index.ts
2
- function createCollection(info, init) {
3
- return {
4
- name: "",
5
- handlers: {},
6
- init(options) {
7
- this.name = options.name;
8
- init(this, options);
9
- },
10
- typeInfo: info
11
- };
12
- }
13
-
14
- export {
15
- createCollection
16
- };
@@ -1,24 +0,0 @@
1
- // src/collections/handlers/fs.ts
2
- import picomatch from "picomatch";
3
- import path from "path";
4
- function buildFileHandler({ workspace }, config, supportedFormats) {
5
- const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
6
- let matcher;
7
- return {
8
- patterns,
9
- dir: workspace ? path.resolve(workspace.dir, config.dir) : config.dir,
10
- isFileSupported(filePath) {
11
- return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
12
- },
13
- hasFile(filePath) {
14
- if (!this.isFileSupported(filePath)) return false;
15
- const relativePath = path.relative(this.dir, filePath);
16
- if (relativePath.startsWith(`..${path.sep}`)) return false;
17
- return (matcher ??= picomatch(patterns))(relativePath);
18
- }
19
- };
20
- }
21
-
22
- export {
23
- buildFileHandler
24
- };
@@ -1,33 +0,0 @@
1
- // src/plugins/with-loader/index.ts
2
- function withLoader(plugin, { test, createLoader }) {
3
- let loader;
4
- return {
5
- bun: {
6
- async build(build) {
7
- const { toBun } = await import("./bun-DMNX4PBC.js");
8
- toBun(test, await (loader ??= createLoader.call(this, "bun")))(build);
9
- }
10
- },
11
- node: {
12
- async createLoad() {
13
- const { toNode } = await import("./node-DCMYL4DL.js");
14
- return toNode(test, await (loader ??= createLoader.call(this, "node")));
15
- }
16
- },
17
- vite: {
18
- async createPlugin() {
19
- const { toVite } = await import("./vite-QCUPZHHB.js");
20
- return toVite(
21
- plugin.name,
22
- test,
23
- await (loader ??= createLoader.call(this, "vite"))
24
- );
25
- }
26
- },
27
- ...plugin
28
- };
29
- }
30
-
31
- export {
32
- withLoader
33
- };
@@ -1,38 +0,0 @@
1
- // src/config/dynamic.ts
2
- import fs from "fs/promises";
3
- function createDynamicCore({
4
- core,
5
- buildConfig,
6
- mode
7
- }) {
8
- let prev;
9
- async function getConfigHash() {
10
- if (mode === "production") return "static";
11
- const stats = await fs.stat(core.getOptions().configPath).catch(() => {
12
- throw new Error("Cannot find config file");
13
- });
14
- return stats.mtime.getTime().toString();
15
- }
16
- return {
17
- async getCore() {
18
- const hash = await getConfigHash();
19
- if (!prev || hash !== prev.hash) {
20
- prev = {
21
- hash,
22
- init: (async () => {
23
- const { loadConfig } = await import("./load-from-file-HL2VEY3M.js");
24
- await core.init({
25
- config: loadConfig(core, buildConfig)
26
- });
27
- })()
28
- };
29
- }
30
- await prev.init;
31
- return core;
32
- }
33
- };
34
- }
35
-
36
- export {
37
- createDynamicCore
38
- };
@@ -1,30 +0,0 @@
1
- // src/utils/async-cache.ts
2
- function createCache(store = /* @__PURE__ */ new Map()) {
3
- return {
4
- cached(key, fn) {
5
- let cached = store.get(key);
6
- if (cached) return cached;
7
- cached = fn();
8
- if (cached instanceof Promise) {
9
- cached = cached.then((out) => {
10
- if (store.has(key)) {
11
- store.set(key, out);
12
- }
13
- return out;
14
- });
15
- }
16
- store.set(key, cached);
17
- return cached;
18
- },
19
- invalidate(key) {
20
- store.delete(key);
21
- },
22
- $value() {
23
- return this;
24
- }
25
- };
26
- }
27
-
28
- export {
29
- createCache
30
- };
@@ -1,104 +0,0 @@
1
- import {
2
- fumaMatter
3
- } from "./chunk-VWJKRQZR.js";
4
-
5
- // src/collections/mdx/loader.ts
6
- import { z } from "zod";
7
- import fs from "fs/promises";
8
- import path from "path";
9
- import { createHash } from "crypto";
10
- var querySchema = z.object({
11
- only: z.literal(["frontmatter", "all"]).default("all"),
12
- collection: z.string().optional(),
13
- workspace: z.string().optional()
14
- }).loose();
15
- var cacheEntry = z.object({
16
- code: z.string(),
17
- map: z.any().optional(),
18
- hash: z.string().optional()
19
- });
20
- function createMdxLoader({ getCore }) {
21
- return {
22
- async load({
23
- getSource,
24
- development: isDevelopment,
25
- query,
26
- compiler,
27
- filePath
28
- }) {
29
- let core = await getCore();
30
- const value = await getSource();
31
- const matter = fumaMatter(value);
32
- const {
33
- collection: collectionName,
34
- workspace,
35
- only
36
- } = querySchema.parse(query);
37
- if (workspace) {
38
- core = core.getWorkspaces().get(workspace) ?? core;
39
- }
40
- let after;
41
- const { experimentalBuildCache = false } = core.getConfig();
42
- if (!isDevelopment && experimentalBuildCache) {
43
- const cacheDir = experimentalBuildCache;
44
- const cacheKey = `${collectionName ?? "global"}_${generateCacheHash(filePath)}`;
45
- const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
46
- if (cached && cached.hash === generateCacheHash(value)) return cached;
47
- after = async () => {
48
- await fs.mkdir(cacheDir, { recursive: true });
49
- await fs.writeFile(
50
- path.join(cacheDir, cacheKey),
51
- JSON.stringify({
52
- ...out,
53
- hash: generateCacheHash(value)
54
- })
55
- );
56
- };
57
- }
58
- const collection = collectionName ? core.getCollection(collectionName) : void 0;
59
- const handler = collection?.handlers.mdx;
60
- if (collection && handler?.frontmatter) {
61
- matter.data = await handler.frontmatter.call(
62
- { collection, filePath, source: value },
63
- matter.data
64
- );
65
- }
66
- if (only === "frontmatter") {
67
- return {
68
- code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
69
- map: null
70
- };
71
- }
72
- const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
73
- const { buildMDX } = await import("./build-mdx-I4NROXCF.js");
74
- const compiled = await buildMDX(core, collection, {
75
- isDevelopment,
76
- source: "\n".repeat(lineOffset) + matter.content,
77
- filePath,
78
- frontmatter: matter.data,
79
- _compiler: compiler,
80
- environment: "bundler"
81
- });
82
- const out = {
83
- code: String(compiled.value),
84
- map: compiled.map
85
- };
86
- await after?.();
87
- return out;
88
- }
89
- };
90
- }
91
- function generateCacheHash(input) {
92
- return createHash("md5").update(input).digest("hex");
93
- }
94
- function countLines(s) {
95
- let num = 0;
96
- for (const c of s) {
97
- if (c === "\n") num++;
98
- }
99
- return num;
100
- }
101
-
102
- export {
103
- createMdxLoader
104
- };
@@ -1,40 +0,0 @@
1
- import {
2
- buildConfig
3
- } from "./chunk-W6HENTK7.js";
4
-
5
- // src/config/load-from-file.ts
6
- import { pathToFileURL } from "url";
7
- async function compileConfig(core) {
8
- const { build } = await import("esbuild");
9
- const { configPath, outDir } = core.getOptions();
10
- const transformed = await build({
11
- entryPoints: [{ in: configPath, out: "content.config" }],
12
- bundle: true,
13
- outdir: outDir,
14
- target: "node20",
15
- write: true,
16
- platform: "node",
17
- format: "esm",
18
- packages: "external",
19
- outExtension: {
20
- ".js": ".mjs"
21
- },
22
- allowOverwrite: true
23
- });
24
- if (transformed.errors.length > 0) {
25
- throw new Error("failed to compile configuration file");
26
- }
27
- }
28
- async function loadConfig(core, build = false) {
29
- if (build) await compileConfig(core);
30
- const url = pathToFileURL(core.getCompiledConfigPath());
31
- url.searchParams.set("hash", Date.now().toString());
32
- const config = import(url.href).then(
33
- (loaded) => buildConfig(loaded)
34
- );
35
- return await config;
36
- }
37
-
38
- export {
39
- loadConfig
40
- };
@@ -1,167 +0,0 @@
1
- import {
2
- createCache
3
- } from "./chunk-JBZTQ55D.js";
4
-
5
- // src/utils/code-generator.ts
6
- import path from "path";
7
- import { glob } from "tinyglobby";
8
- function importInfo() {
9
- return {
10
- named: /* @__PURE__ */ new Map(),
11
- namespaces: /* @__PURE__ */ new Set(),
12
- isUsed: /* @__PURE__ */ new Set()
13
- };
14
- }
15
- var CodeGenerator = class {
16
- lines = [];
17
- globCache;
18
- // specifier -> imported members/info
19
- importInfos = /* @__PURE__ */ new Map();
20
- eagerImportId = 0;
21
- options;
22
- constructor({
23
- target = "default",
24
- jsExtension = false,
25
- globCache = /* @__PURE__ */ new Map(),
26
- outDir = ""
27
- }) {
28
- this.options = {
29
- target,
30
- jsExtension,
31
- globCache,
32
- outDir
33
- };
34
- this.globCache = createCache(globCache);
35
- }
36
- addNamespaceImport(namespace, specifier, types = false) {
37
- const info = this.importInfos.get(specifier) ?? importInfo();
38
- this.importInfos.set(specifier, info);
39
- if (!types) info.isUsed.add(namespace);
40
- info.namespaces.add(namespace);
41
- }
42
- addNamedImport(names, specifier, types = false) {
43
- const info = this.importInfos.get(specifier) ?? importInfo();
44
- this.importInfos.set(specifier, info);
45
- for (const name of names) {
46
- const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
47
- info.named.set(importName, memberName);
48
- if (!types) info.isUsed.add(importName);
49
- }
50
- }
51
- push(...insert) {
52
- this.lines.push(...insert);
53
- }
54
- async pushAsync(insert) {
55
- for (const line of await Promise.all(insert)) {
56
- if (line === void 0) continue;
57
- this.lines.push(line);
58
- }
59
- }
60
- async generateGlobImport(patterns, options) {
61
- if (this.options.target === "vite") {
62
- return this.generateViteGlobImport(patterns, options);
63
- }
64
- return this.generateNodeGlobImport(patterns, options);
65
- }
66
- generateViteGlobImport(patterns, { base, ...rest }) {
67
- patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
68
- normalizeViteGlobPath
69
- );
70
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
71
- {
72
- base: normalizeViteGlobPath(path.relative(this.options.outDir, base)),
73
- ...rest
74
- },
75
- null,
76
- 2
77
- )})`;
78
- }
79
- async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
80
- const files = await this.globCache.cached(
81
- JSON.stringify({ patterns, base }),
82
- () => glob(patterns, {
83
- cwd: base
84
- })
85
- );
86
- let code = "{";
87
- for (const item of files) {
88
- const fullPath = path.join(base, item);
89
- const searchParams = new URLSearchParams();
90
- for (const [k, v] of Object.entries(query)) {
91
- if (v !== void 0) searchParams.set(k, v);
92
- }
93
- const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
94
- if (eager) {
95
- const name = `__fd_glob_${this.eagerImportId++}`;
96
- this.lines.unshift(
97
- importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
98
- );
99
- code += `${JSON.stringify(item)}: ${name}, `;
100
- } else {
101
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
102
- if (importName) {
103
- line += `.then(mod => mod.${importName})`;
104
- }
105
- code += `${line}, `;
106
- }
107
- }
108
- code += "}";
109
- return code;
110
- }
111
- formatImportPath(file) {
112
- const ext = path.extname(file);
113
- let filename;
114
- if (ext === ".ts") {
115
- filename = file.substring(0, file.length - ext.length);
116
- if (this.options.jsExtension) filename += ".js";
117
- } else {
118
- filename = file;
119
- }
120
- const importPath = slash(path.relative(this.options.outDir, filename));
121
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
122
- }
123
- toString() {
124
- const final = ["// @ts-nocheck"];
125
- if (this.options.target === "vite") {
126
- final.push('/// <reference types="vite/client" />');
127
- }
128
- for (const [specifier, info] of this.importInfos) {
129
- const { namespaces, named, isUsed } = info;
130
- for (const namespace of namespaces) {
131
- final.push(
132
- isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`
133
- );
134
- }
135
- const namedImports = [];
136
- for (const [importName, memberName] of named) {
137
- const item = importName === memberName ? importName : `${memberName} as ${importName}`;
138
- namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
139
- }
140
- if (namedImports.length > 0) {
141
- final.push(
142
- `import { ${namedImports.join(", ")} } from "${specifier}";`
143
- );
144
- }
145
- }
146
- final.push(...this.lines);
147
- return final.join("\n");
148
- }
149
- };
150
- function normalizeViteGlobPath(file) {
151
- file = slash(file);
152
- if (file.startsWith("./")) return file;
153
- if (file.startsWith("/")) return `.${file}`;
154
- return `./${file}`;
155
- }
156
- function slash(path2) {
157
- const isExtendedLengthPath = path2.startsWith("\\\\?\\");
158
- if (isExtendedLengthPath) {
159
- return path2;
160
- }
161
- return path2.replaceAll("\\", "/");
162
- }
163
-
164
- export {
165
- CodeGenerator,
166
- slash
167
- };