@navita/core 3.0.0-next.1 → 3.0.0-next.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.
@@ -5,7 +5,7 @@ let _navita_engine = require("@navita/engine");
5
5
  let magic_string = require("magic-string");
6
6
  magic_string = require_runtime.__toESM(magic_string);
7
7
  //#region src/createRenderer.ts
8
- function createRenderer({ resolver, readFile, importMap = [], engineOptions, context }) {
8
+ function createRenderer({ resolver, readFile, importMap = [], engineOptions, context, transformNodeModules = [] }) {
9
9
  const engine = new _navita_engine.Engine({
10
10
  context,
11
11
  ...engineOptions || {}
@@ -30,6 +30,7 @@ function createRenderer({ resolver, readFile, importMap = [], engineOptions, con
30
30
  resolver,
31
31
  readFile,
32
32
  importMap,
33
+ transformNodeModules,
33
34
  engine,
34
35
  resultCache,
35
36
  moduleCache,
@@ -1,3 +1,4 @@
1
+ import { n as NodeModuleMatcher } from "./evaluateAndProcess-Bd56H_hx.js";
1
2
  import { Engine, Options as EngineOptions, UsedIdCache } from "@navita/engine";
2
3
  import { ImportMap } from "@navita/types";
3
4
 
@@ -8,13 +9,20 @@ interface Options {
8
9
  importMap: ImportMap;
9
10
  engineOptions?: EngineOptions;
10
11
  context?: string;
12
+ /**
13
+ * `node_modules` paths that should be recursively evaluated instead of
14
+ * imported as opaque modules — a library authored WITH navita. Each matcher
15
+ * is a substring (`id.includes(...)`) or a `RegExp` tested against the id.
16
+ */
17
+ transformNodeModules?: NodeModuleMatcher[];
11
18
  }
12
19
  declare function createRenderer({
13
20
  resolver,
14
21
  readFile,
15
22
  importMap,
16
23
  engineOptions,
17
- context
24
+ context,
25
+ transformNodeModules
18
26
  }: Options): {
19
27
  engine: Engine;
20
28
  clearCache: (filePath: string) => void;
@@ -33,4 +41,4 @@ declare function createRenderer({
33
41
  };
34
42
  type Renderer = ReturnType<typeof createRenderer>;
35
43
  //#endregion
36
- export { type Engine, type EngineOptions, type ImportMap, Options, Renderer, type UsedIdCache, createRenderer };
44
+ export { type Engine, type EngineOptions, type ImportMap, type NodeModuleMatcher, Options, Renderer, type UsedIdCache, createRenderer };
@@ -5,7 +5,7 @@ import { evaluateAndProcess } from "./evaluateAndProcess.mjs";
5
5
  import { Engine } from "@navita/engine";
6
6
  import MagicString from "magic-string";
7
7
  //#region src/createRenderer.ts
8
- function createRenderer({ resolver, readFile, importMap = [], engineOptions, context }) {
8
+ function createRenderer({ resolver, readFile, importMap = [], engineOptions, context, transformNodeModules = [] }) {
9
9
  const engine = new Engine({
10
10
  context,
11
11
  ...engineOptions || {}
@@ -30,6 +30,7 @@ function createRenderer({ resolver, readFile, importMap = [], engineOptions, con
30
30
  resolver,
31
31
  readFile,
32
32
  importMap,
33
+ transformNodeModules,
33
34
  engine,
34
35
  resultCache,
35
36
  moduleCache,
@@ -0,0 +1,74 @@
1
+ import { Engine } from "@navita/engine";
2
+ import { ImportMap } from "@navita/types";
3
+
4
+ //#region src/helpers/createDefineFunction.d.ts
5
+ type FilePath$1 = string;
6
+ type ResolverCache = Record<FilePath$1, unknown>;
7
+ type NodeModuleCache = Record<FilePath$1, unknown>;
8
+ //#endregion
9
+ //#region src/helpers/setAdapter.d.ts
10
+ type FilePath = string;
11
+ type ResultCache = Record<FilePath, {
12
+ start: number;
13
+ end: number;
14
+ value: string;
15
+ }[]>;
16
+ //#endregion
17
+ //#region src/evaluateAndProcess.d.ts
18
+ /**
19
+ * A dependency is "external" when navita imports it as an opaque module (native
20
+ * `import()`, exports used as-is) instead of recursively evaluating its source
21
+ * to extract navita styles from it. By default that's navita's own packages
22
+ * (`rootDir`) and everything under `node_modules`.
23
+ *
24
+ * `transformNodeModules` carves specific `node_modules` paths back OUT of that
25
+ * set — a component library authored WITH navita ships un-compiled `style()`/
26
+ * theme calls in files that DO need recursive evaluation (and dependency
27
+ * tracking for HMR). navita's own packages stay external regardless, so a broad
28
+ * matcher can never make navita try to evaluate `@navita/css` itself.
29
+ */
30
+ type NodeModuleMatcher = string | RegExp;
31
+ type FilePathWithType = string;
32
+ type ModuleCache = Map<FilePathWithType, {
33
+ source: string;
34
+ compiledFn: () => Promise<{
35
+ dependencies: string[];
36
+ exports: Record<string, unknown>;
37
+ }>;
38
+ }>;
39
+ interface Caches {
40
+ nodeModuleCache?: NodeModuleCache;
41
+ resolverCache?: ResolverCache;
42
+ moduleCache?: ModuleCache;
43
+ resultCache?: ResultCache;
44
+ }
45
+ type Types = "entryPoint" | "dependency";
46
+ interface Output<Type extends Types> {
47
+ result: Type extends "entryPoint" ? ResultCache[number] : Record<string, unknown>;
48
+ dependencies: string[];
49
+ }
50
+ declare function evaluateAndProcess<Type extends "entryPoint" | "dependency">({
51
+ type,
52
+ filePath,
53
+ source,
54
+ engine,
55
+ resolver,
56
+ readFile,
57
+ importMap,
58
+ transformNodeModules,
59
+ nodeModuleCache,
60
+ resolverCache,
61
+ moduleCache,
62
+ resultCache
63
+ }: {
64
+ source: string;
65
+ filePath: string;
66
+ type: Type;
67
+ engine: Engine;
68
+ resolver: (filePath: string, request: string) => Promise<string>;
69
+ readFile: (filePath: string) => Promise<string>;
70
+ importMap: ImportMap;
71
+ transformNodeModules?: NodeModuleMatcher[];
72
+ } & Caches): Promise<Output<Type>>;
73
+ //#endregion
74
+ export { NodeModuleMatcher as n, evaluateAndProcess as r, Caches as t };
@@ -8,13 +8,15 @@ node_path = require_runtime.__toESM(node_path);
8
8
  let _navita_extraction = require("@navita/extraction");
9
9
  //#region src/evaluateAndProcess.ts
10
10
  const rootDir = node_path.default.resolve(__dirname, "../../");
11
- const isExternal = (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules");
11
+ const matches = (matchers, dependency) => matchers.some((matcher) => matcher instanceof RegExp ? matcher.test(dependency) : dependency.includes(matcher));
12
+ const createIsExternal = (transformNodeModules) => (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules") && !matches(transformNodeModules, dependency);
12
13
  const defaultNodeModuleCache = {};
13
14
  const defaultResolverCache = {};
14
15
  const defaultModuleCache = /* @__PURE__ */ new Map();
15
16
  const defaultResultCache = {};
16
- async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
17
+ async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, transformNodeModules = [], nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
17
18
  const cacheKey = `${filePath}:${type}`;
19
+ const isExternal = createIsExternal(transformNodeModules);
18
20
  return (await (async () => {
19
21
  if (moduleCache.has(cacheKey)) {
20
22
  const cache = moduleCache.get(cacheKey);
@@ -43,6 +45,7 @@ async function evaluateAndProcess({ type, filePath, source, engine, resolver, re
43
45
  resolver,
44
46
  readFile,
45
47
  importMap,
48
+ transformNodeModules,
46
49
  nodeModuleCache,
47
50
  resolverCache,
48
51
  moduleCache
@@ -1,59 +1,2 @@
1
- import { Engine } from "@navita/engine";
2
- import { ImportMap } from "@navita/types";
3
-
4
- //#region src/helpers/createDefineFunction.d.ts
5
- type FilePath$1 = string;
6
- type ResolverCache = Record<FilePath$1, unknown>;
7
- type NodeModuleCache = Record<FilePath$1, unknown>;
8
- //#endregion
9
- //#region src/helpers/setAdapter.d.ts
10
- type FilePath = string;
11
- type ResultCache = Record<FilePath, {
12
- start: number;
13
- end: number;
14
- value: string;
15
- }[]>;
16
- //#endregion
17
- //#region src/evaluateAndProcess.d.ts
18
- type FilePathWithType = string;
19
- type ModuleCache = Map<FilePathWithType, {
20
- source: string;
21
- compiledFn: () => Promise<{
22
- dependencies: string[];
23
- exports: Record<string, unknown>;
24
- }>;
25
- }>;
26
- interface Caches {
27
- nodeModuleCache?: NodeModuleCache;
28
- resolverCache?: ResolverCache;
29
- moduleCache?: ModuleCache;
30
- resultCache?: ResultCache;
31
- }
32
- type Types = "entryPoint" | "dependency";
33
- interface Output<Type extends Types> {
34
- result: Type extends "entryPoint" ? ResultCache[number] : Record<string, unknown>;
35
- dependencies: string[];
36
- }
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;
57
- } & Caches): Promise<Output<Type>>;
58
- //#endregion
59
- export { Caches, evaluateAndProcess };
1
+ import { n as NodeModuleMatcher, r as evaluateAndProcess, t as Caches } from "./evaluateAndProcess-Bd56H_hx.js";
2
+ export { Caches, NodeModuleMatcher, evaluateAndProcess };
@@ -9,13 +9,15 @@ import path from "node:path";
9
9
  import { extraction } from "@navita/extraction";
10
10
  //#region src/evaluateAndProcess.ts
11
11
  const rootDir = path.resolve(__TSDOWN_SHIM_DIRNAME__, "../../");
12
- const isExternal = (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules");
12
+ const matches = (matchers, dependency) => matchers.some((matcher) => matcher instanceof RegExp ? matcher.test(dependency) : dependency.includes(matcher));
13
+ const createIsExternal = (transformNodeModules) => (dependency) => dependency.startsWith(rootDir) || dependency.includes("node_modules") && !matches(transformNodeModules, dependency);
13
14
  const defaultNodeModuleCache = {};
14
15
  const defaultResolverCache = {};
15
16
  const defaultModuleCache = /* @__PURE__ */ new Map();
16
17
  const defaultResultCache = {};
17
- async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
18
+ async function evaluateAndProcess({ type, filePath, source, engine, resolver, readFile, importMap, transformNodeModules = [], nodeModuleCache = defaultNodeModuleCache, resolverCache = defaultResolverCache, moduleCache = defaultModuleCache, resultCache = defaultResultCache }) {
18
19
  const cacheKey = `${filePath}:${type}`;
20
+ const isExternal = createIsExternal(transformNodeModules);
19
21
  return (await (async () => {
20
22
  if (moduleCache.has(cacheKey)) {
21
23
  const cache = moduleCache.get(cacheKey);
@@ -44,6 +46,7 @@ async function evaluateAndProcess({ type, filePath, source, engine, resolver, re
44
46
  resolver,
45
47
  readFile,
46
48
  importMap,
49
+ transformNodeModules,
47
50
  nodeModuleCache,
48
51
  resolverCache,
49
52
  moduleCache
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/core",
3
- "version": "3.0.0-next.1",
3
+ "version": "3.0.0-next.3",
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
  "magic-string": "^0.30.3",
30
30
  "outdent": "^0.8.0",
31
- "@navita/adapter": "3.0.0-next.1",
32
- "@navita/engine": "3.0.0-next.1",
33
- "@navita/extraction": "3.0.0-next.1",
34
- "@navita/types": "3.0.0-next.1"
31
+ "@navita/adapter": "3.0.0-next.3",
32
+ "@navita/engine": "3.0.0-next.3",
33
+ "@navita/extraction": "3.0.0-next.3",
34
+ "@navita/types": "3.0.0-next.3"
35
35
  },
36
36
  "license": "MIT",
37
37
  "author": "Eagerpatch",