@rozenite/vite-plugin 1.0.0-alpha.4 → 1.0.0-alpha.6
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/dist/index.cjs +129 -96
- package/dist/index.js +129 -96
- package/dist/react-native-plugin.d.ts.map +1 -1
- package/dist/require-plugin.d.ts.map +1 -1
- package/dist/server-plugin.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const react = require("@vitejs/plugin-react");
|
|
4
4
|
const reactNativeWeb = require("vite-plugin-react-native-web");
|
|
5
5
|
const process$1 = require("node:process");
|
|
6
|
-
const fs = require("node:fs");
|
|
7
6
|
const path = require("node:path");
|
|
7
|
+
const fs = require("node:fs");
|
|
8
8
|
const ejs = require("ejs");
|
|
9
9
|
const node_url = require("node:url");
|
|
10
10
|
const vite = require("vite");
|
|
@@ -12,35 +12,23 @@ const fs$1 = require("node:fs/promises");
|
|
|
12
12
|
const maybeDtsPlugin = require("vite-plugin-dts");
|
|
13
13
|
const assert = require("node:assert");
|
|
14
14
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
15
|
-
const resolveFileWithExtensions = (directory, baseName) => {
|
|
16
|
-
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
17
|
-
for (const ext of extensions) {
|
|
18
|
-
const filePath = path.join(directory, baseName + ext);
|
|
19
|
-
if (fs.existsSync(filePath)) {
|
|
20
|
-
return filePath;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
15
|
const rozeniteServerPlugin = () => {
|
|
26
16
|
return {
|
|
27
17
|
name: "rozenite-server-plugin",
|
|
28
18
|
config(config) {
|
|
29
|
-
var _a;
|
|
30
19
|
const projectRoot = config.root ?? process$1.cwd();
|
|
31
|
-
const backgroundFilePath = resolveFileWithExtensions(
|
|
32
|
-
projectRoot,
|
|
33
|
-
"background"
|
|
34
|
-
);
|
|
35
|
-
if (!backgroundFilePath) {
|
|
36
|
-
throw new Error("Background file not found");
|
|
37
|
-
}
|
|
38
20
|
config.build ?? (config.build = {});
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
config.build.lib = {
|
|
22
|
+
entry: path.resolve(projectRoot, "metro.ts"),
|
|
23
|
+
formats: ["es", "cjs"],
|
|
24
|
+
fileName: (format) => `metro.${format === "es" ? "js" : "cjs"}`
|
|
25
|
+
};
|
|
41
26
|
config.build.ssr = true;
|
|
42
|
-
config.build.rollupOptions
|
|
43
|
-
|
|
27
|
+
config.build.rollupOptions = {
|
|
28
|
+
output: {
|
|
29
|
+
exports: "named",
|
|
30
|
+
interop: "auto"
|
|
31
|
+
}
|
|
44
32
|
};
|
|
45
33
|
}
|
|
46
34
|
};
|
|
@@ -267,15 +255,68 @@ const rozeniteReactNativePlugin = () => {
|
|
|
267
255
|
}
|
|
268
256
|
return !id.startsWith(".") && !path.isAbsolute(id);
|
|
269
257
|
};
|
|
258
|
+
config.build.rollupOptions.output = {
|
|
259
|
+
exports: "named",
|
|
260
|
+
interop: "auto"
|
|
261
|
+
};
|
|
270
262
|
delete config.build.rollupOptions.input;
|
|
271
263
|
}
|
|
272
264
|
};
|
|
273
265
|
};
|
|
266
|
+
const REQUIRE_REGEX = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
|
|
267
|
+
const IMPORT_PREFIX = "__import_";
|
|
274
268
|
function requirePlugin() {
|
|
275
269
|
let input = "";
|
|
276
270
|
let inputName = "";
|
|
277
271
|
let isDevMode = false;
|
|
278
272
|
const moduleToChunkMap = /* @__PURE__ */ new Map();
|
|
273
|
+
const moduleInfoMap = /* @__PURE__ */ new Map();
|
|
274
|
+
const extractModuleName = (filePath) => {
|
|
275
|
+
return path.basename(filePath).replace(/\.[^/.]+$/, "");
|
|
276
|
+
};
|
|
277
|
+
const getFileExtension = (format) => {
|
|
278
|
+
return format === "es" ? ".js" : ".cjs";
|
|
279
|
+
};
|
|
280
|
+
const findRequireStatements = (code) => {
|
|
281
|
+
const requires = /* @__PURE__ */ new Set();
|
|
282
|
+
let match;
|
|
283
|
+
REQUIRE_REGEX.lastIndex = 0;
|
|
284
|
+
while ((match = REQUIRE_REGEX.exec(code)) !== null) {
|
|
285
|
+
const moduleName = match[1];
|
|
286
|
+
if (moduleName && moduleName.trim()) {
|
|
287
|
+
requires.add(moduleName.trim());
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return requires;
|
|
291
|
+
};
|
|
292
|
+
const transformRequireToImports = (code) => {
|
|
293
|
+
const imports = [];
|
|
294
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
295
|
+
const requires = findRequireStatements(code);
|
|
296
|
+
requires.forEach((moduleName, index) => {
|
|
297
|
+
const importName = `${IMPORT_PREFIX}${index}`;
|
|
298
|
+
importMap.set(moduleName, importName);
|
|
299
|
+
imports.push(`import * as ${importName} from '${moduleName}';`);
|
|
300
|
+
});
|
|
301
|
+
let transformedCode = code.replace(REQUIRE_REGEX, (match, moduleName) => {
|
|
302
|
+
const importName = importMap.get(moduleName.trim());
|
|
303
|
+
return importName || match;
|
|
304
|
+
});
|
|
305
|
+
if (imports.length > 0) {
|
|
306
|
+
transformedCode = imports.join("\n") + "\n" + transformedCode;
|
|
307
|
+
}
|
|
308
|
+
return { code: transformedCode, imports, importMap };
|
|
309
|
+
};
|
|
310
|
+
const transformRequireToChunkReferences = (code, format) => {
|
|
311
|
+
return code.replace(REQUIRE_REGEX, (match, moduleName) => {
|
|
312
|
+
const chunkName = moduleToChunkMap.get(moduleName.trim());
|
|
313
|
+
if (chunkName) {
|
|
314
|
+
const extension = getFileExtension(format);
|
|
315
|
+
return `require('./${chunkName}${extension}')`;
|
|
316
|
+
}
|
|
317
|
+
return match;
|
|
318
|
+
});
|
|
319
|
+
};
|
|
279
320
|
return {
|
|
280
321
|
name: "vite-require-plugin",
|
|
281
322
|
configResolved(config) {
|
|
@@ -285,85 +326,77 @@ function requirePlugin() {
|
|
|
285
326
|
if (!isDevMode || id !== input) {
|
|
286
327
|
return null;
|
|
287
328
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
importMap.set(moduleName, importName);
|
|
298
|
-
imports.push(`import * as ${importName} from '${moduleName}';`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
transformedCode = transformedCode.replace(
|
|
302
|
-
/require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,
|
|
303
|
-
(match2, moduleName) => {
|
|
304
|
-
const importName = importMap.get(moduleName);
|
|
305
|
-
return importName || match2;
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
if (imports.length > 0) {
|
|
309
|
-
transformedCode = imports.join("\n") + "\n" + transformedCode;
|
|
329
|
+
try {
|
|
330
|
+
const result = transformRequireToImports(code);
|
|
331
|
+
return {
|
|
332
|
+
code: result.code,
|
|
333
|
+
map: null
|
|
334
|
+
};
|
|
335
|
+
} catch (error) {
|
|
336
|
+
console.error("Error transforming require statements:", error);
|
|
337
|
+
return null;
|
|
310
338
|
}
|
|
311
|
-
return {
|
|
312
|
-
code: transformedCode,
|
|
313
|
-
map: null
|
|
314
|
-
};
|
|
315
339
|
},
|
|
316
340
|
async buildStart(options) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
try {
|
|
342
|
+
assert(Array.isArray(options.input), "input must be an array");
|
|
343
|
+
assert(
|
|
344
|
+
options.input.length === 1,
|
|
345
|
+
"input must be an array with one entry"
|
|
346
|
+
);
|
|
347
|
+
input = options.input[0];
|
|
348
|
+
inputName = extractModuleName(input);
|
|
349
|
+
const code = fs.readFileSync(input, "utf-8");
|
|
350
|
+
const requires = findRequireStatements(code);
|
|
351
|
+
for (const req of requires) {
|
|
352
|
+
try {
|
|
353
|
+
const resolved = await this.resolve(req, input);
|
|
354
|
+
if (resolved) {
|
|
355
|
+
const fileName = extractModuleName(resolved.id);
|
|
356
|
+
this.addWatchFile(resolved.id);
|
|
357
|
+
this.emitFile({
|
|
358
|
+
type: "chunk",
|
|
359
|
+
id: resolved.id,
|
|
360
|
+
fileName
|
|
361
|
+
});
|
|
362
|
+
moduleToChunkMap.set(req, fileName);
|
|
363
|
+
moduleInfoMap.set(req, {
|
|
364
|
+
fileName,
|
|
365
|
+
resolvedId: resolved.id
|
|
366
|
+
});
|
|
367
|
+
} else {
|
|
368
|
+
console.warn(`Could not resolve module: ${req}`);
|
|
369
|
+
}
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error(`Error resolving module ${req}:`, error);
|
|
372
|
+
}
|
|
345
373
|
}
|
|
374
|
+
} catch (error) {
|
|
375
|
+
console.error("Error in buildStart:", error);
|
|
376
|
+
throw error;
|
|
346
377
|
}
|
|
347
378
|
},
|
|
348
|
-
renderChunk(code, chunk) {
|
|
349
|
-
|
|
379
|
+
renderChunk(code, chunk, options) {
|
|
380
|
+
try {
|
|
381
|
+
const additionalChunkNames = Array.from(moduleToChunkMap.values());
|
|
382
|
+
if (additionalChunkNames.includes(chunk.fileName)) {
|
|
383
|
+
chunk.fileName = chunk.fileName + getFileExtension(options.format);
|
|
384
|
+
}
|
|
385
|
+
if (chunk.name !== inputName) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
const transformedCode = transformRequireToChunkReferences(
|
|
389
|
+
code,
|
|
390
|
+
options.format
|
|
391
|
+
);
|
|
392
|
+
return {
|
|
393
|
+
code: transformedCode,
|
|
394
|
+
map: null
|
|
395
|
+
};
|
|
396
|
+
} catch (error) {
|
|
397
|
+
console.error("Error in renderChunk:", error);
|
|
350
398
|
return null;
|
|
351
399
|
}
|
|
352
|
-
let transformedCode = code;
|
|
353
|
-
transformedCode = transformedCode.replace(
|
|
354
|
-
/require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,
|
|
355
|
-
(match, moduleName) => {
|
|
356
|
-
const chunkName = moduleToChunkMap.get(moduleName);
|
|
357
|
-
if (chunkName) {
|
|
358
|
-
return `require('./${chunkName}')`;
|
|
359
|
-
}
|
|
360
|
-
return match;
|
|
361
|
-
}
|
|
362
|
-
);
|
|
363
|
-
return {
|
|
364
|
-
code: transformedCode,
|
|
365
|
-
map: null
|
|
366
|
-
};
|
|
367
400
|
}
|
|
368
401
|
};
|
|
369
402
|
}
|
|
@@ -372,13 +405,13 @@ const rozenitePlugin = () => {
|
|
|
372
405
|
const isServer = process.env.VITE_ROZENITE_TARGET === "server";
|
|
373
406
|
const isReactNative = process.env.VITE_ROZENITE_TARGET === "react-native";
|
|
374
407
|
if (isServer) {
|
|
375
|
-
return [rozeniteServerPlugin()];
|
|
408
|
+
return [rozeniteServerPlugin(), dtsPlugin()];
|
|
376
409
|
} else if (isReactNative) {
|
|
377
410
|
return [
|
|
378
411
|
react(),
|
|
379
412
|
requirePlugin(),
|
|
380
413
|
rozeniteReactNativePlugin(),
|
|
381
|
-
dtsPlugin(
|
|
414
|
+
dtsPlugin()
|
|
382
415
|
];
|
|
383
416
|
}
|
|
384
417
|
return [
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
import react from "@vitejs/plugin-react";
|
|
2
2
|
import reactNativeWeb from "vite-plugin-react-native-web";
|
|
3
3
|
import process$1 from "node:process";
|
|
4
|
-
import fs, { readFileSync } from "node:fs";
|
|
5
4
|
import path from "node:path";
|
|
5
|
+
import fs, { readFileSync } from "node:fs";
|
|
6
6
|
import ejs from "ejs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { transformWithEsbuild } from "vite";
|
|
9
9
|
import fs$1 from "node:fs/promises";
|
|
10
10
|
import maybeDtsPlugin from "vite-plugin-dts";
|
|
11
11
|
import assert from "node:assert";
|
|
12
|
-
const resolveFileWithExtensions = (directory, baseName) => {
|
|
13
|
-
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
14
|
-
for (const ext of extensions) {
|
|
15
|
-
const filePath = path.join(directory, baseName + ext);
|
|
16
|
-
if (fs.existsSync(filePath)) {
|
|
17
|
-
return filePath;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
12
|
const rozeniteServerPlugin = () => {
|
|
23
13
|
return {
|
|
24
14
|
name: "rozenite-server-plugin",
|
|
25
15
|
config(config) {
|
|
26
|
-
var _a;
|
|
27
16
|
const projectRoot = config.root ?? process$1.cwd();
|
|
28
|
-
const backgroundFilePath = resolveFileWithExtensions(
|
|
29
|
-
projectRoot,
|
|
30
|
-
"background"
|
|
31
|
-
);
|
|
32
|
-
if (!backgroundFilePath) {
|
|
33
|
-
throw new Error("Background file not found");
|
|
34
|
-
}
|
|
35
17
|
config.build ?? (config.build = {});
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
config.build.lib = {
|
|
19
|
+
entry: path.resolve(projectRoot, "metro.ts"),
|
|
20
|
+
formats: ["es", "cjs"],
|
|
21
|
+
fileName: (format) => `metro.${format === "es" ? "js" : "cjs"}`
|
|
22
|
+
};
|
|
38
23
|
config.build.ssr = true;
|
|
39
|
-
config.build.rollupOptions
|
|
40
|
-
|
|
24
|
+
config.build.rollupOptions = {
|
|
25
|
+
output: {
|
|
26
|
+
exports: "named",
|
|
27
|
+
interop: "auto"
|
|
28
|
+
}
|
|
41
29
|
};
|
|
42
30
|
}
|
|
43
31
|
};
|
|
@@ -264,15 +252,68 @@ const rozeniteReactNativePlugin = () => {
|
|
|
264
252
|
}
|
|
265
253
|
return !id.startsWith(".") && !path.isAbsolute(id);
|
|
266
254
|
};
|
|
255
|
+
config.build.rollupOptions.output = {
|
|
256
|
+
exports: "named",
|
|
257
|
+
interop: "auto"
|
|
258
|
+
};
|
|
267
259
|
delete config.build.rollupOptions.input;
|
|
268
260
|
}
|
|
269
261
|
};
|
|
270
262
|
};
|
|
263
|
+
const REQUIRE_REGEX = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
|
|
264
|
+
const IMPORT_PREFIX = "__import_";
|
|
271
265
|
function requirePlugin() {
|
|
272
266
|
let input = "";
|
|
273
267
|
let inputName = "";
|
|
274
268
|
let isDevMode = false;
|
|
275
269
|
const moduleToChunkMap = /* @__PURE__ */ new Map();
|
|
270
|
+
const moduleInfoMap = /* @__PURE__ */ new Map();
|
|
271
|
+
const extractModuleName = (filePath) => {
|
|
272
|
+
return path.basename(filePath).replace(/\.[^/.]+$/, "");
|
|
273
|
+
};
|
|
274
|
+
const getFileExtension = (format) => {
|
|
275
|
+
return format === "es" ? ".js" : ".cjs";
|
|
276
|
+
};
|
|
277
|
+
const findRequireStatements = (code) => {
|
|
278
|
+
const requires = /* @__PURE__ */ new Set();
|
|
279
|
+
let match;
|
|
280
|
+
REQUIRE_REGEX.lastIndex = 0;
|
|
281
|
+
while ((match = REQUIRE_REGEX.exec(code)) !== null) {
|
|
282
|
+
const moduleName = match[1];
|
|
283
|
+
if (moduleName && moduleName.trim()) {
|
|
284
|
+
requires.add(moduleName.trim());
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return requires;
|
|
288
|
+
};
|
|
289
|
+
const transformRequireToImports = (code) => {
|
|
290
|
+
const imports = [];
|
|
291
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
292
|
+
const requires = findRequireStatements(code);
|
|
293
|
+
requires.forEach((moduleName, index) => {
|
|
294
|
+
const importName = `${IMPORT_PREFIX}${index}`;
|
|
295
|
+
importMap.set(moduleName, importName);
|
|
296
|
+
imports.push(`import * as ${importName} from '${moduleName}';`);
|
|
297
|
+
});
|
|
298
|
+
let transformedCode = code.replace(REQUIRE_REGEX, (match, moduleName) => {
|
|
299
|
+
const importName = importMap.get(moduleName.trim());
|
|
300
|
+
return importName || match;
|
|
301
|
+
});
|
|
302
|
+
if (imports.length > 0) {
|
|
303
|
+
transformedCode = imports.join("\n") + "\n" + transformedCode;
|
|
304
|
+
}
|
|
305
|
+
return { code: transformedCode, imports, importMap };
|
|
306
|
+
};
|
|
307
|
+
const transformRequireToChunkReferences = (code, format) => {
|
|
308
|
+
return code.replace(REQUIRE_REGEX, (match, moduleName) => {
|
|
309
|
+
const chunkName = moduleToChunkMap.get(moduleName.trim());
|
|
310
|
+
if (chunkName) {
|
|
311
|
+
const extension = getFileExtension(format);
|
|
312
|
+
return `require('./${chunkName}${extension}')`;
|
|
313
|
+
}
|
|
314
|
+
return match;
|
|
315
|
+
});
|
|
316
|
+
};
|
|
276
317
|
return {
|
|
277
318
|
name: "vite-require-plugin",
|
|
278
319
|
configResolved(config) {
|
|
@@ -282,85 +323,77 @@ function requirePlugin() {
|
|
|
282
323
|
if (!isDevMode || id !== input) {
|
|
283
324
|
return null;
|
|
284
325
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
importMap.set(moduleName, importName);
|
|
295
|
-
imports.push(`import * as ${importName} from '${moduleName}';`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
transformedCode = transformedCode.replace(
|
|
299
|
-
/require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,
|
|
300
|
-
(match2, moduleName) => {
|
|
301
|
-
const importName = importMap.get(moduleName);
|
|
302
|
-
return importName || match2;
|
|
303
|
-
}
|
|
304
|
-
);
|
|
305
|
-
if (imports.length > 0) {
|
|
306
|
-
transformedCode = imports.join("\n") + "\n" + transformedCode;
|
|
326
|
+
try {
|
|
327
|
+
const result = transformRequireToImports(code);
|
|
328
|
+
return {
|
|
329
|
+
code: result.code,
|
|
330
|
+
map: null
|
|
331
|
+
};
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error("Error transforming require statements:", error);
|
|
334
|
+
return null;
|
|
307
335
|
}
|
|
308
|
-
return {
|
|
309
|
-
code: transformedCode,
|
|
310
|
-
map: null
|
|
311
|
-
};
|
|
312
336
|
},
|
|
313
337
|
async buildStart(options) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
try {
|
|
339
|
+
assert(Array.isArray(options.input), "input must be an array");
|
|
340
|
+
assert(
|
|
341
|
+
options.input.length === 1,
|
|
342
|
+
"input must be an array with one entry"
|
|
343
|
+
);
|
|
344
|
+
input = options.input[0];
|
|
345
|
+
inputName = extractModuleName(input);
|
|
346
|
+
const code = readFileSync(input, "utf-8");
|
|
347
|
+
const requires = findRequireStatements(code);
|
|
348
|
+
for (const req of requires) {
|
|
349
|
+
try {
|
|
350
|
+
const resolved = await this.resolve(req, input);
|
|
351
|
+
if (resolved) {
|
|
352
|
+
const fileName = extractModuleName(resolved.id);
|
|
353
|
+
this.addWatchFile(resolved.id);
|
|
354
|
+
this.emitFile({
|
|
355
|
+
type: "chunk",
|
|
356
|
+
id: resolved.id,
|
|
357
|
+
fileName
|
|
358
|
+
});
|
|
359
|
+
moduleToChunkMap.set(req, fileName);
|
|
360
|
+
moduleInfoMap.set(req, {
|
|
361
|
+
fileName,
|
|
362
|
+
resolvedId: resolved.id
|
|
363
|
+
});
|
|
364
|
+
} else {
|
|
365
|
+
console.warn(`Could not resolve module: ${req}`);
|
|
366
|
+
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.error(`Error resolving module ${req}:`, error);
|
|
369
|
+
}
|
|
342
370
|
}
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error("Error in buildStart:", error);
|
|
373
|
+
throw error;
|
|
343
374
|
}
|
|
344
375
|
},
|
|
345
|
-
renderChunk(code, chunk) {
|
|
346
|
-
|
|
376
|
+
renderChunk(code, chunk, options) {
|
|
377
|
+
try {
|
|
378
|
+
const additionalChunkNames = Array.from(moduleToChunkMap.values());
|
|
379
|
+
if (additionalChunkNames.includes(chunk.fileName)) {
|
|
380
|
+
chunk.fileName = chunk.fileName + getFileExtension(options.format);
|
|
381
|
+
}
|
|
382
|
+
if (chunk.name !== inputName) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
const transformedCode = transformRequireToChunkReferences(
|
|
386
|
+
code,
|
|
387
|
+
options.format
|
|
388
|
+
);
|
|
389
|
+
return {
|
|
390
|
+
code: transformedCode,
|
|
391
|
+
map: null
|
|
392
|
+
};
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error("Error in renderChunk:", error);
|
|
347
395
|
return null;
|
|
348
396
|
}
|
|
349
|
-
let transformedCode = code;
|
|
350
|
-
transformedCode = transformedCode.replace(
|
|
351
|
-
/require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,
|
|
352
|
-
(match, moduleName) => {
|
|
353
|
-
const chunkName = moduleToChunkMap.get(moduleName);
|
|
354
|
-
if (chunkName) {
|
|
355
|
-
return `require('./${chunkName}')`;
|
|
356
|
-
}
|
|
357
|
-
return match;
|
|
358
|
-
}
|
|
359
|
-
);
|
|
360
|
-
return {
|
|
361
|
-
code: transformedCode,
|
|
362
|
-
map: null
|
|
363
|
-
};
|
|
364
397
|
}
|
|
365
398
|
};
|
|
366
399
|
}
|
|
@@ -369,13 +402,13 @@ const rozenitePlugin = () => {
|
|
|
369
402
|
const isServer = process.env.VITE_ROZENITE_TARGET === "server";
|
|
370
403
|
const isReactNative = process.env.VITE_ROZENITE_TARGET === "react-native";
|
|
371
404
|
if (isServer) {
|
|
372
|
-
return [rozeniteServerPlugin()];
|
|
405
|
+
return [rozeniteServerPlugin(), dtsPlugin()];
|
|
373
406
|
} else if (isReactNative) {
|
|
374
407
|
return [
|
|
375
408
|
react(),
|
|
376
409
|
requirePlugin(),
|
|
377
410
|
rozeniteReactNativePlugin(),
|
|
378
|
-
dtsPlugin(
|
|
411
|
+
dtsPlugin()
|
|
379
412
|
];
|
|
380
413
|
}
|
|
381
414
|
return [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-plugin.d.ts","sourceRoot":"","sources":["../src/react-native-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,eAAO,MAAM,yBAAyB,QAAO,
|
|
1
|
+
{"version":3,"file":"react-native-plugin.d.ts","sourceRoot":"","sources":["../src/react-native-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,eAAO,MAAM,yBAAyB,QAAO,MA+B5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-plugin.d.ts","sourceRoot":"","sources":["../src/require-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"require-plugin.d.ts","sourceRoot":"","sources":["../src/require-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAgB9B,MAAM,CAAC,OAAO,UAAU,aAAa,IAAI,MAAM,CAuL9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-plugin.d.ts","sourceRoot":"","sources":["../src/server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,eAAO,MAAM,oBAAoB,QAAO,
|
|
1
|
+
{"version":3,"file":"server-plugin.d.ts","sourceRoot":"","sources":["../src/server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,eAAO,MAAM,oBAAoB,QAAO,MAsBvC,CAAC"}
|
package/package.json
CHANGED