@navita/core 0.0.13 → 0.1.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.
- package/createRenderer.cjs +9 -1
- package/createRenderer.d.ts +1 -0
- package/createRenderer.mjs +9 -1
- package/evaluateAndProcess.cjs +4 -4
- package/evaluateAndProcess.d.ts +4 -3
- package/evaluateAndProcess.mjs +4 -4
- package/helpers/setAdapter.cjs +6 -9
- package/helpers/setAdapter.mjs +6 -9
- package/package.json +5 -5
package/createRenderer.cjs
CHANGED
|
@@ -4,14 +4,21 @@ var engine = require('@navita/engine');
|
|
|
4
4
|
var MagicString = require('magic-string');
|
|
5
5
|
var evaluateAndProcess = require('./evaluateAndProcess.cjs');
|
|
6
6
|
|
|
7
|
+
const resultCache = {};
|
|
7
8
|
function createRenderer({ resolver , readFile , importMap =[] , engineOptions , context }) {
|
|
8
9
|
const engine$1 = new engine.Engine({
|
|
9
10
|
context,
|
|
10
11
|
...engineOptions || {}
|
|
11
12
|
});
|
|
13
|
+
const clearCache = (filePath)=>{
|
|
14
|
+
engine$1.clearCache(filePath);
|
|
15
|
+
resultCache[filePath] = [];
|
|
16
|
+
};
|
|
12
17
|
return {
|
|
13
18
|
engine: engine$1,
|
|
19
|
+
clearCache,
|
|
14
20
|
async transformAndProcess ({ content , filePath }) {
|
|
21
|
+
clearCache(filePath);
|
|
15
22
|
const { result , dependencies } = await evaluateAndProcess.evaluateAndProcess({
|
|
16
23
|
type: 'entryPoint',
|
|
17
24
|
source: content,
|
|
@@ -19,7 +26,8 @@ function createRenderer({ resolver , readFile , importMap =[] , engineOptions ,
|
|
|
19
26
|
resolver,
|
|
20
27
|
readFile,
|
|
21
28
|
importMap,
|
|
22
|
-
engine: engine$1
|
|
29
|
+
engine: engine$1,
|
|
30
|
+
resultCache
|
|
23
31
|
});
|
|
24
32
|
const newSource = new MagicString(content, {
|
|
25
33
|
filename: filePath
|
package/createRenderer.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface Options {
|
|
|
13
13
|
}
|
|
14
14
|
declare function createRenderer({ resolver, readFile, importMap, engineOptions, context, }: Options): {
|
|
15
15
|
engine: Engine;
|
|
16
|
+
clearCache: (filePath: string) => void;
|
|
16
17
|
transformAndProcess({ content, filePath, }: {
|
|
17
18
|
content: string;
|
|
18
19
|
filePath: string;
|
package/createRenderer.mjs
CHANGED
|
@@ -2,14 +2,21 @@ import { Engine } from '@navita/engine';
|
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
3
|
import { evaluateAndProcess } from './evaluateAndProcess.mjs';
|
|
4
4
|
|
|
5
|
+
const resultCache = {};
|
|
5
6
|
function createRenderer({ resolver , readFile , importMap =[] , engineOptions , context }) {
|
|
6
7
|
const engine = new Engine({
|
|
7
8
|
context,
|
|
8
9
|
...engineOptions || {}
|
|
9
10
|
});
|
|
11
|
+
const clearCache = (filePath)=>{
|
|
12
|
+
engine.clearCache(filePath);
|
|
13
|
+
resultCache[filePath] = [];
|
|
14
|
+
};
|
|
10
15
|
return {
|
|
11
16
|
engine,
|
|
17
|
+
clearCache,
|
|
12
18
|
async transformAndProcess ({ content , filePath }) {
|
|
19
|
+
clearCache(filePath);
|
|
13
20
|
const { result , dependencies } = await evaluateAndProcess({
|
|
14
21
|
type: 'entryPoint',
|
|
15
22
|
source: content,
|
|
@@ -17,7 +24,8 @@ function createRenderer({ resolver , readFile , importMap =[] , engineOptions ,
|
|
|
17
24
|
resolver,
|
|
18
25
|
readFile,
|
|
19
26
|
importMap,
|
|
20
|
-
engine
|
|
27
|
+
engine,
|
|
28
|
+
resultCache
|
|
21
29
|
});
|
|
22
30
|
const newSource = new MagicString(content, {
|
|
23
31
|
filename: filePath
|
package/evaluateAndProcess.cjs
CHANGED
|
@@ -11,8 +11,8 @@ const isExternal = (dependency)=>dependency.startsWith(rootDir) || dependency.in
|
|
|
11
11
|
const defaultNodeModuleCache = {};
|
|
12
12
|
const defaultResolverCache = {};
|
|
13
13
|
const defaultModuleCache = new Map();
|
|
14
|
-
const
|
|
15
|
-
async function evaluateAndProcess({ type , filePath , source , engine , resolver , readFile , importMap , nodeModuleCache =defaultNodeModuleCache , resolverCache =defaultResolverCache , moduleCache =defaultModuleCache }) {
|
|
14
|
+
const defaultResultCache = {};
|
|
15
|
+
async function evaluateAndProcess({ type , filePath , source , engine , resolver , readFile , importMap , nodeModuleCache =defaultNodeModuleCache , resolverCache =defaultResolverCache , moduleCache =defaultModuleCache , resultCache =defaultResultCache }) {
|
|
16
16
|
const cacheKey = `${filePath}:${type}`;
|
|
17
17
|
const compiledFn = await (async ()=>{
|
|
18
18
|
if (moduleCache.has(cacheKey)) {
|
|
@@ -34,7 +34,7 @@ async function evaluateAndProcess({ type , filePath , source , engine , resolver
|
|
|
34
34
|
nodeModuleCache,
|
|
35
35
|
setAdapter: ()=>helpers_setAdapter.setAdapter({
|
|
36
36
|
engine,
|
|
37
|
-
|
|
37
|
+
resultCache: resultCache
|
|
38
38
|
})
|
|
39
39
|
}, (dependency)=>readFile(dependency).then((source)=>evaluateAndProcess({
|
|
40
40
|
type: 'dependency',
|
|
@@ -58,7 +58,7 @@ async function evaluateAndProcess({ type , filePath , source , engine , resolver
|
|
|
58
58
|
return compiledFn().then(({ dependencies , exports })=>{
|
|
59
59
|
if (type === 'entryPoint') {
|
|
60
60
|
return {
|
|
61
|
-
result:
|
|
61
|
+
result: resultCache[filePath] || [],
|
|
62
62
|
dependencies
|
|
63
63
|
};
|
|
64
64
|
}
|
package/evaluateAndProcess.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type ResolverCache = Record<FilePath$1, unknown>;
|
|
|
6
6
|
type NodeModuleCache = Record<FilePath$1, unknown>;
|
|
7
7
|
|
|
8
8
|
type FilePath = string;
|
|
9
|
-
type
|
|
9
|
+
type ResultCache = Record<FilePath, {
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
12
|
value: string;
|
|
@@ -24,13 +24,14 @@ interface Caches {
|
|
|
24
24
|
nodeModuleCache?: NodeModuleCache;
|
|
25
25
|
resolverCache?: ResolverCache;
|
|
26
26
|
moduleCache?: ModuleCache;
|
|
27
|
+
resultCache?: ResultCache;
|
|
27
28
|
}
|
|
28
29
|
type Types = 'entryPoint' | 'dependency';
|
|
29
30
|
interface Output<Type extends Types> {
|
|
30
|
-
result: Type extends 'entryPoint' ?
|
|
31
|
+
result: Type extends 'entryPoint' ? ResultCache[number] : Record<string, unknown>;
|
|
31
32
|
dependencies: string[];
|
|
32
33
|
}
|
|
33
|
-
declare function evaluateAndProcess<Type extends 'entryPoint' | 'dependency'>({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache, resolverCache, moduleCache, }: {
|
|
34
|
+
declare function evaluateAndProcess<Type extends 'entryPoint' | 'dependency'>({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache, resolverCache, moduleCache, resultCache, }: {
|
|
34
35
|
source: string;
|
|
35
36
|
filePath: string;
|
|
36
37
|
type: Type;
|
package/evaluateAndProcess.mjs
CHANGED
|
@@ -13,8 +13,8 @@ const isExternal = (dependency)=>dependency.startsWith(rootDir) || dependency.in
|
|
|
13
13
|
const defaultNodeModuleCache = {};
|
|
14
14
|
const defaultResolverCache = {};
|
|
15
15
|
const defaultModuleCache = new Map();
|
|
16
|
-
const
|
|
17
|
-
async function evaluateAndProcess({ type , filePath , source , engine , resolver , readFile , importMap , nodeModuleCache =defaultNodeModuleCache , resolverCache =defaultResolverCache , moduleCache =defaultModuleCache }) {
|
|
16
|
+
const defaultResultCache = {};
|
|
17
|
+
async function evaluateAndProcess({ type , filePath , source , engine , resolver , readFile , importMap , nodeModuleCache =defaultNodeModuleCache , resolverCache =defaultResolverCache , moduleCache =defaultModuleCache , resultCache =defaultResultCache }) {
|
|
18
18
|
const cacheKey = `${filePath}:${type}`;
|
|
19
19
|
const compiledFn = await (async ()=>{
|
|
20
20
|
if (moduleCache.has(cacheKey)) {
|
|
@@ -36,7 +36,7 @@ async function evaluateAndProcess({ type , filePath , source , engine , resolver
|
|
|
36
36
|
nodeModuleCache,
|
|
37
37
|
setAdapter: ()=>setAdapter({
|
|
38
38
|
engine,
|
|
39
|
-
|
|
39
|
+
resultCache: resultCache
|
|
40
40
|
})
|
|
41
41
|
}, (dependency)=>readFile(dependency).then((source)=>evaluateAndProcess({
|
|
42
42
|
type: 'dependency',
|
|
@@ -60,7 +60,7 @@ async function evaluateAndProcess({ type , filePath , source , engine , resolver
|
|
|
60
60
|
return compiledFn().then(({ dependencies , exports })=>{
|
|
61
61
|
if (type === 'entryPoint') {
|
|
62
62
|
return {
|
|
63
|
-
result:
|
|
63
|
+
result: resultCache[filePath] || [],
|
|
64
64
|
dependencies
|
|
65
65
|
};
|
|
66
66
|
}
|
package/helpers/setAdapter.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var adapter = require('@navita/adapter');
|
|
4
4
|
var engine = require('@navita/engine');
|
|
5
5
|
|
|
6
|
-
function setAdapter({ engine: engine$1 ,
|
|
6
|
+
function setAdapter({ engine: engine$1 , resultCache , }) {
|
|
7
7
|
adapter.setAdapter({
|
|
8
8
|
generateIdentifier: (value)=>engine$1.generateIdentifier(value),
|
|
9
9
|
addStaticCss: (selector, css)=>engine$1.addStatic(selector, css),
|
|
@@ -19,12 +19,6 @@ function setAdapter({ engine: engine$1 , collectResults , }) {
|
|
|
19
19
|
return engine$1.addFontFace(fontFace);
|
|
20
20
|
},
|
|
21
21
|
collectResult ({ index , filePath , identifier , result: resultFactory , sourceMap: { line , column } , position , }) {
|
|
22
|
-
if (index === 0) {
|
|
23
|
-
if (collectResults) {
|
|
24
|
-
collectResults[filePath] = [];
|
|
25
|
-
}
|
|
26
|
-
engine$1.clearUsedIds(filePath);
|
|
27
|
-
}
|
|
28
22
|
engine$1.setFilePath(filePath);
|
|
29
23
|
let result = resultFactory();
|
|
30
24
|
engine$1.setFilePath(undefined);
|
|
@@ -44,9 +38,12 @@ function setAdapter({ engine: engine$1 , collectResults , }) {
|
|
|
44
38
|
].join(' '));
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
|
-
if (
|
|
41
|
+
if (resultCache) {
|
|
42
|
+
if (!resultCache[filePath]) {
|
|
43
|
+
resultCache[filePath] = [];
|
|
44
|
+
}
|
|
48
45
|
const [start, end] = position;
|
|
49
|
-
|
|
46
|
+
resultCache[filePath][index] = {
|
|
50
47
|
start,
|
|
51
48
|
end,
|
|
52
49
|
value: result === undefined ? "undefined" : JSON.stringify(result)
|
package/helpers/setAdapter.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setAdapter as setAdapter$1 } from '@navita/adapter';
|
|
2
2
|
import { ClassList } from '@navita/engine';
|
|
3
3
|
|
|
4
|
-
function setAdapter({ engine ,
|
|
4
|
+
function setAdapter({ engine , resultCache , }) {
|
|
5
5
|
setAdapter$1({
|
|
6
6
|
generateIdentifier: (value)=>engine.generateIdentifier(value),
|
|
7
7
|
addStaticCss: (selector, css)=>engine.addStatic(selector, css),
|
|
@@ -17,12 +17,6 @@ function setAdapter({ engine , collectResults , }) {
|
|
|
17
17
|
return engine.addFontFace(fontFace);
|
|
18
18
|
},
|
|
19
19
|
collectResult ({ index , filePath , identifier , result: resultFactory , sourceMap: { line , column } , position , }) {
|
|
20
|
-
if (index === 0) {
|
|
21
|
-
if (collectResults) {
|
|
22
|
-
collectResults[filePath] = [];
|
|
23
|
-
}
|
|
24
|
-
engine.clearUsedIds(filePath);
|
|
25
|
-
}
|
|
26
20
|
engine.setFilePath(filePath);
|
|
27
21
|
let result = resultFactory();
|
|
28
22
|
engine.setFilePath(undefined);
|
|
@@ -42,9 +36,12 @@ function setAdapter({ engine , collectResults , }) {
|
|
|
42
36
|
].join(' '));
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
if (
|
|
39
|
+
if (resultCache) {
|
|
40
|
+
if (!resultCache[filePath]) {
|
|
41
|
+
resultCache[filePath] = [];
|
|
42
|
+
}
|
|
46
43
|
const [start, end] = position;
|
|
47
|
-
|
|
44
|
+
resultCache[filePath][index] = {
|
|
48
45
|
start,
|
|
49
46
|
end,
|
|
50
47
|
value: result === undefined ? "undefined" : JSON.stringify(result)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Core package for Navita. Used for creating integrations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"core",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"enhanced-resolve": "^5.15.0",
|
|
29
29
|
"outdent": "^0.8.0",
|
|
30
30
|
"magic-string": "^0.30.3",
|
|
31
|
-
"@navita/types": "0.0
|
|
32
|
-
"@navita/adapter": "0.0
|
|
33
|
-
"@navita/swc": "0.0
|
|
34
|
-
"@navita/engine": "0.
|
|
31
|
+
"@navita/types": "0.1.0",
|
|
32
|
+
"@navita/adapter": "0.1.0",
|
|
33
|
+
"@navita/swc": "0.1.0",
|
|
34
|
+
"@navita/engine": "0.1.1"
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"author": "Eagerpatch",
|