@navita/core 1.0.1 → 3.0.0-next.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/_virtual/_rolldown/runtime.cjs +23 -0
- package/createRenderer.cjs +49 -48
- package/createRenderer.d.ts +31 -24
- package/createRenderer.mjs +49 -46
- package/evaluateAndProcess.cjs +63 -67
- package/evaluateAndProcess.d.ts +44 -29
- package/evaluateAndProcess.mjs +64 -69
- package/helpers/createCompiledFunction.cjs +21 -27
- package/helpers/createCompiledFunction.mjs +20 -24
- package/helpers/createDefineFunction.cjs +75 -92
- package/helpers/createDefineFunction.mjs +74 -94
- package/helpers/magicProxy.cjs +4 -8
- package/helpers/magicProxy.mjs +6 -6
- package/helpers/setAdapter.cjs +42 -55
- package/helpers/setAdapter.mjs +44 -53
- package/package.json +6 -6
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
package/createRenderer.cjs
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function createRenderer({ resolver
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_evaluateAndProcess = require("./evaluateAndProcess.cjs");
|
|
4
|
+
let _navita_engine = require("@navita/engine");
|
|
5
|
+
let magic_string = require("magic-string");
|
|
6
|
+
magic_string = require_runtime.__toESM(magic_string);
|
|
7
|
+
//#region src/createRenderer.ts
|
|
8
|
+
function createRenderer({ resolver, readFile, importMap = [], engineOptions, context }) {
|
|
9
|
+
const engine = new _navita_engine.Engine({
|
|
10
|
+
context,
|
|
11
|
+
...engineOptions || {}
|
|
12
|
+
});
|
|
13
|
+
const resultCache = {};
|
|
14
|
+
const moduleCache = /* @__PURE__ */ new Map();
|
|
15
|
+
const nodeModuleCache = {};
|
|
16
|
+
const resolverCache = {};
|
|
17
|
+
const clearCache = (filePath) => {
|
|
18
|
+
engine.clearCache(filePath);
|
|
19
|
+
resultCache[filePath] = [];
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
engine,
|
|
23
|
+
clearCache,
|
|
24
|
+
async transformAndProcess({ content, filePath }) {
|
|
25
|
+
clearCache(filePath);
|
|
26
|
+
const { result, dependencies } = await require_evaluateAndProcess.evaluateAndProcess({
|
|
27
|
+
type: "entryPoint",
|
|
28
|
+
source: content,
|
|
29
|
+
filePath,
|
|
30
|
+
resolver,
|
|
31
|
+
readFile,
|
|
32
|
+
importMap,
|
|
33
|
+
engine,
|
|
34
|
+
resultCache,
|
|
35
|
+
moduleCache,
|
|
36
|
+
nodeModuleCache,
|
|
37
|
+
resolverCache
|
|
38
|
+
});
|
|
39
|
+
const newSource = new magic_string.default(content, { filename: filePath });
|
|
40
|
+
for (const { start, end, value } of result.reverse()) newSource.update(start, end, value);
|
|
41
|
+
return {
|
|
42
|
+
result: newSource.toString(),
|
|
43
|
+
dependencies,
|
|
44
|
+
usedIds: engine.getCacheIds([filePath]),
|
|
45
|
+
sourceMap: newSource.generateMap()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
//#endregion
|
|
50
51
|
exports.createRenderer = createRenderer;
|
package/createRenderer.d.ts
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export { Engine, Options as EngineOptions, UsedIdCache } from '@navita/engine';
|
|
4
|
-
import { ImportMap } from '@navita/types';
|
|
5
|
-
export { ImportMap } from '@navita/types';
|
|
1
|
+
import { Engine, Options as EngineOptions, UsedIdCache } from "@navita/engine";
|
|
2
|
+
import { ImportMap } from "@navita/types";
|
|
6
3
|
|
|
4
|
+
//#region src/createRenderer.d.ts
|
|
7
5
|
interface Options {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
resolver: (filepath: string, request: string) => Promise<string>;
|
|
7
|
+
readFile: (filepath: string) => Promise<string>;
|
|
8
|
+
importMap: ImportMap;
|
|
9
|
+
engineOptions?: EngineOptions;
|
|
10
|
+
context?: string;
|
|
13
11
|
}
|
|
14
|
-
declare function createRenderer({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
declare function createRenderer({
|
|
13
|
+
resolver,
|
|
14
|
+
readFile,
|
|
15
|
+
importMap,
|
|
16
|
+
engineOptions,
|
|
17
|
+
context
|
|
18
|
+
}: Options): {
|
|
19
|
+
engine: Engine;
|
|
20
|
+
clearCache: (filePath: string) => void;
|
|
21
|
+
transformAndProcess({
|
|
22
|
+
content,
|
|
23
|
+
filePath
|
|
24
|
+
}: {
|
|
25
|
+
content: string;
|
|
26
|
+
filePath: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
result: string;
|
|
29
|
+
dependencies: string[];
|
|
30
|
+
usedIds: UsedIdCache;
|
|
31
|
+
sourceMap: import("magic-string").SourceMap;
|
|
32
|
+
}>;
|
|
26
33
|
};
|
|
27
34
|
type Renderer = ReturnType<typeof createRenderer>;
|
|
28
|
-
|
|
29
|
-
export { Options, Renderer, createRenderer };
|
|
35
|
+
//#endregion
|
|
36
|
+
export { type Engine, type EngineOptions, type ImportMap, Options, Renderer, type UsedIdCache, createRenderer };
|
package/createRenderer.mjs
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { evaluateAndProcess } from "./evaluateAndProcess.mjs";
|
|
5
|
+
import { Engine } from "@navita/engine";
|
|
6
|
+
import MagicString from "magic-string";
|
|
7
|
+
//#region src/createRenderer.ts
|
|
8
|
+
function createRenderer({ resolver, readFile, importMap = [], engineOptions, context }) {
|
|
9
|
+
const engine = new Engine({
|
|
10
|
+
context,
|
|
11
|
+
...engineOptions || {}
|
|
12
|
+
});
|
|
13
|
+
const resultCache = {};
|
|
14
|
+
const moduleCache = /* @__PURE__ */ new Map();
|
|
15
|
+
const nodeModuleCache = {};
|
|
16
|
+
const resolverCache = {};
|
|
17
|
+
const clearCache = (filePath) => {
|
|
18
|
+
engine.clearCache(filePath);
|
|
19
|
+
resultCache[filePath] = [];
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
engine,
|
|
23
|
+
clearCache,
|
|
24
|
+
async transformAndProcess({ content, filePath }) {
|
|
25
|
+
clearCache(filePath);
|
|
26
|
+
const { result, dependencies } = await evaluateAndProcess({
|
|
27
|
+
type: "entryPoint",
|
|
28
|
+
source: content,
|
|
29
|
+
filePath,
|
|
30
|
+
resolver,
|
|
31
|
+
readFile,
|
|
32
|
+
importMap,
|
|
33
|
+
engine,
|
|
34
|
+
resultCache,
|
|
35
|
+
moduleCache,
|
|
36
|
+
nodeModuleCache,
|
|
37
|
+
resolverCache
|
|
38
|
+
});
|
|
39
|
+
const newSource = new MagicString(content, { filename: filePath });
|
|
40
|
+
for (const { start, end, value } of result.reverse()) newSource.update(start, end, value);
|
|
41
|
+
return {
|
|
42
|
+
result: newSource.toString(),
|
|
43
|
+
dependencies,
|
|
44
|
+
usedIds: engine.getCacheIds([filePath]),
|
|
45
|
+
sourceMap: newSource.generateMap()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
//#endregion
|
|
48
51
|
export { createRenderer };
|
package/evaluateAndProcess.cjs
CHANGED
|
@@ -1,72 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_helpers_createCompiledFunction = require("./helpers/createCompiledFunction.cjs");
|
|
4
|
+
const require_helpers_createDefineFunction = require("./helpers/createDefineFunction.cjs");
|
|
5
|
+
const require_helpers_setAdapter = require("./helpers/setAdapter.cjs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_runtime.__toESM(node_path);
|
|
8
|
+
let _navita_extraction = require("@navita/extraction");
|
|
9
|
+
//#region src/evaluateAndProcess.ts
|
|
10
|
+
const rootDir = node_path.default.resolve(__dirname, "../../");
|
|
11
|
+
const isExternal = (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules");
|
|
11
12
|
const defaultNodeModuleCache = {};
|
|
12
13
|
const defaultResolverCache = {};
|
|
13
|
-
const defaultModuleCache = new Map();
|
|
14
|
+
const defaultModuleCache = /* @__PURE__ */ new Map();
|
|
14
15
|
const defaultResultCache = {};
|
|
15
|
-
async function evaluateAndProcess({ type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
result: exports,
|
|
67
|
-
dependencies
|
|
68
|
-
};
|
|
69
|
-
});
|
|
16
|
+
async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
|
|
17
|
+
const cacheKey = `${filePath}:${type}`;
|
|
18
|
+
return (await (async () => {
|
|
19
|
+
if (moduleCache.has(cacheKey)) {
|
|
20
|
+
const cache = moduleCache.get(cacheKey);
|
|
21
|
+
if (cache.source === source) return cache.compiledFn;
|
|
22
|
+
}
|
|
23
|
+
const newSource = await (0, _navita_extraction.extraction)(source, {
|
|
24
|
+
filename: filePath,
|
|
25
|
+
entryPoint: type === "entryPoint",
|
|
26
|
+
importMap
|
|
27
|
+
});
|
|
28
|
+
const define = require_helpers_createDefineFunction.createDefineFunction({
|
|
29
|
+
filePath,
|
|
30
|
+
resolver,
|
|
31
|
+
isExternal,
|
|
32
|
+
resolverCache,
|
|
33
|
+
nodeModuleCache,
|
|
34
|
+
setAdapter: () => require_helpers_setAdapter.setAdapter({
|
|
35
|
+
engine,
|
|
36
|
+
resultCache
|
|
37
|
+
})
|
|
38
|
+
}, (dependency) => readFile(dependency).then((source) => evaluateAndProcess({
|
|
39
|
+
type: "dependency",
|
|
40
|
+
source: source.toString(),
|
|
41
|
+
filePath: dependency,
|
|
42
|
+
engine,
|
|
43
|
+
resolver,
|
|
44
|
+
readFile,
|
|
45
|
+
importMap,
|
|
46
|
+
nodeModuleCache,
|
|
47
|
+
resolverCache,
|
|
48
|
+
moduleCache
|
|
49
|
+
})).then(({ result }) => result));
|
|
50
|
+
const compiledFn = require_helpers_createCompiledFunction.createCompiledFunction(`return ${newSource}`, define);
|
|
51
|
+
moduleCache.set(cacheKey, {
|
|
52
|
+
source,
|
|
53
|
+
compiledFn
|
|
54
|
+
});
|
|
55
|
+
return compiledFn;
|
|
56
|
+
})())().then(({ dependencies, exports }) => {
|
|
57
|
+
if (type === "entryPoint") return {
|
|
58
|
+
result: resultCache[filePath] || [],
|
|
59
|
+
dependencies
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
result: exports,
|
|
63
|
+
dependencies
|
|
64
|
+
};
|
|
65
|
+
});
|
|
70
66
|
}
|
|
71
|
-
|
|
67
|
+
//#endregion
|
|
72
68
|
exports.evaluateAndProcess = evaluateAndProcess;
|
package/evaluateAndProcess.d.ts
CHANGED
|
@@ -1,44 +1,59 @@
|
|
|
1
|
-
import { Engine } from
|
|
2
|
-
import { ImportMap } from
|
|
1
|
+
import { Engine } from "@navita/engine";
|
|
2
|
+
import { ImportMap } from "@navita/types";
|
|
3
3
|
|
|
4
|
+
//#region src/helpers/createDefineFunction.d.ts
|
|
4
5
|
type FilePath$1 = string;
|
|
5
6
|
type ResolverCache = Record<FilePath$1, unknown>;
|
|
6
7
|
type NodeModuleCache = Record<FilePath$1, unknown>;
|
|
7
|
-
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/helpers/setAdapter.d.ts
|
|
8
10
|
type FilePath = string;
|
|
9
11
|
type ResultCache = Record<FilePath, {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
value: string;
|
|
13
15
|
}[]>;
|
|
14
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/evaluateAndProcess.d.ts
|
|
15
18
|
type FilePathWithType = string;
|
|
16
19
|
type ModuleCache = Map<FilePathWithType, {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
source: string;
|
|
21
|
+
compiledFn: () => Promise<{
|
|
22
|
+
dependencies: string[];
|
|
23
|
+
exports: Record<string, unknown>;
|
|
24
|
+
}>;
|
|
22
25
|
}>;
|
|
23
26
|
interface Caches {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
nodeModuleCache?: NodeModuleCache;
|
|
28
|
+
resolverCache?: ResolverCache;
|
|
29
|
+
moduleCache?: ModuleCache;
|
|
30
|
+
resultCache?: ResultCache;
|
|
28
31
|
}
|
|
29
|
-
type Types =
|
|
32
|
+
type Types = "entryPoint" | "dependency";
|
|
30
33
|
interface Output<Type extends Types> {
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
result: Type extends "entryPoint" ? ResultCache[number] : Record<string, unknown>;
|
|
35
|
+
dependencies: string[];
|
|
33
36
|
}
|
|
34
|
-
declare function evaluateAndProcess<Type extends
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
declare function evaluateAndProcess<Type extends "entryPoint" | "dependency">({
|
|
38
|
+
type,
|
|
39
|
+
filePath,
|
|
40
|
+
source,
|
|
41
|
+
engine,
|
|
42
|
+
resolver,
|
|
43
|
+
readFile,
|
|
44
|
+
importMap,
|
|
45
|
+
nodeModuleCache,
|
|
46
|
+
resolverCache,
|
|
47
|
+
moduleCache,
|
|
48
|
+
resultCache
|
|
49
|
+
}: {
|
|
50
|
+
source: string;
|
|
51
|
+
filePath: string;
|
|
52
|
+
type: Type;
|
|
53
|
+
engine: Engine;
|
|
54
|
+
resolver: (filePath: string, request: string) => Promise<string>;
|
|
55
|
+
readFile: (filePath: string) => Promise<string>;
|
|
56
|
+
importMap: ImportMap;
|
|
42
57
|
} & Caches): Promise<Output<Type>>;
|
|
43
|
-
|
|
44
|
-
export { Caches, evaluateAndProcess };
|
|
58
|
+
//#endregion
|
|
59
|
+
export { Caches, evaluateAndProcess };
|
package/evaluateAndProcess.mjs
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
const rootDir = path.resolve(
|
|
12
|
-
const isExternal = (dependency)=>dependency.startsWith(rootDir) || dependency.includes(
|
|
1
|
+
import __tsdown_shims_path from "node:path";
|
|
2
|
+
import __tsdown_shims_url from "node:url";
|
|
3
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url);
|
|
4
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__);
|
|
5
|
+
import { createCompiledFunction } from "./helpers/createCompiledFunction.mjs";
|
|
6
|
+
import { createDefineFunction } from "./helpers/createDefineFunction.mjs";
|
|
7
|
+
import { setAdapter } from "./helpers/setAdapter.mjs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { extraction } from "@navita/extraction";
|
|
10
|
+
//#region src/evaluateAndProcess.ts
|
|
11
|
+
const rootDir = path.resolve(__TSDOWN_SHIM_DIRNAME__, "../../");
|
|
12
|
+
const isExternal = (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules");
|
|
13
13
|
const defaultNodeModuleCache = {};
|
|
14
14
|
const defaultResolverCache = {};
|
|
15
|
-
const defaultModuleCache = new Map();
|
|
15
|
+
const defaultModuleCache = /* @__PURE__ */ new Map();
|
|
16
16
|
const defaultResultCache = {};
|
|
17
|
-
async function evaluateAndProcess({ type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
result: exports,
|
|
69
|
-
dependencies
|
|
70
|
-
};
|
|
71
|
-
});
|
|
17
|
+
async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
|
|
18
|
+
const cacheKey = `${filePath}:${type}`;
|
|
19
|
+
return (await (async () => {
|
|
20
|
+
if (moduleCache.has(cacheKey)) {
|
|
21
|
+
const cache = moduleCache.get(cacheKey);
|
|
22
|
+
if (cache.source === source) return cache.compiledFn;
|
|
23
|
+
}
|
|
24
|
+
const newSource = await extraction(source, {
|
|
25
|
+
filename: filePath,
|
|
26
|
+
entryPoint: type === "entryPoint",
|
|
27
|
+
importMap
|
|
28
|
+
});
|
|
29
|
+
const define = createDefineFunction({
|
|
30
|
+
filePath,
|
|
31
|
+
resolver,
|
|
32
|
+
isExternal,
|
|
33
|
+
resolverCache,
|
|
34
|
+
nodeModuleCache,
|
|
35
|
+
setAdapter: () => setAdapter({
|
|
36
|
+
engine,
|
|
37
|
+
resultCache
|
|
38
|
+
})
|
|
39
|
+
}, (dependency) => readFile(dependency).then((source) => evaluateAndProcess({
|
|
40
|
+
type: "dependency",
|
|
41
|
+
source: source.toString(),
|
|
42
|
+
filePath: dependency,
|
|
43
|
+
engine,
|
|
44
|
+
resolver,
|
|
45
|
+
readFile,
|
|
46
|
+
importMap,
|
|
47
|
+
nodeModuleCache,
|
|
48
|
+
resolverCache,
|
|
49
|
+
moduleCache
|
|
50
|
+
})).then(({ result }) => result));
|
|
51
|
+
const compiledFn = createCompiledFunction(`return ${newSource}`, define);
|
|
52
|
+
moduleCache.set(cacheKey, {
|
|
53
|
+
source,
|
|
54
|
+
compiledFn
|
|
55
|
+
});
|
|
56
|
+
return compiledFn;
|
|
57
|
+
})())().then(({ dependencies, exports }) => {
|
|
58
|
+
if (type === "entryPoint") return {
|
|
59
|
+
result: resultCache[filePath] || [],
|
|
60
|
+
dependencies
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
result: exports,
|
|
64
|
+
dependencies
|
|
65
|
+
};
|
|
66
|
+
});
|
|
72
67
|
}
|
|
73
|
-
|
|
68
|
+
//#endregion
|
|
74
69
|
export { evaluateAndProcess };
|