@navita/vite-plugin 2.1.0 → 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.
@@ -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
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var createRenderer = require('@navita/core/createRenderer');
5
- var css = require('@navita/css');
6
-
7
- const VIRTUAL_MODULE_ID = 'virtual:navita.css';
8
- const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID.replace(/.css$/, '');
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
- const importMap = [
11
- ...css.importMap,
12
- ...options?.importMap || []
13
- ];
14
- let server;
15
- let config;
16
- let updateTimer = null;
17
- let cssEmitted = false;
18
- let isProduction = false;
19
- return {
20
- enforce: 'pre',
21
- name: 'navita',
22
- configResolved (_resolvedConfig) {
23
- config = _resolvedConfig;
24
- isProduction = config.mode === 'production';
25
- },
26
- configureServer (_server) {
27
- server = _server;
28
- },
29
- buildStart () {
30
- if (getRenderer()) {
31
- return;
32
- }
33
- setRenderer(createRenderer.createRenderer({
34
- context: config.root,
35
- engineOptions: {
36
- enableSourceMaps: !isProduction,
37
- enableDebugIdentifiers: !isProduction,
38
- ...options?.engineOptions || {}
39
- },
40
- importMap,
41
- resolver: async (filepath, request)=>{
42
- const resolved = await this.resolve(request, filepath);
43
- return resolved?.id || null;
44
- },
45
- readFile: (path)=>{
46
- return fs.promises.readFile(path, 'utf-8');
47
- }
48
- }));
49
- },
50
- resolveId (source) {
51
- const [id] = source.split('?');
52
- if (id.endsWith(VIRTUAL_MODULE_ID)) {
53
- return RESOLVED_VIRTUAL_MODULE_ID;
54
- }
55
- },
56
- async load (source) {
57
- const [id] = source.split('?');
58
- if (id === RESOLVED_VIRTUAL_MODULE_ID) {
59
- const css = getRenderer()?.engine.renderCssToString() || '';
60
- return {
61
- code: css,
62
- map: {
63
- mappings: ''
64
- }
65
- };
66
- }
67
- },
68
- async transform (code, id) {
69
- const renderer = getRenderer();
70
- if (!renderer || id.includes('node_modules')) {
71
- return null;
72
- }
73
- if (!importMap.map((x)=>x.source).some((value)=>code.indexOf(value) !== -1)) {
74
- renderer.clearCache(id);
75
- return null;
76
- }
77
- const { result, sourceMap, dependencies } = await renderer.transformAndProcess({
78
- content: code,
79
- filePath: id
80
- });
81
- if (!isProduction) {
82
- for (const dependency of dependencies){
83
- this.addWatchFile(dependency);
84
- }
85
- updateNavitaCSS();
86
- }
87
- return {
88
- code: result,
89
- map: sourceMap
90
- };
91
- },
92
- transformIndexHtml: {
93
- handler: async ()=>{
94
- // If we're building, we don't want to inject the CSS into the HTML.
95
- // We'll do this in the `renderChunk` hook instead.
96
- if (isProduction) {
97
- return [];
98
- }
99
- return [
100
- {
101
- tag: 'link',
102
- injectTo: 'head',
103
- attrs: {
104
- rel: 'stylesheet',
105
- href: `/${VIRTUAL_MODULE_ID}`
106
- }
107
- }
108
- ];
109
- }
110
- },
111
- renderChunk (_, chunk) {
112
- if (cssEmitted) {
113
- return;
114
- }
115
- chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
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 = '__navita_renderer';
118
+ const globalNavitaRendererKey = "__navita_renderer";
149
119
  function setRenderer(renderer) {
150
- globalThis[globalNavitaRendererKey] = renderer;
120
+ globalThis[globalNavitaRendererKey] = renderer;
151
121
  }
152
122
  function getRenderer() {
153
- return globalThis[globalNavitaRendererKey];
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 { ImportMap, EngineOptions, Renderer } from '@navita/core/createRenderer';
2
- import { Plugin } from 'vite';
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
- importMap?: ImportMap;
7
- engineOptions?: EngineOptions;
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 fs from 'node:fs';
2
- import { createRenderer } from '@navita/core/createRenderer';
3
- import { importMap } from '@navita/css';
4
-
5
- const VIRTUAL_MODULE_ID = 'virtual:navita.css';
6
- const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID.replace(/.css$/, '');
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
- const importMap$1 = [
9
- ...importMap,
10
- ...options?.importMap || []
11
- ];
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()) {
29
- return;
30
- }
31
- setRenderer(createRenderer({
32
- context: config.root,
33
- engineOptions: {
34
- enableSourceMaps: !isProduction,
35
- enableDebugIdentifiers: !isProduction,
36
- ...options?.engineOptions || {}
37
- },
38
- importMap: importMap$1,
39
- resolver: async (filepath, request)=>{
40
- const resolved = await this.resolve(request, filepath);
41
- return resolved?.id || null;
42
- },
43
- readFile: (path)=>{
44
- return fs.promises.readFile(path, 'utf-8');
45
- }
46
- }));
47
- },
48
- resolveId (source) {
49
- const [id] = source.split('?');
50
- if (id.endsWith(VIRTUAL_MODULE_ID)) {
51
- return RESOLVED_VIRTUAL_MODULE_ID;
52
- }
53
- },
54
- async load (source) {
55
- const [id] = source.split('?');
56
- if (id === RESOLVED_VIRTUAL_MODULE_ID) {
57
- const css = getRenderer()?.engine.renderCssToString() || '';
58
- return {
59
- code: css,
60
- map: {
61
- mappings: ''
62
- }
63
- };
64
- }
65
- },
66
- async transform (code, id) {
67
- const renderer = getRenderer();
68
- if (!renderer || id.includes('node_modules')) {
69
- return null;
70
- }
71
- if (!importMap$1.map((x)=>x.source).some((value)=>code.indexOf(value) !== -1)) {
72
- renderer.clearCache(id);
73
- return null;
74
- }
75
- const { result, sourceMap, dependencies } = await renderer.transformAndProcess({
76
- content: code,
77
- filePath: id
78
- });
79
- if (!isProduction) {
80
- for (const dependency of dependencies){
81
- this.addWatchFile(dependency);
82
- }
83
- updateNavitaCSS();
84
- }
85
- return {
86
- code: result,
87
- map: sourceMap
88
- };
89
- },
90
- transformIndexHtml: {
91
- handler: async ()=>{
92
- // If we're building, we don't want to inject the CSS into the HTML.
93
- // We'll do this in the `renderChunk` hook instead.
94
- if (isProduction) {
95
- return [];
96
- }
97
- return [
98
- {
99
- tag: 'link',
100
- injectTo: 'head',
101
- attrs: {
102
- rel: 'stylesheet',
103
- href: `/${VIRTUAL_MODULE_ID}`
104
- }
105
- }
106
- ];
107
- }
108
- },
109
- renderChunk (_, chunk) {
110
- if (cssEmitted) {
111
- return;
112
- }
113
- chunk.viteMetadata.importedCss.add(this.getFileName(this.emitFile({
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 = '__navita_renderer';
118
+ const globalNavitaRendererKey = "__navita_renderer";
147
119
  function setRenderer(renderer) {
148
- globalThis[globalNavitaRendererKey] = renderer;
120
+ globalThis[globalNavitaRendererKey] = renderer;
149
121
  }
150
122
  function getRenderer() {
151
- return globalThis[globalNavitaRendererKey];
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": "2.1.0",
3
+ "version": "3.0.0-next.0",
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": "1.0.1",
31
- "@navita/css": "0.2.1"
30
+ "@navita/core": "3.0.0-next.0",
31
+ "@navita/css": "3.0.0-next.0"
32
32
  },
33
33
  "license": "MIT",
34
34
  "author": "Eagerpatch",
package/remix.cjs CHANGED
@@ -1,85 +1,52 @@
1
- 'use strict';
2
-
3
- var crypto = require('node:crypto');
4
- var index = require('./index.cjs');
5
-
6
- function _interopNamespaceDefault(e) {
7
- var n = Object.create(null);
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
- let isProduction = false;
32
- let hasEmittedCss = false;
33
- const { renderChunk, ...navitaVite } = index.navita(options);
34
- return [
35
- navitaVite,
36
- {
37
- name: 'navita-remix',
38
- configResolved (config) {
39
- isProduction = config.mode === 'production';
40
- },
41
- transform (code, id) {
42
- if (isProduction || !VIRTUAL_MODULE_IDS.includes(id)) {
43
- return;
44
- }
45
- return `${code}\n${SERVER_BUILD_EXTENSION}`;
46
- },
47
- renderChunk (_, chunk, options) {
48
- const isServerChunk = options.dir.endsWith('/server');
49
- const isClientChunk = options.dir.endsWith('/client');
50
- if (isClientChunk && chunk.name === "root") {
51
- // Generate a random name for the CSS file.
52
- // Vite uses a file hash as the name, but since the client build will finish before
53
- // the server build, we need to generate a random name for the CSS file.
54
- // Ideally we could use a hash, but since the server might contain more styles than the client, we need to do it like this.
55
- const random = crypto__namespace.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8);
56
- cssFileName = `assets/navita-${random}.css`;
57
- chunk.viteMetadata.importedCss.add(cssFileName);
58
- return;
59
- }
60
- if (isServerChunk && !hasEmittedCss) {
61
- // In the server-build, we'll generate the CSS and emit it as an asset.
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: '/${index.VIRTUAL_MODULE_ID}' },
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 { Plugin } from 'vite';
2
- import { Options } from './index.js';
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 * as crypto from 'node:crypto';
2
- import { navita, getRenderer, VIRTUAL_MODULE_ID } from './index.mjs';
3
-
4
- const VIRTUAL_MODULE_IDS = [
5
- '\0virtual:remix/server-build',
6
- '\0virtual:react-router/server-build'
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
- let isProduction = false;
11
- let hasEmittedCss = false;
12
- const { renderChunk, ...navitaVite } = navita(options);
13
- return [
14
- navitaVite,
15
- {
16
- name: 'navita-remix',
17
- configResolved (config) {
18
- isProduction = config.mode === 'production';
19
- },
20
- transform (code, id) {
21
- if (isProduction || !VIRTUAL_MODULE_IDS.includes(id)) {
22
- return;
23
- }
24
- return `${code}\n${SERVER_BUILD_EXTENSION}`;
25
- },
26
- renderChunk (_, chunk, options) {
27
- const isServerChunk = options.dir.endsWith('/server');
28
- const isClientChunk = options.dir.endsWith('/client');
29
- if (isClientChunk && chunk.name === "root") {
30
- // Generate a random name for the CSS file.
31
- // Vite uses a file hash as the name, but since the client build will finish before
32
- // the server build, we need to generate a random name for the CSS file.
33
- // Ideally we could use a hash, but since the server might contain more styles than the client, we need to do it like this.
34
- const random = crypto.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8);
35
- cssFileName = `assets/navita-${random}.css`;
36
- chunk.viteMetadata.importedCss.add(cssFileName);
37
- return;
38
- }
39
- if (isServerChunk && !hasEmittedCss) {
40
- // In the server-build, we'll generate the CSS and emit it as an asset.
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 CHANGED
@@ -1,96 +1,60 @@
1
- 'use strict';
2
-
3
- var fsp = require('node:fs/promises');
4
- var path = require('node:path');
5
- var index = require('./index.cjs');
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
25
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
26
-
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
27
9
  function navitaRwsdk(options) {
28
- let projectRootDir;
29
- let base;
30
- const navitaPlugin = index.navita(options);
31
- return [
32
- navitaPlugin,
33
- {
34
- name: "navita-rwsdk",
35
- enforce: "post",
36
- configResolved (config) {
37
- projectRootDir = config.root;
38
- base = config.base;
39
- },
40
- async renderChunk (code) {
41
- // Only run during the linker pass on the worker environment
42
- // @ts-expect-error - environment exists at runtime in Vite 6+
43
- const environmentName = this.environment?.name;
44
- if (environmentName !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") {
45
- return null;
46
- }
47
- // Read the client manifest to find the navita CSS path
48
- const manifestPath = path__namespace.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
49
- let manifestContent;
50
- try {
51
- manifestContent = await fsp__namespace.readFile(manifestPath, "utf-8");
52
- } catch {
53
- console.warn("[navita-rwsdk] Could not read client manifest, skipping CSS replacement");
54
- return null;
55
- }
56
- const manifest = JSON.parse(manifestContent);
57
- // Find the navita CSS file in the manifest
58
- let navitaCssPath = null;
59
- for (const [key, value] of Object.entries(manifest)){
60
- // Check if this is the navita CSS entry directly
61
- if (key.includes("navita") && key.endsWith(".css")) {
62
- navitaCssPath = (base || "/") + value.file;
63
- break;
64
- }
65
- // Also check if it's referenced in the css array of any entry
66
- if (value.css) {
67
- for (const cssFile of value.css){
68
- if (cssFile.includes("navita")) {
69
- navitaCssPath = (base || "/") + cssFile;
70
- break;
71
- }
72
- }
73
- if (navitaCssPath) break;
74
- }
75
- }
76
- if (!navitaCssPath) {
77
- console.warn("[navita-rwsdk] Could not find navita CSS in manifest");
78
- return null;
79
- }
80
- // Replace virtual:navita.css references with the actual hashed path
81
- let newCode = code;
82
- newCode = newCode.replaceAll(`/${index.VIRTUAL_MODULE_ID}`, navitaCssPath);
83
- newCode = newCode.replaceAll(index.VIRTUAL_MODULE_ID, navitaCssPath);
84
- if (newCode !== code) {
85
- return {
86
- code: newCode,
87
- map: null
88
- };
89
- }
90
- return null;
91
- }
92
- }
93
- ];
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
+ }];
94
58
  }
95
-
59
+ //#endregion
96
60
  exports.navitaRwsdk = navitaRwsdk;
package/rwsdk.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Plugin } from 'vite';
2
- import { Options } from './index.js';
3
- import '@navita/core/createRenderer';
1
+ import { Options } from "./index.js";
2
+ import { Plugin } from "vite";
4
3
 
4
+ //#region src/rwsdk.d.ts
5
5
  declare function navitaRwsdk(options?: Options): Plugin[];
6
-
7
- export { navitaRwsdk };
6
+ //#endregion
7
+ export { navitaRwsdk };
package/rwsdk.mjs CHANGED
@@ -1,74 +1,59 @@
1
- import * as fsp from 'node:fs/promises';
2
- import * as path from 'node:path';
3
- import { navita, VIRTUAL_MODULE_ID } from './index.mjs';
4
-
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
5
8
  function navitaRwsdk(options) {
6
- let projectRootDir;
7
- let base;
8
- const navitaPlugin = navita(options);
9
- return [
10
- navitaPlugin,
11
- {
12
- name: "navita-rwsdk",
13
- enforce: "post",
14
- configResolved (config) {
15
- projectRootDir = config.root;
16
- base = config.base;
17
- },
18
- async renderChunk (code) {
19
- // Only run during the linker pass on the worker environment
20
- // @ts-expect-error - environment exists at runtime in Vite 6+
21
- const environmentName = this.environment?.name;
22
- if (environmentName !== "worker" || process.env.RWSDK_BUILD_PASS !== "linker") {
23
- return null;
24
- }
25
- // Read the client manifest to find the navita CSS path
26
- const manifestPath = path.resolve(projectRootDir, "dist", "client", ".vite", "manifest.json");
27
- let manifestContent;
28
- try {
29
- manifestContent = await fsp.readFile(manifestPath, "utf-8");
30
- } catch {
31
- console.warn("[navita-rwsdk] Could not read client manifest, skipping CSS replacement");
32
- return null;
33
- }
34
- const manifest = JSON.parse(manifestContent);
35
- // Find the navita CSS file in the manifest
36
- let navitaCssPath = null;
37
- for (const [key, value] of Object.entries(manifest)){
38
- // Check if this is the navita CSS entry directly
39
- if (key.includes("navita") && key.endsWith(".css")) {
40
- navitaCssPath = (base || "/") + value.file;
41
- break;
42
- }
43
- // Also check if it's referenced in the css array of any entry
44
- if (value.css) {
45
- for (const cssFile of value.css){
46
- if (cssFile.includes("navita")) {
47
- navitaCssPath = (base || "/") + cssFile;
48
- break;
49
- }
50
- }
51
- if (navitaCssPath) break;
52
- }
53
- }
54
- if (!navitaCssPath) {
55
- console.warn("[navita-rwsdk] Could not find navita CSS in manifest");
56
- return null;
57
- }
58
- // Replace virtual:navita.css references with the actual hashed path
59
- let newCode = code;
60
- newCode = newCode.replaceAll(`/${VIRTUAL_MODULE_ID}`, navitaCssPath);
61
- newCode = newCode.replaceAll(VIRTUAL_MODULE_ID, navitaCssPath);
62
- if (newCode !== code) {
63
- return {
64
- code: newCode,
65
- map: null
66
- };
67
- }
68
- return null;
69
- }
70
- }
71
- ];
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
+ }];
72
57
  }
73
-
58
+ //#endregion
74
59
  export { navitaRwsdk };