@navita/vite-plugin 2.0.5 → 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/index.cjs +119 -149
- package/index.d.ts +7 -6
- package/index.mjs +119 -147
- package/package.json +8 -3
- package/remix.cjs +40 -73
- package/remix.d.ts +5 -5
- package/remix.mjs +39 -51
- package/rwsdk.cjs +60 -0
- package/rwsdk.d.ts +7 -0
- package/rwsdk.mjs +59 -0
|
@@ -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/index.cjs
CHANGED
|
@@ -1,158 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
node_fs = require_runtime.__toESM(node_fs);
|
|
5
|
+
let _navita_core_createRenderer = require("@navita/core/createRenderer");
|
|
6
|
+
let _navita_css = require("@navita/css");
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
9
|
+
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID.replace(/.css$/, "")}`;
|
|
9
10
|
function navita(options) {
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
name: 'navita.css',
|
|
117
|
-
type: 'asset',
|
|
118
|
-
source: getRenderer()?.engine.renderCssToString()
|
|
119
|
-
})));
|
|
120
|
-
cssEmitted = true;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
function updateNavitaCSS() {
|
|
124
|
-
if (!server) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
clearTimeout(updateTimer);
|
|
128
|
-
updateTimer = setTimeout(()=>{
|
|
129
|
-
const { moduleGraph, ws } = server;
|
|
130
|
-
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
131
|
-
if (mod) {
|
|
132
|
-
moduleGraph.invalidateModule(mod);
|
|
133
|
-
ws.send({
|
|
134
|
-
type: 'update',
|
|
135
|
-
updates: [
|
|
136
|
-
{
|
|
137
|
-
type: 'css-update',
|
|
138
|
-
path: `/${VIRTUAL_MODULE_ID}`,
|
|
139
|
-
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
140
|
-
timestamp: Date.now()
|
|
141
|
-
}
|
|
142
|
-
]
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}, 20);
|
|
146
|
-
}
|
|
11
|
+
const importMap = [..._navita_css.importMap, ...options?.importMap || []];
|
|
12
|
+
let server;
|
|
13
|
+
let config;
|
|
14
|
+
let updateTimer = null;
|
|
15
|
+
let cssEmitted = false;
|
|
16
|
+
let isProduction = false;
|
|
17
|
+
return {
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
name: "navita",
|
|
20
|
+
configResolved(_resolvedConfig) {
|
|
21
|
+
config = _resolvedConfig;
|
|
22
|
+
isProduction = config.mode === "production";
|
|
23
|
+
},
|
|
24
|
+
configureServer(_server) {
|
|
25
|
+
server = _server;
|
|
26
|
+
},
|
|
27
|
+
buildStart() {
|
|
28
|
+
if (getRenderer()) return;
|
|
29
|
+
setRenderer((0, _navita_core_createRenderer.createRenderer)({
|
|
30
|
+
context: config.root,
|
|
31
|
+
engineOptions: {
|
|
32
|
+
enableSourceMaps: !isProduction,
|
|
33
|
+
enableDebugIdentifiers: !isProduction,
|
|
34
|
+
...options?.engineOptions || {}
|
|
35
|
+
},
|
|
36
|
+
importMap,
|
|
37
|
+
resolver: async (filepath, request) => {
|
|
38
|
+
return (await this.resolve(request, filepath))?.id || null;
|
|
39
|
+
},
|
|
40
|
+
readFile: (path) => {
|
|
41
|
+
return node_fs.default.promises.readFile(path, "utf-8");
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
resolveId(source) {
|
|
46
|
+
const [id] = source.split("?");
|
|
47
|
+
if (id.endsWith("virtual:navita.css")) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
48
|
+
},
|
|
49
|
+
async load(source) {
|
|
50
|
+
const [id] = source.split("?");
|
|
51
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) return {
|
|
52
|
+
code: getRenderer()?.engine.renderCssToString() || "",
|
|
53
|
+
map: { mappings: "" }
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async transform(code, id) {
|
|
57
|
+
const renderer = getRenderer();
|
|
58
|
+
if (!renderer || id.includes("node_modules") || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
59
|
+
if (!importMap.map((x) => x.source).some((value) => code.indexOf(value) !== -1)) {
|
|
60
|
+
renderer.clearCache(id);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const { result, sourceMap, dependencies } = await renderer.transformAndProcess({
|
|
64
|
+
content: code,
|
|
65
|
+
filePath: id
|
|
66
|
+
});
|
|
67
|
+
if (!isProduction) {
|
|
68
|
+
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
69
|
+
updateNavitaCSS();
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
code: result,
|
|
73
|
+
map: sourceMap
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
transformIndexHtml: { handler: async () => {
|
|
77
|
+
if (isProduction) return [];
|
|
78
|
+
return [{
|
|
79
|
+
tag: "link",
|
|
80
|
+
injectTo: "head",
|
|
81
|
+
attrs: {
|
|
82
|
+
rel: "stylesheet",
|
|
83
|
+
href: `/${VIRTUAL_MODULE_ID}`
|
|
84
|
+
}
|
|
85
|
+
}];
|
|
86
|
+
} },
|
|
87
|
+
renderChunk(_, chunk) {
|
|
88
|
+
if (cssEmitted) return;
|
|
89
|
+
chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
|
|
90
|
+
name: "navita.css",
|
|
91
|
+
type: "asset",
|
|
92
|
+
source: getRenderer()?.engine.renderCssToString()
|
|
93
|
+
})));
|
|
94
|
+
cssEmitted = true;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function updateNavitaCSS() {
|
|
98
|
+
if (!server) return;
|
|
99
|
+
clearTimeout(updateTimer);
|
|
100
|
+
updateTimer = setTimeout(() => {
|
|
101
|
+
const { moduleGraph, ws } = server;
|
|
102
|
+
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
103
|
+
if (mod) {
|
|
104
|
+
moduleGraph.invalidateModule(mod);
|
|
105
|
+
ws.send({
|
|
106
|
+
type: "update",
|
|
107
|
+
updates: [{
|
|
108
|
+
type: "css-update",
|
|
109
|
+
path: `/${VIRTUAL_MODULE_ID}`,
|
|
110
|
+
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
111
|
+
timestamp: Date.now()
|
|
112
|
+
}]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, 20);
|
|
116
|
+
}
|
|
147
117
|
}
|
|
148
|
-
const globalNavitaRendererKey =
|
|
118
|
+
const globalNavitaRendererKey = "__navita_renderer";
|
|
149
119
|
function setRenderer(renderer) {
|
|
150
|
-
|
|
120
|
+
globalThis[globalNavitaRendererKey] = renderer;
|
|
151
121
|
}
|
|
152
122
|
function getRenderer() {
|
|
153
|
-
|
|
123
|
+
return globalThis[globalNavitaRendererKey];
|
|
154
124
|
}
|
|
155
|
-
|
|
125
|
+
//#endregion
|
|
156
126
|
exports.VIRTUAL_MODULE_ID = VIRTUAL_MODULE_ID;
|
|
157
127
|
exports.getRenderer = getRenderer;
|
|
158
128
|
exports.navita = navita;
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from
|
|
1
|
+
import { EngineOptions, ImportMap, Renderer } from "@navita/core/createRenderer";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
4
5
|
declare const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
5
6
|
interface Options {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
importMap?: ImportMap;
|
|
8
|
+
engineOptions?: EngineOptions;
|
|
8
9
|
}
|
|
9
10
|
declare function navita(options?: Options): Plugin;
|
|
10
11
|
declare function getRenderer(): Renderer | undefined;
|
|
11
|
-
|
|
12
|
-
export { Options, VIRTUAL_MODULE_ID, getRenderer, navita };
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Options, VIRTUAL_MODULE_ID, getRenderer, navita };
|
package/index.mjs
CHANGED
|
@@ -1,154 +1,126 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { createRenderer } from "@navita/core/createRenderer";
|
|
6
|
+
import { importMap } from "@navita/css";
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const VIRTUAL_MODULE_ID = "virtual:navita.css";
|
|
9
|
+
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID.replace(/.css$/, "")}`;
|
|
7
10
|
function navita(options) {
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
name: 'navita.css',
|
|
115
|
-
type: 'asset',
|
|
116
|
-
source: getRenderer()?.engine.renderCssToString()
|
|
117
|
-
})));
|
|
118
|
-
cssEmitted = true;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
function updateNavitaCSS() {
|
|
122
|
-
if (!server) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
clearTimeout(updateTimer);
|
|
126
|
-
updateTimer = setTimeout(()=>{
|
|
127
|
-
const { moduleGraph, ws } = server;
|
|
128
|
-
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
129
|
-
if (mod) {
|
|
130
|
-
moduleGraph.invalidateModule(mod);
|
|
131
|
-
ws.send({
|
|
132
|
-
type: 'update',
|
|
133
|
-
updates: [
|
|
134
|
-
{
|
|
135
|
-
type: 'css-update',
|
|
136
|
-
path: `/${VIRTUAL_MODULE_ID}`,
|
|
137
|
-
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
138
|
-
timestamp: Date.now()
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}, 20);
|
|
144
|
-
}
|
|
11
|
+
const importMap$1 = [...importMap, ...options?.importMap || []];
|
|
12
|
+
let server;
|
|
13
|
+
let config;
|
|
14
|
+
let updateTimer = null;
|
|
15
|
+
let cssEmitted = false;
|
|
16
|
+
let isProduction = false;
|
|
17
|
+
return {
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
name: "navita",
|
|
20
|
+
configResolved(_resolvedConfig) {
|
|
21
|
+
config = _resolvedConfig;
|
|
22
|
+
isProduction = config.mode === "production";
|
|
23
|
+
},
|
|
24
|
+
configureServer(_server) {
|
|
25
|
+
server = _server;
|
|
26
|
+
},
|
|
27
|
+
buildStart() {
|
|
28
|
+
if (getRenderer()) return;
|
|
29
|
+
setRenderer(createRenderer({
|
|
30
|
+
context: config.root,
|
|
31
|
+
engineOptions: {
|
|
32
|
+
enableSourceMaps: !isProduction,
|
|
33
|
+
enableDebugIdentifiers: !isProduction,
|
|
34
|
+
...options?.engineOptions || {}
|
|
35
|
+
},
|
|
36
|
+
importMap: importMap$1,
|
|
37
|
+
resolver: async (filepath, request) => {
|
|
38
|
+
return (await this.resolve(request, filepath))?.id || null;
|
|
39
|
+
},
|
|
40
|
+
readFile: (path) => {
|
|
41
|
+
return fs.promises.readFile(path, "utf-8");
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
resolveId(source) {
|
|
46
|
+
const [id] = source.split("?");
|
|
47
|
+
if (id.endsWith("virtual:navita.css")) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
48
|
+
},
|
|
49
|
+
async load(source) {
|
|
50
|
+
const [id] = source.split("?");
|
|
51
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) return {
|
|
52
|
+
code: getRenderer()?.engine.renderCssToString() || "",
|
|
53
|
+
map: { mappings: "" }
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async transform(code, id) {
|
|
57
|
+
const renderer = getRenderer();
|
|
58
|
+
if (!renderer || id.includes("node_modules") || process.env.RWSDK_BUILD_PASS === "linker") return null;
|
|
59
|
+
if (!importMap$1.map((x) => x.source).some((value) => code.indexOf(value) !== -1)) {
|
|
60
|
+
renderer.clearCache(id);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const { result, sourceMap, dependencies } = await renderer.transformAndProcess({
|
|
64
|
+
content: code,
|
|
65
|
+
filePath: id
|
|
66
|
+
});
|
|
67
|
+
if (!isProduction) {
|
|
68
|
+
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
69
|
+
updateNavitaCSS();
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
code: result,
|
|
73
|
+
map: sourceMap
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
transformIndexHtml: { handler: async () => {
|
|
77
|
+
if (isProduction) return [];
|
|
78
|
+
return [{
|
|
79
|
+
tag: "link",
|
|
80
|
+
injectTo: "head",
|
|
81
|
+
attrs: {
|
|
82
|
+
rel: "stylesheet",
|
|
83
|
+
href: `/${VIRTUAL_MODULE_ID}`
|
|
84
|
+
}
|
|
85
|
+
}];
|
|
86
|
+
} },
|
|
87
|
+
renderChunk(_, chunk) {
|
|
88
|
+
if (cssEmitted) return;
|
|
89
|
+
chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
|
|
90
|
+
name: "navita.css",
|
|
91
|
+
type: "asset",
|
|
92
|
+
source: getRenderer()?.engine.renderCssToString()
|
|
93
|
+
})));
|
|
94
|
+
cssEmitted = true;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function updateNavitaCSS() {
|
|
98
|
+
if (!server) return;
|
|
99
|
+
clearTimeout(updateTimer);
|
|
100
|
+
updateTimer = setTimeout(() => {
|
|
101
|
+
const { moduleGraph, ws } = server;
|
|
102
|
+
const mod = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
103
|
+
if (mod) {
|
|
104
|
+
moduleGraph.invalidateModule(mod);
|
|
105
|
+
ws.send({
|
|
106
|
+
type: "update",
|
|
107
|
+
updates: [{
|
|
108
|
+
type: "css-update",
|
|
109
|
+
path: `/${VIRTUAL_MODULE_ID}`,
|
|
110
|
+
acceptedPath: `/${VIRTUAL_MODULE_ID}`,
|
|
111
|
+
timestamp: Date.now()
|
|
112
|
+
}]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, 20);
|
|
116
|
+
}
|
|
145
117
|
}
|
|
146
|
-
const globalNavitaRendererKey =
|
|
118
|
+
const globalNavitaRendererKey = "__navita_renderer";
|
|
147
119
|
function setRenderer(renderer) {
|
|
148
|
-
|
|
120
|
+
globalThis[globalNavitaRendererKey] = renderer;
|
|
149
121
|
}
|
|
150
122
|
function getRenderer() {
|
|
151
|
-
|
|
123
|
+
return globalThis[globalNavitaRendererKey];
|
|
152
124
|
}
|
|
153
|
-
|
|
125
|
+
//#endregion
|
|
154
126
|
export { VIRTUAL_MODULE_ID, getRenderer, navita };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/vite-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "Navita Vite Plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -19,11 +19,16 @@
|
|
|
19
19
|
"import": "./remix.mjs",
|
|
20
20
|
"require": "./remix.cjs",
|
|
21
21
|
"types": "./remix.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./rwsdk": {
|
|
24
|
+
"import": "./rwsdk.mjs",
|
|
25
|
+
"require": "./rwsdk.cjs",
|
|
26
|
+
"types": "./rwsdk.d.ts"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"dependencies": {
|
|
25
|
-
"@navita/core": "
|
|
26
|
-
"@navita/css": "0.
|
|
30
|
+
"@navita/core": "3.0.0-next.0",
|
|
31
|
+
"@navita/css": "3.0.0-next.0"
|
|
27
32
|
},
|
|
28
33
|
"license": "MIT",
|
|
29
34
|
"author": "Eagerpatch",
|
package/remix.cjs
CHANGED
|
@@ -1,85 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
24
|
-
|
|
25
|
-
const VIRTUAL_MODULE_IDS = [
|
|
26
|
-
'\0virtual:remix/server-build',
|
|
27
|
-
'\0virtual:react-router/server-build'
|
|
28
|
-
];
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_index = require("./index.cjs");
|
|
4
|
+
let node_crypto = require("node:crypto");
|
|
5
|
+
node_crypto = require_runtime.__toESM(node_crypto);
|
|
6
|
+
//#region src/remix.ts
|
|
7
|
+
const VIRTUAL_MODULE_IDS = ["\0virtual:remix/server-build", "\0virtual:react-router/server-build"];
|
|
29
8
|
let cssFileName;
|
|
30
9
|
function navitaRemix(options) {
|
|
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
|
-
// Remix/react-router will then move it to the client assets.
|
|
63
|
-
this.emitFile({
|
|
64
|
-
fileName: cssFileName,
|
|
65
|
-
name: 'navita.css',
|
|
66
|
-
type: 'asset',
|
|
67
|
-
source: index.getRenderer()?.engine.renderCssToString()
|
|
68
|
-
});
|
|
69
|
-
hasEmittedCss = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
];
|
|
10
|
+
let isProduction = false;
|
|
11
|
+
let hasEmittedCss = false;
|
|
12
|
+
const navitaVite = require_index.navita(options);
|
|
13
|
+
delete navitaVite.renderChunk;
|
|
14
|
+
return [navitaVite, {
|
|
15
|
+
name: "navita-remix",
|
|
16
|
+
configResolved(config) {
|
|
17
|
+
isProduction = config.mode === "production";
|
|
18
|
+
},
|
|
19
|
+
transform(code, id) {
|
|
20
|
+
if (isProduction || !VIRTUAL_MODULE_IDS.includes(id)) return;
|
|
21
|
+
return `${code}\n${SERVER_BUILD_EXTENSION}`;
|
|
22
|
+
},
|
|
23
|
+
renderChunk(_, chunk, options) {
|
|
24
|
+
const isServerChunk = options.dir.endsWith("/server");
|
|
25
|
+
if (options.dir.endsWith("/client") && chunk.name === "root") {
|
|
26
|
+
cssFileName = `assets/navita-${node_crypto.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8)}.css`;
|
|
27
|
+
chunk.viteMetadata.importedCss.add(cssFileName);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (isServerChunk && !hasEmittedCss) {
|
|
31
|
+
this.emitFile({
|
|
32
|
+
fileName: cssFileName,
|
|
33
|
+
name: "navita.css",
|
|
34
|
+
type: "asset",
|
|
35
|
+
source: require_index.getRenderer()?.engine.renderCssToString()
|
|
36
|
+
});
|
|
37
|
+
hasEmittedCss = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}];
|
|
74
41
|
}
|
|
75
42
|
const SERVER_BUILD_EXTENSION = `
|
|
76
43
|
routes.root.module = {
|
|
77
44
|
...route0,
|
|
78
45
|
links: () => [
|
|
79
46
|
...(route0.links ? route0.links() : []),
|
|
80
|
-
{ rel: 'stylesheet', href: '/${
|
|
47
|
+
{ rel: 'stylesheet', href: '/${require_index.VIRTUAL_MODULE_ID}' },
|
|
81
48
|
],
|
|
82
49
|
};
|
|
83
50
|
`;
|
|
84
|
-
|
|
51
|
+
//#endregion
|
|
85
52
|
exports.navitaRemix = navitaRemix;
|
package/remix.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import '@navita/core/createRenderer';
|
|
1
|
+
import { Options } from "./index.js";
|
|
2
|
+
import { Plugin } from "vite";
|
|
4
3
|
|
|
4
|
+
//#region src/remix.d.ts
|
|
5
5
|
declare function navitaRemix(options?: Options): Plugin[];
|
|
6
|
-
|
|
7
|
-
export { navitaRemix };
|
|
6
|
+
//#endregion
|
|
7
|
+
export { navitaRemix };
|
package/remix.mjs
CHANGED
|
@@ -1,55 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
];
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { VIRTUAL_MODULE_ID, getRenderer, navita } from "./index.mjs";
|
|
5
|
+
import * as crypto from "node:crypto";
|
|
6
|
+
//#region src/remix.ts
|
|
7
|
+
const VIRTUAL_MODULE_IDS = ["\0virtual:remix/server-build", "\0virtual:react-router/server-build"];
|
|
8
8
|
let cssFileName;
|
|
9
9
|
function navitaRemix(options) {
|
|
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
|
-
// Remix/react-router will then move it to the client assets.
|
|
42
|
-
this.emitFile({
|
|
43
|
-
fileName: cssFileName,
|
|
44
|
-
name: 'navita.css',
|
|
45
|
-
type: 'asset',
|
|
46
|
-
source: getRenderer()?.engine.renderCssToString()
|
|
47
|
-
});
|
|
48
|
-
hasEmittedCss = true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
];
|
|
10
|
+
let isProduction = false;
|
|
11
|
+
let hasEmittedCss = false;
|
|
12
|
+
const navitaVite = navita(options);
|
|
13
|
+
delete navitaVite.renderChunk;
|
|
14
|
+
return [navitaVite, {
|
|
15
|
+
name: "navita-remix",
|
|
16
|
+
configResolved(config) {
|
|
17
|
+
isProduction = config.mode === "production";
|
|
18
|
+
},
|
|
19
|
+
transform(code, id) {
|
|
20
|
+
if (isProduction || !VIRTUAL_MODULE_IDS.includes(id)) return;
|
|
21
|
+
return `${code}\n${SERVER_BUILD_EXTENSION}`;
|
|
22
|
+
},
|
|
23
|
+
renderChunk(_, chunk, options) {
|
|
24
|
+
const isServerChunk = options.dir.endsWith("/server");
|
|
25
|
+
if (options.dir.endsWith("/client") && chunk.name === "root") {
|
|
26
|
+
cssFileName = `assets/navita-${crypto.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8)}.css`;
|
|
27
|
+
chunk.viteMetadata.importedCss.add(cssFileName);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (isServerChunk && !hasEmittedCss) {
|
|
31
|
+
this.emitFile({
|
|
32
|
+
fileName: cssFileName,
|
|
33
|
+
name: "navita.css",
|
|
34
|
+
type: "asset",
|
|
35
|
+
source: getRenderer()?.engine.renderCssToString()
|
|
36
|
+
});
|
|
37
|
+
hasEmittedCss = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}];
|
|
53
41
|
}
|
|
54
42
|
const SERVER_BUILD_EXTENSION = `
|
|
55
43
|
routes.root.module = {
|
|
@@ -60,5 +48,5 @@ const SERVER_BUILD_EXTENSION = `
|
|
|
60
48
|
],
|
|
61
49
|
};
|
|
62
50
|
`;
|
|
63
|
-
|
|
51
|
+
//#endregion
|
|
64
52
|
export { navitaRemix };
|
package/rwsdk.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_index = require("./index.cjs");
|
|
4
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
node_fs_promises = require_runtime.__toESM(node_fs_promises);
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_runtime.__toESM(node_path);
|
|
8
|
+
//#region src/rwsdk.ts
|
|
9
|
+
function navitaRwsdk(options) {
|
|
10
|
+
let projectRootDir;
|
|
11
|
+
let base;
|
|
12
|
+
return [require_index.navita(options), {
|
|
13
|
+
name: "navita-rwsdk",
|
|
14
|
+
enforce: "post",
|
|
15
|
+
configResolved(config) {
|
|
16
|
+
projectRootDir = config.root;
|
|
17
|
+
base = config.base;
|
|
18
|
+
},
|
|
19
|
+
async renderChunk(code) {
|
|
20
|
+
if (this.environment?.name !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") return null;
|
|
21
|
+
const manifestPath = node_path.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
|
|
22
|
+
let manifestContent;
|
|
23
|
+
try {
|
|
24
|
+
manifestContent = await node_fs_promises.readFile(manifestPath, "utf-8");
|
|
25
|
+
} catch {
|
|
26
|
+
console.warn("[navita-rwsdk] Could not read client manifest, skipping CSS replacement");
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const manifest = JSON.parse(manifestContent);
|
|
30
|
+
let navitaCssPath = null;
|
|
31
|
+
for (const [key, value] of Object.entries(manifest)) {
|
|
32
|
+
if (key.includes("navita") && key.endsWith(".css")) {
|
|
33
|
+
navitaCssPath = (base || "/") + value.file;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (value.css) {
|
|
37
|
+
for (const cssFile of value.css) if (cssFile.includes("navita")) {
|
|
38
|
+
navitaCssPath = (base || "/") + cssFile;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (navitaCssPath) break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!navitaCssPath) {
|
|
45
|
+
console.warn("[navita-rwsdk] Could not find navita CSS in manifest");
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
let newCode = code;
|
|
49
|
+
newCode = newCode.replaceAll(`/${require_index.VIRTUAL_MODULE_ID}`, navitaCssPath);
|
|
50
|
+
newCode = newCode.replaceAll(require_index.VIRTUAL_MODULE_ID, navitaCssPath);
|
|
51
|
+
if (newCode !== code) return {
|
|
52
|
+
code: newCode,
|
|
53
|
+
map: null
|
|
54
|
+
};
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}];
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.navitaRwsdk = navitaRwsdk;
|
package/rwsdk.d.ts
ADDED
package/rwsdk.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
import { VIRTUAL_MODULE_ID, navita } from "./index.mjs";
|
|
5
|
+
import * as fsp from "node:fs/promises";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
//#region src/rwsdk.ts
|
|
8
|
+
function navitaRwsdk(options) {
|
|
9
|
+
let projectRootDir;
|
|
10
|
+
let base;
|
|
11
|
+
return [navita(options), {
|
|
12
|
+
name: "navita-rwsdk",
|
|
13
|
+
enforce: "post",
|
|
14
|
+
configResolved(config) {
|
|
15
|
+
projectRootDir = config.root;
|
|
16
|
+
base = config.base;
|
|
17
|
+
},
|
|
18
|
+
async renderChunk(code) {
|
|
19
|
+
if (this.environment?.name !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") return null;
|
|
20
|
+
const manifestPath = path.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
|
|
21
|
+
let manifestContent;
|
|
22
|
+
try {
|
|
23
|
+
manifestContent = await fsp.readFile(manifestPath, "utf-8");
|
|
24
|
+
} catch {
|
|
25
|
+
console.warn("[navita-rwsdk] Could not read client manifest, skipping CSS replacement");
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const manifest = JSON.parse(manifestContent);
|
|
29
|
+
let navitaCssPath = null;
|
|
30
|
+
for (const [key, value] of Object.entries(manifest)) {
|
|
31
|
+
if (key.includes("navita") && key.endsWith(".css")) {
|
|
32
|
+
navitaCssPath = (base || "/") + value.file;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (value.css) {
|
|
36
|
+
for (const cssFile of value.css) if (cssFile.includes("navita")) {
|
|
37
|
+
navitaCssPath = (base || "/") + cssFile;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (navitaCssPath) break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!navitaCssPath) {
|
|
44
|
+
console.warn("[navita-rwsdk] Could not find navita CSS in manifest");
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
let newCode = code;
|
|
48
|
+
newCode = newCode.replaceAll(`/${VIRTUAL_MODULE_ID}`, navitaCssPath);
|
|
49
|
+
newCode = newCode.replaceAll(VIRTUAL_MODULE_ID, navitaCssPath);
|
|
50
|
+
if (newCode !== code) return {
|
|
51
|
+
code: newCode,
|
|
52
|
+
map: null
|
|
53
|
+
};
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}];
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { navitaRwsdk };
|