@navita/vite-plugin 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.
- package/index.cjs +18 -15
- package/index.d.ts +19 -0
- package/index.mjs +18 -15
- package/package.json +3 -3
- package/rwsdk.cjs +8 -0
- package/rwsdk.mjs +9 -1
package/index.cjs
CHANGED
|
@@ -9,6 +9,8 @@ const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
|
9
9
|
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID.replace(/.css$/, "")}`;
|
|
10
10
|
function navita(options) {
|
|
11
11
|
const importMap = [..._navita_css.importMap, ...options?.importMap || []];
|
|
12
|
+
const transformNodeModules = options?.transformNodeModules || [];
|
|
13
|
+
const isForcedNodeModule = (id) => transformNodeModules.some((matcher) => matcher instanceof RegExp ? matcher.test(id) : id.includes(matcher));
|
|
12
14
|
let server;
|
|
13
15
|
let config;
|
|
14
16
|
let updateTimer = null;
|
|
@@ -34,6 +36,7 @@ function navita(options) {
|
|
|
34
36
|
...options?.engineOptions || {}
|
|
35
37
|
},
|
|
36
38
|
importMap,
|
|
39
|
+
transformNodeModules,
|
|
37
40
|
resolver: async (filepath, request) => {
|
|
38
41
|
return (await this.resolve(request, filepath))?.id || null;
|
|
39
42
|
},
|
|
@@ -55,7 +58,7 @@ function navita(options) {
|
|
|
55
58
|
},
|
|
56
59
|
async transform(code, id) {
|
|
57
60
|
const renderer = getRenderer();
|
|
58
|
-
if (!renderer || id.includes("node_modules") || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
61
|
+
if (!renderer || id.includes("node_modules") && !isForcedNodeModule(id) || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
59
62
|
if (!importMap.map((x) => x.source).some((value) => code.indexOf(value) !== -1)) {
|
|
60
63
|
renderer.clearCache(id);
|
|
61
64
|
return null;
|
|
@@ -85,11 +88,13 @@ function navita(options) {
|
|
|
85
88
|
}];
|
|
86
89
|
} },
|
|
87
90
|
renderChunk(_, chunk) {
|
|
88
|
-
if (cssEmitted) return;
|
|
91
|
+
if (this.environment?.name !== "client" || cssEmitted) return;
|
|
92
|
+
const css = getRenderer()?.engine.renderCssToString();
|
|
93
|
+
if (!css) return;
|
|
89
94
|
chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
|
|
90
95
|
name: "navita.css",
|
|
91
96
|
type: "asset",
|
|
92
|
-
source:
|
|
97
|
+
source: css
|
|
93
98
|
})));
|
|
94
99
|
cssEmitted = true;
|
|
95
100
|
}
|
|
@@ -100,18 +105,16 @@ function navita(options) {
|
|
|
100
105
|
updateTimer = setTimeout(() => {
|
|
101
106
|
const { moduleGraph, ws } = server;
|
|
102
107
|
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
103
|
-
if (mod)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
}
|
|
108
|
+
if (mod) moduleGraph.invalidateModule(mod);
|
|
109
|
+
ws.send({
|
|
110
|
+
type: "update",
|
|
111
|
+
updates: [{
|
|
112
|
+
type: "css-update",
|
|
113
|
+
path: `/${VIRTUAL_MODULE_ID}`,
|
|
114
|
+
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
115
|
+
timestamp: Date.now()
|
|
116
|
+
}]
|
|
117
|
+
});
|
|
115
118
|
}, 20);
|
|
116
119
|
}
|
|
117
120
|
}
|
package/index.d.ts
CHANGED
|
@@ -6,6 +6,25 @@ declare const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
|
6
6
|
interface Options {
|
|
7
7
|
importMap?: ImportMap;
|
|
8
8
|
engineOptions?: EngineOptions;
|
|
9
|
+
/**
|
|
10
|
+
* By default the transform skips every file under `node_modules`, since most
|
|
11
|
+
* dependencies ship plain CSS or no navita styles at all. A component library
|
|
12
|
+
* authored WITH navita, however, ships un-compiled `style()` calls that must
|
|
13
|
+
* still be transformed — otherwise they throw "Could not find an adapter" at
|
|
14
|
+
* runtime.
|
|
15
|
+
*
|
|
16
|
+
* Provide matchers here for the `node_modules` paths that should be treated
|
|
17
|
+
* as navita source. Each matcher is a substring (matched with
|
|
18
|
+
* `id.includes(...)`) or a `RegExp` tested against the module id. A matched
|
|
19
|
+
* path is both transformed AND recursively evaluated, so the library's own
|
|
20
|
+
* cross-file imports (a theme/tokens file it ships) resolve correctly instead
|
|
21
|
+
* of being imported as an opaque module. navita's own packages (`@navita/*`)
|
|
22
|
+
* stay external regardless.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* navita({ transformNodeModules: ["@acme/ui", /@acme\/.*\/navita\//] })
|
|
26
|
+
*/
|
|
27
|
+
transformNodeModules?: (string | RegExp)[];
|
|
9
28
|
}
|
|
10
29
|
declare function navita(options?: Options): Plugin;
|
|
11
30
|
declare function getRenderer(): Renderer | undefined;
|
package/index.mjs
CHANGED
|
@@ -9,6 +9,8 @@ const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
|
9
9
|
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID.replace(/.css$/, "")}`;
|
|
10
10
|
function navita(options) {
|
|
11
11
|
const importMap$1 = [...importMap, ...options?.importMap || []];
|
|
12
|
+
const transformNodeModules = options?.transformNodeModules || [];
|
|
13
|
+
const isForcedNodeModule = (id) => transformNodeModules.some((matcher) => matcher instanceof RegExp ? matcher.test(id) : id.includes(matcher));
|
|
12
14
|
let server;
|
|
13
15
|
let config;
|
|
14
16
|
let updateTimer = null;
|
|
@@ -34,6 +36,7 @@ function navita(options) {
|
|
|
34
36
|
...options?.engineOptions || {}
|
|
35
37
|
},
|
|
36
38
|
importMap: importMap$1,
|
|
39
|
+
transformNodeModules,
|
|
37
40
|
resolver: async (filepath, request) => {
|
|
38
41
|
return (await this.resolve(request, filepath))?.id || null;
|
|
39
42
|
},
|
|
@@ -55,7 +58,7 @@ function navita(options) {
|
|
|
55
58
|
},
|
|
56
59
|
async transform(code, id) {
|
|
57
60
|
const renderer = getRenderer();
|
|
58
|
-
if (!renderer || id.includes("node_modules") || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
61
|
+
if (!renderer || id.includes("node_modules") && !isForcedNodeModule(id) || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
59
62
|
if (!importMap$1.map((x) => x.source).some((value) => code.indexOf(value) !== -1)) {
|
|
60
63
|
renderer.clearCache(id);
|
|
61
64
|
return null;
|
|
@@ -85,11 +88,13 @@ function navita(options) {
|
|
|
85
88
|
}];
|
|
86
89
|
} },
|
|
87
90
|
renderChunk(_, chunk) {
|
|
88
|
-
if (cssEmitted) return;
|
|
91
|
+
if (this.environment?.name !== "client" || cssEmitted) return;
|
|
92
|
+
const css = getRenderer()?.engine.renderCssToString();
|
|
93
|
+
if (!css) return;
|
|
89
94
|
chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
|
|
90
95
|
name: "navita.css",
|
|
91
96
|
type: "asset",
|
|
92
|
-
source:
|
|
97
|
+
source: css
|
|
93
98
|
})));
|
|
94
99
|
cssEmitted = true;
|
|
95
100
|
}
|
|
@@ -100,18 +105,16 @@ function navita(options) {
|
|
|
100
105
|
updateTimer = setTimeout(() => {
|
|
101
106
|
const { moduleGraph, ws } = server;
|
|
102
107
|
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
103
|
-
if (mod)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
}
|
|
108
|
+
if (mod) moduleGraph.invalidateModule(mod);
|
|
109
|
+
ws.send({
|
|
110
|
+
type: "update",
|
|
111
|
+
updates: [{
|
|
112
|
+
type: "css-update",
|
|
113
|
+
path: `/${VIRTUAL_MODULE_ID}`,
|
|
114
|
+
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
115
|
+
timestamp: Date.now()
|
|
116
|
+
}]
|
|
117
|
+
});
|
|
115
118
|
}, 20);
|
|
116
119
|
}
|
|
117
120
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/vite-plugin",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.3",
|
|
4
4
|
"description": "Navita Vite Plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@navita/core": "3.0.0-next.
|
|
31
|
-
"@navita/css": "3.0.0-next.
|
|
30
|
+
"@navita/core": "3.0.0-next.3",
|
|
31
|
+
"@navita/css": "3.0.0-next.3"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"author": "Eagerpatch",
|
package/rwsdk.cjs
CHANGED
|
@@ -16,6 +16,14 @@ function navitaRwsdk(options) {
|
|
|
16
16
|
projectRootDir = config.root;
|
|
17
17
|
base = config.base;
|
|
18
18
|
},
|
|
19
|
+
configureServer(server) {
|
|
20
|
+
server.middlewares.use((req, res, next) => {
|
|
21
|
+
if (req.url?.split("?")[0] !== `/virtual:navita.css`) return next();
|
|
22
|
+
res.setHeader("Content-Type", "text/css");
|
|
23
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
24
|
+
res.end(require_index.getRenderer()?.engine.renderCssToString() ?? "");
|
|
25
|
+
});
|
|
26
|
+
},
|
|
19
27
|
async renderChunk(code) {
|
|
20
28
|
if (this.environment?.name !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") return null;
|
|
21
29
|
const manifestPath = node_path.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
|
package/rwsdk.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
import { VIRTUAL_MODULE_ID, navita } from "./index.mjs";
|
|
4
|
+
import { VIRTUAL_MODULE_ID, getRenderer, navita } from "./index.mjs";
|
|
5
5
|
import * as fsp from "node:fs/promises";
|
|
6
6
|
import * as path from "node:path";
|
|
7
7
|
//#region src/rwsdk.ts
|
|
@@ -15,6 +15,14 @@ function navitaRwsdk(options) {
|
|
|
15
15
|
projectRootDir = config.root;
|
|
16
16
|
base = config.base;
|
|
17
17
|
},
|
|
18
|
+
configureServer(server) {
|
|
19
|
+
server.middlewares.use((req, res, next) => {
|
|
20
|
+
if (req.url?.split("?")[0] !== `/virtual:navita.css`) return next();
|
|
21
|
+
res.setHeader("Content-Type", "text/css");
|
|
22
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
23
|
+
res.end(getRenderer()?.engine.renderCssToString() ?? "");
|
|
24
|
+
});
|
|
25
|
+
},
|
|
18
26
|
async renderChunk(code) {
|
|
19
27
|
if (this.environment?.name !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") return null;
|
|
20
28
|
const manifestPath = path.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
|